diff --git a/PCF8575.cpp b/PCF8575.cpp index 5d3423c..7582691 100644 --- a/PCF8575.cpp +++ b/PCF8575.cpp @@ -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; @@ -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 "); diff --git a/PCF8575.h b/PCF8575.h index 1ea2842..017c930 100644 --- a/PCF8575.h +++ b/PCF8575.h @@ -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__); } @@ -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 @@ -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; diff --git a/library.properties b/library.properties index cdef4b2..82e55b3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8575 library -version=1.0.1 +version=1.0.2 author=Renzo Mischianti maintainer=Renzo Mischianti sentence=PCF8575, library for Arduino, ESP8266, smt32 and esp32 diff --git a/resources/testBoard.fzz b/resources/testBoard.fzz index eb03287..0f762b4 100644 Binary files a/resources/testBoard.fzz and b/resources/testBoard.fzz differ