ESPHome  2024.4.0
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::i2c::I2CRegister16 Class Reference

This class is used to create I2CRegister16 objects that act as proxies to read/write internal registers (specified with a 16 bit address) on an I2C device. More...

#include <i2c.h>

Public Member Functions

I2CRegister16operator= (uint8_t value)
 overloads the = operator. More...
 
I2CRegister16operator &= (uint8_t value)
 overloads the compound &= operator. More...
 
I2CRegister16operator|= (uint8_t value)
 overloads the compound |= operator. More...
 
 operator uint8_t () const
 overloads the uint8_t() cast operator to return the I²C register value More...
 
uint8_t get () const
 returns the register value More...
 

Protected Member Functions

 I2CRegister16 (I2CDevice *parent, uint16_t a_register)
 protected constructor that store the owning object and the register address. More...
 

Protected Attributes

I2CDeviceparent_
 I2CDevice object pointer. More...
 
uint16_t register_
 the internal 16 bits address of the register More...
 

Detailed Description

This class is used to create I2CRegister16 objects that act as proxies to read/write internal registers (specified with a 16 bit address) on an I2C device.


typical usage:

constexpr uint16_t X16_BIT_ADDR_REGISTER_1 = 0x1234;
i2c::I2CRegister16 reg_1 = this->reg16(X16_BIT_ADDR_REGISTER_1); // declare
reg_1 |= 0x01; // set bit
reg_1 &= ~0x01; // reset bit
reg_1 = 10; // Set value
uint val = reg_1.get(); // get value

The I²C protocol specification, reads/writes in sets of 8-bits followed by an Acknowledgement (ACK/NACK) from the device receiving the data. How the device interprets the bits read/written to it can vary greatly from device to device. This class can be used to access in the device 8 bits registers that uses a 16 bits internal address. After sending the device address, the controller sends the internal register address (using two consecutive bytes following the big indian convention) and then read or write the register content.

Definition at line 88 of file i2c.h.

Constructor & Destructor Documentation

◆ I2CRegister16()

esphome::i2c::I2CRegister16::I2CRegister16 ( I2CDevice parent,
uint16_t  a_register 
)
inlineprotected

protected constructor that store the owning object and the register address.

Only friends can create an I2CRegister16

See also
I2CDevice::reg16()
Parameters
parentour parent
a_register16 bits address of the i2c register

Definition at line 120 of file i2c.h.

Member Function Documentation

◆ get()

uint8_t esphome::i2c::I2CRegister16::get ( ) const

returns the register value

Returns
the register value

Definition at line 96 of file i2c.cpp.

◆ operator &=()

I2CRegister16& esphome::i2c::I2CRegister16::operator&= ( uint8_t  value)

overloads the compound &= operator.

This allows to reset specific bits of an I²C register

Parameters
valueused for the & operation
Returns
pointer to current object

◆ operator uint8_t()

esphome::i2c::I2CRegister16::operator uint8_t ( ) const
inlineexplicit

overloads the uint8_t() cast operator to return the I²C register value

Returns
the register value

Definition at line 107 of file i2c.h.

◆ operator=()

I2CRegister16 & esphome::i2c::I2CRegister16::operator= ( uint8_t  value)

overloads the = operator.

This allows to set the value of an I²C register

Parameters
valuevalue to be set in the register
Returns
pointer to current object

Definition at line 81 of file i2c.cpp.

◆ operator|=()

I2CRegister16 & esphome::i2c::I2CRegister16::operator|= ( uint8_t  value)

overloads the compound |= operator.

This allows to set bits of an I²C register

Parameters
valueused for the & operation
Returns
pointer to current object

Definition at line 90 of file i2c.cpp.

Field Documentation

◆ parent_

I2CDevice* esphome::i2c::I2CRegister16::parent_
protected

I2CDevice object pointer.

Definition at line 122 of file i2c.h.

◆ register_

uint16_t esphome::i2c::I2CRegister16::register_
protected

the internal 16 bits address of the register

Definition at line 123 of file i2c.h.


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