Skip to content

Commit

Permalink
fix example, add RP2040 to build-CI (RobTillaart#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Oct 19, 2022
1 parent 4940727 commit 675c4cf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 55 deletions.
32 changes: 10 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,32 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.5] - 2022-06-17
## [0.3.6] - 2022-10-19
- fix example PCF8574_rotaryEncoder.ino
- add RP2040 to build-CI
- simplified changelog.md

### Added
## [0.3.5] - 2022-06-17
- add select(), selectN(), selectNone() and selectAll()
convenience wrappers


## [0.3.4] - 2022-04-11

### Added
- add CHANGELOG.md


### Fixed
- **begin(int sda, int scl)** int parameters for ESP alike.

- fix **begin(int sda, int scl)** int parameters for ESP alike.

## [0.3.3] - 2021-12-23

### Changed
- update library.json, license, readme, minor edits


## [0.3.2] - 2021-07-04

### Added
- fix #25 add setAddress()


## [0.3.1] - 2021-04-23

### Fixed
- Fix for platformIO compatibility


## [0.3.0] - 2021-01-03
- add multiWire support - inspired by mattbue - issue #14

### Added
- multiWire support - inspired by mattbue - issue #14

---

## [0.2.4] - 2020-12-17
- fix #6 tag problem 0.2.3
Expand All @@ -65,6 +51,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- added begin(dsa, scl) for ESP32
- added reverse()

----

## [0.1.9] - 2017-02-27
- fix warning about return in readButton8()

Expand Down
34 changes: 17 additions & 17 deletions PCF8574.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: PCF8574.cpp
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.5
// VERSION: 0.3.6
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
Expand Down Expand Up @@ -70,17 +70,17 @@ uint8_t PCF8574::getAddress()
}


// removed _wire->beginTransmission(_address);
// with @100 KHz -> 265 micros()
// without @100 KHz -> 132 micros()
// without @400 KHz -> 52 micros()
// TODO @800 KHz -> ??
// removed _wire->beginTransmission(_address);
// with @100 KHz -> 265 micros()
// without @100 KHz -> 132 micros()
// without @400 KHz -> 52 micros()
// TODO @800 KHz -> ??
uint8_t PCF8574::read8()
{
if (_wire->requestFrom(_address, (uint8_t)1) != 1)
{
_error = PCF8574_I2C_ERROR;
return _dataIn; // last value
return _dataIn; // last value
}
_dataIn = _wire->read();
return _dataIn;
Expand Down Expand Up @@ -148,25 +148,25 @@ void PCF8574::toggleMask(const uint8_t mask)
void PCF8574::shiftRight(const uint8_t n)
{
if ((n == 0) || (_dataOut == 0)) return;
if (n > 7) _dataOut = 0; // shift 8++ clears all, valid...
if (_dataOut != 0) _dataOut >>= n; // only shift if there are bits set
if (n > 7) _dataOut = 0; // shift 8++ clears all, valid...
if (_dataOut != 0) _dataOut >>= n; // only shift if there are bits set
PCF8574::write8(_dataOut);
}


void PCF8574::shiftLeft(const uint8_t n)
{
if ((n == 0) || (_dataOut == 0)) return;
if (n > 7) _dataOut = 0; // shift 8++ clears all, valid...
if (_dataOut != 0) _dataOut <<= n; // only shift if there are bits set
if (n > 7) _dataOut = 0; // shift 8++ clears all, valid...
if (_dataOut != 0) _dataOut <<= n; // only shift if there are bits set
PCF8574::write8(_dataOut);
}


int PCF8574::lastError()
{
int e = _error;
_error = PCF8574_OK; // reset error after read, is this wise?
_error = PCF8574_OK; // reset error after read, is this wise?
return e;
}

Expand All @@ -186,7 +186,7 @@ void PCF8574::rotateLeft(const uint8_t n)
}


void PCF8574::reverse() // quite fast: 14 shifts, 3 or, 3 assignment.
void PCF8574::reverse() // quite fast: 14 shifts, 3 or, 3 assignment.
{
uint8_t x = _dataOut;
x = (((x & 0xAA) >> 1) | ((x & 0x55) << 1));
Expand All @@ -196,18 +196,18 @@ void PCF8574::reverse() // quite fast: 14 shifts, 3 or, 3 assignment.
}


//added 0.1.07/08 Septillion
// added 0.1.07/08 Septillion
uint8_t PCF8574::readButton8(const uint8_t mask)
{
uint8_t temp = _dataOut;
PCF8574::write8(mask | _dataOut); // read only selected lines
PCF8574::write8(mask | _dataOut); // read only selected lines
PCF8574::read8();
PCF8574::write8(temp); // restore
PCF8574::write8(temp); // restore
return _dataIn;
}


//added 0.1.07 Septillion
// added 0.1.07 Septillion
uint8_t PCF8574::readButton(const uint8_t pin)
{
if (pin > 7)
Expand Down
12 changes: 6 additions & 6 deletions PCF8574.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// FILE: PCF8574.h
// AUTHOR: Rob Tillaart
// DATE: 02-febr-2013
// VERSION: 0.3.5
// VERSION: 0.3.6
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8574
// http://forum.arduino.cc/index.php?topic=184800
Expand All @@ -14,7 +14,7 @@
#include "Wire.h"


#define PCF8574_LIB_VERSION (F("0.3.5"))
#define PCF8574_LIB_VERSION (F("0.3.6"))

#ifndef PCF8574_INITIAL_VALUE
#define PCF8574_INITIAL_VALUE 0xFF
Expand All @@ -37,8 +37,8 @@ class PCF8574
bool isConnected();


// note: setting the address corrupt internal buffer values
// a read8() / write8() call updates them.
// note: setting the address corrupt internal buffer values
// a read8() / write8() call updates them.
bool setAddress(const uint8_t deviceAddress);
uint8_t getAddress();

Expand All @@ -53,15 +53,15 @@ class PCF8574
uint8_t valueOut() const { return _dataOut; }


//added 0.1.07/08 Septillion
// added 0.1.07/08 Septillion
uint8_t readButton8() { return PCF8574::readButton8(_buttonMask); }
uint8_t readButton8(const uint8_t mask);
uint8_t readButton(const uint8_t pin);
void setButtonMask(const uint8_t mask) { _buttonMask = mask; };
uint8_t getButtonMask() { return _buttonMask; };


// 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 uint8_t mask = 0xFF); // default 0xFF ==> invertAll()
void shiftRight(const uint8_t n = 1);
Expand Down
16 changes: 8 additions & 8 deletions examples/PCF8574_rotaryEncoder/PCF8574_rotaryEncoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
// SCL A5
// INT 2
//
// note: a dedicated rotary decoder class is created
// - https://github.com/RobTillaart/rotaryDecoder -
// note: a dedicated rotary decoder class is created
// - https://github.com/RobTillaart/rotaryDecoder -


#include "PCF8574.h"

PCF8574 decoder(0x20);


// hold position of 4 RE + last position
// hold position of 4 RE + last position
uint8_t lastpos[4] = {0, 0, 0, 0};
int32_t encoder[4] = {0, 0, 0, 0};
volatile bool flag = false;


// IRQ routine
// IRQ routine
void moved()
{
flag = true;
Expand Down Expand Up @@ -96,7 +96,7 @@ void initRotaryDecoder()
}


// assumes 4 rotary encoders connected to one PCF8574
// assumes 4 rotary encoders connected to one PCF8574
void updateRotaryDecoder()
{
uint8_t val = decoder.read8();
Expand All @@ -105,12 +105,12 @@ void updateRotaryDecoder()
for (uint8_t i = 0; i < 4; i++)
{
uint8_t currentpos = (val & 0x03);
if (lastpos[i] != currentpos) // moved!
if (lastpos[i] != currentpos) // moved!
{
uint8_t change = (lastpos[i] << 2) | currentpos;
switch (change)
{
case 0b0001: // fall through..
case 0b0001: // fall through..
case 0b0111:
case 0b1110:
case 0b1000:
Expand All @@ -124,8 +124,8 @@ void updateRotaryDecoder()
break;
}
lastpos[i] = currentpos;
val >>= 2;
}
val >>= 2;
}
}

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/PCF8574.git"
},
"version": "0.3.5",
"version": "0.3.6",
"license": "MIT",
"frameworks": "arduino",
"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=PCF8574
version=0.3.5
version=0.3.6
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander
Expand Down

0 comments on commit 675c4cf

Please sign in to comment.