I2CBusDMA
上游未提供类型说明。
构造与析构
1I2CBusDMA
I2CBusDMA::I2CBusDMA (I2C_HandleTypeDef *hi2c, BusPins pins)
使用 HAL I2C 句柄构造总线对象 hi2c 要绑定的 HAL I2C 句柄 pins 当前总线的 SCL/SDA 引脚定义
bsp/i2c_driver/I2CBusDMA.hpp:49成员函数
20clearTransferState
void I2CBusDMA::clearTransferState ()
清空当前事务的软件状态
bsp/i2c_driver/I2CBusDMA.hpp:171completeFromISR
void I2CBusDMA::completeFromISR (bool success, uint32_t hal_error)
在 ISR 中记录完成状态并唤醒等待线程 success 本次完成是否成功 hal_error HAL 层返回的错误码
bsp/i2c_driver/I2CBusDMA.hpp:166failAndRecover
bool I2CBusDMA::failAndRecover (Error error, uint32_t hal_error)
记录失败原因并执行恢复流程 error 本次失败的抽象错误码 hal_error 本次失败对应的 HAL 错误码 始终返回 false,便于直接作为失败出口
bsp/i2c_driver/I2CBusDMA.hpp:179fromHandle
I2CBusDMA * I2CBusDMA::fromHandle (I2C_HandleTypeDef *hi2c)
I2CBusDMA 根据 HAL 句柄反查实例 hi2c HAL I2C 句柄 I2CBusDMA 对应的实例,不存在则返回空指针
bsp/i2c_driver/I2CBusDMA.hpp:130handle
I2C_HandleTypeDef * I2CBusDMA::handle () const
获取底层 HAL I2C 句柄 当前绑定的 HAL I2C 句柄
bsp/i2c_driver/I2CBusDMA.hpp:55isBusy
bool I2CBusDMA::isBusy () const
查询总线当前是否忙碌 当前是否仍有事务未完成,或 HAL 状态尚未回到 READY
bsp/i2c_driver/I2CBusDMA.hpp:61lastError
Error I2CBusDMA::lastError () const
获取最近一次事务的抽象错误码 最近一次事务记录的错误状态
bsp/i2c_driver/I2CBusDMA.hpp:67lastHalError
uint32_t I2CBusDMA::lastHalError () const
获取最近一次事务的 HAL 原始错误码 最近一次事务记录的 HAL 错误码
bsp/i2c_driver/I2CBusDMA.hpp:72memRead
bool I2CBusDMA::memRead (uint8_t device_addr_7bit, uint8_t reg, uint8_t *data, uint16_t len, uint32_t timeout_ms)
发起一次带寄存器地址的 DMA 读事务 device_addr_7bit 7 位设备地址 reg 目标寄存器地址 data 读数据缓冲区 len 读取字节数 timeout_ms 等待完成超时时间,单位毫秒 事务是否成功完成
bsp/i2c_driver/I2CBusDMA.hpp:83memWrite
bool I2CBusDMA::memWrite (uint8_t device_addr_7bit, uint8_t device_reg, const uint8_t *data, uint16_t len, uint32_t timeout_ms)
发起一次带寄存器地址的 DMA 写事务 device_addr_7bit 7 位设备地址 device_reg 目标寄存器地址 data 写数据缓冲区 len 写入字节数 timeout_ms 等待完成超时时间,单位毫秒 事务是否成功完成
bsp/i2c_driver/I2CBusDMA.hpp:94onErrorFromISR
void I2CBusDMA::onErrorFromISR ()
在 ISR 中上报事务错误
bsp/i2c_driver/I2CBusDMA.hpp:143onRxCompleteFromISR
void I2CBusDMA::onRxCompleteFromISR ()
在 ISR 中上报接收完成
bsp/i2c_driver/I2CBusDMA.hpp:139onTxCompleteFromISR
void I2CBusDMA::onTxCompleteFromISR ()
在 ISR 中上报发送完成
bsp/i2c_driver/I2CBusDMA.hpp:135prepareTransfer
bool I2CBusDMA::prepareTransfer ()
在启动 DMA 前准备一次事务 当前是否允许启动新事务
bsp/i2c_driver/I2CBusDMA.hpp:152read
bool I2CBusDMA::read (uint8_t device_addr_7bit, uint8_t *data, uint16_t len, uint32_t timeout_ms)
发起一次原始 DMA 读事务 device_addr_7bit 7 位设备地址 data 读数据缓冲区 len 读取字节数 timeout_ms 等待完成超时时间,单位毫秒 事务是否成功完成
bsp/i2c_driver/I2CBusDMA.hpp:108recover
bool I2CBusDMA::recover ()
尝试恢复当前 I2C 总线 恢复后总线是否重新回到可用状态
bsp/i2c_driver/I2CBusDMA.hpp:123recoverBusLines
bool I2CBusDMA::recoverBusLines ()
上游未提供说明。
bsp/i2c_driver/I2CBusDMA.hpp:181registerInstance
bool I2CBusDMA::registerInstance (I2CBusDMA *instance)
把实例注册到静态反查表 instance 要注册的总线对象 注册是否成功
bsp/i2c_driver/I2CBusDMA.hpp:188waitForTransfer
bool I2CBusDMA::waitForTransfer (uint32_t timeout_ms)
阻塞等待当前事务完成 timeout_ms 等待完成超时时间,单位毫秒 当前事务是否成功完成
bsp/i2c_driver/I2CBusDMA.hpp:159write
bool I2CBusDMA::write (uint8_t device_addr_7bit, const uint8_t *data, uint16_t len, uint32_t timeout_ms)
发起一次原始 DMA 写事务 device_addr_7bit 7 位设备地址 data 写数据缓冲区 len 写入字节数 timeout_ms 等待完成超时时间,单位毫秒 事务是否成功完成
bsp/i2c_driver/I2CBusDMA.hpp:117成员变量
12MaxInstances
std::size_t I2CBusDMA::MaxInstances
上游未提供说明。
bsp/i2c_driver/I2CBusDMA.hpp:146completed_
volatile bool I2CBusDMA::completed_
当前事务是否已收到完成记录
bsp/i2c_driver/I2CBusDMA.hpp:194completed_transfer_id_
volatile uint32_t I2CBusDMA::completed_transfer_id_
最近一次完成记录对应的事务编号
bsp/i2c_driver/I2CBusDMA.hpp:197current_transfer_id_
volatile uint32_t I2CBusDMA::current_transfer_id_
当前正在等待的事务编号
bsp/i2c_driver/I2CBusDMA.hpp:196hi2c_
I2C_HandleTypeDef* I2CBusDMA::hi2c_
绑定的 HAL I2C 句柄
bsp/i2c_driver/I2CBusDMA.hpp:190instances_
I2CBusDMA * I2CBusDMA::instances_ [MaxInstances]
所有 bus 实例共享的 HAL 句柄反查表
bsp/i2c_driver/I2CBusDMA.hpp:201last_error_
volatile Error I2CBusDMA::last_error_
最近一次事务记录的抽象错误状态
bsp/i2c_driver/I2CBusDMA.hpp:198last_hal_error_
volatile uint32_t I2CBusDMA::last_hal_error_
最近一次事务记录的 HAL 错误码
bsp/i2c_driver/I2CBusDMA.hpp:199next_transfer_id_
volatile uint32_t I2CBusDMA::next_transfer_id_
下一次启动事务时要分配的事务编号
bsp/i2c_driver/I2CBusDMA.hpp:195pins_
BusPins I2CBusDMA::pins_
当前总线的引脚定义
bsp/i2c_driver/I2CBusDMA.hpp:191transmitting_
volatile bool I2CBusDMA::transmitting_
当前是否已有事务启动且尚未完成收敛
bsp/i2c_driver/I2CBusDMA.hpp:193waiting_thread_
osThreadId_t I2CBusDMA::waiting_thread_
当前阻塞等待事务完成的线程句柄
bsp/i2c_driver/I2CBusDMA.hpp:192嵌套类型
2上游未提供说明。
bsp/i2c_driver/I2CBusDMA.hpp:20Error
描述一次总线事务的最终错误状态
Busy- 总线或驱动当前忙碌,无法启动新事务
HalError- HAL 在事务过程中报告错误
InvalidContext- 调用上下文不是可阻塞等待的 CMSIS 线程
InvalidHandle- HAL I2C 句柄无效
None- 最近一次事务成功完成
RecoveryFailed- 失败后的恢复流程也未成功
StartFailed- DMA 事务启动失败
Timeout- 等待完成超时