mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.6.0 MCP23017_RT
This commit is contained in:
parent
db25e10016
commit
bbc9c7e115
@ -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.6.0] 2023-12-24
|
||||
- Fix #26, support for Arduino ESP32 S3 - breaking change
|
||||
- update readme.md
|
||||
- update examples.
|
||||
|
||||
----
|
||||
|
||||
## [0.5.0] 2023-12-10
|
||||
- refactor API, begin()
|
||||
- add **uimt8_t getADdress()**
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: MCP23017.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.5.0
|
||||
// VERSION: 0.6.0
|
||||
// PURPOSE: Arduino library for I2C MCP23017 16 channel port expander
|
||||
// DATE: 2019-10-12
|
||||
// URL: https://github.com/RobTillaart/MCP23017_RT
|
||||
@ -80,7 +80,7 @@ uint8_t MCP23017::getAddress()
|
||||
// single pin interface
|
||||
// pin = 0..15
|
||||
// mode = INPUT, OUTPUT, INPUT_PULLUP (= same as INPUT)
|
||||
bool MCP23017::pinMode(uint8_t pin, uint8_t mode)
|
||||
bool MCP23017::pinMode1(uint8_t pin, uint8_t mode)
|
||||
{
|
||||
if (pin > 15)
|
||||
{
|
||||
@ -126,7 +126,7 @@ bool MCP23017::pinMode(uint8_t pin, uint8_t mode)
|
||||
|
||||
// pin = 0..15
|
||||
// value = LOW, HIGH
|
||||
bool MCP23017::digitalWrite(uint8_t pin, uint8_t value)
|
||||
bool MCP23017::write1(uint8_t pin, uint8_t value)
|
||||
{
|
||||
if (pin > 15)
|
||||
{
|
||||
@ -168,7 +168,7 @@ bool MCP23017::digitalWrite(uint8_t pin, uint8_t value)
|
||||
}
|
||||
|
||||
|
||||
uint8_t MCP23017::digitalRead(uint8_t pin)
|
||||
uint8_t MCP23017::read1(uint8_t pin)
|
||||
{
|
||||
if (pin > 15)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: MCP23017.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.5.0
|
||||
// VERSION: 0.6.0
|
||||
// PURPOSE: Arduino library for I2C MCP23017 16 channel port expander
|
||||
// DATE: 2019-10-12
|
||||
// URL: https://github.com/RobTillaart/MCP23017_RT
|
||||
@ -14,7 +14,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define MCP23017_LIB_VERSION (F("0.5.0"))
|
||||
#define MCP23017_LIB_VERSION (F("0.6.0"))
|
||||
|
||||
#define MCP23017_OK 0x00
|
||||
#define MCP23017_PIN_ERROR 0x81
|
||||
@ -38,9 +38,9 @@ public:
|
||||
|
||||
// single pin interface
|
||||
// mode = INPUT, OUTPUT or 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);
|
||||
|
@ -21,7 +21,7 @@ This library gives easy control over the 16 pins of a (I2C) MCP23017 chip.
|
||||
This IC is strongly related tot the MCP23S17 SPI port expander - https://github.com/RobTillaart/MCP23S17
|
||||
Programming Interface is kept the same as much as possible.
|
||||
|
||||
Since 0.3.1 the **digitalWrite(pin, value)** is optimized.
|
||||
The **write1(pin, value)** is optimized.
|
||||
If a pin is not changed it will not be written again to save time.
|
||||
|
||||
|
||||
@ -49,6 +49,28 @@ However low prio.
|
||||
Note that the MCP23S017 (SPI version) does not have this "feature" for GPA7 and GPB7.
|
||||
|
||||
|
||||
#### 0.6.0 Breaking change
|
||||
|
||||
The version 0.6.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.5.0 Breaking change
|
||||
|
||||
Version 0.5.0 introduced a breaking change.
|
||||
@ -102,9 +124,9 @@ Can be overruled with Wire0..WireN.
|
||||
|
||||
Please note REVD remarks at top.
|
||||
|
||||
- **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.
|
||||
|
@ -15,7 +15,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(230400);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23017_test version: ");
|
||||
Serial.print("MCP23017_LIB_VERSION: ");
|
||||
Serial.println(MCP23017_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
@ -24,10 +24,10 @@ void setup()
|
||||
MCP.pinMode8(0, 0x00); // CHECK
|
||||
MCP.pinMode8(1, 0x00);
|
||||
|
||||
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('\t');
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(230400);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("MCP23017_test version: ");
|
||||
Serial.print("MCP23017_LIB_VERSION: ");
|
||||
Serial.println(MCP23017_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
@ -27,10 +27,10 @@ void setup()
|
||||
MCP.pinMode8(1, 0x00);
|
||||
Wire.setClock(50);
|
||||
|
||||
Serial.println("TEST digitalWrite(0)");
|
||||
Serial.println("TEST write1(0)");
|
||||
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('\t');
|
||||
delay(250);
|
||||
@ -38,10 +38,10 @@ void setup()
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
Serial.println("TEST digitalWrite(pin)");
|
||||
Serial.println("TEST write1(pin)");
|
||||
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('\t');
|
||||
}
|
||||
@ -52,7 +52,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('\t');
|
||||
}
|
||||
|
@ -35,35 +35,35 @@ void setup()
|
||||
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();
|
||||
volatile int val = 0;
|
||||
for (int pin = 0; pin < 16; pin++)
|
||||
{
|
||||
val = MCP.digitalRead(pin);
|
||||
val = MCP.read1(pin);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.println((stop - start) / 16.0);
|
||||
|
@ -33,7 +33,7 @@ void setup()
|
||||
//
|
||||
// test 8 bit interface
|
||||
//
|
||||
Serial.println("TEST digitalWrite8(port, value)");
|
||||
Serial.println("TEST write8(port, value) + read8(port)");
|
||||
for (uint16_t i = 0; i < 256; i++)
|
||||
{
|
||||
MCP.write8(0, i);
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/MCP23017_RT.git"
|
||||
},
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=MCP23017_RT
|
||||
version=0.5.0
|
||||
version=0.6.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for I2C MCP23017 16 channel port expander 16 IO-lines
|
||||
|
@ -85,21 +85,21 @@ unittest(test_lastError)
|
||||
assertEqual(MCP23017_OK, MCP.lastError());
|
||||
|
||||
// MCP23017_PIN_ERROR
|
||||
MCP.pinMode(16, INPUT);
|
||||
MCP.pinMode1(16, INPUT);
|
||||
assertEqual(MCP23017_PIN_ERROR, MCP.lastError());
|
||||
assertEqual(MCP23017_OK, MCP.lastError());
|
||||
|
||||
MCP.digitalWrite(16, 1);
|
||||
MCP.write1(16, 1);
|
||||
assertEqual(MCP23017_PIN_ERROR, MCP.lastError());
|
||||
assertEqual(MCP23017_OK, MCP.lastError());
|
||||
|
||||
uint8_t y = MCP.digitalRead(16);
|
||||
uint8_t y = MCP.read1(16);
|
||||
assertEqual(MCP23017_PIN_ERROR, MCP.lastError());
|
||||
assertEqual(MCP23017_OK, MCP.lastError());
|
||||
|
||||
|
||||
// MCP23017_VALUE_ERROR - 3 is not INPUT, INPUT_PULLUP, OUTPUT)
|
||||
MCP.pinMode(0, 3);
|
||||
MCP.pinMode1(0, 3);
|
||||
assertEqual(MCP23017_VALUE_ERROR, MCP.lastError());
|
||||
assertEqual(MCP23017_OK, MCP.lastError());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user