Skip to content

Commit 5492b60

Browse files
authored
fix: reduce current usage on STM32-based hosts when using TXNs (#146)
When using transactions (for example, when talking to a NOTE-ESP) this library must initialize and uninitialize GPIOs for RTX and CTX. For system current usage reasons - particularly, if the sketch is using the Low Power library - it is important that we don't put IO pins with no pullups or pulldowns into an ambiguous GPIO state that will cause excessive current draw. This PR leverages the STM32's ability to actually put a pin into a floating state with no leakage.
1 parent 9d78fc7 commit 5492b60

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/NoteTxn_Arduino.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ NoteTxn_Arduino::NoteTxn_Arduino
5656
_rtx_pin(rtx_pin_)
5757
{
5858
// Float CTX/RTX to conserve energy
59+
#ifdef ARDUINO_ARCH_STM32
60+
::pinMode(_ctx_pin, INPUT_ANALOG);
61+
::pinMode(_rtx_pin, INPUT_ANALOG);
62+
#else
5963
::pinMode(_ctx_pin, INPUT);
6064
::pinMode(_rtx_pin, INPUT);
65+
#endif
6166
}
6267

6368
bool
@@ -84,7 +89,11 @@ NoteTxn_Arduino::start (
8489
}
8590

8691
// Float CTX to conserve energy
92+
#ifdef ARDUINO_ARCH_STM32
93+
::pinMode(_ctx_pin, INPUT_ANALOG);
94+
#else
8795
::pinMode(_ctx_pin, INPUT);
96+
#endif
8897

8998
// Abandon request on timeout
9099
if (!result) {
@@ -100,7 +109,11 @@ NoteTxn_Arduino::stop (
100109
)
101110
{
102111
// Float RTX pin
112+
#ifdef ARDUINO_ARCH_STM32
113+
::pinMode(_rtx_pin, INPUT_ANALOG);
114+
#else
103115
::pinMode(_rtx_pin, INPUT);
116+
#endif
104117
}
105118

106119
// Explicitly instantiate the template function for array types

0 commit comments

Comments
 (0)