0.4.0 MCP23S17

This commit is contained in:
Rob Tillaart 2023-12-24 15:27:25 +01:00
parent ebbd578569
commit 4f0fcccc37
15 changed files with 83 additions and 54 deletions

View File

@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.4.0] - 2023-12-24
- Fix #30, support for Arduino ESP32 S3 - breaking change
- update readme.md
- update examples.
----
## [0.3.0] - 2023-12-01
- refactor constructor interface - breaking changes.
- minimize conditional code. -- create SPI_CLASS macro to solve it.

View File

@ -1,7 +1,7 @@
//
// FILE: MCP23S17.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.7
// VERSION: 0.4.0
// PURPOSE: Arduino library for SPI MCP23S17 16 channel port expander
// DATE: 2021-12-30
// URL: https://github.com/RobTillaart/MCP23S17
@ -98,7 +98,7 @@ uint8_t MCP23S17::getAddress()
//
// pin = 0..15
// mode = INPUT, OUTPUT, INPUT_PULLUP (= same as INPUT)
bool MCP23S17::pinMode(uint8_t pin, uint8_t mode)
bool MCP23S17::pinMode1(uint8_t pin, uint8_t mode)
{
if (pin > 15)
{
@ -144,7 +144,7 @@ bool MCP23S17::pinMode(uint8_t pin, uint8_t mode)
// pin = 0..15
// value = LOW, HIGH
bool MCP23S17::digitalWrite(uint8_t pin, uint8_t value)
bool MCP23S17::write1(uint8_t pin, uint8_t value)
{
if (pin > 15)
{
@ -187,7 +187,7 @@ bool MCP23S17::digitalWrite(uint8_t pin, uint8_t value)
}
uint8_t MCP23S17::digitalRead(uint8_t pin)
uint8_t MCP23S17::read1(uint8_t pin)
{
if (pin > 15)
{

View File

@ -2,7 +2,7 @@
//
// FILE: MCP23S17.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.0
// VERSION: 0.4.0
// 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.3.0"))
#define MCP23S17_LIB_VERSION (F("0.4.0"))
// ERROR CODES
#define MCP23S17_OK 0x00
@ -53,9 +53,9 @@ public:
// single pin interface
// mode: 0 = OUTPUT, 1 = INPUT, 1 = INPUT_PULLUP (==INPUT)
bool pinMode(uint8_t pin, uint8_t mode);
bool digitalWrite(uint8_t pin, uint8_t value);
uint8_t digitalRead(uint8_t pin);
bool pinMode1(uint8_t pin, uint8_t mode);
bool write1(uint8_t pin, uint8_t value);
uint8_t read1(uint8_t pin);
bool setPolarity(uint8_t pin, bool reversed);
bool getPolarity(uint8_t pin, bool &reversed);

View File

@ -16,12 +16,34 @@ Arduino library for MCP23S17 16 channel SPI port expander.
## Description
This experimental library gives easy control over the 16 pins of a (SPI) MCP23S17 chip.
This library gives easy control over the 16 pins of a (SPI) MCP23S17 chip.
This IC is strongly related to the MCP23017 I2C port expander - https://github.com/RobTillaart/MCP23017_RT
Programming Interface is kept the same as much as possible.
#### 0.4.0 Breaking change
The version 0.4.0 has breaking changes in the interface.
The rationale is that the programming environment of the **Arduino ESP32 S3**
board uses a remapping by means of the include file **io_pin_remap.h**.
This file remaps the pins of several core Arduino functions.
The remapping is implemented by #define macros and these implement "hard" text
replacements without considering context.
The effect is that methods from this class (and several others) which have the same
name as those Arduino core functions will be remapped into something not working.
The following library functions have been renamed:
| old name | new name | notes |
|:-----------------|:-------------|:--------|
| analogRead() | read() |
| analogWrite() | write() |
| pinMode() | pinMode1() |
| digitalRead() | read1() |
| digitalWrite() | write1() |
#### 0.3.0 Breaking change
The version 0.3.0 has breaking changes in the interface.
@ -100,9 +122,9 @@ See also **IO Control Register** section below.
### Single pin interface
- **bool pinMode(uint8_t pin, uint8_t mode)** pin = 0..15, mode = INPUT, OUTPUT. Returns true if successful.
- **bool digitalWrite(uint8_t pin, uint8_t value)** pin = 0..15, value = LOW(0) HIGH (!0). Returns true if successful.
- **uint8_t digitalRead(uint8_t pin)** pin = 0..15, returns LOW or HIGH, might set the lastError();
- **bool pinMode1(uint8_t pin, uint8_t mode)** pin = 0..15, mode = INPUT, OUTPUT. Returns true if successful.
- **bool write1(uint8_t pin, uint8_t value)** pin = 0..15, value = LOW(0) HIGH (!0). Returns true if successful.
- **uint8_t read1(uint8_t pin)** pin = 0..15, returns LOW or HIGH, might set the lastError();
- **bool setPolarity(uint8_t pin, bool reversed)** pin = 0..15, set reversed flag. Returns true if successful.
- **bool getPolarity(uint8_t pin, bool &reversed)** pin = 0..15, reads reversed flag. Returns true if successful.
- **bool setPullup(uint8_t pin, bool pullup)** pin = 0..15, set pull-up flag. Returns true if successful.
@ -219,7 +241,7 @@ See examples.
- investigate and reimplement the INPUT_PULLUP for pinMode() ?
- RP2040 support for SPI, setGPIOpins() etc
- See MCP_DAC
- AVR software SPI optimize 0.3.0
- AVR software SPI optimize
- dao and clock - see fastShiftOut.
#### Wont

View File

@ -17,7 +17,7 @@ void setup()
{
Serial.begin(115200);
Serial.println();
Serial.print("MCP23S17_test version: ");
Serial.print("MCP23S17_LIB_VERSION: ");
Serial.println(MCP23S17_LIB_VERSION);
delay(100);
@ -34,10 +34,10 @@ void setup()
Serial.print("HWSPI: ");
Serial.println(MCP.usesHWSPI());
Serial.println("TEST digitalRead(pin)");
Serial.println("TEST read1(pin)");
for (int pin = 0; pin < 16; pin++)
{
int val = MCP.digitalRead(pin);
int val = MCP.read1(pin);
Serial.print(val);
Serial.print(' ');
delay(100);
@ -49,10 +49,10 @@ void setup()
void loop()
{
delay(1000);
Serial.println("TEST digitalRead(pin)");
Serial.println("TEST read1(pin)");
for (int pin = 0; pin < 16; pin++)
{
int val = MCP.digitalRead(pin);
int val = MCP.read1(pin);
Serial.print(val);
Serial.print(' ');
delay(100);

View File

@ -15,7 +15,7 @@ void setup()
{
Serial.begin(115200);
Serial.println();
Serial.print("MCP23S17_test version: ");
Serial.print("MCP23S17_LIB_VERSION: ");
Serial.println(MCP23S17_LIB_VERSION);
delay(100);
@ -27,11 +27,11 @@ void setup()
MCP.pinMode8(0, 0x00); // 0 = output , 1 = input
MCP.pinMode8(1, 0x00);
Serial.println("TEST digitalWrite(0)");
Serial.println("TEST write1(0)");
delay(100);
for (int i = 0; i < 16; i++)
{
MCP.digitalWrite(0, i % 2); // alternating HIGH/LOW
MCP.write1(0, i % 2); // alternating HIGH/LOW
Serial.print(i % 2);
Serial.print(' ');
delay(100);
@ -39,11 +39,11 @@ void setup()
Serial.println();
Serial.println();
Serial.println("TEST digitalWrite(pin)");
Serial.println("TEST write1(pin)");
delay(100);
for (int pin = 0; pin < 16; pin++)
{
MCP.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW
MCP.write1(pin, 1 - pin % 2); // alternating HIGH/LOW
Serial.print(1 - pin % 2);
Serial.print(' ');
delay(100);
@ -55,7 +55,7 @@ void setup()
for (int pin = 0; pin < 16; pin++)
{
int val = MCP.digitalRead(pin);
int val = MCP.read1(pin);
Serial.print(val);
Serial.print(' ');
delay(100);

View File

@ -61,9 +61,9 @@ void loop()
{
int pin = random(64);
int addr = random(4);
MCP[addr].digitalWrite(pin, HIGH);
MCP[addr].write1(pin, HIGH);
delay(100);
MCP[addr].digitalWrite(pin, LOW);
MCP[addr].write1(pin, LOW);
delay(100);
}

View File

@ -22,7 +22,7 @@ void setup()
{
Serial.begin(115200);
Serial.println();
Serial.print("MCP23S17_test version: ");
Serial.print("MCP23S17_LIB_VERSION: ");
Serial.println(MCP23S17_LIB_VERSION);
Serial.println();
delay(100);
@ -59,34 +59,34 @@ void test()
delay(100);
Serial.print("TEST digitalWrite(0, value):\t");
Serial.print("TEST write1(0, value):\t");
delay(100);
start = micros();
for (int i = 0; i < 16; i++)
{
MCP.digitalWrite(0, i & 0x01); // alternating HIGH/LOW
MCP.write1(0, i & 0x01); // alternating HIGH/LOW
}
stop = micros();
Serial.println((stop - start) / 16.0);
Serial.print("TEST digitalWrite(pin, value):\t");
Serial.print("TEST write1(pin, value):\t");
delay(100);
start = micros();
for (int pin = 0; pin < 16; pin++)
{
MCP.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW
MCP.write1(pin, 1 - pin % 2); // alternating HIGH/LOW
}
stop = micros();
Serial.println((stop - start) / 16.0);
Serial.print("TEST digitalRead(pin):\t");
Serial.print("TEST read1(pin):\t");
delay(100);
start = micros();
for (int pin = 0; pin < 16; pin++)
{
val1 = MCP.digitalRead(pin);
val1 = MCP.read1(pin);
}
stop = micros();
Serial.println((stop - start) / 16.0);

View File

@ -65,15 +65,15 @@ void ledbar_1(int x)
int i = 0;
while (i++ < x)
{
MCP.digitalWrite(i, HIGH);
MCP.write1(i, HIGH);
}
while (i++ < 10) MCP.digitalWrite(i, LOW);
while (i++ < 10) MCP.write1(i, LOW);
}
void ledbar_2(int x)
{
// use 16 bit bitmask.
// use 16 bit bit mask.
uint16_t n = (1 << x) - 1;
MCP.write16(n);
}

View File

@ -54,16 +54,16 @@ void loop()
int x = random(32);
if (x < 16)
{
MCP_A.digitalWrite(x, HIGH);
MCP_A.write1(x, HIGH);
delay(100);
MCP_A.digitalWrite(x, LOW);
MCP_A.write1(x, LOW);
}
else
{
x -= 16;
MCP_B.digitalWrite(x, HIGH);
MCP_B.write1(x, HIGH);
delay(100);
MCP_B.digitalWrite(x, LOW);
MCP_B.write1(x, LOW);
}
}

View File

@ -52,16 +52,16 @@ void loop()
int x = random(32);
if (x < 16)
{
MCP_A.digitalWrite(x, HIGH);
MCP_A.write1(x, HIGH);
delay(100);
MCP_A.digitalWrite(x, LOW);
MCP_A.write1(x, LOW);
}
else
{
x -= 16;
MCP_B.digitalWrite(x, HIGH);
MCP_B.write1(x, HIGH);
delay(100);
MCP_B.digitalWrite(x, LOW);
MCP_B.write1(x, LOW);
}
}

View File

@ -9,9 +9,9 @@ begin KEYWORD2
isConnected KEYWORD2
getAddress KEYWORD2
pinMode KEYWORD2
digitalWrite KEYWORD2
digitalRead KEYWORD2
pinMode1 KEYWORD2
write1 KEYWORD2
read1 KEYWORD2
setPolarity KEYWORD2
getPolarity KEYWORD2

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/MCP23S17.git"
},
"version": "0.3.0",
"version": "0.4.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=MCP23S17
version=0.3.0
version=0.4.0
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

View File

@ -113,9 +113,9 @@ unittest(test_pinMode)
MCP23S17 mcp_hw(10);
assertEqual(MCP23S17_OK, mcp_hw.lastError());
assertFalse(mcp_hw.pinMode(16, INPUT));
assertFalse(mcp_hw.pinMode1(16, INPUT));
assertEqual(MCP23S17_PIN_ERROR, mcp_hw.lastError());
assertFalse(mcp_hw.pinMode(0, 4));
assertFalse(mcp_hw.pinMode1(0, 4));
assertEqual(MCP23S17_VALUE_ERROR, mcp_hw.lastError());
}
@ -125,7 +125,7 @@ unittest(test_digitalWrite)
MCP23S17 mcp_hw(10);
assertEqual(MCP23S17_OK, mcp_hw.lastError());
assertFalse(mcp_hw.digitalWrite(16, 0));
assertFalse(mcp_hw.write1(16, 0));
assertEqual(MCP23S17_PIN_ERROR, mcp_hw.lastError());
}
@ -135,7 +135,7 @@ unittest(test_digitalRead)
MCP23S17 mcp_hw(10);
assertEqual(MCP23S17_OK, mcp_hw.lastError());
assertEqual(MCP23S17_INVALID_READ, mcp_hw.digitalRead(16));
assertEqual(MCP23S17_INVALID_READ, mcp_hw.read1(16));
assertEqual(MCP23S17_PIN_ERROR, mcp_hw.lastError());
}