ESPHome  1.15.2
Public Member Functions | Protected Attributes
esphome::i2c::I2CDevice Class Reference

All components doing communication on the I2C bus should subclass I2CDevice. More...

#include <i2c.h>

Inheritance diagram for esphome::i2c::I2CDevice:
esphome::ade7953::ADE7953 esphome::ads1115::ADS1115Component esphome::aht10::AHT10Component esphome::am2320::AM2320Component esphome::apds9960::APDS9960 esphome::as3935_i2c::I2CAS3935Component esphome::bh1750::BH1750Sensor esphome::bme280::BME280Component esphome::bme680::BME680Component esphome::bmp085::BMP085Component esphome::bmp280::BMP280Component esphome::ccs811::CCS811Component esphome::dht12::DHT12Component esphome::hdc1080::HDC1080Component esphome::hm3301::HM3301Component esphome::hmc5883l::HMC5883LComponent esphome::htu21d::HTU21DComponent esphome::ina219::INA219Component esphome::ina226::INA226Component esphome::ina3221::INA3221Component esphome::lcd_pcf8574::PCF8574LCDDisplay esphome::mcp23008::MCP23008 esphome::mcp23016::MCP23016 esphome::mcp23017::MCP23017 esphome::mpr121::MPR121Component esphome::mpu6050::MPU6050Component esphome::ms5611::MS5611Component esphome::pca9685::PCA9685Output esphome::pcf8574::PCF8574Component esphome::qmc5883l::QMC5883LComponent esphome::scd30::SCD30Component esphome::sgp30::SGP30Component esphome::sht3xd::SHT3XDComponent esphome::shtcx::SHTCXComponent esphome::sps30::SPS30Component esphome::ssd1306_i2c::I2CSSD1306 esphome::sts3x::STS3XComponent esphome::sx1509::SX1509Component esphome::tcs34725::TCS34725Component esphome::tlc59208f::TLC59208FOutput esphome::tmp117::TMP117Component esphome::tsl2561::TSL2561Sensor esphome::ttp229_lsf::TTP229LSFComponent esphome::vl53l0x::VL53L0XSensor

Public Member Functions

 I2CDevice ()=default
 
 I2CDevice (I2CComponent *parent, uint8_t address)
 
void set_i2c_address (uint8_t address)
 Manually set the i2c address of this device. More...
 
void set_i2c_parent (I2CComponent *parent)
 Manually set the parent i2c bus for this device. More...
 
I2CRegister reg (uint8_t a_register)
 
bool read_bytes (uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion=0)
 Read len amount of bytes from a register into data. More...
 
bool read_bytes_raw (uint8_t *data, uint8_t len)
 
template<size_t N>
optional< std::array< uint8_t, N > > read_bytes (uint8_t a_register)
 
template<size_t N>
optional< std::array< uint8_t, N > > read_bytes_raw ()
 
bool read_bytes_16 (uint8_t a_register, uint16_t *data, uint8_t len, uint32_t conversion=0)
 Read len amount of 16-bit words (MSB first) from a register into data. More...
 
bool read_byte (uint8_t a_register, uint8_t *data, uint32_t conversion=0)
 Read a single byte from a register into the data variable. Return true if successful. More...
 
optional< uint8_t > read_byte (uint8_t a_register)
 
bool read_byte_16 (uint8_t a_register, uint16_t *data, uint32_t conversion=0)
 Read a single 16-bit words (MSB first) from a register into the data variable. Return true if successful. More...
 
bool write_bytes (uint8_t a_register, const uint8_t *data, uint8_t len)
 Write len amount of 8-bit bytes to the specified register. More...
 
bool write_bytes_raw (const uint8_t *data, uint8_t len)
 
bool write_bytes (uint8_t a_register, const std::vector< uint8_t > &data)
 Write a vector of data to a register. More...
 
bool write_bytes_raw (const std::vector< uint8_t > &data)
 
template<size_t N>
bool write_bytes (uint8_t a_register, const std::array< uint8_t, N > &data)
 
template<size_t N>
bool write_bytes_raw (const std::array< uint8_t, N > &data)
 
bool write_bytes_16 (uint8_t a_register, const uint16_t *data, uint8_t len)
 Write len amount of 16-bit words (MSB first) to the specified register. More...
 
bool write_byte (uint8_t a_register, uint8_t data)
 Write a single byte of data into the specified register. Return true if successful. More...
 
bool write_byte_16 (uint8_t a_register, uint16_t data)
 Write a single 16-bit word of data into the specified register. Return true if successful. More...
 

Protected Attributes

uint8_t address_ {0x00}
 
I2CComponentparent_ {nullptr}
 

Detailed Description

All components doing communication on the I2C bus should subclass I2CDevice.

This class stores 1. the address of the i2c device and has a helper function to allow users to manually set the address and 2. stores a reference to the "parent" I2CComponent.

All this class basically does is to expose all helper functions from I2CComponent.

Definition at line 163 of file i2c.h.

Constructor & Destructor Documentation

◆ I2CDevice() [1/2]

esphome::i2c::I2CDevice::I2CDevice ( )
default

◆ I2CDevice() [2/2]

esphome::i2c::I2CDevice::I2CDevice ( I2CComponent parent,
uint8_t  address 
)
inline

Definition at line 166 of file i2c.h.

Member Function Documentation

◆ read_byte() [1/2]

bool esphome::i2c::I2CDevice::read_byte ( uint8_t  a_register,
uint8_t *  data,
uint32_t  conversion = 0 
)

Read a single byte from a register into the data variable. Return true if successful.

Definition at line 184 of file i2c.cpp.

◆ read_byte() [2/2]

optional<uint8_t> esphome::i2c::I2CDevice::read_byte ( uint8_t  a_register)
inline

Definition at line 216 of file i2c.h.

◆ read_byte_16()

bool esphome::i2c::I2CDevice::read_byte_16 ( uint8_t  a_register,
uint16_t *  data,
uint32_t  conversion = 0 
)

Read a single 16-bit words (MSB first) from a register into the data variable. Return true if successful.

Definition at line 196 of file i2c.cpp.

◆ read_bytes() [1/2]

bool esphome::i2c::I2CDevice::read_bytes ( uint8_t  a_register,
uint8_t *  data,
uint8_t  len,
uint32_t  conversion = 0 
)

Read len amount of bytes from a register into data.

Optionally with a conversion time after writing the register value to the bus.

Parameters
a_registerThe register number to write to the bus before reading.
dataAn array to store len amount of 8-bit bytes into.
lenThe amount of bytes to request and write into data.
conversionThe time in ms between writing the register value and reading out the value.
Returns
If the operation was successful.

Definition at line 181 of file i2c.cpp.

◆ read_bytes() [2/2]

template<size_t N>
optional<std::array<uint8_t, N> > esphome::i2c::I2CDevice::read_bytes ( uint8_t  a_register)
inline

Definition at line 188 of file i2c.h.

◆ read_bytes_16()

bool esphome::i2c::I2CDevice::read_bytes_16 ( uint8_t  a_register,
uint16_t *  data,
uint8_t  len,
uint32_t  conversion = 0 
)

Read len amount of 16-bit words (MSB first) from a register into data.

Parameters
a_registerThe register number to write to the bus before reading.
dataAn array to store len amount of 16-bit words into.
lenThe amount of 16-bit words to request and write into data.
conversionThe time in ms between writing the register value and reading out the value.
Returns
If the operation was successful.

Definition at line 193 of file i2c.cpp.

◆ read_bytes_raw() [1/2]

bool esphome::i2c::I2CDevice::read_bytes_raw ( uint8_t *  data,
uint8_t  len 
)
inline

Definition at line 186 of file i2c.h.

◆ read_bytes_raw() [2/2]

template<size_t N>
optional<std::array<uint8_t, N> > esphome::i2c::I2CDevice::read_bytes_raw ( )
inline

Definition at line 195 of file i2c.h.

◆ reg()

I2CRegister esphome::i2c::I2CDevice::reg ( uint8_t  a_register)
inline

Definition at line 174 of file i2c.h.

◆ set_i2c_address()

void esphome::i2c::I2CDevice::set_i2c_address ( uint8_t  address)

Manually set the i2c address of this device.

Definition at line 180 of file i2c.cpp.

◆ set_i2c_parent()

void esphome::i2c::I2CDevice::set_i2c_parent ( I2CComponent parent)

Manually set the parent i2c bus for this device.

Definition at line 205 of file i2c.cpp.

◆ write_byte()

bool esphome::i2c::I2CDevice::write_byte ( uint8_t  a_register,
uint8_t  data 
)

Write a single byte of data into the specified register. Return true if successful.

Definition at line 190 of file i2c.cpp.

◆ write_byte_16()

bool esphome::i2c::I2CDevice::write_byte_16 ( uint8_t  a_register,
uint16_t  data 
)

Write a single 16-bit word of data into the specified register. Return true if successful.

Definition at line 202 of file i2c.cpp.

◆ write_bytes() [1/3]

bool esphome::i2c::I2CDevice::write_bytes ( uint8_t  a_register,
const uint8_t *  data,
uint8_t  len 
)

Write len amount of 8-bit bytes to the specified register.

Parameters
a_registerThe register to write the values to.
dataAn array from which len bytes of data will be written to the bus.
lenThe amount of bytes to write to the bus.
Returns
If the operation was successful.

Definition at line 187 of file i2c.cpp.

◆ write_bytes() [2/3]

bool esphome::i2c::I2CDevice::write_bytes ( uint8_t  a_register,
const std::vector< uint8_t > &  data 
)
inline

Write a vector of data to a register.

Parameters
a_registerThe register to write to.
dataThe data to write.
Returns
If the operation was successful.

Definition at line 244 of file i2c.h.

◆ write_bytes() [3/3]

template<size_t N>
bool esphome::i2c::I2CDevice::write_bytes ( uint8_t  a_register,
const std::array< uint8_t, N > &  data 
)
inline

Definition at line 249 of file i2c.h.

◆ write_bytes_16()

bool esphome::i2c::I2CDevice::write_bytes_16 ( uint8_t  a_register,
const uint16_t *  data,
uint8_t  len 
)

Write len amount of 16-bit words (MSB first) to the specified register.

Parameters
a_registerThe register to write the values to.
dataAn array from which len 16-bit words of data will be written to the bus.
lenThe amount of bytes to write to the bus.
Returns
If the operation was successful.

Definition at line 199 of file i2c.cpp.

◆ write_bytes_raw() [1/3]

bool esphome::i2c::I2CDevice::write_bytes_raw ( const uint8_t *  data,
uint8_t  len 
)
inline

Definition at line 234 of file i2c.h.

◆ write_bytes_raw() [2/3]

bool esphome::i2c::I2CDevice::write_bytes_raw ( const std::vector< uint8_t > &  data)
inline

Definition at line 247 of file i2c.h.

◆ write_bytes_raw() [3/3]

template<size_t N>
bool esphome::i2c::I2CDevice::write_bytes_raw ( const std::array< uint8_t, N > &  data)
inline

Definition at line 252 of file i2c.h.

Field Documentation

◆ address_

uint8_t esphome::i2c::I2CDevice::address_ {0x00}
protected

Definition at line 272 of file i2c.h.

◆ parent_

I2CComponent* esphome::i2c::I2CDevice::parent_ {nullptr}
protected

Definition at line 273 of file i2c.h.


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