Two Wire Slave interface (TWIS) peripheral driver. More...
Modules | |
TWIS peripheral driver configuration | |
Data Structures | |
struct | nrfx_twis_t |
TWIS driver instance data structure. More... | |
struct | nrfx_twis_evt_t |
TWIS driver event structure. More... | |
struct | nrfx_twis_config_t |
Structure for TWIS configuration. More... | |
Macros | |
#define | NRFX_TWIS_INSTANCE(id) |
Macro for creating a TWIS driver instance. More... | |
#define | NRFX_TWIS_DEFAULT_CONFIG |
Generate default configuration for TWIS driver instance. More... | |
Typedefs | |
typedef void(* | nrfx_twis_event_handler_t )(nrfx_twis_evt_t const *p_event) |
TWI slave event callback function type. More... | |
Enumerations | |
enum | { NRFX_TWIS_ENABLED_COUNT } |
enum | nrfx_twis_evt_type_t { NRFX_TWIS_EVT_READ_REQ, NRFX_TWIS_EVT_READ_DONE, NRFX_TWIS_EVT_READ_ERROR, NRFX_TWIS_EVT_WRITE_REQ, NRFX_TWIS_EVT_WRITE_DONE, NRFX_TWIS_EVT_WRITE_ERROR, NRFX_TWIS_EVT_GENERAL_ERROR } |
Event callback function event definitions. More... | |
enum | nrfx_twis_error_t { NRFX_TWIS_ERROR_OVERFLOW = NRF_TWIS_ERROR_OVERFLOW, NRFX_TWIS_ERROR_DATA_NACK = NRF_TWIS_ERROR_DATA_NACK, NRFX_TWIS_ERROR_OVERREAD = NRF_TWIS_ERROR_OVERREAD, NRFX_TWIS_ERROR_UNEXPECTED_EVENT = 1 << 8 } |
Possible error sources. More... | |
Functions | |
nrfx_err_t | nrfx_twis_init (nrfx_twis_t const *p_instance, nrfx_twis_config_t const *p_config, nrfx_twis_event_handler_t event_handler) |
Function for initializing the TWIS driver instance. More... | |
void | nrfx_twis_uninit (nrfx_twis_t const *p_instance) |
Function for uninitializing the TWIS driver instance. More... | |
void | nrfx_twis_enable (nrfx_twis_t const *p_instance) |
Enable TWIS instance. More... | |
void | nrfx_twis_disable (nrfx_twis_t const *p_instance) |
Disable TWIS instance. More... | |
uint32_t | nrfx_twis_error_get_and_clear (nrfx_twis_t const *p_instance) |
Get and clear last error flags. More... | |
nrfx_err_t | nrfx_twis_tx_prepare (nrfx_twis_t const *p_instance, void const *p_buf, size_t size) |
Prepare data for sending. More... | |
__STATIC_INLINE size_t | nrfx_twis_tx_amount (nrfx_twis_t const *p_instance) |
Get number of transmitted bytes. More... | |
nrfx_err_t | nrfx_twis_rx_prepare (nrfx_twis_t const *p_instance, void *p_buf, size_t size) |
Prepare data for receiving. More... | |
__STATIC_INLINE size_t | nrfx_twis_rx_amount (nrfx_twis_t const *p_instance) |
Get number of received bytes. More... | |
bool | nrfx_twis_is_busy (nrfx_twis_t const *p_instance) |
Function checks if driver is busy right now. More... | |
bool | nrfx_twis_is_waiting_tx_buff (nrfx_twis_t const *p_instance) |
Function checks if driver is waiting for tx buffer. More... | |
bool | nrfx_twis_is_waiting_rx_buff (nrfx_twis_t const *p_instance) |
Function checks if driver is waiting for rx buffer. More... | |
bool | nrfx_twis_is_pending_tx (nrfx_twis_t const *p_instance) |
Check if driver is sending data. More... | |
bool | nrfx_twis_is_pending_rx (nrfx_twis_t const *p_instance) |
Check if driver is receiving data. More... | |
void | nrfx_twis_0_irq_handler (void) |
void | nrfx_twis_1_irq_handler (void) |
Two Wire Slave interface (TWIS) peripheral driver.
#define NRFX_TWIS_DEFAULT_CONFIG |
Generate default configuration for TWIS driver instance.
#define NRFX_TWIS_INSTANCE | ( | id | ) |
Macro for creating a TWIS driver instance.
typedef void(* nrfx_twis_event_handler_t)(nrfx_twis_evt_t const *p_event) |
TWI slave event callback function type.
[in] | p_event | Event information structure. |
enum nrfx_twis_error_t |
Possible error sources.
This is flag enum - values from this enum can be connected using logical or operator.
enum nrfx_twis_evt_type_t |
Event callback function event definitions.
Enumerator | |
---|---|
NRFX_TWIS_EVT_READ_REQ |
Read request detected. If there is no buffer prepared, buf_req flag in the even will be set. Call then nrfx_twis_tx_prepare to give parameters for buffer. |
NRFX_TWIS_EVT_READ_DONE |
Read request has finished - free any data. |
NRFX_TWIS_EVT_READ_ERROR |
Read request finished with error. |
NRFX_TWIS_EVT_WRITE_REQ |
Write request detected. If there is no buffer prepared, buf_req flag in the even will be set. Call then nrfx_twis_rx_prepare to give parameters for buffer. |
NRFX_TWIS_EVT_WRITE_DONE |
Write request has finished - process data. |
NRFX_TWIS_EVT_WRITE_ERROR |
Write request finished with error. |
NRFX_TWIS_EVT_GENERAL_ERROR |
Error that happens not inside WRITE or READ transaction. |
void nrfx_twis_disable | ( | nrfx_twis_t const * | p_instance | ) |
Disable TWIS instance.
Disabling TWIS instance gives possibility to turn off the TWIS while holding configuration done by nrfx_twis_init.
p_instance | Pointer to the driver instance structure. |
void nrfx_twis_enable | ( | nrfx_twis_t const * | p_instance | ) |
Enable TWIS instance.
This function enables TWIS instance. Function defined if there is needs for dynamically enabling and disabling the peripheral. Use nrfx_twis_enable and nrfx_twis_disable functions. They do not change any configuration registers.
p_instance | Pointer to the driver instance structure. |
uint32_t nrfx_twis_error_get_and_clear | ( | nrfx_twis_t const * | p_instance | ) |
Get and clear last error flags.
Function gets information about errors. This is also the only possibility to exit from error substate of the internal state machine.
[in] | p_instance | Pointer to the driver instance structure. |
nrfx_err_t nrfx_twis_init | ( | nrfx_twis_t const * | p_instance, |
nrfx_twis_config_t const * | p_config, | ||
nrfx_twis_event_handler_t | event_handler | ||
) |
Function for initializing the TWIS driver instance.
Function initializes and enables TWIS driver.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_config | Pointer to the structure with initial configuration. |
[in] | event_handler | Event handler provided by the user. |
NRFX_SUCCESS | If initialization was successful. |
NRFX_ERROR_INVALID_STATE | If the driver is already initialized. |
NRFX_ERROR_BUSY | If some other peripheral with the same instance ID is already in use. This is possible only if NRFX_PRS_ENABLED is set to a value other than zero. |
bool nrfx_twis_is_busy | ( | nrfx_twis_t const * | p_instance | ) |
Function checks if driver is busy right now.
Actual driver substate is tested. If driver is in any other state than IDLE or ERROR this function returns true.
[in] | p_instance | Pointer to the driver instance structure. |
true | Driver is in state other than ERROR or IDLE. |
false | There is no transmission pending. |
bool nrfx_twis_is_pending_rx | ( | nrfx_twis_t const * | p_instance | ) |
Check if driver is receiving data.
If this function returns true, it means that there is ongoing input transmission.
[in] | p_instance | Pointer to the driver instance structure. |
true | There is ongoing input transmission. |
false | Driver is in other state. |
bool nrfx_twis_is_pending_tx | ( | nrfx_twis_t const * | p_instance | ) |
Check if driver is sending data.
If this function returns true, it means that there is ongoing output transmission.
[in] | p_instance | Pointer to the driver instance structure. |
true | There is ongoing output transmission. |
false | Driver is in other state. |
bool nrfx_twis_is_waiting_rx_buff | ( | nrfx_twis_t const * | p_instance | ) |
Function checks if driver is waiting for rx buffer.
If this function returns true, it means that driver is staled expecting of the nrfx_twis_rx_prepare function call.
[in] | p_instance | Pointer to the driver instance structure. |
true | Driver waits for nrfx_twis_rx_prepare. |
false | Driver is not in the state where it waits for preparing rx buffer. |
bool nrfx_twis_is_waiting_tx_buff | ( | nrfx_twis_t const * | p_instance | ) |
Function checks if driver is waiting for tx buffer.
If this function returns true, it means that driver is stalled expecting of the nrfx_twis_tx_prepare function call.
[in] | p_instance | Pointer to the driver instance structure. |
true | Driver waits for nrfx_twis_tx_prepare. |
false | Driver is not in the state where it waits for preparing tx buffer. |
__STATIC_INLINE size_t nrfx_twis_rx_amount | ( | nrfx_twis_t const * | p_instance | ) |
Get number of received bytes.
Function returns number of bytes received. This function may be called after NRFX_TWIS_EVT_WRITE_DONE or NRFX_TWIS_EVT_WRITE_ERROR events.
[in] | p_instance | Pointer to the driver instance structure. |
nrfx_err_t nrfx_twis_rx_prepare | ( | nrfx_twis_t const * | p_instance, |
void * | p_buf, | ||
size_t | size | ||
) |
Prepare data for receiving.
This function should be used in response for NRFX_TWIS_EVT_WRITE_REQ event.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_buf | Buffer that would be filled with received data. |
size | Size of the buffer (maximum amount of data to receive). |
NRFX_SUCCESS | Preparation finished properly. |
NRFX_ERROR_INVALID_ADDR | Given p_buf is not placed inside the RAM. |
NRFX_ERROR_INVALID_LENGTH | Wrong value in size parameter. |
NRFX_ERROR_INVALID_STATE | Module not initialized or not enabled. |
__STATIC_INLINE size_t nrfx_twis_tx_amount | ( | nrfx_twis_t const * | p_instance | ) |
Get number of transmitted bytes.
Function returns number of bytes sent. This function may be called after NRFX_TWIS_EVT_READ_DONE or NRFX_TWIS_EVT_READ_ERROR events.
[in] | p_instance | Pointer to the driver instance structure. |
nrfx_err_t nrfx_twis_tx_prepare | ( | nrfx_twis_t const * | p_instance, |
void const * | p_buf, | ||
size_t | size | ||
) |
Prepare data for sending.
This function should be used in response for NRFX_TWIS_EVT_READ_REQ event.
[in] | p_instance | Pointer to the driver instance structure. |
[in] | p_buf | Transmission buffer. |
size | Maximum number of bytes that master may read from buffer given. |
NRFX_SUCCESS | Preparation finished properly. |
NRFX_ERROR_INVALID_ADDR | Given p_buf is not placed inside the RAM. |
NRFX_ERROR_INVALID_LENGTH | Wrong value in size parameter. |
NRFX_ERROR_INVALID_STATE | Module not initialized or not enabled. |
void nrfx_twis_uninit | ( | nrfx_twis_t const * | p_instance | ) |
Function for uninitializing the TWIS driver instance.
Function initializes the peripheral and resets all registers to default values.
[in] | p_instance | Pointer to the driver instance structure. |