TWIS HAL
- group nrf_twis_hal
Hardware access layer for managing the Two Wire Interface Slave with EasyDMA (TWIS) peripheral.
Defines
-
NRF_TWIS_INST_GET(idx)
Macro getting pointer to the structure of registers of the TWIS peripheral.
- Parameters:
idx – [in] TWIS instance index.
- Returns:
Pointer to the structure of registers of the TWIS peripheral.
-
NRF_TWIS_HAS_DMA_REG
Symbol indicating whether dedicated DMA register is present.
-
NRF_TWIS_HAS_DMA_TASKS_EVENTS
Symbol indicating whether TWIS DMA tasks and events are present.
Typedefs
-
typedef uint8_t nrf_twis_address_t
Smallest variable type to hold the TWI address.
Variable of the minimum size that can hold a single TWI address.
Note
Defined to make it simple to change if the new TWI supports for example 10 bit addressing mode.
Enums
-
enum nrf_twis_task_t
TWIS tasks.
Values:
-
enumerator NRF_TWIS_TASK_STOP
Stop TWIS transaction.
-
enumerator NRF_TWIS_TASK_SUSPEND
Suspend TWIS transaction.
-
enumerator NRF_TWIS_TASK_RESUME
Resume TWIS transaction.
-
enumerator NRF_TWIS_TASK_PREPARERX
Prepare the TWIS slave to respond to a write command.
-
enumerator NRF_TWIS_TASK_PREPARETX
Prepare the TWIS slave to respond to a read command.
-
enumerator NRF_TWIS_TASK_STOP
-
enum nrf_twis_event_t
TWIS events.
Values:
-
enumerator NRF_TWIS_EVENT_STOPPED
TWIS stopped.
-
enumerator NRF_TWIS_EVENT_ERROR
TWIS error.
-
enumerator NRF_TWIS_EVENT_RXSTARTED
Receive sequence started.
-
enumerator NRF_TWIS_EVENT_TXSTARTED
Transmit sequence started.
-
enumerator NRF_TWIS_EVENT_WRITE
Write command received.
-
enumerator NRF_TWIS_EVENT_READ
Read command received.
-
enumerator NRF_TWIS_EVENT_STOPPED
-
enum nrf_twis_short_mask_t
TWIS shortcuts.
Values:
-
enumerator NRF_TWIS_SHORT_WRITE_SUSPEND_MASK
Shortcut between WRITE event and SUSPEND task.
-
enumerator NRF_TWIS_SHORT_READ_SUSPEND_MASK
Shortcut between READ event and SUSPEND task.
-
enumerator NRF_TWIS_SHORT_WRITE_SUSPEND_MASK
-
enum nrf_twis_int_mask_t
TWIS interrupts.
Values:
-
enumerator NRF_TWIS_INT_STOPPED_MASK
Interrupt on STOPPED event.
-
enumerator NRF_TWIS_INT_ERROR_MASK
Interrupt on ERROR event.
-
enumerator NRF_TWIS_INT_RXSTARTED_MASK
Interrupt on RXSTARTED event.
-
enumerator NRF_TWIS_INT_TXSTARTED_MASK
Interrupt on TXSTARTED event.
-
enumerator NRF_TWIS_INT_WRITE_MASK
Interrupt on WRITE event.
-
enumerator NRF_TWIS_INT_READ_MASK
Interrupt on READ event.
-
enumerator NRF_TWIS_INT_STOPPED_MASK
-
enum nrf_twis_error_t
TWIS error source.
Values:
-
enumerator NRF_TWIS_ERROR_OVERFLOW
RX buffer overflow detected, and prevented.
-
enumerator NRF_TWIS_ERROR_DATA_NACK
NACK sent after receiving a data byte.
-
enumerator NRF_TWIS_ERROR_OVERREAD
TX buffer over-read detected, and prevented.
-
enumerator NRF_TWIS_ERROR_OVERFLOW
-
enum nrf_twis_config_addr_mask_t
TWIS address matching configuration.
Values:
-
enumerator NRF_TWIS_CONFIG_ADDRESS0_MASK
Enable or disable address matching on ADDRESS[0].
-
enumerator NRF_TWIS_CONFIG_ADDRESS1_MASK
Enable or disable address matching on ADDRESS[1].
-
enumerator NRF_TWIS_CONFIG_ADDRESS01_MASK
Enable both address matching.
-
enumerator NRF_TWIS_CONFIG_ADDRESS0_MASK
Functions
-
NRF_STATIC_INLINE void nrf_twis_task_trigger(NRF_TWIS_Type *p_reg, nrf_twis_task_t task)
Function for activating the specified TWIS task.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task to be activated.
-
NRF_STATIC_INLINE uint32_t nrf_twis_task_address_get(NRF_TWIS_Type const *p_reg, nrf_twis_task_t task)
Function for returning the address of the specified TWIS task register.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] The specified task.
- Returns:
Task address.
-
NRF_STATIC_INLINE void nrf_twis_event_clear(NRF_TWIS_Type *p_reg, nrf_twis_event_t event)
Function for clearing the specified event.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] The specified event.
-
NRF_STATIC_INLINE bool nrf_twis_event_check(NRF_TWIS_Type const *p_reg, nrf_twis_event_t event)
Function for retrieving the state of the TWIS event.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event to be checked.
- Return values:
true – The event has been generated.
false – The event has not been generated.
-
NRF_STATIC_INLINE bool nrf_twis_event_get_and_clear(NRF_TWIS_Type *p_reg, nrf_twis_event_t event)
Function for getting and clearing the state of the specified event.
This function checks the state of the event and clears it.
- Parameters:
p_reg – [inout] Pointer to the structure of registers of the peripheral.
event – [in] Event.
- Return values:
true – The event was set.
false – The event was not set.
-
NRF_STATIC_INLINE uint32_t nrf_twis_event_address_get(NRF_TWIS_Type const *p_reg, nrf_twis_event_t event)
Function for returning the address of the specified TWIS event register.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event.
- Returns:
Address.
-
NRF_STATIC_INLINE void nrf_twis_shorts_enable(NRF_TWIS_Type *p_reg, uint32_t mask)
Function for setting a shortcut.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of shortcuts to be enabled.
-
NRF_STATIC_INLINE void nrf_twis_shorts_disable(NRF_TWIS_Type *p_reg, uint32_t mask)
Function for clearing shortcuts.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of shortcuts to be disabled.
-
NRF_STATIC_INLINE uint32_t nrf_twis_shorts_get(NRF_TWIS_Type const *p_reg)
Function for getting the shorts mask.
Function returns shorts register.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Flags of currently enabled shortcuts
-
NRF_STATIC_INLINE void nrf_twis_int_enable(NRF_TWIS_Type *p_reg, uint32_t mask)
Function for enabling the specified interrupts.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be enabled.
-
NRF_STATIC_INLINE uint32_t nrf_twis_int_enable_check(NRF_TWIS_Type const *p_reg, uint32_t mask)
Function for checking if the specified interrupts are enabled.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be checked.
- Returns:
Mask of enabled interrupts.
-
NRF_STATIC_INLINE void nrf_twis_int_disable(NRF_TWIS_Type *p_reg, uint32_t mask)
Function for disabling the specified interrupts.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
mask – [in] Mask of interrupts to be disabled.
-
NRF_STATIC_INLINE void nrf_twis_subscribe_set(NRF_TWIS_Type *p_reg, nrf_twis_task_t task, uint8_t channel)
Function for setting the subscribe configuration for a given TWIS task.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task for which to set the configuration.
channel – [in] Channel through which to subscribe events.
-
NRF_STATIC_INLINE void nrf_twis_subscribe_clear(NRF_TWIS_Type *p_reg, nrf_twis_task_t task)
Function for clearing the subscribe configuration for a given TWIS task.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
task – [in] Task for which to clear the configuration.
-
NRF_STATIC_INLINE void nrf_twis_publish_set(NRF_TWIS_Type *p_reg, nrf_twis_event_t event, uint8_t channel)
Function for setting the publish configuration for a given TWIS event.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event for which to set the configuration.
channel – [in] Channel through which to publish the event.
-
NRF_STATIC_INLINE void nrf_twis_publish_clear(NRF_TWIS_Type *p_reg, nrf_twis_event_t event)
Function for clearing the publish configuration for a given TWIS event.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
event – [in] Event for which to clear the configuration.
-
NRF_STATIC_INLINE uint32_t nrf_twis_error_source_get_and_clear(NRF_TWIS_Type *p_reg)
Function for retrieving and clearing the TWIS error source.
- Attention
Error sources are cleared after read.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Error source mask with values from nrf_twis_error_t.
-
NRF_STATIC_INLINE uint_fast8_t nrf_twis_match_get(NRF_TWIS_Type const *p_reg)
Function for getting information about which of the addresses matched.
Function returns index in the address table that points to the address that already matched.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Index of matched address.
-
NRF_STATIC_INLINE void nrf_twis_enable(NRF_TWIS_Type *p_reg)
Function for enabling TWIS.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_STATIC_INLINE void nrf_twis_disable(NRF_TWIS_Type *p_reg)
Function for disabling TWIS.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_STATIC_INLINE void nrf_twis_pins_set(NRF_TWIS_Type *p_reg, uint32_t scl, uint32_t sda)
Function for configuring TWIS pins.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
scl – [in] SCL pin number.
sda – [in] SDA pin number.
-
NRF_STATIC_INLINE uint32_t nrf_twis_scl_pin_get(NRF_TWIS_Type const *p_reg)
Function for retrieving the SCL pin selection.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
SCL pin selection.
-
NRF_STATIC_INLINE uint32_t nrf_twis_sda_pin_get(NRF_TWIS_Type const *p_reg)
Function for retrieving the SDA pin selection.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
SDA pin selection.
-
NRF_STATIC_INLINE void nrf_twis_rx_buffer_set(NRF_TWIS_Type *p_reg, uint8_t *p_buf, size_t length)
Function for setting the receive buffer.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
p_buf – [in] Pointer to the buffer for received data.
length – [in] Maximum number of data bytes to receive.
-
NRF_STATIC_INLINE void nrf_twis_rx_prepare(NRF_TWIS_Type *p_reg, uint8_t *p_buf, size_t length)
Function that prepares TWIS for receiving.
This function sets receive buffer and then sets NRF_TWIS_TASK_PREPARERX task.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
p_buf – [in] Pointer to the buffer for received data.
length – [in] Maximum number of data bytes to receive.
-
NRF_STATIC_INLINE size_t nrf_twis_rx_amount_get(NRF_TWIS_Type const *p_reg)
Function for getting number of bytes received in the last transaction.
- Parameters:
p_reg – [in] TWIS instance.
- Returns:
Amount of bytes received.
-
NRF_STATIC_INLINE void nrf_twis_tx_buffer_set(NRF_TWIS_Type *p_reg, uint8_t const *p_buf, size_t length)
Function for setting the transmit buffer.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
p_buf – [in] Pointer to the buffer with data to send.
length – [in] Maximum number of data bytes to transmit.
-
NRF_STATIC_INLINE void nrf_twis_tx_prepare(NRF_TWIS_Type *p_reg, uint8_t const *p_buf, size_t length)
Function for preparing TWIS for transmitting.
This function sets transmit buffer and then sets NRF_TWIS_TASK_PREPARETX task.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
p_buf – [in] Pointer to the buffer with data to send.
length – [in] Maximum number of data bytes to transmit.
-
NRF_STATIC_INLINE size_t nrf_twis_tx_amount_get(NRF_TWIS_Type const *p_reg)
Function for getting the number of bytes transmitted in the last transaction.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Amount of bytes transmitted.
-
NRF_STATIC_INLINE void nrf_twis_address_set(NRF_TWIS_Type *p_reg, uint_fast8_t n, nrf_twis_address_t addr)
Function for setting the slave address.
Function sets the selected address for this TWI interface.
See also
See also
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
n – [in] Index of address to be set.
addr – [in] Addres to be set.
-
NRF_STATIC_INLINE nrf_twis_address_t nrf_twis_address_get(NRF_TWIS_Type const *p_reg, uint_fast8_t n)
Function for retrieving configured slave address.
Function gets the selected address for this TWI interface.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
n – [in] Index of address to get.
- Returns:
Configured slave address.
-
NRF_STATIC_INLINE void nrf_twis_config_address_set(NRF_TWIS_Type *p_reg, nrf_twis_config_addr_mask_t addr_mask)
Function for setting the device address configuration.
See also
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
addr_mask – [in] Mask of address indexes of what device should answer to.
-
NRF_STATIC_INLINE nrf_twis_config_addr_mask_t nrf_twis_config_address_get(NRF_TWIS_Type const *p_reg)
Function for retrieving the device address configuration.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Mask of address indexes of what device should answer to.
-
NRF_STATIC_INLINE void nrf_twis_orc_set(NRF_TWIS_Type *p_reg, uint8_t orc)
Function for setting the over-read character.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
orc – [in] Over-read character. Character clocked out in case of over-read of the TXD buffer.
-
NRF_STATIC_INLINE uint8_t nrf_twis_orc_get(NRF_TWIS_Type const *p_reg)
Function for setting the over-read character.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
- Returns:
Over-read character configured for selected instance.
-
NRF_STATIC_INLINE void nrf_twis_tx_list_enable(NRF_TWIS_Type *p_reg)
Function for enabling the TX list feature.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_STATIC_INLINE void nrf_twis_tx_list_disable(NRF_TWIS_Type *p_reg)
Function for disabling the TX list feature.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_STATIC_INLINE void nrf_twis_rx_list_enable(NRF_TWIS_Type *p_reg)
Function for enabling the RX list feature.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_STATIC_INLINE void nrf_twis_rx_list_disable(NRF_TWIS_Type *p_reg)
Function for disabling the RX list feature.
- Parameters:
p_reg – [in] Pointer to the structure of registers of the peripheral.
-
NRF_TWIS_INST_GET(idx)