Module for scheduling TWI transactions.
More...
|
#define | APP_TWI_NO_STOP 0x01 |
| Flag indicating that a given transfer should not be ended with a stop condition. More...
|
|
#define | APP_TWI_WRITE(address, p_data, length, flags) APP_TWI_TRANSFER(APP_TWI_WRITE_OP(address), p_data, length, flags) |
| Macro for creating a write transfer. More...
|
|
#define | APP_TWI_READ(address, p_data, length, flags) APP_TWI_TRANSFER(APP_TWI_READ_OP(address), p_data, length, flags) |
| Macro for creating a read transfer. More...
|
|
#define | APP_TWI_TRANSFER(_operation, _p_data, _length, _flags) |
| Helper macro, should not be used directly. More...
|
|
#define | APP_TWI_WRITE_OP(address) (((address) << 1) | 0) |
| Helper macro, should not be used directly.
|
|
#define | APP_TWI_READ_OP(address) (((address) << 1) | 1) |
| Helper macro, should not be used directly.
|
|
#define | APP_TWI_IS_READ_OP(operation) ((operation) & 1) |
| Helper macro, should not be used directly.
|
|
#define | APP_TWI_OP_ADDRESS(operation) ((operation) >> 1) |
| Helper macro, should not be used directly.
|
|
#define | APP_TWI_DEF(_app_twi_name, _queue_size, _twi_idx) |
| Macro that simplifies defining a TWI transaction manager instance. More...
|
|
Module for scheduling TWI transactions.
#define APP_TWI_DEF |
( |
|
_app_twi_name, |
|
|
|
_queue_size, |
|
|
|
_twi_idx |
|
) |
| |
Value:
_app_twi_name##_queue, \
(_queue_size), \
{ \
.p_queue = &_app_twi_name##_queue, \
}
Macro that simplifies defining a TWI transaction manager instance.
This macro allocates a static buffer for the transaction queue. Therefore, it should be used in only one place in the code for a given instance.
- Note
- The queue size is the maximum number of pending transactions not counting the one that is currently realized. This means that for an empty queue with size of, for example, 4 elements, it is possible to schedule up to 5 transactions.
- Parameters
-
[in] | _app_twi_name | Name of instance to be created. |
[in] | _queue_size | Size of the transaction queue (maximum number of pending transactions). |
[in] | _twi_idx | Index of hardware TWI instance to be used. |
#define APP_TWI_NO_STOP 0x01 |
Flag indicating that a given transfer should not be ended with a stop condition.
Use this flag when a stop condition is undesirable between two transfers, for example, when the first transfer is a write that sets an address in the slave device and the second one is a read that fetches certain data using this address. In this case, the second transfer should follow directly after the first transfer, with a repeated start condition instead of a stop and then a new start condition.
Macro for creating a read transfer.
- Parameters
-
| address | Slave address. |
[in] | p_data | Pointer to the buffer where received data should be placed. |
| length | Number of bytes to transfer. |
| flags | Transfer flags (see APP_TWI_NO_STOP). |
#define APP_TWI_TRANSFER |
( |
|
_operation, |
|
|
|
_p_data, |
|
|
|
_length, |
|
|
|
_flags |
|
) |
| |
Value:{ \
.p_data = (uint8_t *)(_p_data), \
.length = _length, \
.operation = _operation, \
.flags = _flags \
}
Helper macro, should not be used directly.
Macro for creating a write transfer.
- Parameters
-
[in] | address | Slave address. |
[in] | p_data | Pointer to the data to be sent. |
[in] | length | Number of bytes to transfer. |
[in] | flags | Transfer flags (see APP_TWI_NO_STOP). |
typedef void(* app_twi_callback_t)(ret_code_t result, void *p_user_data) |
TWI transaction callback prototype.
- Parameters
-
| result | Result of operation (NRF_SUCCESS on success, otherwise a relevant error code). |
[in] | p_user_data | Pointer to user data defined in transaction descriptor. |
Function for initializing a TWI transaction manager instance.
- Parameters
-
[in] | p_app_twi | Pointer to the instance to be initialized. |
[in] | p_default_twi_config | Pointer to the TWI master driver configuration. This configuration will be used whenever the scheduled transaction will have p_twi_configuration set to NULL value. |
- Returns
- Values returned by the nrf_drv_twi_init function.
__STATIC_INLINE bool app_twi_is_idle |
( |
app_twi_t const * |
p_app_twi | ) |
|
Function for getting the current state of a TWI transaction manager instance.
- Parameters
-
[in] | p_app_twi | Pointer to the TWI transaction manager instance. |
- Return values
-
true | If all scheduled transactions have been finished. |
false | Otherwise. |
Function for scheduling a transaction and waiting until it is finished.
This function schedules a transaction that consists of one or more transfers and waits until it is finished.
- Parameters
-
[in] | p_app_twi | Pointer to the TWI transaction manager instance. |
[in] | p_transfers | Pointer to an array of transfers to be performed. |
| number_of_transfers | Number of transfers to be performed. |
| user_function | User-specified function to be called while waiting. NULL if such functionality is not needed. |
- Return values
-
NRF_SUCCESS | If the transfers have been successfully realized. |
NRF_ERROR_BUSY | If some transfers are already being performed. |
- | Other error codes mean that the transaction has ended with the error that is specified in the error code. |
void app_twi_uninit |
( |
app_twi_t const * |
p_app_twi | ) |
|
Function for uninitializing a TWI transaction manager instance.
- Parameters
-
[in] | p_app_twi | Pointer to the instance to be uninitialized. |