Clean up TFT / Touch code (#18296)
This commit is contained in:
parent
884e2146a1
commit
6d571a547c
@ -25,6 +25,29 @@
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
|
||||
|
||||
/*
|
||||
* Draw and Touch processing
|
||||
*
|
||||
* LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
|
||||
* TOUCH_SCREEN_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
|
||||
* LCD_FULL_PIXEL_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_SCREEN_* 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 LCD_PIXEL_OFFSET_X/Y (translated to SCREEN_START_LEFT/TOP)
|
||||
* and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_WIDTH/HEIGHT).
|
||||
*/
|
||||
// Touch screen resolution independent of display resolution
|
||||
#define TOUCH_SCREEN_HEIGHT 240
|
||||
#define TOUCH_SCREEN_WIDTH 320
|
||||
@ -33,8 +56,13 @@
|
||||
#define BUTTON_AREA_TOP 175
|
||||
#define BUTTON_AREA_BOT 234
|
||||
|
||||
#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))
|
||||
#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
|
||||
#define SCREEN_START_LEFT ((LCD_PIXEL_OFFSET_X) * (TOUCH_SCREEN_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
|
||||
#define SCREEN_HEIGHT ((LCD_PIXEL_HEIGHT * FSMC_UPSCALE) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
|
||||
#define SCREEN_WIDTH ((LCD_PIXEL_WIDTH * FSMC_UPSCALE) * (TOUCH_SCREEN_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
|
||||
|
||||
#define TOUCHABLE_Y_HEIGHT SCREEN_HEIGHT
|
||||
#define TOUCHABLE_X_WIDTH SCREEN_WIDTH
|
||||
|
||||
#ifndef TOUCH_INT_PIN
|
||||
#define TOUCH_INT_PIN -1
|
||||
@ -98,10 +126,10 @@ uint8_t XPT2046::read_buttons() {
|
||||
: WITHIN(x, 242, 305) ? EN_C
|
||||
: 0;
|
||||
|
||||
if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0;
|
||||
if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 0;
|
||||
|
||||
// Column and row above BUTTON_AREA_TOP
|
||||
int8_t col = x * (LCD_WIDTH) / (TOUCH_SCREEN_WIDTH),
|
||||
int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
|
||||
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
|
||||
|
||||
// Send the touch to the UI (which will simulate the encoder wheel)
|
||||
|
@ -73,10 +73,6 @@
|
||||
extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
|
||||
#endif
|
||||
|
||||
#ifndef FSMC_UPSCALE
|
||||
#define FSMC_UPSCALE 2
|
||||
#endif
|
||||
|
||||
#define WIDTH LCD_PIXEL_WIDTH
|
||||
#define HEIGHT LCD_PIXEL_HEIGHT
|
||||
#define PAGE_HEIGHT 8
|
||||
|
@ -254,4 +254,8 @@
|
||||
#define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
|
||||
#define INFO_FONT_WIDTH 6
|
||||
|
||||
#ifndef FSMC_UPSCALE
|
||||
#define FSMC_UPSCALE 2
|
||||
#endif
|
||||
|
||||
extern U8G_CLASS u8g;
|
||||
|
@ -1455,7 +1455,7 @@ void MarlinUI::update() {
|
||||
encoderDiff = ENCODER_PULSES_PER_STEP * ydir;
|
||||
else if (screen_items > 0) {
|
||||
// Last 3 cols act as a scroll :-)
|
||||
if (col > (LCD_WIDTH) - 3)
|
||||
if (col > (LCD_WIDTH) - 5)
|
||||
// 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.)
|
||||
encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user