Browse Source

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

vanilla_fb_2.0.x
Victor Oliveira 4 years ago
committed by Scott Lahteine
parent
commit
cf996949fa
  1. 1
      Marlin/Configuration.h
  2. 9
      Marlin/src/inc/Conditionals_LCD.h
  3. 3
      Marlin/src/lcd/tft/tft.h
  4. 67
      Marlin/src/lcd/tft/ui_480x320.cpp
  5. 13
      Marlin/src/lcd/tft/ui_480x320.h
  6. 6
      Marlin/src/lcd/tft_io/ssd1963.h
  7. 45
      Marlin/src/lcd/tft_io/touch_calibration.cpp
  8. 5
      Marlin/src/pins/stm32f4/pins_ANET_ET4.h

1
Marlin/Configuration.h

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

9
Marlin/src/inc/Conditionals_LCD.h

@ -1169,6 +1169,12 @@
#elif ENABLED(TFT_INTERFACE_FSMC) #elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320 #define TFT_480x320
#endif #endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x272_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x272
#endif
#endif #endif
// Fewer lines with touch buttons on-screen // Fewer lines with touch buttons on-screen
@ -1178,6 +1184,9 @@
#elif EITHER(TFT_480x320, TFT_480x320_SPI) #elif EITHER(TFT_480x320, TFT_480x320_SPI)
#define HAS_UI_480x320 1 #define HAS_UI_480x320 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x272, TFT_480x272_SPI)
#define HAS_UI_480x272 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif #endif
// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'

3
Marlin/src/lcd/tft/tft.h

@ -43,6 +43,9 @@
#elif HAS_UI_480x320 #elif HAS_UI_480x320
#define TFT_WIDTH 480 #define TFT_WIDTH 480
#define TFT_HEIGHT 320 #define TFT_HEIGHT 320
#elif HAS_UI_480x272
#define TFT_WIDTH 480
#define TFT_HEIGHT 272
#else #else
#error "Unsupported display resolution!" #error "Unsupported display resolution!"
#endif #endif

67
Marlin/src/lcd/tft/ui_480x320.cpp

@ -22,7 +22,7 @@
#include "../../inc/MarlinConfigPre.h" #include "../../inc/MarlinConfigPre.h"
#if HAS_UI_480x320 #if HAS_UI_480x320 || HAS_UI_480x272
#include "ui_480x320.h" #include "ui_480x320.h"
@ -56,9 +56,9 @@
void MarlinUI::tft_idle() { void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
if (draw_menu_navigation) { if (draw_menu_navigation) {
add_control(104, 286, PAGE_UP, imgPageUp, encoderTopLine > 0); add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
add_control(344, 286, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items); add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
add_control(224, 286, BACK, imgBack); add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
draw_menu_navigation = false; draw_menu_navigation = false;
} }
#endif #endif
@ -259,10 +259,12 @@ void MarlinUI::draw_status_screen() {
} }
} }
y += TERN(HAS_UI_480x272, 118, 128);
// coordinates // coordinates
tft.canvas(4, 132, TFT_WIDTH - 8, 34); tft.canvas(4, y, TFT_WIDTH - 8, FONT_LINE_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft.add_rectangle(0, 0, TFT_WIDTH - 8, 34, COLOR_AXIS_HOMED); tft.add_rectangle(0, 0, TFT_WIDTH - 8, FONT_LINE_HEIGHT, COLOR_AXIS_HOMED);
tft.add_text( 16, 3, COLOR_AXIS_HOMED , "X"); tft.add_text( 16, 3, COLOR_AXIS_HOMED , "X");
tft.add_text(192, 3, COLOR_AXIS_HOMED , "Y"); tft.add_text(192, 3, COLOR_AXIS_HOMED , "Y");
@ -290,10 +292,11 @@ void MarlinUI::draw_status_screen() {
offset -= tft_string.width(); offset -= tft_string.width();
} }
tft.add_text(455 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string); tft.add_text(455 - tft_string.width() - offset, 3, not_homed ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, 132, TFT_WIDTH - 8, 34)); TERN_(TOUCH_SCREEN, touch.add_control(MOVE_AXIS, 4, y, TFT_WIDTH - 8, FONT_LINE_HEIGHT));
y += TERN(HAS_UI_480x272, 38, 48);
// feed rate // feed rate
tft.canvas(96, 180, 100, 32); tft.canvas(96, y, 100, 32);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED; uint16_t color = feedrate_percentage == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
tft.add_image(0, 0, imgFeedRate, color); tft.add_image(0, 0, imgFeedRate, color);
@ -303,7 +306,7 @@ void MarlinUI::draw_status_screen() {
TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32)); TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32));
// flow rate // flow rate
tft.canvas(284, 180, 100, 32); tft.canvas(284, y, 100, 32);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED; color = planner.flow_percentage[0] == 100 ? COLOR_RATE_100 : COLOR_RATE_ALTERED;
tft.add_image(0, 0, imgFlowRate, color); tft.add_image(0, 0, imgFlowRate, color);
@ -312,36 +315,38 @@ void MarlinUI::draw_status_screen() {
tft.add_text(36, 1, color , tft_string); tft.add_text(36, 1, color , tft_string);
TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder)); TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder));
#if ENABLED(TOUCH_SCREEN)
add_control(404, y, menu_main, imgSettings);
TERN_(SDSUPPORT, add_control(12, y, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
#endif
y += TERN(HAS_UI_480x272, 36, 44);
// print duration // print duration
char buffer[14]; char buffer[14];
duration_t elapsed = print_job_timer.duration(); duration_t elapsed = print_job_timer.duration();
elapsed.toDigital(buffer); elapsed.toDigital(buffer);
tft.canvas((TFT_WIDTH - 128) / 2, 224, 128, 29); tft.canvas((TFT_WIDTH - 128) / 2, y, 128, 29);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(buffer); tft_string.set(buffer);
tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string); tft.add_text(tft_string.center(128), 0, COLOR_PRINT_TIME, tft_string);
y += TERN(HAS_UI_480x272, 28, 36);
// progress bar // progress bar
const uint8_t progress = ui.get_progress_percent(); const uint8_t progress = ui.get_progress_percent();
tft.canvas(4, 260, TFT_WIDTH - 8, 9); tft.canvas(4, y, TFT_WIDTH - 8, 9);
tft.set_background(COLOR_PROGRESS_BG); tft.set_background(COLOR_PROGRESS_BG);
tft.add_rectangle(0, 0, TFT_WIDTH - 8, 9, COLOR_PROGRESS_FRAME); tft.add_rectangle(0, 0, TFT_WIDTH - 8, 9, COLOR_PROGRESS_FRAME);
if (progress) if (progress)
tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress) / 100, 7, COLOR_PROGRESS_BAR); tft.add_bar(1, 1, ((TFT_WIDTH - 10) * progress) / 100, 7, COLOR_PROGRESS_BAR);
y += 20;
// status message // status message
tft.canvas(0, 280, TFT_WIDTH, 29); tft.canvas(0, y, TFT_WIDTH, FONT_LINE_HEIGHT - 5);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(status_message); tft_string.set(status_message);
tft_string.trim(); tft_string.trim();
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string); tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
#if ENABLED(TOUCH_SCREEN)
add_control(404, 180, menu_main, imgSettings);
TERN_(SDSUPPORT, add_control(12, 180, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
#endif
} }
// Draw a static item with no left-right margin required. Centered by default. // 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
void TFT::draw_edit_screen_buttons() { void TFT::draw_edit_screen_buttons() {
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
add_control(64, 256, DECREASE, imgDecrease); add_control(64, TFT_HEIGHT - 64, DECREASE, imgDecrease);
add_control(352, 256, INCREASE, imgIncrease); add_control(352, TFT_HEIGHT - 64, INCREASE, imgIncrease);
add_control(208, 256, CLICK, imgConfirm); add_control(208, TFT_HEIGHT - 64, CLICK, imgConfirm);
#endif #endif
} }
@ -481,8 +486,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
} }
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
add_control(88, 256, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL); add_control(88, TFT_HEIGHT - 64, CANCEL, imgCancel, true, yesno ? HALF(COLOR_CONTROL_CANCEL) : COLOR_CONTROL_CANCEL);
add_control(328, 256, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM)); add_control(328, TFT_HEIGHT - 64, CONFIRM, imgConfirm, true, yesno ? COLOR_CONTROL_CONFIRM : HALF(COLOR_CONTROL_CONFIRM));
#endif #endif
} }
@ -541,7 +546,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) }, const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
lpos = pos.asLogical(); lpos = pos.asLogical();
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2 - 43, 120, 43); tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 - MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(X_LBL); tft_string.set(X_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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
tft_string.trim(); tft_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2, 120, 43); tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 120, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(Y_LBL); tft_string.set(Y_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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
tft_string.trim(); tft_string.trim();
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2 + 43, 120, 43); tft.canvas(320, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2 + MENU_ITEM_HEIGHT, 120, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(Z_LBL); tft_string.set(Z_LBL);
tft.add_text(0, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); 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
tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, 43); tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(x_plot)); tft_string.set(ui8tostr3rj(x_plot));
tft_string.trim(); tft_string.trim();
tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - 43) / 2, 48, 43); tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT);
tft.set_background(COLOR_BACKGROUND); tft.set_background(COLOR_BACKGROUND);
tft_string.set(ui8tostr3rj(y_plot)); tft_string.set(ui8tostr3rj(y_plot));
tft_string.trim(); tft_string.trim();
@ -586,7 +591,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
add_control(GRID_OFFSET_X + CONTROL_OFFSET, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, - ENCODER_STEPS_PER_MENU_ITEM, imgLeft); add_control(GRID_OFFSET_X + CONTROL_OFFSET, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, - ENCODER_STEPS_PER_MENU_ITEM, imgLeft);
add_control(GRID_OFFSET_X + GRID_WIDTH - CONTROL_OFFSET - 32, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, ENCODER_STEPS_PER_MENU_ITEM, imgRight); add_control(GRID_OFFSET_X + GRID_WIDTH - CONTROL_OFFSET - 32, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, UBL, ENCODER_STEPS_PER_MENU_ITEM, imgRight);
add_control(320, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, CLICK, imgLeveling); add_control(320, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET, CLICK, imgLeveling);
add_control(224, 286, BACK, imgBack); add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
#endif #endif
} }
#endif // AUTO_BED_LEVELING_UBL #endif // AUTO_BED_LEVELING_UBL
@ -644,7 +649,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
#endif // TOUCH_SCREEN_CALIBRATION #endif // TOUCH_SCREEN_CALIBRATION
void menu_line(const uint8_t row, uint16_t color) { void menu_line(const uint8_t row, uint16_t color) {
tft.canvas(0, 4 + 45 * row, TFT_WIDTH, 43); tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT);
tft.set_background(color); tft.set_background(color);
} }
@ -661,7 +666,7 @@ void menu_item(const uint8_t row, bool sel ) {
menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
#if ENABLED(TOUCH_SCREEN) #if ENABLED(TOUCH_SCREEN)
const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
touch.add_control(tct, 0, 4 + 45 * row, TFT_WIDTH, 43, encoderTopLine + row); touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
#endif #endif
} }

13
Marlin/src/lcd/tft/ui_480x320.h

@ -38,8 +38,17 @@ void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND); void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
void menu_item(const uint8_t row, bool sel = false); void menu_item(const uint8_t row, bool sel = false);
#define MENU_FONT_NAME Helvetica18 #if HAS_UI_480x320
#define SYMBOLS_FONT_NAME Helvetica18_symbols #define MENU_FONT_NAME Helvetica18
#define SYMBOLS_FONT_NAME Helvetica18_symbols
#define MENU_ITEM_HEIGHT 43
#define FONT_LINE_HEIGHT 34
#elif HAS_UI_480x272
#define MENU_FONT_NAME Helvetica14
#define SYMBOLS_FONT_NAME Helvetica14_symbols
#define MENU_ITEM_HEIGHT 36
#define FONT_LINE_HEIGHT 24
#endif
#define ABSOLUTE_ZERO -273.15 #define ABSOLUTE_ZERO -273.15

6
Marlin/src/lcd/tft_io/ssd1963.h

@ -39,10 +39,10 @@
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \ IF_0((TFT_ORIENTATION) & TFT_INVERT_X, SSD1963_MADCTL_FH) | \
IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV) IF_0((TFT_ORIENTATION) & TFT_INVERT_Y, SSD1963_MADCTL_FV)
#if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_BGR #if !defined(TFT_COLOR) || TFT_COLOR == TFT_COLOR_RGB
#define SSD1963_COLOR SSD1963_MADCTL_BGR
#elif TFT_COLOR == TFT_COLOR_RGB
#define SSD1963_COLOR SSD1963_MADCTL_RGB #define SSD1963_COLOR SSD1963_MADCTL_RGB
#elif TFT_COLOR == TFT_COLOR_BGR
#define SSD1963_COLOR SSD1963_MADCTL_BGR
#endif #endif
#define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR) #define SSD1963_MADCTL_DATA (SSD1963_ORIENTATION) | (SSD1963_COLOR)

45
Marlin/src/lcd/tft_io/touch_calibration.cpp

@ -23,6 +23,11 @@
#include "touch_calibration.h" #include "touch_calibration.h"
#define TOUCH_CALIBRATION_MAX_RETRIES 5
#define DEBUG_OUT ENABLED(DEBUG_TOUCH_CALIBRATION)
#include "../../core/debug_out.h"
TouchCalibration touch_calibration; TouchCalibration touch_calibration;
touch_calibration_t TouchCalibration::calibration; touch_calibration_t TouchCalibration::calibration;
@ -31,23 +36,40 @@ touch_calibration_point_t TouchCalibration::calibration_points[4];
uint8_t TouchCalibration::failed_count; uint8_t TouchCalibration::failed_count;
void TouchCalibration::validate_calibration() { void TouchCalibration::validate_calibration() {
const bool landscape = validate_precision_x(0, 1) && validate_precision_x(2, 3) && validate_precision_y(0, 2) && validate_precision_y(1, 3); #define VALIDATE_PRECISION(XY, A, B) validate_precision_##XY(CALIBRATION_##A, CALIBRATION_##B)
const bool portrait = validate_precision_y(0, 1) && validate_precision_y(2, 3) && validate_precision_x(0, 2) && validate_precision_x(1, 3); const bool landscape = VALIDATE_PRECISION(x, TOP_LEFT, BOTTOM_LEFT)
&& VALIDATE_PRECISION(x, TOP_RIGHT, BOTTOM_RIGHT)
&& VALIDATE_PRECISION(y, TOP_LEFT, TOP_RIGHT)
&& VALIDATE_PRECISION(y, BOTTOM_LEFT, BOTTOM_RIGHT);
const bool portrait = VALIDATE_PRECISION(y, TOP_LEFT, BOTTOM_LEFT)
&& VALIDATE_PRECISION(y, TOP_RIGHT, BOTTOM_RIGHT)
&& VALIDATE_PRECISION(x, TOP_LEFT, TOP_RIGHT)
&& VALIDATE_PRECISION(x, BOTTOM_LEFT, BOTTOM_RIGHT);
#undef VALIDATE_PRECISION
if (landscape || portrait) { #define CAL_PTS(N) calibration_points[CALIBRATION_##N]
if (landscape) {
calibration_state = CALIBRATION_SUCCESS;
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);
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);
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);
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);
calibration.orientation = TOUCH_LANDSCAPE;
}
else if (portrait) {
calibration_state = CALIBRATION_SUCCESS; calibration_state = CALIBRATION_SUCCESS;
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); 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);
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); 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);
calibration.offset_x = calibration_points[0].x - int16_t(((calibration_points[0].raw_x + calibration_points[1].raw_x) * calibration.x) >> 17); 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);
calibration.offset_y = calibration_points[0].y - int16_t(((calibration_points[0].raw_y + calibration_points[2].raw_y) * calibration.y) >> 17); 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);
calibration.orientation = landscape ? TOUCH_LANDSCAPE : TOUCH_PORTRAIT; calibration.orientation = TOUCH_PORTRAIT;
} }
else { else {
calibration_state = CALIBRATION_FAIL; calibration_state = CALIBRATION_FAIL;
calibration_reset(); calibration_reset();
// Retry up to 5 times before reporting the failure if (need_calibration() && failed_count++ < TOUCH_CALIBRATION_MAX_RETRIES) calibration_state = CALIBRATION_TOP_LEFT;
if (need_calibration() && failed_count++ < 5) calibration_state = CALIBRATION_TOP_LEFT;
} }
#undef CAL_PTS
if (calibration_state == CALIBRATION_SUCCESS) { if (calibration_state == CALIBRATION_SUCCESS) {
SERIAL_ECHOLNPGM("Touch screen calibration completed"); SERIAL_ECHOLNPGM("Touch screen calibration completed");
@ -55,7 +77,7 @@ void TouchCalibration::validate_calibration() {
SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y); SERIAL_ECHOLNPAIR("TOUCH_CALIBRATION_Y ", calibration.y);
SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x); SERIAL_ECHOLNPAIR("TOUCH_OFFSET_X ", calibration.offset_x);
SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y); SERIAL_ECHOLNPAIR("TOUCH_OFFSET_Y ", calibration.offset_y);
SERIAL_ECHOPGM("TOUCH_ORIENTATION "); if (calibration.orientation == TOUCH_LANDSCAPE) SERIAL_ECHOLNPGM("TOUCH_LANDSCAPE"); else SERIAL_ECHOLNPGM("TOUCH_PORTRAIT"); SERIAL_ECHO_TERNARY(calibration.orientation == TOUCH_LANDSCAPE, "TOUCH_ORIENTATION ", "TOUCH_LANDSCAPE", "TOUCH_PORTRAIT", "\n");
} }
} }
@ -68,6 +90,7 @@ bool TouchCalibration::handleTouch(uint16_t x, uint16_t y) {
if (calibration_state < CALIBRATION_SUCCESS) { if (calibration_state < CALIBRATION_SUCCESS) {
calibration_points[calibration_state].raw_x = x; calibration_points[calibration_state].raw_x = x;
calibration_points[calibration_state].raw_y = y; calibration_points[calibration_state].raw_y = y;
DEBUG_ECHOLNPAIR("TouchCalibration - State: ", calibration_state, ", x: ", calibration_points[calibration_state].x, ", raw_x: ", x, ", y: ", calibration_points[calibration_state].y, ", raw_y: ", y);
} }
switch (calibration_state) { switch (calibration_state) {

5
Marlin/src/pins/stm32f4/pins_ANET_ET4.h

@ -155,11 +155,6 @@
#define TOUCH_INT_PIN PB1 #define TOUCH_INT_PIN PB1
#endif #endif
// Touchscreen calibration does not work correctly with ANET_ET5_TFT35 or ANET_ET4_TFT28
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#undef TOUCH_SCREEN_CALIBRATION
#endif
#if ENABLED(ANET_ET5_TFT35) #if ENABLED(ANET_ET5_TFT35)
#ifndef TOUCH_CALIBRATION_X #ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 17125 #define TOUCH_CALIBRATION_X 17125

Loading…
Cancel
Save