diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 950656f..a13ec5e 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -33,7 +33,7 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.13' - name: Install PlatformIO Core run: pip install --upgrade platformio esptool diff --git a/CYD-Klipper/.vscode/settings.json b/CYD-Klipper/.vscode/settings.json index e1ffb15..96d51cd 100644 --- a/CYD-Klipper/.vscode/settings.json +++ b/CYD-Klipper/.vscode/settings.json @@ -48,7 +48,8 @@ "stdexcept": "cpp", "streambuf": "cpp", "cinttypes": "cpp", - "typeinfo": "cpp" + "typeinfo": "cpp", + "*.tpp": "cpp" }, "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/CYD-Klipper/boards/esp32-JC3248W535C.json b/CYD-Klipper/boards/esp32-JC3248W535C.json index 1870b12..2a670e6 100644 --- a/CYD-Klipper/boards/esp32-JC3248W535C.json +++ b/CYD-Klipper/boards/esp32-JC3248W535C.json @@ -16,9 +16,6 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "extra_flags": [ - "-DESP32S3", - "-DARDUINO_RUNNING_CORE=1", - "-DARDUINO_EVENT_RUNNING_CORE=1", "-DLCD_WIDTH=320", "-DLCD_HEIGHT=480", "-DCYD_SCREEN_GAP_PX=8", @@ -44,7 +41,7 @@ "-DCYD_BOARD_JC3248W535C", "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION", "-DUSER_SETUP_LOADED", - "'-D ARDUINO_USB_CDC_ON_BOOT=0'", + "-DARDUINO_USB_CDC_ON_BOOT=1", "-DCYD_SCREEN_VERTICAL=1" ], "flash_mode": "qio", diff --git a/CYD-Klipper/boards/esp32-JC4827W543C.json b/CYD-Klipper/boards/esp32-JC4827W543C.json new file mode 100644 index 0000000..9cb8acf --- /dev/null +++ b/CYD-Klipper/boards/esp32-JC4827W543C.json @@ -0,0 +1,66 @@ +{ + "name": "ESP32-JC4827W543C", + "url": "https://s.click.aliexpress.com/e/_oEcVE26", + "vendor": "Guition", + + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "memory_type": "qio_opi" + }, + "core": "esp32", + "mcu": "esp32s3", + "variant": "esp32s3", + + "f_cpu": "240000000L", + "f_flash": "80000000L", + "extra_flags": [ + "-DBOARD_HAS_PSRAM", + "-DLCD_WIDTH=480", + "-DLCD_HEIGHT=270", + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", + "-DCYD_SCREEN_WIDTH_PX=480", + "-DCYD_SCREEN_HEIGHT_PX=272", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45", + "-DLCD_CS=45", + "-DLCD_CLK=47", + "-DLCD_D0=21", + "-DLCD_D1=48", + "-DLCD_D2=40", + "-DLCD_D3=39", + "-DLCD_RST=-1", + "-DLCD_DC=8", + "-DLCD_BL_PIN=1", + "-DCYD_BOARD_JC4827W543C", + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION", + "-DUSER_SETUP_LOADED", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DCYD_S3" + ], + "flash_mode": "qio", + + "hwids": [ + [ + "0X303A", + "0x1001" + ] + ] + }, + + "upload": { + "flash_size": "4MB", + "flash_mode": "qio", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "require_upload_port": true, + "speed": 921600 + }, + + "frameworks": ["arduino", "espidf"], + "connectivity": ["wifi", "bluetooth"] + } + \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index fef45eb..930ee96 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -127,6 +127,18 @@ lib_deps = moononournation/GFX Library for Arduino lvgl/lvgl@^8.4.0 plageoj/UrlEncode + bblanchon/ArduinoJson@^7.0.0 + knolleary/PubSubClient@^2.8 + WiFiClientSecure + +[env:esp32-JC4827W543C] +board = esp32-JC4827W543C +lib_deps = + SPI + https://github.com/moononournation/Arduino_GFX#v1.4.9 + https://github.com/mmMicky/TouchLib#ccaedcd9155ef8a6560ae9f594ea92e32c68020f + lvgl/lvgl@^8.4.0 + plageoj/UrlEncode bblanchon/ArduinoJson@^7.0.0 knolleary/PubSubClient@^2.8 WiFiClientSecure \ No newline at end of file diff --git a/CYD-Klipper/src/core/device/ESP32-JC3248W535C.cpp b/CYD-Klipper/src/core/device/ESP32-JC3248W535C.cpp index 8723e6e..71f91b7 100644 --- a/CYD-Klipper/src/core/device/ESP32-JC3248W535C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-JC3248W535C.cpp @@ -11,7 +11,6 @@ #define CPU_FREQ_HIGH 240 #define CPU_FREQ_LOW 80 - struct TouchPoint { uint8_t gesture; uint8_t num; diff --git a/CYD-Klipper/src/core/device/ESP32-JC4827W543C.cpp b/CYD-Klipper/src/core/device/ESP32-JC4827W543C.cpp new file mode 100644 index 0000000..0804109 --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-JC4827W543C.cpp @@ -0,0 +1,85 @@ +#ifdef CYD_BOARD_JC4827W543C + +#include "../screen_driver.h" +#include +#include "lvgl.h" +#include "../lv_setup.h" +#include "../../conf/global_config.h" +#include "ESP32-JC4827W543C_touch.h" +#define CPU_FREQ_HIGH 240 +#define CPU_FREQ_LOW 80 + +Arduino_DataBus *bus = new Arduino_ESP32QSPI(LCD_CS, LCD_CLK, LCD_D0, LCD_D1, LCD_D2, LCD_D3); +Arduino_NV3041A *panel = new Arduino_NV3041A(bus, LCD_RST, 0, true); + +static lv_disp_draw_buf_t draw_buf; +static lv_disp_drv_t disp_drv; +static lv_color_t disp_draw_buf[LCD_WIDTH * 48]; + +void screen_setBrightness(uint8_t brightness) +{ + uint32_t duty = 4095 * brightness / 255; + ledcWrite(0, duty); +} + +void screen_lv_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) +{ + uint32_t w = (area->x2 - area->x1 + 1); + uint32_t h = (area->y2 - area->y1 + 1); + + panel->startWrite(); + panel->setAddrWindow(area->x1, area->y1, w, h); + panel->writePixels((uint16_t *)&color_p->full, w * h); + panel->endWrite(); + + lv_disp_flush_ready(disp); +} + +void IRAM_ATTR screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + if (touch_has_signal() && touch_touched()) + { + data->state = LV_INDEV_STATE_PR; + data->point.x = touch_last_x; + data->point.y = touch_last_y; + } + else + { + data->state = LV_INDEV_STATE_REL; + } +} + +void set_invert_display() +{ + panel->invertDisplay(global_config.printer_config[global_config.printer_index].invert_colors); +} + +void screen_setup() +{ + pinMode(LCD_BL_PIN, OUTPUT); + ledcSetup(0, 5000, 12); + ledcAttachPin(LCD_BL_PIN, 0); + screen_setBrightness(128); + + panel->begin(); + panel->setRotation(global_config.rotate_screen ? 2 : 0); + + touch_init(panel->width(), panel->height(), panel->getRotation()); + lv_init(); + + lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, NULL, LCD_WIDTH * 48); + lv_disp_drv_init(&disp_drv); + disp_drv.flush_cb = screen_lv_flush; + disp_drv.draw_buf = &draw_buf; + disp_drv.hor_res = CYD_SCREEN_WIDTH_PX; + disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX; + lv_disp_drv_register(&disp_drv); + + static lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = screen_lv_touchRead; + lv_indev_drv_register(&indev_drv); +} + +#endif // CYD_BOARD_JC4827W543C diff --git a/CYD-Klipper/src/core/device/ESP32-JC4827W543C_touch.h b/CYD-Klipper/src/core/device/ESP32-JC4827W543C_touch.h new file mode 100644 index 0000000..a5fce22 --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-JC4827W543C_touch.h @@ -0,0 +1,196 @@ +/******************************************************************************* + * + * TouchLib https://github.com/mmMicky/TouchLib + Add Library from ZIP: TouchLib-main.zip + * + * Touch libraries: + * XPT2046: https://github.com/PaulStoffregen/XPT2046_Touchscreen.git + * + * Capacitive touchscreen libraries + * TouchLib: https://github.com/mmMicky/TouchLib.git + ******************************************************************************/ + +/* uncomment for XPT2046 */ +// #define TOUCH_XPT2046 +// #define TOUCH_XPT2046_SCK 12 +// #define TOUCH_XPT2046_MISO 13 +// #define TOUCH_XPT2046_MOSI 11 +// #define TOUCH_XPT2046_CS 38 +// #define TOUCH_XPT2046_INT 3 +// #define TOUCH_XPT2046_ROTATION 0 +// #define TOUCH_XPT2046_SAMPLES 50 + + //uncomment for most capacitive touchscreen + #define TOUCH_MODULES_GT911 // GT911 / CST_SELF / CST_MUTUAL / ZTW622 / L58 / FT3267 / FT5x06 + #define TOUCH_MODULE_ADDR GT911_SLAVE_ADDRESS1 // CTS328_SLAVE_ADDRESS / L58_SLAVE_ADDRESS / CTS826_SLAVE_ADDRESS / CTS820_SLAVE_ADDRESS / CTS816S_SLAVE_ADDRESS / FT3267_SLAVE_ADDRESS / FT5x06_ADDR / GT911_SLAVE_ADDRESS1 / GT911_SLAVE_ADDRESS2 / ZTW622_SLAVE1_ADDRESS / ZTW622_SLAVE2_ADDRESS + #define TOUCH_SCL 4 + #define TOUCH_SDA 8 + #define TOUCH_RES 38 + #define TOUCH_INT 3 + +// Please fill below values from Arduino_GFX Example - TouchCalibration +bool touch_swap_xy = false; +int16_t touch_map_x1 = -1; +int16_t touch_map_x2 = -1; +int16_t touch_map_y1 = -1; +int16_t touch_map_y2 = -1; + +int16_t touch_max_x = 0, touch_max_y = 0; +int16_t touch_raw_x = 0, touch_raw_y = 0; +int16_t touch_last_x = 0, touch_last_y = 0; + +#if defined(TOUCH_XPT2046) +#include +#include +XPT2046_Touchscreen ts(TOUCH_XPT2046_CS, TOUCH_XPT2046_INT); + +#elif defined(TOUCH_MODULE_ADDR) // TouchLib +#include +#include +TouchLib touch(Wire, TOUCH_SDA, TOUCH_SCL, TOUCH_MODULE_ADDR); + +#endif // TouchLib + +void touch_init(int16_t w, int16_t h, uint8_t r) +{ + touch_max_x = w - 1; + touch_max_y = h - 1; + if (touch_map_x1 == -1) + { + switch (r) + { + case 3: + touch_swap_xy = true; + touch_map_x1 = touch_max_x; + touch_map_x2 = 0; + touch_map_y1 = 0; + touch_map_y2 = touch_max_y; + break; + case 2: + touch_swap_xy = false; + touch_map_x1 = touch_max_x; + touch_map_x2 = 0; + touch_map_y1 = touch_max_y; + touch_map_y2 = 0; + break; + case 1: + touch_swap_xy = true; + touch_map_x1 = 0; + touch_map_x2 = touch_max_x; + touch_map_y1 = touch_max_y; + touch_map_y2 = 0; + break; + default: // case 0: + touch_swap_xy = false; + touch_map_x1 = 0; + touch_map_x2 = touch_max_x; + touch_map_y1 = 0; + touch_map_y2 = touch_max_y; + break; + } + } + +#if defined(TOUCH_XPT2046) + SPI.begin(TOUCH_XPT2046_SCK, TOUCH_XPT2046_MISO, TOUCH_XPT2046_MOSI, TOUCH_XPT2046_CS); + ts.begin(); + ts.setRotation(TOUCH_XPT2046_ROTATION); + +#elif defined(TOUCH_MODULE_ADDR) // TouchLib + // Reset touchscreen +#if (TOUCH_RES > 0) + pinMode(TOUCH_RES, OUTPUT); + digitalWrite(TOUCH_RES, 0); + delay(200); + digitalWrite(TOUCH_RES, 1); + delay(200); +#endif + Wire.begin(TOUCH_SDA, TOUCH_SCL); + touch.init(); + +#endif // TouchLib +} + +bool touch_has_signal() +{ +#if defined(TOUCH_XPT2046) + return ts.tirqTouched(); + +#elif defined(TOUCH_MODULE_ADDR) // TouchLib + // TODO: implement TOUCH_INT + return true; +#endif // TouchLib + + return false; +} + +void translate_touch_raw() +{ + if (touch_swap_xy) + { + touch_last_x = map(touch_raw_y, touch_map_x1, touch_map_x2, 0, touch_max_x); + touch_last_y = map(touch_raw_x, touch_map_y1, touch_map_y2, 0, touch_max_y); + } + else + { + touch_last_x = map(touch_raw_x, touch_map_x1, touch_map_x2, 0, touch_max_x); + touch_last_y = map(touch_raw_y, touch_map_y1, touch_map_y2, 0, touch_max_y); + } + // Serial.printf("touch_raw_x: %d, touch_raw_y: %d, touch_last_x: %d, touch_last_y: %d\n", touch_raw_x, touch_raw_y, touch_last_x, touch_last_y); +} + +bool touch_touched() +{ +#if defined(TOUCH_XPT2046) + if (ts.touched()) + { + TS_Point p = ts.getPoint(); + touch_raw_x = p.x; + touch_raw_y = p.y; + int max_z = p.z; + int count = 0; + while ((ts.touched()) && (count < TOUCH_XPT2046_SAMPLES)) + { + count++; + + TS_Point p = ts.getPoint(); + if (p.z > max_z) + { + touch_raw_x = p.x; + touch_raw_y = p.y; + max_z = p.z; + } + // Serial.printf("touch_raw_x: %d, touch_raw_y: %d, p.z: %d\n", touch_raw_x, touch_raw_y, p.z); + } + translate_touch_raw(); + return true; + } +#elif defined(TOUCH_MODULE_ADDR) // TouchLib + if (touch.read()) + { + TP_Point t = touch.getPoint(0); + touch_raw_x = t.x; + touch_raw_y = t.y; + + touch_last_x = touch_raw_x; + touch_last_y = touch_raw_y; + + translate_touch_raw(); + return true; + } + +#endif // TouchLib + + return false; +} + +bool touch_released() +{ +#if defined(TOUCH_XPT2046) + return true; + +#elif defined(TOUCH_MODULE_ADDR) // TouchLib + return false; +#endif // TouchLib + + return false; +} diff --git a/CYD-Klipper/src/core/klipper-serial/serial_klipper_printer_integration.cpp b/CYD-Klipper/src/core/klipper-serial/serial_klipper_printer_integration.cpp index bc96566..10ffabe 100644 --- a/CYD-Klipper/src/core/klipper-serial/serial_klipper_printer_integration.cpp +++ b/CYD-Klipper/src/core/klipper-serial/serial_klipper_printer_integration.cpp @@ -274,6 +274,12 @@ bool SerialKlipperPrinter::set_power_device_state(const char* device_name, bool return make_serial_request_nocontent(HttpGet, request.c_str()); } +#ifdef CYD_S3 +#define MAX_FILE_LIST_SIZE 200 +#else +#define MAX_FILE_LIST_SIZE 20 +#endif + Files SerialKlipperPrinter::get_files() { Files files_result = {0}; @@ -291,7 +297,7 @@ Files SerialKlipperPrinter::get_files() return files_result; } - parse_file_list(doc, files, 20); + parse_file_list(doc, files, MAX_FILE_LIST_SIZE); files_result.available_files = (char**)malloc(sizeof(char*) * files.size()); diff --git a/ci.json b/ci.json index 49e6275..03a87ac 100644 --- a/ci.json +++ b/ci.json @@ -52,6 +52,12 @@ "s3": true, "brand": "CrowPanel" }, + "esp32-JC4827W543C": { + "name": "ESP-JC4827W543C (4.3\" Capacitive)", + "site": true, + "s3": true, + "brand": "Guition" + }, "esp32-JC8048W550": { "name": "Guition JC8048W550 (5\" Capacitive)", "site": true, diff --git a/ci.py b/ci.py index f258f1f..37dce57 100644 --- a/ci.py +++ b/ci.py @@ -1,28 +1,5 @@ import subprocess, os, shutil, json -CYD_PORTS = [ - "esp32-2432S028R", - "esp32-3248S035C", - "esp32-2432S032C-SD", - "esp32-8048S043C-SD", - "esp32-8048S043C-SD-alt", - "esp32-2432S024C-SD", - "esp32-4827S043C-SD", - "esp32-3248S035C-V", - #"esp32-4827S043R-SD", - "esp32-CROWPANEL-28R", - "esp32-CROWPANEL-35C", - "esp32-JC8048W550", -] - -ESP_S3_CHIPS = [ - "esp32-8048S043C-SD", - "esp32-8048S043C-SD-alt", - "esp32-4827S043C-SD", - "esp32-CROWPANEL-35C", - "esp32-JC8048W550", -] - BASE_DIR = os.getcwd() def get_manifest(base_path : str, device_name : str, is_s3 : bool):