Skip to content

Commit

Permalink
doxyclanged!
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jan 8, 2025
1 parent 66448b3 commit c602ea0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Adafruit_BusIO_Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ uint32_t Adafruit_BusIO_Register::read(void) {
*/
uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }

/*!
@brief Read a number of bytes from a register into a buffer
@param buffer Buffer to read data into
@param len Number of bytes to read into the buffer
@return true on successful read, otherwise false
*/
bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
(uint8_t)(_address >> 8)};
Expand Down
31 changes: 27 additions & 4 deletions Adafruit_GenericDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "Adafruit_GenericDevice.h"

/*! @brief Create a Generic device with the provided read/write functions
@param read_func Function pointer for reading raw data
@param write_func Function pointer for writing raw data
@param readreg_func Function pointer for reading registers (optional)
@param writereg_func Function pointer for writing registers (optional) */
Adafruit_GenericDevice::Adafruit_GenericDevice(
busio_genericdevice_read_t read_func,
busio_genericdevice_write_t write_func,
Expand All @@ -12,38 +17,56 @@ Adafruit_GenericDevice::Adafruit_GenericDevice(
_begun = false;
}

/*! @brief Initializes the device
@return true if initialization was successful, otherwise false */
bool Adafruit_GenericDevice::begin(void) {
_begun = true;
return true;
}

/*! @brief Write a buffer of data
@param buffer Pointer to buffer of data to write
@param len Number of bytes to write
@return true if write was successful, otherwise false */
bool Adafruit_GenericDevice::write(const uint8_t *buffer, size_t len) {
if (!_begun)
return false;

return _write_func(buffer, len);
}

/*! @brief Read data into a buffer
@param buffer Pointer to buffer to read data into
@param len Number of bytes to read
@return true if read was successful, otherwise false */
bool Adafruit_GenericDevice::read(uint8_t *buffer, size_t len) {
if (!_begun)
return false;

return _read_func(buffer, len);
}

/*! @brief Read from a register location
@param addr_buf Buffer containing register address
@param addrsiz Size of register address in bytes
@param buf Buffer to store read data
@param bufsiz Size of data to read in bytes
@return true if read was successful, otherwise false */
bool Adafruit_GenericDevice::readRegister(uint8_t *addr_buf, uint8_t addrsiz,
uint8_t *buf, uint16_t bufsiz) {
if (!_begun || !_readreg_func)
return false;

return _readreg_func(addr_buf, addrsiz, buf, bufsiz);
}

/*! @brief Write to a register location
@param addr_buf Buffer containing register address
@param addrsiz Size of register address in bytes
@param buf Buffer containing data to write
@param bufsiz Size of data to write in bytes
@return true if write was successful, otherwise false */
bool Adafruit_GenericDevice::writeRegister(uint8_t *addr_buf, uint8_t addrsiz,
const uint8_t *buf,
uint16_t bufsiz) {
if (!_begun || !_writereg_func)
return false;

return _writereg_func(addr_buf, addrsiz, buf, bufsiz);
}
7 changes: 6 additions & 1 deletion Adafruit_GenericDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ class Adafruit_GenericDevice {
uint16_t bufsiz);

protected:
/*! @brief Function pointer for reading raw data from the device */
busio_genericdevice_read_t _read_func;
/*! @brief Function pointer for writing raw data to the device */
busio_genericdevice_write_t _write_func;
/*! @brief Function pointer for reading a 'register' from the device */
busio_genericdevice_readreg_t _readreg_func;
/*! @brief Function pointer for writing a 'register' to the device */
busio_genericdevice_writereg_t _writereg_func;

bool _begun;
bool _begun; ///< whether we have initialized yet (in case the function needs
///< to do something)
};

#endif // ADAFRUIT_GENERICDEVICE_H

0 comments on commit c602ea0

Please sign in to comment.