Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use better defines for TFT_LVGL_UI: SPI and FSMC version #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2152,17 +2152,19 @@
// Just copy the `assets` folder from the build directory to the
// root of your SD card, together with the compiled firmware.
//
//#define TFT_LVGL_UI
// Robin nano v1.2 uses FSMC
//
//#define TFT_LVGL_UI_FSMC

// Robin nano v2.0 uses SPI
//
//#define TFT_LVGL_UI_SPI


//=============================================================================
//============================ Other Controllers ============================
//=============================================================================

//
// Robin nano v2.0 SPI touch screen
//
//#define SPI_GRAPHICAL_TFT

//
// Ender-3 v2 OEM display. A DWIN display with Rotary Encoder.
//
Expand Down
7 changes: 6 additions & 1 deletion Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,17 @@
#define IS_ULTIPANEL
#endif

// LVGL UI, SPI or FSMC
#if EITHER(TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
#define TFT_LVGL_UI
#endif

// FSMC/SPI TFT Panels
#if ENABLED(FSMC_GRAPHICAL_TFT)
#define DOGLCD
#define IS_ULTIPANEL
#define DELAYED_BACKLIGHT_INIT
#elif ENABLED(SPI_GRAPHICAL_TFT)
#elif ENABLED(TFT_LVGL_UI_SPI)
#define DELAYED_BACKLIGHT_INIT
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)

#include <SPI.h>
#include "../../../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -333,4 +333,4 @@ void TFT::LCD_Draw_Logo() {
SetWindows(0, 0, 479, 319);
}

#endif // SPI_GRAPHICAL_TFT
#endif // TFT_LVGL_UI_SPI
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 @@ -33,7 +33,7 @@
//#include "../lvgl/src/lv_core/lv_refr.h"

#include "../../../../MarlinCore.h"
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif

Expand Down Expand Up @@ -76,7 +76,7 @@ void lv_draw_error_message(PGM_P const msg) {
lv_task_handler();
#endif

TERN(SPI_GRAPHICAL_TFT, SPI_TFT.LCD_clear, LCD_Clear)(0x0000);
TERN(TFT_LVGL_UI_SPI, SPI_TFT.LCD_clear, LCD_Clear)(0x0000);
if (msg) disp_string((TFT_WIDTH - strlen(msg) * 16) / 2, 100, msg, 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("PRINTER HALTED") * 16) / 2, 140, "PRINTER HALTED", 0xFFFF, 0x0000);
disp_string((TFT_WIDTH - strlen("Please Reset") * 16) / 2, 180, "Please Reset", 0xFFFF, 0x0000);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void lv_gcode_file_read(uint8_t *data_buf) {
j = 0;
ignore_start = false;
}
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
for (i = 0; i < 200;) {
p_index = (uint16_t *)(&public_buf[i]);

Expand All @@ -527,7 +527,7 @@ void lv_gcode_file_read(uint8_t *data_buf) {
i += 2;
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3; //
}
#endif //SPI_GRAPHICAL_TFT
#endif //TFT_LVGL_UI_SPI
memcpy(data_buf, public_buf, 200);
#endif //SDSUPPORT
}
Expand Down
18 changes: 9 additions & 9 deletions Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <SPI.h>

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif

Expand Down Expand Up @@ -496,7 +496,7 @@ char *creat_title_text() {
// SERIAL_ECHOLNPAIR("gPicturePreviewStart: ", gPicturePreviewStart, " PREVIEW_LITTLE_PIC_SIZE: ", PREVIEW_LITTLE_PIC_SIZE);

card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8);
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.spi_init(SPI_FULL_SPEED);
// SPI_TFT.SetCursor(0,0);
SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
Expand All @@ -517,7 +517,7 @@ char *creat_title_text() {
}
if (j >= 400) break;
}
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
uint16_t Color, SpiColor;
SpiColor = (LV_COLOR_BACKGROUND.full >> 8) | ((LV_COLOR_BACKGROUND.full & 0xFF) << 8);
for (i = 0; i < 400;) {
Expand Down Expand Up @@ -619,7 +619,7 @@ char *creat_title_text() {
card.openFileRead(cur_name);

card.setIndex((PREVIEW_LITTLE_PIC_SIZE + To_pre_view) + size * row + 8);
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.spi_init(SPI_FULL_SPEED);
// SPI_TFT.SetCursor(0,0);
SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
Expand Down Expand Up @@ -653,7 +653,7 @@ char *creat_title_text() {
//#endif

}
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
for (i = 0; i < 400;) {
p_index = (uint16_t *)(&bmp_public_buf[i]);

Expand Down Expand Up @@ -754,7 +754,7 @@ char *creat_title_text() {
}
else {
default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
uint16_t Color;
for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) {
p_index = (uint16_t *)(&bmp_public_buf[i]);
Expand All @@ -766,7 +766,7 @@ char *creat_title_text() {
}
#else
default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) {
p_index = (uint16_t *)(&bmp_public_buf[i]);
Color = (*p_index >> 8);
Expand All @@ -777,7 +777,7 @@ char *creat_title_text() {
#endif

i = 0;
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)

// SPI_TFT.spi_init(SPI_FULL_SPEED);
// SPI_TFT.SetWindows(xpos_pixel, y_off * 20+ypos_pixel, 200,20); //200*200
Expand Down Expand Up @@ -820,7 +820,7 @@ char *creat_title_text() {
}
if (i >= 8000) break;
}
#endif // if ENABLED(SPI_GRAPHICAL_TFT)
#endif // if ENABLED(TFT_LVGL_UI_SPI)
y_off++;
}
W25QXX.init(SPI_QUARTER_SPEED);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "mks_hardware_test.h"
#include "draw_ui.h"

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif

Expand Down Expand Up @@ -583,7 +583,7 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1
for (uint16_t i = 0; i < 24; i++) {
const uint16_t tmp_char = pgm_read_word(&ASCII_Table_16x24[((c - 0x20) * 24) + i]);
for (uint16_t j = 0; j < 16; j++) {
TERN(SPI_GRAPHICAL_TFT, SPI_TFT.SetPoint, tft_set_point)
TERN(TFT_LVGL_UI_SPI, SPI_TFT.SetPoint, tft_set_point)
(x + j, y + i, ((tmp_char >> j) & 0x01) ? charColor : bkColor);
}
}
Expand All @@ -599,7 +599,7 @@ void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor

//static lv_obj_t * scr_test;
void disp_assets_update() {
#if DISABLED(SPI_GRAPHICAL_TFT)
#if DISABLED(TFT_LVGL_UI_SPI)
LCD_Clear(0x0000);
#endif
disp_string(100, 150, "Assets Updating...", 0xFFFF, 0x0000);
Expand Down
24 changes: 12 additions & 12 deletions Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#include <SPI.h>

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
#include "SPI_TFT.h"
#endif

Expand Down Expand Up @@ -88,7 +88,7 @@ void SysTick_Callback() {
print_time_count();
}

#if DISABLED(SPI_GRAPHICAL_TFT)
#if DISABLED(TFT_LVGL_UI_SPI)

extern void LCD_IO_Init(uint8_t cs, uint8_t rs);
extern void LCD_IO_WriteData(uint16_t RegValue);
Expand Down Expand Up @@ -402,7 +402,7 @@ void init_tft() {
}
}

#endif // !SPI_GRAPHICAL_TFT
#endif // !TFT_LVGL_UI_SPI

extern uint8_t bmp_public_buf[17 * 1024];

Expand All @@ -417,7 +417,7 @@ void tft_lvgl_init() {
disp_language_init();

//init tft first!
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
SPI_TFT.spi_init(SPI_FULL_SPEED);
SPI_TFT.LCD_init();
#else
Expand Down Expand Up @@ -485,7 +485,7 @@ void tft_lvgl_init() {
}

void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
uint16_t i, width, height;
uint16_t clr_temp;
uint8_t tbuf[480 * 2];
Expand Down Expand Up @@ -520,7 +520,7 @@ void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * co

W25QXX.init(SPI_QUARTER_SPEED);

#else // !SPI_GRAPHICAL_TFT
#else // !TFT_LVGL_UI_SPI

#if 1
uint16_t i, width, height;
Expand All @@ -540,7 +540,7 @@ void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * co
lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/
#endif

#endif // !SPI_GRAPHICAL_TFT
#endif // !TFT_LVGL_UI_SPI
}

#define TICK_CYCLE 1
Expand All @@ -551,7 +551,7 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) {
return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick));
}

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)

#ifndef USE_XPT2046
#define USE_XPT2046 1
Expand Down Expand Up @@ -639,7 +639,7 @@ static void xpt2046_corr(uint16_t *x, uint16_t *y) {
#define CHY 0xD0

int SPI2_ReadWrite2Bytes(void) {
#define SPI_READ_WRITE_BYTE(B) TERN(SPI_GRAPHICAL_TFT, SPI_TFT.spi_read_write_byte, W25QXX.spi_flash_read_write_byte)(B)
#define SPI_READ_WRITE_BYTE(B) TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_read_write_byte, W25QXX.spi_flash_read_write_byte)(B)
const uint16_t t1 = SPI_READ_WRITE_BYTE(0xFF),
t2 = SPI_READ_WRITE_BYTE(0xFF);
return (((t1 << 8) | t2) >> 3) & 0x0FFF;
Expand All @@ -649,10 +649,10 @@ uint16_t x_addata[times], y_addata[times];
void XPT2046_Rd_Addata(uint16_t *X_Addata, uint16_t *Y_Addata) {
uint16_t i, j, k;

TERN(SPI_GRAPHICAL_TFT, SPI_TFT.spi_init, W25QXX.init)(SPI_SPEED_6);
TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_init, W25QXX.init)(SPI_SPEED_6);

for (i = 0; i < times; i++) {
#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)
OUT_WRITE(TOUCH_CS_PIN, LOW);
SPI_TFT.spi_read_write_byte(CHX);
y_addata[i] = SPI2_ReadWrite2Bytes();
Expand All @@ -675,7 +675,7 @@ void XPT2046_Rd_Addata(uint16_t *X_Addata, uint16_t *Y_Addata) {
#endif

}
TERN(SPI_GRAPHICAL_TFT,,W25QXX.init(SPI_QUARTER_SPEED));
TERN(TFT_LVGL_UI_SPI,,W25QXX.init(SPI_QUARTER_SPEED));

for (i = 0; i < times; i++)
for (j = i + 1; j < times; j++)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
* to let the bootloader init the screen.
*/

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)

#define SPI_TFT_CS_PIN PD11
#define SPI_TFT_SCK_PIN PA5
Expand Down Expand Up @@ -201,7 +201,7 @@

#endif // TFT_LVGL_UI

#endif // SPI_GRAPHICAL_TFT
#endif // TFT_LVGL_UI_SPI

#if ENABLED(FSMC_GRAPHICAL_TFT)
//#define DOGLCD_MOSI -1 // prevent redefine Conditionals_post.h
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
* to let the bootloader init the screen.
*/

#if ENABLED(SPI_GRAPHICAL_TFT)
#if ENABLED(TFT_LVGL_UI_SPI)

#define SPI_TFT_CS_PIN PD11
#define SPI_TFT_SCK_PIN PA5
Expand Down Expand Up @@ -268,7 +268,7 @@

#endif //TFT_LITTLE_VGL_UI

#endif// SPI_GRAPHICAL_TFT
#endif// TFT_LVGL_UI_SPI

#if HAS_SPI_LCD

Expand Down