HPM SDK
HPMicro Software Development Kit
hpm_i2c_drv.h File Reference
#include "hpm_common.h"
#include "hpm_i2c_regs.h"
#include "hpm_soc_feature.h"

Go to the source code of this file.

Data Structures

struct  i2c_config_t
 I2C config. More...
 

Macros

#define I2C_DATACNT_MAP(x)   (((x) == I2C_SOC_TRANSFER_COUNT_MAX) ? 0 : x)
 
#define I2C_CMD_NO_ACTION   (I2C_CMD_CMD_SET(0))
 I2C CMD. More...
 
#define I2C_CMD_ISSUE_DATA_TRANSMISSION   (I2C_CMD_CMD_SET(1))
 
#define I2C_CMD_ACK   (I2C_CMD_CMD_SET(2))
 
#define I2C_CMD_NACK   (I2C_CMD_CMD_SET(3))
 
#define I2C_CMD_CLEAR_FIFO   (I2C_CMD_CMD_SET(4))
 
#define I2C_CMD_RESET   (I2C_CMD_CMD_SET(5))
 
#define I2C_DIR_MASTER_WRITE   (0U)
 I2C data direction. More...
 
#define I2C_DIR_MASTER_READ   (1U)
 
#define I2C_DIR_SLAVE_READ   (0U)
 
#define I2C_DIR_SLAVE_WRITE   (1U)
 
#define I2C_EVENT_TRANSACTION_COMPLETE   I2C_INTEN_CMPL_MASK
 I2C events for interrupt enable and status check. More...
 
#define I2C_EVENT_BYTE_RECEIVED   I2C_INTEN_BYTERECV_MASK
 
#define I2C_EVENT_BYTE_TRANSMIT   I2C_INTEN_BYTETRANS_MASK
 
#define I2C_EVENT_START_CONDITION   I2C_INTEN_START_MASK
 
#define I2C_EVENT_STOP_CONDITION   I2C_INTEN_STOP_MASK
 
#define I2C_EVENT_LOSS_ARBITRATION   I2C_INTEN_ARBLOSE_MASK
 
#define I2C_EVENT_ADDRESS_HIT   I2C_INTEN_ADDRHIT_MASK
 
#define I2C_EVENT_FIFO_HALF   I2C_INTEN_FIFOHALF_MASK
 
#define I2C_EVENT_FIFO_FULL   I2C_INTEN_FIFOFULL_MASK
 
#define I2C_EVENT_FIFO_EMPTY   I2C_INTEN_FIFOEMPTY_MASK
 
#define I2C_EVENT_ALL_MASK
 
#define I2C_STATUS_LINE_SDA   I2C_STATUS_LINESDA_MASK
 I2C status for status check only. More...
 
#define I2C_STATUS_LINE_SCL   I2C_STATUS_LINESCL_MASK
 
#define I2C_STATUS_GENERAL_CALL   I2C_STATUS_GENCALL_MASK
 
#define I2C_STATUS_BUS_BUSY   I2C_STATUS_BUSBUSY_MASK
 
#define I2C_STATUS_ACK   I2C_STATUS_ACK_MASK
 
#define I2C_WR   0x0000 /* not operable with read flags*/
 
#define I2C_RD   (1u << 0) /* not operable with write flags*/
 
#define I2C_ADDR_10BIT   (1u << 2) /* this is a ten bit chip address */
 
#define I2C_NO_START   (1u << 4) /* no start phase */
 
#define I2C_NO_ADDRESS   (1u << 5) /* no address phase */
 
#define I2C_NO_READ_ACK   (1u << 6) /* when I2C reading, we do not ACK */
 
#define I2C_NO_STOP   (1u << 7) /* no stop phase */
 
#define I2C_WRITE_CHECK_ACK   (1u << 8) /* when I2C writing, need check the slave returns ack */
 
#define i2c_master_seq_transmit(ptr, device_address, buf, size, opt)   i2c_master_seq_transmit_check_ack(ptr, device_address, buf, size, opt, false)
 sequential transmit in master I2C mode an amount of data and checks ACK in blocking, but does not check for ACK signals. More...
 

Typedefs

typedef enum i2c_mode i2c_mode_t
 I2C mode. More...
 
typedef enum i2c_seq_transfer_opt i2c_seq_transfer_opt_t
 I2c sequential transfer options. More...
 

Enumerations

enum  {
  status_i2c_no_ack = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 1 )) , status_i2c_invalid_data = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 2 )) , status_i2c_no_addr_hit = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 3 )) , status_i2c_transmit_not_completed = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 4 )) ,
  status_i2c_bus_busy = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 5 )) , status_i2c_not_supported = ((uint32_t)( status_group_i2c )*1000U + (uint32_t)( 9 ))
}
 I2C status. More...
 
enum  i2c_mode { i2c_mode_normal , i2c_mode_fast , i2c_mode_fast_plus }
 I2C mode. More...
 
enum  i2c_seq_transfer_opt { i2c_frist_frame = 0 , i2c_next_frame , i2c_last_frame }
 I2c sequential transfer options. More...
 

Functions

static void i2c_respond_Nack (I2C_Type *ptr)
 respond NACK More...
 
static void i2c_respond_ack (I2C_Type *ptr)
 respond ACK More...
 
static void i2c_clear_fifo (I2C_Type *ptr)
 clear I2C fifo More...
 
static uint16_t i2c_get_data_count (I2C_Type *ptr)
 check data count More...
 
static bool i2c_fifo_is_full (I2C_Type *ptr)
 check if I2C FIFO is full More...
 
static bool i2c_fifo_is_half (I2C_Type *ptr)
 check if I2C FIFO is half More...
 
static bool i2c_fifo_is_empty (I2C_Type *ptr)
 check if I2C FIFO is empty More...
 
static bool i2c_is_writing (I2C_Type *ptr)
 check if I2C is writing More...
 
static bool i2c_is_reading (I2C_Type *ptr)
 check if I2C is reading More...
 
static bool i2c_get_line_sda_status (I2C_Type *ptr)
 get i2c sda line status More...
 
static bool i2c_get_line_scl_status (I2C_Type *ptr)
 get i2c scl line status More...
 
static void i2c_clear_status (I2C_Type *ptr, uint32_t mask)
 clear status More...
 
static uint32_t i2c_get_status (I2C_Type *ptr)
 get status More...
 
static uint32_t i2c_get_irq_setting (I2C_Type *ptr)
 i2c get interrupts setting More...
 
static void i2c_disable_irq (I2C_Type *ptr, uint32_t mask)
 disable interrupts More...
 
static void i2c_enable_irq (I2C_Type *ptr, uint32_t mask)
 enable interrupts More...
 
static void i2c_disable_auto_ack (I2C_Type *ptr)
 disable auto ack More...
 
static void i2c_enable_auto_ack (I2C_Type *ptr)
 enable auto ack More...
 
static void i2c_enable_10bit_address_mode (I2C_Type *ptr, bool enable)
 enable 10 bit address mode More...
 
hpm_stat_t i2c_init_master (I2C_Type *ptr, uint32_t src_clk_in_hz, i2c_config_t *config)
 I2C master initialization. More...
 
hpm_stat_t i2c_master_address_write (I2C_Type *ptr, const uint16_t device_address, uint8_t *addr, uint32_t addr_size_in_byte, uint8_t *buf, const uint32_t size_in_byte)
 I2C master write data to specific address of certain slave device. More...
 
hpm_stat_t i2c_master_address_read (I2C_Type *ptr, const uint16_t device_address, uint8_t *addr, uint32_t addr_size_in_byte, uint8_t *buf, const uint32_t size_in_byte)
 I2C master read data from specific address of certain slave device. More...
 
hpm_stat_t i2c_master_write (I2C_Type *ptr, const uint16_t device_address, uint8_t *buf, const uint32_t size)
 I2C master write data to certain slave device. More...
 
hpm_stat_t i2c_master_start_dma_write (I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size)
 I2C master start write data by DMA. More...
 
hpm_stat_t i2c_master_start_dma_read (I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size)
 I2C master start read data by DMA. More...
 
hpm_stat_t i2c_master_read (I2C_Type *ptr, const uint16_t device_address, uint8_t *buf, const uint32_t size)
 I2C master read data from certain slave device. More...
 
hpm_stat_t i2c_init_slave (I2C_Type *ptr, uint32_t src_clk_in_hz, i2c_config_t *config, const uint16_t slave_address)
 I2C slave initialization. More...
 
hpm_stat_t i2c_slave_read (I2C_Type *ptr, uint8_t *buf, const uint32_t size)
 I2C slave read data. More...
 
hpm_stat_t i2c_slave_write (I2C_Type *ptr, uint8_t *buf, const uint32_t size)
 I2C slave write data. More...
 
void i2c_reset (I2C_Type *ptr)
 reset I2C More...
 
static void i2c_dma_enable (I2C_Type *ptr)
 Enable i2c DMA. More...
 
static void i2c_dma_disable (I2C_Type *ptr)
 Disable i2c DMA. More...
 
hpm_stat_t i2c_slave_dma_transfer (I2C_Type *ptr, const uint32_t size)
 I2C slave dma transfer data. More...
 
static void i2c_write_byte (I2C_Type *ptr, uint8_t data)
 I2C write byte into FIFO. More...
 
static uint8_t i2c_read_byte (I2C_Type *ptr)
 I2C read byte into FIFO. More...
 
static uint8_t i2c_get_direction (I2C_Type *ptr)
 I2C get direction. More...
 
hpm_stat_t i2c_master_configure_transfer (I2C_Type *i2c_ptr, const uint16_t device_address, uint32_t size, bool read)
 I2C master configure transfer setting. More...
 
hpm_stat_t i2c_master_seq_transmit_check_ack (I2C_Type *ptr, const uint16_t device_address, uint8_t *buf, const uint32_t size, i2c_seq_transfer_opt_t opt, bool ack_check)
 sequential transmit in master I2C mode an amount of data and checks ACK in blocking More...
 
hpm_stat_t i2c_master_seq_receive (I2C_Type *ptr, const uint16_t device_address, uint8_t *buf, const uint32_t size, i2c_seq_transfer_opt_t opt)
 sequential receive in master I2C mode an amount of data in blocking More...
 
static void i2c_gen_reset_signal (I2C_Type *ptr, uint8_t clk_len)
 generate SCL clock as reset signal More...
 
hpm_stat_t i2c_master_transfer (I2C_Type *ptr, const uint16_t device_address, uint8_t *buf, const uint32_t size, uint16_t flags)
 data transfer on master I2C mode in blocking More...
 
static hpm_stat_t i2c_set_data_count (I2C_Type *ptr, uint32_t size)
 Set the I2C data transfer count. More...
 
static void i2c_master_issue_data_transmission (I2C_Type *ptr)
 Trigger the I2C controller to issue a data transmission command. More...
 
static void i2c_master_set_slave_address (I2C_Type *ptr, uint16_t address)
 Set the slave address for I2C master mode. More...
 
static void i2c_master_enable_start_phase (I2C_Type *ptr)
 Enable start phase at the transaction. More...
 
static void i2c_master_disable_start_phase (I2C_Type *ptr)
 Disable start phase at the transaction. More...
 
static void i2c_master_enable_addr_phase (I2C_Type *ptr)
 Enable address phase at the transaction. More...
 
static void i2c_master_disable_addr_phase (I2C_Type *ptr)
 Disable address phase at the transaction. More...
 
static void i2c_master_enable_data_phase (I2C_Type *ptr)
 Enable data phase at the transaction. More...
 
static void i2c_master_disable_data_phase (I2C_Type *ptr)
 Disable data phase at the transaction. More...
 
static void i2c_master_enable_stop_phase (I2C_Type *ptr)
 Enable stop phase at the transaction. More...
 
static void i2c_master_disable_stop_phase (I2C_Type *ptr)
 Disable stop phase at the transaction. More...
 
static void i2c_set_direction (I2C_Type *ptr, bool direction)
 set i2c transaction direction More...