HPM SDK
HPMicro Software Development Kit
I2C driver APIs

I2C driver APIs. More...

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...
 

Detailed Description

I2C driver APIs.

Macro Definition Documentation

◆ I2C_ADDR_10BIT

#define I2C_ADDR_10BIT   (1u << 2) /* this is a ten bit chip address */

◆ I2C_CMD_ACK

#define I2C_CMD_ACK   (I2C_CMD_CMD_SET(2))

◆ I2C_CMD_CLEAR_FIFO

#define I2C_CMD_CLEAR_FIFO   (I2C_CMD_CMD_SET(4))

◆ I2C_CMD_ISSUE_DATA_TRANSMISSION

#define I2C_CMD_ISSUE_DATA_TRANSMISSION   (I2C_CMD_CMD_SET(1))

◆ I2C_CMD_NACK

#define I2C_CMD_NACK   (I2C_CMD_CMD_SET(3))

◆ I2C_CMD_NO_ACTION

#define I2C_CMD_NO_ACTION   (I2C_CMD_CMD_SET(0))

#include <drivers/inc/hpm_i2c_drv.h>

I2C CMD.

◆ I2C_CMD_RESET

#define I2C_CMD_RESET   (I2C_CMD_CMD_SET(5))

◆ I2C_DATACNT_MAP

#define I2C_DATACNT_MAP (   x)    (((x) == I2C_SOC_TRANSFER_COUNT_MAX) ? 0 : x)

◆ I2C_DIR_MASTER_READ

#define I2C_DIR_MASTER_READ   (1U)

◆ I2C_DIR_MASTER_WRITE

#define I2C_DIR_MASTER_WRITE   (0U)

#include <drivers/inc/hpm_i2c_drv.h>

I2C data direction.

◆ I2C_DIR_SLAVE_READ

#define I2C_DIR_SLAVE_READ   (0U)

◆ I2C_DIR_SLAVE_WRITE

#define I2C_DIR_SLAVE_WRITE   (1U)

◆ I2C_EVENT_ADDRESS_HIT

#define I2C_EVENT_ADDRESS_HIT   I2C_INTEN_ADDRHIT_MASK

◆ I2C_EVENT_ALL_MASK

#define I2C_EVENT_ALL_MASK

#include <drivers/inc/hpm_i2c_drv.h>

Value:
#define I2C_INTEN_ARBLOSE_MASK
Definition: hpm_i2c_regs.h:105
#define I2C_INTEN_FIFOHALF_MASK
Definition: hpm_i2c_regs.h:130
#define I2C_INTEN_START_MASK
Definition: hpm_i2c_regs.h:82
#define I2C_INTEN_FIFOFULL_MASK
Definition: hpm_i2c_regs.h:141
#define I2C_INTEN_ADDRHIT_MASK
Definition: hpm_i2c_regs.h:117
#define I2C_INTEN_BYTETRANS_MASK
Definition: hpm_i2c_regs.h:71
#define I2C_INTEN_CMPL_MASK
Definition: hpm_i2c_regs.h:48
#define I2C_INTEN_STOP_MASK
Definition: hpm_i2c_regs.h:93
#define I2C_INTEN_FIFOEMPTY_MASK
Definition: hpm_i2c_regs.h:152
#define I2C_INTEN_BYTERECV_MASK
Definition: hpm_i2c_regs.h:60

◆ I2C_EVENT_BYTE_RECEIVED

#define I2C_EVENT_BYTE_RECEIVED   I2C_INTEN_BYTERECV_MASK

◆ I2C_EVENT_BYTE_TRANSMIT

#define I2C_EVENT_BYTE_TRANSMIT   I2C_INTEN_BYTETRANS_MASK

◆ I2C_EVENT_FIFO_EMPTY

#define I2C_EVENT_FIFO_EMPTY   I2C_INTEN_FIFOEMPTY_MASK

◆ I2C_EVENT_FIFO_FULL

#define I2C_EVENT_FIFO_FULL   I2C_INTEN_FIFOFULL_MASK

◆ I2C_EVENT_FIFO_HALF

#define I2C_EVENT_FIFO_HALF   I2C_INTEN_FIFOHALF_MASK

◆ I2C_EVENT_LOSS_ARBITRATION

#define I2C_EVENT_LOSS_ARBITRATION   I2C_INTEN_ARBLOSE_MASK

◆ I2C_EVENT_START_CONDITION

#define I2C_EVENT_START_CONDITION   I2C_INTEN_START_MASK

◆ I2C_EVENT_STOP_CONDITION

#define I2C_EVENT_STOP_CONDITION   I2C_INTEN_STOP_MASK

◆ I2C_EVENT_TRANSACTION_COMPLETE

#define I2C_EVENT_TRANSACTION_COMPLETE   I2C_INTEN_CMPL_MASK

#include <drivers/inc/hpm_i2c_drv.h>

I2C events for interrupt enable and status check.

◆ i2c_master_seq_transmit

#define i2c_master_seq_transmit (   ptr,
  device_address,
  buf,
  size,
  opt 
)    i2c_master_seq_transmit_check_ack(ptr, device_address, buf, size, opt, false)

#include <drivers/inc/hpm_i2c_drv.h>

sequential transmit in master I2C mode an amount of data and checks ACK in blocking, but does not check for ACK signals.

Parameters
[in]ptrptr I2C base address
[in]device_addressI2C slave address
[in]bufpointer of the buffer to store data sent from device
[in]sizesize of data to be sent in bytes
[in]optI2c sequential transfer options
Return values
hpm_stat_tstatus_success if transmit is completed without any error

◆ I2C_NO_ADDRESS

#define I2C_NO_ADDRESS   (1u << 5) /* no address phase */

◆ I2C_NO_READ_ACK

#define I2C_NO_READ_ACK   (1u << 6) /* when I2C reading, we do not ACK */

◆ I2C_NO_START

#define I2C_NO_START   (1u << 4) /* no start phase */

◆ I2C_NO_STOP

#define I2C_NO_STOP   (1u << 7) /* no stop phase */

◆ I2C_RD

#define I2C_RD   (1u << 0) /* not operable with write flags*/

◆ I2C_STATUS_ACK

#define I2C_STATUS_ACK   I2C_STATUS_ACK_MASK

◆ I2C_STATUS_BUS_BUSY

#define I2C_STATUS_BUS_BUSY   I2C_STATUS_BUSBUSY_MASK

◆ I2C_STATUS_GENERAL_CALL

#define I2C_STATUS_GENERAL_CALL   I2C_STATUS_GENCALL_MASK

◆ I2C_STATUS_LINE_SCL

#define I2C_STATUS_LINE_SCL   I2C_STATUS_LINESCL_MASK

◆ I2C_STATUS_LINE_SDA

#define I2C_STATUS_LINE_SDA   I2C_STATUS_LINESDA_MASK

#include <drivers/inc/hpm_i2c_drv.h>

I2C status for status check only.

◆ I2C_WR

#define I2C_WR   0x0000 /* not operable with read flags*/

◆ I2C_WRITE_CHECK_ACK

#define I2C_WRITE_CHECK_ACK   (1u << 8) /* when I2C writing, need check the slave returns ack */

Typedef Documentation

◆ i2c_mode_t

typedef enum i2c_mode i2c_mode_t

#include <drivers/inc/hpm_i2c_drv.h>

I2C mode.

◆ i2c_seq_transfer_opt_t

#include <drivers/inc/hpm_i2c_drv.h>

I2c sequential transfer options.

  • : i2c_frist_frame: has start signal
  • : i2c_next_frame: middle transfer
  • : i2c_last_frame: has stop signal

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

#include <drivers/inc/hpm_i2c_drv.h>

I2C status.

Enumerator
status_i2c_no_ack 
status_i2c_invalid_data 
status_i2c_no_addr_hit 
status_i2c_transmit_not_completed 
status_i2c_bus_busy 
status_i2c_not_supported 

◆ i2c_mode

enum i2c_mode

#include <drivers/inc/hpm_i2c_drv.h>

I2C mode.

Enumerator
i2c_mode_normal 
i2c_mode_fast 
i2c_mode_fast_plus 

◆ i2c_seq_transfer_opt

#include <drivers/inc/hpm_i2c_drv.h>

I2c sequential transfer options.

  • : i2c_frist_frame: has start signal
  • : i2c_next_frame: middle transfer
  • : i2c_last_frame: has stop signal
Enumerator
i2c_frist_frame 
i2c_next_frame 
i2c_last_frame 

Function Documentation

◆ i2c_clear_fifo()

static void i2c_clear_fifo ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

clear I2C fifo

Parameters
[in]ptrI2C base address

◆ i2c_clear_status()

static void i2c_clear_status ( I2C_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

clear status

Clear status based on mask

Parameters
[in]ptrI2C base address
[in]maskmask to clear status

◆ i2c_disable_auto_ack()

static void i2c_disable_auto_ack ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

disable auto ack

Disable I2C auto generates proper acknowledgements for each byte received

Parameters
[in]ptrI2C base address

◆ i2c_disable_irq()

static void i2c_disable_irq ( I2C_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

disable interrupts

Disable interrupts based on given mask

Parameters
[in]ptrI2C base address
[in]maskinterrupt mask to be disabled

◆ i2c_dma_disable()

static void i2c_dma_disable ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Disable i2c DMA.

Parameters
[in]ptrI2C base address

◆ i2c_dma_enable()

static void i2c_dma_enable ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Enable i2c DMA.

Parameters
[in]ptrI2C base address

◆ i2c_enable_10bit_address_mode()

static void i2c_enable_10bit_address_mode ( I2C_Type ptr,
bool  enable 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

enable 10 bit address mode

enable 10 bit address mode, if not, address is 7 bit mode

Parameters
[in]ptrI2C base address
[in]enable
  • true: enable 10 bit address mode
  • false: enable 7 bit address mode

◆ i2c_enable_auto_ack()

static void i2c_enable_auto_ack ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

enable auto ack

Enable I2C auto generates proper acknowledgements for each byte received

Parameters
[in]ptrI2C base address

◆ i2c_enable_irq()

static void i2c_enable_irq ( I2C_Type ptr,
uint32_t  mask 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

enable interrupts

Enable interrupts based on given mask

Parameters
[in]ptrI2C base address
[in]maskinterrupt mask to be enabled

◆ i2c_fifo_is_empty()

static bool i2c_fifo_is_empty ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check if I2C FIFO is empty

Parameters
[in]ptrI2C base address
Return values
trueif FIFO is empty

◆ i2c_fifo_is_full()

static bool i2c_fifo_is_full ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check if I2C FIFO is full

Parameters
[in]ptrI2C base address
Return values
trueif FIFO is full

◆ i2c_fifo_is_half()

static bool i2c_fifo_is_half ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check if I2C FIFO is half

Note
When I2C is transmitting data, it indicates if fifo is half-empty;
When I2C is receiving data, it indicates if fifo is half full.
Parameters
[in]ptrI2C base address
Return values
trueif FIFO is half empty or full

◆ i2c_gen_reset_signal()

static void i2c_gen_reset_signal ( I2C_Type ptr,
uint8_t  clk_len 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

generate SCL clock as reset signal

Parameters
ptr[in] ptr I2C base address
[in]clk_lenSCL clock length

◆ i2c_get_data_count()

static uint16_t i2c_get_data_count ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check data count

It indicates number of bytes to transfer

Parameters
[in]ptrI2C base address
Return values
datacount value in byte

◆ i2c_get_direction()

static uint8_t i2c_get_direction ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

I2C get direction.

Note
The same value has different meanings in master and slave modes
Parameters
ptr[in] ptr I2C base address
Returns
uint8_t direction value

◆ i2c_get_irq_setting()

static uint32_t i2c_get_irq_setting ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

i2c get interrupts setting

Get interrupt setting register value

Parameters
[in]ptrI2C base address
Return values
[out]uint32_t interrupt setting register value

◆ i2c_get_line_scl_status()

static bool i2c_get_line_scl_status ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

get i2c scl line status

Parameters
[in]ptrI2C base address
Return values
boolvalue
  • true: the scl line is high
  • false: the scl line is low

◆ i2c_get_line_sda_status()

static bool i2c_get_line_sda_status ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

get i2c sda line status

Parameters
[in]ptrI2C base address
Return values
boolvalue
  • true: the sda line is high
  • false: the sda line is low

◆ i2c_get_status()

static uint32_t i2c_get_status ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

get status

Get current I2C status bits

Parameters
[in]ptrI2C base address
Return values
currentI2C status

◆ i2c_init_master()

hpm_stat_t i2c_init_master ( I2C_Type ptr,
uint32_t  src_clk_in_hz,
i2c_config_t config 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master initialization.

Initialized I2C controller working at master mode

Parameters
[in]ptrI2C base address
[in]src_clk_in_hzI2C controller source clock source frequency in Hz
[in]configi2c_config_t
Return values
hpm_stat_tstatus_success if initialization is completed without any error

◆ i2c_init_slave()

hpm_stat_t i2c_init_slave ( I2C_Type ptr,
uint32_t  src_clk_in_hz,
i2c_config_t config,
const uint16_t  slave_address 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C slave initialization.

Initialize I2C controller working at slave mode

Parameters
[in]ptrI2C base address
[in]src_clk_in_hzI2C controller source clock source frequency in Hz
[in]configI2C configuration structure
[in]slave_addressI2C address to be used at slave mode
Return values
hpm_stat_tstatus_success if initialization is completed without any error

◆ i2c_is_reading()

static bool i2c_is_reading ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check if I2C is reading

Parameters
[in]ptrI2C base address
Return values
boolvalue
  • true: send data if master mode, receive data in slave mode
  • false: receive data if master mode, send data in slave mode

◆ i2c_is_writing()

static bool i2c_is_writing ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

check if I2C is writing

Parameters
[in]ptrI2C base address
Return values
boolvalue
  • true: receive data if master mode, send data in slave mode
  • false: send data if master mode, reveive data in slave mode

◆ i2c_master_address_read()

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 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master read data from specific address of certain slave device.

Read fram certain I2C device at specific address within that device

Note
both addr_size_in_byte and size_in_byte should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]device_addressI2C slave address
[in]addraddress in that I2C device
[in]addr_size_in_byteI2C address in byte
[out]bufpointer of the buffer to receive data read from the device
[in]size_in_bytesize of data to be read in bytes
Return values
hpm_stat_tstatus_success if reading is completed without any error

◆ i2c_master_address_write()

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 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master write data to specific address of certain slave device.

Write to certain I2C device at specific address within that device

Note
the sum of addr_size_in_byte and size_in_byte should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]device_addressI2C slave address
[in]addraddress in that I2C device
[in]addr_size_in_byteI2C address in byte
[in]bufpointer of the data to be sent
[in]size_in_bytesize of data to be sent in bytes
Return values
hpm_stat_tstatus_success if writing is completed without any error

◆ i2c_master_configure_transfer()

hpm_stat_t i2c_master_configure_transfer ( I2C_Type i2c_ptr,
const uint16_t  device_address,
uint32_t  size,
bool  read 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master configure transfer setting.

Parameters
i2c_ptr[in] ptr I2C base address
device_address[in] I2C slave address
size[in] size of data to be transferred in bytes
read[in] true for receive, false for transmit
Return values
hpm_stat_tstatus_success if configuring transmission without any error

◆ i2c_master_disable_addr_phase()

static void i2c_master_disable_addr_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Disable address phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_disable_data_phase()

static void i2c_master_disable_data_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Disable data phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_disable_start_phase()

static void i2c_master_disable_start_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Disable start phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_disable_stop_phase()

static void i2c_master_disable_stop_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Disable stop phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_enable_addr_phase()

static void i2c_master_enable_addr_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Enable address phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_enable_data_phase()

static void i2c_master_enable_data_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Enable data phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_enable_start_phase()

static void i2c_master_enable_start_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Enable start phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_enable_stop_phase()

static void i2c_master_enable_stop_phase ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Enable stop phase at the transaction.

Parameters
[in]ptrptr I2C base address

◆ i2c_master_issue_data_transmission()

static void i2c_master_issue_data_transmission ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Trigger the I2C controller to issue a data transmission command.

Its purpose is to send a command to the I2C controller, instructing it to initiate a data transmission transaction as the master device.

Parameters
[in]ptrI2C base address

◆ i2c_master_read()

hpm_stat_t i2c_master_read ( I2C_Type ptr,
const uint16_t  device_address,
uint8_t *  buf,
const uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master read data from certain slave device.

Read data from I2C device

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]device_addressI2C slave address
[out]bufpointer of the buffer to store data read from device
[in]sizesize of data to be read in bytes
Return values
hpm_stat_tstatus_success if reading is completed without any error

◆ i2c_master_seq_receive()

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 
)

#include <drivers/inc/hpm_i2c_drv.h>

sequential receive in master I2C mode an amount of data in blocking

Parameters
[in]ptrptr I2C base address
[in]device_addressI2C slave address
[in]bufpointer of the buffer to store data sent from device
[in]sizesize of data to be sent in bytes
[in]optI2c sequential transfer options
Return values
hpm_stat_tstatus_success if receive is completed without any error

◆ i2c_master_seq_transmit_check_ack()

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 
)

#include <drivers/inc/hpm_i2c_drv.h>

sequential transmit in master I2C mode an amount of data and checks ACK in blocking

Parameters
[in]ptrptr I2C base address
[in]device_addressI2C slave address
[in]bufpointer of the buffer to store data sent from device
[in]sizesize of data to be sent in bytes
[in]optI2c sequential transfer options
[in]ack_checktrue to check ack, false to not check ack
Return values
hpm_stat_tstatus_success if transmit is completed without any error

◆ i2c_master_set_slave_address()

static void i2c_master_set_slave_address ( I2C_Type ptr,
uint16_t  address 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Set the slave address for I2C master mode.

This function configures the slave address in I2C master mode by writing the processed slave address to the ADDR register of the I2C module.

Parameters
[in]ptrI2C base address
[in]addressThe slave address to be set, which is a 7-bit or 10-bit address depending on the I2C protocol

◆ i2c_master_start_dma_read()

hpm_stat_t i2c_master_start_dma_read ( I2C_Type i2c_ptr,
const uint16_t  device_address,
uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master start read data by DMA.

Read data to I2C device by DMA

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]i2c_ptrI2C base address
[in]device_addressI2C slave address
[in]sizesize of data to be read in bytes
Return values
hpm_stat_tstatus_success if starting transmission without any error

◆ i2c_master_start_dma_write()

hpm_stat_t i2c_master_start_dma_write ( I2C_Type i2c_ptr,
const uint16_t  device_address,
uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master start write data by DMA.

Write data to I2C device by DMA

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]i2c_ptrI2C base address
[in]device_addressI2C slave address
[in]sizesize of data to be sent in bytes
Return values
hpm_stat_tstatus_success if starting transmission without any error

◆ i2c_master_transfer()

hpm_stat_t i2c_master_transfer ( I2C_Type ptr,
const uint16_t  device_address,
uint8_t *  buf,
const uint32_t  size,
uint16_t  flags 
)

#include <drivers/inc/hpm_i2c_drv.h>

data transfer on master I2C mode in blocking

Parameters
[in]ptrptr I2C base address
[in]device_addressI2C slave address
[in]bufpointer of the buffer to store data sent from device
[in]sizesize of data to be sent in bytes
[in]flagsflag bit, which can be other flag bits except I2C_WR I2C_RD, and can perform "|" operation
Return values
hpm_stat_tstatus_success if receive is completed without any error

◆ i2c_master_write()

hpm_stat_t i2c_master_write ( I2C_Type ptr,
const uint16_t  device_address,
uint8_t *  buf,
const uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C master write data to certain slave device.

Write data to I2C device

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]device_addressI2C slave address
[in]bufpointer of the data to be sent
[in]sizesize of data to be sent in bytes
Return values
hpm_stat_tstatus_success if writing is completed without any error

◆ i2c_read_byte()

static uint8_t i2c_read_byte ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

I2C read byte into FIFO.

Parameters
ptr[in] ptr I2C base address
Returns
uint8_t read byte

◆ i2c_reset()

void i2c_reset ( I2C_Type ptr)

#include <drivers/inc/hpm_i2c_drv.h>

reset I2C

Parameters
[in]ptrI2C base address

◆ i2c_respond_ack()

static void i2c_respond_ack ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

respond ACK

Parameters
[in]ptrI2C base address

◆ i2c_respond_Nack()

static void i2c_respond_Nack ( I2C_Type ptr)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

respond NACK

Parameters
[in]ptrI2C base address

◆ i2c_set_data_count()

static hpm_stat_t i2c_set_data_count ( I2C_Type ptr,
uint32_t  size 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

Set the I2C data transfer count.

This function configures the I2C controller to specify the amount of data to be transferred. It ensures that the data size does not exceed the system's maximum transfer limit.

Parameters
[in]ptrI2C base address
[in]sizeThe amount of data to be transferred, in bytes
Return values
hpm_stat_tstatus_success if set without any error

◆ i2c_set_direction()

static void i2c_set_direction ( I2C_Type ptr,
bool  direction 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

set i2c transaction direction

Parameters
[in]ptrptr I2C base address

◆ i2c_slave_dma_transfer()

hpm_stat_t i2c_slave_dma_transfer ( I2C_Type ptr,
const uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C slave dma transfer data.

Note
The direction of data transmission depends on Master setting
Parameters
[in]ptrI2C base address
[in]sizesize of data in bytes
Return values
hpm_stat_tstatus_success if configuring transmission without any error

◆ i2c_slave_read()

hpm_stat_t i2c_slave_read ( I2C_Type ptr,
uint8_t *  buf,
const uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C slave read data.

Read data at slave mode

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]bufpointer of the buffer to store data read from device
[in]sizesize of data to be read in bytes
Return values
hpm_stat_tstatus_success if reading is completed without any error

◆ i2c_slave_write()

hpm_stat_t i2c_slave_write ( I2C_Type ptr,
uint8_t *  buf,
const uint32_t  size 
)

#include <drivers/inc/hpm_i2c_drv.h>

I2C slave write data.

Write data at slave mode.

Note
size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
Parameters
[in]ptrI2C base address
[in]bufpointer of the buffer to store data sent from device
[in]sizesize of data to be sent in bytes
Return values
hpm_stat_tstatus_success if writing is completed without any error

◆ i2c_write_byte()

static void i2c_write_byte ( I2C_Type ptr,
uint8_t  data 
)
inlinestatic

#include <drivers/inc/hpm_i2c_drv.h>

I2C write byte into FIFO.

Parameters
ptr[in] ptr I2C base address
data[in] byte to ne sent