|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
Manages a single I2C bus. Handles bus initialization and device creation. More...
#include <EspI2c.h>
Public Member Functions | |
| EspI2cBus (const hf_i2c_master_bus_config_t &config) noexcept | |
| Construct a new EspI2cBus. | |
| ~EspI2cBus () noexcept | |
| Destructor. Automatically deinitializes the bus and devices if needed. | |
| EspI2cBus (const EspI2cBus &)=delete | |
| EspI2cBus & | operator= (const EspI2cBus &)=delete |
| EspI2cBus (EspI2cBus &&)=delete | |
| EspI2cBus & | operator= (EspI2cBus &&)=delete |
| bool | Initialize () noexcept |
| Initialize the I2C bus. | |
| bool | Deinitialize () noexcept |
| Deinitialize the I2C bus and remove all devices. | |
| int | CreateDevice (const hf_i2c_device_config_t &device_config) noexcept |
| Create and add a device to the I2C bus. | |
| BaseI2c * | GetDevice (int device_index) noexcept |
| Get device by index (BaseI2c interface). | |
| const BaseI2c * | GetDevice (int device_index) const noexcept |
| Get device by index (const version). | |
| EspI2cDevice * | GetEspDevice (int device_index) noexcept |
| Get ESP-specific device by index. | |
| const EspI2cDevice * | GetEspDevice (int device_index) const noexcept |
| Get ESP-specific device by index (const version). | |
| BaseI2c * | GetDeviceByAddress (hf_u16_t device_address) noexcept |
| Get device by address. | |
| std::size_t | GetDeviceCount () const noexcept |
| Get number of devices on the bus. | |
| bool | RemoveDevice (int device_index) noexcept |
| Remove a device from the bus. | |
| bool | RemoveDeviceByAddress (hf_u16_t device_address) noexcept |
| Remove a device from the bus by address. | |
| BaseI2c * | operator[] (int device_index) noexcept |
| Get device by index with bounds checking. | |
| const BaseI2c * | operator[] (int device_index) const noexcept |
| Get device by index with bounds checking (const version). | |
| EspI2cDevice * | At (int device_index) noexcept |
| Get ESP-specific device by index with bounds checking. | |
| const EspI2cDevice * | At (int device_index) const noexcept |
| Get ESP-specific device by index with bounds checking (const version). | |
| bool | IsValidIndex (int device_index) const noexcept |
| Check if device index is valid. | |
| BaseI2c * | GetFirstDevice () noexcept |
| Get first device on the bus. | |
| const BaseI2c * | GetFirstDevice () const noexcept |
| Get first device on the bus (const version). | |
| BaseI2c * | GetLastDevice () noexcept |
| Get last device on the bus. | |
| const BaseI2c * | GetLastDevice () const noexcept |
| Get last device on the bus (const version). | |
| std::vector< BaseI2c * > | GetAllDevices () noexcept |
| Get all devices as a vector of BaseI2c pointers. | |
| std::vector< const BaseI2c * > | GetAllDevices () const noexcept |
| Get all devices as a vector of const BaseI2c pointers. | |
| std::vector< EspI2cDevice * > | GetAllEspDevices () noexcept |
| Get all ESP-specific devices as a vector. | |
| std::vector< const EspI2cDevice * > | GetAllEspDevices () const noexcept |
| Get all ESP-specific devices as a vector (const version). | |
| int | FindDeviceIndex (hf_u16_t device_address) const noexcept |
| Find device index by address with bounds checking. | |
| std::vector< hf_u16_t > | GetDeviceAddresses () const noexcept |
| Get device addresses as a vector. | |
| bool | HasDevices () const noexcept |
| Check if bus has any devices. | |
| bool | IsEmpty () const noexcept |
| Check if bus is empty (no devices). | |
| bool | ClearAllDevices () noexcept |
| Clear all devices from the bus. | |
| const hf_i2c_master_bus_config_t & | GetConfig () const noexcept |
| Get the bus configuration. | |
| i2c_master_bus_handle_t | GetHandle () const noexcept |
| Get the ESP-IDF bus handle. | |
| int | GetPort () const noexcept |
| Get the I2C port number. | |
| bool | IsInitialized () const noexcept |
| Check if the bus is initialized. | |
| size_t | ScanDevices (std::vector< hf_u16_t > &found_devices, hf_u16_t start_addr=0x08, hf_u16_t end_addr=0x77, hf_u32_t scan_timeout_ms=0) noexcept |
| Scan the I2C bus for devices. | |
| bool | ProbeDevice (hf_u16_t device_addr, hf_u32_t timeout_ms=10) noexcept |
| Probe for device presence on the bus. | |
| bool | ResetBus () noexcept |
| Reset the I2C bus. | |
| hf_i2c_mode_t | GetMode () const noexcept |
| Get the current I2C operation mode. | |
| bool | IsAsyncMode () const noexcept |
| Check if async mode is enabled. | |
| bool | IsSyncMode () const noexcept |
| Check if sync mode is enabled. | |
| bool | SwitchMode (hf_i2c_mode_t new_mode, uint8_t queue_depth=10) noexcept |
| Switch operation mode (recreates bus) | |
Private Member Functions | |
| int | FindDeviceIndexByAddress (hf_u16_t device_address) const noexcept |
| Find device index by address. | |
| hf_i2c_err_t | ConvertEspError (esp_err_t esp_error) const noexcept |
| Convert ESP-IDF error to HardFOC error. | |
| bool | CustomFastProbe (hf_u16_t device_addr, hf_u32_t timeout_ms) noexcept |
| Custom fast I2C probe that works around ESP-IDF's broken probe function. | |
Private Attributes | |
| hf_i2c_master_bus_config_t | config_ |
| Bus configuration. | |
| i2c_master_bus_handle_t | bus_handle_ |
| ESP-IDF bus handle. | |
| bool | initialized_ |
| Initialization status. | |
| PlatformMutex | mutex_ |
| Bus mutex for thread safety. | |
| std::vector< std::unique_ptr< EspI2cDevice > > | devices_ |
| Device instances. | |
| hf_i2c_mode_t | current_mode_ |
| Current operation mode. | |
| hf_i2c_statistics_t | statistics_ |
| Bus-level statistics. | |
| hf_i2c_diagnostics_t | diagnostics_ |
| Bus-level diagnostics. | |
Manages a single I2C bus. Handles bus initialization and device creation.
Provides full configuration and control for the I2C bus, including device management, bus initialization, and ESP-IDF v5.5+ features. Thread-safe device management with proper resource cleanup.
|
explicitnoexcept |
Construct a new EspI2cBus.
| config | Bus configuration |
|
noexcept |
Destructor. Automatically deinitializes the bus and devices if needed.
|
delete |
|
delete |
|
noexcept |
Get ESP-specific device by index with bounds checking (const version).
| device_index | Index of the device (0-based) |
|
noexcept |
Get ESP-specific device by index with bounds checking.
| device_index | Index of the device (0-based) |
|
noexcept |
Clear all devices from the bus.
|
privatenoexcept |
Convert ESP-IDF error to HardFOC error.
| esp_error | ESP-IDF error code |
|
noexcept |
Create and add a device to the I2C bus.
| device_config | Device configuration |
Custom fast I2C probe that works around ESP-IDF's broken probe function.
| device_addr | Device address to probe |
| timeout_ms | Timeout in milliseconds |
|
noexcept |
Deinitialize the I2C bus and remove all devices.
|
noexcept |
Find device index by address with bounds checking.
| device_address | Device address to find |
|
privatenoexcept |
Find device index by address.
| device_address | Device address to find |
|
noexcept |
|
noexcept |
|
noexcept |
Get all ESP-specific devices as a vector (const version).
|
noexcept |
Get all ESP-specific devices as a vector.
|
noexcept |
Get the bus configuration.
|
noexcept |
Get device by index (const version).
| device_index | Index of the device |
|
noexcept |
|
noexcept |
Get device addresses as a vector.
Get device by address.
| device_address | Device address to find |
|
noexcept |
Get number of devices on the bus.
|
noexcept |
Get ESP-specific device by index (const version).
| device_index | Index of the device |
|
noexcept |
Get ESP-specific device by index.
| device_index | Index of the device |
|
noexcept |
Get first device on the bus (const version).
|
noexcept |
Get first device on the bus.
|
noexcept |
Get the ESP-IDF bus handle.
|
noexcept |
Get last device on the bus (const version).
|
noexcept |
Get last device on the bus.
|
noexcept |
Get the current I2C operation mode.
|
noexcept |
Get the I2C port number.
|
noexcept |
Check if bus has any devices.
|
noexcept |
Initialize the I2C bus.
|
noexcept |
Check if async mode is enabled.
|
noexcept |
Check if bus is empty (no devices).
|
noexcept |
Check if the bus is initialized.
|
noexcept |
Check if sync mode is enabled.
|
noexcept |
Check if device index is valid.
| device_index | Index to check |
|
noexcept |
Get device by index with bounds checking (const version).
| device_index | Index of the device (0-based) |
|
noexcept |
Get device by index with bounds checking.
| device_index | Index of the device (0-based) |
Probe for device presence on the bus.
| device_addr | Device address to probe |
| timeout_ms | Timeout in milliseconds (0 = use default 1000ms) |
|
noexcept |
Remove a device from the bus.
| device_index | Index of the device to remove |
|
noexcept |
Remove a device from the bus by address.
| device_address | Address of the device to remove |
|
noexcept |
Reset the I2C bus.
|
noexcept |
Scan the I2C bus for devices.
| found_devices | Vector to store found device addresses |
| start_addr | Starting address for scan (default: 0x08) |
| end_addr | Ending address for scan (default: 0x77) |
| scan_timeout_ms | Timeout for each probe operation (0 = use fast 10ms timeout) |
|
noexcept |
Switch operation mode (recreates bus)
| new_mode | New operation mode to switch to |
| queue_depth | Queue depth for async mode (ignored for sync mode) |
|
private |
ESP-IDF bus handle.
|
private |
Bus configuration.
|
private |
Current operation mode.
|
private |
Device instances.
|
mutableprivate |
Bus-level diagnostics.
|
private |
Initialization status.
|
mutableprivate |
Bus mutex for thread safety.
|
mutableprivate |
Bus-level statistics.