From e9053654a73830bb8d242784bb864b3305633636 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Tue, 3 Nov 2020 20:25:33 -0300 Subject: [PATCH] Better Classic UI touch resolution (#20004) --- .../dogm/u8g_dev_tft_upscale_from_128x64.cpp | 35 ++-------- Marlin/src/lcd/touch/touch_buttons.cpp | 64 +++++-------------- Marlin/src/lcd/touch/touch_buttons.h | 30 +++++++++ Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 15 +---- Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 15 +---- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h | 17 +---- .../src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h | 15 +---- Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h | 15 +---- 8 files changed, 59 insertions(+), 147 deletions(-) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp index 106c18cf0..8698dbb01 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp @@ -73,10 +73,8 @@ TFT_IO tftio; #define HEIGHT LCD_PIXEL_HEIGHT #define PAGE_HEIGHT 8 -#include "../scaled_tft.h" +#include "../touch/touch_buttons.h" -#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE)) -#define UPSCALE(A,M) (UPSCALE0(M) + (A)) #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1) #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1) @@ -276,29 +274,10 @@ static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, B01111111,B11111111,B11111111,B11111110, }; - #define BUTTON_SIZE_X 32 - #define BUTTON_SIZE_Y 20 - - // 14, 90, 166, 242, 185 are the original values upscaled 2x. - #define BUTTOND_X_LO UPSCALE0(14 / 2) - #define BUTTOND_X_HI (UPSCALE(BUTTOND_X_LO, BUTTON_SIZE_X) - 1) - - #define BUTTONA_X_LO UPSCALE0(90 / 2) - #define BUTTONA_X_HI (UPSCALE(BUTTONA_X_LO, BUTTON_SIZE_X) - 1) - - #define BUTTONB_X_LO UPSCALE0(166 / 2) - #define BUTTONB_X_HI (UPSCALE(BUTTONB_X_LO, BUTTON_SIZE_X) - 1) - - #define BUTTONC_X_LO UPSCALE0(242 / 2) - #define BUTTONC_X_HI (UPSCALE(BUTTONC_X_LO, BUTTON_SIZE_X) - 1) - - #define BUTTON_Y_LO UPSCALE0(140 / 2) + 44 // 184 2x, 254 3x - #define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1) - void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) { - uint16_t buffer[BUTTON_SIZE_X * sq(GRAPHICAL_TFT_UPSCALE)]; + uint16_t buffer[BUTTON_WIDTH * sq(GRAPHICAL_TFT_UPSCALE)]; - if (length > BUTTON_SIZE_X) return; + if (length > BUTTON_WIDTH) return; for (uint16_t i = 0; i < height; i++) { uint16_t k = 0; @@ -368,16 +347,16 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u // Bottom buttons #if HAS_TOUCH_XPT2046 setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI); - drawImage(buttonD, u8g, dev, 32, 20, TFT_BTCANCEL_COLOR); + drawImage(buttonD, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTCANCEL_COLOR); setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI); - drawImage(buttonA, u8g, dev, 32, 20, TFT_BTARROWS_COLOR); + drawImage(buttonA, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI); - drawImage(buttonB, u8g, dev, 32, 20, TFT_BTARROWS_COLOR); + drawImage(buttonB, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR); setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI); - drawImage(buttonC, u8g, dev, 32, 20, TFT_BTOKMENU_COLOR); + drawImage(buttonC, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTOKMENU_COLOR); #endif // HAS_TOUCH_XPT2046 return 0; diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index eeb22aae6..4e9848696 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -29,45 +29,13 @@ XPT2046 touchIO; #include "../../lcd/marlinui.h" // For EN_C bit mask -/** - * Draw and Touch processing - * - * LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution. - * TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution. - * TFT_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution. - * - * - All native (u8g) drawing is done in LCD_PIXEL_* (128x64) - * - The DOGM pixels are is upscaled 2-3x (as needed) for display. - * - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to - * click and scroll-wheel events (emulating of a common DOGM display). - * - * TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made - * and originally calibrated for 320x240. If you decide to change the resolution of the touch code, - * new calibration values will be needed. - * - * The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a - * fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to - * navigate and select menu items. Both regions are touchable. - * - * The Marlin screen touchable area starts at TFT_PIXEL_OFFSET_X/Y (translated to SCREEN_PCT_LEFT/TOP) - * and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_PCT_WIDTH/HEIGHT). - */ +#define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X +#define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y +#define DOGM_AREA_WIDTH (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH) +#define DOGM_AREA_HEIGHT (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT) -// Touch sensor resolution independent of display resolution -#define TOUCH_SENSOR_WIDTH 320 -#define TOUCH_SENSOR_HEIGHT 240 - -#define SCREEN_PCT_WIDE(X) ((X) * (TOUCH_SENSOR_WIDTH) / (TFT_WIDTH)) -#define SCREEN_PCT_HIGH(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (TFT_HEIGHT)) - -#define SCREEN_PCT_LEFT SCREEN_PCT_WIDE(TFT_PIXEL_OFFSET_X) -#define SCREEN_PCT_TOP SCREEN_PCT_HIGH(TFT_PIXEL_OFFSET_Y) -#define SCREEN_PCT_WIDTH SCREEN_PCT_WIDE((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH)) -#define SCREEN_PCT_HEIGHT SCREEN_PCT_HIGH((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT)) - -// Coordinates in terms of 240-unit-tall touch area -#define BUTTON_AREA_TOP 175 -#define BUTTON_AREA_BOT 234 +#define BUTTON_AREA_TOP BUTTON_Y_LO +#define BUTTON_AREA_BOT BUTTON_Y_HI TouchButtons touch; @@ -83,25 +51,25 @@ uint8_t TouchButtons::read_buttons() { y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; #if (TFT_ROTATION & TFT_ROTATE_180) - x = TOUCH_SENSOR_WIDTH - x; - y = TOUCH_SENSOR_HEIGHT - y; + x = TFT_WIDTH - x; + y = TFT_HEIGHT - y; #endif // 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 + return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D + : WITHIN(x, BUTTONA_X_LO, BUTTONA_X_HI) ? EN_A + : WITHIN(x, BUTTONB_X_LO, BUTTONB_X_HI) ? EN_B + : WITHIN(x, BUTTONC_X_LO, BUTTONC_X_HI) ? EN_C : 0; - if ( !WITHIN(x, SCREEN_PCT_LEFT, SCREEN_PCT_LEFT + SCREEN_PCT_WIDTH) - || !WITHIN(y, SCREEN_PCT_TOP, SCREEN_PCT_TOP + SCREEN_PCT_HEIGHT) + if ( !WITHIN(x, DOGM_AREA_LEFT, DOGM_AREA_LEFT + DOGM_AREA_WIDTH) + || !WITHIN(y, DOGM_AREA_TOP, DOGM_AREA_TOP + DOGM_AREA_HEIGHT) ) return 0; // Column and row above BUTTON_AREA_TOP - int8_t col = (x - (SCREEN_PCT_LEFT)) * (LCD_WIDTH) / (SCREEN_PCT_WIDTH), - row = (y - (SCREEN_PCT_TOP)) * (LCD_HEIGHT) / (SCREEN_PCT_HEIGHT); + int8_t col = (x - (DOGM_AREA_LEFT)) * (LCD_WIDTH) / (DOGM_AREA_WIDTH), + row = (y - (DOGM_AREA_TOP)) * (LCD_HEIGHT) / (DOGM_AREA_HEIGHT); // Send the touch to the UI (which will simulate the encoder wheel) MarlinUI::screen_click(row, col, x, y); diff --git a/Marlin/src/lcd/touch/touch_buttons.h b/Marlin/src/lcd/touch/touch_buttons.h index 451e5a5a3..bf05d2bae 100644 --- a/Marlin/src/lcd/touch/touch_buttons.h +++ b/Marlin/src/lcd/touch/touch_buttons.h @@ -20,6 +20,36 @@ #include +#include "../../inc/MarlinConfig.h" +#include "../scaled_tft.h" + +#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE)) +#define UPSCALE(A,M) (UPSCALE0(M) + (A)) + +#define BUTTON_DRAW_WIDTH 32 +#define BUTTON_DRAW_HEIGHT 20 + +#define BUTTON_WIDTH UPSCALE0(BUTTON_DRAW_WIDTH) +#define BUTTON_HEIGHT UPSCALE0(BUTTON_DRAW_HEIGHT) + +// calc the space between buttons +#define BUTTON_SPACING (((TFT_WIDTH) - (BUTTON_WIDTH * 4)) / 5) + +#define BUTTOND_X_LO BUTTON_SPACING +#define BUTTOND_X_HI BUTTOND_X_LO + BUTTON_WIDTH - 1 + +#define BUTTONA_X_LO BUTTOND_X_HI + BUTTON_SPACING +#define BUTTONA_X_HI BUTTONA_X_LO + BUTTON_WIDTH - 1 + +#define BUTTONB_X_LO BUTTONA_X_HI + BUTTON_SPACING +#define BUTTONB_X_HI BUTTONB_X_LO + BUTTON_WIDTH - 1 + +#define BUTTONC_X_LO BUTTONB_X_HI + BUTTON_SPACING +#define BUTTONC_X_HI BUTTONC_X_LO + BUTTON_WIDTH - 1 + +#define BUTTON_Y_HI (TFT_HEIGHT) - (BUTTON_SPACING / 2) +#define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT + class TouchButtons { public: static void init(); diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index d89cfc6da..181872737 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -155,7 +155,7 @@ #endif // XPT2046 Touch Screen calibration -#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) +#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -168,19 +168,6 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12316 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8981 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 340 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -20 - #endif #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 262a9a241..1d6e6b398 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -170,7 +170,7 @@ #endif // XPT2046 Touch Screen calibration -#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) +#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -183,19 +183,6 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12316 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8981 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 340 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -20 - #endif #endif // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h index ff381b375..5c3dfc2ad 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h @@ -198,7 +198,7 @@ #endif // XPT2046 Touch Screen calibration -#if EITHER(HAS_TFT_LVGL_UI_FSMC, TFT_480x320) +#if ANY(HAS_TFT_LVGL_UI_FSMC, TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_480x320) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION 17880 #endif @@ -211,20 +211,7 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET 349 #endif -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION 12149 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION -8746 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET -35 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET 256 - #endif -#elif ENABLED(TFT_320x240) +#elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -12246 #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h index 0630c0f3c..e009d34d9 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h @@ -284,7 +284,7 @@ #endif // XPT2046 Touch Screen calibration -#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI) +#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17253 #endif @@ -297,19 +297,6 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -24 #endif -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -11386 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8684 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 339 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -18 - #endif #endif #if HAS_WIRED_LCD && !HAS_SPI_TFT diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index 818dbb5f7..8314858d1 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -137,7 +137,7 @@ #endif // XPT2046 Touch Screen calibration -#if ENABLED(TFT_COLOR_UI) || ENABLED(TFT_LVGL_UI) +#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) #ifndef XPT2046_X_CALIBRATION #define XPT2046_X_CALIBRATION -17181 #endif @@ -150,19 +150,6 @@ #ifndef XPT2046_Y_OFFSET #define XPT2046_Y_OFFSET -9 #endif -#elif ENABLED(TFT_CLASSIC_UI) - #ifndef XPT2046_X_CALIBRATION - #define XPT2046_X_CALIBRATION -12316 - #endif - #ifndef XPT2046_Y_CALIBRATION - #define XPT2046_Y_CALIBRATION 8981 - #endif - #ifndef XPT2046_X_OFFSET - #define XPT2046_X_OFFSET 340 - #endif - #ifndef XPT2046_Y_OFFSET - #define XPT2046_Y_OFFSET -20 - #endif #endif #if NEED_TOUCH_PINS