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
 

Macros

#define USE_I2C_DMA_MGR   (0U)
 

Typedefs

typedef enum i2c_speed i2c_speed_t
 
typedef enum i2c_communication_mode i2c_communication_mode_t
 
typedef struct i2c_initialize_config i2c_initialize_config_t
 

Enumerations

enum  i2c_speed { i2c_speed_100khz , i2c_speed_400khz , i2c_speed_1Mhz }
 
enum  i2c_communication_mode { i2c_master , i2c_slave }
 

Functions

void hpm_i2c_get_default_init_config (i2c_initialize_config_t *config)
 
hpm_stat_t hpm_i2c_initialize (I2C_Type *ptr, i2c_initialize_config_t *config)
 Initialize the I2C interface. More...
 
hpm_stat_t hpm_i2c_master_probe_slave_address (I2C_Type *ptr, uint16_t device_address)
 Probes an I2C slave address. More...
 
hpm_stat_t hpm_i2c_master_addr_write_blocking (I2C_Type *ptr, const uint16_t device_address, uint32_t addr, uint8_t addr_size, uint8_t *buf, uint32_t buf_size, uint32_t timeout)
 
hpm_stat_t hpm_i2c_master_addr_read_blocking (I2C_Type *ptr, 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 (I2C_Type *ptr, 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 (I2C_Type *ptr, 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 (I2C_Type *ptr, 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 (I2C_Type *ptr, 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

◆ i2c_communication_mode_t

Define the I2C communication mode enumeration type.

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

◆ i2c_initialize_config_t

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

◆ i2c_speed_t

typedef enum i2c_speed 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_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_config()

void hpm_i2c_get_default_init_config ( i2c_initialize_config_t config)

Get the default I2C initialization configuration

This function initializes the I2C configuration structure with default settings.

Parameters
configPointer to an i2c_initialize_config_t structure where the default initialization settings will be stored. This structure contains various configuration parameters required for I2C device initialization.

◆ hpm_i2c_initialize()

hpm_stat_t hpm_i2c_initialize ( I2C_Type ptr,
i2c_initialize_config_t config 
)

Initialize the I2C interface.

This function initializes the I2C module based on the provided configuration, setting it up for communication.

Parameters
[in]ptrI2C base address
[in]configPointer to the I2C initialization configuration structure, containing settings such as mode and speed
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 ( I2C_Type ptr,
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]ptrI2C base address
[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 ( I2C_Type ptr,
const uint16_t  device_address,
uint32_t  addr,
uint8_t  addr_size,
uint8_t *  buf,
uint32_t  buf_size,
uint32_t  timeout 
)

@briefI2C 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]ptrI2C base address
[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 ( I2C_Type ptr,
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]ptrI2C base address
[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 ( I2C_Type ptr,
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]ptrI2C base address
[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 ( I2C_Type ptr,
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]ptrI2C base address
[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 ( I2C_Type ptr,
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]ptrI2C base address
[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 ( I2C_Type ptr,
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]ptrI2C base address
[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