HPM SDK
HPMicro Software Development Kit
hpm_i2c.h File Reference
#include "hpm_i2c_drv.h"
#include "hpm_dma_drv.h"
#include "hpm_dmamux_drv.h"
#include "hpm_misc.h"
#include "hpm_l1c_drv.h"

Go to the source code of this file.

Data Structures

struct  i2c_initialize_config
 
struct  i2c_context_t
 

Macros

#define USE_I2C_DMA_MGR   (0U)
 

Typedefs

typedef enum i2c_speed hpm_i2c_speed_t
 
typedef enum i2c_communication_mode hpm_i2c_communication_mode_t
 
typedef enum i2c_master_addr_endianness hpm_i2c_master_addr_endianness_t
 
typedef struct i2c_initialize_config hpm_i2c_initialize_config_t
 
typedef struct i2c_context_t hpm_i2c_context_t
 

Enumerations

enum  i2c_speed { i2c_speed_100khz , i2c_speed_400khz , i2c_speed_1Mhz }
 
enum  i2c_communication_mode { i2c_master , i2c_slave }
 
enum  i2c_master_addr_endianness { i2c_master_addr_little_endian = 0 , i2c_master_addr_big_endian }
 

Functions

void hpm_i2c_get_default_init_context (hpm_i2c_context_t *context)
 
hpm_stat_t hpm_i2c_initialize (hpm_i2c_context_t *context)
 Initialize the I2C interface. More...
 
hpm_stat_t hpm_i2c_master_probe_slave_address (hpm_i2c_context_t *context, uint16_t device_address)
 Probes an I2C slave address. More...
 
hpm_stat_t hpm_i2c_master_addr_write_blocking (hpm_i2c_context_t *context, const uint16_t device_address, uint32_t addr, uint8_t addr_size, uint8_t *buf, uint32_t buf_size, uint32_t timeout)
 I2C master write data to a device's address over I2C in blocking mode. More...
 
hpm_stat_t hpm_i2c_master_addr_read_blocking (hpm_i2c_context_t *context, const uint16_t device_address, uint32_t addr, uint8_t addr_size, uint8_t *buf, uint32_t buf_size, uint32_t timeout)
 I2C master read data from a specified address of an I2C slave device in blocking mode. More...
 
hpm_stat_t hpm_i2c_master_write_blocking (hpm_i2c_context_t *context, uint16_t device_address, uint8_t *buf, uint32_t size, uint32_t timeout)
 I2C master write data to an I2C slave device in blocking mode. More...
 
hpm_stat_t hpm_i2c_master_read_blocking (hpm_i2c_context_t *context, const uint16_t device_address, uint8_t *buf, const uint32_t size, uint32_t timeout)
 I2C master read data from an I2C device in blocking mode. More...
 
hpm_stat_t hpm_i2c_slave_write_blocking (hpm_i2c_context_t *context, uint8_t *buf, uint32_t size, uint32_t timeout)
 I2C slave write operation in blocking mode. More...
 
hpm_stat_t hpm_i2c_slave_read_blocking (hpm_i2c_context_t *context, uint8_t *buf, uint32_t size, uint32_t timeout)
 I2C slave read operation in blocking mode. More...
 

Macro Definition Documentation

◆ USE_I2C_DMA_MGR

#define USE_I2C_DMA_MGR   (0U)

Typedef Documentation

◆ hpm_i2c_communication_mode_t

Define the I2C communication mode enumeration type.

I2C communication modes include master (i2c_master) and slave (i2c_slave).

◆ hpm_i2c_context_t

◆ hpm_i2c_initialize_config_t

Define the I2C initialization configuration structure This structure configures the I2C communication mode, speed, addressing method, and slave address

◆ hpm_i2c_master_addr_endianness_t

◆ hpm_i2c_speed_t

typedef enum i2c_speed hpm_i2c_speed_t

Define an enumeration type for I2C communication speeds

The I2C protocol allows different communication speeds. This enumeration defines the three most common speed options.

Enumeration Type Documentation

◆ i2c_communication_mode

Define the I2C communication mode enumeration type.

I2C communication modes include master (i2c_master) and slave (i2c_slave).

Enumerator
i2c_master 
i2c_slave 

◆ i2c_master_addr_endianness

Enumerator
i2c_master_addr_little_endian 
i2c_master_addr_big_endian 

◆ i2c_speed

enum i2c_speed

Define an enumeration type for I2C communication speeds

The I2C protocol allows different communication speeds. This enumeration defines the three most common speed options.

Enumerator
i2c_speed_100khz 
i2c_speed_400khz 
i2c_speed_1Mhz 

Function Documentation

◆ hpm_i2c_get_default_init_context()

void hpm_i2c_get_default_init_context ( hpm_i2c_context_t context)

Get the default initialization context for I2C

This function initializes the I2C context structure, setting the default address endianness to little-endian.

Parameters
contextPointer to the I2C context structure

◆ hpm_i2c_initialize()

hpm_stat_t hpm_i2c_initialize ( hpm_i2c_context_t context)

Initialize the I2C interface.

This function initializes the I2C module based on the provided configuration, setting it up for communication. It configures the I2C mode, speed, addressing method, and initializes the I2C device as either a master or slave.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t" which contains initialization configurations and base address information.
Return values
hpm_stat_tReturns the initialization status, indicating success or error codes

◆ hpm_i2c_master_addr_read_blocking()

hpm_stat_t hpm_i2c_master_addr_read_blocking ( hpm_i2c_context_t context,
const uint16_t  device_address,
uint32_t  addr,
uint8_t  addr_size,
uint8_t *  buf,
uint32_t  buf_size,
uint32_t  timeout 
)

I2C master read data from a specified address of an I2C slave device in blocking mode.

This function reads data from a specified address of an I2C slave device using the I2C bus in a blocking manner. It first sends the slave device address, then the memory address to read from, and finally reads the data.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]device_addressAddress of the I2C slave device (7-bit or 10-bit address, depending on the hardware).
[in]addrInternal address within the slave device to read from (can be a register or memory address).
[in]addr_sizeSize of the address in bytes, indicating the number of bits in the address.
[in]bufPointer to the buffer where the read data will be stored.
[in]buf_sizeNumber of bytes to read.
[in]timeoutTimeout value in milliseconds. If the read operation does not complete within this time, the function returns a timeout error.
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_master_addr_write_blocking()

hpm_stat_t hpm_i2c_master_addr_write_blocking ( hpm_i2c_context_t context,
const uint16_t  device_address,
uint32_t  addr,
uint8_t  addr_size,
uint8_t *  buf,
uint32_t  buf_size,
uint32_t  timeout 
)

I2C master write data to a device's address over I2C in blocking mode.

This function writes data to a specific device over the I2C bus in a blocking manner. It requires the base address of the I2C peripheral, the device's I2C address, the address within the device, the address size, the data buffer, and the buffer size. The function ensures that the data transfer is completed within the specified timeout period.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]device_addressAddress of the I2C slave device (7-bit or 10-bit address, depending on the hardware)
[in]addrThe address within the device where data writing should start
[in]addr_sizeThe size of the address, indicating the width of the device's internal address (in bytes)
[in]bufPointer to the buffer containing the data to be written
[in]buf_sizeThe size of the buffer, indicating the length of the data to be written (in bytes)
[in]timeoutThe timeout period, within which the function must complete the data transfer
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_master_probe_slave_address()

hpm_stat_t hpm_i2c_master_probe_slave_address ( hpm_i2c_context_t context,
uint16_t  device_address 
)

Probes an I2C slave address.

This function sends a probe signal over the I2C bus to check if a slave device at the specified address is present. It is primarily used to verify that a slave device is correctly connected to the I2C bus without performing any data transfer.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]device_addressaddress of the slave device to probe
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_master_read_blocking()

hpm_stat_t hpm_i2c_master_read_blocking ( hpm_i2c_context_t context,
const uint16_t  device_address,
uint8_t *  buf,
const uint32_t  size,
uint32_t  timeout 
)

I2C master read data from an I2C device in blocking mode.

This function reads a specified number of bytes from the I2C device with the given address and stores them in the provided buffer. The read operation is blocking, meaning it will wait until the read is complete or an error occurs.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]device_addressAddress of the I2C slave device (7-bit or 10-bit address, depending on the hardware)
[in]bufPointer to the buffer where the read data will be stored
[in]sizeNumber of bytes to read
[in]timeoutTimeout for the operation in milliseconds
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_master_write_blocking()

hpm_stat_t hpm_i2c_master_write_blocking ( hpm_i2c_context_t context,
uint16_t  device_address,
uint8_t *  buf,
uint32_t  size,
uint32_t  timeout 
)

I2C master write data to an I2C slave device in blocking mode.

This function performs a blocking write operation for an I2C master device, writing a specified number of bytes to the I2C slave device. Blocking mode means the function will return only after the data transfer is complete, and it will occupy CPU resources during the data transfer.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]device_addressAddress of the I2C slave device (7-bit or 10-bit address, depending on the hardware)
[in]bufPointer to the buffer containing the data to be written, data type is uint8_t
[in]sizeNumber of bytes to write, data type is uint32_t
[in]timeoutTimeout for the operation, in milliseconds. If the operation does not complete within this time, the function will return an error
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_slave_read_blocking()

hpm_stat_t hpm_i2c_slave_read_blocking ( hpm_i2c_context_t context,
uint8_t *  buf,
uint32_t  size,
uint32_t  timeout 
)

I2C slave read operation in blocking mode.

This function reads data from the I2C slave device using the specified I2C interface in a blocking mode.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]bufPointer to the buffer where the read data will be stored.
[in]sizeNumber of bytes to read from the I2C slave device.
[in]timeoutTimeout value in milliseconds for the read operation. If the read operation does not complete within this time, it will be terminated.
Return values
hpm_stat_tOperation status, indicating success or error codes

◆ hpm_i2c_slave_write_blocking()

hpm_stat_t hpm_i2c_slave_write_blocking ( hpm_i2c_context_t context,
uint8_t *  buf,
uint32_t  size,
uint32_t  timeout 
)

I2C slave write operation in blocking mode.

This function handles the write operation for an I2C slave in a blocking manner. It waits until all data is successfully written or an error occurs, or the specified timeout is exceeded.

Parameters
[in]contextA pointer to the struct of "hpm_i2c_context_t"
[in]bufPointer to the buffer where received data will be stored
[in]sizeNumber of bytes to receive
[in]timeoutTimeout value for the operation; if the operation does not complete within this time, the function returns a timeout error
Return values
hpm_stat_tOperation status, indicating success or error codes