SparkFun Toolkit  v1.0.5-6-g34ffa30
Core Functionality Library
Loading...
Searching...
No Matches
sfTkArdI2C Class Reference

The sfTkArdI2C implements an sfTkII2C interface, defining the Arduino implementation for I2C in the Toolkit. More...

#include <sfTkArdI2C.h>

Inheritance diagram for sfTkArdI2C:

Public Member Functions

 sfTkArdI2C (void)
 Constructor. More...
 
 sfTkArdI2C (uint8_t addr)
 Constructor. More...
 
 sfTkArdI2C (sfTkArdI2C const &rhs)
 copy constructor More...
 
sfTkArdI2Coperator= (const sfTkArdI2C &rhs)
 Copy assignment. More...
 
sfTkError_t init ()
 Method sets up the required I2C settings. More...
 
sfTkError_t init (uint8_t addr)
 
  • address version of the init method
More...
 
sfTkError_t init (TwoWire &wirePort, uint8_t addr, bool bInit=false)
 Method sets up the required I2C settings. More...
 
sfTkError_t ping ()
 A simple ping of the device at the given address. More...
 
sfTkError_t writeRegister (uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length)
 Writes data to a specified register on an I2C device. More...
 
sfTkError_t readRegister (uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes, uint32_t read_delay=0)
 Reads data from a specified register of an I2C device. More...
 
void setBufferChunkSize (size_t theChunk)
 set the buffer chunk size More...
 
size_t bufferChunkSize (void)
 set the buffer chunk size More...
 
virtual sfTkError_t readRegister (uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes, uint32_t read_delay=0)=0
 Reads an array of bytes to a register on the target address. Supports any address size. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint8_t &data)
 Read a single byte from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint16_t &data)
 Read a single word (16 bit) from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint32_t &data)
 Read a 32 bit value from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes)
 Reads data from a specified register. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint8_t &value)
 Overloaded function to read a 8-bit value from the given 16-bit register address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint16_t &value)
 Overloaded function to read a 16-bit value from the given 16-bit register address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint32_t &value)
 Overloaded function to read a 32-bit value from the given 16-bit register address. More...
 
sfTkError_t readRegister (uint16_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes)
 Reads a specified number of bytes from a given register with a 16bit address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint16_t *data, size_t length, size_t &read16)
 Reads a 16-bit block of data from the given 16-bit register address. More...
 
virtual sfTkError_t writeRegister (uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length)=0
 Writes an array of bytes to a register on the target address. Supports any address size. More...
 
sfTkError_t writeRegister (uint8_t devReg, uint8_t data)
 Write a single byte (8 bit) to the given register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint16_t data)
 Write a single word (16 bit) to the given register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint8_t *data, size_t length)
 Writes a number of bytes starting at the given register's address. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint8_t *data, size_t length)
 Writes a number of bytes starting at the given register's 16-bit address. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint8_t data)
 Writes a 8-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint16_t data)
 Writes a 16-bit data value to a specified device 16bit register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint16_t *data, size_t length)
 Writes a number of uint16's starting at the given register's 16-bit address. More...
 
- Public Member Functions inherited from sfTkII2C
 sfTkII2C ()
 Constructor for the I2C bus. More...
 
 sfTkII2C (uint8_t addr)
 Constructor for the I2C bus with an address passed in. More...
 
virtual sfTkError_t ping ()=0
 A simple ping of the device at the set address. More...
 
virtual void setAddress (uint8_t devAddr)
 setter for the I2C address More...
 
virtual uint8_t address (void)
 getter for the I2C address More...
 
virtual void setStop (bool stop)
 setter for I2C stop message (vs restarts) More...
 
virtual bool stop (void)
 getter for I2C stops message (vs restarts) More...
 
virtual uint8_t type (void)
 Get the type of the object. More...
 
- Public Member Functions inherited from sfTkIBus
 sfTkIBus ()
 Constructor. More...
 
virtual sfTkError_t writeRegister (uint8_t *devReg, size_t regLength, const uint8_t *data, size_t length)=0
 Writes an array of bytes to a register on the target address. Supports any address size. More...
 
virtual sfTkError_t writeData (uint8_t data)
 Writes a 8-bit data value. More...
 
sfTkError_t writeUInt8 (uint8_t data)
 Writes a 8-bit data value. More...
 
virtual sfTkError_t writeData (uint16_t data)
 Send a 16 bit value to the device. More...
 
sfTkError_t writeUInt16 (uint16_t data)
 Send a 16 bit value to the device. More...
 
virtual sfTkError_t writeData (uint32_t data)
 Writes a 32-bit data value. More...
 
sfTkError_t writeUInt32 (uint32_t data)
 Writes a 32-bit data value. More...
 
virtual sfTkError_t writeData (const uint8_t *data, size_t length)
 Writes an array. More...
 
sfTkError_t writeRegister (uint8_t devReg, uint8_t data)
 Write a single byte (8 bit) to the given register. More...
 
sfTkError_t writeRegisterUInt8 (uint8_t reg, uint8_t data)
 Write a single byte (8 bit) to the given register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint16_t data)
 Write a single word (16 bit) to the given register. More...
 
sfTkError_t writeRegisterUInt16 (uint8_t reg, uint16_t data)
 Write a single word (16 bit) to the given register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
sfTkError_t writeRegisterUInt32 (uint8_t reg, uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint8_t devReg, const uint8_t *data, size_t length)
 Writes a number of bytes starting at the given register's address. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint8_t *data, size_t length)
 Writes a number of bytes starting at the given register's 16-bit address. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint8_t data)
 Writes a 8-bit data value to a specified device register. More...
 
sfTkError_t writeRegisterUInt8 (uint16_t reg, const uint8_t data)
 Writes a 8-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint16_t data)
 Writes a 16-bit data value to a specified device 16bit register. More...
 
sfTkError_t writeRegisterUInt16 (uint16_t reg, const uint16_t data)
 Writes a 16-bit data value to a specified device 16bit register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
sfTkError_t writeRegisterUInt32 (uint16_t reg, const uint32_t data)
 Writes a 32-bit data value to a specified device register. More...
 
virtual sfTkError_t writeRegister (uint16_t devReg, const uint16_t *data, size_t length)
 Writes a number of uint16's starting at the given register's 16-bit address. More...
 
virtual sfTkError_t readRegister (uint8_t *devReg, size_t regLength, uint8_t *data, size_t numBytes, size_t &readBytes, uint32_t read_delay=0)=0
 Reads an array of bytes to a register on the target address. Supports any address size. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint8_t &data)
 Read a single byte from the given register. More...
 
sfTkError_t readRegisterUInt8 (uint8_t devReg, uint8_t &data)
 Read a single byte from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint16_t &data)
 Read a single word (16 bit) from the given register. More...
 
sfTkError_t readRegisterUInt16 (uint8_t devReg, uint16_t &data)
 Read a single word (16 bit) from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint32_t &data)
 Read a 32 bit value from the given register. More...
 
sfTkError_t readRegisterUInt32 (uint8_t devReg, uint32_t &data)
 Read a 32 bit value from the given register. More...
 
virtual sfTkError_t readRegister (uint8_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes)
 Reads data from a specified register. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint8_t &value)
 Overloaded function to read a 8-bit value from the given 16-bit register address. More...
 
sfTkError_t readRegisterUInt8 (uint16_t devReg, uint8_t &data)
 Overloaded function to read a 8-bit value from the given 16-bit register address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint16_t &value)
 Overloaded function to read a 16-bit value from the given 16-bit register address. More...
 
sfTkError_t readRegisterUInt16 (uint16_t devReg, uint16_t &data)
 Overloaded function to read a 16-bit value from the given 16-bit register address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint32_t &value)
 Overloaded function to read a 32-bit value from the given 16-bit register address. More...
 
sfTkError_t readRegisterUInt32 (uint16_t devReg, uint32_t &data)
 Overloaded function to read a 32-bit value from the given 16-bit register address. More...
 
sfTkError_t readRegister (uint16_t devReg, uint8_t *data, size_t numBytes, size_t &readBytes)
 Reads a specified number of bytes from a given register with a 16bit address. More...
 
virtual sfTkError_t readRegister (uint16_t reg, uint16_t *data, size_t length, size_t &read16)
 Reads a 16-bit block of data from the given 16-bit register address. More...
 
virtual uint8_t type (void)
 Get the type of the object. More...
 
void setByteOrder (sfTkByteOrder order)
 Set the byte order for multi-byte data transfers. More...
 
sfTkByteOrder byteOrder (void)
 Get the current byte order. More...
 

Protected Attributes

TwoWire * _i2cPort
 
- Protected Attributes inherited from sfTkIBus
sfTkByteOrder _byteOrder
 

Additional Inherited Members

- Static Public Attributes inherited from sfTkII2C
static constexpr uint8_t kNoAddress = 0
 kNoAddress is a constant to indicate no address has been set More...
 

Detailed Description

The sfTkArdI2C implements an sfTkII2C interface, defining the Arduino implementation for I2C in the Toolkit.

Constructor & Destructor Documentation

◆ sfTkArdI2C() [1/3]

sfTkArdI2C::sfTkArdI2C ( void  )
inline

Constructor.

◆ sfTkArdI2C() [2/3]

sfTkArdI2C::sfTkArdI2C ( uint8_t  addr)
inline

Constructor.

Parameters
addrThe address of the device

◆ sfTkArdI2C() [3/3]

sfTkArdI2C::sfTkArdI2C ( sfTkArdI2C const &  rhs)
inline

copy constructor

Member Function Documentation

◆ bufferChunkSize()

size_t sfTkArdI2C::bufferChunkSize ( void  )
inline

set the buffer chunk size

Return values
Thecurrent chunk size

◆ init() [1/3]

sfTkError_t sfTkArdI2C::init ( void  )

Method sets up the required I2C settings.

Initializes the I2C communication with the currently set address.

Note
This function provides a default I2C Port.
Return values
ksfTkErrOkon successful execution.

This function initializes the I2C communication by calling the init function with the address that is currently set for the I2C device.

Returns
sfTkError_t Returns an error code indicating the success or failure of the initialization.

◆ init() [2/3]

sfTkError_t sfTkArdI2C::init ( TwoWire &  wirePort,
uint8_t  addr,
bool  bInit = false 
)

Method sets up the required I2C settings.

Initializes the I2C communication for the sfTkArdI2C object.

Parameters
wirePortPort for I2C communication.
addrThe address of the device
bInitThis flag tracks whether the bus has been initialized.
Return values
ksfTkErrOkon successful execution.

This function sets up the I2C communication by assigning the provided TwoWire object to the internal _i2cPort pointer. If the I2C port is not already set, it will use the provided wirePort and optionally initialize it by calling its begin() method. It also sets the I2C address for communication.

Parameters
wirePortReference to a TwoWire object representing the I2C port.
addrThe I2C address to be used for communication.
bInitBoolean flag indicating whether to initialize the I2C port by calling its begin() method. If true, begin() will be called.
Returns
sfTkError_t Returns ksfTkErrOk on successful initialization.

◆ init() [3/3]

sfTkError_t sfTkArdI2C::init ( uint8_t  addr)

  • address version of the init method

Initializes the I2C communication with the specified address.

Parameters
addrThe address of the device

This function initializes the I2C communication for the device. If no I2C port is specified, it defaults to using the Wire library. If an I2C port is already specified, it assumes the initialization is already done.

Parameters
addrThe I2C address of the device.
Returns
sfTkError_t Returns ksfTkErrOk if the initialization is successful, otherwise returns an error code.

◆ operator=()

sfTkArdI2C & sfTkArdI2C::operator= ( const sfTkArdI2C rhs)
inline

Copy assignment.

Parameters
rhsright hand side of the assignment
Returns
value of the left hand side of the assignment

◆ ping()

sfTkError_t sfTkArdI2C::ping ( )
virtual

A simple ping of the device at the given address.

Pings the I2C device to check if it is responsive.

Note
sfTkIBus interface method
Return values
ksfTkErrOkon success,

This function attempts to initiate a transmission to the I2C device and checks if the device acknowledges the transmission. It can be used to verify that the device is properly connected and responsive.

Returns
sfTkError_t
  • ksfTkErrOk: if the device acknowledges the transmission.
  • ksfTkErrFail: if the device does not acknowledge the transmission.
  • ksfTkErrBusNotInit: if the I2C bus is not initialized.

Implements sfTkII2C.

◆ readRegister() [1/11]

sfTkError_t sfTkIBus::readRegister ( uint16_t  devReg,
uint8_t *  data,
size_t  numBytes,
size_t &  readBytes 
)
inline

Reads a specified number of bytes from a given register with a 16bit address.

This function reads data from a 16-bit register and stores it in the provided buffer.

Parameters
devRegThe 16-bit register address to read from. Byteswapped if needed.
dataPointer to the buffer where the read data will be stored.
numBytesThe number of bytes to read from the register.
readBytesReference to a variable where the number of bytes actually read will be stored.
Returns
sfTkError_t Error code indicating the success or failure of the read operation.

◆ readRegister() [2/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint16_t  reg,
uint16_t &  value 
)
inlinevirtual

Overloaded function to read a 16-bit value from the given 16-bit register address.

This function reads a 16-bit value from the specified 16-bit register address.

Parameters
regThe device's 16-bit register's address. The address is byteswapped if needed.
[out]valueThe 16-bit value read from the register. The value is byte swapped if needed.
Returns
sfTkError_t Returns ksfTkErrOk on success, or an error code on failure.

Reimplemented from sfTkIBus.

◆ readRegister() [3/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint16_t  reg,
uint16_t *  data,
size_t  length,
size_t &  read16 
)
inlinevirtual

Reads a 16-bit block of data from the given 16-bit register address.


Parameters
regThe device's 16 bit register's address. Byteswapped if needed
dataData area to read into - byteswapped if needed
length- length of data (16 bit element count)
[out]read16- number of 16 bit words read
Return values
intreturns ksfTkErrOk on success, or ksfTkErrFail code

Reimplemented from sfTkIBus.

◆ readRegister() [4/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint16_t  reg,
uint32_t &  value 
)
inlinevirtual

Overloaded function to read a 32-bit value from the given 16-bit register address.

This function reads a 32-bit value from the specified 16-bit register address.

Parameters
regThe device's 16-bit register's address. The address is byteswapped if needed.
[out]valueThe 32-bit value read from the register. The value is byte swapped if needed.
Returns
sfTkError_t Returns ksfTkErrOk on success, or an error code on failure.

Reimplemented from sfTkIBus.

◆ readRegister() [5/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint16_t  reg,
uint8_t &  value 
)
inlinevirtual

Overloaded function to read a 8-bit value from the given 16-bit register address.

This function reads a 8-bit value from the specified 16-bit register address.

Parameters
regThe device's 16-bit register's address. The address is byteswapped if needed
[out]valueThe 8-bit value read from the register.
Returns
sfTkError_t Returns ksfTkErrOk on success, or an error code on failure.

Reimplemented from sfTkIBus.

◆ readRegister() [6/11]

sfTkError_t sfTkArdI2C::readRegister ( uint8_t *  devReg,
size_t  regLength,
uint8_t *  data,
size_t  numBytes,
size_t &  readBytes,
uint32_t  read_delay = 0 
)
virtual

Reads data from a specified register of an I2C device.

Reads an array of bytes to a register on the target address. Supports any address size.

Parameters
devRegPointer to the register address to read from.
regLengthLength of the register address.
dataPointer to the buffer where the read data will be stored.
numBytesNumber of bytes to read from the register.
readBytesReference to a variable where the number of bytes actually read will be stored.
read_delayAfter sending the address, delay in milliseconds before reading the data
Returns
sfTkError_t Error code indicating the success or failure of the read operation.
Parameters
devRegThe device's register's address - can be any size
regLengthThe length of the register address
dataThe data to buffer to read into
numBytesThe length of the data buffer
readBytes[out]The number of bytes read
read_delayAfter sending the address, delay in milliseconds before reading the data
Returns
sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code

Implements sfTkIBus.

◆ readRegister() [7/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint8_t *  devReg,
size_t  regLength,
uint8_t *  data,
size_t  numBytes,
size_t &  readBytes,
uint32_t  read_delay = 0 
)
virtual

Reads an array of bytes to a register on the target address. Supports any address size.

Parameters
devRegThe device's register's address - can be any size
regLengthThe length of the register address
dataThe data to buffer to read into
numBytesThe length of the data buffer
readBytes[out]The number of bytes read
read_delayAfter sending the address, delay in milliseconds before reading the data
Returns
sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code

Implements sfTkIBus.

◆ readRegister() [8/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint8_t  devReg,
uint16_t &  data 
)
inlinevirtual

Read a single word (16 bit) from the given register.


Parameters
devRegThe device's register's address.
dataData to read.– the data value is byteswapped if needed
Return values
sfTkError_t- ksfTkErrOk on successful execution.

Reimplemented from sfTkIBus.

◆ readRegister() [9/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint8_t  devReg,
uint32_t &  data 
)
inlinevirtual

Read a 32 bit value from the given register.


Parameters
devRegThe device's register's address.
dataData to read. The data value is byteswapped if needed
Return values
sfTkError_t- ksfTkErrOk on successful execution.

Reimplemented from sfTkIBus.

◆ readRegister() [10/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint8_t  devReg,
uint8_t &  data 
)
inlinevirtual

Read a single byte from the given register.


Parameters
devRegThe device's register's address.
dataData to read.
Return values
sfTkError_t- ksfTkErrOk on successful execution.

Reimplemented from sfTkIBus.

◆ readRegister() [11/11]

virtual sfTkError_t sfTkIBus::readRegister ( uint8_t  devReg,
uint8_t *  data,
size_t  numBytes,
size_t &  readBytes 
)
inlinevirtual

Reads data from a specified register.

This function reads a specified number of bytes from a given register and stores the data in the provided buffer.

Parameters
devRegThe register address to read from.
dataPointer to the buffer where the read data will be stored.
numBytesThe number of bytes to read from the register.
readBytesReference to a variable where the number of bytes actually read will be stored.
Returns
sfTkError_t Error code indicating the success or failure of the read operation.

Reimplemented from sfTkIBus.

◆ setBufferChunkSize()

void sfTkArdI2C::setBufferChunkSize ( size_t  theChunk)
inline

set the buffer chunk size

Note
default size is 32
Parameters
theChunkthe new size - must be > 0

◆ writeRegister() [1/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint16_t  devReg,
const uint16_t *  data,
size_t  length 
)
inlinevirtual

Writes a number of uint16's starting at the given register's 16-bit address.


Parameters
devRegThe device's register's address.
data16 bit Data to write. This value is byteswapped if the byteorder set is different than the systems byteorder
length- length of data
Return values
sfTkError_tksfTkErrOk on successful execution

Reimplemented from sfTkIBus.

◆ writeRegister() [2/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint16_t  devReg,
const uint16_t  data 
)
inlinevirtual

Writes a 16-bit data value to a specified device 16bit register.

This function writes a 16-bit data value to a specified device register. If the system byte order differs from the byte order expected by the device, the data value is byte-swapped before being written.

Parameters
devRegThe 16 bit register address to write to.
dataThe 16-bit data value to write.
Returns
sfTkError_t Error code indicating the success or failure of the operation.

Reimplemented from sfTkIBus.

◆ writeRegister() [3/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint16_t  devReg,
const uint32_t  data 
)
inlinevirtual

Writes a 32-bit data value to a specified device register.

This function writes a 32-bit data value to a specified device register. If the system byte order differs from the byte order expected by the device, the data value is byte-swapped before being written.

Parameters
devRegThe register address to write to.
dataThe 32-bit data value to write. This value is byteswapped if the byteorder set is different that the systems byteorder
Returns
sfTkError_t Error code indicating the success or failure of the operation.

Reimplemented from sfTkIBus.

◆ writeRegister() [4/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint16_t  devReg,
const uint8_t *  data,
size_t  length 
)
inlinevirtual

Writes a number of bytes starting at the given register's 16-bit address.


Parameters
devRegThe device's register's 16 bit address. If the byteorder is different than the systems, the address is byteswapped
dataData to write.
length- length of data
Return values
sfTkError_tksfTkErrOk on successful execution

Reimplemented from sfTkIBus.

◆ writeRegister() [5/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint16_t  devReg,
const uint8_t  data 
)
inlinevirtual

Writes a 8-bit data value to a specified device register.

This function writes a 16-bit data value to a specified device register. If the system byte order differs from the byte order expected by the device, the data value is byte-swapped before being written.

Parameters
devRegThe device's register's 16 bit address. If the byteorder is different than the systems, the address is byteswapped
dataThe 8-bit data value to write.
Returns
sfTkError_t Error code indicating the success or failure of the operation.

Reimplemented from sfTkIBus.

◆ writeRegister() [6/11]

sfTkError_t sfTkArdI2C::writeRegister ( uint8_t *  devReg,
size_t  regLength,
const uint8_t *  data,
size_t  length 
)
virtual

Writes data to a specified register on an I2C device.

Writes an array of bytes to a register on the target address. Supports any address size.

Parameters
devRegPointer to the register address on the I2C device.
regLengthLength of the register address in bytes.
dataPointer to the data to be written to the register.
lengthLength of the data to be written in bytes.
Returns
sfTkError_t Error code indicating the success or failure of the operation.
Parameters
devRegThe device's register's address - can be any size
regLengthThe length of the register address
dataThe data to write
lengthThe length of the data buffer
Returns
sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code

Implements sfTkIBus.

◆ writeRegister() [7/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint8_t *  devReg,
size_t  regLength,
const uint8_t *  data,
size_t  length 
)
virtual

Writes an array of bytes to a register on the target address. Supports any address size.

Note
This is the minimum required write method to implement for a driver
Parameters
devRegThe device's register's address - can be any size, If nullptr, address is not sent
regLengthThe length of the register address. If 0, address is not sent
dataThe data to write
lengthThe length of the data buffer
Returns
sfTkError_t Returns ksfTkErrOk on success, or ksfTkErrFail code

Implements sfTkIBus.

◆ writeRegister() [8/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint8_t  devReg,
const uint16_t  data 
)
inlinevirtual

Write a single word (16 bit) to the given register.


Parameters
devRegThe device's register's address.
dataData to write. Note - if byte order differs, swap the data before writing.
Return values
sfTkError_t- ksfTkErrOk on successful execution.

Reimplemented from sfTkIBus.

◆ writeRegister() [9/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint8_t  devReg,
const uint32_t  data 
)
inlinevirtual

Writes a 32-bit data value to a specified device register.

This function writes a 32-bit data value to a specified device register. If the system byte order differs from the byte order expected by the device, the data value is byte-swapped before being written.

Parameters
devRegThe register address to write to.
dataThe 32-bit data value to write.
Returns
sfTkError_t Error code indicating the success or failure of the operation.

Reimplemented from sfTkIBus.

◆ writeRegister() [10/11]

virtual sfTkError_t sfTkIBus::writeRegister ( uint8_t  devReg,
const uint8_t *  data,
size_t  length 
)
inlinevirtual

Writes a number of bytes starting at the given register's address.


Parameters
devRegThe device's register's address.
dataData to write.
length- length of data
Return values
sfTkError_tksfTkErrOk on successful execution

Reimplemented from sfTkIBus.

◆ writeRegister() [11/11]

sfTkError_t sfTkIBus::writeRegister ( uint8_t  devReg,
uint8_t  data 
)
inline

Write a single byte (8 bit) to the given register.


Parameters
devRegThe device's register's address.
dataData to write. Note - if byte order differs, swap the data before writing.
Return values
sfTkError_t- ksfTkErrOk on successful execution.

Member Data Documentation

◆ _i2cPort

TwoWire* sfTkArdI2C::_i2cPort
protected

The actual Arduino i2c port


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