ESPHome  2024.10.2
Public Member Functions | Data Fields
esphome::weikai::WeikaiRegister Class Referenceabstract

WeikaiRegister objects acts as proxies to access remote register independently of the bus type. More...

#include <weikai.h>

Inheritance diagram for esphome::weikai::WeikaiRegister:
esphome::weikai_i2c::WeikaiRegisterI2C esphome::weikai_spi::WeikaiRegisterSPI

Public Member Functions

 WeikaiRegister (WeikaiComponent *const comp, uint8_t reg, uint8_t channel)
 WeikaiRegister constructor. More...
 
virtual ~WeikaiRegister ()
 
WeikaiRegisteroperator= (uint8_t value)
 overloads the = operator. More...
 
WeikaiRegisteroperator &= (uint8_t value)
 overloads the compound &= operator. More...
 
WeikaiRegisteroperator|= (uint8_t value)
 overloads the compound |= operator. More...
 
 operator uint8_t () const
 cast operator that returns the content of the weikai register More...
 
virtual uint8_t read_reg () const =0
 reads the register More...
 
virtual void write_reg (uint8_t value)=0
 writes the register More...
 
virtual void read_fifo (uint8_t *data, size_t length) const =0
 read an array of bytes from the receiver fifo More...
 
virtual void write_fifo (uint8_t *data, size_t length)=0
 write an array of bytes to the transmitter fifo More...
 

Data Fields

WeikaiComponent *const comp_
 pointer to our parent (aggregation) More...
 
uint8_t register_
 address of the register More...
 
uint8_t channel_
 channel for this register More...
 

Detailed Description

WeikaiRegister objects acts as proxies to access remote register independently of the bus type.

This is an abstract interface class that provides many operations to access to registers while hiding the actual implementation. This allow to accesses the registers in the Weikai component abstract class independently of the actual bus (I2C, SPI). The derived classes will actually implements the specific bus operations dependant of the bus used.
typical usage of WeikaiRegister:

WeikaiRegister reg_X {&WeikaiComponent, ADDR_REGISTER_X, CHANNEL_NUM} // declaration
reg_X |= 0x01; // set bit 0 of the weikai register
reg_X &= ~0x01; // reset bit 0 of the weikai register
reg_X = 10; // Set the value of weikai register
uint val = reg_X; // get the value of weikai register

Definition at line 139 of file weikai.h.

Constructor & Destructor Documentation

◆ WeikaiRegister()

esphome::weikai::WeikaiRegister::WeikaiRegister ( WeikaiComponent *const  comp,
uint8_t  reg,
uint8_t  channel 
)
inline

WeikaiRegister constructor.

Parameters
compour parent WeikaiComponent
regaddress of the register
channelthe channel of this register

Definition at line 145 of file weikai.h.

◆ ~WeikaiRegister()

virtual esphome::weikai::WeikaiRegister::~WeikaiRegister ( )
inlinevirtual

Definition at line 147 of file weikai.h.

Member Function Documentation

◆ operator &=()

WeikaiRegister& esphome::weikai::WeikaiRegister::operator&= ( uint8_t  value)

overloads the compound &= operator.

This is often used to reset bits in the weikai register

Parameters
valueperforms an & operation with value and store the result
Returns
this object

◆ operator uint8_t()

esphome::weikai::WeikaiRegister::operator uint8_t ( ) const
inline

cast operator that returns the content of the weikai register

Definition at line 165 of file weikai.h.

◆ operator=()

WeikaiRegister & esphome::weikai::WeikaiRegister::operator= ( uint8_t  value)

overloads the = operator.

This is used to set a value into the weikai register

Parameters
valueto be set
Returns
this object

Definition at line 136 of file weikai.cpp.

◆ operator|=()

WeikaiRegister & esphome::weikai::WeikaiRegister::operator|= ( uint8_t  value)

overloads the compound |= operator.

This is often used to set bits in the weikai register

Parameters
valueperforms an | operation with value and store the result
Returns
this object

Definition at line 147 of file weikai.cpp.

◆ read_fifo()

virtual void esphome::weikai::WeikaiRegister::read_fifo ( uint8_t *  data,
size_t  length 
) const
pure virtual

read an array of bytes from the receiver fifo

Parameters
datapointer to data buffer
lengthnumber of bytes to read

Implemented in esphome::weikai_i2c::WeikaiRegisterI2C, and esphome::weikai_spi::WeikaiRegisterSPI.

◆ read_reg()

virtual uint8_t esphome::weikai::WeikaiRegister::read_reg ( ) const
pure virtual

reads the register

Returns
the value read from the register

Implemented in esphome::weikai_i2c::WeikaiRegisterI2C, and esphome::weikai_spi::WeikaiRegisterSPI.

◆ write_fifo()

virtual void esphome::weikai::WeikaiRegister::write_fifo ( uint8_t *  data,
size_t  length 
)
pure virtual

write an array of bytes to the transmitter fifo

Parameters
datapointer to data buffer
lengthnumber of bytes to write

Implemented in esphome::weikai_i2c::WeikaiRegisterI2C, and esphome::weikai_spi::WeikaiRegisterSPI.

◆ write_reg()

virtual void esphome::weikai::WeikaiRegister::write_reg ( uint8_t  value)
pure virtual

writes the register

Parameters
valueto write in the register

Implemented in esphome::weikai_i2c::WeikaiRegisterI2C, and esphome::weikai_spi::WeikaiRegisterSPI.

Field Documentation

◆ channel_

uint8_t esphome::weikai::WeikaiRegister::channel_

channel for this register

Definition at line 187 of file weikai.h.

◆ comp_

WeikaiComponent* const esphome::weikai::WeikaiRegister::comp_

pointer to our parent (aggregation)

Definition at line 185 of file weikai.h.

◆ register_

uint8_t esphome::weikai::WeikaiRegister::register_

address of the register

Definition at line 186 of file weikai.h.


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