From df920a659e818c8dba8435be4d97f27f6db9c30c Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 5 Mar 2024 11:26:07 +0100 Subject: [PATCH] 0.5.1 MCP23S17 --- .../MCP23S17/.github/workflows/arduino-lint.yml | 2 +- .../.github/workflows/arduino_test_runner.yml | 2 +- .../MCP23S17/.github/workflows/jsoncheck.yml | 2 +- libraries/MCP23S17/CHANGELOG.md | 6 ++++++ libraries/MCP23S17/MCP23S17.cpp | 17 ++++++++++------- libraries/MCP23S17/MCP23S17.h | 10 +++++----- libraries/MCP23S17/README.md | 12 +++++++----- .../MCP23S17_test_led_bar.ino | 1 + .../MCP23S17_two_ADDRESS.ino | 9 +++++---- libraries/MCP23S17/library.json | 2 +- libraries/MCP23S17/library.properties | 2 +- 11 files changed, 39 insertions(+), 26 deletions(-) diff --git a/libraries/MCP23S17/.github/workflows/arduino-lint.yml b/libraries/MCP23S17/.github/workflows/arduino-lint.yml index 8a26f14a..870a1769 100644 --- a/libraries/MCP23S17/.github/workflows/arduino-lint.yml +++ b/libraries/MCP23S17/.github/workflows/arduino-lint.yml @@ -6,7 +6,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/libraries/MCP23S17/.github/workflows/arduino_test_runner.yml b/libraries/MCP23S17/.github/workflows/arduino_test_runner.yml index fadfa904..5506eb6a 100644 --- a/libraries/MCP23S17/.github/workflows/arduino_test_runner.yml +++ b/libraries/MCP23S17/.github/workflows/arduino_test_runner.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 diff --git a/libraries/MCP23S17/.github/workflows/jsoncheck.yml b/libraries/MCP23S17/.github/workflows/jsoncheck.yml index 37a11298..beb88295 100644 --- a/libraries/MCP23S17/.github/workflows/jsoncheck.yml +++ b/libraries/MCP23S17/.github/workflows/jsoncheck.yml @@ -10,7 +10,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: json-syntax-check uses: limitusus/json-syntax-check@v1 with: diff --git a/libraries/MCP23S17/CHANGELOG.md b/libraries/MCP23S17/CHANGELOG.md index 98360f38..a01dd147 100644 --- a/libraries/MCP23S17/CHANGELOG.md +++ b/libraries/MCP23S17/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.1] - 2024-03-02 +- Fix #38, add parameter to **begin(bool pullup)** +- update GitHub/actions to version v4 in workflows. +- Fix #37, using ints as parameter in constructor. + + ## [0.5.0] - 2024-01-20 - Fix #32, improve handling SPI dependency. - update examples diff --git a/libraries/MCP23S17/MCP23S17.cpp b/libraries/MCP23S17/MCP23S17.cpp index e8b5f9c2..abc2c741 100644 --- a/libraries/MCP23S17/MCP23S17.cpp +++ b/libraries/MCP23S17/MCP23S17.cpp @@ -1,7 +1,7 @@ // // FILE: MCP23S17.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.5.0 +// VERSION: 0.5.1 // PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander // DATE: 2021-12-30 // URL: https://github.com/RobTillaart/MCP23S17 @@ -24,13 +24,13 @@ MCP23S17::MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t cloc // HARDWARE SPI -MCP23S17::MCP23S17(uint8_t select, __SPI_CLASS__ * spi) +MCP23S17::MCP23S17(int select, __SPI_CLASS__ * spi) { MCP23S17(select, 0x00, spi); } -MCP23S17::MCP23S17(uint8_t select, uint8_t address, __SPI_CLASS__ * spi) +MCP23S17::MCP23S17(int select, int address, __SPI_CLASS__ * spi) { _address = (address << 1); _select = select; @@ -40,7 +40,7 @@ MCP23S17::MCP23S17(uint8_t select, uint8_t address, __SPI_CLASS__ * spi) } -bool MCP23S17::begin() +bool MCP23S17::begin(bool pullup) { ::pinMode(_select, OUTPUT); ::digitalWrite(_select, HIGH); @@ -71,9 +71,12 @@ bool MCP23S17::begin() // 0 = Sequential operation enabled, address pointer increments. if (! writeReg(MCP23S17_IOCR, MCP23S17_IOCR_SEQOP)) return false; - // Force INPUT_PULLUP - if (! writeReg(MCP23S17_PUR_A, 0xFF)) return false; // 0xFF == all UP - if (! writeReg(MCP23S17_PUR_B, 0xFF)) return false; // 0xFF == all UP + if (pullup) + { + // Force INPUT_PULLUP + if (! writeReg(MCP23S17_PUR_A, 0xFF)) return false; // 0xFF == all UP + if (! writeReg(MCP23S17_PUR_B, 0xFF)) return false; // 0xFF == all UP + } return true; } diff --git a/libraries/MCP23S17/MCP23S17.h b/libraries/MCP23S17/MCP23S17.h index d69906da..fff8c15a 100644 --- a/libraries/MCP23S17/MCP23S17.h +++ b/libraries/MCP23S17/MCP23S17.h @@ -2,7 +2,7 @@ // // FILE: MCP23S17.h // AUTHOR: Rob Tillaart -// VERSION: 0.5.0 +// VERSION: 0.5.1 // PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander // DATE: 2021-12-30 // URL: https://github.com/RobTillaart/MCP23S17 @@ -13,7 +13,7 @@ #include "MCP23S17_registers.h" -#define MCP23S17_LIB_VERSION (F("0.5.0")) +#define MCP23S17_LIB_VERSION (F("0.5.1")) // ERROR CODES #define MCP23S17_OK 0x00 @@ -43,10 +43,10 @@ public: // SOFTWARE SPI MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00); // HARDWARE SPI - MCP23S17(uint8_t select, __SPI_CLASS__ * spi); - MCP23S17(uint8_t select, uint8_t address = 0x00, __SPI_CLASS__ * spi = &SPI); + MCP23S17(int select, __SPI_CLASS__ * spi); + MCP23S17(int select, int address = 0x00, __SPI_CLASS__ * spi = &SPI); - bool begin(); + bool begin(bool pullup = true); bool isConnected(); uint8_t getAddress(); // default returns 0x00 diff --git a/libraries/MCP23S17/README.md b/libraries/MCP23S17/README.md index b4bd417f..42732736 100644 --- a/libraries/MCP23S17/README.md +++ b/libraries/MCP23S17/README.md @@ -84,11 +84,13 @@ Also it makes the library a bit simpler to maintain. ### Constructor - **MCP23S17(uint8_t select, uint8_t dataIn, uint8_t dataOut, uint8_t clock, uint8_t address = 0x00)** constructor SOFTWARE SPI. -- **MCP23S17(uint8_t select, SPIClassRP2040\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. -- **MCP23S17(uint8_t select, SPIClass\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. -- **MCP23S17(uint8_t select, uint8_t address = 0x00, SPIClassRP2040\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface. -- **MCP23S17(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. +- **MCP23S17(int select, SPIClassRP2040\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. +- **MCP23S17(int select, SPIClass\* spi)** constructor HARDWARE SPI with explicit SPI interface selected. +- **MCP23S17(int select, int address = 0x00, SPIClassRP2040\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface. +- **MCP23S17(int select, int address = 0x00, SPIClass\* spi = &SPI)** constructor HARDWARE SPI with optional address pins and SPI interface. +- **bool begin(bool pullup = true)** initializes library, returns true if successful. +Default sets the pins to INPUT PULLUP. +Returns false if not connected or a register could not be set. - **bool isConnected()** returns true if connected, false otherwise. (dummy for compatibility reasons) - **uint8_t getAddress()** returns the address set in the constructor. Default = 0, range = 0..7. diff --git a/libraries/MCP23S17/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino b/libraries/MCP23S17/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino index 31a02aeb..37eccdbd 100644 --- a/libraries/MCP23S17/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino +++ b/libraries/MCP23S17/examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino @@ -17,6 +17,7 @@ MCP23S17 MCP(10); // HW SPI address 0x00 uint32_t start, stop; + void setup() { Serial.begin(115200); diff --git a/libraries/MCP23S17/examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino b/libraries/MCP23S17/examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino index 458cb3ac..b1988041 100644 --- a/libraries/MCP23S17/examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino +++ b/libraries/MCP23S17/examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino @@ -10,11 +10,11 @@ #include "MCP23S17.h" -MCP23S17 MCP_A(10, 12, 11, 13, 0); // SW SPI, address 0 -MCP23S17 MCP_B(10 , 12, 11, 13, 1); // SW SPI, address 1 +//MCP23S17 MCP_A(10, 12, 11, 13, 0); // SW SPI, address 0 +//MCP23S17 MCP_B(10, 12, 11, 13, 1); // SW SPI, address 1 -// MCP23S17 MCP_A(10, 0); // HW SPI, address 0 -// MCP23S17 MCP_B(10, 1); // HW SPI, address 1 +MCP23S17 MCP_A(10, &SPI); // HW SPI, address 0 (default) +MCP23S17 MCP_B(10, 1); // HW SPI, address 1 void setup() @@ -52,6 +52,7 @@ void setup() void loop() { int x = random(32); + Serial.println(x); if (x < 16) { MCP_A.write1(x, HIGH); diff --git a/libraries/MCP23S17/library.json b/libraries/MCP23S17/library.json index 47cb9a6a..510cff3c 100644 --- a/libraries/MCP23S17/library.json +++ b/libraries/MCP23S17/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/MCP23S17.git" }, - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/MCP23S17/library.properties b/libraries/MCP23S17/library.properties index 37eb47f6..2d445dfa 100644 --- a/libraries/MCP23S17/library.properties +++ b/libraries/MCP23S17/library.properties @@ -1,5 +1,5 @@ name=MCP23S17 -version=0.5.0 +version=0.5.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for SPI MCP23S17 16 channel port expander 16 IO-lines