peary::interface::iface_i2c

I2C interface via Kernel I2C module.

#include <peary/interfaces/I2C/i2c.hpp>

Inherits from peary::interface::Interface< i2c_reg_t, i2c_t, iface_i2c_config >

Public Functions

Name
~iface_i2c() overrideDestructor closes the file handle for the I2C module.
iface_i2c() =deleteDelete the default constructor to prevent instantiation without configuration.
i2c_address_t devAddress() constGet the I2C device address.
virtual i2c_t write(const i2c_t & data) overrideWrite a single byte to the I2C bus.
virtual std::pair< i2c_reg_t, i2c_t > write(const std::pair< i2c_reg_t, i2c_t > & data) overrideWrite a byte to a specific register on the I2C device.
virtual dataVector_type write(const i2c_reg_t & reg, const dataVector_type & data) overrideWrite multiple bytes to a specific register on the I2C device.
virtual dataVector_type read(const unsigned int length) overrideRead multiple bytes from the I2C device.
virtual dataVector_type read(const i2c_reg_t & reg, const unsigned int length) overrideRead multiple bytes from a specific register on the I2C device.
dataVector_type wordwrite(const uint16_t & reg, const dataVector_type & data)Write multiple bytes to a 16-bit register on the I2C device.
dataVector_type wordread(const uint16_t reg, const unsigned int length)Read multiple bytes from a 16-bit register on the I2C device.
bool probe(const i2c_reg_t & reg) constProbe the I2C device to check if it is responsive.

Friends

Name
iface_i2c & InterfaceManager::getInterface(const configuration_type & ) Get an instance of the iface_i2c interface from the InterfaceManager.
void InterfaceManager::deleteInterface(iface_i2c * ) Delete an instance of the iface_i2c interface from the InterfaceManager.

Additional inherited members

Public Types inherited from peary::interface::Interface< i2c_reg_t, i2c_t, iface_i2c_config >

Name
using REG_T reg_type Type aliases for register type, data type, configuration type, and data vector type.
using DATA_T data_type
using CONFIG_T configuration_type
using std::vector< data_type > dataVector_type

Public Functions inherited from peary::interface::Interface< i2c_reg_t, i2c_t, iface_i2c_config >

Name
std::string devicePath() constGet the device path associated with the interface.

Protected Functions inherited from peary::interface::Interface< i2c_reg_t, i2c_t, iface_i2c_config >

Name
Interface(const InterfaceConfiguration & config)Constructor for Interface class.
virtual ~Interface() =defaultVirtual destructor for Interface class.

Public Functions Documentation

function ~iface_i2c

  ~iface_i2c() override
  

Destructor closes the file handle for the I2C module.

function iface_i2c

  iface_i2c() =delete
  

Delete the default constructor to prevent instantiation without configuration.

function devAddress

  inline i2c_address_t devAddress() const
  

Get the I2C device address.

Return: The I2C device address

function write

  virtual i2c_t write(
    const i2c_t & data
) override
  

Write a single byte to the I2C bus.

Parameters:

  • data The byte to write

Return: The byte read back from the device (if any)

Reimplements: peary::interface::Interface::write

function write

  virtual std::pair< i2c_reg_t, i2c_t > write(
    const std::pair< i2c_reg_t, i2c_t > & data
) override
  

Write a byte to a specific register on the I2C device.

Parameters:

  • data A pair containing the register address and the byte to write

Return: A pair containing the register address and the byte read back from the device (if any)

Reimplements: peary::interface::Interface::write

function write

  virtual dataVector_type write(
    const i2c_reg_t & reg,
    const dataVector_type & data
) override
  

Write multiple bytes to a specific register on the I2C device.

Parameters:

  • reg The register address to write to
  • data A vector containing the bytes to write

Return: A vector containing the bytes read back from the device (if any)

Reimplements: peary::interface::Interface::write

function read

  virtual dataVector_type read(
    const unsigned int length
) override
  

Read multiple bytes from the I2C device.

Parameters:

  • length The number of bytes to read

Return: A vector containing the bytes read from the device

Reimplements: peary::interface::Interface::read

function read

  virtual dataVector_type read(
    const i2c_reg_t & reg,
    const unsigned int length
) override
  

Read multiple bytes from a specific register on the I2C device.

Parameters:

  • reg The register address to read from
  • length The number of bytes to read

Return: A vector containing the bytes read from the device

Reimplements: peary::interface::Interface::read

function wordwrite

  dataVector_type wordwrite(
    const uint16_t & reg,
    const dataVector_type & data
)
  

Write multiple bytes to a 16-bit register on the I2C device.

Parameters:

  • reg The 16-bit register address to write to
  • data A vector containing the bytes to write

Return: A vector containing the bytes read back from the device (if any)

function wordread

  dataVector_type wordread(
    const uint16_t reg,
    const unsigned int length
)
  

Read multiple bytes from a 16-bit register on the I2C device.

Parameters:

  • reg The 16-bit register address to read from
  • length The number of bytes to read

Return: A vector containing the bytes read from the device

function probe

  bool probe(
    const i2c_reg_t & reg
) const
  

Probe the I2C device to check if it is responsive.

Parameters:

  • reg The register address to probe

Return: True if the device responds, false otherwise

Friends

friend InterfaceManager::getInterface

  friend iface_i2c & InterfaceManager::getInterface(
    const configuration_type & 
);
  

Get an instance of the iface_i2c interface from the InterfaceManager.

Return: A reference to the iface_i2c instance

friend InterfaceManager::deleteInterface

  friend void InterfaceManager::deleteInterface(
    iface_i2c * 
);
  

Delete an instance of the iface_i2c interface from the InterfaceManager.


Updated on 2025-11-14 at 11:31:23 +0100