Class I2cDevice¶
Defined in File i2c_device.hpp
Class Documentation¶
-
class I2cDevice¶
Low-level I2C device communication wrapper.
This class provides a clean interface for I2C communication using Linux I2C API. It manages the I2C device file descriptor and provides methods for device detection, register reading/writing, and proper error handling.
Public Functions¶
-
I2cDevice(const std::string &bus_path, uint8_t device_address)¶
Construct a new I2cDevice object.
Opens the I2C bus and configures the slave address. The object is fully initialized upon successful construction following RAII principles.
-
bool is_connected() const¶
Check if the device is connected and responsive.
- Returns:¶
true if device is connected, false otherwise
-
std::optional<uint8_t> read_register(uint8_t reg_address)¶
Read a single byte from a register.
Note
Uses hardware I2C timeout (configured at bus level, typically 1-2 seconds)
-
bool write_register(uint8_t reg_address, uint8_t value)¶
Write a single byte to a register.
Note
Uses hardware I2C timeout (configured at bus level, typically 1-2 seconds)
-
bool read_registers(uint8_t reg_address, uint8_t *buffer, size_t length)¶
Read multiple bytes from consecutive registers.
Performs an I2C combined transaction: write register address, then read data.
Note
Uses hardware I2C timeout (configured at bus level, typically 1-2 seconds) @threadsafe NO - Must not be called from multiple threads concurrently
-
bool write_registers(uint8_t reg_address, const uint8_t *buffer, size_t length)¶
Write multiple bytes to consecutive registers.
Note
Uses hardware I2C timeout (configured at bus level, typically 1-2 seconds) @threadsafe NO - Must not be called from multiple threads concurrently
-
I2cDevice(const std::string &bus_path, uint8_t device_address)¶