Adafruit Bus IO Library
Public Member Functions | List of all members
Adafruit_BusIO_Register Class Reference

The class which defines a device register (a location to read/write data from) More...

#include <Adafruit_BusIO_Register.h>

Public Member Functions

 Adafruit_BusIO_Register (Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr, uint8_t width=1, uint8_t byteorder=LSBFIRST, uint8_t address_width=1)
 Create a register we access over an I2C Device (which defines the bus and address) More...
 
 Adafruit_BusIO_Register (Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_SPIRegType type, uint8_t width=1, uint8_t byteorder=LSBFIRST, uint8_t address_width=1)
 Create a register we access over an SPI Device (which defines the bus and CS pin) More...
 
 Adafruit_BusIO_Register (Adafruit_I2CDevice *i2cdevice, Adafruit_SPIDevice *spidevice, Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width=1, uint8_t byteorder=LSBFIRST, uint8_t address_width=1)
 Create a register we access over an I2C or SPI Device. This is a handy function because we can pass in nullptr for the unused interface, allowing libraries to mass-define all the registers. More...
 
bool read (uint8_t *buffer, uint8_t len)
 Read a buffer of data from the register location. More...
 
bool read (uint8_t *value)
 Read 1 byte of data from the register location. More...
 
bool read (uint16_t *value)
 Read 2 bytes of data from the register location. More...
 
uint32_t read (void)
 Read data from the register location. This does not do any error checking! More...
 
uint32_t readCached (void)
 Read cached data from last time we wrote to this register. More...
 
bool write (uint8_t *buffer, uint8_t len)
 Write a buffer of data to the register location. More...
 
bool write (uint32_t value, uint8_t numbytes=0)
 Write up to 4 bytes of data to the register location. More...
 
uint8_t width (void)
 The width of the register data, helpful for doing calculations. More...
 
void setWidth (uint8_t width)
 Set the default width of data. More...
 
void setAddress (uint16_t address)
 Set register address. More...
 
void setAddressWidth (uint16_t address_width)
 Set the width of register address. More...
 
void print (Stream *s=&Serial)
 Pretty printer for this register. More...
 
void println (Stream *s=&Serial)
 Pretty printer for this register. More...
 

Detailed Description

The class which defines a device register (a location to read/write data from)

Constructor & Destructor Documentation

◆ Adafruit_BusIO_Register() [1/3]

Adafruit_BusIO_Register::Adafruit_BusIO_Register ( Adafruit_I2CDevice i2cdevice,
uint16_t  reg_addr,
uint8_t  width = 1,
uint8_t  byteorder = LSBFIRST,
uint8_t  address_width = 1 
)

Create a register we access over an I2C Device (which defines the bus and address)

Parameters
i2cdeviceThe I2CDevice to use for underlying I2C access
reg_addrThe address pointer value for the I2C/SMBus register, can be 8 or 16 bits
widthThe width of the register data itself, defaults to 1 byte
byteorderThe byte order of the register (used when width is > 1), defaults to LSBFIRST
address_widthThe width of the register address itself, defaults to 1 byte

◆ Adafruit_BusIO_Register() [2/3]

Adafruit_BusIO_Register::Adafruit_BusIO_Register ( Adafruit_SPIDevice spidevice,
uint16_t  reg_addr,
Adafruit_BusIO_SPIRegType  type,
uint8_t  width = 1,
uint8_t  byteorder = LSBFIRST,
uint8_t  address_width = 1 
)

Create a register we access over an SPI Device (which defines the bus and CS pin)

Parameters
spideviceThe SPIDevice to use for underlying SPI access
reg_addrThe address pointer value for the SPI register, can be 8 or 16 bits
typeThe method we use to read/write data to SPI (which is not as well defined as I2C)
widthThe width of the register data itself, defaults to 1 byte
byteorderThe byte order of the register (used when width is > 1), defaults to LSBFIRST
address_widthThe width of the register address itself, defaults to 1 byte

◆ Adafruit_BusIO_Register() [3/3]

Adafruit_BusIO_Register::Adafruit_BusIO_Register ( Adafruit_I2CDevice i2cdevice,
Adafruit_SPIDevice spidevice,
Adafruit_BusIO_SPIRegType  type,
uint16_t  reg_addr,
uint8_t  width = 1,
uint8_t  byteorder = LSBFIRST,
uint8_t  address_width = 1 
)

Create a register we access over an I2C or SPI Device. This is a handy function because we can pass in nullptr for the unused interface, allowing libraries to mass-define all the registers.

Parameters
i2cdeviceThe I2CDevice to use for underlying I2C access, if nullptr we use SPI
spideviceThe SPIDevice to use for underlying SPI access, if nullptr we use I2C
reg_addrThe address pointer value for the I2C/SMBus/SPI register, can be 8 or 16 bits
typeThe method we use to read/write data to SPI (which is not as well defined as I2C)
widthThe width of the register data itself, defaults to 1 byte
byteorderThe byte order of the register (used when width is > 1), defaults to LSBFIRST
address_widthThe width of the register address itself, defaults to 1 byte

Member Function Documentation

◆ read() [1/4]

bool Adafruit_BusIO_Register::read ( uint8_t *  buffer,
uint8_t  len 
)

Read a buffer of data from the register location.

Parameters
bufferPointer to data to read into
lenNumber of bytes to read
Returns
True on successful write (only really useful for I2C as SPI is uncheckable)

◆ read() [2/4]

bool Adafruit_BusIO_Register::read ( uint8_t *  value)

Read 1 byte of data from the register location.

Parameters
valuePointer to uint8_t variable to read into
Returns
True on successful write (only really useful for I2C as SPI is uncheckable)

◆ read() [3/4]

bool Adafruit_BusIO_Register::read ( uint16_t *  value)

Read 2 bytes of data from the register location.

Parameters
valuePointer to uint16_t variable to read into
Returns
True on successful write (only really useful for I2C as SPI is uncheckable)

◆ read() [4/4]

uint32_t Adafruit_BusIO_Register::read ( void  )

Read data from the register location. This does not do any error checking!

Returns
Returns 0xFFFFFFFF on failure, value otherwise

◆ readCached()

uint32_t Adafruit_BusIO_Register::readCached ( void  )

Read cached data from last time we wrote to this register.

Returns
Returns 0xFFFFFFFF on failure, value otherwise

◆ write() [1/2]

bool Adafruit_BusIO_Register::write ( uint8_t *  buffer,
uint8_t  len 
)

Write a buffer of data to the register location.

Parameters
bufferPointer to data to write
lenNumber of bytes to write
Returns
True on successful write (only really useful for I2C as SPI is uncheckable)

◆ write() [2/2]

bool Adafruit_BusIO_Register::write ( uint32_t  value,
uint8_t  numbytes = 0 
)

Write up to 4 bytes of data to the register location.

Parameters
valueData to write
numbytesHow many bytes from 'value' to write
Returns
True on successful write (only really useful for I2C as SPI is uncheckable)

◆ width()

uint8_t Adafruit_BusIO_Register::width ( void  )

The width of the register data, helpful for doing calculations.

Returns
The data width used when initializing the register

◆ setWidth()

void Adafruit_BusIO_Register::setWidth ( uint8_t  width)

Set the default width of data.

Parameters
widththe default width of data read from register

◆ setAddress()

void Adafruit_BusIO_Register::setAddress ( uint16_t  address)

Set register address.

Parameters
addressthe address from register

◆ setAddressWidth()

void Adafruit_BusIO_Register::setAddressWidth ( uint16_t  address_width)

Set the width of register address.

Parameters
address_widththe width for register address

◆ print()

void Adafruit_BusIO_Register::print ( Stream *  s = &Serial)

Pretty printer for this register.

Parameters
sThe Stream to print to, defaults to &Serial

◆ println()

void Adafruit_BusIO_Register::println ( Stream *  s = &Serial)

Pretty printer for this register.

Parameters
sThe Stream to print to, defaults to &Serial

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