Initial port to ESP32_3248S035C

This commit is contained in:
suchmememanyskill
2024-02-07 21:03:26 +01:00
parent 1f76012423
commit ab4688c6dd
15 changed files with 357 additions and 105 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "CYD-Klipper/boards"]
path = CYD-Klipper/boards
url = https://github.com/rzeldent/platformio-espressif32-sunton

1
CYD-Klipper/boards Submodule

Submodule CYD-Klipper/boards added at b66bca7127

View File

@@ -8,11 +8,20 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32dev]
[env]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
https://github.com/suchmememanyskill/esp32-smartdisplay
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
[env:esp32-2432S028R]
lib_deps =
SPI
https://github.com/suchmememanyskill/lvgl
@@ -20,7 +29,6 @@ lib_deps =
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
-DUSER_SETUP_LOADED=1
@@ -50,3 +58,44 @@ build_flags =
-DCYD_SCREEN_FONT_SMALL=&lv_font_montserrat_10
-DCYD_SCREEN_SIDEBAR_SIZE_PX=40
-DCYD_SCREEN_DRIVER_ESP32_2432S028R=1
[env:esp32-3248S035C]
lib_deps =
SPI
https://github.com/suchmememanyskill/lvgl
https://github.com/Bodmer/TFT_eSPI.git
https://github.com/OperatorB/gt911-arduino-fixed-reset.git
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
-DUSER_SETUP_LOADED=1
-DST7796_DRIVER=1
-DTFT_BL=27
-DTFT_BACKLIGHT_ON=HIGH
-DTFT_MISO=12
-DTFT_MOSI=13
-DTFT_SCLK=14
-DTFT_CS=15
-DTFT_DC=2
-DTFT_RST=-1
-DLOAD_GCLD=1
-DLOAD_FONT2=1
-DLOAD_GFXFF=1
-DSMOOTH_FONT=1
-DSPI_FREQUENCY=55000000
-DSPI_READ_FREQUENCY=20000000
-DSPI_TOUCH_FREQUENCY=2500000
-DTOUCH_CS=-1
-DCYD_SCREEN_HEIGHT_PX=320
-DCYD_SCREEN_WIDTH_PX=480
-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_3248S035C=1

View File

@@ -7,6 +7,7 @@
#include "lvgl.h"
#include <XPT2046_Touchscreen.h>
#include <TFT_eSPI.h>
#include "../lv_setup.h"
#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
@@ -19,16 +20,11 @@
SPIClass touchscreen_spi = SPIClass(HSPI);
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
uint32_t LV_EVENT_GET_COMP_CHILD;
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();
bool isScreenInSleep = false;
lv_timer_t *screenSleepTimer;
TS_Point touchscreen_point()
{
TS_Point p = touchscreen.getPoint();
@@ -103,61 +99,6 @@ void screen_setBrightness(byte brightness)
ledcWrite(0, duty);
}
void set_screen_brightness()
{
if (global_config.brightness < 32)
screen_setBrightness(255);
else
screen_setBrightness(global_config.brightness);
}
void screen_timer_wake()
{
lv_timer_reset(screenSleepTimer);
isScreenInSleep = false;
set_screen_brightness();
// Reset cpu freq
setCpuFrequencyMhz(CPU_FREQ_HIGH);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}
void screen_timer_sleep(lv_timer_t *timer)
{
screen_setBrightness(0);
isScreenInSleep = true;
// Screen is off, no need to make the cpu run fast, the user won't notice ;)
setCpuFrequencyMhz(CPU_FREQ_LOW);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}
void screen_timer_setup()
{
screenSleepTimer = lv_timer_create(screen_timer_sleep, global_config.screenTimeout * 1000 * 60, NULL);
lv_timer_pause(screenSleepTimer);
}
void screen_timer_start()
{
lv_timer_resume(screenSleepTimer);
}
void screen_timer_stop()
{
lv_timer_pause(screenSleepTimer);
}
void screen_timer_period(uint32_t period)
{
lv_timer_set_period(screenSleepTimer, period);
}
void set_screen_timer_period()
{
screen_timer_period(global_config.screenTimeout * 1000 * 60);
}
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);
@@ -173,12 +114,10 @@ void screen_lv_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *col
void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
if (touchscreen.tirqTouched() && touchscreen.touched())
{
lv_timer_reset(screenSleepTimer);
// dont pass first touch after power on
if (isScreenInSleep)
if (is_screen_asleep())
{
screen_timer_wake();
while (touchscreen.touched())
@@ -197,25 +136,6 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
}
}
void set_color_scheme(){
lv_disp_t *dispp = lv_disp_get_default();
lv_color_t main_color = {0};
COLOR_DEF color_def = color_defs[global_config.color_scheme];
if (color_defs[global_config.color_scheme].primary_color_light > 0){
main_color = lv_palette_lighten(color_def.primary_color, color_def.primary_color_light);
}
else if (color_defs[global_config.color_scheme].primary_color_light < 0) {
main_color = lv_palette_darken(color_def.primary_color, color_def.primary_color_light * -1);
}
else {
main_color = lv_palette_main(color_defs[global_config.color_scheme].primary_color);
}
lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !global_config.lightMode, CYD_SCREEN_FONT);
lv_disp_set_theme(dispp, theme);
}
void set_invert_display(){
tft.invertDisplay(global_config.invertColors);
}
@@ -254,20 +174,12 @@ void screen_setup()
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);
screen_timer_setup();
screen_timer_start();
/*Initialize the graphics library */
LV_EVENT_GET_COMP_CHILD = lv_event_register_id();
set_color_scheme();
}
#endif // CYD_SCREEN_DRIVER_ESP32_2432S028R

View File

@@ -0,0 +1,141 @@
#ifdef CYD_SCREEN_DRIVER_ESP32_3248S035C
#include "lvgl.h"
#include <TAMC_GT911.h>
#include <TFT_eSPI.h>
#include "../../conf/global_config.h"
#include "../lv_setup.h"
#define TOUCH_SDA 33
#define TOUCH_SCL 32
#define TOUCH_INT 21
#define TOUCH_RST 25
#define TOUCH_WIDTH 320
#define TOUCH_HEIGHT 480
#define LED_PIN_R 4
#define LED_PIN_G 16
#define LED_PIN_B 17
TAMC_GT911 tp = TAMC_GT911(TOUCH_SDA, TOUCH_SCL, TOUCH_INT, TOUCH_RST, TOUCH_WIDTH, TOUCH_HEIGHT);
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();
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)
{
tp.read();
if (!tp.isTouched)
{
data->state = LV_INDEV_STATE_REL;
}
else
{
data->state = LV_INDEV_STATE_PR;
for (int i = 0; i < tp.touches; i++)
{
uint16_t magicX; // fix GT911 driver - orientation and handle rotation
uint16_t magicY;
if (!global_config.rotateScreen)
{
magicY = tp.points[i].x;
magicX = TOUCH_HEIGHT - tp.points[i].y;
}
else
{
magicY = TOUCH_WIDTH - tp.points[i].x;
magicX = tp.points[i].y;
}
data->point.x = magicX;
data->point.y = magicY;
}
if (is_screen_asleep())
{
screen_timer_wake();
}
}
}
void set_invert_display()
{
tft.invertDisplay(global_config.invertColors);
}
void set_LED_color(uint8_t rgbVal[3])
{
analogWrite(LED_PIN_R, 255 - rgbVal[0]);
analogWrite(LED_PIN_G, 255 - rgbVal[1]);
analogWrite(LED_PIN_B, 255 - rgbVal[2]);
}
void LED_init()
{
pinMode(LED_PIN_R, OUTPUT);
pinMode(LED_PIN_G, OUTPUT);
pinMode(LED_PIN_B, OUTPUT);
uint8_t rgbVal[3] = {0, 0, 0};
set_LED_color(rgbVal);
}
void screen_setup()
{
// Initialize the touchscreen
tp.begin();
tp.setRotation(ROTATION_NORMAL);
// Initialize LVGL
lv_init();
// Initialize the display
tft.init();
ledcSetup(0, 5000, 12);
ledcAttachPin(TFT_BL, 0);
tft.setRotation(global_config.rotateScreen ? 3 : 1);
tft.fillScreen(TFT_BLACK);
set_screen_brightness();
set_invert_display();
LED_init();
lv_disp_draw_buf_init(&draw_buf, buf, NULL, TFT_WIDTH * TFT_HEIGHT / 10);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = TFT_HEIGHT;
disp_drv.ver_res = TFT_WIDTH;
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_3248S035C

View File

@@ -0,0 +1,33 @@
#ifdef CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY
#include "../screen_driver.h"
#include <esp32_smartdisplay.h>
#include "../../conf/global_config.h"
#include "lvgl.h"
#include "../lv_setup.h"
void touchscreen_calibrate(bool force)
{
// TODO: Stubbed
return;
}
void screen_setBrightness(byte brightness)
{
smartdisplay_lcd_set_backlight(brightness / 255.0f);
}
void set_invert_display(){
// Stubbed
}
void screen_setup()
{
smartdisplay_init();
// TODO: Touch input doesn't get translated when doing this
lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotateScreen) ? LV_DISP_ROT_270 : LV_DISP_ROT_90);
}
#endif // CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY

View File

@@ -0,0 +1,102 @@
#include "lvgl.h"
#include "screen_driver.h"
#include "../conf/global_config.h"
#include <Esp.h>
#ifndef CPU_FREQ_HIGH
#define CPU_FREQ_HIGH 240
#endif
#ifndef CPU_FREQ_LOW
#define CPU_FREQ_LOW 80
#endif
bool isScreenInSleep = false;
lv_timer_t *screenSleepTimer;
void set_screen_brightness()
{
if (global_config.brightness < 32)
screen_setBrightness(255);
else
screen_setBrightness(global_config.brightness);
}
void screen_timer_wake()
{
lv_timer_reset(screenSleepTimer);
isScreenInSleep = false;
set_screen_brightness();
// Reset cpu freq
setCpuFrequencyMhz(CPU_FREQ_HIGH);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}
void screen_timer_sleep(lv_timer_t *timer)
{
screen_setBrightness(0);
isScreenInSleep = true;
// Screen is off, no need to make the cpu run fast, the user won't notice ;)
setCpuFrequencyMhz(CPU_FREQ_LOW);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}
void screen_timer_setup()
{
screenSleepTimer = lv_timer_create(screen_timer_sleep, global_config.screenTimeout * 1000 * 60, NULL);
lv_timer_pause(screenSleepTimer);
}
void screen_timer_start()
{
lv_timer_resume(screenSleepTimer);
}
void screen_timer_stop()
{
lv_timer_pause(screenSleepTimer);
}
void screen_timer_period(unsigned int period)
{
lv_timer_set_period(screenSleepTimer, period);
}
void set_screen_timer_period()
{
screen_timer_period(global_config.screenTimeout * 1000 * 60);
}
void set_color_scheme()
{
lv_disp_t *dispp = lv_disp_get_default();
lv_color_t main_color = {0};
COLOR_DEF color_def = color_defs[global_config.color_scheme];
if (color_defs[global_config.color_scheme].primary_color_light > 0){
main_color = lv_palette_lighten(color_def.primary_color, color_def.primary_color_light);
}
else if (color_defs[global_config.color_scheme].primary_color_light < 0) {
main_color = lv_palette_darken(color_def.primary_color, color_def.primary_color_light * -1);
}
else {
main_color = lv_palette_main(color_defs[global_config.color_scheme].primary_color);
}
lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !global_config.lightMode, CYD_SCREEN_FONT);
lv_disp_set_theme(dispp, theme);
}
void lv_setup()
{
screen_timer_setup();
screen_timer_start();
set_color_scheme();
}
bool is_screen_asleep()
{
return isScreenInSleep;
}

View File

@@ -0,0 +1,10 @@
#pragma once
void set_screen_brightness();
void set_screen_timer_period();
void screen_timer_wake();
void screen_timer_start();
void screen_timer_stop();
void set_color_scheme();
void lv_setup();
bool is_screen_asleep();

View File

@@ -3,13 +3,5 @@
void touchscreen_calibrate(bool force = false);
void screen_setBrightness(unsigned char brightness);
void screen_timer_setup();
void screen_timer_start();
void screen_timer_stop();
void screen_timer_period(unsigned int period);
void set_color_scheme();
void screen_setup();
void set_invert_display();
void screen_timer_wake();
void set_screen_timer_period();
void set_screen_brightness();
void set_invert_display();

View File

@@ -7,12 +7,14 @@
#include "ui/main_ui.h"
#include "ui/nav_buttons.h"
#include <Esp.h>
#include "core/lv_setup.h"
void setup() {
Serial.begin(115200);
Serial.println("Hello World");
LoadGlobalConfig();
screen_setup();
lv_setup();
Serial.println("Screen init done");
wifi_init();

View File

@@ -1,7 +1,6 @@
#include "ip_setup.h"
#include "../conf/global_config.h"
#include "lvgl.h"
#include <TFT_eSPI.h>
#include <HTTPClient.h>
#include "core/data_setup.h"
#include "ui_utils.h"

View File

@@ -7,6 +7,7 @@
#include "ui_utils.h"
#include "panels/panel.h"
#include "../core/macros_query.h"
#include "../core/lv_setup.h"
char extruder_temp_buff[20];
char bed_temp_buff[20];
@@ -20,8 +21,6 @@ static void btn_click_firmware_restart(lv_event_t * e){
send_gcode(false, "FIRMWARE_RESTART");
}
void error_ui_macros_open(lv_event_t * e){
lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0);

View File

@@ -1,8 +1,8 @@
#include "lvgl.h"
#include "panel.h"
#include "../../core/data_setup.h"
#include <TFT_eSPI.h>
#include "../ui_utils.h"
#include <stdio.h>
static bool last_homing_state = false;

View File

@@ -5,6 +5,7 @@
#include "../main_ui.h"
#include "../ui_utils.h"
#include <Esp.h>
#include "../../core/lv_setup.h"
static void invert_color_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));

View File

@@ -1,5 +1,13 @@
#pragma once
#ifndef CYD_SCREEN_WIDTH_PX
#define CYD_SCREEN_WIDTH_PX LCD_HEIGHT
#endif
#ifndef CYD_SCREEN_HEIGHT_PX
#define CYD_SCREEN_HEIGHT_PX LCD_WIDTH
#endif
#define CYD_SCREEN_PANEL_WIDTH_PX \
(CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX)