Concrete I2C communication adapter for PCA9685 using BaseI2c.
More...
#include <Pca9685Handler.h>
|
| | HalI2cPca9685Comm (BaseI2c &i2c_device) noexcept |
| | Construct the I2C communication adapter.
|
| |
|
Called by pca9685::I2cInterface<HalI2cPca9685Comm> via static dispatch.
|
| bool | Write (uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept |
| | Write data to a device register.
|
| |
| bool | Read (uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept |
| | Read data from a device register.
|
| |
| bool | EnsureInitialized () noexcept |
| | Ensure the I2C bus is initialized and ready.
|
| |
|
| BaseI2c & | i2c_device_ |
| | I2C device interface (not owned).
|
| |
| RtosMutex | i2c_mutex_ |
| | Thread safety for I2C operations.
|
| |
Concrete I2C communication adapter for PCA9685 using BaseI2c.
Implements all methods required by pca9685::I2cInterface<HalI2cPca9685Comm> through the CRTP pattern. This class bridges the HardFOC BaseI2c device interface (where the I2C address is pre-configured on the device) with the PCA9685 driver's I2C interface (which passes the address as a parameter).
Key behaviors:
- Address validation: Every write/read validates that the driver's address matches the BaseI2c device's configured address.
- Register framing: Writes are framed as [register, data...] per I2C convention.
- Thread safety: All I2C operations are mutex-protected.
- Lazy initialization: EnsureInitialized() delegates to BaseI2c.
- Note
- This class does NOT own the BaseI2c device; it must remain valid for the lifetime of this adapter.
- See also
- pca9685::I2cInterface CRTP base class from the PCA9685 driver
◆ HalI2cPca9685Comm()
| HalI2cPca9685Comm::HalI2cPca9685Comm |
( |
BaseI2c & | i2c_device | ) |
|
|
explicitnoexcept |
Construct the I2C communication adapter.
- Parameters
-
| i2c_device | Reference to a BaseI2c device with pre-configured address. |
- Warning
- The BaseI2c device must outlive this adapter.
◆ EnsureInitialized()
| bool HalI2cPca9685Comm::EnsureInitialized |
( |
| ) |
|
|
noexcept |
Ensure the I2C bus is initialized and ready.
- Returns
- true if the BaseI2c device is initialized or was initialized successfully.
◆ Read()
| bool HalI2cPca9685Comm::Read |
( |
uint8_t | addr, |
|
|
uint8_t | reg, |
|
|
uint8_t * | data, |
|
|
size_t | len ) |
|
noexcept |
Read data from a device register.
Sends the register address via BaseI2c::WriteRead() and reads back data.
- Parameters
-
| addr | 7-bit I2C address (validated against BaseI2c device). |
| reg | Register address to read from. |
| data | Buffer to store read data. |
| len | Number of bytes to read. |
- Returns
- true if read succeeded, false on address mismatch or I2C error.
◆ Write()
| bool HalI2cPca9685Comm::Write |
( |
uint8_t | addr, |
|
|
uint8_t | reg, |
|
|
const uint8_t * | data, |
|
|
size_t | len ) |
|
noexcept |
Write data to a device register.
Frames the write as [register_address, data...] and sends via BaseI2c::Write().
- Parameters
-
| addr | 7-bit I2C address (validated against BaseI2c device). |
| reg | Register address to write to. |
| data | Pointer to data buffer. |
| len | Number of bytes to write. |
- Returns
- true if write succeeded, false on address mismatch or I2C error.
◆ i2c_device_
| BaseI2c& HalI2cPca9685Comm::i2c_device_ |
|
private |
I2C device interface (not owned).
◆ i2c_mutex_
| RtosMutex HalI2cPca9685Comm::i2c_mutex_ |
|
mutableprivate |
Thread safety for I2C operations.
The documentation for this class was generated from the following files: