Skip to content

Commit de00a4e

Browse files
committed
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/).
1 parent 77d0496 commit de00a4e

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

PCF8574.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
5353
_usingInterrupt = true;
5454
};
5555

56-
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
56+
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO)
5757
/**
5858
* Constructor
5959
* @param address: i2c address
@@ -90,7 +90,7 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
9090
};
9191
#endif
9292

93-
#ifdef ESP32
93+
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD)
9494
/**
9595
* Constructor
9696
* @param address: i2c address
@@ -115,7 +115,8 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
115115
_interruptFunction = interruptFunction;
116116
_usingInterrupt = true;
117117
};
118-
118+
#endif
119+
#if defined(ESP32)
119120
/**
120121
* Constructor
121122
* @param address: i2c address
@@ -185,10 +186,14 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
185186
*/
186187
bool PCF8574::begin(){
187188
this->transmissionStatus = 4;
188-
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
189+
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO)
189190
DEBUG_PRINT(F("begin(sda, scl) -> "));DEBUG_PRINT(_sda);DEBUG_PRINT(F(" "));DEBUG_PRINTLN(_scl);
190191
// _wire->begin(_sda, _scl);
192+
#ifdef ARDUINO_ARCH_STM32
193+
_wire->begin((uint32_t)_sda, (uint32_t)_scl);
194+
#else
191195
_wire->begin((int)_sda, (int)_scl);
196+
#endif
192197
#else
193198
// Default pin for AVR some problem on software emulation
194199
// #define SCL_PIN _scl

PCF8574.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* PCF8574 GPIO Port Expand
33
*
44
* AUTHOR: Renzo Mischianti
5-
* VERSION: 2.3.3
5+
* VERSION: 2.3.4
66
*
77
* https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
88
*
@@ -109,17 +109,18 @@ class PCF8574 {
109109
PCF8574(uint8_t address);
110110
PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
111111

112-
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
112+
#if !defined(__AVR) && !defined(ARDUINO_ARCH_SAMD) && !defined(ARDUINO_ARCH_STM32) && !defined(TEENSYDUINO)
113113
PCF8574(uint8_t address, int sda, int scl);
114114
PCF8574(uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
115115
#endif
116116

117-
#ifdef ESP32
117+
#if defined(ESP32) || defined(ARDUINO_ARCH_SAMD)
118118
///// changes for second i2c bus
119119
PCF8574(TwoWire *pWire, uint8_t address);
120-
PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl);
121-
122120
PCF8574(TwoWire *pWire, uint8_t address, uint8_t interruptPin, void (*interruptFunction)() );
121+
#endif
122+
#if defined(ESP32)
123+
PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl);
123124
PCF8574(TwoWire *pWire, uint8_t address, int sda, int scl, uint8_t interruptPin, void (*interruptFunction)());
124125
#endif
125126

@@ -201,7 +202,7 @@ class PCF8574 {
201202
uint8_t _address;
202203

203204
#if !defined(DEFAULT_SDA)
204-
# if defined(__STM32F1__)
205+
# if defined(ARDUINO_ARCH_STM32)
205206
# define DEFAULT_SDA PB7
206207
# elif defined(ESP8266)
207208
# define DEFAULT_SDA 4
@@ -212,7 +213,7 @@ class PCF8574 {
212213
# endif
213214
#endif
214215
#if !defined(DEFAULT_SCL)
215-
# if defined(__STM32F1__)
216+
# if defined(ARDUINO_ARCH_STM32)
216217
# define DEFAULT_SCL PB6
217218
# elif defined(ESP8266)
218219
# define DEFAULT_SCL 5

PCF8574_library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* PCF8574 GPIO Port Expand
33
*
44
* AUTHOR: Renzo Mischianti
5-
* VERSION: 2.3.3
5+
* VERSION: 2.3.4
66
*
77
* https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
88
*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Tutorial:
2929
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 `<arduinosketchfolder>/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
3030

3131
## Changelog
32+
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/).
3233
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/).
3334
28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device.
3435
26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56.

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "PCF8574 library",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"keywords": "digital, i2c, encoder, expander, pcf8574, pcf8574a, esp32, esp8266, stm32, SAMD, Arduino, wire",
5-
"description": "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.",
5+
"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.",
66
"homepage": "https://www.mischianti.org/category/my-libraries/pcf8574/",
77
"authors":
88
[

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=PCF8574 library
2-
version=2.3.3
2+
version=2.3.4
33
author=Renzo Mischianti <renzo.mischianti@gmail.com>
44
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
5-
sentence=PCF8574, library for Arduino, ESP8266, smt32 and esp32
6-
paragraph=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.
5+
sentence=Most starred PCF8574 library for Arduino (standard and SAMD), ESP8266, smt32 and esp32
6+
paragraph=Most starred PCF8574 library. i2c digital expander for Arduino (standard and SAMD), esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.
77
category=Sensors
88
url=https://www.mischianti.org/category/my-libraries/pcf8574/
99
repository=https://github.com/xreef/PCF8574_library

0 commit comments

Comments
 (0)