revert register logic

This commit is contained in:
caternuson 2021-09-28 15:11:01 -07:00
parent 6ffc223ad3
commit 4ccef6ae19
4 changed files with 29 additions and 48 deletions

View File

@ -1,5 +1,8 @@
#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)
@ -18,9 +21,7 @@ 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;
@ -41,7 +42,6 @@ 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,7 +87,6 @@ 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
@ -104,7 +103,6 @@ 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!
@ -131,7 +129,6 @@ 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;
} }
@ -208,7 +205,6 @@ 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!
@ -234,7 +230,6 @@ 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;
} }
@ -366,3 +361,5 @@ 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

View File

@ -4,8 +4,6 @@
#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
@ -47,7 +45,6 @@ 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,
@ -58,7 +55,6 @@ 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);
@ -79,9 +75,7 @@ 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;
@ -107,3 +101,5 @@ private:
}; };
#endif // BusIO_Register_h #endif // BusIO_Register_h
#endif // SPI exists

42
LICENSE
View File

@ -1,29 +1,21 @@
The MIT License(MIT) The MIT License (MIT)
Copyright(c) 2017 Adafruit Industries Copyright (c) 2017 Adafruit Industries
Permission is hereby granted, Permission is hereby granted, free of charge, to any person obtaining a copy
free of charge, of this software and associated documentation files (the "Software"), to deal
to any person obtaining a copy of this software and associated documentation in the Software without restriction, including without limitation the rights
files(the "Software"), to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
to deal in the Software without restriction, copies of the Software, and to permit persons to whom the Software is
including without limitation the rights to use, copy, modify, merge, publish furnished to do so, subject to the following conditions:
,
distribute, sublicense, and / or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions :
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in all
all copies copies or substantial portions of the Software.
or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
TORT OR OTHERWISE, ARISING FROM, SOFTWARE.
OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,12 +1,8 @@
#Adafruit Bus IO Library[![Build Status]( \ # Adafruit Bus IO Library [![Build Status](https://github.com/adafruit/Adafruit_BusIO/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_BusIO/actions)
https \
: // github.com/adafruit/Adafruit_BusIO/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_BusIO/actions)
This is a helper libary to abstract away I2C &SPI transactions and registers
Adafruit invests time and resources providing this open source code, This is a helper libary to abstract away I2C & SPI transactions and registers
please support Adafruit and open -
source hardware by purchasing products from Adafruit !
MIT license, Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
all text above must be included in any redistribution
MIT license, all text above must be included in any redistribution