From 70c7838e022396f85feb1fef32459136c6967373 Mon Sep 17 00:00:00 2001 From: Renzo Mischianti Date: Thu, 16 Feb 2023 09:11:32 +0100 Subject: [PATCH] Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards --- PCF8574.cpp | 10 +++++++--- PCF8574.h | 6 +++--- PCF8574_library.h | 2 +- README.md | 35 +++++++++++++---------------------- library.json | 2 +- library.properties | 2 +- 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/PCF8574.cpp b/PCF8574.cpp index 15f0484..80aed9f 100644 --- a/PCF8574.cpp +++ b/PCF8574.cpp @@ -53,7 +53,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio _usingInterrupt = true; }; -#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO) +#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) /** * Constructor * @param address: i2c address @@ -90,7 +90,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio }; #endif -#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD)|| defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) /** * Constructor * @param address: i2c address @@ -186,11 +186,15 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio */ bool PCF8574::begin(){ this->transmissionStatus = 4; - #if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO) + #if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) DEBUG_PRINT(F("begin(sda, scl) -> "));DEBUG_PRINT(_sda);DEBUG_PRINT(F(" "));DEBUG_PRINTLN(_scl); // _wire->begin(_sda, _scl); #ifdef ARDUINO_ARCH_STM32 _wire->begin((uint32_t)_sda, (uint32_t)_scl); +#elif defined(ARDUINO_ARCH_RP2040) + _wire->setSCL(_scl); + _wire->setSDA(_sda); + _wire->begin(); #else _wire->begin((int)_sda, (int)_scl); #endif diff --git a/PCF8574.h b/PCF8574.h index 2667ff0..6c857d2 100644 --- a/PCF8574.h +++ b/PCF8574.h @@ -2,7 +2,7 @@ * PCF8574 GPIO Port Expand * * AUTHOR: Renzo Mischianti - * VERSION: 2.3.4 + * VERSION: 2.3.5 * * https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/ * @@ -109,12 +109,12 @@ public: PCF8574(uint8_t address); PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunction)() ); -#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO) +#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(TEENSYDUINO) PCF8574(uint8_t address, int sda, int scl); PCF8574(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)()); #endif -#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) +#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32) ///// changes for second i2c bus PCF8574(TwoWire *pWire, uint8_t address); PCF8574(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() ); diff --git a/PCF8574_library.h b/PCF8574_library.h index d0babcd..14c7d5c 100644 --- a/PCF8574_library.h +++ b/PCF8574_library.h @@ -2,7 +2,7 @@ * PCF8574 GPIO Port Expand * * AUTHOR: Renzo Mischianti - * VERSION: 2.3.4 + * VERSION: 2.3.5 * * https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/ * diff --git a/README.md b/README.md index d57f366..da6fb56 100644 --- a/README.md +++ b/README.md @@ -9,37 +9,28 @@ align="right"> -# -# -# -# -# # -### Additional information and documentation on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/). -### If you need more pins [here](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/) you can find the pcf8575 16bit version of the IC. +# PCF8574 PCF8574AP digital input and output expander with i2c bus. +#### Complete documentation on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/). -### Version 2.2 - -Library to use I2C analog IC with arduino and esp8266. Can read and write digital value with only 2 wires (perfect for ESP-01). - -Tutorial: - -To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8574. Check that the PCF8574 folder contains `PCF8574\\.cpp` and `PCF8574.h`. Place the DHT library folder your `/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. +#### If you need more pins [here](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/) you can find the pcf8575 16bit version of the IC. ## Changelog -10/08/2022: v2.3.4 Add support for custom SERCOM interface of Arduino SAMD devices. Force SDA SCL to use GPIO numeration for STM32 bug (https://www.mischianti.org/forums/topic/compatible-with-stm32duino/). -28/07/2022: v2.3.3 Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/). -28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device. -26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56. -06/04/2022: v2.3.0 Fix package size -30/12/2021: v2.2.4 Minor fix and remove deprecated declaration -23/11/2020: v2.2.2 Add multiple implementation for encoder management (you can enable by uncomment relative define) + - 08/02/2023: v2.3.5 Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards + - 10/08/2022: v2.3.4 Add support for custom SERCOM interface of Arduino SAMD devices. Force SDA SCL to use GPIO numeration for STM32 bug (https://www.mischianti.org/forums/topic/compatible-with-stm32duino/). + - 28/07/2022: v2.3.3 Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/). + - 28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device. + - 26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56. + - 06/04/2022: v2.3.0 Fix package size + - 30/12/2021: v2.2.4 Minor fix and remove deprecated declaration + - 23/11/2020: v2.2.2 Add multiple implementation for encoder management (you can enable by uncomment relative define) -# Reef complete PCF8574 PCF8574AP digital input and output expander with i2c bus. I try to simplify the use of this IC, with a minimal set of operations. +Tested with esp8266, esp32, Arduino, Arduino SAMD (Nano 33 IoT, MKR etc.), STM32 and rp2040 (Raspberry Pi Pico and similar) + PCF8574P address map 0x20-0x27 PCF8574AP address map 0x38-0x3f diff --git a/library.json b/library.json index 80a8ac8..eb20ef0 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "PCF8574 library", - "version": "2.3.4", + "version": "2.3.5", "keywords": "digital, i2c, encoder, expander, pcf8574, pcf8574a, esp32, esp8266, stm32, SAMD, Arduino, wire", "description": "Most starred PCF8574 library. i2c digital expander for Arduino, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.", "homepage": "https://www.mischianti.org/category/my-libraries/pcf8574/", diff --git a/library.properties b/library.properties index 47b4f05..f3fb157 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PCF8574 library -version=2.3.4 +version=2.3.5 author=Renzo Mischianti maintainer=Renzo Mischianti sentence=Most starred PCF8574 library for Arduino (standard and SAMD), ESP8266, smt32 and esp32