Skip to content

Instantly share code, notes, and snippets.

@chrismatthieu
Created November 7, 2024 16:18
Show Gist options
  • Save chrismatthieu/f885c2dd70b924909e8cc15a304fff94 to your computer and use it in GitHub Desktop.
Save chrismatthieu/f885c2dd70b924909e8cc15a304fff94 to your computer and use it in GitHub Desktop.
Radxa X4 Firmata
// Raspberry Pi Pico
// https://datasheets.raspberrypi.org/pico/Pico-R3-A4-Pinout.pdf
#elif defined(TARGET_RP2040) || defined(TARGET_RASPBERRY_PI_PICO)
#define TOTAL_ANALOG_PINS 4
#define TOTAL_PINS 30
#define VERSION_BLINK_PIN LED_BUILTIN
#define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) < 23) || (p) == LED_BUILTIN)
#define IS_PIN_ANALOG(p) ((p) >= 26 && (p) < 26 + TOTAL_ANALOG_PINS)
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) != LED_BUILTIN)
// From the data sheet I2C-0 defaults to GP 4 (SDA) & 5 (SCL) (physical pins 6 & 7)
// However, v2.3.1 of mbed_rp2040 defines WIRE_HOWMANY to 1 and uses the non-default GPs 6 & 7:
//#define WIRE_HOWMANY (1)
//#define PIN_WIRE_SDA (6u)
//#define PIN_WIRE_SCL (7u)
#define IS_PIN_I2C(p) ((p) == PIN_WIRE_SDA || (p) == PIN_WIRE_SCL)
// SPI-0 defaults to GP 16 (RX / MISO), 17 (CSn), 18 (SCK) & 19 (TX / MOSI) (physical pins 21, 22, 24, 25)
#define IS_PIN_SPI(p) ((p) == PIN_SPI_SCK || (p) == PIN_SPI_MOSI || (p) == PIN_SPI_MISO || (p) == PIN_SPI_SS)
// UART-0 defaults to GP 0 (TX) & 1 (RX)
#define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1 || (p) == 4 || (p) == 5 || (p) == 8 || (p) == 9 || (p) == 12 || (p) == 13 || (p) == 16 || (p) == 17)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 26)
#define PIN_TO_PWM(p) (p)
#define PIN_TO_SERVO(p) (p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment