Skip to content

Commit c929b5e

Browse files
Merge main
2 parents 4093251 + b6c2b50 commit c929b5e

File tree

3 files changed

+281
-0
lines changed

3 files changed

+281
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "ESP32-JC3248W535C",
3+
"url": "https://www.aliexpress.com/item/1005007566315926.html",
4+
"vendor": "Guition",
5+
6+
"build": {
7+
"arduino": {
8+
"ldscript": "esp32s3_out.ld",
9+
"memory_type": "qio_opi",
10+
"partitions": "default_16MB.csv"
11+
},
12+
"core": "esp32",
13+
"mcu": "esp32s3",
14+
"variant": "esp32s3",
15+
16+
"f_cpu": "240000000L",
17+
"f_flash": "80000000L",
18+
"extra_flags": [
19+
"-DESP32S3",
20+
"-DARDUINO_RUNNING_CORE=1",
21+
"-DARDUINO_EVENT_RUNNING_CORE=1",
22+
"-DLCD_WIDTH=320",
23+
"-DLCD_HEIGHT=480",
24+
"-DCYD_SCREEN_GAP_PX=8",
25+
"-DCYD_SCREEN_FONT=lv_font_montserrat_14",
26+
"-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12",
27+
"-DCYD_SCREEN_WIDTH_PX=LCD_WIDTH",
28+
"-DCYD_SCREEN_HEIGHT_PX=LCD_HEIGHT",
29+
"-DCYD_SCREEN_SIDEBAR_SIZE_PX=50",
30+
"-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=45",
31+
"-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45",
32+
"-DLCD_CS=45",
33+
"-DLCD_CLK=47",
34+
"-DLCD_D0=21",
35+
"-DLCD_D1=48",
36+
"-DLCD_D2=40",
37+
"-DLCD_D3=39",
38+
"-DLCD_RST=-1",
39+
"-DLCD_DC=8",
40+
"-DTOUCH_SDA=4",
41+
"-DTOUCH_SCL=8",
42+
"-DTOUCH_ADDR=0x3B",
43+
"-DLCD_BL_PIN=1",
44+
"-DCYD_BOARD_JC3248W535C",
45+
"-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION"
46+
],
47+
"flash_mode": "qio",
48+
49+
"hwids": [
50+
[
51+
"0X303A",
52+
"0x1001"
53+
]
54+
]
55+
},
56+
57+
"upload": {
58+
"flash_size": "16MB",
59+
"flash_mode": "qio",
60+
"maximum_ram_size": 327680,
61+
"maximum_size": 16777216,
62+
"require_upload_port": true,
63+
"speed": 921600
64+
},
65+
66+
"frameworks": ["arduino", "espidf"],
67+
"connectivity": ["wifi", "bluetooth"]
68+
}
69+

CYD-Klipper/platformio.ini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,30 @@ lib_deps =
120120

121121
[env:esp32-JC8048W550]
122122
board = esp32-JC8048W550
123+
124+
[env:ESP32-JC3248W535C]
125+
platform = espressif32@^6.4.0
126+
board = esp32-JC3248W535C
127+
framework = arduino
128+
board_build.flash_mode = qio
129+
board_build.partitions = huge_app.csv
130+
board_build.psram_size = 8MB
131+
build_flags =
132+
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
133+
-DUSER_SETUP_LOADED
134+
-DARDUINO_USB_CDC_ON_BOOT=1
135+
-DCYD_SCREEN_VERTICAL=1
136+
137+
138+
lib_deps =
139+
SPI
140+
moononournation/GFX Library for Arduino
141+
lvgl/lvgl@^8.4.0
142+
plageoj/UrlEncode
143+
bblanchon/ArduinoJson@^7.0.0
144+
knolleary/PubSubClient@^2.8
145+
WiFiClientSecure
146+
147+
monitor_filters = esp32_exception_decoder
148+
monitor_speed = 115200
149+
upload_speed = 921600
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
#ifdef CYD_BOARD_JC3248W535C
2+
3+
#include "../screen_driver.h"
4+
#include <databus/Arduino_ESP32QSPI.h>
5+
#include <display/Arduino_AXS15231B.h>
6+
#include <canvas/Arduino_Canvas.h>
7+
#include "lvgl.h"
8+
#include "../lv_setup.h"
9+
#include "../../conf/global_config.h"
10+
#include <Wire.h>
11+
#define CPU_FREQ_HIGH 240
12+
#define CPU_FREQ_LOW 80
13+
14+
15+
struct TouchPoint {
16+
uint8_t gesture;
17+
uint8_t num;
18+
uint8_t x_h : 4;
19+
uint8_t _pad1 : 2;
20+
uint8_t event : 2;
21+
uint8_t x_l;
22+
uint8_t y_h : 4;
23+
uint8_t _pad2 : 4;
24+
uint8_t y_l;
25+
} __attribute__((packed));
26+
27+
static Arduino_ESP32QSPI qspiBus(
28+
LCD_CS, LCD_CLK,
29+
LCD_D0, LCD_D1,
30+
LCD_D2, LCD_D3,
31+
false);
32+
33+
34+
Arduino_GFX *gfx = new Arduino_AXS15231B(
35+
&qspiBus, -1, 2, true,
36+
LCD_WIDTH, LCD_HEIGHT,
37+
0, 0, 0, 0);
38+
39+
#ifdef CYD_SCREEN_VERTICAL
40+
static bool horizontal = false;
41+
static Arduino_Canvas canvas(CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX, gfx, 0, 0);
42+
#else
43+
static bool horizontal = true;
44+
static Arduino_Canvas canvas(CYD_SCREEN_HEIGHT_PX, CYD_SCREEN_WIDTH_PX, gfx, 0, 0);
45+
46+
#endif
47+
48+
static lv_disp_draw_buf_t draw_buf;
49+
static lv_color_t *buf = nullptr;
50+
static lv_disp_t *main_disp = nullptr;
51+
52+
53+
void screen_setBrightness(uint8_t brightness)
54+
{
55+
uint32_t duty = (4095UL * brightness) / 255UL;
56+
ledcWrite(0, duty);
57+
}
58+
59+
void screen_lv_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
60+
{
61+
int x = area->x1;
62+
int y = area->y1;
63+
int w = area->x2 - area->x1 + 1;
64+
int h = area->y2 - area->y1 + 1;
65+
canvas.draw16bitRGBBitmap(x, y, (uint16_t *)color_p, w, h);
66+
canvas.flush();
67+
68+
lv_disp_flush_ready(disp);
69+
}
70+
71+
// Reads 1 touch point from AXS15231B controller at I2C addr 0x3B
72+
bool read_touch(uint16_t &x, uint16_t &y) {
73+
const uint8_t addr = 0x3B;
74+
75+
const uint8_t read_cmd[11] = {
76+
0xB5, 0xAB, 0xA5, 0x5A, 0x00, 0x00,
77+
0x00, 8, // length of expected reply (MSB, LSB)
78+
0x00, 0x00, 0x00
79+
};
80+
81+
Wire.beginTransmission(addr);
82+
Wire.write(read_cmd, sizeof(read_cmd));
83+
if (Wire.endTransmission(false) != 0) {
84+
return false;
85+
}
86+
87+
uint8_t data[8] = {0};
88+
if (Wire.requestFrom(addr, (uint8_t)sizeof(data)) != sizeof(data)) {
89+
return false;
90+
}
91+
92+
for (uint8_t i = 0; i < sizeof(data); i++) {
93+
data[i] = Wire.read();
94+
}
95+
96+
TouchPoint *p = (TouchPoint *)data;
97+
98+
if (p->num > 0 && p->num <= 2) {
99+
x = ((p->x_h & 0x0F) << 8) | p->x_l;
100+
y = ((p->y_h & 0x0F) << 8) | p->y_l;
101+
102+
// Clamp to screen bounds
103+
if (x >= CYD_SCREEN_WIDTH_PX) x = CYD_SCREEN_WIDTH_PX - 1;
104+
if (y >= CYD_SCREEN_HEIGHT_PX) y = CYD_SCREEN_HEIGHT_PX - 1;
105+
return true;
106+
}
107+
108+
return false;
109+
}
110+
111+
112+
void screen_lv_touchRead(lv_indev_drv_t * /*indev_driver*/, lv_indev_data_t *data)
113+
{
114+
uint16_t x, y;
115+
if (read_touch(x, y)) {
116+
x = min(x, uint16_t(CYD_SCREEN_WIDTH_PX - 1));
117+
y = min(y, uint16_t(CYD_SCREEN_HEIGHT_PX - 1));
118+
// Adjust coordinates based on screen rotation
119+
if (global_config.rotate_screen) {
120+
// Assuming rotation = 2 (180 degrees)
121+
x = CYD_SCREEN_WIDTH_PX - x;
122+
y = CYD_SCREEN_HEIGHT_PX - y;
123+
}
124+
125+
data->state = LV_INDEV_STATE_PR;
126+
data->point.x = x;
127+
data->point.y = y;
128+
} else {
129+
data->state = LV_INDEV_STATE_REL;
130+
}
131+
}
132+
133+
void set_invert_display()
134+
{
135+
gfx->invertDisplay(global_config.printer_config[global_config.printer_index].invert_colors);
136+
}
137+
138+
void screen_setup()
139+
{
140+
pinMode(LCD_BL_PIN, OUTPUT);
141+
ledcSetup(0, 5000, 12);
142+
ledcAttachPin(LCD_BL_PIN, 0);
143+
screen_setBrightness(255);
144+
145+
// gfx->begin();
146+
canvas.begin();
147+
gfx->invertDisplay(true); // OK after begin()
148+
gfx->setRotation(global_config.rotate_screen ? 2 : 0);
149+
canvas.fillScreen(0x0000);
150+
canvas.flush();
151+
152+
Wire.begin(TOUCH_SDA, TOUCH_SCL);
153+
154+
lv_init();
155+
156+
// Allocate full canvas buffer for LVGL
157+
buf = (lv_color_t *)heap_caps_malloc(
158+
CYD_SCREEN_WIDTH_PX * CYD_SCREEN_HEIGHT_PX * sizeof(lv_color_t),
159+
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
160+
161+
assert(buf);
162+
163+
lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_WIDTH_PX * CYD_SCREEN_HEIGHT_PX);
164+
165+
static lv_disp_drv_t disp_drv;
166+
lv_disp_drv_init(&disp_drv);
167+
disp_drv.flush_cb = screen_lv_flush;
168+
disp_drv.draw_buf = &draw_buf;
169+
170+
disp_drv.hor_res = CYD_SCREEN_WIDTH_PX;
171+
disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX;
172+
if(horizontal){
173+
main_disp = lv_disp_drv_register(&disp_drv);
174+
lv_disp_set_rotation(main_disp, LV_DISP_ROT_90);
175+
} else {
176+
lv_disp_drv_register(&disp_drv);
177+
}
178+
static lv_indev_drv_t indev_drv;
179+
lv_indev_drv_init(&indev_drv);
180+
indev_drv.type = LV_INDEV_TYPE_POINTER;
181+
indev_drv.read_cb = screen_lv_touchRead;
182+
lv_indev_drv_register(&indev_drv);
183+
}
184+
185+
#endif // CYD_BOARD_JC3248W535C

0 commit comments

Comments
 (0)