Modules | |
nRF TWI Sensor module configuration | |
Data Structures | |
struct | nrf_twi_sensor_t |
Structure holding sensor instance. More... | |
struct | nrf_twi_sensor_read_cmd_t |
Struct describing sensor read command. More... | |
struct | nrf_twi_sensor_write_cmd_t |
Struct describing sensor write command. More... | |
union | nrf_twi_sensor_cmd_t |
Union for sensor commands. Needed in buffer definition. More... | |
Macros | |
#define | NRF_TWI_SENSOR_SEND_BUF_SIZE 16 |
Internal write operation buffer length. More... | |
#define | NRF_TWI_SENSOR_DEF(twi_sensor_name, p_nrf_twi_mngr, msg_buff_size) |
Macro creating common twi sensor instance. More... | |
#define | NRF_TWI_SENSOR_READ(p_reg_addr, p_buffer, byte_cnt) |
Macro for defining TWI manager read transfer. More... | |
#define | NRF_TWI_SENSOR_WRITE(p_buffer, byte_cnt) NRF_TWI_MNGR_WRITE(0x00, p_buffer, byte_cnt, 0) |
Macro for defining TWI manager write transfer. More... | |
#define | NRF_TWI_SENSOR_ADDRESS_SET(_transfers, _sensor_addr) |
Macro for assigning sensor address to transfers. More... | |
#define | NRF_TWI_SENSOR_REG_SET(_register, _msk, _pos, _val) |
Macro for setting parameters in sensor register. More... | |
#define | NRF_TWI_SENSOR_REG_VAL_GET(_register, _msk, _pos) (((_register) & (_msk)) >> (_pos)) |
Macro for getting parameters from sensor register. More... | |
Typedefs | |
typedef void(* | nrf_twi_sensor_reg_cb_t )(ret_code_t result, void *p_register_data) |
Register read callback prototype. More... | |
Functions | |
ret_code_t | nrf_twi_sensor_init (nrf_twi_sensor_t *p_twi_sensor) |
Function for initialization of sensor common instance. More... | |
ret_code_t | nrf_twi_sensor_reg_read (nrf_twi_sensor_t const *p_instance, uint8_t sensor_addr, uint8_t reg_address, nrf_twi_sensor_reg_cb_t user_cb, uint8_t *p_data, uint8_t length) |
Function for reading sensor register. More... | |
ret_code_t | nrf_twi_sensor_write (nrf_twi_sensor_t const *p_instance, uint8_t sensor_addr, uint8_t const *p_data, uint8_t length, bool copy_flag) |
Function for writing to sensor. More... | |
ret_code_t | nrf_twi_sensor_reg_write (nrf_twi_sensor_t const *p_instance, uint8_t sensor_addr, uint8_t reg_address, uint8_t *p_data, uint8_t length) |
Function for writing to sensor register. More... | |
__STATIC_INLINE uint8_t | nrf_twi_sensor_max_util_get (nrf_twi_sensor_t const *p_twi_sensor) |
Function for getting maximum utilization of sensor buffer. More... | |
#define NRF_TWI_SENSOR_ADDRESS_SET | ( | _transfers, | |
_sensor_addr | |||
) |
Macro for assigning sensor address to transfers.
[in] | _transfers | Transfers array. |
[in] | _sensor_addr | Desired sensor address. |
#define NRF_TWI_SENSOR_DEF | ( | twi_sensor_name, | |
p_nrf_twi_mngr, | |||
msg_buff_size | |||
) |
Macro creating common twi sensor instance.
Data in structure is used for basic communication with sensors. THere should be one instance per TWI bus.
[in] | twi_sensor_name | TWI common sensor instance name. |
[in] | p_nrf_twi_mngr | Pointer to TWI Manager instance. NRF_TWI_MNGR_DEF |
[in] | msg_buff_size | Size of buffer used in communication |
#define NRF_TWI_SENSOR_READ | ( | p_reg_addr, | |
p_buffer, | |||
byte_cnt | |||
) |
Macro for defining TWI manager read transfer.
#define NRF_TWI_SENSOR_REG_SET | ( | _register, | |
_msk, | |||
_pos, | |||
_val | |||
) |
Macro for setting parameters in sensor register.
[in,out] | _register | Register to be altered. |
[in] | _msk | Parameter mask. |
[in] | _pos | Parameter position. |
[in] | _val | Parameter value to be set. |
#define NRF_TWI_SENSOR_REG_VAL_GET | ( | _register, | |
_msk, | |||
_pos | |||
) | (((_register) & (_msk)) >> (_pos)) |
Macro for getting parameters from sensor register.
[in] | _register | Register to be processed. |
[in] | _msk | Parameter mask. |
[in] | _pos | Parameter position. |
#define NRF_TWI_SENSOR_SEND_BUF_SIZE 16 |
Internal write operation buffer length.
Defines how many bytes can be stored internally. 16 bytes were selected so that nrf_twi_sensor_write_cmd_t size matches nrf_twi_sensor_read_cmd_t size.
#define NRF_TWI_SENSOR_WRITE | ( | p_buffer, | |
byte_cnt | |||
) | NRF_TWI_MNGR_WRITE(0x00, p_buffer, byte_cnt, 0) |
Macro for defining TWI manager write transfer.
typedef void(* nrf_twi_sensor_reg_cb_t)(ret_code_t result, void *p_register_data) |
Register read callback prototype.
[in] | result | Return error code from TWI manager and underlying drivers. |
[in] | p_register_data | Pointer to register value. |
ret_code_t nrf_twi_sensor_init | ( | nrf_twi_sensor_t * | p_twi_sensor | ) |
Function for initialization of sensor common instance.
[in] | p_twi_sensor | Pointer to sensor common instance. |
__STATIC_INLINE uint8_t nrf_twi_sensor_max_util_get | ( | nrf_twi_sensor_t const * | p_twi_sensor | ) |
Function for getting maximum utilization of sensor buffer.
[in] | p_twi_sensor | Pointer to sensor buffer. |
ret_code_t nrf_twi_sensor_reg_read | ( | nrf_twi_sensor_t const * | p_instance, |
uint8_t | sensor_addr, | ||
uint8_t | reg_address, | ||
nrf_twi_sensor_reg_cb_t | user_cb, | ||
uint8_t * | p_data, | ||
uint8_t | length | ||
) |
Function for reading sensor register.
[in] | p_instance | Pointer to sensor instance. |
[in] | sensor_addr | Sensor address. |
[in] | reg_address | Register address. |
[in] | user_cb | User callback. |
[out] | p_data | Pointer to data save location. |
[in] | length | Number of bytes to read. |
NRF_ERROR_NO_MEM | If there is no memory in sensor buffer |
NRF_SUCCESS | If the operation was successful. |
other | Error code from TWI manager nrf_twi_mngr_schedule. |
ret_code_t nrf_twi_sensor_reg_write | ( | nrf_twi_sensor_t const * | p_instance, |
uint8_t | sensor_addr, | ||
uint8_t | reg_address, | ||
uint8_t * | p_data, | ||
uint8_t | length | ||
) |
Function for writing to sensor register.
[in] | p_instance | Pointer to sensor instance. |
[in] | sensor_addr | Sensor address. |
[in] | reg_address | Register address. |
[in] | p_data | Pointer to data to be written. |
[in] | length | Number of bytes to write. |
NRF_ERROR_NO_MEM | If there is no memory in sensor buffer |
NRF_ERROR_INVALID_LENGTH | If trying to copy more bytes than NRF_TWI_SENSOR_SEND_BUF_SIZE - 1. One byte reserved for register address. |
NRF_SUCCESS | If the operation was successful. |
other | Error code from TWI manager nrf_twi_mngr_schedule. |
ret_code_t nrf_twi_sensor_write | ( | nrf_twi_sensor_t const * | p_instance, |
uint8_t | sensor_addr, | ||
uint8_t const * | p_data, | ||
uint8_t | length, | ||
bool | copy_flag | ||
) |
Function for writing to sensor.
[in] | p_instance | Pointer to sensor instance. |
[in] | sensor_addr | Sensor address. |
[in] | p_data | Pointer to data to be written. |
[in] | length | Number of bytes to write. |
[in] | copy_flag | If true, p_data is copied into internal static buffer. |
NRF_ERROR_NO_MEM | If there is no memory in sensor buffer |
NRF_ERROR_INVALID_LENGTH | If trying to copy more bytes than NRF_TWI_SENSOR_SEND_BUF_SIZE. |
NRF_SUCCESS | If the operation was successful. |
other | Error code from TWI manager nrf_twi_mngr_schedule. |