|
SmartSnippets DA1459x SDK
|
Go to the documentation of this file.
46 #if dg_configUSE_HW_I2C
58 #define HW_I2C_DMA_SUPPORT dg_configI2C_DMA_SUPPORT
60 #if HW_I2C_DMA_SUPPORT
70 #ifndef HW_I2C_SLAVE_SUPPORT
71 #define HW_I2C_SLAVE_SUPPORT ( 1 )
75 #define IBA(id) ((I2C_Type *)id)
81 #define I2C_FIFO_DEPTH (4)
90 #define I2C_SETUP(id, seq) \
101 #define HW_I2C1 ((void *)I2C_BASE)
103 #define HW_I2C2 ((void *)I2C2_BASE)
106 #define HW_I2C3 ((void *)I2C3_BASE)
108 typedef void * HW_I2C_ID;
113 #define HW_I2C_F_NONE 0x00000000
114 #define HW_I2C_F_WAIT_FOR_STOP 0x00000001
115 #define HW_I2C_F_ADD_STOP 0x00000002
116 #define HW_I2C_F_ADD_RESTART 0x00000004
131 #define HW_I2C_I2C1_MADDR 0x01
133 #define HW_I2C_I2C2_MADDR 0x05
136 #define HW_I2C_I2C3_MADDR 0x07
189 #if (HW_I2C_SLAVE_SUPPORT == 1)
224 #if (HW_I2C_DMA_SUPPORT == 1)
230 HW_I2C_DMA_TRANSFER_WRITE,
231 HW_I2C_DMA_TRANSFER_MASTER_READ,
232 #if (HW_I2C_SLAVE_SUPPORT == 1)
233 HW_I2C_DMA_TRANSFER_SLAVE_READ,
267 #if (HW_I2C_SLAVE_SUPPORT == 1)
297 #if (HW_I2C_SLAVE_SUPPORT == 1)
300 #if (HW_I2C_DMA_SUPPORT == 1)
316 #define HW_I2C_REG_SETF(id, reg, field, val) \
317 IBA(id)->reg##_REG = ((IBA(id)->reg##_REG & ~(I2C_##reg##_REG_##field##_Msk)) | \
318 ((I2C_##reg##_REG_##field##_Msk) & ((val) << (I2C_##reg##_REG_##field##_Pos))))
330 #define HW_I2C_REG_GETF(id, reg, field) \
331 ((IBA(id)->reg##_REG & (I2C_##reg##_REG_##field##_Msk)) >> (I2C_##reg##_REG_##field##_Pos))
341 #define HW_I2C_REG_SET_FIELD(reg, field, var, val) \
342 REG_SET_FIELD(I2C, reg##_REG, field, var, val)
457 return IBA(
id)->I2C_ENABLE_STATUS_REG;
460 #if (HW_I2C_DMA_SUPPORT == 1)
545 #if (HW_I2C_SLAVE_SUPPORT == 0)
546 ASSERT_WARNING(set_master);
548 uint32_t tmp = IBA(
id)->I2C_CON_REG;
551 IBA(
id)->I2C_CON_REG = tmp;
617 uint32_t tmp = IBA(
id)->I2C_TAR_REG;
620 IBA(
id)->I2C_TAR_REG = tmp;
638 #if (HW_I2C_SLAVE_SUPPORT == 1)
700 #if (HW_I2C_SLAVE_SUPPORT == 1)
710 #if (HW_I2C_DMA_SUPPORT == 1)
758 #if (HW_I2C_SLAVE_SUPPORT == 1)
1111 void *cb_data, uint32_t flags);
1242 return IBA(
id)->I2C_INTR_STAT_REG;
1258 return IBA(
id)->I2C_RAW_INTR_STAT_REG;
1276 (void) IBA(
id)->I2C_CLR_INTR_REG;
1289 (void) IBA(
id)->I2C_CLR_RX_UNDER_REG;
1302 (void) IBA(
id)->I2C_CLR_RX_OVER_REG;
1315 (void) IBA(
id)->I2C_CLR_TX_OVER_REG;
1328 (void) IBA(
id)->I2C_CLR_RD_REQ_REG;
1341 (void) IBA(
id)->I2C_CLR_TX_ABRT_REG;
1354 (void) IBA(
id)->I2C_CLR_RX_DONE_REG;
1367 (void) IBA(
id)->I2C_CLR_ACTIVITY_REG;
1380 (void) IBA(
id)->I2C_CLR_START_DET_REG;
1393 (void) IBA(
id)->I2C_CLR_STOP_DET_REG;
1406 (void) IBA(
id)->I2C_CLR_GEN_CALL_REG;
1425 return IBA(
id)->I2C_TX_ABRT_SOURCE_REG & 0x1FFFF;
1464 #if (HW_I2C_DMA_SUPPORT == 1)
uint16_t fs_lcnt
Definition: hw_i2c.h:288
Definition of API for the DMA Low Level Driver.
__STATIC_INLINE uint32_t hw_i2c_get_abort_source(HW_I2C_ID id)
Get abort source.
Definition: hw_i2c.h:1423
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_7B_ADDR_NOACK_Msk
Definition: DA1459x-00.h:3600
__STATIC_INLINE void hw_i2c_set_speed(HW_I2C_ID id, HW_I2C_SPEED speed)
Set I2C interface bus speed.
Definition: hw_i2c.h:577
__STATIC_INLINE bool hw_i2c_is_enabled(HW_I2C_ID id)
Get I2C controller enable status.
Definition: hw_i2c.h:444
__STATIC_INLINE void hw_i2c_set_rx_fifo_threshold(HW_I2C_ID id, uint8_t level)
Set threshold level on RX FIFO.
Definition: hw_i2c.h:1159
#define I2C_I2C_INTR_STAT_REG_R_RD_REQ_Msk
Definition: DA1459x-00.h:3468
__STATIC_INLINE void hw_i2c_write_byte(HW_I2C_ID id, uint8_t byte)
Write single byte into TX FIFO.
Definition: hw_i2c.h:891
HW_I2C_SPEED speed
Definition: hw_i2c.h:293
HW_I2C_INT
I2C interrupt source.
Definition: hw_i2c.h:209
bool hw_i2c_is_occupied(HW_I2C_ID id)
Get I2C controller occupied status.
void hw_i2c_setup_slave(HW_I2C_ID id, HW_I2C_ADDRESSING addr_mode, uint16_t address, hw_i2c_event_cb cb)
Setup controller for operation in slave mode.
hw_i2c_dma_prio_t dma_prio
Definition: hw_i2c.h:301
HW_I2C_DMA_TRANSFER
DMA transfer type.
Definition: hw_i2c.h:229
__STATIC_INLINE uint8_t hw_i2c_is_master(HW_I2C_ID id)
Get I2C controller master mode status.
Definition: hw_i2c.h:563
void hw_i2c_init(HW_I2C_ID id, const i2c_config *cfg)
Initialize I2C controller.
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10B_RD_NORSTRT_Msk
Definition: DA1459x-00.h:3580
__STATIC_INLINE void hw_i2c_reset_int_start_detected(HW_I2C_ID id)
Reset START_DETECTED interrupt state.
Definition: hw_i2c.h:1378
__STATIC_INLINE void hw_i2c_reset_int_tx_overflow(HW_I2C_ID id)
Reset TX_OVERFLOW interrupt state.
Definition: hw_i2c.h:1313
__STATIC_INLINE bool hw_i2c_is_master_busy(HW_I2C_ID id)
Check if controller is busy when operating in master mode.
Definition: hw_i2c.h:753
#define I2C_I2C_INTR_STAT_REG_R_TX_OVER_Msk
Definition: DA1459x-00.h:3472
uint16_t fs_hcnt
Definition: hw_i2c.h:287
__STATIC_INLINE void hw_i2c_set_restart_enabled(HW_I2C_ID id, bool enabled)
Set whether RESTART conditions may be sent when acting as master.
Definition: hw_i2c.h:601
size_t hw_i2c_read_buffer_sync(HW_I2C_ID id, uint8_t *data, uint16_t len, HW_I2C_ABORT_SOURCE *abrt_code, uint32_t flags)
Read multiple bytes from I2C slave synchronously.
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_USER_ABRT_Msk
Definition: DA1459x-00.h:3568
void hw_i2c_deinit(HW_I2C_ID id)
DeInitialize I2C controller.
HW_I2C_ADDRESSING
I2C addressing mode.
Definition: hw_i2c.h:184
#define I2C_I2C_INTR_STAT_REG_R_START_DET_Msk
Definition: DA1459x-00.h:3458
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLV_ARBLOST_Msk
Definition: DA1459x-00.h:3572
Central include header file with platform definitions.
void hw_i2c_set_slave_callback(HW_I2C_ID id, hw_i2c_event_cb cb)
Setup callback function for operation in slave mode.
#define I2C_I2C_INTR_STAT_REG_R_STOP_DET_Msk
Definition: DA1459x-00.h:3460
void hw_i2c_disable(HW_I2C_ID id)
Disable I2C controller.
DMA peripherals priority structure.
Definition: hw_dma.h:275
void hw_i2c_register_slave_dma_read_callback(HW_I2C_ID id)
Register proper handling for DMA read in slave mode.
size_t hw_i2c_write_buffer_sync(HW_I2C_ID id, const uint8_t *data, uint16_t len, HW_I2C_ABORT_SOURCE *abrt_code, uint32_t flags)
Write multiple bytes to I2C slave synchronously.
hw_i2c_event_cb event_cb
Definition: hw_i2c.h:298
#define I2C_I2C_INTR_STAT_REG_R_TX_EMPTY_Msk
Definition: DA1459x-00.h:3470
uint16_t hw_i2c_get_int_mask(HW_I2C_ID id)
Get current bitmask of requested interrupt events.
#define I2C_I2C_DATA_CMD_REG_I2C_CMD_Msk
Definition: DA1459x-00.h:3368
#define I2C_I2C_INTR_STAT_REG_R_TX_ABRT_Msk
Definition: DA1459x-00.h:3466
#define I2C_I2C_INTR_STAT_REG_R_ACTIVITY_Msk
Definition: DA1459x-00.h:3462
void hw_i2c_unregister_int(HW_I2C_ID id)
Unregister interrupt handler.
__STATIC_INLINE uint8_t hw_i2c_read_byte(HW_I2C_ID id)
Read single byte from RX FIFO.
Definition: hw_i2c.h:1129
int hw_i2c_write_buffer_async(HW_I2C_ID id, const uint8_t *data, uint16_t len, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Write multiple bytes to I2C slave asynchronously.
__STATIC_INLINE void hw_i2c_reset_int_stop_detected(HW_I2C_ID id)
Reset STOP_DETECTED interrupt state.
Definition: hw_i2c.h:1391
__STATIC_INLINE void hw_i2c_set_mode(HW_I2C_ID id, HW_I2C_MODE mode)
Set I2C controller mode.
Definition: hw_i2c.h:541
__STATIC_INLINE void hw_i2c_set_target_address(HW_I2C_ID id, uint16_t address)
Set target slave address in master mode.
Definition: hw_i2c.h:854
__STATIC_INLINE void hw_i2c_flush_rx_fifo(HW_I2C_ID id)
Flushing RX FIFO.
Definition: hw_i2c.h:1218
void(* hw_i2c_complete_cb)(HW_I2C_ID id, void *cb_data, uint16_t len, bool success)
Callback called upon completion of read or write in non-blocking mode (FIFO or DMA)
Definition: hw_i2c.h:265
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10ADDR2_NOACK_Msk
Definition: DA1459x-00.h:3596
void(* hw_i2c_interrupt_cb)(HW_I2C_ID id, uint16_t mask)
Callback called on interrupt from I2C controller.
Definition: hw_i2c.h:253
__STATIC_INLINE void hw_i2c_set_general_call_enabled(HW_I2C_ID id, bool enabled)
Set whether General Call should be used to address slaves.
Definition: hw_i2c.h:615
__STATIC_INLINE bool hw_i2c_is_slave_busy(HW_I2C_ID id)
Check if controller is busy when operating in slave mode.
Definition: hw_i2c.h:767
__STATIC_INLINE void hw_i2c_reset_int_read_request(HW_I2C_ID id)
Reset READ_REQUEST interrupt state.
Definition: hw_i2c.h:1326
__STATIC_INLINE uint16_t hw_i2c_get_int_state(HW_I2C_ID id)
Get interrupt state.
Definition: hw_i2c.h:1240
__STATIC_INLINE void hw_i2c_reset_abort_source(HW_I2C_ID id)
Reset abort source.
Definition: hw_i2c.h:1441
HW_I2C_ABORT_SOURCE
I2C abort source.
Definition: hw_i2c.h:142
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_MASTER_DIS_Msk
Definition: DA1459x-00.h:3578
void hw_i2c_register_int(HW_I2C_ID id, hw_i2c_interrupt_cb cb, uint16_t mask)
Register interrupt handler.
__STATIC_INLINE uint16_t hw_i2c_get_raw_int_state(HW_I2C_ID id)
Get raw interrupt state.
Definition: hw_i2c.h:1256
__STATIC_INLINE uint8_t hw_i2c_get_rx_fifo_threshold(HW_I2C_ID id)
Get threshold level on RX FIFO.
Definition: hw_i2c.h:1181
__STATIC_INLINE uint8_t hw_i2c_get_tx_fifo_threshold(HW_I2C_ID id)
Get threshold level on TX FIFO.
Definition: hw_i2c.h:1170
#define I2C_I2C_INTR_STAT_REG_R_RX_DONE_Msk
Definition: DA1459x-00.h:3464
__STATIC_INLINE uint16_t hw_i2c_get_enable_status(HW_I2C_ID id)
Get I2C Controller Enable status.
Definition: hw_i2c.h:455
uint16_t ss_hcnt
Definition: hw_i2c.h:285
uint16_t ss_lcnt
Definition: hw_i2c.h:286
__STATIC_INLINE void hw_i2c_reset_int_activity(HW_I2C_ID id)
Reset ACTIVITY interrupt state.
Definition: hw_i2c.h:1365
__STATIC_INLINE bool hw_i2c_is_rx_fifo_full(HW_I2C_ID id)
Check if RX FIFO queue is full.
Definition: hw_i2c.h:827
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10ADDR1_NOACK_Msk
Definition: DA1459x-00.h:3598
bool hw_i2c_is_clk_enabled(const HW_I2C_ID id)
Get the status of the I2C interface clock source.
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_TXDATA_NOACK_Msk
Definition: DA1459x-00.h:3594
__STATIC_INLINE bool hw_i2c_is_tx_fifo_empty(HW_I2C_ID id)
Check if TX FIFO queue is empty.
Definition: hw_i2c.h:796
#define HW_I2C_REG_SETF(id, reg, field, val)
Write a value to an I2C register field.
Definition: hw_i2c.h:316
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SBYTE_ACKDET_Msk
Definition: DA1459x-00.h:3586
HW_I2C_EVENT
Callback events when working as slave.
Definition: hw_i2c.h:194
void hw_i2c_write_buffer_dma(HW_I2C_ID id, uint8_t channel, const uint16_t *data, uint16_t len, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Write multiple bytes on I2C bus using DMA.
__STATIC_INLINE bool hw_i2c_controler_is_busy(HW_I2C_ID id)
Check controller activity.
Definition: hw_i2c.h:781
__STATIC_INLINE void hw_i2c_reset_int_rx_overflow(HW_I2C_ID id)
Reset RX_OVERFLOW interrupt state.
Definition: hw_i2c.h:1300
uint16_t hs_lcnt
Definition: hw_i2c.h:290
HW_GPIO_MODE mode
Definition: hw_gpio.h:211
__STATIC_INLINE void hw_i2c_master_abort_transfer(HW_I2C_ID id)
Aborts I2C transfer.
Definition: hw_i2c.h:1456
#define I2C_I2C_TX_ABRT_SOURCE_REG_ARB_LOST_Msk
Definition: DA1459x-00.h:3576
#define I2C_I2C_INTR_STAT_REG_R_RX_OVER_Msk
Definition: DA1459x-00.h:3476
HW_I2C_MODE mode
Definition: hw_i2c.h:294
__STATIC_INLINE void hw_i2c_reset_int_tx_abort(HW_I2C_ID id)
Reset TX_ABORT interrupt state.
Definition: hw_i2c.h:1339
#define I2C_I2C_DATA_CMD_REG_I2C_DAT_Msk
Definition: DA1459x-00.h:3370
__STATIC_INLINE void hw_i2c_set_tx_fifo_threshold(HW_I2C_ID id, uint8_t level)
Set threshold level on TX FIFO.
Definition: hw_i2c.h:1144
void hw_i2c_reset_dma_cb(HW_I2C_ID id)
Reset DMA callback.
void hw_i2c_configure(HW_I2C_ID id, const i2c_config *cfg)
Configure I2C controller.
__STATIC_INLINE void hw_i2c_reset_int_all(HW_I2C_ID id)
Reset all interrupt state.
Definition: hw_i2c.h:1274
uint16_t hs_hcnt
Definition: hw_i2c.h:289
__STATIC_INLINE void hw_i2c_set_target_addressing_mode(HW_I2C_ID id, HW_I2C_ADDRESSING addr_mode)
Set target slave addressing mode in master mode.
Definition: hw_i2c.h:632
uint16_t address
Definition: hw_i2c.h:296
__STATIC_INLINE uint8_t hw_i2c_get_rx_fifo_level(HW_I2C_ID id)
Get number of bytes in RX FIFO.
Definition: hw_i2c.h:1207
__STATIC_INLINE void hw_i2c_set_general_call_ack_enabled(HW_I2C_ID id, bool ack)
Set support for general call acknowledgment.
Definition: hw_i2c.h:679
__STATIC_INLINE void hw_i2c_enable(HW_I2C_ID id)
Enable I2C controller.
Definition: hw_i2c.h:422
__STATIC_INLINE void hw_i2c_reset_int_rx_underflow(HW_I2C_ID id)
Reset RX_UNDERFLOW interrupt state.
Definition: hw_i2c.h:1287
void hw_i2c_setup_master(HW_I2C_ID id, HW_I2C_ADDRESSING addr_mode, uint16_t address)
Setup controller for operation in master mode.
void hw_i2c_dma_start(HW_I2C_ID id)
Starts DMA transfer.
void hw_i2c_prepare_dma(HW_I2C_ID id, uint8_t channel, void *data, uint16_t len, HW_I2C_DMA_TRANSFER type, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Prepares I2C DMA for transfer.
#define HW_I2C_REG_GETF(id, reg, field)
Get the value of an I2C register field.
Definition: hw_i2c.h:330
void hw_i2c_set_int_mask(HW_I2C_ID id, uint16_t mask)
Set bitmask of requested interrupt events.
hw_dma_periph_prio_t hw_i2c_dma_prio_t
I2C DMA priority configuration.
Definition: hw_i2c.h:243
void hw_i2c_disable_clk(const HW_I2C_ID id)
Disable I2C clock.
I2C configuration.
Definition: hw_i2c.h:282
__STATIC_INLINE void hw_i2c_set_slave_address(HW_I2C_ID id, uint16_t address)
Set slave address in slave mode.
Definition: hw_i2c.h:663
#define I2C_I2C_INTR_STAT_REG_R_RX_FULL_Msk
Definition: DA1459x-00.h:3474
__STATIC_INLINE bool hw_i2c_is_rx_fifo_not_empty(HW_I2C_ID id)
Check if RX FIFO is not empty.
Definition: hw_i2c.h:842
#define I2C_I2C_INTR_STAT_REG_R_GEN_CALL_Msk
Definition: DA1459x-00.h:3456
int hw_i2c_write_then_read_async(HW_I2C_ID id, const uint8_t *w_data, uint16_t w_len, uint8_t *r_data, uint16_t r_len, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Write then read multiple bytes from I2C slave.
void hw_i2c_read_buffer_dma(HW_I2C_ID id, uint8_t channel, uint8_t *data, uint16_t len, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Read multiple bytes from I2C bus using DMA.
HW_I2C_SPEED
I2C interface speed.
Definition: hw_i2c.h:165
__STATIC_INLINE void hw_i2c_set_slave_addressing_mode(HW_I2C_ID id, HW_I2C_ADDRESSING addr_mode)
Set slave addressing mode in slave mode.
Definition: hw_i2c.h:648
HW_I2C_MODE
I2C mode.
Definition: hw_i2c.h:175
void hw_i2c_enable_clk(const HW_I2C_ID id)
Enable I2C clock.
#define HW_I2C_REG_SET_FIELD(reg, field, var, val)
Sets a field value of an I2C register. Aimed to be used with local variables.
Definition: hw_i2c.h:341
__STATIC_INLINE bool hw_i2c_is_tx_fifo_not_full(HW_I2C_ID id)
Check if TX FIFO is not full.
Definition: hw_i2c.h:811
__STATIC_INLINE void hw_i2c_reset_int_rx_done(HW_I2C_ID id)
Reset RX_DONE interrupt state.
Definition: hw_i2c.h:1352
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_GCALL_READ_Msk
Definition: DA1459x-00.h:3590
void(* hw_i2c_event_cb)(HW_I2C_ID id, HW_I2C_EVENT event)
Callback called on event when in slave mode.
Definition: hw_i2c.h:275
__STATIC_INLINE uint8_t hw_i2c_get_tx_fifo_level(HW_I2C_ID id)
Get number of bytes in TX FIFO.
Definition: hw_i2c.h:1194
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLVFLUSH_TXFIFO_Msk
Definition: DA1459x-00.h:3574
__STATIC_INLINE void hw_i2c_read_byte_trigger(HW_I2C_ID id)
Initiate reading from I2C bus.
Definition: hw_i2c.h:994
#define I2C_I2C_INTR_STAT_REG_R_RX_UNDER_Msk
Definition: DA1459x-00.h:3478
HW_I2C_ADDRESSING addr_mode
Definition: hw_i2c.h:295
__STATIC_INLINE void hw_i2c_reset_int_gen_call(HW_I2C_ID id)
Reset GENERAL_CALL interrupt state.
Definition: hw_i2c.h:1404
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_GCALL_NOACK_Msk
Definition: DA1459x-00.h:3592
int hw_i2c_read_buffer_async(HW_I2C_ID id, uint8_t *data, uint16_t len, hw_i2c_complete_cb cb, void *cb_data, uint32_t flags)
Read multiple bytes from I2C slave asynchronously.
#define I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLVRD_INTX_Msk
Definition: DA1459x-00.h:3570