mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Start of porting process
This commit is contained in:
3
CYD-Klipper/.vscode/settings.json
vendored
3
CYD-Klipper/.vscode/settings.json
vendored
@@ -9,6 +9,7 @@
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"algorithm": "cpp"
|
||||
"algorithm": "cpp",
|
||||
"cstddef": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -41,3 +41,25 @@ build_flags =
|
||||
-DSPI_FREQUENCY=55000000
|
||||
-DSPI_READ_FREQUENCY=20000000
|
||||
-DSPI_TOUCH_FREQUENCY=2500000
|
||||
|
||||
### Porting options ###
|
||||
# Defines the screen height
|
||||
-DCYD_SCREEN_HEIGHT=240
|
||||
# Defines the screen width
|
||||
-DCYD_SCREEN_WIDTH=320
|
||||
# Defines the pixel gap used for large gaps (like between buttons)
|
||||
-DCYD_SCREEN_BIG_GAP_PX=8
|
||||
# Defines the pixel gap used for small gaps (like between text and buttons)
|
||||
-DCYD_SCREEN_SMALL_GAP_PX=4
|
||||
# Defines the minimum pixel height of a button
|
||||
-DCYD_SCREEN_MIN_BUTTON_HEIGHT=35
|
||||
# Defines the minimum pixel width of a button
|
||||
-DCYD_SCREEN_MIN_BUTTON_WIDTH=35
|
||||
# Defines the size of font used
|
||||
-DCYD_SCREEN_FONT=&lv_font_montserrat_14
|
||||
# Defines the size of font used for small text
|
||||
-DCYD_SCREEN_FONT_SMALL=&lv_font_montserrat_10
|
||||
# Defines the size of the sizebar
|
||||
-DCYD_SCREEN_SIDEBAR_SIZE_PX=40
|
||||
# Defines the screen driver
|
||||
-DCYD_SCREEN_DRIVER_ESP32_2432S028R=1
|
||||
@@ -1,8 +1,19 @@
|
||||
#include "screen_driver.h"
|
||||
#include "ESP32-2432S028R.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include "../conf/global_config.h"
|
||||
#include "../../conf/global_config.h"
|
||||
#include "lvgl.h"
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
#define XPT2046_IRQ 36
|
||||
#define XPT2046_MOSI 32
|
||||
#define XPT2046_MISO 39
|
||||
#define XPT2046_CLK 25
|
||||
#define XPT2046_CS 33
|
||||
#define CPU_FREQ_HIGH 240
|
||||
#define CPU_FREQ_LOW 80
|
||||
|
||||
SPIClass touchscreen_spi = SPIClass(HSPI);
|
||||
XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);
|
||||
@@ -229,7 +240,7 @@ void screen_setup()
|
||||
touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
||||
touchscreen.begin(touchscreen_spi);
|
||||
|
||||
touchscreen_calibrate();
|
||||
touchscreen_calibrate(false);
|
||||
|
||||
lv_disp_draw_buf_init(&draw_buf, buf, NULL, TFT_WIDTH * TFT_HEIGHT / 10);
|
||||
|
||||
1
CYD-Klipper/src/core/device/ESP32-2432S028R.h
Normal file
1
CYD-Klipper/src/core/device/ESP32-2432S028R.h
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
@@ -1,35 +1,21 @@
|
||||
#pragma once
|
||||
// Adapted from https://github.com/xperiments-in/xtouch/blob/main/src/devices/2.8/screen.h
|
||||
|
||||
#ifndef _SCREEN_DRIVER_INIT
|
||||
#define _SCREEN_DRIVER_INIT
|
||||
#ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R
|
||||
#include "device/ESP32-2432S028R.h"
|
||||
#else
|
||||
#error "No screen driver defined"
|
||||
#endif
|
||||
|
||||
#define CPU_FREQ_HIGH 240
|
||||
#define CPU_FREQ_LOW 80
|
||||
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
#define XPT2046_IRQ 36
|
||||
#define XPT2046_MOSI 32
|
||||
#define XPT2046_MISO 39
|
||||
#define XPT2046_CLK 25
|
||||
#define XPT2046_CS 33
|
||||
|
||||
TS_Point touchscreen_point();
|
||||
void touchscreen_calibrate(bool force = false);
|
||||
void screen_setBrightness(byte brightness);
|
||||
void screen_setBrightness(unsigned char brightness);
|
||||
void screen_timer_setup();
|
||||
void screen_timer_start();
|
||||
void screen_timer_stop();
|
||||
void screen_timer_period(uint32_t period);
|
||||
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();
|
||||
|
||||
extern TFT_eSPI tft;
|
||||
|
||||
#endif // _SCREEN_DRIVER_INIT
|
||||
void set_screen_brightness();
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "core/data_setup.h"
|
||||
#include "ui/main_ui.h"
|
||||
#include "ui/nav_buttons.h"
|
||||
#include <Esp.h>
|
||||
|
||||
static void event_handler(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
|
||||
@@ -3,15 +3,10 @@
|
||||
#include "../nav_buttons.h"
|
||||
#include "../../core/data_setup.h"
|
||||
#include "../../core/macros_query.h"
|
||||
#include "../ui_utils.h"
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
int y_offset_macros = 40;
|
||||
const int y_element_size = 50;
|
||||
const int y_seperator_size = 1;
|
||||
const int y_seperator_x_padding = 50;
|
||||
const int panel_width = TFT_HEIGHT - 40;
|
||||
const int y_element_x_padding = 30;
|
||||
const static lv_point_t line_points[] = { {0, 0}, {panel_width - y_seperator_x_padding, 0} };
|
||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} };
|
||||
|
||||
static void btn_press(lv_event_t * e){
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
@@ -24,44 +19,11 @@ static void btn_goto_settings(lv_event_t * e){
|
||||
nav_buttons_setup(3);
|
||||
}
|
||||
|
||||
void create_macro_widget(const char* macro, lv_obj_t* root_panel){
|
||||
lv_obj_t * panel = lv_obj_create(root_panel);
|
||||
lv_obj_set_style_border_width(panel, 0, 0);
|
||||
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_pad_all(panel, 0, 0);
|
||||
lv_obj_align(panel, LV_ALIGN_TOP_MID, 0, y_offset_macros);
|
||||
lv_obj_set_size(panel, panel_width - y_element_x_padding, y_element_size);
|
||||
|
||||
lv_obj_t * line = lv_line_create(panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, y_seperator_size, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, macro);
|
||||
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_width(label, (TFT_HEIGHT - 40) * 0.75f);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Run");
|
||||
lv_obj_center(label);
|
||||
|
||||
y_offset_macros += y_element_size;
|
||||
}
|
||||
|
||||
void macros_panel_init(lv_obj_t* panel) {
|
||||
y_offset_macros = 40;
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_set_size(btn, TFT_HEIGHT - 40 - 20, 30);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 5);
|
||||
lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT);
|
||||
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_BIG_GAP_PX);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings");
|
||||
@@ -75,7 +37,42 @@ void macros_panel_init(lv_obj_t* panel) {
|
||||
return;
|
||||
}
|
||||
|
||||
lv_obj_t * root_panel = lv_create_empty_panel(panel);
|
||||
lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT - CYD_SCREEN_MIN_BUTTON_HEIGHT - CYD_SCREEN_BIG_GAP_PX);
|
||||
lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX);
|
||||
lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX);
|
||||
lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_pad_column(root_panel, 0, 0);
|
||||
lv_obj_set_style_pad_row(root_panel, 0, 0);
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
for (int i = 0; i < query.count; i++){
|
||||
create_macro_widget(query.macros[i], panel);
|
||||
const char* macro = query.macros[i];
|
||||
|
||||
lv_obj_t * panel = lv_create_empty_panel(root_panel);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2);
|
||||
|
||||
lv_obj_t * line = lv_line_create(panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, macro);
|
||||
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
// TODO: Hack. Needs to be fixed for proper porting
|
||||
lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH * 0.75f);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT);
|
||||
lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Run");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "../../core/screen_driver.h"
|
||||
#include "../../conf/global_config.h"
|
||||
#include "../main_ui.h"
|
||||
#include "../ui_utils.h"
|
||||
#include <Esp.h>
|
||||
|
||||
static void invert_color_switch(lv_event_t * e){
|
||||
auto state = lv_obj_get_state(lv_event_get_target(e));
|
||||
@@ -80,25 +82,20 @@ static void on_during_print_switch(lv_event_t* e){
|
||||
WriteGlobalConfig();
|
||||
}
|
||||
|
||||
int y_offset = 0;
|
||||
const int y_element_size = 50;
|
||||
const int y_seperator_size = 1;
|
||||
const int y_seperator_x_padding = 50;
|
||||
const int panel_width = TFT_HEIGHT - 40;
|
||||
const int y_element_x_padding = 30;
|
||||
const static lv_point_t line_points[] = { {0, 0}, {panel_width - y_seperator_x_padding, 0} };
|
||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} };
|
||||
|
||||
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){
|
||||
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT);
|
||||
|
||||
lv_obj_t * panel = lv_obj_create(root_panel);
|
||||
lv_obj_set_style_border_width(panel, 0, 0);
|
||||
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_pad_all(panel, 0, 0);
|
||||
lv_obj_align(panel, LV_ALIGN_TOP_MID, 0, y_offset);
|
||||
lv_obj_set_size(panel, panel_width - y_element_x_padding, y_element_size);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2);
|
||||
|
||||
lv_obj_t * line = lv_line_create(panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, y_seperator_size, 0);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
@@ -108,11 +105,15 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t*
|
||||
|
||||
lv_obj_set_parent(object, panel);
|
||||
lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
y_offset += y_element_size;
|
||||
}
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel){
|
||||
y_offset = 0;
|
||||
|
||||
lv_obj_set_layout(panel, LV_LAYOUT_FLEX);
|
||||
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_pad_column(panel, 0, 0);
|
||||
lv_obj_set_style_pad_row(panel, 0, 0);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
10
CYD-Klipper/src/ui/ui_utils.cpp
Normal file
10
CYD-Klipper/src/ui/ui_utils.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "lvgl.h"
|
||||
#include "ui_utils.h"
|
||||
|
||||
lv_obj_t* lv_create_empty_panel(lv_obj_t* root) {
|
||||
lv_obj_t* panel = lv_obj_create(root);
|
||||
lv_obj_set_style_border_width(panel, 0, 0);
|
||||
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_pad_all(panel, 0, 0);
|
||||
return panel;
|
||||
}
|
||||
6
CYD-Klipper/src/ui/ui_utils.h
Normal file
6
CYD-Klipper/src/ui/ui_utils.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#define CYD_SCREEN_PANEL_WIDTH \
|
||||
(CYD_SCREEN_WIDTH - CYD_SCREEN_SIDEBAR_SIZE_PX)
|
||||
|
||||
lv_obj_t* lv_create_empty_panel(lv_obj_t* root);
|
||||
Reference in New Issue
Block a user