Skip to content

Commit

Permalink
Support LED digitalWrite on RP2350+CYW
Browse files Browse the repository at this point in the history
Also move "special GPIO" to 64 since the Pimoroni Pico 2W uses the
RP2350B with 48 GPIOs.
  • Loading branch information
earlephilhower committed Nov 17, 2024
1 parent 1780acd commit c1a0993
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 38 deletions.
37 changes: 37 additions & 0 deletions cores/rp2040/cyw43_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,41 @@ extern "C" void __unlockBluetooth() {
async_context_release_lock(cyw43_arch_async_context());
}

extern "C" void __pinMode(pin_size_t pin, PinMode mode);
extern "C" void __digitalWrite(pin_size_t pin, PinStatus val);
extern "C" PinStatus __digitalRead(pin_size_t pin);

extern "C" void cyw43_pinMode(pin_size_t pin, PinMode mode) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 64) {
__pinMode(pin, mode);
} else {
// TBD - There is no GPIO direction control in the driver
}
}

extern "C" void cyw43_digitalWrite(pin_size_t pin, PinStatus val) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 64) {
__digitalWrite(pin, val);
} else {
cyw43_arch_gpio_put(pin - 64, val == HIGH ? 1 : 0);
}
}

extern "C" PinStatus cyw43_digitalRead(pin_size_t pin) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 64) {
return __digitalRead(pin);
} else {
return cyw43_arch_gpio_get(pin - 64) ? HIGH : LOW;
}
}

#endif
13 changes: 10 additions & 3 deletions cores/rp2040/cyw43_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@

#pragma once

#include <Arduino.h>

extern bool __isPicoW;
extern "C" void init_cyw43_wifi();
extern "C" void __lockBluetooth();
extern "C" void __unlockBluetooth();
extern "C" {
void init_cyw43_wifi();
void __lockBluetooth();
void __unlockBluetooth();
void cyw43_pinMode(pin_size_t pin, PinMode mode);
void cyw43_digitalWrite(pin_size_t pin, PinStatus val);
PinStatus cyw43_digitalRead(pin_size_t pin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,16 @@
*/

#include "Arduino.h"
#include <pico/cyw43_arch.h>

extern "C" void __pinMode(pin_size_t pin, PinMode mode);
extern "C" void __digitalWrite(pin_size_t pin, PinStatus val);
extern "C" PinStatus __digitalRead(pin_size_t pin);

extern bool __isPicoW;
#include <cyw43_wrappers.h>

extern "C" void pinMode(pin_size_t pin, PinMode mode) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 32) {
__pinMode(pin, mode);
} else {
// TBD - There is no GPIO direction control in the driver
}
cyw43_pinMode(pin, mode);
}

extern "C" void digitalWrite(pin_size_t pin, PinStatus val) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 32) {
__digitalWrite(pin, val);
} else {
cyw43_arch_gpio_put(pin - 32, val == HIGH ? 1 : 0);
}
cyw43_digitalWrite(pin, val);
}

extern "C" PinStatus digitalRead(pin_size_t pin) {
if (!__isPicoW && (pin == PIN_LED)) {
pin = 25; // Silently swap in the Pico's LED
}
if (pin < 32) {
return __digitalRead(pin);
} else {
return cyw43_arch_gpio_get(pin - 32) ? HIGH : LOW;
}
return cyw43_digitalRead(pin);
}
2 changes: 1 addition & 1 deletion variants/pimoroni_pico_plus_2w/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

extern "C" void init_cyw43_wifi();
#include <cyw43_wrappers.h>

extern "C" void initVariant() {
init_cyw43_wifi();
Expand Down
33 changes: 33 additions & 0 deletions variants/rpipicow/digital.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
pinMode and digitalRead/Write for the Raspberry Pi Pico W RP2040
Copyright (c) 2022 Earle F. Philhower, III <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "Arduino.h"
#include <cyw43_wrappers.h>

extern "C" void pinMode(pin_size_t pin, PinMode mode) {
cyw43_pinMode(pin, mode);
}

extern "C" void digitalWrite(pin_size_t pin, PinStatus val) {
cyw43_digitalWrite(pin, val);
}

extern "C" PinStatus digitalRead(pin_size_t pin) {
return cyw43_digitalRead(pin);
}
2 changes: 1 addition & 1 deletion variants/rpipicow/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

extern "C" void init_cyw43_wifi();
#include <cyw43_wrappers.h>

extern "C" void initVariant() {
init_cyw43_wifi();
Expand Down
2 changes: 1 addition & 1 deletion variants/rpipicow/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <cyw43_wrappers.h>

// LEDs
#define PIN_LED (32u)
#define PIN_LED (64u)

// Serial
#define PIN_SERIAL1_TX (0u)
Expand Down
33 changes: 33 additions & 0 deletions variants/sparkfun_thingplusrp2350/digital.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
pinMode and digitalRead/Write for the Raspberry Pi Pico W RP2040
Copyright (c) 2022 Earle F. Philhower, III <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "Arduino.h"
#include <cyw43_wrappers.h>

extern "C" void pinMode(pin_size_t pin, PinMode mode) {
cyw43_pinMode(pin, mode);
}

extern "C" void digitalWrite(pin_size_t pin, PinStatus val) {
cyw43_digitalWrite(pin, val);
}

extern "C" PinStatus digitalRead(pin_size_t pin) {
return cyw43_digitalRead(pin);
}
2 changes: 1 addition & 1 deletion variants/sparkfun_thingplusrp2350/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

extern "C" void init_cyw43_wifi();
#include <cyw43_wrappers.h>

extern "C" void initVariant() {
init_cyw43_wifi();
Expand Down

0 comments on commit c1a0993

Please sign in to comment.