Better Classic UI touch resolution (#20004)

This commit is contained in:
Victor Oliveira 2020-11-03 20:25:33 -03:00 committed by Scott Lahteine
parent 65383dd616
commit 930aad6d31
8 changed files with 59 additions and 147 deletions

View file

@ -73,10 +73,8 @@ TFT_IO tftio;
#define HEIGHT LCD_PIXEL_HEIGHT #define HEIGHT LCD_PIXEL_HEIGHT
#define PAGE_HEIGHT 8 #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 X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
#define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 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, 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) { 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++) { for (uint16_t i = 0; i < height; i++) {
uint16_t k = 0; 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 // Bottom buttons
#if HAS_TOUCH_XPT2046 #if HAS_TOUCH_XPT2046
setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI); 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); 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); 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); 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 #endif // HAS_TOUCH_XPT2046
return 0; return 0;

View file

@ -29,45 +29,13 @@ XPT2046 touchIO;
#include "../../lcd/marlinui.h" // For EN_C bit mask #include "../../lcd/marlinui.h" // For EN_C bit mask
/** #define DOGM_AREA_LEFT TFT_PIXEL_OFFSET_X
* Draw and Touch processing #define DOGM_AREA_TOP TFT_PIXEL_OFFSET_Y
* #define DOGM_AREA_WIDTH (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH)
* LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution. #define DOGM_AREA_HEIGHT (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT)
* 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).
*/
// Touch sensor resolution independent of display resolution #define BUTTON_AREA_TOP BUTTON_Y_LO
#define TOUCH_SENSOR_WIDTH 320 #define BUTTON_AREA_BOT BUTTON_Y_HI
#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
TouchButtons touch; TouchButtons touch;
@ -83,25 +51,25 @@ uint8_t TouchButtons::read_buttons() {
y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET; y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
#if (TFT_ROTATION & TFT_ROTATE_180) #if (TFT_ROTATION & TFT_ROTATE_180)
x = TOUCH_SENSOR_WIDTH - x; x = TFT_WIDTH - x;
y = TOUCH_SENSOR_HEIGHT - y; y = TFT_HEIGHT - y;
#endif #endif
// Touch within the button area simulates an encoder button // Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT) if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, 14, 77) ? EN_D return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D
: WITHIN(x, 90, 153) ? EN_A : WITHIN(x, BUTTONA_X_LO, BUTTONA_X_HI) ? EN_A
: WITHIN(x, 166, 229) ? EN_B : WITHIN(x, BUTTONB_X_LO, BUTTONB_X_HI) ? EN_B
: WITHIN(x, 242, 305) ? EN_C : WITHIN(x, BUTTONC_X_LO, BUTTONC_X_HI) ? EN_C
: 0; : 0;
if ( !WITHIN(x, SCREEN_PCT_LEFT, SCREEN_PCT_LEFT + SCREEN_PCT_WIDTH) if ( !WITHIN(x, DOGM_AREA_LEFT, DOGM_AREA_LEFT + DOGM_AREA_WIDTH)
|| !WITHIN(y, SCREEN_PCT_TOP, SCREEN_PCT_TOP + SCREEN_PCT_HEIGHT) || !WITHIN(y, DOGM_AREA_TOP, DOGM_AREA_TOP + DOGM_AREA_HEIGHT)
) return 0; ) return 0;
// Column and row above BUTTON_AREA_TOP // Column and row above BUTTON_AREA_TOP
int8_t col = (x - (SCREEN_PCT_LEFT)) * (LCD_WIDTH) / (SCREEN_PCT_WIDTH), int8_t col = (x - (DOGM_AREA_LEFT)) * (LCD_WIDTH) / (DOGM_AREA_WIDTH),
row = (y - (SCREEN_PCT_TOP)) * (LCD_HEIGHT) / (SCREEN_PCT_HEIGHT); row = (y - (DOGM_AREA_TOP)) * (LCD_HEIGHT) / (DOGM_AREA_HEIGHT);
// Send the touch to the UI (which will simulate the encoder wheel) // Send the touch to the UI (which will simulate the encoder wheel)
MarlinUI::screen_click(row, col, x, y); MarlinUI::screen_click(row, col, x, y);

View file

@ -20,6 +20,36 @@
#include <stdint.h> #include <stdint.h>
#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 { class TouchButtons {
public: public:
static void init(); static void init();

View file

@ -155,7 +155,7 @@
#endif #endif
// XPT2046 Touch Screen calibration // 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 #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17181 #define XPT2046_X_CALIBRATION -17181
#endif #endif
@ -168,19 +168,6 @@
#ifndef XPT2046_Y_OFFSET #ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -9 #define XPT2046_Y_OFFSET -9
#endif #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 #endif
// SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

View file

@ -170,7 +170,7 @@
#endif #endif
// XPT2046 Touch Screen calibration // 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 #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17181 #define XPT2046_X_CALIBRATION -17181
#endif #endif
@ -183,19 +183,6 @@
#ifndef XPT2046_Y_OFFSET #ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -9 #define XPT2046_Y_OFFSET -9
#endif #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 #endif
// SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

View file

@ -198,7 +198,7 @@
#endif #endif
// XPT2046 Touch Screen calibration // 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 #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION 17880 #define XPT2046_X_CALIBRATION 17880
#endif #endif
@ -211,20 +211,7 @@
#ifndef XPT2046_Y_OFFSET #ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET 349 #define XPT2046_Y_OFFSET 349
#endif #endif
#elif ENABLED(TFT_CLASSIC_UI) #elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240)
#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)
#ifndef XPT2046_X_CALIBRATION #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -12246 #define XPT2046_X_CALIBRATION -12246
#endif #endif

View file

@ -284,7 +284,7 @@
#endif #endif
// XPT2046 Touch Screen calibration // 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 #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17253 #define XPT2046_X_CALIBRATION -17253
#endif #endif
@ -297,19 +297,6 @@
#ifndef XPT2046_Y_OFFSET #ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -24 #define XPT2046_Y_OFFSET -24
#endif #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 #endif
#if HAS_WIRED_LCD && !HAS_SPI_TFT #if HAS_WIRED_LCD && !HAS_SPI_TFT

View file

@ -137,7 +137,7 @@
#endif #endif
// XPT2046 Touch Screen calibration // 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 #ifndef XPT2046_X_CALIBRATION
#define XPT2046_X_CALIBRATION -17181 #define XPT2046_X_CALIBRATION -17181
#endif #endif
@ -150,19 +150,6 @@
#ifndef XPT2046_Y_OFFSET #ifndef XPT2046_Y_OFFSET
#define XPT2046_Y_OFFSET -9 #define XPT2046_Y_OFFSET -9
#endif #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 #endif
#if NEED_TOUCH_PINS #if NEED_TOUCH_PINS