ESPHome 2025.10.0-dev
Loading...
Searching...
No Matches
esphome::sensirion_common::SensirionI2CDevice Class Reference

#include <i2c_sensirion.h>

Inheritance diagram for esphome::sensirion_common::SensirionI2CDevice:
esphome::i2c::I2CDevice esphome::scd30::SCD30Component esphome::scd4x::SCD4XComponent esphome::sdp3x::SDP3XComponent esphome::sen5x::SEN5XComponent esphome::sfa30::SFA30Component esphome::sgp30::SGP30Component esphome::sgp4x::SGP4xComponent esphome::sht3xd::SHT3XDComponent esphome::sht4x::SHT4XComponent esphome::shtcx::SHTCXComponent esphome::sps30::SPS30Component esphome::sts3x::STS3XComponent

Public Types

enum  CommandLen : uint8_t { ADDR_8_BIT = 1 , ADDR_16_BIT = 2 }
 

Public Member Functions

bool read_data (uint16_t *data, uint8_t len)
 Read data words from I2C device.
 
bool read_data (uint16_t &data)
 Read 1 data word from I2C device.
 
bool get_register (uint16_t command, uint16_t *data, uint8_t len, uint8_t delay=0)
 get data words from I2C register.
 
bool get_register (uint16_t i2c_register, uint16_t &data, uint8_t delay=0)
 Read 1 data word from 16 bit I2C register.
 
bool get_8bit_register (uint8_t i2c_register, uint16_t *data, uint8_t len, uint8_t delay=0)
 get data words from I2C register.
 
bool get_8bit_register (uint8_t i2c_register, uint16_t &data, uint8_t delay=0)
 Read 1 data word from 8 bit I2C register.
 
template<class T >
bool write_command (T i2c_register)
 Write a command to the I2C device.
 
template<class T >
bool write_command (T i2c_register, uint16_t data)
 Write a command and one data word to the I2C device .
 
template<class T >
bool write_command (T i2c_register, const std::vector< uint16_t > &data)
 Write a command with arguments as words.
 
template<class T >
bool write_command (T i2c_register, const uint16_t *data, uint8_t len)
 Write a command with arguments as words.
 
- Public Member Functions inherited from esphome::i2c::I2CDevice
 I2CDevice ()=default
 we use the C++ default constructor
 
void set_i2c_address (uint8_t address)
 We store the address of the device on the bus.
 
uint8_t get_i2c_address () const
 Returns the I2C address of the object.
 
void set_i2c_bus (I2CBus *bus)
 we store the pointer to the I2CBus to use
 
I2CRegister reg (uint8_t a_register)
 calls the I2CRegister constructor
 
I2CRegister16 reg16 (uint16_t a_register)
 calls the I2CRegister16 constructor
 
ErrorCode read (uint8_t *data, size_t len) const
 reads an array of bytes from the device using an I2CBus
 
ErrorCode read_register (uint8_t a_register, uint8_t *data, size_t len)
 reads an array of bytes from a specific register in the I²C device
 
ErrorCode read_register16 (uint16_t a_register, uint8_t *data, size_t len)
 reads an array of bytes from a specific register in the I²C device
 
ErrorCode write (const uint8_t *data, size_t len) const
 writes an array of bytes to a device using an I2CBus
 
ErrorCode write_read (const uint8_t *write_data, size_t write_len, uint8_t *read_data, size_t read_len) const
 writes an array of bytes to a device, then reads an array, as a single transaction
 
ErrorCode write_register (uint8_t a_register, const uint8_t *data, size_t len) const
 writes an array of bytes to a specific register in the I²C device
 
ErrorCode write_register16 (uint16_t a_register, const uint8_t *data, size_t len) const
 write an array of bytes to a specific register in the I²C device
 
bool read_bytes (uint8_t a_register, uint8_t *data, uint8_t len)
 Compat APIs All methods below have been added for compatibility reasons.
 
bool read_bytes_raw (uint8_t *data, uint8_t len) const
 
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)
 
bool read_byte (uint8_t a_register, uint8_t *data)
 
optional< uint8_t > read_byte (uint8_t a_register)
 
bool read_byte_16 (uint8_t a_register, uint16_t *data)
 
bool write_bytes (uint8_t a_register, const uint8_t *data, uint8_t len) const
 
bool write_bytes (uint8_t a_register, const std::vector< uint8_t > &data) const
 
template<size_t N>
bool write_bytes (uint8_t a_register, const std::array< uint8_t, N > &data)
 
bool write_bytes_16 (uint8_t a_register, const uint16_t *data, uint8_t len) const
 
bool write_byte (uint8_t a_register, uint8_t data) const
 
bool write_byte_16 (uint8_t a_register, uint16_t data) const
 
 ESPDEPRECATED ("The stop argument is no longer used. This will be removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode read_register(uint8_t a_register
 
 ESPDEPRECATED ("The stop argument is no longer used. This will be removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode read_register16(uint16_t a_register
 
 ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write(const uint8_t *data
 
 ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write_register(uint8_t a_register
 
 ESPDEPRECATED ("The stop argument is no longer used; use write_read() for consecutive write and read. This will be " "removed from ESPHome 2026.3.0", "2025.9.0") ErrorCode write_register16(uint16_t a_register
 

Protected Member Functions

bool write_command_ (uint16_t command, CommandLen command_len, const uint16_t *data, uint8_t data_len)
 Write a command with arguments as words.
 
bool get_register_ (uint16_t reg, CommandLen command_len, uint16_t *data, uint8_t len, uint8_t delay)
 get data words from I2C register.
 

Protected Attributes

i2c::ErrorCode last_error_
 last error code from I2C operation
 
- Protected Attributes inherited from esphome::i2c::I2CDevice
uint8_t address_ {0x00}
 store the address of the device on the bus
 
I2CBusbus_ {nullptr}
 pointer to I2CBus instance
 

Additional Inherited Members

- Data Fields inherited from esphome::i2c::I2CDevice
uint8_t * data
 
uint8_t size_t len
 
uint8_t size_t bool stop
 
size_t len
 
size_t bool stop const { return this->write(data, len)
 
const uint8_t * data
 
const uint8_t size_t len
 
const uint8_t size_t bool stop const
 

Detailed Description

Definition at line 20 of file i2c_sensirion.h.

Member Enumeration Documentation

◆ CommandLen

Enumerator
ADDR_8_BIT 
ADDR_16_BIT 

Definition at line 22 of file i2c_sensirion.h.

Member Function Documentation

◆ get_8bit_register() [1/2]

bool esphome::sensirion_common::SensirionI2CDevice::get_8bit_register ( uint8_t i2c_register,
uint16_t & data,
uint8_t delay = 0 )
inline

Read 1 data word from 8 bit I2C register.

Parameters
I2Cregister
datareference to raw result
delaymilliseconds to to wait between sending the I2C command and reading the result
Returns
true if reading succeeded

Definition at line 77 of file i2c_sensirion.h.

◆ get_8bit_register() [2/2]

bool esphome::sensirion_common::SensirionI2CDevice::get_8bit_register ( uint8_t i2c_register,
uint16_t * data,
uint8_t len,
uint8_t delay = 0 )
inline

get data words from I2C register.

handles CRC check used by Sensirion sensors

Parameters
I2Cregister
datapointer to raw result
lennumber of words to read
delaymilliseconds to to wait between sending the I2C command and reading the result
Returns
true if reading succeeded

Definition at line 67 of file i2c_sensirion.h.

◆ get_register() [1/2]

bool esphome::sensirion_common::SensirionI2CDevice::get_register ( uint16_t command,
uint16_t * data,
uint8_t len,
uint8_t delay = 0 )
inline

get data words from I2C register.

handles CRC check used by Sensirion sensors

Parameters
I2Cregister
datapointer to raw result
lennumber of words to read
delaymilliseconds to to wait between sending the I2C command and reading the result
Returns
true if reading succeeded

Definition at line 46 of file i2c_sensirion.h.

◆ get_register() [2/2]

bool esphome::sensirion_common::SensirionI2CDevice::get_register ( uint16_t i2c_register,
uint16_t & data,
uint8_t delay = 0 )
inline

Read 1 data word from 16 bit I2C register.

Parameters
I2Cregister
datareference to raw result
delaymilliseconds to to wait between sending the I2C command and reading the result
Returns
true if reading succeeded

Definition at line 55 of file i2c_sensirion.h.

◆ get_register_()

bool esphome::sensirion_common::SensirionI2CDevice::get_register_ ( uint16_t reg,
CommandLen command_len,
uint16_t * data,
uint8_t len,
uint8_t delay )
protected

get data words from I2C register.

handles CRC check used by Sensirion sensors

Parameters
I2Cregister
command_leneither 1 for short 8 bit command or 2 for 16 bit command codes
datapointer to raw result
lennumber of words to read
delaymilliseconds to to wait between sending the I2C command and reading the result
Returns
true if reading succeeded

Definition at line 86 of file i2c_sensirion.cpp.

◆ read_data() [1/2]

bool esphome::sensirion_common::SensirionI2CDevice::read_data ( uint16_t & data)
inline

Read 1 data word from I2C device.

Parameters
datareference to raw result
Returns
true if reading succeeded

Definition at line 36 of file i2c_sensirion.h.

◆ read_data() [2/2]

bool esphome::sensirion_common::SensirionI2CDevice::read_data ( uint16_t * data,
uint8_t len )

Read data words from I2C device.

handles CRC check used by Sensirion sensors

Parameters
datapointer to raw result
lennumber of words to read
Returns
true if reading succeeded

Definition at line 14 of file i2c_sensirion.cpp.

◆ write_command() [1/4]

template<class T >
bool esphome::sensirion_common::SensirionI2CDevice::write_command ( T i2c_register)
inline

Write a command to the I2C device.

Parameters
commandI2C command to send
Returns
true if reading succeeded

Definition at line 85 of file i2c_sensirion.h.

◆ write_command() [2/4]

template<class T >
bool esphome::sensirion_common::SensirionI2CDevice::write_command ( T i2c_register,
const std::vector< uint16_t > & data )
inline

Write a command with arguments as words.

Parameters
i2c_registerI2C command to send - an be uint8_t or uint16_t
datavector<uint16> arguments for the I2C command
Returns
true if reading succeeded

Definition at line 99 of file i2c_sensirion.h.

◆ write_command() [3/4]

template<class T >
bool esphome::sensirion_common::SensirionI2CDevice::write_command ( T i2c_register,
const uint16_t * data,
uint8_t len )
inline

Write a command with arguments as words.

Parameters
i2c_registerI2C command to send - an be uint8_t or uint16_t
dataarguments for the I2C command
lennumber of arguments (words)
Returns
true if reading succeeded

Definition at line 109 of file i2c_sensirion.h.

◆ write_command() [4/4]

template<class T >
bool esphome::sensirion_common::SensirionI2CDevice::write_command ( T i2c_register,
uint16_t data )
inline

Write a command and one data word to the I2C device .

Parameters
commandI2C command to send
dataargument for the I2C command
Returns
true if reading succeeded

Definition at line 92 of file i2c_sensirion.h.

◆ write_command_()

bool esphome::sensirion_common::SensirionI2CDevice::write_command_ ( uint16_t command,
CommandLen command_len,
const uint16_t * data,
uint8_t data_len )
protected

Write a command with arguments as words.

Parameters
commandI2C command to send can be uint8_t or uint16_t
command_leneither 1 for short 8 bit command or 2 for 16 bit command codes
dataarguments for the I2C command
data_lennumber of arguments (words)
Returns
true if reading succeeded

Definition at line 40 of file i2c_sensirion.cpp.

Field Documentation

◆ last_error_

i2c::ErrorCode esphome::sensirion_common::SensirionI2CDevice::last_error_
protected

last error code from I2C operation

Definition at line 138 of file i2c_sensirion.h.


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