Skip to content

Commit c9b4daf

Browse files
authored
Merge pull request #302 from RockBase-iot/main
Add NM-CYD-C5 board support, the first ESP32-C5 board for Launcher
2 parents b92e1e4 + 45f790c commit c9b4daf

11 files changed

Lines changed: 313 additions & 5 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
- { env: "CYD-3248S035C" }
5454
- { env: "CYD-8048S043C" }
5555
- { env: "CYD-8048W550C" }
56+
- { env: "NM-CYD-C5" }
5657
- { env: "CYD-3248W535C" }
5758
- { env: "CYD-4827S043R" }
5859
- { env: "lilygo-t-dongle-s3-tft" }

boards/NM-CYD-C5/interface.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include "powerSave.h"
2+
#include <Wire.h>
3+
#include <interface.h>
4+
5+
#ifndef TFT_BRIGHT_CHANNEL
6+
#define TFT_BRIGHT_CHANNEL 0
7+
#define TFT_BRIGHT_FREQ 5000
8+
#define TFT_BRIGHT_Bits 8
9+
#define TFT_BL 25
10+
#endif
11+
12+
// NM-CYD-C5 uses XPT2046 resistive touch on the shared SPI bus
13+
#include "CYD28_TouchscreenR.h"
14+
#ifndef CYD28_DISPLAY_HOR_RES_MAX
15+
#define CYD28_DISPLAY_HOR_RES_MAX 320
16+
#endif
17+
#ifndef CYD28_DISPLAY_VER_RES_MAX
18+
#define CYD28_DISPLAY_VER_RES_MAX 240
19+
#endif
20+
CYD28_TouchR touch(CYD28_DISPLAY_HOR_RES_MAX, CYD28_DISPLAY_VER_RES_MAX);
21+
22+
/***************************************************************************************
23+
** Function name: _setup_gpio()
24+
** Location: main.cpp
25+
** Description: initial setup for the device
26+
***************************************************************************************/
27+
void _setup_gpio() {
28+
pinMode(CYD28_TouchR_CS, OUTPUT); // Touch CS pin (XPT2046)
29+
}
30+
31+
/***************************************************************************************
32+
** Function name: _post_setup_gpio()
33+
** Location: main.cpp
34+
** Description: second stage gpio setup to make a few functions work
35+
***************************************************************************************/
36+
void _post_setup_gpio() {
37+
// Brightness control must be initialized after tft in this case @Pirata
38+
pinMode(TFT_BL, OUTPUT);
39+
ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits);
40+
ledcWrite(TFT_BL, bright);
41+
42+
// Display and touch share the same SPI bus; pass &SPI so the driver reuses it
43+
if (!touch.begin(&SPI)) {
44+
Serial.println("Touch IC not Started");
45+
log_i("Touch IC not Started");
46+
} else Serial.println("Touch IC Started");
47+
}
48+
49+
/*********************************************************************
50+
** Function: setBrightness
51+
** location: settings.cpp
52+
** set brightness value
53+
**********************************************************************/
54+
void _setBrightness(uint8_t brightval) {
55+
int dutyCycle;
56+
if (brightval == 100) dutyCycle = 250;
57+
else if (brightval == 75) dutyCycle = 130;
58+
else if (brightval == 50) dutyCycle = 70;
59+
else if (brightval == 25) dutyCycle = 20;
60+
else if (brightval == 0) dutyCycle = 0;
61+
else dutyCycle = ((brightval * 250) / 100);
62+
63+
log_i("dutyCycle for bright 0-255: %d", dutyCycle);
64+
if (!ledcWrite(TFT_BL, dutyCycle)) {
65+
Serial.println("Failed to set brightness");
66+
ledcDetach(TFT_BL);
67+
ledcAttach(TFT_BL, TFT_BRIGHT_FREQ, TFT_BRIGHT_Bits);
68+
ledcWrite(TFT_BL, dutyCycle);
69+
}
70+
}
71+
72+
/*********************************************************************
73+
** Function: InputHandler
74+
** Handles the variables PrevPress, NextPress, SelPress, AnyKeyPress and EscPress
75+
**********************************************************************/
76+
void InputHandler(void) {
77+
static long d_tmp = millis();
78+
if (millis() - d_tmp > 250 || LongPress) { // I know R3CK.. I Should NOT nest if statements..
79+
// but it is needed to not keep SPI bus used without need, it save resources
80+
TouchPoint t;
81+
#ifdef DONT_USE_INPUT_TASK
82+
checkPowerSaveTime();
83+
#endif
84+
if (touch.touched()) {
85+
auto t = touch.getPointScaled();
86+
d_tmp = millis();
87+
#ifdef DONT_USE_INPUT_TASK // need to reset the variables to avoid ghost click
88+
NextPress = false;
89+
PrevPress = false;
90+
UpPress = false;
91+
DownPress = false;
92+
SelPress = false;
93+
EscPress = false;
94+
AnyKeyPress = false;
95+
touchPoint.pressed = false;
96+
#endif
97+
if (rotation == 3) {
98+
t.y = (tftHeight + 20) - t.y;
99+
t.x = tftWidth - t.x;
100+
}
101+
if (rotation == 0) {
102+
int tmp = t.x;
103+
t.x = tftWidth - t.y;
104+
t.y = tmp;
105+
}
106+
if (rotation == 2) {
107+
int tmp = t.x;
108+
t.x = t.y;
109+
t.y = (tftHeight + 20) - tmp;
110+
}
111+
Serial.printf("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
112+
log_i("\nTouch Pressed on x=%d, y=%d, rot=%d\n", t.x, t.y, rotation);
113+
114+
if (!wakeUpScreen()) AnyKeyPress = true;
115+
else return;
116+
117+
// Touch point global variable
118+
touchPoint.x = t.x;
119+
touchPoint.y = t.y;
120+
touchPoint.pressed = true;
121+
touchHeatMap(touchPoint);
122+
}
123+
}
124+
}
125+
126+
/*********************************************************************
127+
** Function: powerOff
128+
** location: mykeyboard.cpp
129+
** Turns off the device (or try to)
130+
**********************************************************************/
131+
void powerOff() { esp_deep_sleep_start(); }
132+
133+
/*********************************************************************
134+
** Function: checkReboot
135+
** location: mykeyboard.cpp
136+
** Btn logic to tornoff the device (name is odd btw)
137+
**********************************************************************/
138+
void checkReboot() { /* No dedicated reboot button on NM-CYD-C5 */ }

boards/NM-CYD-C5/platformio.ini

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
##################################### NM-CYD-C5 (ESP32-C5) ####################################################
12+
[env:NM-CYD-C5]
13+
board = nm-cyd-c5
14+
board_build.partitions = support_files/custom_16Mb.csv
15+
extra_scripts =
16+
${env.extra_scripts}
17+
build_src_filter = ${env.build_src_filter} +<../boards/NM-CYD-C5>
18+
build_flags =
19+
${env.build_flags}
20+
-Iboards/NM-CYD-C5
21+
-DDEVICE_NAME='"NM-CYD-C5"'
22+
-DOTA_TAG='"NM-CYD-C5"'
23+
-DHAS_TOUCH=1
24+
-DPART_16MB=1
25+
-DNM_CYD_C5
26+
-DDIMMER_SETUP=60
27+
-DARDUINO_USB_CDC_ON_BOOT=1
28+
-DARDUINO_USB_MODE=1
29+
-DROTATION=3
30+
; text sizes
31+
-DFP=1
32+
-DFM=2
33+
-DFG=3
34+
-DST7789_DRIVER=1
35+
-DTFT_WIDTH=240
36+
-DTFT_HEIGHT=320
37+
-DTFT_BL=25
38+
-DTFT_RST=-1
39+
-DTFT_DC=24
40+
-DTFT_MISO=2
41+
-DTFT_MOSI=7
42+
-DTFT_SCLK=6
43+
-DTFT_CS=23
44+
-DTOUCH_CS=1
45+
-DTFT_IPS=0
46+
-DTFT_COL_OFS1=0
47+
-DTFT_ROW_OFS1=0
48+
-DTFT_COL_OFS2=0
49+
-DTFT_ROW_OFS2=0
50+
-DCYD28_TouchR_CAL_XMIN=185
51+
-DCYD28_TouchR_CAL_XMAX=3700
52+
-DCYD28_TouchR_CAL_YMIN=250
53+
-DCYD28_TouchR_CAL_YMAX=3800
54+
-DCYD28_DISPLAY_HOR_RES_MAX=320
55+
-DCYD28_DISPLAY_VER_RES_MAX=240
56+
-DTOUCH_XPT2046_SPI=1
57+
-DCYD28_TouchR_IRQ=-1
58+
-DCYD28_TouchR_MISO=TFT_MISO
59+
-DCYD28_TouchR_MOSI=TFT_MOSI
60+
-DCYD28_TouchR_CLK=TFT_SCLK
61+
-DCYD28_TouchR_CS=1
62+
-DBOARD_HAS_TF=1
63+
-DSDCARD_CS=10
64+
-DSDCARD_SCK=TFT_SCLK
65+
-DSDCARD_MISO=TFT_MISO
66+
-DSDCARD_MOSI=TFT_MOSI
67+
68+
lib_deps =
69+
Wire
70+
SD
71+
FS
72+
ESP32Async/ESPAsyncWebServer
73+
bblanchon/ArduinoJson @ ^7.0.4
74+
moononournation/GFX Library for Arduino @ ^1.5.5

boards/_jsonfiles/nm-cyd-c5.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "esp32c5_out.ld",
5+
"partitions": "default_16MB.csv",
6+
"memory_type": "qio_qspi"
7+
},
8+
"core": "esp32",
9+
"extra_flags": [
10+
"'-D ARDUINO_ESP32C5_DEV'",
11+
"'-D BOARD_HAS_PSRAM'",
12+
"'-D ARDUINO_USB_MODE=1'",
13+
"'-D ARDUINO_USB_CDC_ON_BOOT=1'"
14+
],
15+
"f_cpu": "240000000L",
16+
"f_flash": "80000000L",
17+
"flash_mode": "qio",
18+
"hwids": [
19+
[
20+
"0x303A",
21+
"0x1001"
22+
]
23+
],
24+
"mcu": "esp32c5",
25+
"variant": "pinouts"
26+
},
27+
"connectivity": [
28+
"wifi",
29+
"bluetooth",
30+
"zigbee",
31+
"thread"
32+
],
33+
"debug": {
34+
"openocd_target": "esp32c5.cfg"
35+
},
36+
"frameworks": [
37+
"arduino",
38+
"espidf"
39+
],
40+
"name": "NM-CYD-C5",
41+
"upload": {
42+
"flash_size": "16MB",
43+
"maximum_ram_size": 327680,
44+
"maximum_size": 16777216,
45+
"require_upload_port": true,
46+
"speed": 460800
47+
},
48+
"url": "https://github.com/RockBase-iot/NM-CYD-C5",
49+
"vendor": "RockBase IoT"
50+
}

boards/pinouts/nm-cyd-c5.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
static const uint8_t LED_BUILTIN = 27;
7+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
8+
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN
9+
10+
// LP UART Pins are fixed on ESP32-C5
11+
static const uint8_t LP_RX = 12;
12+
static const uint8_t LP_TX = 11;
13+
14+
static const uint8_t USB_DM = 13;
15+
static const uint8_t USB_DP = 14;
16+
17+
static const uint8_t A0 = 1;
18+
static const uint8_t A1 = 2;
19+
static const uint8_t A2 = 3;
20+
static const uint8_t A3 = 4;
21+
static const uint8_t A4 = 5;
22+
static const uint8_t A5 = 6;
23+
24+
// UART (CH340 USB-to-UART bridge)
25+
static const uint8_t TX = 4;
26+
static const uint8_t RX = 5;
27+
28+
// I2C (CN1 connector)
29+
static const uint8_t SDA = 9;
30+
static const uint8_t SCL = 8;
31+
32+
// SPI2 (FSPI) - shared by Display (ST7789), Touch (XPT2046) and SD card
33+
static const uint8_t SS = 10; // SD card CS
34+
static const uint8_t MOSI = 7;
35+
static const uint8_t MISO = 2;
36+
static const uint8_t SCK = 6;
37+
38+
#endif /* Pins_Arduino_h */

boards/pinouts/pins_arduino.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "lilygo-t-lora-pager.h"
1313
#elif ARDUINO_M5STACK_CARDPUTER
1414
#include "m5stack-cardputer.h"
15+
#elif NM_CYD_C5
16+
#include "nm-cyd-c5.h"
1517
#elif CYD
1618
#include "CYD-2432S028.h"
1719
#elif ARDUINO_M5STACK_CORE

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ default_envs =
2424
;CYD-3248S035R
2525
;CYD-8048S043C
2626
;CYD-8048W550C
27+
NM-CYD-C5
2728
;CYD-3248W535C
2829
;CYD-4827S043R
2930
;headless-esp32-4mb
@@ -48,7 +49,7 @@ default_envs =
4849
;lilygo-t-hmi
4950
;lilygo-t-watch-s3
5051
;lilygo-t-watch-ultra
51-
m5stack-cardputer # ADV is in this env
52+
;m5stack-cardputer # ADV is in this env
5253
;m5stack-core
5354
;m5stack-core-4Mb
5455
;m5stack-core2

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ void loop() {
433433
#endif
434434
[=]() { loopOptionsWebUi(); }
435435
},
436-
#if defined(ARDUINO_USB_MODE)
436+
#if defined(SOC_USB_OTG_SUPPORTED)
437437
{
438438
#if TFT_HEIGHT < 135
439439
"USB", "SD->USB",

src/massStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,4 @@ void drawUSBStickIcon(bool plugged) {
383383
tft->display(false);
384384
}
385385

386-
#endif // ARDUINO_USB_MODE
386+
#endif // SOC_USB_OTG_SUPPORTED

src/massStorage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifdef ARDUINO_USB_MODE
1+
#ifdef SOC_USB_OTG_SUPPORTED
22

33
#ifndef __MASS_STORAGE_H__
44
#define __MASS_STORAGE_H__
@@ -45,4 +45,4 @@ bool usbStartStopCallback(uint8_t power_condition, bool start, bool load_eject);
4545
void drawUSBStickIcon(bool plugged);
4646

4747
#endif // MASS_STORAGE_H
48-
#endif // ARDUINO_USB_MODE
48+
#endif // SOC_USB_OTG_SUPPORTED

0 commit comments

Comments
 (0)