|
libxr
1.0
Want to be the best embedded framework
|
Public Member Functions | |
| ESP32I2C (i2c_port_t port_num, int scl_pin, int sda_pin, uint32_t clock_speed=400000U, bool enable_internal_pullup=true, uint32_t timeout_ms=100U, uint32_t isr_enable_min_size=32U) | |
| ErrorCode | Read (uint16_t slave_addr, RawData read_data, ReadOperation &op, bool in_isr=false) override |
| 读取 I2C 设备的数据。 Reads data from an I2C device. | |
| ErrorCode | Write (uint16_t slave_addr, ConstRawData write_data, WriteOperation &op, bool in_isr=false) override |
| 向 I2C 设备写入数据。 Writes data to an I2C device. | |
| ErrorCode | SetConfig (Configuration config) override |
| 配置 I2C 设备参数。 Configures the I2C device settings. | |
| ErrorCode | MemRead (uint16_t slave_addr, uint16_t mem_addr, RawData read_data, ReadOperation &op, MemAddrLength mem_addr_size=MemAddrLength::BYTE_8, bool in_isr=false) 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=MemAddrLength::BYTE_8, bool in_isr=false) override |
| 向 I2C 设备指定寄存器写入数据。 Writes data to a specific register of an I2C device. | |
| i2c_port_t | Port () const |
Public Member Functions inherited from LibXR::I2C | |
| I2C () | |
| 默认构造函数。 Default constructor. | |
Static Public Attributes | |
| static constexpr int | PIN_NO_CHANGE = -1 |
Private Member Functions | |
| bool | Acquire () |
| void | Release () |
| ErrorCode | InitHardware () |
| ErrorCode | ConfigurePins () |
| ErrorCode | ApplyConfig () |
| ErrorCode | ResolveClockSource (uint32_t &source_hz) |
| ErrorCode | RecoverController () |
| ErrorCode | EnsureInitialized (bool in_isr) |
| bool | ShouldUseInterruptAsync (size_t total_size) const |
| ErrorCode | ExecuteTransaction (uint16_t slave_addr, const uint8_t *write_payload, size_t write_size, uint8_t *read_payload, size_t read_size) |
| ErrorCode | StartAsyncTransaction (uint16_t slave_addr, const uint8_t *write_prefix_payload, size_t write_prefix_size, const uint8_t *write_payload, size_t write_size, uint8_t *read_payload, size_t read_size, ReadOperation &op) |
| ErrorCode | KickAsyncTransaction () |
| void | FinishAsync (bool in_isr, ErrorCode ec) |
| ErrorCode | InstallInterrupt () |
| void | HandleInterrupt () |
Static Private Member Functions | |
| static size_t | MemAddrBytes (MemAddrLength mem_addr_size) |
| static void | EncodeMemAddr (uint16_t mem_addr, size_t mem_len, uint8_t *out) |
| static bool | IsValid7BitAddr (uint16_t addr) |
| static void | I2cIsrEntry (void *arg) |
Private Attributes | |
| i2c_port_t | port_num_ |
| int | scl_pin_ |
| int | sda_pin_ |
| bool | enable_internal_pullup_ |
| uint32_t | timeout_ms_ |
| uint32_t | isr_enable_min_size_ |
| bool | initialized_ = false |
| Configuration | config_ {} |
| i2c_hal_context_t | hal_ = {} |
| uint32_t | source_clock_hz_ = 0U |
| Flag::Plain | busy_ |
| intr_handle_t | intr_handle_ = nullptr |
| bool | intr_installed_ = false |
| bool | async_running_ = false |
| ReadOperation | async_op_ {} |
| uint16_t | async_slave_addr_ = 0U |
| std::array< uint8_t, 2 > | async_write_prefix_ = {} |
| size_t | async_write_prefix_size_ = 0U |
| size_t | async_write_prefix_offset_ = 0U |
| const uint8_t * | async_write_payload_ = nullptr |
| size_t | async_write_size_ = 0U |
| size_t | async_write_offset_ = 0U |
| uint8_t * | async_read_payload_ = nullptr |
| size_t | async_read_size_ = 0U |
| size_t | async_read_offset_ = 0U |
| size_t | async_pending_read_chunk_ = 0U |
| bool | async_write_phase_done_ = true |
| bool | async_write_addr_sent_ = false |
| bool | async_write_stop_sent_ = false |
| bool | async_read_addr_sent_ = false |
| AsyncBlockWait | block_wait_ {} |
Static Private Attributes | |
| static constexpr size_t | FIFO_LEN = SOC_I2C_FIFO_LEN |
| static constexpr size_t | MAX_WRITE_PAYLOAD = (FIFO_LEN > 4U) ? (FIFO_LEN - 4U) : 0U |
| static constexpr size_t | MAX_WRITE_READ_PREFIX = (FIFO_LEN > 5U) ? (FIFO_LEN - 5U) : 0U |
| static constexpr size_t | MAX_READ_PAYLOAD = (FIFO_LEN > 4U) ? (FIFO_LEN - 4U) : FIFO_LEN |
Additional Inherited Members | |
Public Types inherited from LibXR::I2C | |
| enum class | MemAddrLength : uint8_t { BYTE_8 , BYTE_16 } |
Definition at line 19 of file esp_i2c.hpp.
| LibXR::ESP32I2C::ESP32I2C | ( | i2c_port_t | port_num, |
| int | scl_pin, | ||
| int | sda_pin, | ||
| uint32_t | clock_speed = 400000U, | ||
| bool | enable_internal_pullup = true, | ||
| uint32_t | timeout_ms = 100U, | ||
| uint32_t | isr_enable_min_size = 32U ) |
Definition at line 134 of file esp_i2c.cpp.
|
private |
Definition at line 159 of file esp_i2c.cpp.
|
private |
Definition at line 209 of file esp_i2c.cpp.
|
private |
Definition at line 293 of file esp_i2c.cpp.
|
staticprivate |
Definition at line 183 of file esp_i2c.cpp.
|
private |
Definition at line 165 of file esp_i2c.cpp.
|
private |
Definition at line 751 of file esp_i2c.cpp.
|
private |
Definition at line 619 of file esp_i2c.cpp.
|
private |
Definition at line 692 of file esp_i2c.cpp.
|
staticprivate |
Definition at line 683 of file esp_i2c.cpp.
|
private |
Definition at line 235 of file esp_i2c.cpp.
|
private |
Definition at line 660 of file esp_i2c.cpp.
|
staticprivate |
Definition at line 163 of file esp_i2c.cpp.
|
private |
Definition at line 460 of file esp_i2c.cpp.
|
staticprivate |
Definition at line 178 of file esp_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 1163 of file esp_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 1070 of file esp_i2c.cpp.
|
inline |
Definition at line 46 of file esp_i2c.hpp.
|
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 1013 of file esp_i2c.cpp.
|
private |
Definition at line 323 of file esp_i2c.cpp.
|
private |
Definition at line 161 of file esp_i2c.cpp.
|
private |
Definition at line 196 of file esp_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 928 of file esp_i2c.cpp.
|
private |
Definition at line 350 of file esp_i2c.cpp.
|
private |
Definition at line 360 of file esp_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 955 of file esp_i2c.cpp.
|
private |
Definition at line 96 of file esp_i2c.hpp.
|
private |
Definition at line 107 of file esp_i2c.hpp.
|
private |
Definition at line 111 of file esp_i2c.hpp.
|
private |
Definition at line 106 of file esp_i2c.hpp.
|
private |
Definition at line 104 of file esp_i2c.hpp.
|
private |
Definition at line 105 of file esp_i2c.hpp.
|
private |
Definition at line 95 of file esp_i2c.hpp.
|
private |
Definition at line 97 of file esp_i2c.hpp.
|
private |
Definition at line 109 of file esp_i2c.hpp.
|
private |
Definition at line 103 of file esp_i2c.hpp.
|
private |
Definition at line 101 of file esp_i2c.hpp.
|
private |
Definition at line 108 of file esp_i2c.hpp.
|
private |
Definition at line 98 of file esp_i2c.hpp.
|
private |
Definition at line 100 of file esp_i2c.hpp.
|
private |
Definition at line 99 of file esp_i2c.hpp.
|
private |
Definition at line 102 of file esp_i2c.hpp.
|
private |
Definition at line 110 of file esp_i2c.hpp.
|
private |
Definition at line 112 of file esp_i2c.hpp.
|
private |
Definition at line 91 of file esp_i2c.hpp.
|
private |
Definition at line 88 of file esp_i2c.hpp.
|
private |
Definition at line 84 of file esp_i2c.hpp.
|
staticconstexprprivate |
Definition at line 49 of file esp_i2c.hpp.
|
private |
Definition at line 89 of file esp_i2c.hpp.
|
private |
Definition at line 87 of file esp_i2c.hpp.
|
private |
Definition at line 92 of file esp_i2c.hpp.
|
private |
Definition at line 93 of file esp_i2c.hpp.
|
private |
Definition at line 86 of file esp_i2c.hpp.
|
staticconstexprprivate |
Definition at line 52 of file esp_i2c.hpp.
|
staticconstexprprivate |
Definition at line 50 of file esp_i2c.hpp.
|
staticconstexprprivate |
Definition at line 51 of file esp_i2c.hpp.
|
staticconstexpr |
Definition at line 22 of file esp_i2c.hpp.
|
private |
Definition at line 81 of file esp_i2c.hpp.
|
private |
Definition at line 82 of file esp_i2c.hpp.
|
private |
Definition at line 83 of file esp_i2c.hpp.
|
private |
Definition at line 90 of file esp_i2c.hpp.
|
private |
Definition at line 85 of file esp_i2c.hpp.