SatCat5
satcat5::util::I2cAddr Struct Referencefinal

Detailed Description

Conversion function for I2C device addresses.

See also
cfg::I2cGeneric, cfg::I2c.

Natively, conventional I2C device addresses are 7-bits followed by the read/write flag. Two bytes are required for 10-bit address mode.

There are conflicting conventions for representing this in software. This wrapper allows unambiguous use of all common conventions:

  • 7-bit addresses (e.g., 0x77 = 1110111) are right-justified.
  • 8-bit addresses (e.g., 0xEE/0xEF = 1110111x) are left-justified and come in pairs, treating read and write as a "separate" address. (This example refers to the same underlying I2C device address.)
  • 10-bit addresses (e.g., 0x377 = 1101110111) are right-justified. See also: https://www.i2c-bus.org/addressing/10-bit-addressing/ We insert the required 11110 prefix at this time, and shift bits 9 and 8 to make room for the R/Wb bit. Doing more work up front (i.e., usually at build-time) simplifies downstream processing.

Definition at line 30 of file cfg_i2c.h.

#include <cfg_i2c.h>

Public Member Functions

 I2cAddr (const I2cAddr &t)=default
 
I2cAddroperator= (const I2cAddr &t)=default
 
bool is_10b () const
 Is this a 10-bit address?
 
bool operator== (const I2cAddr &other) const
 Comparison operators:
 
bool operator!= (const I2cAddr &other) const
 Comparison operators:
 

Static Public Member Functions

static constexpr I2cAddr addr7 (u8 addr)
 Create I2C address from a 7-bit input (right-justified) Example: I2cAddr my_addr = I2cAddr::addr7(0x77);
 
static constexpr I2cAddr addr8 (u8 addr)
 Create I2C address from an 8-bit input (left-justified) Example: I2cAddr my_addr = I2cAddr::addr8(0xEE);
 
static constexpr I2cAddr addr10 (u16 addr)
 Create I2C address from a 10-bit input (right-justified) Example: I2cAddr my_addr = I2cAddr::addr10(0x377);
 
static constexpr I2cAddr native (u16 addr)
 Create I2C address from its native internal representation.
 

Public Attributes

const u16 m_addr
 Native internal address representation.
 

Private Member Functions

constexpr I2cAddr (u16 addr)
 

The documentation for this struct was generated from the following file: