Boboter
Loading...
Searching...
No Matches
HAL::I2C::Controller Class Reference

The I2C hardware abstraction layer's control class. More...

#include <i2c.h>

Public Member Functions

 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 Public Member Functions

static Controller & get_instance ()
 Returns a reference to the static controller instance.

Detailed Description

The I2C hardware abstraction layer's control class.

Constructor & Destructor Documentation

◆ Controller()

HAL::I2C::Controller::Controller ( const Controller & )
delete

Member Function Documentation

◆ 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
configThe device configuration

◆ configure()

void HAL::I2C::Controller::configure ( const bus_config_t & config)

Configures the I2C controller.

Parameters
configThe 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_handleThe handle of the target device
bufferPointer to the buffer where the read data will be stored
sizeNumber of bytes to read
timeout_msOperation 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_handleThe handle of the target device
dataPointer to the buffer containing the data to send
sizeNumber of bytes to write
timeout_msOperation 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_handleThe handle of the target device
write_dataBuffer containing the data to send (register address, ...)
write_sizeNumber of bytes to write before starting the read
read_bufferBuffer where the recieved datawill be stored
read_sizeNumber of bytes to read
timeout_msOperation timeout in milliseconds (default: -1)

The documentation for this class was generated from the following files: