Appiko
hal_twim.h
1 
30 #ifndef CODEBASE_HAL_HAL_TWIM_H_
31 #define CODEBASE_HAL_HAL_TWIM_H_
32 
33 #include "nrf.h"
34 
35 #ifdef NRF51
36 #error TWIM peripheral is not present in the nRF51 SoC
37 #endif
38 
39 #if SYS_CFG_PRESENT == 1
40 #include "sys_config.h"
41 #endif
42 #ifndef HAL_TWIM_PERIPH_USED
43 #define HAL_TWIM_PERIPH_USED 0
44 #endif
45 
46 
48 #define TWIM_USED HAL_TWIM_PERIPH_USED
49 
52 typedef enum
53 {
54  HAL_TWI_FREQ_100K = TWI_FREQUENCY_FREQUENCY_K100,
55  HAL_TWI_FREQ_250K = TWI_FREQUENCY_FREQUENCY_K250,
56  HAL_TWI_FREQ_400K = TWI_FREQUENCY_FREQUENCY_K400
58 
61 typedef enum {
66 
69 typedef enum {
73 } twim_err_t;
74 
77 typedef enum {
82 
87 #define TWIM_TX_DONE_MSK (1<<TWIM_TX)
88 #define TWIM_RX_DONE_MSK (1<<TWIM_RX)
89 #define TWIM_TX_RX_DONE_MSK (1<<TWIM_TX_RX)
90 
94 typedef struct
95 {
96  uint32_t scl;
97  uint32_t sda;
99  uint32_t irq_priority;
100  uint32_t address;
101  void (*evt_handler)(twim_err_t evt, twim_transfer_t transfer);
106  uint32_t evt_mask;
108 
116 
120 void hal_twim_uninit(void);
121 
128 twim_ret_status hal_twim_tx(uint8_t * tx_ptr, uint32_t tx_len);
129 
136 twim_ret_status hal_twim_rx(uint8_t * rx_ptr, uint32_t rx_len);
137 
146 twim_ret_status hal_twim_tx_rx(uint8_t * tx_ptr, uint32_t tx_len,
147  uint8_t * rx_ptr, uint32_t rx_len);
148 
153 uint32_t hal_twim_get_current_adrs(void);
154 
155 #endif /* CODEBASE_HAL_HAL_TWIM_H_ */
156 
uint32_t irq_priority
Interrupt priority.
Definition: hal_twim.h:99
uint32_t evt_mask
Event Mask for specifying which successful transfer type calls the handler.
Definition: hal_twim.h:106
hal_twim_freq_t frequency
TWI frequency.
Definition: hal_twim.h:98
twim_ret_status hal_twim_rx(uint8_t *rx_ptr, uint32_t rx_len)
Start a Rx only TWI transfer.
Definition: hal_twim.c:210
The TWIM peripheral is not initialized.
Definition: hal_twim.h:80
The slave device generated an error on the data bytes.
Definition: hal_twim.h:72
twim_transfer_t
Defines for the types of transfers possible.
Definition: hal_twim.h:61
uint32_t hal_twim_get_current_adrs(void)
Get the current specified address of the I2C slave.
Definition: hal_twim.c:266
100 kbps
Definition: hal_twim.h:54
250 kbps
Definition: hal_twim.h:55
Only a Tx transfer.
Definition: hal_twim.h:62
hal_twim_freq_t
Defines for TWI master clock frequency.
Definition: hal_twim.h:52
The slave device generated an error on the address bytes.
Definition: hal_twim.h:71
void hal_twim_uninit(void)
Function for uninitializing and disabling one of the TWIM peripheral.
Definition: hal_twim.c:136
400 kbps
Definition: hal_twim.h:56
twim_err_t
Defines for the types of errors possible during TWI transactions.
Definition: hal_twim.h:69
A Tx transfer followed by Rx with a repeated start.
Definition: hal_twim.h:64
twim_ret_status
Defines for the return values for the transfer calls.
Definition: hal_twim.h:77
No error for this transfer.
Definition: hal_twim.h:70
Only a Rx transfer.
Definition: hal_twim.h:63
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.
Definition: hal_twim.c:236
A transfer is already happening.
Definition: hal_twim.h:79
Transfer successfully started.
Definition: hal_twim.h:78
Structure for the TWI master driver initialization.
Definition: hal_twim.h:94
uint32_t scl
SCL pin number.
Definition: hal_twim.h:96
uint32_t sda
SDA pin number.
Definition: hal_twim.h:97
void hal_twim_init(hal_twim_init_config_t *config)
Function for initializing and enabling one of the TWIM peripheral.
Definition: hal_twim.c:100
twim_ret_status hal_twim_tx(uint8_t *tx_ptr, uint32_t tx_len)
Start a Tx only TWI transfer.
Definition: hal_twim.c:184