From 446b470d109c3470062f8968dff624eff6b54c0b Mon Sep 17 00:00:00 2001 From: Madrajib LAB Date: Sat, 30 Nov 2024 16:01:55 +0530 Subject: [PATCH 1/2] Add support for crowpanel 2.8inch display --- CYD-Klipper/boards/esp32-CROWPANEL-28R.json | 63 ++++++++++ CYD-Klipper/platformio.ini | 10 ++ .../src/core/device/ESP32-CROWPANEL_28R.cpp | 111 ++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 CYD-Klipper/boards/esp32-CROWPANEL-28R.json create mode 100644 CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp diff --git a/CYD-Klipper/boards/esp32-CROWPANEL-28R.json b/CYD-Klipper/boards/esp32-CROWPANEL-28R.json new file mode 100644 index 0000000..81ebe66 --- /dev/null +++ b/CYD-Klipper/boards/esp32-CROWPANEL-28R.json @@ -0,0 +1,63 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DUSER_SETUP_LOADED=1", + "-DILI9341_2_DRIVER=1", + "-DTFT_BACKLIGHT_ON=HIGH", + "-DTFT_BL=27", + "-DTFT_MISO=12", + "-DTFT_MOSI=13", + "-DTFT_SCLK=14", + "-DTFT_CS=15", + "-DTFT_DC=2", + "-DTFT_RST=-1", + "-DLOAD_GCLD=1", + "-DSPI_FREQUENCY=15999999", + "-DSPI_READ_FREQUENCY=20000000", + "-DSPI_TOUCH_FREQUENCY=600000", + "-DTOUCH_CS=33", + + "-DCYD_SCREEN_HEIGHT_PX=240", + "-DCYD_SCREEN_WIDTH_PX=320", + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_CROWPANEL_28R=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-crowpanel-28R", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005004502250619.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 87de374..bceab90 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -84,3 +84,13 @@ board = esp32-4827S043C-smartdisplay [env:esp32-8048S043C-SD] board = esp32-8048S043C-smartdisplay +[env:esp32-CROWPANEL-28R] +platform = https://github.com/platformio/platform-espressif32#v6.9.0 +board = esp32-CROWPANEL-28R +lib_deps = + SPI + https://github.com/suchmememanyskill/lvgl + https://github.com/Bodmer/TFT_eSPI.git + bblanchon/ArduinoJson@^7.0.0 + plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 diff --git a/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp b/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp new file mode 100644 index 0000000..5d73109 --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp @@ -0,0 +1,111 @@ +#ifdef CYD_SCREEN_DRIVER_ESP32_CROWPANEL_28R +#include "../screen_driver.h" + +#ifdef CYD_SCREEN_VERTICAL + #error "Vertical screen not supported with the ESP32_CROWPANEL_28R driver" +#endif + +#include +#include +#include "../../conf/global_config.h" +#include "lvgl.h" +#include +#include "../lv_setup.h" + +#define CPU_FREQ_HIGH 240 +#define CPU_FREQ_LOW 80 +#define TOUCH_THRESHOLD 600 + +static lv_disp_draw_buf_t draw_buf; +static lv_color_t buf[CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10]; + +TFT_eSPI tft = TFT_eSPI(); + +uint16_t touchX, touchY; + +void screen_setBrightness(byte brightness) +{ + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / 255) * brightness; + + // write duty to LEDC + 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); + + tft.startWrite(); + tft.setAddrWindow(area->x1, area->y1, w, h); + tft.pushColors((uint16_t *)&color_p->full, w * h, true); + tft.endWrite(); + + lv_disp_flush_ready(disp); +} + +void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + if (tft.getTouch( &touchX, &touchY, TOUCH_THRESHOLD)) + { + data->state = LV_INDEV_STATE_PR; + data->point.x = touchX; + data->point.y = touchY; + } + else + { + data->state = LV_INDEV_STATE_REL; + } +} + +void set_invert_display(){ + tft.invertDisplay(get_current_printer_config()->invert_colors); +} + +void screen_setup() +{ + uint16_t calData[5] = { 189, 3416, 359, 3439, 1}; + + lv_init(); + + tft.init(); + tft.fillScreen(TFT_BLACK); + tft.invertDisplay(false); + delay(300); + + tft.setRotation(1); + tft.setTouch( calData ); + + if (global_config.display_mode) { + // <3 https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/blob/main/cyd.md#the-display-doesnt-look-as-good + tft.writecommand(ILI9341_GAMMASET); //Gamma curve selected + tft.writedata(2); + delay(120); + tft.writecommand(ILI9341_GAMMASET); //Gamma curve selected + tft.writedata(1); + } + + ledcSetup(0, 5000, 12); + ledcAttachPin(TFT_BL, 0); + + lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10); + + /*Initialize the display*/ + static lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = CYD_SCREEN_WIDTH_PX; + disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX; + disp_drv.flush_cb = screen_lv_flush; + disp_drv.draw_buf = &draw_buf; + lv_disp_drv_register(&disp_drv); + + /*Initialize the (dummy) input device driver*/ + 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_SCREEN_DRIVER_ESP32_CROWPANEL_28R \ No newline at end of file From 88f0a2f6e3f58566f4807c1d8408ee15ee6658ee Mon Sep 17 00:00:00 2001 From: Madrajib LAB Date: Sat, 30 Nov 2024 16:01:55 +0530 Subject: [PATCH 2/2] Add support for crowpanel 2.8inch display --- CYD-Klipper/boards/esp32-CROWPANEL-28R.json | 63 ++++++++++ CYD-Klipper/platformio.ini | 10 ++ .../src/core/device/ESP32-CROWPANEL_28R.cpp | 109 ++++++++++++++++++ _site/index.html | 1 + ci.py | 1 + 5 files changed, 184 insertions(+) create mode 100644 CYD-Klipper/boards/esp32-CROWPANEL-28R.json create mode 100644 CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp diff --git a/CYD-Klipper/boards/esp32-CROWPANEL-28R.json b/CYD-Klipper/boards/esp32-CROWPANEL-28R.json new file mode 100644 index 0000000..d5c17da --- /dev/null +++ b/CYD-Klipper/boards/esp32-CROWPANEL-28R.json @@ -0,0 +1,63 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DUSER_SETUP_LOADED=1", + "-DILI9341_2_DRIVER=1", + "-DTFT_BACKLIGHT_ON=HIGH", + "-DTFT_BL=27", + "-DTFT_MISO=12", + "-DTFT_MOSI=13", + "-DTFT_SCLK=14", + "-DTFT_CS=15", + "-DTFT_DC=2", + "-DTFT_RST=-1", + "-DLOAD_GCLD=1", + "-DSPI_FREQUENCY=15999999", + "-DSPI_READ_FREQUENCY=20000000", + "-DSPI_TOUCH_FREQUENCY=600000", + "-DTOUCH_CS=33", + + "-DCYD_SCREEN_HEIGHT_PX=240", + "-DCYD_SCREEN_WIDTH_PX=320", + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_CROWPANEL_28R=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-crowpanel-28R", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.elecrow.com/esp32-display-2-8-inch-hmi-display-spi-tft-lcd-touch-screen.html", + "vendor": "elecrow" + } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 87de374..bceab90 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -84,3 +84,13 @@ board = esp32-4827S043C-smartdisplay [env:esp32-8048S043C-SD] board = esp32-8048S043C-smartdisplay +[env:esp32-CROWPANEL-28R] +platform = https://github.com/platformio/platform-espressif32#v6.9.0 +board = esp32-CROWPANEL-28R +lib_deps = + SPI + https://github.com/suchmememanyskill/lvgl + https://github.com/Bodmer/TFT_eSPI.git + bblanchon/ArduinoJson@^7.0.0 + plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 diff --git a/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp b/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp new file mode 100644 index 0000000..7835636 --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-CROWPANEL_28R.cpp @@ -0,0 +1,109 @@ +#ifdef CYD_SCREEN_DRIVER_ESP32_CROWPANEL_28R +#include "../screen_driver.h" + +#ifdef CYD_SCREEN_VERTICAL + #error "Vertical screen not supported with the ESP32_CROWPANEL_28R driver" +#endif + +#include +#include +#include "../../conf/global_config.h" +#include "lvgl.h" +#include +#include "../lv_setup.h" + +#define TOUCH_THRESHOLD 600 + +static lv_disp_draw_buf_t draw_buf; +static lv_color_t buf[CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10]; + +TFT_eSPI tft = TFT_eSPI(); + +uint16_t touchX, touchY; + +void screen_setBrightness(byte brightness) +{ + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / 255) * brightness; + + // write duty to LEDC + 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); + + tft.startWrite(); + tft.setAddrWindow(area->x1, area->y1, w, h); + tft.pushColors((uint16_t *)&color_p->full, w * h, true); + tft.endWrite(); + + lv_disp_flush_ready(disp); +} + +void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + if (tft.getTouch( &touchX, &touchY, TOUCH_THRESHOLD)) + { + data->state = LV_INDEV_STATE_PR; + data->point.x = touchX; + data->point.y = touchY; + } + else + { + data->state = LV_INDEV_STATE_REL; + } +} + +void set_invert_display(){ + tft.invertDisplay(get_current_printer_config()->invert_colors); +} + +void screen_setup() +{ + uint16_t calData[5] = { 189, 3416, 359, 3439, 1}; + + lv_init(); + + tft.init(); + tft.fillScreen(TFT_BLACK); + tft.invertDisplay(false); + delay(300); + + tft.setRotation(1); + tft.setTouch( calData ); + + if (global_config.display_mode) { + // <3 https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/blob/main/cyd.md#the-display-doesnt-look-as-good + tft.writecommand(ILI9341_GAMMASET); //Gamma curve selected + tft.writedata(2); + delay(120); + tft.writecommand(ILI9341_GAMMASET); //Gamma curve selected + tft.writedata(1); + } + + ledcSetup(0, 5000, 12); + ledcAttachPin(TFT_BL, 0); + + lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10); + + /*Initialize the display*/ + static lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = CYD_SCREEN_WIDTH_PX; + disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX; + disp_drv.flush_cb = screen_lv_flush; + disp_drv.draw_buf = &draw_buf; + lv_disp_drv_register(&disp_drv); + + /*Initialize the (dummy) input device driver*/ + 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_SCREEN_DRIVER_ESP32_CROWPANEL_28R \ No newline at end of file diff --git a/_site/index.html b/_site/index.html index cba34c8..cbe405b 100644 --- a/_site/index.html +++ b/_site/index.html @@ -99,6 +99,7 @@

Install

+ diff --git a/ci.py b/ci.py index c397650..a7ba3d0 100644 --- a/ci.py +++ b/ci.py @@ -9,6 +9,7 @@ "esp32-4827S043C-SD", "esp32-3248S035C-V", #"esp32-4827S043R-SD", + "esp32-CROWPANEL-28R", ] ESP_S3_CHIPS = [