0.5.1 MCP23S17

This commit is contained in:
Rob Tillaart 2024-03-05 11:26:07 +01:00
parent 11b39cc7ff
commit df920a659e
11 changed files with 39 additions and 26 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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;
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;
}

View File

@ -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

View File

@ -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.

View File

@ -17,6 +17,7 @@ MCP23S17 MCP(10); // HW SPI address 0x00
uint32_t start, stop;
void setup()
{
Serial.begin(115200);

View File

@ -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);

View File

@ -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": "*",

View File

@ -1,5 +1,5 @@
name=MCP23S17
version=0.5.0
version=0.5.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SPI MCP23S17 16 channel port expander 16 IO-lines