|
libxr
1.0
Want to be the best embedded framework
|
HPM SDK I2C 主机驱动,适配 LibXR I2C 接口 / HPM SDK based I2C master driver for the LibXR I2C interface. More...
#include <hpm_i2c.hpp>
Data Structures | |
| struct | WaitPolicy |
| HPM I2C 忙等超时策略 / HPM I2C busy-wait timeout policy. More... | |
Public Types | |
| enum class | AddressMode : uint8_t { ADDR_7BIT , ADDR_10BIT } |
| HPM I2C 主机寻址模式 / HPM I2C master addressing mode. More... | |
| enum class | SequenceFrame : uint8_t { FIRST , NEXT , LAST } |
| HPM 主机顺序事务分段类型 / HPM master sequential transfer frame type. More... | |
| enum class | TransferFlag : uint16_t { NONE = 0 , READ = 0x0001U , ADDR_10BIT = 0x0002U , NO_START = 0x0004U , NO_ADDRESS = 0x0008U , NO_READ_ACK = 0x0010U , NO_STOP = 0x0020U , WRITE_CHECK_ACK = 0x0040U } |
| HPM 主机扩展事务标志 / HPM master extended transfer flags. More... | |
| enum class | AsyncTransferKind : uint8_t { NONE , READ , WRITE , MEM_READ } |
| HPM I2C 后台事务类型 / HPM I2C asynchronous transfer kind. More... | |
Public Types inherited from LibXR::I2C | |
| enum class | MemAddrLength : uint8_t { BYTE_8 , BYTE_16 } |
Public Member Functions | |
| HPMI2C (LibXRHpmI2cType *i2c, clock_name_t clock, bool auto_board_init=true, I2C::Configuration config={100000}) | |
| 构造 HPM I2C 主机对象 / Construct an HPM I2C master object. | |
| ErrorCode | SetAddressMode (AddressMode mode) |
| 设置 HPM 主机寻址模式并重建控制器 / Set HPM master addressing mode and rebuild the controller. | |
| ErrorCode | SetWaitPolicy (WaitPolicy policy) |
| 设置当前实例的忙等超时策略 / Set the busy-wait timeout policy for this instance. | |
| WaitPolicy | GetWaitPolicy () const |
| 获取当前实例的忙等超时策略 / Get the current busy-wait timeout policy. | |
| AddressMode | GetAddressMode () const |
| 获取当前 HPM 主机寻址模式 / Get current HPM master addressing mode. | |
| ErrorCode | SequenceWrite (uint16_t slave_addr, ConstRawData write_data, SequenceFrame frame, bool check_ack, WriteOperation &op, bool in_isr=false) |
| 执行一段 HPM 主机顺序写事务 / Execute one HPM master sequential write frame. | |
| ErrorCode | SequenceRead (uint16_t slave_addr, RawData read_data, SequenceFrame frame, ReadOperation &op, bool in_isr=false) |
| 执行一段 HPM 主机顺序读事务 / Execute one HPM master sequential read frame. | |
| ErrorCode | TransferWithFlags (uint16_t slave_addr, RawData data, uint16_t flags, ReadOperation &op, bool in_isr=false) |
| 执行一段 HPM 扩展标志主机事务 / Execute one HPM master transfer with extended SDK flags. | |
| ErrorCode | TransferWithFlags (uint16_t slave_addr, ConstRawData data, uint16_t flags, WriteOperation &op, bool in_isr=false) |
| 执行一段 HPM 扩展标志主机写事务 / Execute one HPM master write transfer with extended SDK flags. | |
| ErrorCode | Read (uint16_t slave_addr, RawData read_data, ReadOperation &op, bool in_isr=false) override |
| 从 I2C 从设备读取字节 / Read bytes from an I2C slave. | |
| ErrorCode | Write (uint16_t slave_addr, ConstRawData write_data, WriteOperation &op, bool in_isr=false) override |
| 向 I2C 从设备写入字节 / Write bytes to an I2C slave. | |
| 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 从设备寄存器或存储器地址读取字节 / Read bytes from an I2C slave register or memory address. | |
| 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 从设备寄存器或存储器地址写入字节 / Write bytes to an I2C slave register or memory address. | |
| ErrorCode | SetConfig (Configuration config) override |
| 应用 I2C 时序配置 / Apply I2C timing configuration. | |
| uint32_t | GetClockFreq () const |
| 获取当前缓存的 I2C 源时钟频率 / Get cached I2C source clock frequency. | |
Public Member Functions inherited from LibXR::I2C | |
| I2C () | |
| 默认构造函数。 Default constructor. | |
Static Public Member Functions | |
| static constexpr WaitPolicy | DefaultWaitPolicy () |
| 返回默认 HPM I2C 忙等超时策略 / Return the default HPM I2C wait policy. | |
Private Member Functions | |
| friend | void::libxr_hpm_i2c_process_interrupt (LibXRHpmI2cType *ptr) |
| uint16_t | BuildTransferFlags (uint16_t flags) const |
| 根据目标固定速率解析 HPM I2C 工作模式 / Resolve HPM I2C operating mode from a fixed target clock rate. | |
| ErrorCode | ValidateSlaveAddress (uint16_t slave_addr) const |
| 校验当前寻址模式下的从地址 / Validate slave address for the current addressing mode. | |
| ErrorCode | ValidateTransferArgs (uint16_t slave_addr, RawData data, bool allow_zero_size) const |
| 校验普通读写事务入口参数 / Validate common read/write entry arguments. | |
| ErrorCode | ValidateTransferArgs (uint16_t slave_addr, ConstRawData data, bool allow_zero_size) const |
| 校验普通写事务入口参数 / Validate common write entry arguments. | |
| ErrorCode | ValidateMemWriteArgs (uint16_t slave_addr, ConstRawData write_data, MemAddrLength mem_addr_size, uint32_t &addr_size) const |
| 校验寄存器写事务入口参数并解析寄存器地址长度 / Validate memory-write entry arguments and resolve memory-address length. | |
| ErrorCode | DoSequenceWrite (uint16_t slave_addr, ConstRawData write_data, SequenceFrame frame, bool check_ack) |
| 执行一段顺序写事务,不做状态分发 / Execute one sequential write frame without LibXR status dispatch. | |
| ErrorCode | DoSequenceRead (uint16_t slave_addr, RawData read_data, SequenceFrame frame) |
| 执行一段顺序读事务,不做状态分发 / Execute one sequential read frame without LibXR status dispatch. | |
| ErrorCode | DoTransferWithFlags (uint16_t slave_addr, RawData data, uint16_t flags) |
| 执行一段扩展标志事务,不做状态分发 / Execute one flag-based transfer without LibXR status dispatch. | |
| hpm_stat_t | DoManualTransferWithFlags (uint16_t slave_addr, RawData data, uint16_t flags) |
| 通过手工 phase 编排执行一笔 blocking 事务 / Execute one blocking transfer through manual phase orchestration. | |
| ErrorCode | EnsureClockReady () |
| 确保 I2C 源时钟已可用 / Ensure the I2C source clock is available. | |
| ErrorCode | EnsureControllerReady () |
| 确保控制器已完成一次可用配置 / Ensure the controller has a usable configuration applied. | |
| ErrorCode | ApplyConfig (const Configuration &config) |
| 按当前后端限制下发配置并缓存成功配置 / Apply configuration under current backend limits and cache it on success. | |
| void | RecoverController () |
| 复位并按缓存配置重建 I2C 控制器 / Reset and reinitialize the I2C controller with cached configuration. | |
| void | TryRecoverBusLines () |
| 在 SDA 被拉低且硬件支持时尝试发出 I2C reset clocks / Try to generate I2C reset clocks when SDA is stuck low and the hardware supports it. | |
Static Private Member Functions | |
| static ErrorCode | ConvertStatus (hpm_stat_t status) |
| 将 HPM SDK I2C 状态码转换为 LibXR 错误码 / Convert HPM SDK I2C status to LibXR ErrorCode. | |
| static uint16_t | GetMaxSlaveAddress (AddressMode mode) |
| 获取指定寻址模式可接受的最大从地址 / Get the maximum valid slave address for the given mode. | |
| static ErrorCode | ResolveMemAddressSize (MemAddrLength len, uint32_t &addr_size) |
| 解析寄存器地址宽度枚举到字节数 / Resolve register-address enum to byte count. | |
| static void | FillMemAddress (uint16_t mem_addr, MemAddrLength len, uint8_t out[2]) |
| 按 BYTE_8/BYTE_16 格式填充寄存器地址字节 / Fill register address bytes according to BYTE_8/BYTE_16 format. | |
| static bool | ShouldRecover (hpm_stat_t status) |
| 判断失败后是否需要重建控制器 / Decide whether the controller should be reinitialized after a failure. | |
| template<typename Op > | |
| static ErrorCode | FinishOperation (Op &op, bool in_isr, ErrorCode ans) |
| 完成 LibXR 操作状态更新或回调 / Complete LibXR operation status update or callback dispatch. | |
Private Attributes | |
| LibXRHpmI2cType * | i2c_ |
| I2C 外设实例 / I2C peripheral instance. | |
| clock_name_t | clock_ |
| I2C 源时钟名称 / I2C source clock name. | |
| uint32_t | source_clock_hz_ = 0 |
| 缓存的源时钟频率 / Cached source clock frequency. | |
| Configuration | current_config_ |
| 最近一次成功总线时序配置 / Most recent successful bus-timing config. | |
| WaitPolicy | wait_policy_ |
| 当前忙等超时策略 / Current busy-wait timeout policy. | |
| AddressMode | address_mode_ |
| 当前主机寻址模式 / Current master addressing mode. | |
| bool | configured_ = false |
| 是否已有成功配置 / Whether a valid config was applied. | |
| bool | auto_board_init_ |
| 是否自动调用板级初始化 / Whether board init is automatic. | |
Static Private Attributes | |
| static constexpr uint16_t | kMax7BitAddress = 0x7FU |
| 当前 HPM 后端支持的最大 7-bit 从地址 / Maximum 7-bit slave address supported by the current HPM backend. | |
| static constexpr uint16_t | kMax10BitAddress = 0x3FFU |
| 当前 HPM 后端支持的最大 10-bit 从地址 / Maximum 10-bit slave address supported by the current HPM backend. | |
HPM SDK I2C 主机驱动,适配 LibXR I2C 接口 / HPM SDK based I2C master driver for the LibXR I2C interface.
该类持有一个 HPM I2C 外设实例,并通过 LibXR::I2C 提供普通字节流传输和 寄存器/存储器地址式传输。 This class owns one HPM I2C peripheral instance and exposes byte-stream transfers and register/memory-address transfers through LibXR::I2C.
默认按 7-bit 主机寻址模式启动,也可通过 HPMI2C::SetAddressMode() 切到 HPM SDK 已支持的 10-bit 主机寻址模式;若遇到超时、总线忙或无响应等典型主机故障,驱动会 尝试用最近一次成功配置重建控制器。 The driver starts in 7-bit master addressing mode by default and can switch to the HPM SDK supported 10-bit master addressing mode through HPMI2C::SetAddressMode(). On typical master-side failures such as timeout, bus busy, or no response, the driver attempts to rebuild the controller with the most recent successful configuration.
BLOCK 模式保持同步阻塞式传输;当工程提供旧分支的 hpm_dma_mgr.h helper 时, POLLING / CALLBACK / NONE 可复用 DMA 后台路径覆盖 Write / Read / MemRead。 当前 upstream HPM5301 模板未携带该 helper 时,这些操作降级为同步完成并即时更新 LibXR Operation 状态。MemWrite 始终保持阻塞路径。对 10-bit / 扩展 flags 的 blocking 手工 phase 路径,地址阶段会显式等待 ADDRHIT,失败时按适配层策略强制 cleanup 并按原始 HPM 状态触发恢复链路。 BLOCK mode stays on synchronous blocking transfers. When the project provides the legacy-branch hpm_dma_mgr.h helper, POLLING / CALLBACK / NONE can reuse the DMA backed path for Write / Read / MemRead. Without that helper, as in the current upstream HPM5301 template, these operations complete synchronously and update the LibXR Operation state before returning. MemWrite always stays on the blocking path. For the blocking manual phase path used by 10-bit / extended-flag transfers, the address phase explicitly waits for ADDRHIT; failures force adapter-level cleanup and preserve the original HPM status for recovery handling.
后台 DMA 完成并不直接代表事务成功,驱动会在 DMA 结束后继续确认 I2C CMPL 和后置状态,再通过 UpdateStatus() 或 AsyncBlockWait 报告最终结果。 DMA completion alone is not treated as transfer success. After DMA finishes, the driver still verifies I2C CMPL and post-transfer status before reporting the final result through UpdateStatus() or AsyncBlockWait. 异步完成路径的 dma_done、cmpl_done、final_status 和 should_recover 原子状态由内部 AsyncCompletionStateMachine helper 统一更新,IRQ 和 DMA 回调只声明 发生的事件。 The asynchronous completion atomics dma_done, cmpl_done, final_status, and should_recover are updated through the internal AsyncCompletionStateMachine helper, leaving IRQ and DMA callbacks to report events only.
当 DMA 后台事务正在进行时,同步 Read / Write / MemRead / MemWrite、顺序 SequenceRead / SequenceWrite 以及扩展 flags 手动 phase 入口会返回 BUSY; 低层手动 helper 在清 FIFO、改 CTRL/INTEN 或发 START 前返回 HPM SDK 的 status_i2c_bus_busy,再由 ConvertStatus() 映射到 LibXR 错误码。 While a DMA-backed transfer is active, synchronous Read / Write / MemRead / MemWrite, sequential SequenceRead / SequenceWrite, and extended-flag manual phase entry points return BUSY. The low-level manual helper returns the HPM SDK status_i2c_bus_busy before clearing FIFO, changing CTRL/INTEN, or issuing START, and ConvertStatus() maps that status to the LibXR error code.
忙等路径统一经实现文件内部的 WaitUntil() 处理;工程可提供强定义 extern "C" void libxr_hpm_i2c_wait_relax_hook(void),在等待 ADDRHIT、CMPL 或 FIFO 状态时插入调度让出、低功耗等待或板级短延时。默认实现仅执行一个 nop, 不改变无 RTOS 裸机场景的时序假设。WaitUntil() 缓存首次读取的 clock_get_core_clock_ticks_per_us() 结果,并使用 unsigned elapsed ticks 比较以 避免 deadline 加法回绕;HPM SDK hpm_csr_get_core_cycle() 返回 64-bit CYCLE 值, 事务期间仍假设 core clock 不被动态改频。 Busy-wait paths are centralized through the implementation-local WaitUntil(). A project may provide a strong extern "C" void libxr_hpm_i2c_wait_relax_hook(void) definition to yield to a scheduler, enter a low-power wait, or add a board-level short delay while waiting for ADDRHIT, CMPL, or FIFO status. The default fallback only executes one nop, preserving bare-metal timing assumptions when no hook is supplied. WaitUntil() caches the first clock_get_core_clock_ticks_per_us() result and uses an unsigned elapsed-tick comparison to avoid deadline-addition wrap-around. The HPM SDK hpm_csr_get_core_cycle() API returns a 64-bit CYCLE value; the core clock is still assumed not to be dynamically retuned during I2C transfers. 每个实例可通过 SetWaitPolicy() 调整这些超时值。 Per-instance timeout values can be adjusted with SetWaitPolicy().
默认 ISR wrapper 按 HPM_I2Cn、IRQn_I2Cn 和 HPM_DMA_SRC_I2Cn 等 HPM SDK header 宏构建同一个实例资源表;该表已拆到 hpm_i2c_platform.hpp 内部 helper, 并由该 helper 解析 index、IRQ 和 DMA request source;若项目层后续要自行接管同一 IRQ,需要单独调整 ownership 方案。 The default ISR wrapper adapts to multi-series instances through HPM SDK header macros such as HPM_I2Cn, IRQn_I2Cn, and HPM_DMA_SRC_I2Cn. The shared instance resource table lives in the internal hpm_i2c_platform.hpp helper, which resolves index, IRQ, and DMA request source. If project code needs to own the same IRQ later, the ownership scheme should be revised in a separate change.
编译期支持由 HPMSOC_HAS_HPMSDK_I2C 和 __has_include("hpm_i2c_drv.h") 同时 gate;缺少能力宏或裁剪 SDK 头时仍保留 LibXR API 形状,但所有事务返回 NOT_SUPPORT,避免 driver/hpm glob 构建在无 I2C SoC 上因 SDK 头缺失失败。 Compile-time support is gated by both HPMSOC_HAS_HPMSDK_I2C and __has_include("hpm_i2c_drv.h"). When the capability macro or trimmed SDK header is missing, the LibXR API shape remains available but transfer APIs return NOT_SUPPORT, preventing the driver/hpm glob build from failing on SoCs without I2C.
Definition at line 146 of file hpm_i2c.hpp.
|
strong |
HPM I2C 主机寻址模式 / HPM I2C master addressing mode.
| Enumerator | |
|---|---|
| ADDR_7BIT | 7-bit 从地址 / 7-bit slave addressing. |
| ADDR_10BIT | 10-bit 从地址 / 10-bit slave addressing. |
Definition at line 152 of file hpm_i2c.hpp.
|
strong |
HPM I2C 后台事务类型 / HPM I2C asynchronous transfer kind.
Definition at line 196 of file hpm_i2c.hpp.
|
strong |
HPM 主机顺序事务分段类型 / HPM master sequential transfer frame type.
| Enumerator | |
|---|---|
| FIRST | 带 START 和地址阶段 / Includes START and address phase. |
| NEXT | 中间段,不带 START/STOP / Middle frame without START/STOP. |
| LAST | 末段,带 STOP / Final frame with STOP. |
Definition at line 161 of file hpm_i2c.hpp.
|
strong |
HPM 主机扩展事务标志 / HPM master extended transfer flags.
Definition at line 171 of file hpm_i2c.hpp.
| HPMI2C::HPMI2C | ( | LibXRHpmI2cType * | i2c, |
| clock_name_t | clock, | ||
| bool | auto_board_init = true, | ||
| I2C::Configuration | config = {100000} ) |
构造 HPM I2C 主机对象 / Construct an HPM I2C master object.
| i2c | HPM I2C 外设基地址,不能为空 / HPM I2C peripheral base address. Must not be nullptr. |
| clock | HPM 时钟树名称;当板级 helper 未提供时用于开启并查询外设源时钟 / HPM clock name used to enable and query the peripheral source clock when the optional board helper does not provide one. |
| auto_board_init | 若为 true 且存在 board.h,则自动调用板级 I2C 时钟和引脚 初始化 helper / If true and board.h is available, call board I2C clock and pin helper functions automatically. |
| config | 初始 I2C 总线配置;当前 HPM 后端只接受 100 kHz、400 kHz、1 MHz 三个固定速率,其他速率由 SetConfig() 返回 NOT_SUPPORT。默认地址模式为 7-bit, 如需 10-bit 可在构造后调用 SetAddressMode() / Initial I2C bus configuration. The current HPM backend accepts only three fixed rates: 100 kHz, 400 kHz, and 1 MHz. Other rates are rejected by SetConfig(). The default address mode is 7-bit; call SetAddressMode() after construction to switch to 10-bit when needed. |
Definition at line 2300 of file hpm_i2c.cpp.
|
private |
按当前后端限制下发配置并缓存成功配置 / Apply configuration under current backend limits and cache it on success.
Definition at line 2363 of file hpm_i2c.cpp.
|
private |
根据目标固定速率解析 HPM I2C 工作模式 / Resolve HPM I2C operating mode from a fixed target clock rate.
转换 HPM 顺序分段枚举到 SDK 枚举 / Convert HPM sequence frame enum to SDK enum.
从当前地址模式补齐 HPM SDK 事务标志 / Merge current address-mode bit into SDK transfer flags.
Definition at line 2321 of file hpm_i2c.cpp.
|
staticprivate |
|
inlinestaticconstexpr |
返回默认 HPM I2C 忙等超时策略 / Return the default HPM I2C wait policy.
Definition at line 226 of file hpm_i2c.hpp.
|
private |
通过手工 phase 编排执行一笔 blocking 事务 / Execute one blocking transfer through manual phase orchestration.
Definition at line 2350 of file hpm_i2c.cpp.
|
private |
执行一段顺序读事务,不做状态分发 / Execute one sequential read frame without LibXR status dispatch.
Definition at line 2333 of file hpm_i2c.cpp.
|
private |
执行一段顺序写事务,不做状态分发 / Execute one sequential write frame without LibXR status dispatch.
Definition at line 2323 of file hpm_i2c.cpp.
执行一段扩展标志事务,不做状态分发 / Execute one flag-based transfer without LibXR status dispatch.
Definition at line 2342 of file hpm_i2c.cpp.
|
private |
确保 I2C 源时钟已可用 / Ensure the I2C source clock is available.
Definition at line 2359 of file hpm_i2c.cpp.
|
private |
确保控制器已完成一次可用配置 / Ensure the controller has a usable configuration applied.
Definition at line 2361 of file hpm_i2c.cpp.
|
staticprivate |
按 BYTE_8/BYTE_16 格式填充寄存器地址字节 / Fill register address bytes according to BYTE_8/BYTE_16 format.
Definition at line 71 of file hpm_i2c.cpp.
|
inlinestaticprivate |
完成 LibXR 操作状态更新或回调 / Complete LibXR operation status update or callback dispatch.
Definition at line 910 of file hpm_i2c.hpp.
|
inline |
获取当前 HPM 主机寻址模式 / Get current HPM master addressing mode.
Definition at line 293 of file hpm_i2c.hpp.
|
inline |
获取当前缓存的 I2C 源时钟频率 / Get cached I2C source clock frequency.
Definition at line 497 of file hpm_i2c.hpp.
|
staticprivate |
获取指定寻址模式可接受的最大从地址 / Get the maximum valid slave address for the given mode.
Definition at line 56 of file hpm_i2c.cpp.
|
inline |
获取当前实例的忙等超时策略 / Get the current busy-wait timeout policy.
Definition at line 287 of file hpm_i2c.hpp.
|
overridevirtual |
从 I2C 从设备寄存器或存储器地址读取字节 / Read bytes from an I2C slave register or memory address.
该接口先发送寄存器/存储器地址,再进入读阶段。BYTE_8 只发送 mem_addr 低 8 位; BYTE_16 按高字节在前、低字节在后的顺序发送。 This API sends the register/memory address before the read phase. BYTE_8 sends only the low 8 bits of mem_addr; BYTE_16 sends the high byte first, then the low byte.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address for the current addressing mode, without the R/W bit. |
| mem_addr | 读阶段前发送的寄存器或存储器地址 / Register or memory address sent before reading. |
| read_data | 目标缓冲区;size_ 为 0 时不访问总线并返回 OK。非零长度时 addr_ 必须非空,且 size_ 不超过 I2C_SOC_TRANSFER_COUNT_MAX / Destination buffer. A zero-size buffer completes with OK without bus access. For non-zero size, addr_ must be non-null and size_ must not exceed I2C_SOC_TRANSFER_COUNT_MAX. |
| op | LibXR 读操作描述符,见类注释中的操作模式说明 / LibXR read operation descriptor. See class-level operation mode notes. |
| mem_addr_size | 寄存器地址宽度:BYTE_8 或 BYTE_16 / Register address width: BYTE_8 or BYTE_16. |
| in_isr | 仅用于 CALLBACK/POLLING 完成分发的中断上下文标志 / ISR-context flag forwarded only to CALLBACK/POLLING completion handling. |
Implements LibXR::I2C.
Definition at line 2403 of file hpm_i2c.cpp.
|
overridevirtual |
向 I2C 从设备寄存器或存储器地址写入字节 / Write bytes to an I2C slave register or memory address.
该接口先发送寄存器/存储器地址,再发送载荷。BYTE_8 只发送 mem_addr 低 8 位; BYTE_16 按高字节在前、低字节在后的顺序发送。零长度载荷合法,只写地址字节。 This API sends the register/memory address before the payload. BYTE_8 sends only the low 8 bits of mem_addr; BYTE_16 sends the high byte first, then the low byte. A zero-size payload is valid and writes only the address bytes.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address for the current addressing mode, without the R/W bit. |
| mem_addr | 载荷前发送的寄存器或存储器地址 / Register or memory address sent before the payload. |
| write_data | 源载荷缓冲区;非零长度时 addr_ 必须非空;地址字节加载荷长度 不能超过 I2C_SOC_TRANSFER_COUNT_MAX / Source payload buffer. For non-zero size, addr_ must be non-null. Address bytes plus payload size must not exceed I2C_SOC_TRANSFER_COUNT_MAX. |
| op | LibXR 写操作描述符,见类注释中的操作模式说明 / LibXR write operation descriptor. See class-level operation mode notes. |
| mem_addr_size | 寄存器地址宽度:BYTE_8 或 BYTE_16 / Register address width: BYTE_8 or BYTE_16. |
| in_isr | 仅用于 CALLBACK/POLLING 完成分发的中断上下文标志 / ISR-context flag forwarded only to CALLBACK/POLLING completion handling. |
Implements LibXR::I2C.
Definition at line 2413 of file hpm_i2c.cpp.
|
overridevirtual |
从 I2C 从设备读取字节 / Read bytes from an I2C slave.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address for the current addressing mode, without the R/W bit. |
| read_data | 目标缓冲区;size_ 为 0 时不访问总线并返回 OK。非零长度时 addr_ 必须非空,且 size_ 不超过 I2C_SOC_TRANSFER_COUNT_MAX / Destination buffer. A zero-size buffer completes with OK without bus access. For non-zero size, addr_ must be non-null and size_ must not exceed I2C_SOC_TRANSFER_COUNT_MAX. |
| op | LibXR 读操作描述符,见类注释中的操作模式说明 / LibXR read operation descriptor. See class-level operation mode notes. |
| in_isr | 仅用于 CALLBACK/POLLING 完成分发的中断上下文标志 / ISR-context flag forwarded only to CALLBACK/POLLING completion handling. |
Implements LibXR::I2C.
Definition at line 2387 of file hpm_i2c.cpp.
|
private |
复位并按缓存配置重建 I2C 控制器 / Reset and reinitialize the I2C controller with cached configuration.
Definition at line 2376 of file hpm_i2c.cpp.
|
staticprivate |
解析寄存器地址宽度枚举到字节数 / Resolve register-address enum to byte count.
Definition at line 66 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::SequenceRead | ( | uint16_t | slave_addr, |
| RawData | read_data, | ||
| SequenceFrame | frame, | ||
| ReadOperation & | op, | ||
| bool | in_isr = false ) |
执行一段 HPM 主机顺序读事务 / Execute one HPM master sequential read frame.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address in the current addressing mode, without the R/W bit. |
| read_data | 当前分段要读入的数据缓冲区,长度必须大于 0 / Destination buffer for this frame. Size must be greater than 0. |
| frame | 分段类型:FIRST/NEXT/LAST / Frame type: FIRST, NEXT, or LAST. |
| op | LibXR 读操作描述符 / LibXR read operation descriptor. |
| in_isr | 仅用于状态分发的中断上下文标志 / ISR-context flag for status dispatch. |
Definition at line 2435 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::SequenceWrite | ( | uint16_t | slave_addr, |
| ConstRawData | write_data, | ||
| SequenceFrame | frame, | ||
| bool | check_ack, | ||
| WriteOperation & | op, | ||
| bool | in_isr = false ) |
执行一段 HPM 主机顺序写事务 / Execute one HPM master sequential write frame.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address in the current addressing mode, without the R/W bit. |
| write_data | 当前分段要写出的数据,长度必须大于 0 / Payload for this frame. Size must be greater than 0. |
| frame | 分段类型:FIRST/NEXT/LAST / Frame type: FIRST, NEXT, or LAST. |
| check_ack | 是否逐字节检查从机 ACK / Whether to check slave ACK byte by byte. |
| op | LibXR 写操作描述符 / LibXR write operation descriptor. |
| in_isr | 仅用于状态分发的中断上下文标志 / ISR-context flag for status dispatch. |
Definition at line 2424 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::SetAddressMode | ( | AddressMode | mode | ) |
设置 HPM 主机寻址模式并重建控制器 / Set HPM master addressing mode and rebuild the controller.
| mode | 目标寻址模式,ADDR_7BIT 或 ADDR_10BIT / Target addressing mode, either ADDR_7BIT or ADDR_10BIT. |
Definition at line 2309 of file hpm_i2c.cpp.
|
overridevirtual |
应用 I2C 时序配置 / Apply I2C timing configuration.
Implements LibXR::I2C.
Definition at line 2380 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::SetWaitPolicy | ( | WaitPolicy | policy | ) |
设置当前实例的忙等超时策略 / Set the busy-wait timeout policy for this instance.
| policy | 新策略;所有字段必须非零 / New policy. Every field must be nonzero. |
Definition at line 76 of file hpm_i2c.cpp.
|
staticprivate |
判断失败后是否需要重建控制器 / Decide whether the controller should be reinitialized after a failure.
Definition at line 2370 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::TransferWithFlags | ( | uint16_t | slave_addr, |
| ConstRawData | data, | ||
| uint16_t | flags, | ||
| WriteOperation & | op, | ||
| bool | in_isr = false ) |
执行一段 HPM 扩展标志主机写事务 / Execute one HPM master write transfer with extended SDK flags.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address in the current addressing mode, without the R/W bit. |
| data | 要写出的数据缓冲区 / Data buffer to be transmitted. |
| flags | HPM 扩展事务标志组合;READ 位若被传入会被忽略 / Combined HPM extended transfer flags. The READ bit is ignored when provided. |
| op | LibXR 写操作描述符 / LibXR write operation descriptor. |
| in_isr | 仅用于状态分发的中断上下文标志 / ISR-context flag for status dispatch. |
Definition at line 2453 of file hpm_i2c.cpp.
| ErrorCode HPMI2C::TransferWithFlags | ( | uint16_t | slave_addr, |
| RawData | data, | ||
| uint16_t | flags, | ||
| ReadOperation & | op, | ||
| bool | in_isr = false ) |
执行一段 HPM 扩展标志主机事务 / Execute one HPM master transfer with extended SDK flags.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address in the current addressing mode, without the R/W bit. |
| data | 数据缓冲区;按 flags 指示读或写 / Data buffer used for read or write according to flags. |
| flags | HPM 扩展事务标志组合 / Combined HPM extended transfer flags. |
| op | LibXR 读写操作描述符 / LibXR read/write operation descriptor. |
| in_isr | 仅用于状态分发的中断上下文标志 / ISR-context flag for status dispatch. |
Definition at line 2444 of file hpm_i2c.cpp.
|
private |
在 SDA 被拉低且硬件支持时尝试发出 I2C reset clocks / Try to generate I2C reset clocks when SDA is stuck low and the hardware supports it.
Definition at line 2378 of file hpm_i2c.cpp.
|
private |
校验当前寻址模式下的从地址 / Validate slave address for the current addressing mode.
Definition at line 61 of file hpm_i2c.cpp.
|
overridevirtual |
向 I2C 从设备写入字节 / Write bytes to an I2C slave.
| slave_addr | 当前寻址模式下的从设备地址,不包含 R/W 位 / Slave address for the current addressing mode, without the R/W bit. |
| write_data | 源缓冲区;size_ 为 0 时不访问总线并返回 OK。非零长度时 addr_ 必须非空,且 size_ 不超过 I2C_SOC_TRANSFER_COUNT_MAX / Source buffer. A zero-size buffer completes with OK without bus access. For non-zero size, addr_ must be non-null and size_ must not exceed I2C_SOC_TRANSFER_COUNT_MAX. |
| op | LibXR 写操作描述符,见类注释中的操作模式说明 / LibXR write operation descriptor. See class-level operation mode notes. |
| in_isr | 仅用于 CALLBACK/POLLING 完成分发的中断上下文标志 / ISR-context flag forwarded only to CALLBACK/POLLING completion handling. |
Implements LibXR::I2C.
Definition at line 2395 of file hpm_i2c.cpp.
|
private |
当前主机寻址模式 / Current master addressing mode.
Definition at line 926 of file hpm_i2c.hpp.
|
private |
是否自动调用板级初始化 / Whether board init is automatic.
Definition at line 943 of file hpm_i2c.hpp.
|
private |
I2C 源时钟名称 / I2C source clock name.
Definition at line 920 of file hpm_i2c.hpp.
|
private |
是否已有成功配置 / Whether a valid config was applied.
Definition at line 928 of file hpm_i2c.hpp.
|
private |
最近一次成功总线时序配置 / Most recent successful bus-timing config.
Definition at line 922 of file hpm_i2c.hpp.
|
private |
I2C 外设实例 / I2C peripheral instance.
Definition at line 919 of file hpm_i2c.hpp.
|
staticconstexprprivate |
当前 HPM 后端支持的最大 10-bit 从地址 / Maximum 10-bit slave address supported by the current HPM backend.
Definition at line 572 of file hpm_i2c.hpp.
|
staticconstexprprivate |
当前 HPM 后端支持的最大 7-bit 从地址 / Maximum 7-bit slave address supported by the current HPM backend.
Definition at line 566 of file hpm_i2c.hpp.
|
private |
缓存的源时钟频率 / Cached source clock frequency.
Definition at line 921 of file hpm_i2c.hpp.
|
private |
当前忙等超时策略 / Current busy-wait timeout policy.
Definition at line 924 of file hpm_i2c.hpp.