Sfoglia il codice sorgente

Clean up TFT / Touch code (#18296)

Victor 4 anni fa
parent
commit
6d571a547c
Nessun account collegato all'indirizzo email del committer

+ 32
- 4
Marlin/src/feature/touch/xpt2046.cpp Vedi File

@@ -25,6 +25,29 @@
25 25
 #include "../../inc/MarlinConfig.h"
26 26
 #include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
27 27
 
28
+/*
29
+ * Draw and Touch processing
30
+ *
31
+ *      LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
32
+ *   TOUCH_SCREEN_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
33
+ * LCD_FULL_PIXEL_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
34
+ *
35
+ *  - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
36
+ *  - The DOGM pixels are is upscaled 2-3x (as needed) for display.
37
+ *  - Touch coordinates use TOUCH_SCREEN_* resolution and are converted to
38
+ *    click and scroll-wheel events (emulating of a common DOGM display).
39
+ *
40
+ *  TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
41
+ *  and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
42
+ *  new calibration values will be needed.
43
+ *
44
+ *  The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
45
+ *  fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
46
+ *  navigate and select menu items. Both regions are touchable.
47
+ *
48
+ * The Marlin screen touchable area starts at LCD_PIXEL_OFFSET_X/Y (translated to SCREEN_START_LEFT/TOP)
49
+ * and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_WIDTH/HEIGHT).
50
+ */
28 51
 // Touch screen resolution independent of display resolution
29 52
 #define TOUCH_SCREEN_HEIGHT 240
30 53
 #define TOUCH_SCREEN_WIDTH 320
@@ -33,8 +56,13 @@
33 56
 #define BUTTON_AREA_TOP 175
34 57
 #define BUTTON_AREA_BOT 234
35 58
 
36
-#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
37
-#define TOUCHABLE_Y_HEIGHT (BUTTON_AREA_TOP - (SCREEN_START_TOP))
59
+#define SCREEN_START_TOP  ((LCD_PIXEL_OFFSET_Y) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
60
+#define SCREEN_START_LEFT ((LCD_PIXEL_OFFSET_X) * (TOUCH_SCREEN_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
61
+#define SCREEN_HEIGHT     ((LCD_PIXEL_HEIGHT * FSMC_UPSCALE) * (TOUCH_SCREEN_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
62
+#define SCREEN_WIDTH      ((LCD_PIXEL_WIDTH * FSMC_UPSCALE) * (TOUCH_SCREEN_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
63
+
64
+#define TOUCHABLE_Y_HEIGHT  SCREEN_HEIGHT
65
+#define TOUCHABLE_X_WIDTH  SCREEN_WIDTH
38 66
 
39 67
 #ifndef TOUCH_INT_PIN
40 68
   #define TOUCH_INT_PIN  -1
@@ -98,10 +126,10 @@ uint8_t XPT2046::read_buttons() {
98 126
          : WITHIN(x, 242, 305) ? EN_C
99 127
          : 0;
100 128
 
101
-  if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0;
129
+  if (x > TOUCH_SCREEN_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 0;
102 130
 
103 131
   // Column and row above BUTTON_AREA_TOP
104
-  int8_t col = x * (LCD_WIDTH) / (TOUCH_SCREEN_WIDTH),
132
+  int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
105 133
          row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
106 134
 
107 135
   // Send the touch to the UI (which will simulate the encoder wheel)

+ 0
- 4
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp Vedi File

@@ -73,10 +73,6 @@
73 73
   extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
74 74
 #endif
75 75
 
76
-#ifndef FSMC_UPSCALE
77
-  #define FSMC_UPSCALE 2
78
-#endif
79
-
80 76
 #define WIDTH LCD_PIXEL_WIDTH
81 77
 #define HEIGHT LCD_PIXEL_HEIGHT
82 78
 #define PAGE_HEIGHT 8

+ 4
- 0
Marlin/src/lcd/dogm/ultralcd_DOGM.h Vedi File

@@ -254,4 +254,8 @@
254 254
 #define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
255 255
 #define INFO_FONT_WIDTH   6
256 256
 
257
+#ifndef FSMC_UPSCALE
258
+  #define FSMC_UPSCALE 2
259
+#endif
260
+
257 261
 extern U8G_CLASS u8g;

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp Vedi File

@@ -1455,7 +1455,7 @@ void MarlinUI::update() {
1455 1455
         encoderDiff = ENCODER_PULSES_PER_STEP * ydir;
1456 1456
       else if (screen_items > 0) {
1457 1457
         // Last 3 cols act as a scroll :-)
1458
-        if (col > (LCD_WIDTH) - 3)
1458
+        if (col > (LCD_WIDTH) - 5)
1459 1459
           // 2 * LCD_HEIGHT to scroll to bottom of next page. (LCD_HEIGHT would only go 1 item down.)
1460 1460
           encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * ydir;
1461 1461
         else

Loading…
Annulla
Salva