From 0a49ad1ccf1122f8fc9a90bf8c103aee10e1b9e4 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 11 Jun 2020 23:42:19 -0300 Subject: [PATCH] TFT 3x upscale followup (#18256) --- Marlin/src/feature/touch/xpt2046.cpp | 12 +++++++++--- .../dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp | 11 +++++++---- Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h | 1 + Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Marlin/src/feature/touch/xpt2046.cpp b/Marlin/src/feature/touch/xpt2046.cpp index f03afe71e..7f9a71860 100644 --- a/Marlin/src/feature/touch/xpt2046.cpp +++ b/Marlin/src/feature/touch/xpt2046.cpp @@ -25,9 +25,15 @@ #include "../../inc/MarlinConfig.h" #include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc. +// Touch screen resolution independent of display resolution +#define TOUCH_SCREEN_HEIGHT 240 +#define TOUCH_SCREEN_WIDTH 320 + +// Coordinates in terms of touch area #define BUTTON_AREA_TOP 175 #define BUTTON_AREA_BOT 234 -#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * 240 / (LCD_FULL_PIXEL_HEIGHT)) + +#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT)) #define TOUCHABLE_Y_HEIGHT (BUTTON_AREA_TOP - (SCREEN_START_TOP)) #ifndef TOUCH_INT_PIN @@ -92,10 +98,10 @@ uint8_t XPT2046::read_buttons() { : WITHIN(x, 242, 305) ? EN_C : 0; - if (x > LCD_FULL_PIXEL_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0; + if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0; // Column and row above BUTTON_AREA_TOP - int8_t col = x * (LCD_WIDTH) / (LCD_FULL_PIXEL_WIDTH), + int8_t col = x * (LCD_WIDTH) / (TOUCH_SCREEN_WIDTH), row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT); // Send the touch to the UI (which will simulate the encoder wheel) diff --git a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp index fdcf47bc5..63d418991 100644 --- a/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp +++ b/Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp @@ -546,12 +546,15 @@ static const uint16_t ili9341_init[] = { #define BUTTONC_X_LO (242 / 2) * (FSMC_UPSCALE) #define BUTTONC_X_HI (BUTTONC_X_LO + (FSMC_UPSCALE) * BUTTON_SIZE_X - 1) - #define BUTTON_Y_LO (184 / 2) * (FSMC_UPSCALE) + #define BUTTON_Y_LO (140 / 2) * (FSMC_UPSCALE) + 44 //184 2x, 254 3x #define BUTTON_Y_HI (BUTTON_Y_LO + (FSMC_UPSCALE) * 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(FSMC_UPSCALE)]; + //NOTE: the buffer are sized for max 32 lenght! If you need draw bigger things with this function, we need increase the buffer + if (length > BUTTON_SIZE_X) return; + for (uint16_t i = 0; i < height; i++) { uint16_t k = 0; for (uint16_t j = 0; j < length; j++) { @@ -567,7 +570,7 @@ static const uint16_t ili9341_init[] = { for (uint16_t l = 0; l < length * (FSMC_UPSCALE); l++) buffer[l + (length * (FSMC_UPSCALE) * n)] = buffer[l]; - LCD_IO_WriteSequence(buffer, COUNT(buffer)); + LCD_IO_WriteSequence(buffer, length * sq(FSMC_UPSCALE)); #else u8g_WriteSequence(u8g, dev, k << 1, (uint8_t*)buffer); u8g_WriteSequence(u8g, dev, k << 1, (uint8_t*)buffer); @@ -657,9 +660,9 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u // bottom line and buttons #if ENABLED(TOUCH_BUTTONS) - setWindow(u8g, dev, 10, 170, 309, 171); + setWindow(u8g, dev, BUTTOND_X_LO - 4, BUTTON_Y_LO - 5, BUTTONC_X_HI + BUFSIZE + 4, BUTTON_Y_LO - 4); #ifdef LCD_USE_DMA_FSMC - LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 600); + LCD_IO_WriteMultiple(TFT_DISABLED_COLOR, 600 / 2 * FSMC_UPSCALE); #else memset2(buffer, TFT_DISABLED_COLOR, 150); for (uint8_t i = 8; i--;) diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index e28cf7f2f..5dd9202d8 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -115,6 +115,7 @@ #define LCD_FULL_PIXEL_WIDTH 480 #define LCD_PIXEL_OFFSET_X 48 #define LCD_FULL_PIXEL_HEIGHT 320 + #define LCD_PIXEL_OFFSET_Y 48 #define LCD_RESET_PIN PF11 #define NO_LCD_REINIT diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 407fb7b22..176ccc867 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -120,6 +120,7 @@ #define LCD_FULL_PIXEL_WIDTH 480 #define LCD_PIXEL_OFFSET_X 48 #define LCD_FULL_PIXEL_HEIGHT 320 + #define LCD_PIXEL_OFFSET_Y 48 #define LCD_RESET_PIN PF11 #define NO_LCD_REINIT