Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/RobTillaart/MCP23S17
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Dec 24, 2023
2 parents e3f9ea4 + 0c1d926 commit 65e8190
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 49 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 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.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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
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.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
Expand All @@ -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
Expand Down Expand Up @@ -53,9 +53,9 @@ class MCP23S17

// 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);
Expand Down
10 changes: 5 additions & 5 deletions examples/MCP23S17_digitalRead/MCP23S17_digitalRead.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions examples/MCP23S17_digitalWrite/MCP23S17_digitalWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -27,23 +27,23 @@ 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);
}
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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions examples/MCP23S17_performance/MCP23S17_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions examples/MCP23S17_test_led_bar/MCP23S17_test_led_bar.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions examples/MCP23S17_two_ADDRESS/MCP23S17_two_ADDRESS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/MCP23S17_two_SELECT/MCP23S17_two_SELECT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.3.0",
"version": "0.4.0",
"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.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
Expand Down
8 changes: 4 additions & 4 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down

0 comments on commit 65e8190

Please sign in to comment.