The I2C hardware abstraction layer's control class.
More...
#include <i2c.h>
|
| | Controller (const Controller &)=delete |
| Controller & | operator= (const Controller &)=delete |
| void | configure (const bus_config_t &config) |
| | Configures the I2C controller.
|
| void | shutdown () |
| | Safely shuts down the I2C controller and removes all devices.
|
| void | scan_for_devices () const |
| | Scans for I2C devices and outputs all found addresses to the serial log.
|
| i2c_master_dev_handle_t | add_device (const device_config_t &config) |
| | Adds a device to the I2C bus and returns its handle.
|
| i2c_master_bus_handle_t | get_bus_handle () const |
| | Gets the controller's I2C bus handle.
|
| void | write (i2c_master_dev_handle_t device_handle, const uint8_t *data, size_t size, int32_t timeout_ms=-1) const |
| | Writes data to a specific device.
|
| void | read (i2c_master_dev_handle_t device_handle, uint8_t *buffer, size_t size, int32_t timeout_ms=-1) const |
| | Reads data from a specific device (For reading data, write_read should be preferred, this function only exists to add support for legacy devices).
|
| void | write_read (i2c_master_dev_handle_t device_handle, const uint8_t *write_data, size_t write_size, uint8_t *read_buffer, size_t read_size, int32_t timeout_ms=-1) const |
| | Write-read operation (Repeated Start, Recommended for reading on most devices).
|
|
| static Controller & | get_instance () |
| | Returns a reference to the static controller instance.
|
The I2C hardware abstraction layer's control class.
◆ Controller()
| HAL::I2C::Controller::Controller |
( |
const Controller & | | ) |
|
|
delete |
◆ add_device()
| i2c_master_dev_handle_t HAL::I2C::Controller::add_device |
( |
const device_config_t & | config | ) |
|
Adds a device to the I2C bus and returns its handle.
- Note
- If controller is not registered,
nullptr will be returned, which will likely bring the firmware to crash later in the program
- Returns
- The created device handle
- Parameters
-
| config | The device configuration |
◆ configure()
| void HAL::I2C::Controller::configure |
( |
const bus_config_t & | config | ) |
|
Configures the I2C controller.
- Parameters
-
| config | The config struct to use |
◆ get_bus_handle()
| i2c_master_bus_handle_t HAL::I2C::Controller::get_bus_handle |
( |
| ) |
const |
|
inlinenodiscard |
Gets the controller's I2C bus handle.
- Returns
- The bus handle
◆ get_instance()
| Controller & HAL::I2C::Controller::get_instance |
( |
| ) |
|
|
inlinestatic |
Returns a reference to the static controller instance.
- Note
- The instance will be created on the first call of this function
- Returns
- Reference to the controller object
◆ operator=()
| Controller & HAL::I2C::Controller::operator= |
( |
const Controller & | | ) |
|
|
delete |
◆ read()
| void HAL::I2C::Controller::read |
( |
i2c_master_dev_handle_t | device_handle, |
|
|
uint8_t * | buffer, |
|
|
size_t | size, |
|
|
int32_t | timeout_ms = -1 ) const |
Reads data from a specific device (For reading data, write_read should be preferred, this function only exists to add support for legacy devices).
- Parameters
-
| device_handle | The handle of the target device |
| buffer | Pointer to the buffer where the read data will be stored |
| size | Number of bytes to read |
| timeout_ms | Operation timeout in milliseconds (default: -1) |
◆ scan_for_devices()
| void HAL::I2C::Controller::scan_for_devices |
( |
| ) |
const |
Scans for I2C devices and outputs all found addresses to the serial log.
◆ shutdown()
| void HAL::I2C::Controller::shutdown |
( |
| ) |
|
Safely shuts down the I2C controller and removes all devices.
◆ write()
| void HAL::I2C::Controller::write |
( |
i2c_master_dev_handle_t | device_handle, |
|
|
const uint8_t * | data, |
|
|
size_t | size, |
|
|
int32_t | timeout_ms = -1 ) const |
Writes data to a specific device.
- Parameters
-
| device_handle | The handle of the target device |
| data | Pointer to the buffer containing the data to send |
| size | Number of bytes to write |
| timeout_ms | Operation timeout in milliseconds (default: -1) |
◆ write_read()
| void HAL::I2C::Controller::write_read |
( |
i2c_master_dev_handle_t | device_handle, |
|
|
const uint8_t * | write_data, |
|
|
size_t | write_size, |
|
|
uint8_t * | read_buffer, |
|
|
size_t | read_size, |
|
|
int32_t | timeout_ms = -1 ) const |
Write-read operation (Repeated Start, Recommended for reading on most devices).
- Parameters
-
| device_handle | The handle of the target device |
| write_data | Buffer containing the data to send (register address, ...) |
| write_size | Number of bytes to write before starting the read |
| read_buffer | Buffer where the recieved datawill be stored |
| read_size | Number of bytes to read |
| timeout_ms | Operation timeout in milliseconds (default: -1) |
The documentation for this class was generated from the following files: