ESPHome
2024.10.2
|
Implementation of a i2c functions for Sensirion sensors Sensirion data requires crc checking. More...
#include <i2c_sensirion.h>
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. More... | |
bool | read_data (uint16_t &data) |
Read 1 data word from i2c device. More... | |
bool | get_register (uint16_t command, uint16_t *data, uint8_t len, uint8_t delay=0) |
get data words from i2c register. More... | |
bool | get_register (uint16_t i2c_register, uint16_t &data, uint8_t delay=0) |
Read 1 data word from 16 bit i2c register. More... | |
bool | get_8bit_register (uint8_t i2c_register, uint16_t *data, uint8_t len, uint8_t delay=0) |
get data words from i2c register. More... | |
bool | get_8bit_register (uint8_t i2c_register, uint16_t &data, uint8_t delay=0) |
Read 1 data word from 8 bit i2c register. More... | |
template<class T > | |
bool | write_command (T i2c_register) |
Write a command to the i2c device. More... | |
template<class T > | |
bool | write_command (T i2c_register, uint16_t data) |
Write a command and one data word to the i2c device . More... | |
template<class T > | |
bool | write_command (T i2c_register, const std::vector< uint16_t > &data) |
Write a command with arguments as words. More... | |
template<class T > | |
bool | write_command (T i2c_register, const uint16_t *data, uint8_t len) |
Write a command with arguments as words. More... | |
Public Member Functions inherited from esphome::i2c::I2CDevice | |
I2CDevice ()=default | |
we use the C++ default constructor More... | |
void | set_i2c_address (uint8_t address) |
We store the address of the device on the bus. More... | |
void | set_i2c_bus (I2CBus *bus) |
we store the pointer to the I2CBus to use More... | |
I2CRegister | reg (uint8_t a_register) |
calls the I2CRegister constructor More... | |
I2CRegister16 | reg16 (uint16_t a_register) |
calls the I2CRegister16 constructor More... | |
ErrorCode | read (uint8_t *data, size_t len) |
reads an array of bytes from the device using an I2CBus More... | |
ErrorCode | read_register (uint8_t a_register, uint8_t *data, size_t len, bool stop=true) |
reads an array of bytes from a specific register in the I²C device More... | |
ErrorCode | read_register16 (uint16_t a_register, uint8_t *data, size_t len, bool stop=true) |
reads an array of bytes from a specific register in the I²C device More... | |
ErrorCode | write (const uint8_t *data, size_t len, bool stop=true) |
writes an array of bytes to a device using an I2CBus More... | |
ErrorCode | write_register (uint8_t a_register, const uint8_t *data, size_t len, bool stop=true) |
writes an array of bytes to a specific register in the I²C device More... | |
ErrorCode | write_register16 (uint16_t a_register, const uint8_t *data, size_t len, bool stop=true) |
write an array of bytes to a specific register in the I²C device More... | |
bool | read_bytes (uint8_t a_register, uint8_t *data, uint8_t len) |
Compat APIs All methods below have been added for compatibility reasons. 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) |
bool | read_byte (uint8_t a_register, uint8_t *data, bool stop=true) |
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, bool stop=true) |
bool | write_bytes (uint8_t a_register, const std::vector< uint8_t > &data) |
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) |
bool | write_byte (uint8_t a_register, uint8_t data, bool stop=true) |
bool | write_byte_16 (uint8_t a_register, uint16_t data) |
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. More... | |
bool | get_register_ (uint16_t reg, CommandLen command_len, uint16_t *data, uint8_t len, uint8_t delay) |
get data words from i2c register. More... | |
uint8_t | sht_crc_ (uint16_t data) |
8-bit CRC checksum that is transmitted after each data word for read and write operation More... | |
uint8_t | sht_crc_ (uint8_t data1, uint8_t data2) |
8-bit CRC checksum that is transmitted after each data word for read and write operation More... | |
Protected Attributes | |
uint8_t | crc_polynomial_ {0x31u} |
i2c::ErrorCode | last_error_ |
last error code from i2c operation More... | |
Protected Attributes inherited from esphome::i2c::I2CDevice | |
uint8_t | address_ {0x00} |
store the address of the device on the bus More... | |
I2CBus * | bus_ {nullptr} |
pointer to I2CBus instance More... | |
Implementation of a i2c functions for Sensirion sensors Sensirion data requires crc checking.
Each 16 bit word is/must be followed 8 bit CRC code (Applies to read and write - note the i2c command code doesn't need a CRC) Format: | 16 Bit Command Code | 16 bit Data word 1 | CRC of DW 1 | 16 bit Data word 1 | CRC of DW 2 | ..
Definition at line 17 of file i2c_sensirion.h.
enum esphome::sensirion_common::SensirionI2CDevice::CommandLen : uint8_t |
Enumerator | |
---|---|
ADDR_8_BIT | |
ADDR_16_BIT |
Definition at line 19 of file i2c_sensirion.h.
|
inline |
get data words from i2c register.
handles crc check used by Sensirion sensors
i2c | register |
data | pointer to raw result |
len | number of words to read |
delay | milliseconds to to wait between sending the i2c command and reading the result |
Definition at line 64 of file i2c_sensirion.h.
|
inline |
Read 1 data word from 8 bit i2c register.
i2c | register |
data | reference to raw result |
delay | milliseconds to to wait between sending the i2c command and reading the result |
Definition at line 74 of file i2c_sensirion.h.
|
inline |
get data words from i2c register.
handles crc check used by Sensirion sensors
i2c | register |
data | pointer to raw result |
len | number of words to read |
delay | milliseconds to to wait between sending the i2c command and reading the result |
Definition at line 43 of file i2c_sensirion.h.
|
inline |
Read 1 data word from 16 bit i2c register.
i2c | register |
data | reference to raw result |
delay | milliseconds to to wait between sending the i2c command and reading the result |
Definition at line 52 of file i2c_sensirion.h.
|
protected |
get data words from i2c register.
handles crc check used by Sensirion sensors
i2c | register |
command_len | either 1 for short 8 bit command or 2 for 16 bit command codes |
data | pointer to raw result |
len | number of words to read |
delay | milliseconds to to wait between sending the i2c command and reading the result |
Definition at line 82 of file i2c_sensirion.cpp.
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
data | pointer to raw result |
len | number of words to read |
Definition at line 13 of file i2c_sensirion.cpp.
|
inline |
Read 1 data word from i2c device.
data | reference to raw result |
Definition at line 33 of file i2c_sensirion.h.
|
protected |
8-bit CRC checksum that is transmitted after each data word for read and write operation
command | i2c command to send |
data | data word for which the crc8 checksum is calculated |
len | number of arguments (words) |
Definition at line 97 of file i2c_sensirion.cpp.
|
inlineprotected |
8-bit CRC checksum that is transmitted after each data word for read and write operation
command | i2c command to send |
data1 | high byte of data word |
data2 | low byte of data word |
Definition at line 149 of file i2c_sensirion.h.
|
inline |
Write a command to the i2c device.
command | i2c command to send |
Definition at line 82 of file i2c_sensirion.h.
|
inline |
Write a command and one data word to the i2c device .
Definition at line 89 of file i2c_sensirion.h.
|
inline |
Write a command with arguments as words.
i2c_register | i2c command to send - an be uint8_t or uint16_t |
data | vector<uint16> arguments for the i2c command |
Definition at line 96 of file i2c_sensirion.h.
|
inline |
Write a command with arguments as words.
i2c_register | i2c command to send - an be uint8_t or uint16_t |
data | arguments for the i2c command |
len | number of arguments (words) |
Definition at line 106 of file i2c_sensirion.h.
|
protected |
Write a command with arguments as words.
command | i2c command to send can be uint8_t or uint16_t |
command_len | either 1 for short 8 bit command or 2 for 16 bit command codes |
data | arguments for the i2c command |
data_len | number of arguments (words) |
Definition at line 38 of file i2c_sensirion.cpp.
|
protected |
Definition at line 114 of file i2c_sensirion.h.
|
protected |
last error code from i2c operation
Definition at line 153 of file i2c_sensirion.h.