clang
This commit is contained in:
parent
c43db9d7c2
commit
66448b37ec
|
|
@ -89,18 +89,16 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Create a register we access over a GenericDevice
|
* @brief Create a register we access over a GenericDevice
|
||||||
* @param genericdevice Generic device to use
|
* @param genericdevice Generic device to use
|
||||||
* @param reg_addr Register address we will read/write
|
* @param reg_addr Register address we will read/write
|
||||||
* @param width Width of the register in bytes (1-4)
|
* @param width Width of the register in bytes (1-4)
|
||||||
* @param byteorder Byte order of register data (LSBFIRST or MSBFIRST)
|
* @param byteorder Byte order of register data (LSBFIRST or MSBFIRST)
|
||||||
* @param address_width Width of the register address in bytes (1 or 2)
|
* @param address_width Width of the register address in bytes (1 or 2)
|
||||||
*/
|
*/
|
||||||
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_GenericDevice *genericdevice,
|
Adafruit_BusIO_Register::Adafruit_BusIO_Register(
|
||||||
uint16_t reg_addr,
|
Adafruit_GenericDevice *genericdevice, uint16_t reg_addr, uint8_t width,
|
||||||
uint8_t width,
|
uint8_t byteorder, uint8_t address_width) {
|
||||||
uint8_t byteorder,
|
|
||||||
uint8_t address_width) {
|
|
||||||
_i2cdevice = nullptr;
|
_i2cdevice = nullptr;
|
||||||
_spidevice = nullptr;
|
_spidevice = nullptr;
|
||||||
_genericdevice = genericdevice;
|
_genericdevice = genericdevice;
|
||||||
|
|
@ -110,7 +108,6 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_GenericDevice *generic
|
||||||
_width = width;
|
_width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Write a buffer of data to the register location
|
* @brief Write a buffer of data to the register location
|
||||||
* @param buffer Pointer to data to write
|
* @param buffer Pointer to data to write
|
||||||
|
|
@ -249,7 +246,6 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Read 2 bytes of data from the register location
|
* @brief Read 2 bytes of data from the register location
|
||||||
* @param value Pointer to uint16_t variable to read into
|
* @param value Pointer to uint16_t variable to read into
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
#if !defined(SPI_INTERFACES_COUNT) || \
|
#if !defined(SPI_INTERFACES_COUNT) || \
|
||||||
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
||||||
|
|
||||||
|
#include <Adafruit_GenericDevice.h>
|
||||||
#include <Adafruit_I2CDevice.h>
|
#include <Adafruit_I2CDevice.h>
|
||||||
#include <Adafruit_SPIDevice.h>
|
#include <Adafruit_SPIDevice.h>
|
||||||
#include <Adafruit_GenericDevice.h>
|
|
||||||
|
|
||||||
typedef enum _Adafruit_BusIO_SPIRegType {
|
typedef enum _Adafruit_BusIO_SPIRegType {
|
||||||
ADDRBIT8_HIGH_TOREAD = 0,
|
ADDRBIT8_HIGH_TOREAD = 0,
|
||||||
|
|
@ -58,8 +58,9 @@ public:
|
||||||
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
|
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
|
||||||
uint8_t address_width = 1);
|
uint8_t address_width = 1);
|
||||||
|
|
||||||
Adafruit_BusIO_Register(Adafruit_GenericDevice *genericdevice, uint16_t reg_addr,
|
Adafruit_BusIO_Register(Adafruit_GenericDevice *genericdevice,
|
||||||
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
|
uint16_t reg_addr, uint8_t width = 1,
|
||||||
|
uint8_t byteorder = LSBFIRST,
|
||||||
uint8_t address_width = 1);
|
uint8_t address_width = 1);
|
||||||
|
|
||||||
bool read(uint8_t *buffer, uint8_t len);
|
bool read(uint8_t *buffer, uint8_t len);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Adafruit_GenericDevice.h"
|
#include "Adafruit_GenericDevice.h"
|
||||||
|
|
||||||
Adafruit_GenericDevice::Adafruit_GenericDevice(busio_genericdevice_read_t read_func,
|
Adafruit_GenericDevice::Adafruit_GenericDevice(
|
||||||
|
busio_genericdevice_read_t read_func,
|
||||||
busio_genericdevice_write_t write_func,
|
busio_genericdevice_write_t write_func,
|
||||||
busio_genericdevice_readreg_t readreg_func,
|
busio_genericdevice_readreg_t readreg_func,
|
||||||
busio_genericdevice_writereg_t writereg_func) {
|
busio_genericdevice_writereg_t writereg_func) {
|
||||||
|
|
@ -30,14 +31,17 @@ bool Adafruit_GenericDevice::read(uint8_t *buffer, size_t len) {
|
||||||
return _read_func(buffer, len);
|
return _read_func(buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_GenericDevice::readRegister(uint8_t *addr_buf, uint8_t addrsiz, uint8_t *buf, uint16_t bufsiz) {
|
bool Adafruit_GenericDevice::readRegister(uint8_t *addr_buf, uint8_t addrsiz,
|
||||||
|
uint8_t *buf, uint16_t bufsiz) {
|
||||||
if (!_begun || !_readreg_func)
|
if (!_begun || !_readreg_func)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return _readreg_func(addr_buf, addrsiz, buf, bufsiz);
|
return _readreg_func(addr_buf, addrsiz, buf, bufsiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_GenericDevice::writeRegister(uint8_t *addr_buf, uint8_t addrsiz, const uint8_t *buf, uint16_t bufsiz) {
|
bool Adafruit_GenericDevice::writeRegister(uint8_t *addr_buf, uint8_t addrsiz,
|
||||||
|
const uint8_t *buf,
|
||||||
|
uint16_t bufsiz) {
|
||||||
if (!_begun || !_writereg_func)
|
if (!_begun || !_writereg_func)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,21 @@
|
||||||
|
|
||||||
typedef bool (*busio_genericdevice_read_t)(uint8_t *buffer, size_t len);
|
typedef bool (*busio_genericdevice_read_t)(uint8_t *buffer, size_t len);
|
||||||
typedef bool (*busio_genericdevice_write_t)(const uint8_t *buffer, size_t len);
|
typedef bool (*busio_genericdevice_write_t)(const uint8_t *buffer, size_t len);
|
||||||
typedef bool (*busio_genericdevice_readreg_t)(uint8_t *addr_buf, uint8_t addrsiz, uint8_t *buf, uint16_t bufsiz);
|
typedef bool (*busio_genericdevice_readreg_t)(uint8_t *addr_buf,
|
||||||
typedef bool (*busio_genericdevice_writereg_t)(uint8_t *addr_buf, uint8_t addrsiz, const uint8_t *buf, uint16_t bufsiz);
|
uint8_t addrsiz, uint8_t *buf,
|
||||||
|
uint16_t bufsiz);
|
||||||
|
typedef bool (*busio_genericdevice_writereg_t)(uint8_t *addr_buf,
|
||||||
|
uint8_t addrsiz,
|
||||||
|
const uint8_t *buf,
|
||||||
|
uint16_t bufsiz);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class for communicating with a device via generic read/write functions
|
* @brief Class for communicating with a device via generic read/write functions
|
||||||
*/
|
*/
|
||||||
class Adafruit_GenericDevice {
|
class Adafruit_GenericDevice {
|
||||||
public:
|
public:
|
||||||
Adafruit_GenericDevice(busio_genericdevice_read_t read_func,
|
Adafruit_GenericDevice(
|
||||||
|
busio_genericdevice_read_t read_func,
|
||||||
busio_genericdevice_write_t write_func,
|
busio_genericdevice_write_t write_func,
|
||||||
busio_genericdevice_readreg_t readreg_func = nullptr,
|
busio_genericdevice_readreg_t readreg_func = nullptr,
|
||||||
busio_genericdevice_writereg_t writereg_func = nullptr);
|
busio_genericdevice_writereg_t writereg_func = nullptr);
|
||||||
|
|
@ -22,8 +28,10 @@ public:
|
||||||
|
|
||||||
bool read(uint8_t *buffer, size_t len);
|
bool read(uint8_t *buffer, size_t len);
|
||||||
bool write(const uint8_t *buffer, size_t len);
|
bool write(const uint8_t *buffer, size_t len);
|
||||||
bool readRegister(uint8_t *addr_buf, uint8_t addrsiz, uint8_t *buf, uint16_t bufsiz);
|
bool readRegister(uint8_t *addr_buf, uint8_t addrsiz, uint8_t *buf,
|
||||||
bool writeRegister(uint8_t *addr_buf, uint8_t addrsiz, const uint8_t *buf, uint16_t bufsiz);
|
uint16_t bufsiz);
|
||||||
|
bool writeRegister(uint8_t *addr_buf, uint8_t addrsiz, const uint8_t *buf,
|
||||||
|
uint16_t bufsiz);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
busio_genericdevice_read_t _read_func;
|
busio_genericdevice_read_t _read_func;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue