From 0f3f025e13e2521af66ab58104b2b9e47a42156a Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 1 Dec 2023 17:16:25 +0100 Subject: [PATCH] 0.3.0 MCP23S08 --- libraries/MCP23S08/CHANGELOG.md | 8 ++- libraries/MCP23S08/MCP23S08.cpp | 66 +------------------ libraries/MCP23S08/MCP23S08.h | 40 +++++------ libraries/MCP23S08/README.md | 21 +++--- .../MCP23S08_digitalWrite.ino | 2 +- libraries/MCP23S08/keywords.txt | 6 -- libraries/MCP23S08/library.json | 2 +- libraries/MCP23S08/library.properties | 2 +- 8 files changed, 39 insertions(+), 108 deletions(-) diff --git a/libraries/MCP23S08/CHANGELOG.md b/libraries/MCP23S08/CHANGELOG.md index 4881d5b0..bada1d76 100644 --- a/libraries/MCP23S08/CHANGELOG.md +++ b/libraries/MCP23S08/CHANGELOG.md @@ -6,11 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.0] - 2023-12-01 +- refactor constructor interface - breaking changes. + - minimize conditional code. -- create SPI_CLASS macro to solve it. +- update readme.md +- update examples + + ## [0.2.1] - 2023-11-13 - update readme.md - update keywords.txt - ## [0.2.0] - 2023-08-19 - add ESP32 support - sync with MCP23S17 diff --git a/libraries/MCP23S08/MCP23S08.cpp b/libraries/MCP23S08/MCP23S08.cpp index 0b1040d4..59ae96f8 100644 --- a/libraries/MCP23S08/MCP23S08.cpp +++ b/libraries/MCP23S08/MCP23S08.cpp @@ -1,7 +1,7 @@ // // FILE: MCP23S08.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.1 +// VERSION: 0.3.0 // PURPOSE: Arduino library for SPI MCP23S08 8 channel port expander // DATE: 2022-01-10 // URL: https://github.com/RobTillaart/MCP23S08 @@ -24,14 +24,14 @@ MCP23S08::MCP23S08(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t cloc // HARDWARE SPI -MCP23S08::MCP23S08(uint8_t select, SPIClass* spi) +MCP23S08::MCP23S08(uint8_t select, __SPI_CLASS__ * spi) { MCP23S08(select, 0x00, spi); } // HARDWARE SPI -MCP23S08::MCP23S08(uint8_t select, uint8_t address, SPIClass* spi) +MCP23S08::MCP23S08(uint8_t select, uint8_t address, __SPI_CLASS__ * spi) { _address = (address << 1); _select = select; @@ -51,24 +51,8 @@ bool MCP23S08::begin() if (_hwSPI) { - #if defined(ESP32) - if (_useHSPI) // HSPI - { - _mySPI = new SPIClass(HSPI); - _mySPI->end(); - _mySPI->begin(14, 12, 13, _select); // CLK=14 MISO=12 MOSI=13 - } - else // VSPI - { - _mySPI = new SPIClass(VSPI); - _mySPI->end(); - _mySPI->begin(18, 19, 23, _select); // CLK=18 MISO=19 MOSI=23 - } - #else // generic hardware SPI - _mySPI = &SPI; _mySPI->end(); _mySPI->begin(); - #endif } else { @@ -432,50 +416,6 @@ void MCP23S08::disableHardwareAddress() } -#if defined(ESP32) - -void MCP23S08::selectHSPI() -{ - _useHSPI = true; -} - - -void MCP23S08::selectVSPI() -{ - _useHSPI = false; -} - - -bool MCP23S08::usesHSPI() -{ - return _useHSPI; -} - - -bool MCP23S08::usesVSPI() -{ - return !_useHSPI; -} - - -void MCP23S08::setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select) -{ - _clock = clk; - _dataOut = mosi; - _dataIn = miso; - _select = select; - pinMode(_select, OUTPUT); - digitalWrite(_select, HIGH); - - _mySPI->end(); // disable old SPI - - _mySPI->begin(clk, miso, mosi, select); // enable new pins -} - -#endif - - - //////////////////////////////////////////////////// // // PRIVATE diff --git a/libraries/MCP23S08/MCP23S08.h b/libraries/MCP23S08/MCP23S08.h index ff60b9c0..cf59e20f 100644 --- a/libraries/MCP23S08/MCP23S08.h +++ b/libraries/MCP23S08/MCP23S08.h @@ -2,7 +2,7 @@ // // FILE: MCP23S08.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.1 +// VERSION: 0.3.0 // PURPOSE: Arduino library for SPI MCP23S08 8 channel port expander // DATE: 2022-01-10 // URL: https://github.com/RobTillaart/MCP23S08 @@ -13,7 +13,7 @@ #include "MCP23S08_registers.h" -#define MCP23S08_LIB_VERSION (F("0.2.1")) +#define MCP23S08_LIB_VERSION (F("0.3.0")) // ERROR CODES #define MCP23S08_OK 0x00 @@ -26,6 +26,15 @@ #define MCP23S08_INVALID_READ -100 +#ifndef __SPI_CLASS__ + #if defined(ARDUINO_ARCH_RP2040) + #define __SPI_CLASS__ SPIClassRP2040 + #else + #define __SPI_CLASS__ SPIClass + #endif +#endif + + const uint32_t MCP23S08_TYP_SPI_SPEED = 8000000; const uint32_t MCP23S08_MAX_SPI_SPEED = 10000000; @@ -37,8 +46,8 @@ public: // SOFTWARE SPI MCP23S08(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00); // HARDWARE SPI - MCP23S08(uint8_t select, SPIClass* spi); - MCP23S08(uint8_t select, uint8_t address = 0x00, SPIClass* spi = &SPI); + MCP23S08(uint8_t select, __SPI_CLASS__* spi); + MCP23S08(uint8_t select, uint8_t address = 0x00, __SPI_CLASS__* spi = &SPI); bool begin(); bool isConnected(); @@ -83,19 +92,6 @@ public: void enableHardwareAddress(); void disableHardwareAddress(); - // ESP32 specific -#if defined(ESP32) - - void selectHSPI(); - void selectVSPI(); - bool usesHSPI(); - bool usesVSPI(); - - // to overrule the ESP32s default hardware pins - void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select); - -#endif - private: // access to low level registers (just make these two functions public). @@ -113,15 +109,11 @@ private: bool _hwSPI = false; // 10 MHz is maximum, 8 is a better clock divider on AVR. - uint32_t _SPIspeed = MCP23S08_TYP_SPI_SPEED; - SPIClass * _mySPI; - SPISettings _spi_settings; + uint32_t _SPIspeed = MCP23S08_TYP_SPI_SPEED; + __SPI_CLASS__ * _mySPI; + SPISettings _spi_settings; uint8_t swSPI_transfer(uint8_t val); - - #if defined(ESP32) - bool _useHSPI = true; - #endif }; diff --git a/libraries/MCP23S08/README.md b/libraries/MCP23S08/README.md index 46948b16..61eed7d3 100644 --- a/libraries/MCP23S08/README.md +++ b/libraries/MCP23S08/README.md @@ -25,6 +25,14 @@ Since 0.1.1 the **digitalWrite(pin, value)** is optimized. If a pin is not changed it will not be written again to save time. +#### 0.3.0 Breaking change + +The version 0.3.0 has breaking changes in the interface. +The essence is removal of ESP32 specific code from the library. +This makes it possible to support the ESP32-S3 and other processors in the future. +Also it makes the library a bit simpler to maintain. + + #### Related 16 bit port expanders @@ -50,7 +58,9 @@ If a pin is not changed it will not be written again to save time. ### Constructor - **MCP23S08(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00)** constructor SOFTWARE SPI. +- **MCP23S08(uint8_t select, SPIClassRP2040\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. - **MCP23S08(uint8_t select, SPIClass\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. +- **MCP23S08(uint8_t select, uint8_t address = 0x00, SPIClassRP2040\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface. - **MCP23S08(uint8_t select, uint8_t address = 0x00, SPIClass\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface. - **bool begin()** returns true if successful. - **bool isConnected()** returns true if connected, false otherwise. (dummy for compatibility reasons) @@ -147,17 +157,6 @@ Since 0.2.0 - **void disableHardwareAddress()** specific for HAEN field. -### ESP32 - -Since 0.2.0 - -- **void selectHSPI()** idem -- **void selectVSPI()** idem -- **bool usesHSPI()** idem -- **bool usesVSPI()** idem -- **void setGPIOpins(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t select)** overrule the ESP32s default hardware pins. - - ### Error codes If one of the above functions return false, there might be an error. diff --git a/libraries/MCP23S08/examples/MCP23S08_digitalWrite/MCP23S08_digitalWrite.ino b/libraries/MCP23S08/examples/MCP23S08_digitalWrite/MCP23S08_digitalWrite.ino index b836a797..5fef514a 100644 --- a/libraries/MCP23S08/examples/MCP23S08_digitalWrite/MCP23S08_digitalWrite.ino +++ b/libraries/MCP23S08/examples/MCP23S08_digitalWrite/MCP23S08_digitalWrite.ino @@ -8,7 +8,7 @@ #include "MCP23S08.h" #include "SPI.h" -MCP23S08 MCP(10, 5, 6, 7); // SW SPI address 0x00 +MCP23S08 MCP(10, 5, 6, 7); // SW SPI address 0x00 void setup() diff --git a/libraries/MCP23S08/keywords.txt b/libraries/MCP23S08/keywords.txt index 73529718..4b5669eb 100644 --- a/libraries/MCP23S08/keywords.txt +++ b/libraries/MCP23S08/keywords.txt @@ -39,12 +39,6 @@ disableControlRegister KEYWORD2 enableHardwareAddress KEYWORD2 disableHardwareAddress KEYWORD2 -selectHSPI KEYWORD2 -selectVSPI KEYWORD2 -usesHSPI KEYWORD2 -usesVSPI KEYWORD2 -setGPIOpins KEYWORD2 - # Instances (KEYWORD2) diff --git a/libraries/MCP23S08/library.json b/libraries/MCP23S08/library.json index f7d56308..8cbfc230 100644 --- a/libraries/MCP23S08/library.json +++ b/libraries/MCP23S08/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/MCP23S08.git" }, - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/MCP23S08/library.properties b/libraries/MCP23S08/library.properties index 5119d5d8..fb7a5af7 100644 --- a/libraries/MCP23S08/library.properties +++ b/libraries/MCP23S08/library.properties @@ -1,5 +1,5 @@ name=MCP23S08 -version=0.2.1 +version=0.3.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for SPI MCP23S08 8 channel port expander 8 IO-lines