diff --git a/LICENSE b/LICENSE index 8eba944..c3d6b3d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2021 Rob Tillaart +Copyright (c) 2020-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/PCF8575.cpp b/PCF8575.cpp index d3187b9..cf709eb 100644 --- a/PCF8575.cpp +++ b/PCF8575.cpp @@ -2,7 +2,7 @@ // FILE: PCF8575.cpp // AUTHOR: Rob Tillaart // DATE: 2020-07-20 -// VERSION: 0.1.3 +// VERSION: 0.1.4 // PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8575 // @@ -15,6 +15,7 @@ // 0.1.2 2021-07-09 fix #10 add set/getAddress() function // 0.1.3 2021-12-01 update build-CI, readme // add getButtonMask() +// 0.1.4 2021-12-23 update library.json, license, minor edits #include "PCF8575.h" @@ -32,7 +33,7 @@ PCF8575::PCF8575(const uint8_t deviceAddress, TwoWire *wire) #if defined (ESP8266) || defined(ESP32) -bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t val) +bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t value) { _wire = &Wire; if ((dataPin < 255) && (clockPin < 255)) @@ -42,17 +43,17 @@ bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t val) _wire->begin(); } if (! isConnected()) return false; - PCF8575::write16(val); + PCF8575::write16(value); return true; } #endif -bool PCF8575::begin(uint16_t val) +bool PCF8575::begin(uint16_t value) { _wire->begin(); if (! isConnected()) return false; - PCF8575::write16(val); + PCF8575::write16(value); return true; } @@ -152,7 +153,7 @@ void PCF8575::toggleMask(const uint16_t mask) void PCF8575::shiftRight(const uint8_t n) { if ((n == 0) || (_dataOut == 0)) return; - if (n > 15) _dataOut = 0; // shift 8++ clears all, valid... + if (n > 15) _dataOut = 0; // shift 15++ clears all, valid... if (_dataOut != 0) _dataOut >>= n; // only shift if there are bits set PCF8575::write16(_dataOut); } @@ -161,7 +162,7 @@ void PCF8575::shiftRight(const uint8_t n) void PCF8575::shiftLeft(const uint8_t n) { if ((n == 0) || (_dataOut == 0)) return; - if (n > 15) _dataOut = 0; // shift 8++ clears all, valid... + if (n > 15) _dataOut = 0; // shift 15++ clears all, valid... if (_dataOut != 0) _dataOut <<= n; // only shift if there are bits set PCF8575::write16(_dataOut); } @@ -229,3 +230,4 @@ uint8_t PCF8575::readButton(const uint8_t pin) // -- END OF FILE -- + diff --git a/PCF8575.h b/PCF8575.h index 8256a8e..684cda3 100644 --- a/PCF8575.h +++ b/PCF8575.h @@ -3,7 +3,7 @@ // FILE: PCF8575.h // AUTHOR: Rob Tillaart // DATE: 2020-07-20 -// VERSION: 0.1.3 +// VERSION: 0.1.4 // PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander // URL: https://github.com/RobTillaart/PCF8575 // @@ -16,7 +16,7 @@ #include "Wire.h" -#define PCF8575_LIB_VERSION (F("0.1.3")) +#define PCF8575_LIB_VERSION (F("0.1.4")) #ifndef PCF8575_INITIAL_VALUE @@ -32,12 +32,12 @@ class PCF8575 { public: // deviceAddress base = 0x20 + depends on address bits - explicit PCF8575(const uint8_t deviceAddress, TwoWire *wire = &Wire); + explicit PCF8575(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire); #if defined (ESP8266) || defined(ESP32) - bool begin(uint8_t sda, uint8_t scl, uint16_t val = PCF8575_INITIAL_VALUE); + bool begin(uint8_t sda, uint8_t scl, uint16_t value = PCF8575_INITIAL_VALUE); #endif - bool begin(uint16_t val = PCF8575_INITIAL_VALUE); + bool begin(uint16_t value = PCF8575_INITIAL_VALUE); bool isConnected(); @@ -90,3 +90,4 @@ class PCF8575 // -- END OF FILE -- + diff --git a/README.md b/README.md index c57c655..b3a0355 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ the include of "pcf8575.h" to overrule the default value used with the ### Constructor -- **PCF8575(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address, -and optional the Wire interface as parameter. -- **bool begin(uint8_t val = PCF8575_INITIAL_VALUE)** set the initial value for the pins and masks. -- **bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8575_INITIAL_VALUE)** idem, +- **PCF8575(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with the optional +I2C device address, default 0x20, and the optional Wire interface as parameter. +- **bool begin(uint8_t value = PCF8575_INITIAL_VALUE)** set the initial value for the pins and masks. +- **bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t value = PCF8575_INITIAL_VALUE)** idem, for the ESP32 where one can choose the I2C pins. - **bool isConnected()** checks if the address is visible on the I2C bus. - **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction. @@ -132,3 +132,5 @@ See examples. - update documentation. - keep in sync with pcf8574 (as far as meaningful) +- **value()** => **lastRead16()** ?? + diff --git a/examples/PCF8575_Wire2/PCF8575_Wire2.ino b/examples/PCF8575_Wire2/PCF8575_Wire2.ino index c71c1bb..bf702f2 100644 --- a/examples/PCF8575_Wire2/PCF8575_Wire2.ino +++ b/examples/PCF8575_Wire2/PCF8575_Wire2.ino @@ -2,15 +2,15 @@ // FILE: PCF8575_Wire2.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// -// PUPROSE: demo -// +// PUPROSE: demo + #include "PCF8575.h" // adjust addresses if needed PCF8575 PCF(0x39, &Wire2); + void setup() { Serial.begin(115200); @@ -34,6 +34,7 @@ void setup() delay(1000); } + void loop() { Serial.println("HLT"); @@ -46,6 +47,7 @@ void loop() } } + void doHigh() { PCF.write(4, HIGH); @@ -54,6 +56,7 @@ void doHigh() Serial.println(x, HEX); } + void doLow() { PCF.write(4, LOW); @@ -62,6 +65,7 @@ void doLow() Serial.println(x, HEX); } + void doToggle() { PCF.toggle(4); @@ -70,4 +74,6 @@ void doToggle() Serial.println(x, HEX); } + // -- END OF FILE -- + diff --git a/examples/PCF8575_array/PCF8575_array.ino b/examples/PCF8575_array/PCF8575_array.ino index 31f1d3e..12ac3df 100644 --- a/examples/PCF8575_array/PCF8575_array.ino +++ b/examples/PCF8575_array/PCF8575_array.ino @@ -3,7 +3,7 @@ // AUTHOR: Rob Tillaart // DATE: 2021-12-13 // PUPROSE: demo array of PCF - not tested -// + #include "PCF8575.h" @@ -28,6 +28,7 @@ void setup() } } + void loop() { for (int i = 0; i < 3; i++) @@ -52,3 +53,4 @@ void loop() // -- END OF FILE -- + diff --git a/examples/PCF8575_interrupt/PCF8575_interrupt.ino b/examples/PCF8575_interrupt/PCF8575_interrupt.ino index ad1df70..ec70bad 100644 --- a/examples/PCF8575_interrupt/PCF8575_interrupt.ino +++ b/examples/PCF8575_interrupt/PCF8575_interrupt.ino @@ -4,18 +4,19 @@ // DATE: 2021-01-03 // PUPROSE: test PCF8575 library // - // TEST SETUP -// Connect INT pin of the PCF8575 to UNO pin 2 +// Connect INT pin of the PCF8575 to UNO pin 2 // -// (from figure 4 datasheet -// Place a pull up resistor 4K7 between pin and 5V -// Place a capacitor 10-400pF between pin and GND +// (from figure 4 datasheet +// Place a pull up resistor 4K7 between pin and 5V +// Place a capacitor 10-400 pF between pin and GND + #include "PCF8575.h" PCF8575 PCF(0x38); + //////////////////////////////////// // // INTERRUPT ROUTINE + FLAG @@ -47,6 +48,7 @@ void setup() attachInterrupt(digitalPinToInterrupt(IRQPIN), pcf_irq, FALLING); } + void loop() { uint32_t now = millis(); @@ -64,4 +66,6 @@ void loop() delay(10); } + // -- END OF FILE -- + diff --git a/examples/PCF8575_isConnected/PCF8575_isConnected.ino b/examples/PCF8575_isConnected/PCF8575_isConnected.ino index 0975e42..8c564a0 100644 --- a/examples/PCF8575_isConnected/PCF8575_isConnected.ino +++ b/examples/PCF8575_isConnected/PCF8575_isConnected.ino @@ -2,15 +2,15 @@ // FILE: PCF8575_isConnected.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// -// PUPROSE: demo -// +// PUPROSE: demo device detection + #include "PCF8575.h" // adjust addresses if needed PCF8575 PCF(0x39); + void setup() { Serial.begin(115200); @@ -32,8 +32,11 @@ void setup() } } + void loop() { } + // -- END OF FILE -- + diff --git a/examples/PCF8575_performance/PCF8575_performance.ino b/examples/PCF8575_performance/PCF8575_performance.ino index 1e27a30..a3b500b 100644 --- a/examples/PCF8575_performance/PCF8575_performance.ino +++ b/examples/PCF8575_performance/PCF8575_performance.ino @@ -2,9 +2,9 @@ // FILE: PCF8575_performance.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-24 -// // PUPROSE: test PCF8575 library + #include "PCF8575.h" PCF8575 PCF(0x38); @@ -13,6 +13,7 @@ uint32_t start, stop; volatile uint16_t x; + void setup() { Serial.begin(115200); @@ -41,10 +42,13 @@ void setup() Serial.println(stop - start); delay(1000); } - } + void loop() { - } + + +// -- END OF FILE -- + diff --git a/examples/PCF8575_test/PCF8575_test.ino b/examples/PCF8575_test/PCF8575_test.ino index 6a8cb2e..cfa4281 100644 --- a/examples/PCF8575_test/PCF8575_test.ino +++ b/examples/PCF8575_test/PCF8575_test.ino @@ -5,17 +5,19 @@ // PUPROSE: test PCF8575 library // URL: https://github.com/RobTillaart/PCF8575 + #include "PCF8575.h" PCF8575 PCF(0x38); + void setup() { Serial.begin(115200); Serial.println(__FILE__); Serial.print("PCF8575_test version: "); Serial.println(PCF8575_LIB_VERSION); - + PCF.begin(); uint16_t x = PCF.read16(); @@ -24,6 +26,7 @@ void setup() delay(1000); } + void loop() { Serial.println("HLT"); @@ -36,6 +39,7 @@ void loop() } } + void doHigh() { PCF.write(4, HIGH); @@ -44,6 +48,7 @@ void doHigh() printHex(x); } + void doLow() { PCF.write(4, LOW); @@ -52,6 +57,7 @@ void doLow() printHex(x); } + void doToggle() { PCF.toggle(4); @@ -69,4 +75,6 @@ void printHex(uint16_t x) Serial.println(x, HEX); } + // -- END OF FILE -- + diff --git a/examples/PCF8575_test1/PCF8575_test1.ino b/examples/PCF8575_test1/PCF8575_test1.ino index 5aa0bdd..bef1d61 100644 --- a/examples/PCF8575_test1/PCF8575_test1.ino +++ b/examples/PCF8575_test1/PCF8575_test1.ino @@ -2,9 +2,8 @@ // FILE: pcf8575_test.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// // PUPROSE: demo -// + #include "PCF8575.h" @@ -12,6 +11,7 @@ PCF8575 PCF_38(0x38); // add switches to lines (used as input) PCF8575 PCF_39(0x39); // add leds to lines (used as output) + void setup() { Serial.begin(115200); @@ -62,6 +62,7 @@ void setup() } } + void loop() { // echos the lines @@ -70,4 +71,6 @@ void loop() delay(100); } -// END OF FILE + +// -- END OF FILE -- + diff --git a/examples/PCF8575_test2/PCF8575_test2.ino b/examples/PCF8575_test2/PCF8575_test2.ino index a1c2714..9294cdb 100644 --- a/examples/PCF8575_test2/PCF8575_test2.ino +++ b/examples/PCF8575_test2/PCF8575_test2.ino @@ -2,14 +2,14 @@ // FILE: pcf8575_test2.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 -// // PUPROSE: demo rotateLeft, -Right and toggleMask -// + #include "PCF8575.h" // adjust addresses if needed -PCF8575 PCF(0x39); // add leds to lines (used as output) +PCF8575 PCF(0x39); // add LEDs to lines (used as output) + void setup() { @@ -61,8 +61,11 @@ void setup() } } + void loop() { } + // -- END OF FILE -- + diff --git a/keywords.txt b/keywords.txt index af1d6f3..8ccbe43 100644 --- a/keywords.txt +++ b/keywords.txt @@ -1,8 +1,10 @@ # Syntax Colouring Map For PCF8575 + # Data types (KEYWORD1) PCF8575 KEYWORD1 + # Methods and Functions (KEYWORD2) begin KEYWORD2 isConnected KEYWORD2 @@ -32,5 +34,11 @@ reverse KEYWORD2 lastError KEYWORD2 + # Constants (LITERAL1) +PCF8575_LIB_VERSION LITERAL1 +PCF8575_INITIAL_VALUE LITERAL1 +PCF8575_OK LITERAL1 +PCF8575_PIN_ERROR LITERAL1 +PCF8575_I2C_ERROR LITERAL1 diff --git a/library.json b/library.json index acfb895..962044c 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/PCF8575.git" }, - "version": "0.1.3", + "version": "0.1.4", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 7c8c55b..f98d13c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8575 -version=0.1.3 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PCF8575 - 16 channel I2C IO expander diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 1b7d1dd..b0b16fa 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -42,16 +42,26 @@ PCF8575 PCF(0x38); unittest_setup() { + fprintf(stderr, "PCF8575_LIB_VERSION: %s\n", (char *) PCF8575_LIB_VERSION); } + unittest_teardown() { } -unittest(test_begin) + +unittest(test_constants) { - fprintf(stderr, "VERSION: %s\n", PCF8575_LIB_VERSION); + assertEqual(PCF8575_INITIAL_VALUE, 0xFFFF); + assertEqual(PCF8575_OK , 0x00); + assertEqual(PCF8575_PIN_ERROR , 0x81); + assertEqual(PCF8575_I2C_ERROR , 0x82); +} + +unittest(test_begin) +{ PCF8575 PCF(0x38); PCF.begin();