SmartSnippets DA1459x SDK
Data Structures | Macros | Typedefs | Enumerations | Functions

Definition of API for the I2C Low Level Driver. More...

#include <stdbool.h>
#include <stdint.h>
#include "sdk_defs.h"
#include "hw_dma.h"

Go to the source code of this file.

Data Structures

struct  i2c_config
 I2C configuration. More...
 

Macros

#define HW_I2C_DMA_SUPPORT   dg_configI2C_DMA_SUPPORT
 DMA support for I2C.
 
#define HW_I2C_SLAVE_SUPPORT   ( 1 )
 I2C slave mode support.
 
#define I2C_FIFO_DEPTH   (4)
 TX/RX FIFO depth. More...
 
#define I2C_SETUP(id, seq)
 Wrapper to perform controller setup. More...
 
#define HW_I2C1   ((void *)I2C_BASE)
 I2C controller instance. More...
 
#define HW_I2C_F_NONE   0x00000000
 
#define HW_I2C_F_WAIT_FOR_STOP   0x00000001
 
#define HW_I2C_F_ADD_STOP   0x00000002
 
#define HW_I2C_F_ADD_RESTART   0x00000004
 
#define HW_I2C_I2C1_MADDR   0x01
 I2C high speed master code. This bit field holds the value of the I2C HS mode master code. HS-mode master codes are reserved 8-bit codes (00001xxx) that are not used for slave addressing or other purposes. Each master has its unique master code. Up to eight high-speed mode masters can be present on the same I2C bus system. Valid values are from 0 to 7. This can be written only when the I2C interface is disabled, which corresponds to the IC_ENABLE[0] register being set to 0. Writes at other times have no effect. More...
 
#define HW_I2C_REG_SETF(id, reg, field, val)
 Write a value to an I2C register field. More...
 
#define HW_I2C_REG_GETF(id, reg, field)   ((IBA(id)->reg##_REG & (I2C_##reg##_REG_##field##_Msk)) >> (I2C_##reg##_REG_##field##_Pos))
 Get the value of an I2C register field. More...
 
#define HW_I2C_REG_SET_FIELD(reg, field, var, val)   REG_SET_FIELD(I2C, reg##_REG, field, var, val)
 Sets a field value of an I2C register. Aimed to be used with local variables. More...
 

Typedefs

typedef hw_dma_periph_prio_t hw_i2c_dma_prio_t
 I2C DMA priority configuration. More...
 
typedef void(* hw_i2c_interrupt_cb) (HW_I2C_ID id, uint16_t mask)
 Callback called on interrupt from I2C controller. More...
 
typedef 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) More...
 
typedef void(* hw_i2c_event_cb) (HW_I2C_ID id, HW_I2C_EVENT event)
 Callback called on event when in slave mode. More...
 

Enumerations

enum  HW_I2C_ABORT_SOURCE {
  HW_I2C_ABORT_NONE = 0, HW_I2C_ABORT_7B_ADDR_NO_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_7B_ADDR_NOACK_Msk, HW_I2C_ABORT_10B_ADDR1_NO_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10ADDR1_NOACK_Msk, HW_I2C_ABORT_10B_ADDR2_NO_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10ADDR2_NOACK_Msk,
  HW_I2C_ABORT_TX_DATA_NO_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_TXDATA_NOACK_Msk, HW_I2C_ABORT_GENERAL_CALL_NO_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_GCALL_NOACK_Msk, HW_I2C_ABORT_GENERAL_CALL_READ = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_GCALL_READ_Msk, HW_I2C_ABORT_START_BYTE_ACK = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SBYTE_ACKDET_Msk,
  HW_I2C_ABORT_10B_READ_NO_RESTART = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_10B_RD_NORSTRT_Msk, HW_I2C_ABORT_MASTER_DISABLED = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_MASTER_DIS_Msk, HW_I2C_ABORT_ARBITRATION_LOST = I2C_I2C_TX_ABRT_SOURCE_REG_ARB_LOST_Msk, HW_I2C_ABORT_SLAVE_FLUSH_TX_FIFO = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLVFLUSH_TXFIFO_Msk,
  HW_I2C_ABORT_SLAVE_ARBITRATION_LOST = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLV_ARBLOST_Msk, HW_I2C_ABORT_SLAVE_IN_TX = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_SLVRD_INTX_Msk, HW_I2C_ABORT_USER_ABORT = I2C_I2C_TX_ABRT_SOURCE_REG_ABRT_USER_ABRT_Msk, HW_I2C_ABORT_SW_ERROR
}
 I2C abort source. More...
 
enum  HW_I2C_SPEED { HW_I2C_SPEED_STANDARD = 0, HW_I2C_SPEED_FAST, HW_I2C_SPEED_HIGH }
 I2C interface speed. More...
 
enum  HW_I2C_MODE { HW_I2C_MODE_MASTER = 0, HW_I2C_MODE_SLAVE }
 I2C mode. More...
 
enum  HW_I2C_ADDRESSING { HW_I2C_ADDRESSING_7B = 0, HW_I2C_ADDRESSING_10B }
 I2C addressing mode. More...
 
enum  HW_I2C_EVENT {
  HW_I2C_EVENT_READ_REQUEST = 0, HW_I2C_EVENT_DATA_READY, HW_I2C_EVENT_TX_ABORT, HW_I2C_EVENT_RX_OVERFLOW,
  HW_I2C_EVENT_INVALID
}
 Callback events when working as slave. More...
 
enum  HW_I2C_INT {
  HW_I2C_INT_RX_UNDERFLOW = I2C_I2C_INTR_STAT_REG_R_RX_UNDER_Msk, HW_I2C_INT_RX_OVERFLOW = I2C_I2C_INTR_STAT_REG_R_RX_OVER_Msk, HW_I2C_INT_RX_FULL = I2C_I2C_INTR_STAT_REG_R_RX_FULL_Msk, HW_I2C_INT_TX_OVERFLOW = I2C_I2C_INTR_STAT_REG_R_TX_OVER_Msk,
  HW_I2C_INT_TX_EMPTY = I2C_I2C_INTR_STAT_REG_R_TX_EMPTY_Msk, HW_I2C_INT_READ_REQUEST = I2C_I2C_INTR_STAT_REG_R_RD_REQ_Msk, HW_I2C_INT_TX_ABORT = I2C_I2C_INTR_STAT_REG_R_TX_ABRT_Msk, HW_I2C_INT_RX_DONE = I2C_I2C_INTR_STAT_REG_R_RX_DONE_Msk,
  HW_I2C_INT_ACTIVITY = I2C_I2C_INTR_STAT_REG_R_ACTIVITY_Msk, HW_I2C_INT_STOP_DETECTED = I2C_I2C_INTR_STAT_REG_R_STOP_DET_Msk, HW_I2C_INT_START_DETECTED = I2C_I2C_INTR_STAT_REG_R_START_DET_Msk, HW_I2C_INT_GENERAL_CALL = I2C_I2C_INTR_STAT_REG_R_GEN_CALL_Msk
}
 I2C interrupt source. More...
 
enum  HW_I2C_DMA_TRANSFER
 DMA transfer type. More...
 

Functions

void hw_i2c_enable_clk (const HW_I2C_ID id)
 Enable I2C clock. More...
 
void hw_i2c_disable_clk (const HW_I2C_ID id)
 Disable I2C clock. More...
 
bool hw_i2c_is_clk_enabled (const HW_I2C_ID id)
 Get the status of the I2C interface clock source. More...
 
void hw_i2c_init (HW_I2C_ID id, const i2c_config *cfg)
 Initialize I2C controller. More...
 
void hw_i2c_deinit (HW_I2C_ID id)
 DeInitialize I2C controller. More...
 
void hw_i2c_configure (HW_I2C_ID id, const i2c_config *cfg)
 Configure I2C controller. More...
 
__STATIC_INLINE void hw_i2c_enable (HW_I2C_ID id)
 Enable I2C controller. More...
 
void hw_i2c_disable (HW_I2C_ID id)
 Disable I2C controller. More...
 
__STATIC_INLINE bool hw_i2c_is_enabled (HW_I2C_ID id)
 Get I2C controller enable status. More...
 
__STATIC_INLINE uint16_t hw_i2c_get_enable_status (HW_I2C_ID id)
 Get I2C Controller Enable status. More...
 
void hw_i2c_reset_dma_cb (HW_I2C_ID id)
 Reset DMA callback. More...
 
bool hw_i2c_is_occupied (HW_I2C_ID id)
 Get I2C controller occupied status. More...
 
void hw_i2c_register_int (HW_I2C_ID id, hw_i2c_interrupt_cb cb, uint16_t mask)
 Register interrupt handler. More...
 
void hw_i2c_unregister_int (HW_I2C_ID id)
 Unregister interrupt handler. More...
 
void hw_i2c_set_int_mask (HW_I2C_ID id, uint16_t mask)
 Set bitmask of requested interrupt events. More...
 
uint16_t hw_i2c_get_int_mask (HW_I2C_ID id)
 Get current bitmask of requested interrupt events. More...
 
__STATIC_INLINE void hw_i2c_set_mode (HW_I2C_ID id, HW_I2C_MODE mode)
 Set I2C controller mode. More...
 
__STATIC_INLINE uint8_t hw_i2c_is_master (HW_I2C_ID id)
 Get I2C controller master mode status. More...
 
__STATIC_INLINE void hw_i2c_set_speed (HW_I2C_ID id, HW_I2C_SPEED speed)
 Set I2C interface bus speed. More...
 
__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. More...
 
__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. More...
 
__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. More...
 
__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. More...
 
__STATIC_INLINE void hw_i2c_set_slave_address (HW_I2C_ID id, uint16_t address)
 Set slave address in slave mode. More...
 
__STATIC_INLINE void hw_i2c_set_general_call_ack_enabled (HW_I2C_ID id, bool ack)
 Set support for general call acknowledgment. More...
 
void hw_i2c_setup_master (HW_I2C_ID id, HW_I2C_ADDRESSING addr_mode, uint16_t address)
 Setup controller for operation in master mode. More...
 
void hw_i2c_set_slave_callback (HW_I2C_ID id, hw_i2c_event_cb cb)
 Setup callback function for operation in slave mode. More...
 
void hw_i2c_register_slave_dma_read_callback (HW_I2C_ID id)
 Register proper handling for DMA read in slave mode. More...
 
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. More...
 
__STATIC_INLINE bool hw_i2c_is_master_busy (HW_I2C_ID id)
 Check if controller is busy when operating in master mode. More...
 
__STATIC_INLINE bool hw_i2c_is_slave_busy (HW_I2C_ID id)
 Check if controller is busy when operating in slave mode. More...
 
__STATIC_INLINE bool hw_i2c_controler_is_busy (HW_I2C_ID id)
 Check controller activity. More...
 
__STATIC_INLINE bool hw_i2c_is_tx_fifo_empty (HW_I2C_ID id)
 Check if TX FIFO queue is empty. More...
 
__STATIC_INLINE bool hw_i2c_is_tx_fifo_not_full (HW_I2C_ID id)
 Check if TX FIFO is not full. More...
 
__STATIC_INLINE bool hw_i2c_is_rx_fifo_full (HW_I2C_ID id)
 Check if RX FIFO queue is full. More...
 
__STATIC_INLINE bool hw_i2c_is_rx_fifo_not_empty (HW_I2C_ID id)
 Check if RX FIFO is not empty. More...
 
__STATIC_INLINE void hw_i2c_set_target_address (HW_I2C_ID id, uint16_t address)
 Set target slave address in master mode. More...
 
__STATIC_INLINE void hw_i2c_write_byte (HW_I2C_ID id, uint8_t byte)
 Write single byte into TX FIFO. More...
 
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. More...
 
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. More...
 
__STATIC_INLINE void hw_i2c_read_byte_trigger (HW_I2C_ID id)
 Initiate reading from I2C bus. More...
 
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. More...
 
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. More...
 
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. More...
 
__STATIC_INLINE uint8_t hw_i2c_read_byte (HW_I2C_ID id)
 Read single byte from RX FIFO. More...
 
__STATIC_INLINE void hw_i2c_set_tx_fifo_threshold (HW_I2C_ID id, uint8_t level)
 Set threshold level on TX FIFO. More...
 
__STATIC_INLINE void hw_i2c_set_rx_fifo_threshold (HW_I2C_ID id, uint8_t level)
 Set threshold level on RX FIFO. More...
 
__STATIC_INLINE uint8_t hw_i2c_get_tx_fifo_threshold (HW_I2C_ID id)
 Get threshold level on TX FIFO. More...
 
__STATIC_INLINE uint8_t hw_i2c_get_rx_fifo_threshold (HW_I2C_ID id)
 Get threshold level on RX FIFO. More...
 
__STATIC_INLINE uint8_t hw_i2c_get_tx_fifo_level (HW_I2C_ID id)
 Get number of bytes in TX FIFO. More...
 
__STATIC_INLINE uint8_t hw_i2c_get_rx_fifo_level (HW_I2C_ID id)
 Get number of bytes in RX FIFO. More...
 
__STATIC_INLINE void hw_i2c_flush_rx_fifo (HW_I2C_ID id)
 Flushing RX FIFO. More...
 
__STATIC_INLINE uint16_t hw_i2c_get_int_state (HW_I2C_ID id)
 Get interrupt state. More...
 
__STATIC_INLINE uint16_t hw_i2c_get_raw_int_state (HW_I2C_ID id)
 Get raw interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_all (HW_I2C_ID id)
 Reset all interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_rx_underflow (HW_I2C_ID id)
 Reset RX_UNDERFLOW interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_rx_overflow (HW_I2C_ID id)
 Reset RX_OVERFLOW interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_tx_overflow (HW_I2C_ID id)
 Reset TX_OVERFLOW interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_read_request (HW_I2C_ID id)
 Reset READ_REQUEST interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_tx_abort (HW_I2C_ID id)
 Reset TX_ABORT interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_rx_done (HW_I2C_ID id)
 Reset RX_DONE interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_activity (HW_I2C_ID id)
 Reset ACTIVITY interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_start_detected (HW_I2C_ID id)
 Reset START_DETECTED interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_stop_detected (HW_I2C_ID id)
 Reset STOP_DETECTED interrupt state. More...
 
__STATIC_INLINE void hw_i2c_reset_int_gen_call (HW_I2C_ID id)
 Reset GENERAL_CALL interrupt state. More...
 
__STATIC_INLINE uint32_t hw_i2c_get_abort_source (HW_I2C_ID id)
 Get abort source. More...
 
__STATIC_INLINE void hw_i2c_reset_abort_source (HW_I2C_ID id)
 Reset abort source. More...
 
__STATIC_INLINE void hw_i2c_master_abort_transfer (HW_I2C_ID id)
 Aborts I2C transfer. More...
 
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. More...
 
void hw_i2c_dma_start (HW_I2C_ID id)
 Starts DMA transfer. More...
 
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. More...
 
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. More...
 

Detailed Description

Definition of API for the I2C Low Level Driver.

Copyright (C) 2015-2023 Renesas Electronics Corporation and/or its affiliates. All rights reserved. Confidential Information.

This software ("Software") is supplied by Renesas Electronics Corporation and/or its affiliates ("Renesas"). Renesas grants you a personal, non-exclusive, non-transferable, revocable, non-sub-licensable right and license to use the Software, solely if used in or together with Renesas products. You may make copies of this Software, provided this copyright notice and disclaimer ("Notice") is included in all such copies. Renesas reserves the right to change or discontinue the Software at any time without notice.

THE SOFTWARE IS PROVIDED "AS IS". RENESAS DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. TO THE MAXIMUM EXTENT PERMITTED UNDER LAW, IN NO EVENT SHALL RENESAS BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE, EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. USE OF THIS SOFTWARE MAY BE SUBJECT TO TERMS AND CONDITIONS CONTAINED IN AN ADDITIONAL AGREEMENT BETWEEN YOU AND RENESAS. IN CASE OF CONFLICT BETWEEN THE TERMS OF THIS NOTICE AND ANY SUCH ADDITIONAL LICENSE AGREEMENT, THE TERMS OF THE AGREEMENT SHALL TAKE PRECEDENCE. BY CONTINUING TO USE THIS SOFTWARE, YOU AGREE TO THE TERMS OF THIS NOTICE.IF YOU DO NOT AGREE TO THESE TERMS, YOU ARE NOT PERMITTED TO USE THIS SOFTWARE.