Skip to content

Commit 7642bfb

Browse files
🐛 Fix TFT Touch Calibration overrides (MarlinFirmware#25579)
…and other misc. display-related updates Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent dbed3f1 commit 7642bfb

17 files changed

+80
-131
lines changed

Marlin/src/HAL/STM32/tft/tft_spi.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
245245
TERN_(TFT_SHARED_IO, while (isBusy()));
246246
}
247247

248-
249248
void TFT_SPI::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
250249
DMAtx.Init.MemInc = MemoryIncrease;
251250
HAL_DMA_Init(&DMAtx);

Marlin/src/HAL/STM32F1/tft/tft_spi.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,24 @@ uint32_t TFT_SPI::GetID() {
9494
}
9595

9696
uint32_t TFT_SPI::ReadID(uint16_t Reg) {
97-
#if !PIN_EXISTS(TFT_MISO)
98-
return 0;
99-
#else
100-
uint8_t d = 0;
101-
uint32_t data = 0;
97+
uint32_t data = 0;
98+
99+
#if PIN_EXISTS(TFT_MISO)
102100
SPIx.setClockDivider(SPI_CLOCK_DIV16);
103101
DataTransferBegin(DATASIZE_8BIT);
104102
WriteReg(Reg);
105103

106104
LOOP_L_N(i, 4) {
107-
SPIx.read((uint8_t*)&d, 1);
105+
uint8_t d;
106+
SPIx.read(&d, 1);
108107
data = (data << 8) | d;
109108
}
110109

111110
DataTransferEnd();
112111
SPIx.setClockDivider(SPI_CLOCK_MAX);
113-
114-
return data >> 7;
115112
#endif
113+
114+
return data >> 7;
116115
}
117116

118117
bool TFT_SPI::isBusy() {

Marlin/src/inc/Conditionals_LCD.h

+14-27
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,22 @@
328328
#define IS_ULTIPANEL 1
329329
#endif
330330

331-
// TFT Legacy Compatibility
331+
// TFT Legacy options masquerade as TFT_GENERIC
332332
#if ANY(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
333333
#define IS_LEGACY_TFT 1
334334
#define TFT_GENERIC
335-
#endif
336-
337-
#if ANY(FSMC_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC)
338-
#define TFT_INTERFACE_FSMC
339-
#elif ANY(SPI_GRAPHICAL_TFT, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI)
340-
#define TFT_INTERFACE_SPI
341-
#endif
342-
343-
#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
344-
#define TFT_CLASSIC_UI
345-
#elif ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI)
346-
#define TFT_COLOR_UI
347-
#elif EITHER(TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
348-
#define TFT_LVGL_UI
335+
#if ANY(FSMC_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC)
336+
#define TFT_INTERFACE_FSMC
337+
#elif ANY(SPI_GRAPHICAL_TFT, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI)
338+
#define TFT_INTERFACE_SPI
339+
#endif
340+
#if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
341+
#define TFT_CLASSIC_UI
342+
#elif ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI)
343+
#define TFT_COLOR_UI
344+
#elif EITHER(TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
345+
#define TFT_LVGL_UI
346+
#endif
349347
#endif
350348

351349
// FSMC/SPI TFT Panels (LVGL)
@@ -1671,7 +1669,7 @@
16711669
#endif
16721670

16731671
#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
1674-
#include "../lcd/tft_io/tft_orientation.h"
1672+
#include "../lcd/tft_io/tft_orientation.h" // for TFT_COLOR_UI_PORTRAIT
16751673
#endif
16761674

16771675
#if ENABLED(TFT_RES_320x240)
@@ -1775,17 +1773,6 @@
17751773
#endif
17761774
#endif
17771775

1778-
// XPT2046_** Compatibility
1779-
#if !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION))
1780-
#if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET)
1781-
#define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION
1782-
#define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION
1783-
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
1784-
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
1785-
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
1786-
#endif
1787-
#endif
1788-
17891776
#if X_HOME_DIR || (HAS_Y_AXIS && Y_HOME_DIR) || (HAS_Z_AXIS && Z_HOME_DIR) \
17901777
|| (HAS_I_AXIS && I_HOME_DIR) || (HAS_J_AXIS && J_HOME_DIR) || (HAS_K_AXIS && K_HOME_DIR) \
17911778
|| (HAS_U_AXIS && U_HOME_DIR) || (HAS_V_AXIS && V_HOME_DIR) || (HAS_W_AXIS && W_HOME_DIR)

Marlin/src/inc/Conditionals_post.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@
560560
#define REINIT_NOISY_LCD 1 // Have the LCD re-init on SD insertion
561561
#endif
562562

563-
#endif
563+
#endif // HAS_MEDIA
564564

565565
/**
566566
* Power Supply
@@ -3153,6 +3153,25 @@
31533153
#endif
31543154
#endif
31553155

3156+
// Touch Calibration
3157+
#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
3158+
#ifndef TOUCH_CALIBRATION_X
3159+
#define TOUCH_CALIBRATION_X 0
3160+
#endif
3161+
#ifndef TOUCH_CALIBRATION_Y
3162+
#define TOUCH_CALIBRATION_Y 0
3163+
#endif
3164+
#ifndef TOUCH_OFFSET_X
3165+
#define TOUCH_OFFSET_X 0
3166+
#endif
3167+
#ifndef TOUCH_OFFSET_Y
3168+
#define TOUCH_OFFSET_Y 0
3169+
#endif
3170+
#ifndef TOUCH_ORIENTATION
3171+
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
3172+
#endif
3173+
#endif
3174+
31563175
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
31573176
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
31583177
#define VFAT_ENTRIES_LIMIT 5

Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,4 @@ U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT,
556556

557557
#endif // TOUCH_SCREEN_CALIBRATION
558558

559-
#endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT)
559+
#endif // HAS_MARLINUI_U8GLIB && (FSMC_CS_PIN || HAS_SPI_GRAPHICAL_TFT || HAS_LTDC_GRAPHICAL_TFT)

Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp

+13-37
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ bool have_pre_pic(char *path) {
120120
static void event_handler(lv_obj_t *obj, lv_event_t event) {
121121
if (event != LV_EVENT_RELEASED) return;
122122
uint8_t i, file_count = 0;
123-
//switch (obj->mks_obj_id)
124-
//{
125123
if (obj->mks_obj_id == ID_P_UP) {
126124
if (dir_offset[curDirLever].curPage > 0) {
127125
// 2015.05.19
@@ -130,9 +128,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
130128
if (dir_offset[curDirLever].cur_page_first_offset >= FILE_NUM)
131129
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset - FILE_NUM;
132130

133-
#if HAS_MEDIA
134-
file_count = search_file();
135-
#endif
131+
TERN_(HAS_MEDIA, file_count = search_file());
136132
if (file_count != 0) {
137133
dir_offset[curDirLever].curPage--;
138134
lv_clear_print_file();
@@ -144,9 +140,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
144140
if (dir_offset[curDirLever].cur_page_last_offset > 0) {
145141
list_file.Sd_file_cnt = 0;
146142
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_last_offset + 1;
147-
#if HAS_MEDIA
148-
file_count = search_file();
149-
#endif
143+
TERN_(HAS_MEDIA, file_count = search_file());
150144
if (file_count != 0) {
151145
dir_offset[curDirLever].curPage++;
152146
lv_clear_print_file();
@@ -161,17 +155,13 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
161155
int8_t *ch = (int8_t *)strrchr(list_file.curDirPath, '/');
162156
if (ch) {
163157
*ch = 0;
164-
#if HAS_MEDIA
165-
card.cdup();
166-
#endif
158+
TERN_(HAS_MEDIA, card.cdup());
167159
dir_offset[curDirLever].curPage = 0;
168160
dir_offset[curDirLever].cur_page_first_offset = 0;
169161
dir_offset[curDirLever].cur_page_last_offset = 0;
170162
curDirLever--;
171163
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
172-
#if HAS_MEDIA
173-
file_count = search_file();
174-
#endif
164+
TERN_(HAS_MEDIA, file_count = search_file());
175165
lv_clear_print_file();
176166
disp_gcode_icon(file_count);
177167
}
@@ -189,9 +179,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
189179
strcpy(list_file.curDirPath, list_file.file_name[i]);
190180
curDirLever++;
191181
list_file.Sd_file_offset = dir_offset[curDirLever].cur_page_first_offset;
192-
#if HAS_MEDIA
193-
file_count = search_file();
194-
#endif
182+
TERN_(HAS_MEDIA, file_count = search_file());
195183
lv_clear_print_file();
196184
disp_gcode_icon(file_count);
197185
}
@@ -396,8 +384,7 @@ int ascii2dec_test(char *ascii) {
396384

397385
void lv_gcode_file_read(uint8_t *data_buf) {
398386
#if HAS_MEDIA
399-
uint16_t i = 0, j = 0, k = 0;
400-
uint16_t row_1 = 0;
387+
uint16_t i = 0, j = 0, k = 0, row_1 = 0;
401388
bool ignore_start = true;
402389
char temp_test[200];
403390
volatile uint16_t *p_index;
@@ -435,24 +422,13 @@ void lv_gcode_file_read(uint8_t *data_buf) {
435422
break;
436423
}
437424
}
438-
#if HAS_TFT_LVGL_UI_SPI
439-
for (i = 0; i < 200;) {
440-
p_index = (uint16_t *)(&public_buf[i]);
441-
442-
//Color = (*p_index >> 8);
443-
//*p_index = Color | ((*p_index & 0xFF) << 8);
444-
i += 2;
445-
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
446-
}
447-
#else // !HAS_TFT_LVGL_UI_SPI
448-
for (i = 0; i < 200;) {
449-
p_index = (uint16_t *)(&public_buf[i]);
450-
//Color = (*p_index >> 8);
451-
//*p_index = Color | ((*p_index & 0xFF) << 8);
452-
i += 2;
453-
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full; // 0x18C3;
454-
}
455-
#endif // !HAS_TFT_LVGL_UI_SPI
425+
for (i = 0; i < 200;) {
426+
p_index = (uint16_t *)(&public_buf[i]);
427+
//Color = (*p_index >> 8);
428+
//*p_index = Color | ((*p_index & 0xFF) << 8);
429+
i += 2;
430+
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
431+
}
456432
memcpy(data_buf, public_buf, 200);
457433
#endif // HAS_MEDIA
458434
}

Marlin/src/lcd/extui/mks_ui/draw_ui.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@
133133
#define FILE_PRE_PIC_Y_OFFSET 0
134134

135135
#define PREVIEW_LITTLE_PIC_SIZE 40910 // 400*100+9*101+1
136-
#define PREVIEW_SIZE 202720 // (PREVIEW_LITTLE_PIC_SIZE+800*200+201*9+1)
136+
#define PREVIEW_SIZE 202720 // (PREVIEW_LITTLE_PIC_SIZE+800*200+201*9+1)
137137

138138
// machine parameter ui
139-
#define PARA_UI_POS_X 10
140-
#define PARA_UI_POS_Y 50
139+
#define PARA_UI_POS_X 10
140+
#define PARA_UI_POS_Y 50
141141

142142
#define PARA_UI_SIZE_X 450
143-
#define PARA_UI_SIZE_Y 40
143+
#define PARA_UI_SIZE_Y 40
144144

145-
#define PARA_UI_ARROW_V 12
145+
#define PARA_UI_ARROW_V 12
146146

147147
#define PARA_UI_BACK_POS_X 400
148148
#define PARA_UI_BACK_POS_Y 270
@@ -152,31 +152,31 @@
152152

153153
#define PARA_UI_VALUE_SIZE_X 370
154154
#define PARA_UI_VALUE_POS_X 400
155-
#define PARA_UI_VALUE_V 5
155+
#define PARA_UI_VALUE_V 5
156156

157157
#define PARA_UI_STATE_POS_X 380
158-
#define PARA_UI_STATE_V 2
158+
#define PARA_UI_STATE_V 2
159159

160160
#define PARA_UI_VALUE_SIZE_X_2 200
161161
#define PARA_UI_VALUE_POS_X_2 320
162-
#define PARA_UI_VALUE_V_2 5
162+
#define PARA_UI_VALUE_V_2 5
163163

164-
#define PARA_UI_VALUE_BTN_X_SIZE 70
165-
#define PARA_UI_VALUE_BTN_Y_SIZE 28
164+
#define PARA_UI_VALUE_BTN_X_SIZE 70
165+
#define PARA_UI_VALUE_BTN_Y_SIZE 28
166166

167-
#define PARA_UI_BACK_BTN_X_SIZE 70
168-
#define PARA_UI_BACK_BTN_Y_SIZE 40
167+
#define PARA_UI_BACK_BTN_X_SIZE 70
168+
#define PARA_UI_BACK_BTN_Y_SIZE 40
169169

170-
#define QRCODE_X 20
171-
#define QRCODE_Y 40
170+
#define QRCODE_X 20
171+
#define QRCODE_Y 40
172172
#define QRCODE_WIDTH 160
173173

174-
#else // ifdef TFT35
174+
#else // !TFT35
175175

176176
#define TFT_WIDTH 320
177177
#define TFT_HEIGHT 240
178178

179-
#endif // ifdef TFT35
179+
#endif
180180

181181
#ifdef __cplusplus
182182
extern "C" {

Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
#include <lvgl.h>
3737

3838
#include "../../../MarlinCore.h"
39+
#include "../../marlinui.h"
40+
3941
#include "../../../inc/MarlinConfig.h"
4042

4143
#include HAL_PATH(../../.., tft/xpt2046.h)
42-
#include "../../marlinui.h"
4344
XPT2046 touch;
4445

4546
#if ENABLED(POWER_LOSS_RECOVERY)

Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.h

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
#include <lvgl.h>
3434

35-
//#define TFT_ROTATION TFT_ROTATE_180
36-
3735
extern uint8_t bmp_public_buf[14 * 1024];
3836
extern uint8_t public_buf[513];
3937

Marlin/src/lcd/extui/mks_ui/wifi_module.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,7 @@ void stopEspTransfer() {
18041804

18051805
W25QXX.init(SPI_QUARTER_SPEED);
18061806

1807+
// ?? Workaround for SPI / Servo issues ??
18071808
TERN_(HAS_TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED));
18081809
TERN_(HAS_SERVOS, servo_init());
18091810
TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());

Marlin/src/lcd/tft/touch.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,18 @@ void Touch::hold(touch_control_t *control, millis_t delay) {
266266
bool Touch::get_point(int16_t *x, int16_t *y) {
267267
#if ENABLED(TFT_TOUCH_DEVICE_XPT2046)
268268
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
269-
bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
270-
269+
const bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
271270
if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
272271
*x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
273272
*y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
274273
}
275274
#else
276-
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
275+
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
277276
*x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
278277
*y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
279278
#endif
280279
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
281-
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
280+
const bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
282281
#endif
283282
#if HAS_TOUCH_SLEEP
284283
if (is_touched)

Marlin/src/lcd/tft_io/ili9488.h

-10
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,6 @@
146146
#define ILI9488_ADJCTL6 0xFC // Adjust Control 6
147147
#define ILI9488_ADJCTL7 0xFF // Adjust Control 7
148148

149-
#if 0
150-
// https://forum.mikroe.com/viewtopic.php?t=74586
151-
#if ANY(MKS_ROBIN_TFT35, TFT_TRONXY_X5SA, ANYCUBIC_TFT35) // ILI9488
152-
#define TFT_DRIVER ILI9488
153-
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
154-
#define TFT_RES_480x320
155-
#define TFT_INTERFACE_FSMC
156-
#endif
157-
#endif
158-
159149
static const uint16_t ili9488_init[] = {
160150
DATASIZE_8BIT,
161151
ESC_REG(ILI9488_SWRESET), ESC_DELAY(120),

Marlin/src/lcd/tft_io/tft_io.h

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#error "DMA_MAX_SIZE is not configured for this platform."
3838
#endif
3939

40-
#include "tft_orientation.h"
41-
4240
#ifndef TFT_DRIVER
4341
#define TFT_DRIVER AUTO
4442
#endif

0 commit comments

Comments
 (0)