From a819f24d00ca34541333eb7d6280b1187d6000a8 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 28 Sep 2021 12:15:40 -0700 Subject: [PATCH 1/4] fix spi preproc guards --- Adafruit_SPIDevice.cpp | 5 ++--- library.properties | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Adafruit_SPIDevice.cpp b/Adafruit_SPIDevice.cpp index f39627a..f560756 100644 --- a/Adafruit_SPIDevice.cpp +++ b/Adafruit_SPIDevice.cpp @@ -1,9 +1,8 @@ +#if (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) + #include #include -#if !defined(SPI_INTERFACES_COUNT) || \ - (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) - //#define DEBUG_SERIAL Serial /*! diff --git a/library.properties b/library.properties index 9203197..4e726a3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit BusIO -version=1.9.2 +version=1.9.3 author=Adafruit maintainer=Adafruit sentence=This is a library for abstracting away UART, I2C and SPI interfacing From c6965bd471b8bca3d4084459008f1ef463a2b243 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 28 Sep 2021 14:31:23 -0700 Subject: [PATCH 2/4] selectively remove spi --- Adafruit_BusIO_Register.cpp | 13 ++++++++----- Adafruit_BusIO_Register.h | 7 ++++++- Adafruit_SPIDevice.cpp | 5 +++-- Adafruit_SPIDevice.h | 2 ++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index f802525..bd42a54 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -1,8 +1,5 @@ #include -#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 * bus and address) @@ -21,7 +18,9 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint8_t byteorder, uint8_t address_width) { _i2cdevice = i2cdevice; +#ifdef HAS_SPI _spidevice = NULL; +#endif _addrwidth = address_width; _address = reg_addr; _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 * to 1 byte */ +#ifdef HAS_SPI Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_SPIRegType type, @@ -87,6 +87,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register( _byteorder = byteorder; _width = width; } +#endif /*! * @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) { return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth); } +#ifdef HAS_SPI if (_spidevice) { if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) { // 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); } +#endif return false; } @@ -205,6 +208,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) { if (_i2cdevice) { return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len); } +#ifdef HAS_SPI if (_spidevice) { if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) { // 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); } +#endif return false; } @@ -361,5 +366,3 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) { void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) { _addrwidth = address_width; } - -#endif // SPI exists diff --git a/Adafruit_BusIO_Register.h b/Adafruit_BusIO_Register.h index 8454b21..4227824 100644 --- a/Adafruit_BusIO_Register.h +++ b/Adafruit_BusIO_Register.h @@ -4,6 +4,8 @@ #if !defined(SPI_INTERFACES_COUNT) || \ (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) +#define HAS_SPI +#endif // SPI exists #ifndef Adafruit_BusIO_Register_h #define Adafruit_BusIO_Register_h @@ -45,6 +47,7 @@ public: uint8_t width = 1, uint8_t byteorder = LSBFIRST, uint8_t address_width = 1); +#ifdef HAS_SPI Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_SPIRegType type, uint8_t width = 1, uint8_t byteorder = LSBFIRST, @@ -55,6 +58,7 @@ public: Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width = 1, uint8_t byteorder = LSBFIRST, uint8_t address_width = 1); +#endif bool read(uint8_t *buffer, uint8_t len); bool read(uint8_t *value); @@ -75,7 +79,9 @@ public: private: Adafruit_I2CDevice *_i2cdevice; +#ifdef HAS_SPI Adafruit_SPIDevice *_spidevice; +#endif Adafruit_BusIO_SPIRegType _spiregtype; uint16_t _address; uint8_t _width, _addrwidth, _byteorder; @@ -102,4 +108,3 @@ private: #endif // BusIO_Register_h -#endif // SPI exists diff --git a/Adafruit_SPIDevice.cpp b/Adafruit_SPIDevice.cpp index f560756..f39627a 100644 --- a/Adafruit_SPIDevice.cpp +++ b/Adafruit_SPIDevice.cpp @@ -1,8 +1,9 @@ -#if (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) - #include #include +#if !defined(SPI_INTERFACES_COUNT) || \ + (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) + //#define DEBUG_SERIAL Serial /*! diff --git a/Adafruit_SPIDevice.h b/Adafruit_SPIDevice.h index 1170e21..921030a 100644 --- a/Adafruit_SPIDevice.h +++ b/Adafruit_SPIDevice.h @@ -1,3 +1,5 @@ +#include + #if !defined(SPI_INTERFACES_COUNT) || \ (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) From 6ffc223ad35baffe9c8081637e8c7ad3885e4225 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 28 Sep 2021 14:41:43 -0700 Subject: [PATCH 3/4] clang --- Adafruit_BusIO_Register.h | 1 - LICENSE | 42 +++++++++++++++++++++++---------------- README.md | 14 ++++++++----- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Adafruit_BusIO_Register.h b/Adafruit_BusIO_Register.h index 4227824..2d8bf3d 100644 --- a/Adafruit_BusIO_Register.h +++ b/Adafruit_BusIO_Register.h @@ -107,4 +107,3 @@ private: }; #endif // BusIO_Register_h - diff --git a/LICENSE b/LICENSE index 860e3e2..03a25dc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,29 @@ -The MIT License (MIT) +The MIT License(MIT) -Copyright (c) 2017 Adafruit Industries + Copyright(c) 2017 Adafruit Industries -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, 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: + Permission is hereby granted, + free of charge, + to any person obtaining a copy of this software and associated documentation + files(the "Software"), + to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish + , + 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 all -copies or substantial portions of the Software. + The above copyright notice and this permission notice shall be included in + all copies + or + substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file + THE SOFTWARE IS PROVIDED "AS IS", + WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 771cd13..1c01a0e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ -# 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) +#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) +This is a helper libary to abstract away I2C &SPI transactions and registers -This is a helper libary to abstract away I2C & SPI transactions and registers + Adafruit invests time and resources providing this open source code, + please support Adafruit and open - + source hardware by purchasing products from Adafruit ! -Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! - -MIT license, all text above must be included in any redistribution + MIT license, + all text above must be included in any redistribution From 4ccef6ae1935459cb2302fb5191b28e596db267f Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 28 Sep 2021 15:11:01 -0700 Subject: [PATCH 4/4] revert register logic --- Adafruit_BusIO_Register.cpp | 13 +++++------- Adafruit_BusIO_Register.h | 8 ++----- LICENSE | 42 +++++++++++++++---------------------- README.md | 14 +++++-------- 4 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index bd42a54..f802525 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -1,5 +1,8 @@ #include +#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 * bus and address) @@ -18,9 +21,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint8_t byteorder, uint8_t address_width) { _i2cdevice = i2cdevice; -#ifdef HAS_SPI _spidevice = NULL; -#endif _addrwidth = address_width; _address = reg_addr; _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 * to 1 byte */ -#ifdef HAS_SPI Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_SPIRegType type, @@ -87,7 +87,6 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register( _byteorder = byteorder; _width = width; } -#endif /*! * @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) { return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth); } -#ifdef HAS_SPI if (_spidevice) { if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) { // 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); } -#endif return false; } @@ -208,7 +205,6 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) { if (_i2cdevice) { return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len); } -#ifdef HAS_SPI if (_spidevice) { if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) { // 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); } -#endif return false; } @@ -366,3 +361,5 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) { void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) { _addrwidth = address_width; } + +#endif // SPI exists diff --git a/Adafruit_BusIO_Register.h b/Adafruit_BusIO_Register.h index 2d8bf3d..8454b21 100644 --- a/Adafruit_BusIO_Register.h +++ b/Adafruit_BusIO_Register.h @@ -4,8 +4,6 @@ #if !defined(SPI_INTERFACES_COUNT) || \ (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) -#define HAS_SPI -#endif // SPI exists #ifndef Adafruit_BusIO_Register_h #define Adafruit_BusIO_Register_h @@ -47,7 +45,6 @@ public: uint8_t width = 1, uint8_t byteorder = LSBFIRST, uint8_t address_width = 1); -#ifdef HAS_SPI Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_SPIRegType type, uint8_t width = 1, uint8_t byteorder = LSBFIRST, @@ -58,7 +55,6 @@ public: Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width = 1, uint8_t byteorder = LSBFIRST, uint8_t address_width = 1); -#endif bool read(uint8_t *buffer, uint8_t len); bool read(uint8_t *value); @@ -79,9 +75,7 @@ public: private: Adafruit_I2CDevice *_i2cdevice; -#ifdef HAS_SPI Adafruit_SPIDevice *_spidevice; -#endif Adafruit_BusIO_SPIRegType _spiregtype; uint16_t _address; uint8_t _width, _addrwidth, _byteorder; @@ -107,3 +101,5 @@ private: }; #endif // BusIO_Register_h + +#endif // SPI exists diff --git a/LICENSE b/LICENSE index 03a25dc..860e3e2 100644 --- a/LICENSE +++ b/LICENSE @@ -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, - free of charge, - to any person obtaining a copy of this software and associated documentation - files(the "Software"), - to deal in the Software without restriction, - including without limitation the rights to use, copy, modify, merge, publish - , - 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 : +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, 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 - all copies - or - substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", - WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 1c01a0e..3fc8a1f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ -#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) +# 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) -This is a helper libary to abstract away I2C &SPI transactions and registers - Adafruit invests time and resources providing this open source code, - please support Adafruit and open - - source hardware by purchasing products from Adafruit ! +This is a helper libary to abstract away I2C & SPI transactions and registers - MIT license, - all text above must be included in any redistribution +Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! + +MIT license, all text above must be included in any redistribution