|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
Represents a single I2C device on a bus. More...
#include <EspI2c.h>
Public Member Functions | |
| EspI2cDevice (EspI2cBus *parent, const hf_i2c_device_config_t &config) | |
| Construct a new EspI2cDevice. | |
| ~EspI2cDevice () noexcept override | |
| Destructor. Automatically removes device from bus if needed. | |
| bool | Initialize () noexcept override |
| Initialize the I2C device (no-op if already initialized). | |
| bool | MarkAsDeinitialized () noexcept |
| Mark device as deinitialized without ESP-IDF cleanup. | |
| bool | Deinitialize () noexcept override |
| Deinitialize the device (internal cleanup only) | |
| hf_i2c_err_t | Write (const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override |
| Write data to the I2C device. | |
| hf_i2c_err_t | Read (hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override |
| Read data from the I2C device. | |
| hf_i2c_err_t | WriteRead (const hf_u8_t *tx_data, hf_u16_t tx_length, hf_u8_t *rx_data, hf_u16_t rx_length, hf_u32_t timeout_ms=0) noexcept override |
| Write then read data from the I2C device. | |
| hf_i2c_err_t | WriteAsync (const hf_u8_t *data, hf_u16_t length, hf_i2c_async_callback_t callback, void *user_data=nullptr, hf_u32_t timeout_ms=1000) noexcept |
| Write data to the I2C device asynchronously. | |
| hf_i2c_err_t | ReadAsync (hf_u8_t *data, hf_u16_t length, hf_i2c_async_callback_t callback, void *user_data=nullptr, hf_u32_t timeout_ms=1000) noexcept |
| Read data from the I2C device asynchronously. | |
| hf_i2c_err_t | WriteReadAsync (const hf_u8_t *tx_data, hf_u16_t tx_length, hf_u8_t *rx_data, hf_u16_t rx_length, hf_i2c_async_callback_t callback, void *user_data=nullptr, hf_u32_t timeout_ms=1000) noexcept |
| Write then read data from the I2C device asynchronously. | |
| bool | IsAsyncModeSupported () const noexcept |
| Check if async mode is supported on this device. | |
| bool | IsAsyncOperationInProgress () const noexcept |
| Check if an async operation is currently in progress. | |
| bool | IsSyncOperationInProgress () const noexcept |
| Check if a sync operation is currently in progress. | |
| bool | WaitAsyncOperationComplete (hf_u32_t timeout_ms=0) noexcept |
| Wait for current async operation to complete. | |
| hf_i2c_err_t | GetStatistics (hf_i2c_statistics_t &statistics) const noexcept override |
| Get I2C bus statistics. | |
| hf_i2c_err_t | GetDiagnostics (hf_i2c_diagnostics_t &diagnostics) const noexcept override |
| Get I2C bus diagnostics. | |
| hf_i2c_err_t | ResetStatistics () noexcept override |
| Reset I2C statistics. | |
| i2c_master_dev_handle_t | GetHandle () const noexcept |
| Get the ESP-IDF device handle. | |
| const hf_i2c_device_config_t & | GetConfig () const noexcept |
| Get the device configuration. | |
| hf_u16_t | GetDeviceAddress () const noexcept |
| Get the device address. | |
| hf_i2c_err_t | GetActualClockFrequency (hf_u32_t &actual_freq_hz) const noexcept |
| Get the actual clock frequency for this device. | |
| bool | ProbeDevice () noexcept |
| Probe if the device is present on the bus. | |
| i2c_master_dev_handle_t | GetDeviceHandle () const noexcept |
| Get the ESP-IDF device handle for internal operations. | |
| hf_i2c_async_callback_t | GetCurrentCallback () const noexcept |
| Get current async callback (for static callback bridge). | |
| void * | GetCurrentUserData () const noexcept |
| Get current user data (for static callback bridge). | |
| void | UpdateErrorRecoveryAttempt () noexcept |
| Update error recovery attempt statistics. | |
| hf_i2c_mode_t | GetMode () const noexcept |
| Get the current I2C operation mode for this device. | |
| bool | IsAsyncMode () const noexcept |
| Check if this device is in async mode. | |
| bool | IsSyncMode () const noexcept |
| Check if this device is in sync mode. | |
Public Member Functions inherited from BaseI2c | |
| virtual | ~BaseI2c () noexcept=default |
| Virtual destructor ensures proper cleanup in derived classes. | |
| BaseI2c (const BaseI2c &)=delete | |
| BaseI2c & | operator= (const BaseI2c &)=delete |
| BaseI2c (BaseI2c &&)=delete | |
| BaseI2c & | operator= (BaseI2c &&)=delete |
| bool | EnsureInitialized () noexcept |
| Ensures that the I2C bus is initialized (lazy initialization). | |
| bool | EnsureDeinitialized () noexcept |
| Ensures that the I2C bus is deinitialized (lazy deinitialization). | |
| bool | IsInitialized () const noexcept |
| Checks if the bus is initialized. | |
| virtual bool | Open () noexcept |
| Open the I2C bus (alias for Initialize). | |
| virtual bool | Close () noexcept |
| Close the I2C bus (alias for Deinitialize). | |
| virtual bool | IsDevicePresent () noexcept |
| Check if this device is present on the bus. | |
| virtual bool | WriteByte (hf_u8_t data) noexcept |
| Write a single byte to the I2C device. | |
| virtual bool | ReadByte (hf_u8_t &data) noexcept |
| Read a single byte from the I2C device. | |
| virtual bool | WriteRegister (hf_u8_t reg_addr, hf_u8_t data) noexcept |
| Write to a register on the I2C device. | |
| virtual bool | ReadRegister (hf_u8_t reg_addr, hf_u8_t &data) noexcept |
| Read from a register on the I2C device. | |
| virtual bool | ReadRegisters (hf_u8_t reg_addr, hf_u8_t *data, hf_u16_t length) noexcept |
| Read multiple registers from the I2C device. | |
| virtual hf_i2c_err_t | ResetDiagnostics () noexcept |
| Reset I2C diagnostic information. | |
Private Member Functions | |
| bool | RegisterTemporaryCallback (hf_i2c_async_callback_t callback, void *user_data, hf_u32_t timeout_ms) noexcept |
| Register temporary async callback for single operation. | |
| void | UnregisterTemporaryCallback () noexcept |
| Unregister temporary async callback after operation. | |
| void | StartAsyncOperationTracking () noexcept |
| Start async operation tracking after I2C operation is successfully started. | |
| void | UpdateStatistics (bool success, size_t bytes_transferred, hf_u64_t operation_time_us) noexcept |
| Update statistics with operation result. | |
| void | UpdateErrorStatistics (hf_i2c_err_t error_code) noexcept |
| Update error-specific statistics. | |
| hf_i2c_err_t | ConvertEspError (esp_err_t esp_error) const noexcept |
| Convert ESP-IDF error to HardFOC error. | |
| bool | ValidateOperation (const void *data, hf_u16_t length, hf_i2c_operation_t operation_type) noexcept |
| Common validation for all I2C operations. | |
| bool | SetupSyncOperation (hf_i2c_operation_t operation_type) noexcept |
| Common sync operation setup and cleanup. | |
| void | CleanupSyncOperation () noexcept |
| Common sync operation cleanup. | |
| void | CleanupAsyncOperation () noexcept |
| Common async operation cleanup. | |
| bool | SetupAsyncOperation (hf_i2c_async_callback_t callback, void *user_data, hf_u32_t timeout_ms) noexcept |
| Common async operation setup. | |
Static Private Member Functions | |
| static bool | InternalAsyncCallback (i2c_master_dev_handle_t i2c_dev, const i2c_master_event_data_t *evt_data, void *arg) |
| Internal C callback bridge for ESP-IDF callbacks. | |
Private Attributes | |
| EspI2cBus * | parent_bus_ |
| Parent bus pointer. | |
| i2c_master_dev_handle_t | handle_ |
| ESP-IDF device handle. | |
| hf_i2c_device_config_t | config_ |
| Device configuration. | |
| bool | initialized_ |
| Initialization status. | |
| hf_i2c_statistics_t | statistics_ |
| Per-device statistics. | |
| hf_i2c_diagnostics_t | diagnostics_ |
| Per-device diagnostics. | |
| PlatformMutex | mutex_ |
| Device mutex for thread safety. | |
| hf_i2c_mode_t | device_mode_ |
| Device operation mode (inherited from bus) | |
| bool | async_operation_in_progress_ |
| Is async operation active. | |
| bool | sync_operation_in_progress_ |
| Is sync operation active (mutual exclusion) | |
| hf_i2c_async_callback_t | current_callback_ |
| Current user callback. | |
| void * | current_user_data_ |
| Current user data. | |
| hf_u64_t | async_start_time_ |
| Async operation start time. | |
| hf_i2c_transaction_type_t | current_op_type_ |
| Current operation type. | |
| hf_u16_t | last_write_length_ |
| Length of last write operation for async tracking. | |
| hf_u16_t | last_read_length_ |
| Length of last read operation for async tracking. | |
Additional Inherited Members | |
Protected Member Functions inherited from BaseI2c | |
| BaseI2c () noexcept | |
| Protected default constructor. Initializes base I2C state with default values. | |
Protected Attributes inherited from BaseI2c | |
| bool | initialized_ |
| Initialization status. | |
| hf_i2c_statistics_t | statistics_ |
| I2C operation statistics. | |
| hf_i2c_diagnostics_t | diagnostics_ |
| I2C diagnostic information. | |
Represents a single I2C device on a bus.
Inherits from BaseI2c and delegates operations to the parent bus. Provides full configuration and control for a single I2C device, including per-device clock speed, addressing mode, and ESP-IDF v5.5+ features.
| EspI2cDevice::EspI2cDevice | ( | EspI2cBus * | parent, |
| const hf_i2c_device_config_t & | config ) |
Construct a new EspI2cDevice.
| parent | Pointer to the parent EspI2cBus |
| config | Device configuration |
|
overridenoexcept |
Destructor. Automatically removes device from bus if needed.
|
privatenoexcept |
Common async operation cleanup.
|
privatenoexcept |
Common sync operation cleanup.
|
privatenoexcept |
Convert ESP-IDF error to HardFOC error.
| esp_error | ESP-IDF error code |
|
overridevirtualnoexcept |
Deinitialize the device (internal cleanup only)
This method only handles internal device cleanup. ESP-IDF cleanup is handled by the parent bus.
Implements BaseI2c.
|
noexcept |
Get the actual clock frequency for this device.
| actual_freq_hz | Reference to store actual frequency |
|
noexcept |
Get the device configuration.
|
inlinenoexcept |
Get current async callback (for static callback bridge).
|
inlinenoexcept |
Get current user data (for static callback bridge).
|
virtualnoexcept |
|
inlinenoexcept |
Get the ESP-IDF device handle for internal operations.
|
overridevirtualnoexcept |
Get I2C bus diagnostics.
| diagnostics | Reference to diagnostics structure to fill |
Reimplemented from BaseI2c.
|
noexcept |
Get the ESP-IDF device handle.
|
noexcept |
Get the current I2C operation mode for this device.
|
overridevirtualnoexcept |
Get I2C bus statistics.
| statistics | Reference to statistics structure to fill |
Reimplemented from BaseI2c.
|
overridevirtualnoexcept |
Initialize the I2C device (no-op if already initialized).
Implements BaseI2c.
|
staticprivate |
Internal C callback bridge for ESP-IDF callbacks.
| i2c_dev | ESP-IDF device handle |
| evt_data | Event data from ESP-IDF (i2c_master_event_data_t) |
| arg | User data (pointer to EspI2cDevice) |
|
noexcept |
Check if this device is in async mode.
|
noexcept |
Check if async mode is supported on this device.
|
noexcept |
Check if an async operation is currently in progress.
|
noexcept |
Check if this device is in sync mode.
|
noexcept |
Check if a sync operation is currently in progress.
|
noexcept |
Mark device as deinitialized without ESP-IDF cleanup.
This method is called by the bus when it handles ESP-IDF cleanup. The device should not attempt to remove itself from the ESP-IDF bus.
|
virtualnoexcept |
Probe if the device is present on the bus.
Reimplemented from BaseI2c.
|
overridevirtualnoexcept |
Read data from the I2C device.
| data | Pointer to buffer to store received data |
| length | Number of bytes to read |
| timeout_ms | Timeout in milliseconds (0 = default) |
Implements BaseI2c.
|
noexcept |
Read data from the I2C device asynchronously.
| data | Pointer to buffer to store received data |
| length | Number of bytes to read |
| callback | Callback function for operation completion |
| user_data | User data passed to callback |
| timeout_ms | Timeout to wait for async slot availability (0 = no wait) |
|
privatenoexcept |
Register temporary async callback for single operation.
| callback | User callback to register |
| user_data | User data for callback |
| timeout_ms | Timeout to wait for slot availability |
|
overridevirtualnoexcept |
|
privatenoexcept |
Common async operation setup.
| callback | User callback |
| user_data | User data |
| timeout_ms | Timeout for slot availability |
|
privatenoexcept |
Common sync operation setup and cleanup.
| operation_type | Operation type for logging |
|
inlineprivatenoexcept |
Start async operation tracking after I2C operation is successfully started.
|
privatenoexcept |
Unregister temporary async callback after operation.
|
noexcept |
Update error recovery attempt statistics.
|
privatenoexcept |
Update error-specific statistics.
| error_code | The specific error code to track |
|
privatenoexcept |
Update statistics with operation result.
| success | Operation success status |
| bytes_transferred | Number of bytes transferred |
| operation_time_us | Operation time in microseconds |
|
privatenoexcept |
Common validation for all I2C operations.
| data | Data buffer pointer |
| length | Data length |
| operation_type | Operation type for logging |
|
noexcept |
Wait for current async operation to complete.
| timeout_ms | Timeout in milliseconds (0 = wait indefinitely) |
|
overridevirtualnoexcept |
Write data to the I2C device.
| data | Pointer to data buffer to write |
| length | Number of bytes to write |
| timeout_ms | Timeout in milliseconds (0 = default) |
Implements BaseI2c.
|
noexcept |
Write data to the I2C device asynchronously.
| data | Pointer to data buffer to write |
| length | Number of bytes to write |
| callback | Callback function for operation completion |
| user_data | User data passed to callback |
| timeout_ms | Timeout to wait for async slot availability (0 = no wait) |
|
overridevirtualnoexcept |
Write then read data from the I2C device.
| tx_data | Pointer to data buffer to write |
| tx_length | Number of bytes to write |
| rx_data | Pointer to buffer to store received data |
| rx_length | Number of bytes to read |
| timeout_ms | Timeout in milliseconds (0 = default) |
Implements BaseI2c.
|
noexcept |
Write then read data from the I2C device asynchronously.
| tx_data | Pointer to data buffer to write |
| tx_length | Number of bytes to write |
| rx_data | Pointer to buffer to store received data |
| rx_length | Number of bytes to read |
| callback | Callback function for operation completion |
| user_data | User data passed to callback |
| timeout_ms | Timeout to wait for async slot availability (0 = no wait) |
|
private |
Is async operation active.
|
private |
Async operation start time.
|
private |
Device configuration.
|
private |
Current user callback.
|
private |
Current operation type.
|
private |
Current user data.
|
private |
Device operation mode (inherited from bus)
|
mutableprivate |
Per-device diagnostics.
|
private |
ESP-IDF device handle.
|
private |
Initialization status.
|
private |
Length of last read operation for async tracking.
|
private |
Length of last write operation for async tracking.
|
mutableprivate |
Device mutex for thread safety.
|
private |
Parent bus pointer.
|
mutableprivate |
Per-device statistics.
|
private |
Is sync operation active (mutual exclusion)