|
libxr
1.0
Want to be the best embedded framework
|
Public Member Functions | |
| CH32I2C (ch32_i2c_id_t id, RawData dma_buff, GPIO_TypeDef *scl_port, uint16_t scl_pin, GPIO_TypeDef *sda_port, uint16_t sda_pin, uint32_t pin_remap=0, uint32_t dma_enable_min_size=3, uint32_t default_clock_hz=400000, bool ten_bit_addr=false) | |
| 构造 I2C 驱动对象 / Construct I2C driver object | |
| ErrorCode | Read (uint16_t slave_addr, RawData read_data, ReadOperation &op, bool in_isr) override |
| 读取 I2C 设备的数据。 Reads data from an I2C device. | |
| ErrorCode | Write (uint16_t slave_addr, ConstRawData write_data, WriteOperation &op, bool in_isr) override |
| 向 I2C 设备写入数据。 Writes data to an I2C device. | |
| ErrorCode | MemRead (uint16_t slave_addr, uint16_t mem_addr, RawData read_data, ReadOperation &op, MemAddrLength mem_addr_size, bool in_isr) override |
| 从 I2C 设备指定寄存器读取数据。 Reads data from a specific register of an I2C device. | |
| ErrorCode | MemWrite (uint16_t slave_addr, uint16_t mem_addr, ConstRawData write_data, WriteOperation &op, MemAddrLength mem_addr_size, bool in_isr) override |
| 向 I2C 设备指定寄存器写入数据。 Writes data to a specific register of an I2C device. | |
| ErrorCode | SetConfig (Configuration config) override |
| 配置 I2C 设备参数。 Configures the I2C device settings. | |
| void | RxDmaIRQHandler () |
| DMA 回调入口 / DMA callbacks from CH32 DMA driver. | |
| void | TxDmaIRQHandler () |
| void | ErrorIRQHandler () |
| 错误中断回调 / I2C error IRQ callback | |
Public Member Functions inherited from LibXR::I2C | |
| I2C () | |
| 默认构造函数。 Default constructor. | |
Data Fields | |
| I2C_TypeDef * | instance_ |
| DMA_Channel_TypeDef * | dma_rx_channel_ |
| DMA_Channel_TypeDef * | dma_tx_channel_ |
| ch32_i2c_id_t | id_ |
| uint32_t | dma_enable_min_size_ |
| RawData | dma_buff_ |
| ReadOperation | read_op_ |
| WriteOperation | write_op_ |
| RawData | read_buff_ |
| bool | read_ = false |
| bool | busy_ = false |
| GPIO_TypeDef * | scl_port_ |
| uint16_t | scl_pin_ |
| GPIO_TypeDef * | sda_port_ |
| uint16_t | sda_pin_ |
| Configuration | cfg_ {400000} |
| bool | ten_bit_addr_ = false |
Static Public Attributes | |
| static CH32I2C * | map_ [CH32_I2C_NUMBER] = {nullptr} |
Private Member Functions | |
| bool | DmaBusy () const |
| bool | WaitEvent (uint32_t evt, uint32_t timeout_us=K_DEFAULT_TIMEOUT_US) |
| bool | WaitFlag (uint32_t flag, FlagStatus st, uint32_t timeout_us=K_DEFAULT_TIMEOUT_US) |
| void | ClearAddrFlag () |
| ErrorCode | MasterStartAndAddress (uint16_t slave_addr, uint8_t dir) |
| ErrorCode | MasterStartAndAddress10Bit (uint16_t addr10, uint8_t final_dir) |
| ErrorCode | SendMemAddr (uint16_t mem_addr, MemAddrLength len) |
| ErrorCode | PollingWriteBytes (const uint8_t *data, uint32_t len) |
| ErrorCode | PollingReadBytes (uint8_t *data, uint32_t len) |
| void | StartTxDma (uint32_t len) |
| void | StartRxDma (uint32_t len) |
| void | AbortTransfer (ErrorCode ec) |
Static Private Member Functions | |
| static uint8_t | Addr7ToAddr8 (uint16_t addr7) |
| static uint16_t | Addr10Clamp (uint16_t addr10) |
Static Private Attributes | |
| static constexpr uint32_t | K_DEFAULT_TIMEOUT_US = 20000 |
| 默认超时(微秒) / Default timeout in microseconds | |
Additional Inherited Members | |
Public Types inherited from LibXR::I2C | |
| enum class | MemAddrLength : uint8_t { BYTE_8 , BYTE_16 } |
Definition at line 19 of file ch32_i2c.hpp.
| CH32I2C::CH32I2C | ( | ch32_i2c_id_t | id, |
| RawData | dma_buff, | ||
| GPIO_TypeDef * | scl_port, | ||
| uint16_t | scl_pin, | ||
| GPIO_TypeDef * | sda_port, | ||
| uint16_t | sda_pin, | ||
| uint32_t | pin_remap = 0, | ||
| uint32_t | dma_enable_min_size = 3, | ||
| uint32_t | default_clock_hz = 400000, | ||
| bool | ten_bit_addr = false ) |
构造 I2C 驱动对象 / Construct I2C driver object
slave_addr 使用不带 R/W 位的原始 7 位或 10 位地址。 slave_addr uses raw 7-bit or 10-bit addresses without the R/W bit.
Definition at line 20 of file ch32_i2c.cpp.
|
private |
Definition at line 440 of file ch32_i2c.cpp.
|
inlinestaticprivate |
Definition at line 73 of file ch32_i2c.hpp.
|
inlinestaticprivate |
Definition at line 65 of file ch32_i2c.hpp.
|
private |
Definition at line 182 of file ch32_i2c.cpp.
|
inlineprivate |
Definition at line 60 of file ch32_i2c.hpp.
| void CH32I2C::ErrorIRQHandler | ( | ) |
错误中断回调 / I2C error IRQ callback
Definition at line 824 of file ch32_i2c.cpp.
|
private |
Definition at line 250 of file ch32_i2c.cpp.
|
private |
Definition at line 190 of file ch32_i2c.cpp.
|
overridevirtual |
从 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.
| slave_addr | 目标 I2C 从设备地址,不带 R/W 位。 Target I2C slave address, no R/W bit included. |
| 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. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
ErrorCode,表示是否读取成功。 Returns ErrorCode indicating success or failure. Implements LibXR::I2C.
Definition at line 646 of file ch32_i2c.cpp.
|
overridevirtual |
向 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.
| slave_addr | 目标 I2C 从设备地址,不带 R/W 位。 Target I2C slave address, no R/W bit included. |
| 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. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
ErrorCode,表示是否写入成功。 Returns ErrorCode indicating success or failure. Implements LibXR::I2C.
Definition at line 577 of file ch32_i2c.cpp.
|
private |
Definition at line 341 of file ch32_i2c.cpp.
|
private |
Definition at line 324 of file ch32_i2c.cpp.
|
overridevirtual |
读取 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.
| slave_addr | 目标 I2C 从设备地址,不带 R/W 位。 Target I2C slave address, no R/W bit included. |
| read_data | 存储读取数据的 RawData 对象。 A RawData object to store the read data. |
| op | 读取操作对象,包含同步或异步操作模式。 Read operation object containing synchronous or asynchronous operation mode. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful. Implements LibXR::I2C.
Definition at line 523 of file ch32_i2c.cpp.
| void CH32I2C::RxDmaIRQHandler | ( | ) |
DMA 回调入口 / DMA callbacks from CH32 DMA driver.
Definition at line 796 of file ch32_i2c.cpp.
|
private |
Definition at line 293 of file ch32_i2c.cpp.
|
overridevirtual |
配置 I2C 设备参数。 Configures the I2C device settings.
该函数用于设置 I2C 设备的参数,例如通信速率等。 This function sets the parameters of the I2C device, such as the communication speed.
ErrorCode,指示配置是否成功。 Returns an ErrorCode indicating whether the configuration was successful. Implements LibXR::I2C.
Definition at line 130 of file ch32_i2c.cpp.
|
private |
Definition at line 426 of file ch32_i2c.cpp.
|
private |
Definition at line 417 of file ch32_i2c.cpp.
| void CH32I2C::TxDmaIRQHandler | ( | ) |
Definition at line 778 of file ch32_i2c.cpp.
|
private |
Definition at line 156 of file ch32_i2c.cpp.
|
private |
Definition at line 169 of file ch32_i2c.cpp.
|
overridevirtual |
向 I2C 设备写入数据。 Writes data to an I2C device.
该函数将 write_data 写入指定的 I2C 从设备地址。 This function writes write_data to the specified I2C slave address.
| slave_addr | 目标 I2C 从设备地址,不带 R/W 位。 Target I2C slave address, no R/W bit included. |
| write_data | 需要写入的数据,ConstRawData 类型。 The data to be written, of type ConstRawData. |
| op | 写入操作对象,包含同步或异步操作模式。 Write operation object containing synchronous or asynchronous operation mode. |
| in_isr | 是否在中断中进行操作。Whether the operation is performed in an ISR. |
ErrorCode,指示操作是否成功。 Returns an ErrorCode indicating whether the operation was successful. Implements LibXR::I2C.
Definition at line 465 of file ch32_i2c.cpp.
| bool LibXR::CH32I2C::busy_ = false |
Definition at line 114 of file ch32_i2c.hpp.
| Configuration LibXR::CH32I2C::cfg_ {400000} |
Definition at line 121 of file ch32_i2c.hpp.
| RawData LibXR::CH32I2C::dma_buff_ |
Definition at line 108 of file ch32_i2c.hpp.
| uint32_t LibXR::CH32I2C::dma_enable_min_size_ |
Definition at line 106 of file ch32_i2c.hpp.
| DMA_Channel_TypeDef* LibXR::CH32I2C::dma_rx_channel_ |
Definition at line 103 of file ch32_i2c.hpp.
| DMA_Channel_TypeDef* LibXR::CH32I2C::dma_tx_channel_ |
Definition at line 104 of file ch32_i2c.hpp.
| ch32_i2c_id_t LibXR::CH32I2C::id_ |
Definition at line 105 of file ch32_i2c.hpp.
| I2C_TypeDef* LibXR::CH32I2C::instance_ |
Definition at line 102 of file ch32_i2c.hpp.
|
staticconstexprprivate |
默认超时(微秒) / Default timeout in microseconds
Definition at line 58 of file ch32_i2c.hpp.
|
static |
Definition at line 54 of file ch32_i2c.hpp.
| bool LibXR::CH32I2C::read_ = false |
Definition at line 113 of file ch32_i2c.hpp.
| RawData LibXR::CH32I2C::read_buff_ |
Definition at line 112 of file ch32_i2c.hpp.
| ReadOperation LibXR::CH32I2C::read_op_ |
Definition at line 110 of file ch32_i2c.hpp.
| uint16_t LibXR::CH32I2C::scl_pin_ |
Definition at line 117 of file ch32_i2c.hpp.
| GPIO_TypeDef* LibXR::CH32I2C::scl_port_ |
Definition at line 116 of file ch32_i2c.hpp.
| uint16_t LibXR::CH32I2C::sda_pin_ |
Definition at line 119 of file ch32_i2c.hpp.
| GPIO_TypeDef* LibXR::CH32I2C::sda_port_ |
Definition at line 118 of file ch32_i2c.hpp.
| bool LibXR::CH32I2C::ten_bit_addr_ = false |
Definition at line 123 of file ch32_i2c.hpp.
| WriteOperation LibXR::CH32I2C::write_op_ |
Definition at line 111 of file ch32_i2c.hpp.