Skip to content

Commit

Permalink
Add define to manage the labelling of the pin like the datasheet instead
Browse files Browse the repository at this point in the history
sequential
  • Loading branch information
xreef committed Jun 27, 2021
1 parent a44fd9d commit eef8d81
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 35 deletions.
21 changes: 19 additions & 2 deletions PCF8575.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,24 @@ void PCF8575::readBuffer(bool force){

DEBUG_PRINT("Buffer value ");
DEBUG_PRINTLN(byteBuffered, BIN);

#ifdef NOT_SEQUENTIAL_PINOUT
if ((bit(0) & readMode)>0) digitalInput.p00 = ((byteBuffered & bit(0))>0)?HIGH:LOW;
if ((bit(1) & readMode)>0) digitalInput.p01 = ((byteBuffered & bit(1))>0)?HIGH:LOW;
if ((bit(2) & readMode)>0) digitalInput.p02 = ((byteBuffered & bit(2))>0)?HIGH:LOW;
if ((bit(3) & readMode)>0) digitalInput.p03 = ((byteBuffered & bit(3))>0)?HIGH:LOW;
if ((bit(4) & readMode)>0) digitalInput.p04 = ((byteBuffered & bit(4))>0)?HIGH:LOW;
if ((bit(5) & readMode)>0) digitalInput.p05 = ((byteBuffered & bit(5))>0)?HIGH:LOW;
if ((bit(6) & readMode)>0) digitalInput.p06 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
if ((bit(7) & readMode)>0) digitalInput.p07 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
if ((bit(8) & readMode)>0) digitalInput.p10 = ((byteBuffered & bit(8))>0)?HIGH:LOW;
if ((bit(9) & readMode)>0) digitalInput.p11 = ((byteBuffered & bit(9))>0)?HIGH:LOW;
if ((bit(10) & readMode)>0) digitalInput.p12 = ((byteBuffered & bit(10))>0)?HIGH:LOW;
if ((bit(11) & readMode)>0) digitalInput.p13 = ((byteBuffered & bit(11))>0)?HIGH:LOW;
if ((bit(12) & readMode)>0) digitalInput.p14 = ((byteBuffered & bit(12))>0)?HIGH:LOW;
if ((bit(13) & readMode)>0) digitalInput.p15 = ((byteBuffered & bit(13))>0)?HIGH:LOW;
if ((bit(14) & readMode)>0) digitalInput.p16 = ((byteBuffered & bit(14))>0)?HIGH:LOW;
if ((bit(15) & readMode)>0) digitalInput.p17 = ((byteBuffered & bit(15))>0)?HIGH:LOW;
#else
if ((bit(0) & readMode)>0) digitalInput.p0 = ((byteBuffered & bit(0))>0)?HIGH:LOW;
if ((bit(1) & readMode)>0) digitalInput.p1 = ((byteBuffered & bit(1))>0)?HIGH:LOW;
if ((bit(2) & readMode)>0) digitalInput.p2 = ((byteBuffered & bit(2))>0)?HIGH:LOW;
Expand All @@ -297,7 +314,7 @@ void PCF8575::readBuffer(bool force){
if ((bit(13) & readMode)>0) digitalInput.p13 = ((byteBuffered & bit(13))>0)?HIGH:LOW;
if ((bit(14) & readMode)>0) digitalInput.p14 = ((byteBuffered & bit(14))>0)?HIGH:LOW;
if ((bit(15) & readMode)>0) digitalInput.p15 = ((byteBuffered & bit(15))>0)?HIGH:LOW;

#endif
if ((readMode & byteBuffered)>0){
byteBuffered = ~readMode & byteBuffered;
DEBUG_PRINT("Buffer hight value readed set readed ");
Expand Down
106 changes: 74 additions & 32 deletions PCF8575.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
// Define where debug output will be printed.
#define DEBUG_PRINTER Serial

// Define to manage original pinout of pcf8575
// like datasheet but not sequential
//#define NOT_SEQUENTIAL_PINOUT

// Setup debug printing macros.
#ifdef PCF8575_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
Expand All @@ -65,22 +69,41 @@
//#define P6 B01000000
//#define P7 B10000000
//
#define P0 0
#define P1 1
#define P2 2
#define P3 3
#define P4 4
#define P5 5
#define P6 6
#define P7 7
#define P8 8
#define P9 9
#define P10 10
#define P11 11
#define P12 12
#define P13 13
#define P14 14
#define P15 15
#ifdef NOT_SEQUENTIAL_PINOUT
#define P00 0
#define P01 1
#define P02 2
#define P03 3
#define P04 4
#define P05 5
#define P06 6
#define P07 7
#define P10 8
#define P11 9
#define P12 10
#define P13 11
#define P14 12
#define P15 13
#define P16 14
#define P17 15
#else
#define P0 0
#define P1 1
#define P2 2
#define P3 3
#define P4 4
#define P5 5
#define P6 6
#define P7 7
#define P8 8
#define P9 9
#define P10 10
#define P11 11
#define P12 12
#define P13 13
#define P14 14
#define P15 15
#endif

#include <math.h>

Expand Down Expand Up @@ -112,22 +135,41 @@ class PCF8575 {
uint8_t digitalRead(uint8_t pin);
#ifndef PCF8575_LOW_MEMORY
struct DigitalInput {
uint8_t p0;
uint8_t p1;
uint8_t p2;
uint8_t p3;
uint8_t p4;
uint8_t p5;
uint8_t p6;
uint8_t p7;
uint8_t p8;
uint8_t p9;
uint8_t p10;
uint8_t p11;
uint8_t p12;
uint8_t p13;
uint8_t p14;
uint8_t p15;
#ifdef NOT_SEQUENTIAL_PINOUT
uint8_t p00;
uint8_t p01;
uint8_t p02;
uint8_t p03;
uint8_t p04;
uint8_t p05;
uint8_t p06;
uint8_t p07;
uint8_t p10;
uint8_t p11;
uint8_t p12;
uint8_t p13;
uint8_t p14;
uint8_t p15;
uint8_t p16;
uint8_t p17;
#else
uint8_t p0;
uint8_t p1;
uint8_t p2;
uint8_t p3;
uint8_t p4;
uint8_t p5;
uint8_t p6;
uint8_t p7;
uint8_t p8;
uint8_t p9;
uint8_t p10;
uint8_t p11;
uint8_t p12;
uint8_t p13;
uint8_t p14;
uint8_t p15;
#endif
} digitalInput;


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=PCF8575 library
version=1.0.1
version=1.0.2
author=Renzo Mischianti <[email protected]>
maintainer=Renzo Mischianti <[email protected]>
sentence=PCF8575, library for Arduino, ESP8266, smt32 and esp32
Expand Down
Binary file modified resources/testBoard.fzz
Binary file not shown.

0 comments on commit eef8d81

Please sign in to comment.