selectively remove spi
This commit is contained in:
parent
a819f24d00
commit
c6965bd471
|
|
@ -1,8 +1,5 @@
|
||||||
#include <Adafruit_BusIO_Register.h>
|
#include <Adafruit_BusIO_Register.h>
|
||||||
|
|
||||||
#if !defined(SPI_INTERFACES_COUNT) || \
|
|
||||||
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Create a register we access over an I2C Device (which defines the
|
* @brief Create a register we access over an I2C Device (which defines the
|
||||||
* bus and address)
|
* bus and address)
|
||||||
|
|
@ -21,7 +18,9 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
|
||||||
uint8_t byteorder,
|
uint8_t byteorder,
|
||||||
uint8_t address_width) {
|
uint8_t address_width) {
|
||||||
_i2cdevice = i2cdevice;
|
_i2cdevice = i2cdevice;
|
||||||
|
#ifdef HAS_SPI
|
||||||
_spidevice = NULL;
|
_spidevice = NULL;
|
||||||
|
#endif
|
||||||
_addrwidth = address_width;
|
_addrwidth = address_width;
|
||||||
_address = reg_addr;
|
_address = reg_addr;
|
||||||
_byteorder = byteorder;
|
_byteorder = byteorder;
|
||||||
|
|
@ -42,6 +41,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
|
||||||
* @param address_width The width of the register address itself, defaults
|
* @param address_width The width of the register address itself, defaults
|
||||||
* to 1 byte
|
* to 1 byte
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAS_SPI
|
||||||
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
|
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
|
||||||
uint16_t reg_addr,
|
uint16_t reg_addr,
|
||||||
Adafruit_BusIO_SPIRegType type,
|
Adafruit_BusIO_SPIRegType type,
|
||||||
|
|
@ -87,6 +87,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
|
||||||
_byteorder = byteorder;
|
_byteorder = byteorder;
|
||||||
_width = width;
|
_width = width;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Write a buffer of data to the register location
|
* @brief Write a buffer of data to the register location
|
||||||
|
|
@ -103,6 +104,7 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
|
||||||
if (_i2cdevice) {
|
if (_i2cdevice) {
|
||||||
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
|
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
|
||||||
}
|
}
|
||||||
|
#ifdef HAS_SPI
|
||||||
if (_spidevice) {
|
if (_spidevice) {
|
||||||
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
||||||
// very special case!
|
// very special case!
|
||||||
|
|
@ -129,6 +131,7 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
|
||||||
}
|
}
|
||||||
return _spidevice->write(buffer, len, addrbuffer, _addrwidth);
|
return _spidevice->write(buffer, len, addrbuffer, _addrwidth);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,6 +208,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
|
||||||
if (_i2cdevice) {
|
if (_i2cdevice) {
|
||||||
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
||||||
}
|
}
|
||||||
|
#ifdef HAS_SPI
|
||||||
if (_spidevice) {
|
if (_spidevice) {
|
||||||
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
|
||||||
// very special case!
|
// very special case!
|
||||||
|
|
@ -230,6 +234,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
|
||||||
}
|
}
|
||||||
return _spidevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
return _spidevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -361,5 +366,3 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) {
|
||||||
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
|
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
|
||||||
_addrwidth = address_width;
|
_addrwidth = address_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPI exists
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#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))
|
||||||
|
#define HAS_SPI
|
||||||
|
#endif // SPI exists
|
||||||
|
|
||||||
#ifndef Adafruit_BusIO_Register_h
|
#ifndef Adafruit_BusIO_Register_h
|
||||||
#define Adafruit_BusIO_Register_h
|
#define Adafruit_BusIO_Register_h
|
||||||
|
|
@ -45,6 +47,7 @@ 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);
|
||||||
|
|
||||||
|
#ifdef HAS_SPI
|
||||||
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
|
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
|
||||||
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
|
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
|
||||||
uint8_t byteorder = LSBFIRST,
|
uint8_t byteorder = LSBFIRST,
|
||||||
|
|
@ -55,6 +58,7 @@ public:
|
||||||
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr,
|
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr,
|
||||||
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);
|
||||||
|
#endif
|
||||||
|
|
||||||
bool read(uint8_t *buffer, uint8_t len);
|
bool read(uint8_t *buffer, uint8_t len);
|
||||||
bool read(uint8_t *value);
|
bool read(uint8_t *value);
|
||||||
|
|
@ -75,7 +79,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_I2CDevice *_i2cdevice;
|
Adafruit_I2CDevice *_i2cdevice;
|
||||||
|
#ifdef HAS_SPI
|
||||||
Adafruit_SPIDevice *_spidevice;
|
Adafruit_SPIDevice *_spidevice;
|
||||||
|
#endif
|
||||||
Adafruit_BusIO_SPIRegType _spiregtype;
|
Adafruit_BusIO_SPIRegType _spiregtype;
|
||||||
uint16_t _address;
|
uint16_t _address;
|
||||||
uint8_t _width, _addrwidth, _byteorder;
|
uint8_t _width, _addrwidth, _byteorder;
|
||||||
|
|
@ -102,4 +108,3 @@ private:
|
||||||
|
|
||||||
#endif // BusIO_Register_h
|
#endif // BusIO_Register_h
|
||||||
|
|
||||||
#endif // SPI exists
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
#if (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
|
||||||
|
|
||||||
#include <Adafruit_SPIDevice.h>
|
#include <Adafruit_SPIDevice.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#if !defined(SPI_INTERFACES_COUNT) || \
|
||||||
|
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
|
||||||
|
|
||||||
//#define DEBUG_SERIAL Serial
|
//#define DEBUG_SERIAL Serial
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#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))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue