Skip to content

Commit 9fd5cdf

Browse files
Move PicoW auto-reassignment of LED pin to code (#1208)
Many examples require that LED_BUILTIN be defined as a constant, so we can't use a ternary operator to swap between Pico and PicoW LED pins. Instead, do the check in the digitalWrite/digitalRead/pinMode calls to cover most of the uses.
1 parent 1b33cbe commit 9fd5cdf

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

variants/rpipicow/picow_digital.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ extern "C" void __pinMode(pin_size_t pin, PinMode mode);
2424
extern "C" void __digitalWrite(pin_size_t pin, PinStatus val);
2525
extern "C" PinStatus __digitalRead(pin_size_t pin);
2626

27+
extern bool __isPicoW;
28+
2729
extern "C" void pinMode(pin_size_t pin, PinMode mode) {
30+
if (!__isPicoW && (pin == PIN_LED)) {
31+
pin = 25; // Silently swap in the Pico's LED
32+
}
2833
if (pin < 32) {
2934
__pinMode(pin, mode);
3035
} else {
@@ -33,6 +38,9 @@ extern "C" void pinMode(pin_size_t pin, PinMode mode) {
3338
}
3439

3540
extern "C" void digitalWrite(pin_size_t pin, PinStatus val) {
41+
if (!__isPicoW && (pin == PIN_LED)) {
42+
pin = 25; // Silently swap in the Pico's LED
43+
}
3644
if (pin < 32) {
3745
__digitalWrite(pin, val);
3846
} else {
@@ -41,6 +49,9 @@ extern "C" void digitalWrite(pin_size_t pin, PinStatus val) {
4149
}
4250

4351
extern "C" PinStatus digitalRead(pin_size_t pin) {
52+
if (!__isPicoW && (pin == PIN_LED)) {
53+
pin = 25; // Silently swap in the Pico's LED
54+
}
4455
if (pin < 32) {
4556
return __digitalRead(pin);
4657
} else {

variants/rpipicow/pins_arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extern bool __isPicoW;
77

88
// LEDs
9-
#define PIN_LED (__isPicoW ? 32u : 25u)
9+
#define PIN_LED (32u)
1010

1111
// Serial
1212
#define PIN_SERIAL1_TX (0u)

0 commit comments

Comments
 (0)