Skip to content

Commit

Permalink
Add TFT_LVGL_UI support (MarlinFirmware#18438)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhapsodyv committed Jul 1, 2020
1 parent 3910538 commit e5bc9d3
Show file tree
Hide file tree
Showing 39 changed files with 1,515 additions and 1,388 deletions.
7 changes: 5 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2135,9 +2135,12 @@
//#define FSMC_GRAPHICAL_TFT

//
// TFT Little VGL UI
// TFT LVGL UI
//
//#define TFT_LITTLE_VGL_UI
// Default MKS icons and fonts: https://git.io/JJvzK
// Copy mks_pic and mks_font folders to the root of your SD
//
//#define TFT_LVGL_UI

//=============================================================================
//============================ Other Controllers ============================
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
return uint32_t(data);
}

#if ENABLED(LCD_USE_DMA_FSMC)
#ifdef LCD_USE_DMA_FSMC

void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
while (count > 0) {
Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "gcode/parser.h"
#include "gcode/queue.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)
#include "lvgl.h"
#include "lcd/extui/lib/mks_ui/tft_lvgl_configuration.h"
#include "lcd/extui/lib/mks_ui/draw_ui.h"
Expand Down Expand Up @@ -743,7 +743,7 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
// Direct Stepping
TERN_(DIRECT_STEPPING, page_manager.write_responses());

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)
LV_TASK_HANDLER();
#endif
}
Expand Down Expand Up @@ -1180,7 +1180,8 @@ void setup() {
SETUP_RUN(page_manager.init());
#endif

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)
if (!card.isMounted()) SETUP_RUN(card.mount()); // Mount SD to load graphics and fonts
SETUP_RUN(tft_lvgl_init());
#endif

Expand Down Expand Up @@ -1216,7 +1217,7 @@ void loop() {

endstops.event_handler();

TERN_(TFT_LITTLE_VGL_UI, printer_state_polling());
TERN_(TFT_LVGL_UI, printer_state_polling());

} while (ENABLED(__AVR__)); // Loop forever on slower (AVR) boards
}
56 changes: 29 additions & 27 deletions Marlin/src/feature/touch/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,41 @@ void XPT2046::init() {
#include "../../lcd/ultralcd.h" // For EN_C bit mask

uint8_t XPT2046::read_buttons() {
int16_t tsoffsets[4] = { 0 };

if (tsoffsets[0] + tsoffsets[1] == 0) {
// Not yet set, so use defines as fallback...
tsoffsets[0] = XPT2046_X_CALIBRATION;
tsoffsets[1] = XPT2046_X_OFFSET;
tsoffsets[2] = XPT2046_Y_CALIBRATION;
tsoffsets[3] = XPT2046_Y_OFFSET;
}
#ifdef HAS_SPI_LCD
int16_t tsoffsets[4] = { 0 };

if (tsoffsets[0] + tsoffsets[1] == 0) {
// Not yet set, so use defines as fallback...
tsoffsets[0] = XPT2046_X_CALIBRATION;
tsoffsets[1] = XPT2046_X_OFFSET;
tsoffsets[2] = XPT2046_Y_CALIBRATION;
tsoffsets[3] = XPT2046_Y_OFFSET;
}

// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.

if (!isTouched()) return 0;
const uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
if (!isTouched()) return 0;
const uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.

// Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, 14, 77) ? EN_D
: WITHIN(x, 90, 153) ? EN_A
: WITHIN(x, 166, 229) ? EN_B
: WITHIN(x, 242, 305) ? EN_C
: 0;
// Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, 14, 77) ? EN_D
: WITHIN(x, 90, 153) ? EN_A
: WITHIN(x, 166, 229) ? EN_B
: WITHIN(x, 242, 305) ? EN_C
: 0;

if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 0;
if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 0;

// Column and row above BUTTON_AREA_TOP
int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
// Column and row above BUTTON_AREA_TOP
int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);

// Send the touch to the UI (which will simulate the encoder wheel)
MarlinUI::screen_click(row, col, x, y);
// Send the touch to the UI (which will simulate the encoder wheel)
MarlinUI::screen_click(row, col, x, y);
#endif
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

#include <string.h>

#if ENABLED(LCD_USE_DMA_FSMC)
#ifdef LCD_USE_DMA_FSMC
extern void LCD_IO_WriteReg(uint16_t Reg);
extern void LCD_IO_WriteData(uint16_t RegValue);
extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/W25Qxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "../../../../inc/MarlinConfigPre.h"

#if 1 // ENABLED(SPI_FLASH)
#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include <SPI.h>
#include "../../../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -391,5 +391,5 @@ void ext_FLASH::SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16

void ext_FLASH::lv_pic_read(uint8_t *P_Rbuff, uint32_t addr, uint32_t size) {SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, addr, size);}

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
#endif // 1 ... SPI_FLASH
27 changes: 13 additions & 14 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "lv_conf.h"
#include "draw_ui.h"
Expand Down Expand Up @@ -99,29 +99,28 @@ void lv_draw_about(void) {

fw_version = lv_label_create(scr, NULL);
lv_obj_set_style(fw_version, &tft_style_lable_rel);
lv_label_set_text(fw_version, "Version: V_2.0.5.3");
lv_label_set_text(fw_version, SHORT_BUILD_VERSION);
lv_obj_align(fw_version, NULL, LV_ALIGN_CENTER, 0, -60);

fw_type = lv_label_create(scr, NULL);
lv_obj_set_style(fw_type, &tft_style_lable_rel);
#if (MOTHERBOARD == BOARD_MKS_ROBIN_PRO)
lv_label_set_text(fw_type, "Firmware: Robin_Pro35");
#elif (MOTHERBOARD == BOARD_MKS_ROBIN_NANO)
lv_label_set_text(fw_type, "Firmware: Robin_Nano35");
#endif
lv_label_set_text(fw_type,
#if MB(MKS_ROBIN_PRO)
"Firmware: Robin_Pro35"
#elif MB(MKS_ROBIN_NANO)
"Firmware: Robin_Nano35"
#else
CUSTOM_MACHINE_NAME
#endif
);
lv_obj_align(fw_type, NULL, LV_ALIGN_CENTER, 0, -20);

board = lv_label_create(scr, NULL);
lv_obj_set_style(board, &tft_style_lable_rel);
#if (MOTHERBOARD == BOARD_MKS_ROBIN_PRO)
lv_label_set_text(board, "Board: MKS Robin pro");
#elif (MOTHERBOARD == BOARD_MKS_ROBIN_NANO)
lv_label_set_text(board, "Board: MKS Robin nano");
#endif

lv_label_set_text(board, "Board: " BOARD_INFO_NAME);
lv_obj_align(board, NULL, LV_ALIGN_CENTER, 0, 20);
}

void lv_clear_about() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
12 changes: 6 additions & 6 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_change_speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "lv_conf.h"
#include "draw_ui.h"
Expand Down Expand Up @@ -310,13 +310,13 @@ void disp_print_speed() {
void disp_speed_type() {
switch (speedType) {
case 1:
lv_obj_set_event_cb_mks(buttonExt, event_handler, ID_C_EXT, "bmp_Extruct_speed_sel.bin", 0);
lv_obj_set_event_cb_mks(buttonMov, event_handler, ID_C_MOVE, "bmp_Mov_speed.bin", 0);
lv_obj_set_event_cb_mks(buttonExt, event_handler, ID_C_EXT, "bmp_extruct_sel.bin", 0);
lv_obj_set_event_cb_mks(buttonMov, event_handler, ID_C_MOVE, "bmp_mov_changespeed.bin", 0);
break;

default:
lv_obj_set_event_cb_mks(buttonExt, event_handler, ID_C_EXT, "bmp_Extruct_speed.bin", 0);
lv_obj_set_event_cb_mks(buttonMov, event_handler, ID_C_MOVE, "bmp_Mov_speed_sel.bin", 0);
lv_obj_set_event_cb_mks(buttonExt, event_handler, ID_C_EXT, "bmp_Extruct.bin", 0);
lv_obj_set_event_cb_mks(buttonMov, event_handler, ID_C_MOVE, "bmp_mov_sel.bin", 0);
break;
}
lv_obj_refresh_ext_draw_pad(buttonExt);
Expand All @@ -333,4 +333,4 @@ void disp_speed_type() {

void lv_clear_change_speed() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
12 changes: 7 additions & 5 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "lv_conf.h"
#include "draw_ui.h"
Expand Down Expand Up @@ -61,7 +61,9 @@ static void btn_ok_event_cb(lv_obj_t * btn, lv_event_t event) {
}
else if (event == LV_EVENT_RELEASED) {
if (DialogType == DIALOG_TYPE_PRINT_FILE) {
preview_gcode_prehandle(list_file.file_name[sel_id]);
#if HAS_GCODE_PREVIEW
preview_gcode_prehandle(list_file.file_name[sel_id]);
#endif
reset_print_time();
start_print_time();

Expand Down Expand Up @@ -202,7 +204,7 @@ void lv_draw_dialog(uint8_t type) {
style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM;
style_btn_rel.body.radius = LV_RADIUS_CIRCLE;
style_btn_rel.text.color = lv_color_hex3(0xDEF);
style_btn_rel.text.font = &gb2312_puhui32;
style_btn_rel.text.font = &lv_font_roboto_22;

static lv_style_t style_btn_pr; // A variable to store the pressed style
lv_style_copy(&style_btn_pr, &style_btn_rel); // Initialize from the released style
Expand All @@ -211,7 +213,7 @@ void lv_draw_dialog(uint8_t type) {
style_btn_pr.body.grad_color = lv_color_hex3(0x24A);
style_btn_pr.body.shadow.width = 2;
style_btn_pr.text.color = lv_color_hex3(0xBCD);
style_btn_pr.text.font = &gb2312_puhui32;
style_btn_pr.text.font = &lv_font_roboto_22;

lv_obj_t * labelDialog = lv_label_create(scr, NULL);
lv_obj_set_style(labelDialog, &tft_style_lable_rel);
Expand Down Expand Up @@ -340,4 +342,4 @@ void lv_draw_dialog(uint8_t type) {

void lv_clear_dialog() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "lv_conf.h"
#include "draw_ui.h"
Expand Down Expand Up @@ -81,4 +81,4 @@ void lv_draw_error_message(PGM_P const msg) {

void lv_clear_error_message() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_extrusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "lv_conf.h"
#include "draw_ui.h"
Expand Down Expand Up @@ -375,4 +375,4 @@ void disp_ext_step() {

void lv_clear_extrusion() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_fan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "../../../../MarlinCore.h"
#include "lv_conf.h"
Expand Down Expand Up @@ -244,4 +244,4 @@ void disp_fan_value() {

void lv_clear_fan() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI
8 changes: 4 additions & 4 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_home.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#include "../../../../inc/MarlinConfigPre.h"

#if ENABLED(TFT_LITTLE_VGL_UI)
#if ENABLED(TFT_LVGL_UI)

#include "../../../../MarlinCore.h"
#include "draw_ready_print.h"
Expand Down Expand Up @@ -190,13 +190,13 @@ void lv_draw_home(void) {
lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_PR, &tft_style_lable_pre);
lv_imgbtn_set_style(buttonHomeZ, LV_BTN_STATE_REL, &tft_style_lable_rel);

lv_obj_set_event_cb_mks(buttonOffAll, event_handler, ID_H_OFF_ALL, "bmp_Motor_off.bin", 0);
lv_obj_set_event_cb_mks(buttonOffAll, event_handler, ID_H_OFF_ALL, "bmp_manual_off.bin", 0);
lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_REL, &bmp_pic);
lv_imgbtn_set_src(buttonOffAll, LV_BTN_STATE_PR, &bmp_pic);
lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_PR, &tft_style_lable_pre);
lv_imgbtn_set_style(buttonOffAll, LV_BTN_STATE_REL, &tft_style_lable_rel);

lv_obj_set_event_cb_mks(buttonOffXY, event_handler, ID_H_OFF_XY, "bmp_Motor_off.bin", 0);
lv_obj_set_event_cb_mks(buttonOffXY, event_handler, ID_H_OFF_XY, "bmp_manual_off.bin", 0);
lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_REL, &bmp_pic);
lv_imgbtn_set_src(buttonOffXY, LV_BTN_STATE_PR, &bmp_pic);
lv_imgbtn_set_style(buttonOffXY, LV_BTN_STATE_PR, &tft_style_lable_pre);
Expand Down Expand Up @@ -280,4 +280,4 @@ void lv_draw_home(void) {

void lv_clear_home() { lv_obj_del(scr); }

#endif // TFT_LITTLE_VGL_UI
#endif // TFT_LVGL_UI

0 comments on commit e5bc9d3

Please sign in to comment.