Browse Source

Better Classic UI touch resolution (#20004)

Victor Oliveira 3 years ago
parent
commit
e9053654a7
No account linked to committer's email address

+ 7
- 28
Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp View File

@@ -73,10 +73,8 @@ TFT_IO tftio;
73 73
 #define HEIGHT LCD_PIXEL_HEIGHT
74 74
 #define PAGE_HEIGHT 8
75 75
 
76
-#include "../scaled_tft.h"
76
+#include "../touch/touch_buttons.h"
77 77
 
78
-#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
79
-#define UPSCALE(A,M) (UPSCALE0(M) + (A))
80 78
 #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
81 79
 #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
82 80
 
@@ -276,29 +274,10 @@ static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin,
276 274
     B01111111,B11111111,B11111111,B11111110,
277 275
   };
278 276
 
279
-  #define BUTTON_SIZE_X 32
280
-  #define BUTTON_SIZE_Y 20
281
-
282
-  // 14, 90, 166, 242, 185 are the original values upscaled 2x.
283
-  #define BUTTOND_X_LO UPSCALE0(14 / 2)
284
-  #define BUTTOND_X_HI (UPSCALE(BUTTOND_X_LO, BUTTON_SIZE_X) - 1)
285
-
286
-  #define BUTTONA_X_LO UPSCALE0(90 / 2)
287
-  #define BUTTONA_X_HI (UPSCALE(BUTTONA_X_LO, BUTTON_SIZE_X) - 1)
288
-
289
-  #define BUTTONB_X_LO UPSCALE0(166 / 2)
290
-  #define BUTTONB_X_HI (UPSCALE(BUTTONB_X_LO, BUTTON_SIZE_X) - 1)
291
-
292
-  #define BUTTONC_X_LO UPSCALE0(242 / 2)
293
-  #define BUTTONC_X_HI (UPSCALE(BUTTONC_X_LO, BUTTON_SIZE_X) - 1)
294
-
295
-  #define BUTTON_Y_LO UPSCALE0(140 / 2) + 44 // 184 2x, 254 3x
296
-  #define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1)
297
-
298 277
   void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
299
-    uint16_t buffer[BUTTON_SIZE_X * sq(GRAPHICAL_TFT_UPSCALE)];
278
+    uint16_t buffer[BUTTON_WIDTH * sq(GRAPHICAL_TFT_UPSCALE)];
300 279
 
301
-    if (length > BUTTON_SIZE_X) return;
280
+    if (length > BUTTON_WIDTH) return;
302 281
 
303 282
     for (uint16_t i = 0; i < height; i++) {
304 283
       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
368 347
       // Bottom buttons
369 348
       #if HAS_TOUCH_XPT2046
370 349
         setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI);
371
-        drawImage(buttonD, u8g, dev, 32, 20, TFT_BTCANCEL_COLOR);
350
+        drawImage(buttonD, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTCANCEL_COLOR);
372 351
 
373 352
         setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI);
374
-        drawImage(buttonA, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);
353
+        drawImage(buttonA, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR);
375 354
 
376 355
         setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI);
377
-        drawImage(buttonB, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);
356
+        drawImage(buttonB, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTARROWS_COLOR);
378 357
 
379 358
         setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI);
380
-        drawImage(buttonC, u8g, dev, 32, 20, TFT_BTOKMENU_COLOR);
359
+        drawImage(buttonC, u8g, dev, BUTTON_DRAW_WIDTH, BUTTON_DRAW_HEIGHT, TFT_BTOKMENU_COLOR);
381 360
       #endif // HAS_TOUCH_XPT2046
382 361
 
383 362
       return 0;

+ 16
- 48
Marlin/src/lcd/touch/touch_buttons.cpp View File

@@ -29,45 +29,13 @@ XPT2046 touchIO;
29 29
 
30 30
 #include "../../lcd/marlinui.h" // For EN_C bit mask
31 31
 
32
-/**
33
- * Draw and Touch processing
34
- *
35
- *      LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
36
- *   TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
37
- * TFT_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
38
- *
39
- *  - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
40
- *  - The DOGM pixels are is upscaled 2-3x (as needed) for display.
41
- *  - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to
42
- *    click and scroll-wheel events (emulating of a common DOGM display).
43
- *
44
- *  TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
45
- *  and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
46
- *  new calibration values will be needed.
47
- *
48
- *  The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
49
- *  fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
50
- *  navigate and select menu items. Both regions are touchable.
51
- *
52
- * The Marlin screen touchable area starts at TFT_PIXEL_OFFSET_X/Y (translated to SCREEN_PCT_LEFT/TOP)
53
- * and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_PCT_WIDTH/HEIGHT).
54
- */
55
-
56
-// Touch sensor resolution independent of display resolution
57
-#define TOUCH_SENSOR_WIDTH  320
58
-#define TOUCH_SENSOR_HEIGHT 240
59
-
60
-#define SCREEN_PCT_WIDE(X) ((X) * (TOUCH_SENSOR_WIDTH)  / (TFT_WIDTH))
61
-#define SCREEN_PCT_HIGH(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (TFT_HEIGHT))
62
-
63
-#define SCREEN_PCT_LEFT   SCREEN_PCT_WIDE(TFT_PIXEL_OFFSET_X)
64
-#define SCREEN_PCT_TOP    SCREEN_PCT_HIGH(TFT_PIXEL_OFFSET_Y)
65
-#define SCREEN_PCT_WIDTH  SCREEN_PCT_WIDE((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH))
66
-#define SCREEN_PCT_HEIGHT SCREEN_PCT_HIGH((GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT))
32
+#define DOGM_AREA_LEFT   TFT_PIXEL_OFFSET_X
33
+#define DOGM_AREA_TOP    TFT_PIXEL_OFFSET_Y
34
+#define DOGM_AREA_WIDTH  (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_WIDTH)
35
+#define DOGM_AREA_HEIGHT (GRAPHICAL_TFT_UPSCALE) * (LCD_PIXEL_HEIGHT)
67 36
 
68
-// Coordinates in terms of 240-unit-tall touch area
69
-#define BUTTON_AREA_TOP 175
70
-#define BUTTON_AREA_BOT 234
37
+#define BUTTON_AREA_TOP BUTTON_Y_LO
38
+#define BUTTON_AREA_BOT BUTTON_Y_HI
71 39
 
72 40
 TouchButtons touch;
73 41
 
@@ -83,25 +51,25 @@ uint8_t TouchButtons::read_buttons() {
83 51
     y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
84 52
 
85 53
     #if (TFT_ROTATION & TFT_ROTATE_180)
86
-      x = TOUCH_SENSOR_WIDTH - x;
87
-      y = TOUCH_SENSOR_HEIGHT - y;
54
+      x = TFT_WIDTH - x;
55
+      y = TFT_HEIGHT - y;
88 56
     #endif
89 57
 
90 58
     // Touch within the button area simulates an encoder button
91 59
     if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
92
-      return WITHIN(x,  14,  77) ? EN_D
93
-           : WITHIN(x,  90, 153) ? EN_A
94
-           : WITHIN(x, 166, 229) ? EN_B
95
-           : WITHIN(x, 242, 305) ? EN_C
60
+      return WITHIN(x, BUTTOND_X_LO, BUTTOND_X_HI) ? EN_D
61
+           : WITHIN(x, BUTTONA_X_LO, BUTTONA_X_HI) ? EN_A
62
+           : WITHIN(x, BUTTONB_X_LO, BUTTONB_X_HI) ? EN_B
63
+           : WITHIN(x, BUTTONC_X_LO, BUTTONC_X_HI) ? EN_C
96 64
            : 0;
97 65
 
98
-    if ( !WITHIN(x, SCREEN_PCT_LEFT, SCREEN_PCT_LEFT + SCREEN_PCT_WIDTH)
99
-      || !WITHIN(y, SCREEN_PCT_TOP,  SCREEN_PCT_TOP  + SCREEN_PCT_HEIGHT)
66
+    if ( !WITHIN(x, DOGM_AREA_LEFT, DOGM_AREA_LEFT + DOGM_AREA_WIDTH)
67
+      || !WITHIN(y, DOGM_AREA_TOP,  DOGM_AREA_TOP  + DOGM_AREA_HEIGHT)
100 68
     ) return 0;
101 69
 
102 70
     // Column and row above BUTTON_AREA_TOP
103
-    int8_t col = (x - (SCREEN_PCT_LEFT)) * (LCD_WIDTH)  / (SCREEN_PCT_WIDTH),
104
-           row = (y - (SCREEN_PCT_TOP))  * (LCD_HEIGHT) / (SCREEN_PCT_HEIGHT);
71
+    int8_t col = (x - (DOGM_AREA_LEFT)) * (LCD_WIDTH)  / (DOGM_AREA_WIDTH),
72
+           row = (y - (DOGM_AREA_TOP))  * (LCD_HEIGHT) / (DOGM_AREA_HEIGHT);
105 73
 
106 74
     // Send the touch to the UI (which will simulate the encoder wheel)
107 75
     MarlinUI::screen_click(row, col, x, y);

+ 30
- 0
Marlin/src/lcd/touch/touch_buttons.h View File

@@ -20,6 +20,36 @@
20 20
 
21 21
 #include <stdint.h>
22 22
 
23
+#include "../../inc/MarlinConfig.h"
24
+#include "../scaled_tft.h"
25
+
26
+#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
27
+#define UPSCALE(A,M) (UPSCALE0(M) + (A))
28
+
29
+#define BUTTON_DRAW_WIDTH  32
30
+#define BUTTON_DRAW_HEIGHT 20
31
+
32
+#define BUTTON_WIDTH  UPSCALE0(BUTTON_DRAW_WIDTH)
33
+#define BUTTON_HEIGHT UPSCALE0(BUTTON_DRAW_HEIGHT)
34
+
35
+// calc the space between buttons
36
+#define BUTTON_SPACING (((TFT_WIDTH) - (BUTTON_WIDTH * 4)) / 5)
37
+
38
+#define BUTTOND_X_LO BUTTON_SPACING
39
+#define BUTTOND_X_HI BUTTOND_X_LO + BUTTON_WIDTH - 1
40
+
41
+#define BUTTONA_X_LO BUTTOND_X_HI + BUTTON_SPACING
42
+#define BUTTONA_X_HI BUTTONA_X_LO + BUTTON_WIDTH - 1
43
+
44
+#define BUTTONB_X_LO BUTTONA_X_HI + BUTTON_SPACING
45
+#define BUTTONB_X_HI BUTTONB_X_LO + BUTTON_WIDTH - 1
46
+
47
+#define BUTTONC_X_LO BUTTONB_X_HI + BUTTON_SPACING
48
+#define BUTTONC_X_HI BUTTONC_X_LO + BUTTON_WIDTH - 1
49
+
50
+#define BUTTON_Y_HI (TFT_HEIGHT) - (BUTTON_SPACING / 2)
51
+#define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
52
+
23 53
 class TouchButtons {
24 54
 public:
25 55
   static void init();

+ 1
- 14
Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h View File

@@ -155,7 +155,7 @@
155 155
 #endif
156 156
 
157 157
 // XPT2046 Touch Screen calibration
158
-#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI)
158
+#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
159 159
   #ifndef XPT2046_X_CALIBRATION
160 160
     #define XPT2046_X_CALIBRATION         -17181
161 161
   #endif
@@ -168,19 +168,6 @@
168 168
   #ifndef XPT2046_Y_OFFSET
169 169
     #define XPT2046_Y_OFFSET                  -9
170 170
   #endif
171
-#elif ENABLED(TFT_CLASSIC_UI)
172
-  #ifndef XPT2046_X_CALIBRATION
173
-    #define XPT2046_X_CALIBRATION         -12316
174
-  #endif
175
-  #ifndef XPT2046_Y_CALIBRATION
176
-    #define XPT2046_Y_CALIBRATION           8981
177
-  #endif
178
-  #ifndef XPT2046_X_OFFSET
179
-    #define XPT2046_X_OFFSET                 340
180
-  #endif
181
-  #ifndef XPT2046_Y_OFFSET
182
-    #define XPT2046_Y_OFFSET                 -20
183
-  #endif
184 171
 #endif
185 172
 
186 173
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

+ 1
- 14
Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h View File

@@ -170,7 +170,7 @@
170 170
 #endif
171 171
 
172 172
 // XPT2046 Touch Screen calibration
173
-#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI)
173
+#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
174 174
   #ifndef XPT2046_X_CALIBRATION
175 175
     #define XPT2046_X_CALIBRATION         -17181
176 176
   #endif
@@ -183,19 +183,6 @@
183 183
   #ifndef XPT2046_Y_OFFSET
184 184
     #define XPT2046_Y_OFFSET                  -9
185 185
   #endif
186
-#elif ENABLED(TFT_CLASSIC_UI)
187
-  #ifndef XPT2046_X_CALIBRATION
188
-    #define XPT2046_X_CALIBRATION         -12316
189
-  #endif
190
-  #ifndef XPT2046_Y_CALIBRATION
191
-    #define XPT2046_Y_CALIBRATION           8981
192
-  #endif
193
-  #ifndef XPT2046_X_OFFSET
194
-    #define XPT2046_X_OFFSET                 340
195
-  #endif
196
-  #ifndef XPT2046_Y_OFFSET
197
-    #define XPT2046_Y_OFFSET                 -20
198
-  #endif
199 186
 #endif
200 187
 
201 188
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

+ 2
- 15
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h View File

@@ -198,7 +198,7 @@
198 198
 #endif
199 199
 
200 200
 // XPT2046 Touch Screen calibration
201
-#if EITHER(HAS_TFT_LVGL_UI_FSMC, TFT_480x320)
201
+#if ANY(HAS_TFT_LVGL_UI_FSMC, TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_480x320)
202 202
   #ifndef XPT2046_X_CALIBRATION
203 203
     #define XPT2046_X_CALIBRATION          17880
204 204
   #endif
@@ -211,20 +211,7 @@
211 211
   #ifndef XPT2046_Y_OFFSET
212 212
    #define XPT2046_Y_OFFSET                  349
213 213
   #endif
214
-#elif ENABLED(TFT_CLASSIC_UI)
215
-  #ifndef XPT2046_X_CALIBRATION
216
-    #define XPT2046_X_CALIBRATION          12149
217
-  #endif
218
-  #ifndef XPT2046_Y_CALIBRATION
219
-    #define XPT2046_Y_CALIBRATION          -8746
220
-  #endif
221
-  #ifndef XPT2046_X_OFFSET
222
-    #define XPT2046_X_OFFSET                 -35
223
-  #endif
224
-  #ifndef XPT2046_Y_OFFSET
225
-    #define XPT2046_Y_OFFSET                 256
226
-  #endif
227
-#elif ENABLED(TFT_320x240)
214
+#elif EITHER(TFT_COLOR_UI, TFT_CLASSIC_UI) && ENABLED(TFT_RES_320x240)
228 215
   #ifndef XPT2046_X_CALIBRATION
229 216
     #define XPT2046_X_CALIBRATION         -12246
230 217
   #endif

+ 1
- 14
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h View File

@@ -284,7 +284,7 @@
284 284
 #endif
285 285
 
286 286
 // XPT2046 Touch Screen calibration
287
-#if EITHER(TFT_LVGL_UI, TFT_COLOR_UI)
287
+#if ANY(TFT_LVGL_UI, TFT_COLOR_UI, TFT_CLASSIC_UI)
288 288
   #ifndef XPT2046_X_CALIBRATION
289 289
     #define XPT2046_X_CALIBRATION         -17253
290 290
   #endif
@@ -297,19 +297,6 @@
297 297
   #ifndef XPT2046_Y_OFFSET
298 298
     #define XPT2046_Y_OFFSET                 -24
299 299
   #endif
300
-#elif ENABLED(TFT_CLASSIC_UI)
301
-  #ifndef XPT2046_X_CALIBRATION
302
-    #define XPT2046_X_CALIBRATION         -11386
303
-  #endif
304
-  #ifndef XPT2046_Y_CALIBRATION
305
-    #define XPT2046_Y_CALIBRATION           8684
306
-  #endif
307
-  #ifndef XPT2046_X_OFFSET
308
-    #define XPT2046_X_OFFSET                 339
309
-  #endif
310
-  #ifndef XPT2046_Y_OFFSET
311
-    #define XPT2046_Y_OFFSET                 -18
312
-  #endif
313 300
 #endif
314 301
 
315 302
 #if HAS_WIRED_LCD && !HAS_SPI_TFT

+ 1
- 14
Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h View File

@@ -137,7 +137,7 @@
137 137
 #endif
138 138
 
139 139
 // XPT2046 Touch Screen calibration
140
-#if ENABLED(TFT_COLOR_UI) || ENABLED(TFT_LVGL_UI)
140
+#if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI)
141 141
   #ifndef XPT2046_X_CALIBRATION
142 142
     #define XPT2046_X_CALIBRATION         -17181
143 143
   #endif
@@ -150,19 +150,6 @@
150 150
   #ifndef XPT2046_Y_OFFSET
151 151
     #define XPT2046_Y_OFFSET                  -9
152 152
   #endif
153
-#elif ENABLED(TFT_CLASSIC_UI)
154
-  #ifndef XPT2046_X_CALIBRATION
155
-    #define XPT2046_X_CALIBRATION         -12316
156
-  #endif
157
-  #ifndef XPT2046_Y_CALIBRATION
158
-    #define XPT2046_Y_CALIBRATION           8981
159
-  #endif
160
-  #ifndef XPT2046_X_OFFSET
161
-    #define XPT2046_X_OFFSET                 340
162
-  #endif
163
-  #ifndef XPT2046_Y_OFFSET
164
-    #define XPT2046_Y_OFFSET                 -20
165
-  #endif
166 153
 #endif
167 154
 
168 155
 #if NEED_TOUCH_PINS

Loading…
Cancel
Save