From 4f3b7068ca45fc751b9f4eea34637d8e646520cc Mon Sep 17 00:00:00 2001 From: Ash-4 <81280775+Ash-4@users.noreply.github.com> Date: Tue, 13 May 2025 12:24:16 -0500 Subject: [PATCH] PCF8574 output pin initialization parameter --- IO_PCF8574.h | 13 ++++++++++--- myHal.cpp_example.txt | 7 +++++++ version.h | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/IO_PCF8574.h b/IO_PCF8574.h index 17241ee..c7b740c 100644 --- a/IO_PCF8574.h +++ b/IO_PCF8574.h @@ -1,4 +1,5 @@ /* + * © 2025 Herb Morton * © 2022 Paul M Antoine * © 2021, Neil McKechnie. All rights reserved. * @@ -43,15 +44,21 @@ class PCF8574 : public GPIOBase { public: - static void create(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) { - if (checkNoOverlap(firstVpin, nPins, i2cAddress)) new PCF8574(firstVpin, nPins, i2cAddress, interruptPin); + static void create(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1, int initPortState=-1) { + if (checkNoOverlap(firstVpin, nPins, i2cAddress)) new PCF8574(firstVpin, nPins, i2cAddress, interruptPin, initPortState); } private: - PCF8574(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) + PCF8574(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1, int initPortState=-1) : GPIOBase((FSH *)F("PCF8574"), firstVpin, nPins, i2cAddress, interruptPin) { requestBlock.setReadParams(_I2CAddress, inputBuffer, 1); + if (initPortState>=0) { + _portMode = 255; // set all pins to output mode + _portInUse = 255; // 8 ports in use + _portOutputState = initPortState; // initialize pins low-high 0-255 + I2CManager.write(_I2CAddress, 1, initPortState); + } } // The PCF8574 handles inputs by applying a weak pull-up when output is driven to '1'. diff --git a/myHal.cpp_example.txt b/myHal.cpp_example.txt index f715c63..144fe1a 100644 --- a/myHal.cpp_example.txt +++ b/myHal.cpp_example.txt @@ -146,7 +146,14 @@ void halSetup() { //PCF8574::create(200, 8, 0x23, 40); + // Alternative form to initialize 8 pins as output + // INT pin -1, when INT is not used + //PCF8574::create(200, 8, 0x23, -1, 255); 8 pins High + //PCF8574::create(200, 8, 0x23, -1, 0); 8 pins Low + //PCF8574::create(200, 8, 0x23, -1, 0b11000010); + // pins listed sequentially from 7 to 0 + //======================================================================= // The following directive defines a PCF8575 16-port I2C GPIO Extender module. //======================================================================= diff --git a/version.h b/version.h index 829e536..ebb4db5 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.5.26" +#define VERSION "5.5.27" +// 5.5.27 - PCF8574 output pin initialization parameter // 5.5.26 - PCA9554 and TCA9554/9534 I2C 8-bit GPIO expander drivers // 5.2.25 - IO_Bitmap and assicated Exrail macros // 5.5.24 - SensorCAM in I2C scan and automatically setClock