From 63b231d9c2141b5876394e1d5db038cc5bc7cadb Mon Sep 17 00:00:00 2001 From: XII-MENG Date: Thu, 30 Apr 2026 00:07:39 +0800 Subject: [PATCH 1/4] Comment out waveshare-c5-tft entry Comment out the 'waveshare-c5-tft' entry in platformio.ini. --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index 0ae3c1bb9d..7278de621f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -66,6 +66,7 @@ default_envs = ;esp32-c5-tft ;esp32-c5 ;ES3C28P + ;waveshare-c5-tft ;uncomment to not use global dirs to avoid possible conflicts ;platforms_dir = .pio/platforms From 93261762786c96551108da03d3bab1dfb31f1087 Mon Sep 17 00:00:00 2001 From: XII-MENG Date: Thu, 30 Apr 2026 00:08:38 +0800 Subject: [PATCH 2/4] Add files via upload --- boards/waveshare-c5-tft/connections.md | 44 ++++++ boards/waveshare-c5-tft/interface.cpp | 126 ++++++++++++++++ boards/waveshare-c5-tft/pins_arduino.h | 151 +++++++++++++++++++ boards/waveshare-c5-tft/waveshare-c5-tft.ini | 37 +++++ 4 files changed, 358 insertions(+) create mode 100644 boards/waveshare-c5-tft/connections.md create mode 100644 boards/waveshare-c5-tft/interface.cpp create mode 100644 boards/waveshare-c5-tft/pins_arduino.h create mode 100644 boards/waveshare-c5-tft/waveshare-c5-tft.ini diff --git a/boards/waveshare-c5-tft/connections.md b/boards/waveshare-c5-tft/connections.md new file mode 100644 index 0000000000..065397b98b --- /dev/null +++ b/boards/waveshare-c5-tft/connections.md @@ -0,0 +1,44 @@ +# Pinouts diagram to use Bruce + +## USING CUSTOM BOARD, with SPI + +## Waveshare ESP32-C5 n16r8 +## TFT ST7789 172x320 RGB + +| Device | SCK | MISO | MOSI | CS | GDO0/CE | GDO2 | TFT_DC | TFT_RES | TFT_BL | +| --- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| Display | 10 | 9 | - | 23 | --- | --- | 24 | C5 RST | 25 | +| SD Card | 10 | 9 | 8 | 6 | --- | --- | --- | --- | --- | +| CC1101 | 10 | 9 | 8 | 3* | 2* | 7* | --- | --- | --- | +| NRF24 | 10 | 9 | 8 | 3* | 2* | --- | --- | --- | --- | +| W5500 | 10 | 9 | 8 | 3* | 2* | --- | --- | --- | --- | + +(*) CC1101, NRF24, W5500 use the same pinouts, need to add a switch on CS and CE/GDO0 to choose which to use. + +Pinouts for buttons +| Buttons | GPIO | +| --- | :---: | +| Prev/UP | 1 | +| Sel | 28 | +| Next/DW | 0 | +| Right | 13 | +| Left | 14 | + + + +| Device | RX | TX | GPIO | +| --- | :---: | :---: | :---: | +| GPS | 4 | 5 | --- | +| IR RX | --- | --- | 26 | +| IR TX | --- | --- | 15 | +| LED | --- | --- | 27 | + +ESP32-C5 doesn't support USB-OTG, for BadUSB you need to use a CH9329 module + +FM Radio, PN532 on I2C, other I2C devices, CH9329, shared with GPS Serial interface. +I2C SDA: 4 +I2C SCL: 5 + +Serial interface to other devices (Flipper) +Serial Tx: 11 +Serial Rx: 12 diff --git a/boards/waveshare-c5-tft/interface.cpp b/boards/waveshare-c5-tft/interface.cpp new file mode 100644 index 0000000000..9f7e96c8a6 --- /dev/null +++ b/boards/waveshare-c5-tft/interface.cpp @@ -0,0 +1,126 @@ +#include "core/powerSave.h" +#include "core/utils.h" +#include + +/*************************************************************************************** +** Function name: _setup_gpio() +** Location: main.cpp +** Description: initial setup for the device +***************************************************************************************/ +void _setup_gpio() { + + pinMode(TFT_CS, OUTPUT); + digitalWrite(TFT_CS, HIGH); + pinMode(TFT_MOSI, OUTPUT); + digitalWrite(TFT_MOSI, HIGH); + pinMode(TFT_SCLK, OUTPUT); + + pinMode(TFT_BL, OUTPUT); + digitalWrite(TFT_BL, HIGH); + pinMode(TFT_RST, OUTPUT); + pinMode(TFT_DC, OUTPUT); + digitalWrite(TFT_DC, HIGH); + +#ifdef HAS_5_BUTTONS + pinMode(UP_BTN, INPUT_PULLUP); // Sets the power btn as an INPUT + pinMode(SEL_BTN, INPUT_PULLUP); + pinMode(DW_BTN, INPUT_PULLUP); + pinMode(R_BTN, INPUT_PULLUP); + pinMode(L_BTN, INPUT_PULLUP); +#endif + + pinMode(NRF24_SS_PIN, OUTPUT); + pinMode(CC1101_SS_PIN, OUTPUT); + pinMode(SDCARD_CS, OUTPUT); + pinMode(W5500_SS_PIN, OUTPUT); + pinMode(TFT_CS, OUTPUT); + + digitalWrite(NRF24_SS_PIN, HIGH); + digitalWrite(CC1101_SS_PIN, HIGH); + digitalWrite(SDCARD_CS, HIGH); + digitalWrite(W5500_SS_PIN, HIGH); + digitalWrite(TFT_CS, HIGH); +} +/*************************************************************************************** +** Function name: _post_setup_gpio() +** Location: main.cpp +** Description: second stage gpio setup to make a few functions work +***************************************************************************************/ +void _post_setup_gpio() {} + +/*************************************************************************************** +** Function name: getBattery() +** location: display.cpp +** Description: Delivers the battery value from 1-100 +***************************************************************************************/ +int getBattery() { return 0; } + +/*************************************************************************************** +** Function name: isCharging() +** Description: Default implementation that returns false +***************************************************************************************/ +bool isCharging() { return false; } + +/********************************************************************* +** Function: setBrightness +** location: settings.cpp +** set brightness value +**********************************************************************/ +void _setBrightness(uint8_t brightval) { + if (brightval == 0) { + analogWrite(TFT_BL, brightval); + } else { + int bl = MINBRIGHT + round(((255 - MINBRIGHT) * brightval / 100)); + analogWrite(TFT_BL, bl); + } +} + +/********************************************************************* +** Function: InputHandler +** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress +**********************************************************************/ +void InputHandler(void) { +static unsigned long tm = 0; + if (millis() - tm < 200 && !LongPress) return; + bool _u = digitalRead(UP_BTN); + bool _d = digitalRead(DW_BTN); + bool _l = digitalRead(L_BTN); + bool _r = digitalRead(R_BTN); + bool _s = digitalRead(SEL_BTN); + + if (!_s || !_u || !_d || !_r || !_l) { + tm = millis(); + if (!wakeUpScreen()) AnyKeyPress = true; + else return; + } + if (!_l) { PrevPress = true; } + if (!_r) { NextPress = true; } + if (!_u) { + UpPress = true; + PrevPagePress = true; + } + if (!_d) { + DownPress = true; + NextPagePress = true; + } + if (!_s) { SelPress = true; } + if (!_l && !_r) { + EscPress = true; + NextPress = false; + PrevPress = false; + } +} + +/********************************************************************* +** Function: powerOff +** location: mykeyboard.cpp +** Turns off the device (or try to) +**********************************************************************/ +void powerOff() {} + +/********************************************************************* +** Function: checkReboot +** location: mykeyboard.cpp +** Btn logic to turnoff the device (name is odd btw) +**********************************************************************/ +void checkReboot() {} diff --git a/boards/waveshare-c5-tft/pins_arduino.h b/boards/waveshare-c5-tft/pins_arduino.h new file mode 100644 index 0000000000..d6c5da1fe2 --- /dev/null +++ b/boards/waveshare-c5-tft/pins_arduino.h @@ -0,0 +1,151 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include "soc/soc_caps.h" +#include + +#define PIN_RGB_LED 27 +// BUILTIN_LED can be used in new Arduino API digitalWrite() like in Blink.ino +static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT + PIN_RGB_LED; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN +// RGB_BUILTIN and RGB_BRIGHTNESS can be used in new Arduino API rgbLedWrite() +#define RGB_BUILTIN LED_BUILTIN +#define RGB_BRIGHTNESS 10 + +static const uint8_t TX = 11; +static const uint8_t RX = 12; + +static const uint8_t USB_DM = 13; +static const uint8_t USB_DP = 14; + +static const uint8_t SDA = 4; +static const uint8_t SCL = 5; + +static const uint8_t SS = 6; +static const uint8_t MOSI = 8; +static const uint8_t MISO = 9; +static const uint8_t SCK = 10; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; + +// LP I2C Pins are fixed on ESP32-C5 +static const uint8_t LP_SDA = 4; +static const uint8_t LP_SCL = 5; +#define WIRE1_PIN_DEFINED +#define SDA1 LP_SDA +#define SCL1 LP_SCL + +// LP UART Pins are fixed on ESP32-C5 +static const uint8_t LP_RX = 12; +static const uint8_t LP_TX = 11; + +#define HAS_RGB_LED 1 +#define LED_ORDER GRB +#define LED_TYPE_IS_RGBW 1 +#define LED_COUNT 1 +#define LED_TYPE WS2812 +#define LED_COLOR_STEP 15 +#define RGB_LED 27 + +/* Communication Buses*/ +// UART +#define SERIAL_TX 11 +#define SERIAL_RX 12 + +// I2C +#define GROVE_SDA 4 +#define GROVE_SCL 5 + +// SPI +#define SPI_SCK_PIN 10 +#define SPI_MOSI_PIN 8 +#define SPI_MISO_PIN 9 +#define SPI_SS_PIN 3 + +/* TFT definitions */ +#define HAS_SCREEN 1 +#define ROTATION 1 +#define MINBRIGHT (uint8_t)4 +#define USER_SETUP_LOADED 1 +/* --------------------- */ +// Setup for ST7789 170x320 + +#define ST7789_DRIVER 1 +#define TFT_RGB_ORDER 0 +#define TFT_WIDTH 172 +#define TFT_HEIGHT 320 + +/* --------------------- */ +// Common TFT definitions +#define TFT_BACKLIGHT_ON 1 +#define TFT_BL 25 +#define TFT_RST -1 +#define TFT_DC 24 +#define TFT_MISO SPI_MISO_PIN // set to share SPI with other devices +#define TFT_MOSI SPI_MOSI_PIN +#define TFT_SCLK SPI_SCK_PIN +#define TFT_CS 23 +#define SMOOTH_FONT 1 +#define SPI_FREQUENCY 20000000 +#define SPI_READ_FREQUENCY 20000000 +#define SPI_TOUCH_FREQUENCY 2500000 + +/* Peripheral settings */ +// Bad USB with CH9329 +#define BAD_RX 4 +#define BAD_TX 5 + +// GPS Bus +#define GPS_SERIAL_TX 5 +#define GPS_SERIAL_RX 4 + +#define BTN_ALIAS "\"OK\"" +#define HAS_5_BUTTONS +#define SEL_BTN 28 +#define DW_BTN 1 +#define UP_BTN 0 +#define R_BTN 13 +#define L_BTN 14 +#define BTN_ACT LOW +#define DEEPSLEEP_WAKEUP_PIN SEL_BTN + +// InfraRed +#define RXLED 26 +#define TXLED 15 +#define LED_ON HIGH +#define LED_OFF LOW + +// SDCard +#define SDCARD_CS 6 +#define SDCARD_SCK SPI_SCK_PIN +#define SDCARD_MISO SPI_MISO_PIN +#define SDCARD_MOSI SPI_MOSI_PIN + +// CC1101 +#define CC1101_GDO2_PIN 7 +#define CC1101_GDO0_PIN 2 +#define CC1101_SS_PIN 3 +#define CC1101_MOSI_PIN SPI_MOSI_PIN +#define CC1101_SCK_PIN SPI_SCK_PIN +#define CC1101_MISO_PIN SPI_MISO_PIN + +// NRF24 +#define NRF24_CE_PIN 2 +#define NRF24_SS_PIN 3 +#define NRF24_MOSI_PIN SPI_MOSI_PIN +#define NRF24_SCK_PIN SPI_SCK_PIN +#define NRF24_MISO_PIN SPI_MISO_PIN + +// Ethernet +#define W5500_INT_PIN 2 +#define W5500_SS_PIN 3 +#define W5500_MOSI_PIN SPI_MOSI_PIN +#define W5500_SCK_PIN SPI_SCK_PIN +#define W5500_MISO_PIN SPI_MISO_PIN +#endif /* Pins_Arduino_h */ diff --git a/boards/waveshare-c5-tft/waveshare-c5-tft.ini b/boards/waveshare-c5-tft/waveshare-c5-tft.ini new file mode 100644 index 0000000000..2487243fa4 --- /dev/null +++ b/boards/waveshare-c5-tft/waveshare-c5-tft.ini @@ -0,0 +1,37 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:waveshare-c5-tft] +board = esp32-c5-devkitc1-n16r8 +board_build.partitions = custom_16Mb.csv +build_src_filter =${env.build_src_filter} +<../boards/waveshare-c5-tft> +build_flags = + ${env.build_flags} + -Iboards/waveshare-c5-tft + -DDEVICE_NAME='"ESP32-C5"' + -DESP32C5_DEVKITC_1_TFT=1 + -DBOARD_HAS_PSRAM=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DARDUINO_USB_MODE=1 + -DCORE_DEBUG_LEVEL=1 + + ; grove pins + ; defaults from https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h + -DALLOW_ALL_GPIO_FOR_IR_RF=1 ; Set this option to make use of all GPIOs, from 1 to 44 to be chosen, except TFT and SD pins + + ; text sizes + -DFP=1 + -DFM=2 + -DFG=3 + ; ui control buttons + -DBTN_ALIAS='"OK"' + + ;FM Radio + ;-DFM_SI4713=1 ;Uncomment to activate FM Radio using Adafruit Si4713 From 436c82989241ae6542eb4674b898a5b7f2d6e483 Mon Sep 17 00:00:00 2001 From: XII-MENG Date: Thu, 30 Apr 2026 00:09:46 +0800 Subject: [PATCH 3/4] Update pins_arduino.h --- boards/pinouts/pins_arduino.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/boards/pinouts/pins_arduino.h b/boards/pinouts/pins_arduino.h index 8cc716273c..2dbaa39ae2 100644 --- a/boards/pinouts/pins_arduino.h +++ b/boards/pinouts/pins_arduino.h @@ -46,4 +46,6 @@ #include "../ESP32-C5-tft/pins_arduino.h" #elif ESP32C5_DEVKITC_1 #include "../ESP32-C5/pins_arduino.h" +#elif WAVESHARE_C5_TFT +#include "../waveshare-c5-tft/pins_arduino.h" #endif From 5b20a08418121fd4f565ad4e56ceddc87e359b12 Mon Sep 17 00:00:00 2001 From: XII-MENG Date: Thu, 30 Apr 2026 00:10:26 +0800 Subject: [PATCH 4/4] Add files via upload --- .../_boards_json/esp32-c5-devkitc1-n16r8.json | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 boards/_boards_json/esp32-c5-devkitc1-n16r8.json diff --git a/boards/_boards_json/esp32-c5-devkitc1-n16r8.json b/boards/_boards_json/esp32-c5-devkitc1-n16r8.json new file mode 100644 index 0000000000..6e7cab5961 --- /dev/null +++ b/boards/_boards_json/esp32-c5-devkitc1-n16r8.json @@ -0,0 +1,39 @@ +{ + "build": { + "arduino": { + "partitions": "default_16MB.csv", + "memory_type": "qio_qspi" + }, + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "psram_type": "qio", + "mcu": "esp32c5", + "variant": "esp32c5" + }, + "connectivity": [ + "bluetooth", + "wifi" + ], + "debug": { + "openocd_target": "esp32c5.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "Espressif ESP32-C5-DevKitC-1-N16R8V (16 MB Flash Quad, 8 MB PSRAM Octal)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32c5/esp32-c5-devkitc-1/user_guide.html", + "vendor": "Espressif" +} \ No newline at end of file