Browse Source

Clean up TFT / Touch code (#18296)

Victor 4 years ago
parent
commit
6d571a547c
No account linked to committer's email address

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

25
 #include "../../inc/MarlinConfig.h"
25
 #include "../../inc/MarlinConfig.h"
26
 #include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
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
 // Touch screen resolution independent of display resolution
51
 // Touch screen resolution independent of display resolution
29
 #define TOUCH_SCREEN_HEIGHT 240
52
 #define TOUCH_SCREEN_HEIGHT 240
30
 #define TOUCH_SCREEN_WIDTH 320
53
 #define TOUCH_SCREEN_WIDTH 320
33
 #define BUTTON_AREA_TOP 175
56
 #define BUTTON_AREA_TOP 175
34
 #define BUTTON_AREA_BOT 234
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
 #ifndef TOUCH_INT_PIN
67
 #ifndef TOUCH_INT_PIN
40
   #define TOUCH_INT_PIN  -1
68
   #define TOUCH_INT_PIN  -1
98
          : WITHIN(x, 242, 305) ? EN_C
126
          : WITHIN(x, 242, 305) ? EN_C
99
          : 0;
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
   // Column and row above BUTTON_AREA_TOP
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
          row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
133
          row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
106
 
134
 
107
   // Send the touch to the UI (which will simulate the encoder wheel)
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 View File

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

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

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

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

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

Loading…
Cancel
Save