2019-03-07 21:15:30 +00:00
|
|
|
#include <Adafruit_I2CDevice.h>
|
2019-05-18 04:36:14 +01:00
|
|
|
#include <Adafruit_SPIDevice.h>
|
2019-03-07 21:15:30 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
2019-05-18 04:36:14 +01:00
|
|
|
#ifndef Adafruit_BusIO_Register_h
|
|
|
|
|
#define Adafruit_BusIO_Register_h
|
2019-03-07 21:15:30 +00:00
|
|
|
|
2019-05-18 05:04:51 +01:00
|
|
|
typedef enum _Adafruit_BusIO_SPIRegType {
|
|
|
|
|
ADDRBIT8_HIGH_TOREAD = 0,
|
2019-12-22 00:24:21 +00:00
|
|
|
AD8_HIGH_TOREAD_AD7_HIGH_TOINC = 1,
|
2020-03-10 19:02:55 +00:00
|
|
|
ADDRBIT8_HIGH_TOWRITE = 2,
|
2019-05-18 05:04:51 +01:00
|
|
|
} Adafruit_BusIO_SPIRegType;
|
2019-03-07 21:15:30 +00:00
|
|
|
|
2019-05-18 19:37:08 +01:00
|
|
|
/*!
|
2019-12-28 00:49:16 +00:00
|
|
|
* @brief The class which defines a device register (a location to read/write
|
|
|
|
|
* data from)
|
2019-05-18 19:37:08 +01:00
|
|
|
*/
|
2019-05-18 04:36:14 +01:00
|
|
|
class Adafruit_BusIO_Register {
|
2019-12-28 00:49:16 +00:00
|
|
|
public:
|
|
|
|
|
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr,
|
2020-03-10 19:28:57 +00:00
|
|
|
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
|
2019-12-28 00:49:16 +00:00
|
|
|
uint8_t address_width = 1);
|
|
|
|
|
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
|
|
|
|
|
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
|
2020-03-10 19:28:57 +00:00
|
|
|
uint8_t byteorder = LSBFIRST,
|
2019-12-28 00:49:16 +00:00
|
|
|
uint8_t address_width = 1);
|
2019-05-18 07:47:48 +01:00
|
|
|
|
|
|
|
|
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
|
2019-12-28 00:49:16 +00:00
|
|
|
Adafruit_SPIDevice *spidevice,
|
|
|
|
|
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr,
|
2020-03-10 19:28:57 +00:00
|
|
|
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
|
2019-12-28 00:49:16 +00:00
|
|
|
uint8_t address_width = 1);
|
2019-05-18 07:47:48 +01:00
|
|
|
|
2019-03-07 21:15:30 +00:00
|
|
|
bool read(uint8_t *buffer, uint8_t len);
|
|
|
|
|
bool read(uint8_t *value);
|
|
|
|
|
bool read(uint16_t *value);
|
2019-03-07 21:23:12 +00:00
|
|
|
uint32_t read(void);
|
2020-06-30 19:00:20 +01:00
|
|
|
uint32_t readCached(void);
|
2019-03-07 21:15:30 +00:00
|
|
|
bool write(uint8_t *buffer, uint8_t len);
|
2019-12-28 00:49:16 +00:00
|
|
|
bool write(uint32_t value, uint8_t numbytes = 0);
|
2019-03-07 21:15:30 +00:00
|
|
|
|
2019-05-18 19:37:08 +01:00
|
|
|
uint8_t width(void);
|
2019-03-08 07:29:27 +00:00
|
|
|
|
2019-12-28 00:49:16 +00:00
|
|
|
void print(Stream *s = &Serial);
|
|
|
|
|
void println(Stream *s = &Serial);
|
2019-03-08 07:29:27 +00:00
|
|
|
|
2019-12-28 00:49:16 +00:00
|
|
|
private:
|
2019-05-18 04:36:14 +01:00
|
|
|
Adafruit_I2CDevice *_i2cdevice;
|
|
|
|
|
Adafruit_SPIDevice *_spidevice;
|
2019-05-18 05:04:51 +01:00
|
|
|
Adafruit_BusIO_SPIRegType _spiregtype;
|
2019-03-07 21:15:30 +00:00
|
|
|
uint16_t _address;
|
2020-03-10 19:28:57 +00:00
|
|
|
uint8_t _width, _addrwidth, _byteorder;
|
2019-12-28 00:49:16 +00:00
|
|
|
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
|
|
|
|
|
// non-buffered read
|
2020-06-30 19:00:20 +01:00
|
|
|
uint32_t _cached = 0;
|
2019-03-07 21:15:30 +00:00
|
|
|
};
|
|
|
|
|
|
2019-05-18 19:37:08 +01:00
|
|
|
/*!
|
2019-12-28 00:49:16 +00:00
|
|
|
* @brief The class which defines a slice of bits from within a device register
|
|
|
|
|
* (a location to read/write data from)
|
2019-05-18 19:37:08 +01:00
|
|
|
*/
|
2019-05-18 04:36:14 +01:00
|
|
|
class Adafruit_BusIO_RegisterBits {
|
2019-12-28 00:49:16 +00:00
|
|
|
public:
|
|
|
|
|
Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits,
|
|
|
|
|
uint8_t shift);
|
2020-02-22 23:08:14 +00:00
|
|
|
bool write(uint32_t value);
|
2019-03-08 07:29:27 +00:00
|
|
|
uint32_t read(void);
|
2019-12-28 00:49:16 +00:00
|
|
|
|
|
|
|
|
private:
|
2019-05-18 04:36:14 +01:00
|
|
|
Adafruit_BusIO_Register *_register;
|
2019-03-08 07:29:27 +00:00
|
|
|
uint8_t _bits, _shift;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-28 00:49:16 +00:00
|
|
|
#endif // BusIO_Register_h
|