libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::I2C Class Referenceabstract

I2C(Inter-Integrated Circuit)接口类。 I2C (Inter-Integrated Circuit) interface class. More...

#include <i2c.hpp>

Inheritance diagram for LibXR::I2C:

Data Structures

struct  Configuration
 I2C 设备的配置信息结构体。 Configuration structure for an I2C device. More...
 

Public Types

enum class  MemAddrLength : uint8_t { BYTE_8 , BYTE_16 }
 

Public Member Functions

 I2C ()
 默认构造函数。 Default constructor.
 
virtual ErrorCode Read (uint16_t slave_addr, RawData read_data, ReadOperation &op)=0
 读取 I2C 设备的数据。 Reads data from an I2C device.
 
virtual ErrorCode Write (uint16_t slave_addr, ConstRawData write_data, WriteOperation &op)=0
 I2C 设备写入数据。 Writes data to an I2C device.
 
virtual ErrorCode SetConfig (Configuration config)=0
 配置 I2C 设备参数。 Configures the I2C device settings.
 
virtual ErrorCode MemRead (uint16_t slave_addr, uint16_t mem_addr, RawData read_data, ReadOperation &op, MemAddrLength mem_addr_size=MemAddrLength::BYTE_8)=0
 I2C 设备指定寄存器读取数据。 Reads data from a specific register of an I2C device.
 
virtual ErrorCode MemWrite (uint16_t slave_addr, uint16_t mem_addr, ConstRawData write_data, WriteOperation &op, MemAddrLength mem_addr_size=MemAddrLength::BYTE_8)=0
 I2C 设备指定寄存器写入数据。 Writes data to a specific register of an I2C device.
 

Detailed Description

I2C(Inter-Integrated Circuit)接口类。 I2C (Inter-Integrated Circuit) interface class.

该类提供 I2C 通信的基础接口,包括读、写以及配置 I2C 设备的功能。 This class provides a fundamental interface for I2C communication, including read, write, and configuration functionalities.

Definition at line 16 of file i2c.hpp.

Member Enumeration Documentation

◆ MemAddrLength

enum class LibXR::I2C::MemAddrLength : uint8_t
strong

Definition at line 29 of file i2c.hpp.

30 {
31 BYTE_8,
32 BYTE_16
33 };

Constructor & Destructor Documentation

◆ I2C()

LibXR::I2C::I2C ( )
inline

默认构造函数。 Default constructor.

Definition at line 39 of file i2c.hpp.

39{}

Member Function Documentation

◆ MemRead()

virtual ErrorCode LibXR::I2C::MemRead ( uint16_t  slave_addr,
uint16_t  mem_addr,
RawData  read_data,
ReadOperation op,
MemAddrLength  mem_addr_size = MemAddrLength::BYTE_8 
)
pure virtual

I2C 设备指定寄存器读取数据。 Reads data from a specific register of an I2C device.

该函数从指定 I2C 从设备的寄存器地址读取数据,并存储到 read_data 中。 This function reads data from the specified register of the I2C slave and stores it in read_data.

Parameters
slave_addrI2C 从设备地址。 I2C slave address.
mem_addr寄存器地址(通常为 8 位或 16 位)。 Register address (typically 8-bit or 16-bit).
read_data用于存储读取数据的 RawData 对象。 RawData object to store read data.
op异步或同步的读取操作对象。 Read operation object (sync or async).
mem_addr_size寄存器地址长度。 Size of register address in bytes.
Returns
返回 ErrorCode,表示是否读取成功。 Returns ErrorCode indicating success or failure.

Implemented in LibXR::STM32I2C.

◆ MemWrite()

virtual ErrorCode LibXR::I2C::MemWrite ( uint16_t  slave_addr,
uint16_t  mem_addr,
ConstRawData  write_data,
WriteOperation op,
MemAddrLength  mem_addr_size = MemAddrLength::BYTE_8 
)
pure virtual

I2C 设备指定寄存器写入数据。 Writes data to a specific register of an I2C device.

该函数将 write_data 写入指定 I2C 从设备的寄存器地址。 This function writes write_data to the specified register of the I2C slave.

Parameters
slave_addrI2C 从设备地址。 I2C slave address.
mem_addr寄存器地址(通常为 8 位或 16 位)。 Register address (typically 8-bit or 16-bit).
write_data要写入的数据,ConstRawData 类型。 Data to be written, of type ConstRawData.
op异步或同步的写入操作对象。 Write operation object (sync or async).
mem_addr_size寄存器地址长度。 Size of register address in bytes.
Returns
返回 ErrorCode,表示是否写入成功。 Returns ErrorCode indicating success or failure.

Implemented in LibXR::STM32I2C.

◆ Read()

virtual ErrorCode LibXR::I2C::Read ( uint16_t  slave_addr,
RawData  read_data,
ReadOperation op 
)
pure virtual

读取 I2C 设备的数据。 Reads data from an I2C device.

该函数从指定的 I2C 从设备地址读取数据,并存储到 read_data 中。 This function reads data from the specified I2C slave address and stores it in read_data.

Parameters
slave_addr目标 I2C 从设备的地址。 The address of the target I2C slave device.
read_data存储读取数据的 RawData 对象。 A RawData object to store the read data.
op读取操作对象,包含同步或异步操作模式。 Read operation object containing synchronous or asynchronous operation mode.
Returns
返回 ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful.

Implemented in LibXR::STM32I2C.

◆ SetConfig()

virtual ErrorCode LibXR::I2C::SetConfig ( Configuration  config)
pure virtual

配置 I2C 设备参数。 Configures the I2C device settings.

该函数用于设置 I2C 设备的参数,例如通信速率等。 This function sets the parameters of the I2C device, such as the communication speed.

Parameters
config包含 I2C 设置信息的 Configuration 结构体。 A Configuration structure containing I2C settings.
Returns
返回 ErrorCode,指示配置是否成功。 Returns an ErrorCode indicating whether the configuration was successful.

Implemented in LibXR::STM32I2C.

◆ Write()

virtual ErrorCode LibXR::I2C::Write ( uint16_t  slave_addr,
ConstRawData  write_data,
WriteOperation op 
)
pure virtual

I2C 设备写入数据。 Writes data to an I2C device.

该函数将 write_data 写入指定的 I2C 从设备地址。 This function writes write_data to the specified I2C slave address.

Parameters
slave_addr目标 I2C 从设备的地址。 The address of the target I2C slave device.
write_data需要写入的数据,ConstRawData 类型。 The data to be written, of type ConstRawData.
op写入操作对象,包含同步或异步操作模式。 Write operation object containing synchronous or asynchronous operation mode.
Returns
返回 ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful.

Implemented in LibXR::STM32I2C.


The documentation for this class was generated from the following file: