Appiko
Data Structures | Macros | Enumerations | Functions

Hardware abstraction layer of the Two Wire Interface in Master mode. This driver is completely event driven and non-blocking, suitable for low power applications. More...

Data Structures

struct  hal_twim_init_config_t
 Structure for the TWI master driver initialization. More...
 

Macros

#define TWIM_USED   HAL_TWIM_PERIPH_USED
 

Enumerations

enum  hal_twim_freq_t { HAL_TWI_FREQ_100K = TWI_FREQUENCY_FREQUENCY_K100, HAL_TWI_FREQ_250K = TWI_FREQUENCY_FREQUENCY_K250, HAL_TWI_FREQ_400K = TWI_FREQUENCY_FREQUENCY_K400 }
 Defines for TWI master clock frequency. More...
 
enum  twim_transfer_t { TWIM_TX, TWIM_RX, TWIM_TX_RX }
 Defines for the types of transfers possible. More...
 
enum  twim_err_t { TWIM_ERR_NONE, TWIM_ERR_ADRS_NACK, TWIM_ERR_DATA_NACK }
 Defines for the types of errors possible during TWI transactions. More...
 
enum  twim_ret_status { TWIM_STARTED, TWIM_BUSY, TWIM_UNINIT }
 Defines for the return values for the transfer calls. More...
 

Functions

void hal_twim_init (hal_twim_init_config_t *config)
 Function for initializing and enabling one of the TWIM peripheral. More...
 
void hal_twim_uninit (void)
 Function for uninitializing and disabling one of the TWIM peripheral.
 
twim_ret_status hal_twim_tx (uint8_t *tx_ptr, uint32_t tx_len)
 Start a Tx only TWI transfer. More...
 
twim_ret_status hal_twim_rx (uint8_t *rx_ptr, uint32_t rx_len)
 Start a Rx only TWI transfer. More...
 
twim_ret_status hal_twim_tx_rx (uint8_t *tx_ptr, uint32_t tx_len, uint8_t *rx_ptr, uint32_t rx_len)
 Start a Tx TWI transfer followed by a Rx by repeated start. More...
 
uint32_t hal_twim_get_current_adrs (void)
 Get the current specified address of the I2C slave. More...
 

Masks for specifying which events calls the handler. These need to be

ORed to enable multiple events' handlers to be called.

#define TWIM_TX_DONE_MSK   (1<<TWIM_TX)
 
#define TWIM_RX_DONE_MSK   (1<<TWIM_RX)
 
#define TWIM_TX_RX_DONE_MSK   (1<<TWIM_TX_RX)
 

Detailed Description

Macro Definition Documentation

◆ TWIM_USED

#define TWIM_USED   HAL_TWIM_PERIPH_USED

Specify which TWIM peripheral is used for this HAL module

Definition at line 48 of file hal_twim.h.

Enumeration Type Documentation

◆ hal_twim_freq_t

Enumerator
HAL_TWI_FREQ_100K 

100 kbps

HAL_TWI_FREQ_250K 

250 kbps

HAL_TWI_FREQ_400K 

400 kbps

Definition at line 52 of file hal_twim.h.

◆ twim_err_t

enum twim_err_t
Enumerator
TWIM_ERR_NONE 

No error for this transfer.

TWIM_ERR_ADRS_NACK 

The slave device generated an error on the address bytes.

TWIM_ERR_DATA_NACK 

The slave device generated an error on the data bytes.

Definition at line 69 of file hal_twim.h.

◆ twim_ret_status

Enumerator
TWIM_STARTED 

Transfer successfully started.

TWIM_BUSY 

A transfer is already happening.

TWIM_UNINIT 

The TWIM peripheral is not initialized.

Definition at line 77 of file hal_twim.h.

◆ twim_transfer_t

Enumerator
TWIM_TX 

Only a Tx transfer.

TWIM_RX 

Only a Rx transfer.

TWIM_TX_RX 

A Tx transfer followed by Rx with a repeated start.

Definition at line 61 of file hal_twim.h.

Function Documentation

◆ hal_twim_get_current_adrs()

uint32_t hal_twim_get_current_adrs ( void  )
Returns
The I2C address currently initialized in the driver

Definition at line 266 of file hal_twim.c.

◆ hal_twim_init()

void hal_twim_init ( hal_twim_init_config_t config)
Parameters
configPointer to the initialization configuration parameters
Warning
The evt_handler in hal_twim_init_config_t should be initialized to a function pointer and must not be NULL.

Definition at line 100 of file hal_twim.c.

References hal_twim_init_config_t::address, hal_twim_init_config_t::evt_handler, hal_twim_init_config_t::evt_mask, hal_twim_init_config_t::frequency, hal_twim_init_config_t::irq_priority, hal_twim_init_config_t::scl, and hal_twim_init_config_t::sda.

◆ hal_twim_rx()

twim_ret_status hal_twim_rx ( uint8_t *  rx_ptr,
uint32_t  rx_len 
)
Parameters
rx_ptrPointer to the data to be received
rx_lenLength of the data to be received
Returns
Status of the transfer as per twim_ret_status

Definition at line 210 of file hal_twim.c.

References TWIM_RX, and TWIM_STARTED.

◆ hal_twim_tx()

twim_ret_status hal_twim_tx ( uint8_t *  tx_ptr,
uint32_t  tx_len 
)
Parameters
tx_ptrPointer to the data to be transferred
tx_lenLength of the data to be transferred
Returns
Status of the transfer as per twim_ret_status

Definition at line 184 of file hal_twim.c.

References TWIM_STARTED, and TWIM_TX.

◆ hal_twim_tx_rx()

twim_ret_status hal_twim_tx_rx ( uint8_t *  tx_ptr,
uint32_t  tx_len,
uint8_t *  rx_ptr,
uint32_t  rx_len 
)
Parameters
tx_ptrPointer to the data to be transferred
tx_lenLength of the data to be transferred
rx_ptrPointer to the data to be received
rx_lenLength of the data to be received
Returns
Status of the transfer as per twim_ret_status

Definition at line 236 of file hal_twim.c.

References TWIM_STARTED, and TWIM_TX_RX.