Skip to content

Commit

Permalink
Fix #38, add parameter to begin(pullup) (#39)
Browse files Browse the repository at this point in the history
- Fix #38, add parameter to **begin(bool pullup)**
- update GitHub/actions to version v4 in workflows.
- Fix #37, using ints as parameter in constructor.
  • Loading branch information
RobTillaart authored Mar 5, 2024
1 parent 8b942cb commit d1f66a8
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions MCP23S17.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions MCP23S17.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -43,10 +43,10 @@ class MCP23S17
// 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

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MCP23S17 MCP(10); // HW SPI address 0x00

uint32_t start, stop;


void setup()
{
Serial.begin(115200);
Expand Down
9 changes: 5 additions & 4 deletions examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -52,6 +52,7 @@ void setup()
void loop()
{
int x = random(32);
Serial.println(x);
if (x < 16)
{
MCP_A.write1(x, HIGH);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MCP23S17
version=0.5.0
version=0.5.1
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for SPI MCP23S17 16 channel port expander 16 IO-lines
Expand Down

0 comments on commit d1f66a8

Please sign in to comment.