Browse Source

Support 4.3" (480x272) Color UI display (#20334)

Victor Oliveira 3 years ago
parent
commit
41e4124af9
No account linked to committer's email address

+ 1
- 0
Marlin/Configuration.h View File

@@ -2438,6 +2438,7 @@
2438 2438
   //#define TOUCH_CALIBRATION_Y -8981
2439 2439
   //#define TOUCH_OFFSET_X        -43
2440 2440
   //#define TOUCH_OFFSET_Y        257
2441
+  //#define TOUCH_ORIENTATION   TOUCH_LANDSCAPE
2441 2442
 
2442 2443
   #if ENABLED(TFT_COLOR_UI)
2443 2444
     //#define SINGLE_TOUCH_NAVIGATION

+ 9
- 0
Marlin/src/inc/Conditionals_LCD.h View File

@@ -1169,6 +1169,12 @@
1169 1169
   #elif ENABLED(TFT_INTERFACE_FSMC)
1170 1170
     #define TFT_480x320
1171 1171
   #endif
1172
+#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272
1173
+  #if ENABLED(TFT_INTERFACE_SPI)
1174
+    #define TFT_480x272_SPI
1175
+  #elif ENABLED(TFT_INTERFACE_FSMC)
1176
+    #define TFT_480x272
1177
+  #endif
1172 1178
 #endif
1173 1179
 
1174 1180
 // Fewer lines with touch buttons on-screen
@@ -1178,6 +1184,9 @@
1178 1184
 #elif EITHER(TFT_480x320, TFT_480x320_SPI)
1179 1185
   #define HAS_UI_480x320 1
1180 1186
   #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
1187
+#elif EITHER(TFT_480x272, TFT_480x272_SPI)
1188
+  #define HAS_UI_480x272 1
1189
+  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
1181 1190
 #endif
1182 1191
 
1183 1192
 // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'

+ 3
- 0
Marlin/src/lcd/tft/tft.h View File

@@ -43,6 +43,9 @@
43 43
 #elif HAS_UI_480x320
44 44
   #define TFT_WIDTH         480
45 45
   #define TFT_HEIGHT        320
46
+#elif HAS_UI_480x272
47
+  #define TFT_WIDTH         480
48
+  #define TFT_HEIGHT        272
46 49
 #else
47 50
   #error "Unsupported display resolution!"
48 51
 #endif

+ 36
- 31
Marlin/src/lcd/tft/ui_480x320.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../inc/MarlinConfigPre.h"
24 24
 
25
-#if HAS_UI_480x320
25
+#if HAS_UI_480x320 || HAS_UI_480x272
26 26
 
27 27
 #include "ui_480x320.h"
28 28
 
@@ -56,9 +56,9 @@
56 56
 void MarlinUI::tft_idle() {
57 57
   #if ENABLED(TOUCH_SCREEN)
58 58
     if (draw_menu_navigation) {
59
-      add_control(104, 286, PAGE_UP, imgPageUp, encoderTopLine > 0);
60
-      add_control(344, 286, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
61
-      add_control(224, 286, BACK, imgBack);
59
+      add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
60
+      add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
61
+      add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
62 62
       draw_menu_navigation = false;
63 63
     }
64 64
   #endif
@@ -259,10 +259,12 @@ void MarlinUI::draw_status_screen() {
259 259
     }
260 260
   }
261 261
 
262
+  y += TERN(HAS_UI_480x272, 118, 128);
263
+
262 264
   // coordinates
263
-  tft.canvas(4, 132, TFT_WIDTH - 8, 34);
265
+  tft.canvas(4, y, TFT_WIDTH - 8, FONT_LINE_HEIGHT);
264 266
   tft.set_background(COLOR_BACKGROUND);
265
-  tft.add_rectangle(0, 0, TFT_WIDTH - 8, 34, COLOR_AXIS_HOMED);
267
+  tft.add_rectangle(0, 0, TFT_WIDTH - 8, FONT_LINE_HEIGHT, COLOR_AXIS_HOMED);
266 268
 
267 269
   tft.add_text( 16, 3, COLOR_AXIS_HOMED , "X");
268 270
   tft.add_text(192, 3, COLOR_AXIS_HOMED , "Y");
@@ -290,10 +292,11 @@ void MarlinUI::draw_status_screen() {
290 292
     offset -= tft_string.width();
291 293
   }
292 294
   tft.add_text(455 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
293
-  TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, 132, TFT_WIDTH - 8, 34));
295
+  TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, y, TFT_WIDTH - 8, FONT_LINE_HEIGHT));
294 296
 
297
+  y += TERN(HAS_UI_480x272, 38, 48);
295 298
   // feed rate
296
-  tft.canvas(96, 180, 100, 32);
299
+  tft.canvas(96, y, 100, 32);
297 300
   tft.set_background(COLOR_BACKGROUND);
298 301
   uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
299 302
   tft.add_image(0, 0, imgFeedRate, color);
@@ -303,7 +306,7 @@ void MarlinUI::draw_status_screen() {
303 306
   TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32));
304 307
 
305 308
   // flow rate
306
-  tft.canvas(284, 180, 100, 32);
309
+  tft.canvas(284, y, 100, 32);
307 310
   tft.set_background(COLOR_BACKGROUND);
308 311
   color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
309 312
   tft.add_image(0, 0, imgFlowRate, color);
@@ -312,36 +315,38 @@ void MarlinUI::draw_status_screen() {
312 315
   tft.add_text(36, 1, color , tft_string);
313 316
   TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder));
314 317
 
318
+  #if ENABLED(TOUCH_SCREEN)
319
+    add_control(404, y, menu_main, imgSettings);
320
+    TERN_(SDSUPPORT, add_control(12, y, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
321
+  #endif
322
+
323
+  y += TERN(HAS_UI_480x272, 36, 44);
315 324
   // print duration
316 325
   char buffer[14];
317 326
   duration_t elapsed = print_job_timer.duration();
318 327
   elapsed.toDigital(buffer);
319 328
 
320
-  tft.canvas((TFT_WIDTH - 128) / 2, 224, 128, 29);
329
+  tft.canvas((TFT_WIDTH - 128) / 2, y, 128, 29);
321 330
   tft.set_background(COLOR_BACKGROUND);
322 331
   tft_string.set(buffer);
323 332
   tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
324 333
 
334
+  y += TERN(HAS_UI_480x272, 28, 36);
325 335
   // progress bar
326 336
   const uint8_t progress = ui.get_progress_percent();
327
-  tft.canvas(4, 260, TFT_WIDTH - 8, 9);
337
+  tft.canvas(4, y, TFT_WIDTH - 8, 9);
328 338
   tft.set_background(COLOR_PROGRESS_BG);
329 339
   tft.add_rectangle(0, 0, TFT_WIDTH - 8, 9, COLOR_PROGRESS_FRAME);
330 340
   if (progress)
331 341
     tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress) / 100, 7, COLOR_PROGRESS_BAR);
332 342
 
343
+  y += 20;
333 344
   // status message
334
-  tft.canvas(0, 280, TFT_WIDTH, 29);
345
+  tft.canvas(0, y, TFT_WIDTH, FONT_LINE_HEIGHT - 5);
335 346
   tft.set_background(COLOR_BACKGROUND);
336 347
   tft_string.set(status_message);
337 348
   tft_string.trim();
338 349
   tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
339
-
340
-
341
-  #if ENABLED(TOUCH_SCREEN)
342
-    add_control(404, 180, menu_main, imgSettings);
343
-    TERN_(SDSUPPORT, add_control(12, 180, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
344
-  #endif
345 350
 }
346 351
 
347 352
 // Draw a static item with no left-right margin required. Centered by default.
@@ -450,9 +455,9 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu
450 455
 
451 456
 void TFT::draw_edit_screen_buttons() {
452 457
   #if ENABLED(TOUCH_SCREEN)
453
-    add_control(64, 256, DECREASE, imgDecrease);
454
-    add_control(352, 256, INCREASE, imgIncrease);
455
-    add_control(208, 256, CLICK, imgConfirm);
458
+    add_control(64, TFT_HEIGHT - 64, DECREASE, imgDecrease);
459
+    add_control(352, TFT_HEIGHT - 64, INCREASE, imgIncrease);
460
+    add_control(208, TFT_HEIGHT - 64, CLICK, imgConfirm);
456 461
   #endif
457 462
 }
458 463
 
@@ -481,8 +486,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
481 486
     tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
482 487
   }
483 488
   #if ENABLED(TOUCH_SCREEN)
484
-    add_control(88, 256, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
485
-    add_control(328, 256, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
489
+    add_control(88, TFT_HEIGHT - 64, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
490
+    add_control(328, TFT_HEIGHT - 64, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
486 491
   #endif
487 492
 }
488 493
 
@@ -541,7 +546,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
541 546
     const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
542 547
                    lpos = pos.asLogical();
543 548
 
544
-    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2 - 43, 120, 43);
549
+    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
545 550
     tft.set_background(COLOR_BACKGROUND);
546 551
     tft_string.set(X_LBL);
547 552
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@@ -549,7 +554,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
549 554
     tft_string.trim();
550 555
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
551 556
 
552
-    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2, 120, 43);
557
+    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 120, MENU_ITEM_HEIGHT);
553 558
     tft.set_background(COLOR_BACKGROUND);
554 559
     tft_string.set(Y_LBL);
555 560
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@@ -557,7 +562,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
557 562
     tft_string.trim();
558 563
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
559 564
 
560
-    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2 + 43, 120, 43);
565
+    tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 + MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
561 566
     tft.set_background(COLOR_BACKGROUND);
562 567
     tft_string.set(Z_LBL);
563 568
     tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
@@ -566,13 +571,13 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
566 571
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
567 572
 
568 573
 
569
-    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, 43);
574
+    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT);
570 575
     tft.set_background(COLOR_BACKGROUND);
571 576
     tft_string.set(ui8tostr3rj(x_plot));
572 577
     tft_string.trim();
573 578
     tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
574 579
 
575
-    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2, 48, 43);
580
+    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT);
576 581
     tft.set_background(COLOR_BACKGROUND);
577 582
     tft_string.set(ui8tostr3rj(y_plot));
578 583
     tft_string.trim();
@@ -586,7 +591,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
586 591
       add_control(GRID_OFFSET_X + CONTROL_OFFSET,                   GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET,      UBL, - ENCODER_STEPS_PER_MENU_ITEM, imgLeft);
587 592
       add_control(GRID_OFFSET_X + GRID_WIDTH - CONTROL_OFFSET - 32, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET,      UBL,   ENCODER_STEPS_PER_MENU_ITEM, imgRight);
588 593
       add_control(320, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, CLICK, imgLeveling);
589
-      add_control(224, 286, BACK, imgBack);
594
+      add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
590 595
     #endif
591 596
   }
592 597
 #endif // AUTO_BED_LEVELING_UBL
@@ -644,7 +649,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
644 649
 #endif // TOUCH_SCREEN_CALIBRATION
645 650
 
646 651
 void menu_line(const uint8_t row, uint16_t color) {
647
-  tft.canvas(0, 4 + 45 * row, TFT_WIDTH, 43);
652
+  tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT);
648 653
   tft.set_background(color);
649 654
 }
650 655
 
@@ -661,7 +666,7 @@ void menu_item(const uint8_t row, bool sel ) {
661 666
   menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
662 667
   #if ENABLED(TOUCH_SCREEN)
663 668
     const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
664
-    touch.add_control(tct, 0, 4 + 45 * row, TFT_WIDTH, 43, encoderTopLine + row);
669
+    touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
665 670
   #endif
666 671
 }
667 672
 

+ 11
- 2
Marlin/src/lcd/tft/ui_480x320.h View File

@@ -38,8 +38,17 @@ void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
38 38
 void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
39 39
 void menu_item(const uint8_t row, bool sel = false);
40 40
 
41
-#define MENU_FONT_NAME    Helvetica18
42
-#define SYMBOLS_FONT_NAME Helvetica18_symbols
41
+#if HAS_UI_480x320
42
+  #define MENU_FONT_NAME    Helvetica18
43
+  #define SYMBOLS_FONT_NAME Helvetica18_symbols
44
+  #define MENU_ITEM_HEIGHT  43
45
+  #define FONT_LINE_HEIGHT  34
46
+#elif HAS_UI_480x272
47
+  #define MENU_FONT_NAME    Helvetica14
48
+  #define SYMBOLS_FONT_NAME Helvetica14_symbols
49
+  #define MENU_ITEM_HEIGHT  36
50
+  #define FONT_LINE_HEIGHT  24
51
+#endif
43 52
 
44 53
 #define ABSOLUTE_ZERO     -273.15
45 54
 

+ 3
- 3
Marlin/src/lcd/tft_io/ssd1963.h View File

@@ -39,10 +39,10 @@
39 39
                             IF_0((TFT_ORIENTATION) & TFT_INVERT_X,    SSD1963_MADCTL_FH) | \
40 40
                             IF_0((TFT_ORIENTATION) & TFT_INVERT_Y,    SSD1963_MADCTL_FV)
41 41
 
42
-#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR
43
-  #define SSD1963_COLOR SSD1963_MADCTL_BGR
44
-#elif TFT_COLOR == TFT_COLOR_RGB
42
+#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB
45 43
   #define SSD1963_COLOR SSD1963_MADCTL_RGB
44
+#elif TFT_COLOR == TFT_COLOR_BGR
45
+  #define SSD1963_COLOR  SSD1963_MADCTL_BGR
46 46
 #endif
47 47
 
48 48
 #define SSD1963_MADCTL_DATA       (SSD1963_ORIENTATION) | (SSD1963_COLOR)

+ 34
- 11
Marlin/src/lcd/tft_io/touch_calibration.cpp View File

@@ -23,6 +23,11 @@
23 23
 
24 24
 #include "touch_calibration.h"
25 25
 
26
+#define TOUCH_CALIBRATION_MAX_RETRIES 5
27
+
28
+#define DEBUG_OUT ENABLED(DEBUG_TOUCH_CALIBRATION)
29
+#include "../../core/debug_out.h"
30
+
26 31
 TouchCalibration touch_calibration;
27 32
 
28 33
 touch_calibration_t TouchCalibration::calibration;
@@ -31,23 +36,40 @@ touch_calibration_point_t TouchCalibration::calibration_points[4];
31 36
 uint8_t TouchCalibration::failed_count;
32 37
 
33 38
 void TouchCalibration::validate_calibration() {
34
-  const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3);
35
-  const bool portrait = validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3);
39
+  #define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B)
40
+  const bool landscape = VALIDATE_PRECISION(x, TOP_LEFT, BOTTOM_LEFT)
41
+                      && VALIDATE_PRECISION(x, TOP_RIGHT, BOTTOM_RIGHT)
42
+                      && VALIDATE_PRECISION(y, TOP_LEFT, TOP_RIGHT)
43
+                      && VALIDATE_PRECISION(y, BOTTOM_LEFT, BOTTOM_RIGHT);
44
+  const bool portrait = VALIDATE_PRECISION(y, TOP_LEFT, BOTTOM_LEFT)
45
+                     && VALIDATE_PRECISION(y, TOP_RIGHT, BOTTOM_RIGHT)
46
+                     && VALIDATE_PRECISION(x, TOP_LEFT, TOP_RIGHT)
47
+                     && VALIDATE_PRECISION(x, BOTTOM_LEFT, BOTTOM_RIGHT);
48
+  #undef VALIDATE_PRECISION
36 49
 
37
-  if (landscape || portrait) {
50
+  #define CAL_PTS(N) calibration_points[CALIBRATION_##N]
51
+  if (landscape) {
52
+    calibration_state = CALIBRATION_SUCCESS;
53
+    calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x + CAL_PTS(TOP_RIGHT).raw_x - CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x);
54
+    calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y - CAL_PTS(TOP_RIGHT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y);
55
+    calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x) * calibration.x) >> 17);
56
+    calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(TOP_RIGHT).raw_y) * calibration.y) >> 17);
57
+    calibration.orientation = TOUCH_LANDSCAPE;
58
+  }
59
+  else if (portrait) {
38 60
     calibration_state = CALIBRATION_SUCCESS;
39
-    calibration.x = ((calibration_points[2].x - calibration_points[0].x) << 17) / (calibration_points[3].raw_x + calibration_points[2].raw_x - calibration_points[1].raw_x - calibration_points[0].raw_x);
40
-    calibration.y = ((calibration_points[1].y - calibration_points[0].y) << 17) / (calibration_points[3].raw_y - calibration_points[2].raw_y + calibration_points[1].raw_y - calibration_points[0].raw_y);
41
-    calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17);
42
-    calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17);
43
-    calibration.orientation = landscape ? TOUCH_LANDSCAPE : TOUCH_PORTRAIT;
61
+    calibration.x = ((CAL_PTS(TOP_RIGHT).x - CAL_PTS(TOP_LEFT).x) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_y + CAL_PTS(TOP_RIGHT).raw_y - CAL_PTS(BOTTOM_LEFT).raw_y - CAL_PTS(TOP_LEFT).raw_y);
62
+    calibration.y = ((CAL_PTS(BOTTOM_LEFT).y - CAL_PTS(TOP_LEFT).y) << 17) / (CAL_PTS(BOTTOM_RIGHT).raw_x - CAL_PTS(TOP_RIGHT).raw_x + CAL_PTS(BOTTOM_LEFT).raw_x - CAL_PTS(TOP_LEFT).raw_x);
63
+    calibration.offset_x = CAL_PTS(TOP_LEFT).x - int16_t(((CAL_PTS(TOP_LEFT).raw_y + CAL_PTS(BOTTOM_LEFT).raw_y) * calibration.x) >> 17);
64
+    calibration.offset_y = CAL_PTS(TOP_LEFT).y - int16_t(((CAL_PTS(TOP_LEFT).raw_x + CAL_PTS(TOP_RIGHT).raw_x) * calibration.y) >> 17);
65
+    calibration.orientation = TOUCH_PORTRAIT;
44 66
   }
45 67
   else {
46 68
     calibration_state = CALIBRATION_FAIL;
47 69
     calibration_reset();
48
-    // Retry up to 5 times before reporting the failure
49
-    if (need_calibration() && failed_count++ < 5) calibration_state = CALIBRATION_TOP_LEFT;
70
+    if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_TOP_LEFT;
50 71
   }
72
+  #undef CAL_PTS
51 73
 
52 74
   if (calibration_state == CALIBRATION_SUCCESS) {
53 75
     SERIAL_ECHOLNPGM("Touch screen calibration completed");
@@ -55,7 +77,7 @@ void TouchCalibration::validate_calibration() {
55 77
     SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y);
56 78
     SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x);
57 79
     SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y);
58
-    SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT");
80
+    SERIAL_ECHO_TERNARY(calibration.orientation == TOUCH_LANDSCAPE, "TOUCH_ORIENTATION ", "TOUCH_LANDSCAPE", "TOUCH_PORTRAIT", "\n");
59 81
   }
60 82
 }
61 83
 
@@ -68,6 +90,7 @@ bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) {
68 90
   if (calibration_state < CALIBRATION_SUCCESS) {
69 91
     calibration_points[calibration_state].raw_x = x;
70 92
     calibration_points[calibration_state].raw_y = y;
93
+    DEBUG_ECHOLNPAIR("TouchCalibration - State: ", calibration_state, ", x: ", calibration_points[calibration_state].x, ", raw_x: ", x, ", y: ", calibration_points[calibration_state].y, ", raw_y: ", y);
71 94
   }
72 95
 
73 96
   switch (calibration_state) {

+ 0
- 5
Marlin/src/pins/stm32f4/pins_ANET_ET4.h View File

@@ -155,11 +155,6 @@
155 155
   #define TOUCH_INT_PIN                     PB1
156 156
 #endif
157 157
 
158
-// Touchscreen calibration does not work correctly with ANET_ET5_TFT35 or ANET_ET4_TFT28
159
-#if ENABLED(TOUCH_SCREEN_CALIBRATION)
160
-  #undef TOUCH_SCREEN_CALIBRATION
161
-#endif
162
-
163 158
 #if ENABLED(ANET_ET5_TFT35)
164 159
   #ifndef TOUCH_CALIBRATION_X
165 160
     #define TOUCH_CALIBRATION_X            17125

Loading…
Cancel
Save