0.1.7 PCF8575

This commit is contained in:
rob tillaart 2022-11-21 20:26:00 +01:00
parent 7b9b3d225c
commit df229d7bb7
11 changed files with 144 additions and 94 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,6 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

View File

@ -2,11 +2,12 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- 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@v2
- uses: actions/checkout@v3
- 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@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -6,75 +6,52 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.6] - 2022-06-18
## [0.1.6] - 2022-11-21
- add RP2040 to build-CI
- simplified changelog.md
- add interrupt section to readme.md
- update GitHub actions from v2 -> v3 (kudos to Thijs Triemstra)
### Added
## [0.1.6] - 2022-06-18
- add select(), selectN(), selectAll(), selectNone()
- update documentation
## [0.1.5] - 2022-04-11
### Added
- add CHANGELOG.md
### Changed
### Fixed
- **begin(int sda, int scl)** int parameters for ESP alike.
to keep in sync with PCF8574 library.
to keep this library in sync with PCF8574 library.
## [0.1.4] - 2021-12-23
### Changed
- update library.json, license, readme, minor edits
- update library.json
- update license
- update readme.md
- minor edits
## [0.1.3] - 2021-12-01
## Added
- add getButtonMask()
### Changed
- update build-CI, readme
- update build-CI
- update readme.md
## [0.1.2] - 2021-07-09
### Fixed
- fix #10 add set/getAddress() function
- fix #10 add set/getAddress()
## [0.1.1] - 2021-04-23
### Fixed
- fix for platformIO compatibility
## [0.1.0] - 2021-01-03
### Added
- add Arduino-CI + unit tests
----
## [0.0.3] - 2020-07-29
### Fixed
- fix #5 reverse() + refactor.
- fix #5 reverse()
- refactor.
## [0.0.2] - 2020-07-21
### Fixed
- fix reverse(); refactor;
- fix reverse()
- refactor;
## [0.0.1] - 2020-07-20
### Added
- initial version

View File

@ -83,16 +83,6 @@ uint16_t PCF8575::read16()
}
void PCF8575::write16(const uint16_t value)
{
_dataOut = value;
_wire->beginTransmission(_address);
_wire->write(_dataOut & 0xFF); // low 8 bits
_wire->write(_dataOut >> 8); // high 8 bits
_error = _wire->endTransmission();
}
uint8_t PCF8575::read(const uint8_t pin)
{
if (pin > 15)
@ -105,6 +95,22 @@ uint8_t PCF8575::read(const uint8_t pin)
}
uint16_t PCF8575::value()
{
return _dataIn;
};
void PCF8575::write16(const uint16_t value)
{
_dataOut = value;
_wire->beginTransmission(_address);
_wire->write(_dataOut & 0xFF); // low 8 bits
_wire->write(_dataOut >> 8); // high 8 bits
_error = _wire->endTransmission();
}
void PCF8575::write(const uint8_t pin, const uint8_t value)
{
if (pin > 15)
@ -124,6 +130,12 @@ void PCF8575::write(const uint8_t pin, const uint8_t value)
}
uint16_t PCF8575::valueOut()
{
return _dataOut;
}
void PCF8575::toggle(const uint8_t pin)
{
if (pin > 15)
@ -160,14 +172,6 @@ void PCF8575::shiftLeft(const uint8_t n)
}
int PCF8575::lastError()
{
int e = _error;
_error = PCF8575_OK; // reset error after read, is this wise?
return e;
}
void PCF8575::rotateRight(const uint8_t n)
{
uint8_t r = n & 15;
@ -183,9 +187,9 @@ void PCF8575::rotateLeft(const uint8_t n)
}
void PCF8575::reverse() // quite fast
void PCF8575::reverse() // quite fast
{ // 1 char === 1 bit
uint16_t x = _dataOut; // x = 0123456789ABCDEF
uint16_t x = _dataOut; // x = 0123456789ABCDEF
x = (((x & 0xAAAA) >> 1) | ((x & 0x5555) << 1)); // x = 1032547698BADCFE
x = (((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2)); // x = 32107654BA98FEDC
x = (((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4)); // x = 76543210FEDCBA98
@ -194,7 +198,10 @@ void PCF8575::reverse() // quite fast
}
//added 0.1.07/08 Septillion
//////////////////////////////////////////////////
//
// added 0.1.07/08 Septillion
//
uint16_t PCF8575::readButton16(const uint16_t mask)
{
uint16_t temp = _dataOut;
@ -205,7 +212,12 @@ uint16_t PCF8575::readButton16(const uint16_t mask)
}
//added 0.1.07 Septillion
uint16_t PCF8575::readButton16()
{
return readButton16(_buttonMask);
}
uint8_t PCF8575::readButton(const uint8_t pin)
{
if (pin > 15)
@ -221,6 +233,22 @@ uint8_t PCF8575::readButton(const uint8_t pin)
}
void PCF8575::setButtonMask(uint16_t mask)
{
_buttonMask = mask;
};
uint16_t PCF8575::getButtonMask()
{
return _buttonMask;
};
//////////////////////////////////////////////////
//
// SELECT
//
void PCF8575::select(const uint8_t pin)
{
uint16_t n = 0x0000;
@ -229,7 +257,7 @@ void PCF8575::select(const uint8_t pin)
};
void PCF8575::selectN(const uint8_t pin)
void PCF8575::selectN(const uint8_t pin)
{
uint16_t n = 0xFFFF;
if (pin < 16) n = (2L << pin) - 1;
@ -237,6 +265,25 @@ void PCF8575::selectN(const uint8_t pin)
};
void PCF8575::selectNone()
{
write16(0x0000);
};
// -- END OF FILE --
void PCF8575::selectAll()
{
write16(0xFFFF);
};
int PCF8575::lastError()
{
int e = _error;
_error = PCF8575_OK; // reset error after read, is this wise?
return e;
}
// -- END OF FILE --

View File

@ -3,17 +3,16 @@
// FILE: PCF8575.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-20
// VERSION: 0.1.6
// VERSION: 0.1.7
// PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8575
//
#include "Arduino.h"
#include "Wire.h"
#define PCF8575_LIB_VERSION (F("0.1.6"))
#define PCF8575_LIB_VERSION (F("0.1.7"))
#ifndef PCF8575_INITIAL_VALUE
@ -28,7 +27,7 @@
class PCF8575
{
public:
// deviceAddress base = 0x20 + depends on address bits
// deviceAddress base = 0x20 + depends on address bits
explicit PCF8575(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
@ -38,33 +37,33 @@ public:
bool isConnected();
// note: setting the address corrupt internal buffer values
// a read8() / write8() call updates them.
// note: setting the address may corrupt internal buffer values
// a read16() / write16() call updates them.
bool setAddress(const uint8_t deviceAddress);
uint8_t getAddress();
uint8_t getAddress();
uint16_t read16();
uint8_t read(uint8_t pin);
uint16_t value() const { return _dataIn; };
uint16_t value();
void write16(const uint16_t value);
void write(const uint8_t pin, const uint8_t value);
uint16_t valueOut() const { return _dataOut; }
uint16_t valueOut();
// added 0.1.07/08 Septillion
uint16_t readButton16() { return readButton16(_buttonMask); }
uint16_t readButton16();
uint16_t readButton16(const uint16_t mask);
uint8_t readButton(const uint8_t pin);
void setButtonMask(uint16_t mask) { _buttonMask = mask; };
uint16_t getButtonMask() { return _buttonMask; };
void setButtonMask(uint16_t mask);
uint16_t getButtonMask();
// rotate, shift, toggle, reverse expect all lines are output
// rotate, shift, toggle, reverse expect all lines are output
void toggle(const uint8_t pin);
void toggleMask(const uint16_t mask = 0xFFFF); // default invertAll()
void toggleMask(const uint16_t mask = 0xFFFF); // 0xFFFF == invertAll()
void shiftRight(const uint8_t n = 1);
void shiftLeft(const uint8_t n = 1);
void rotateRight(const uint8_t n = 1);
@ -72,10 +71,10 @@ public:
void reverse();
void select(const uint8_t pin);
void selectN(const uint8_t pin);
void selectNone() { write16(0x0000); };
void selectAll() { write16(0xFFFF); };
void select(const uint8_t pin);
void selectN(const uint8_t pin);
void selectNone();
void selectAll();
int lastError();

View File

@ -22,8 +22,6 @@ Base address = 0x20 + 0..7 depending on address pins A0..A2.
| TYPE | ADDRESS-RANGE | notes |
|:---------|:-------------:|:------------------------:|
|PCF8575 | 0x20 to 0x27 | same range as PCF8574 !! |
| | | |
So you can connect up to 8 PCF8575 on one I2C bus, giving access
to 8 x 16 = 128 IO lines.
@ -35,6 +33,18 @@ The library allows to read and write both single pins or 16 pins at once.
Furthermore some additional functions are implemented that are playful and useful.
#### Interrupts
The PCF8575 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed.
This can be used to prevent active polling of the PCF8575, which can be more efficient.
The library cannot handle the PCF8575 interrupts as it has no code for it.
The user should catch the interrupt in his own code and can use the library to see which line has changed.
There is one example to show how interrupts can be used:
- PCF8575_interrupt.ino
## I2C Clock
Testing showed that the PCF8575 still works at 600 KHz and failed at 800 KHz.

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PCF8575.git"
},
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=PCF8575
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for PCF8575 - 16 channel I2C IO expander

View File

@ -1,7 +1,6 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2020-12-03
// PURPOSE: unit tests for the PCF8575 I2C port expander
// https://github.com/RobTillaart/PCF8575