Browse Source

Capacitive Touch Screen (GT911) for SKR SE BX (#21843)

Co-authored-by: Msq001 <alansayyeah@gmail.com>
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
BigTreeTech 3 years ago
parent
commit
c9de9d4f9b
No account linked to committer's email address

+ 1
- 1
Marlin/Configuration.h View File

@@ -2571,7 +2571,7 @@
2571 2571
 //#define DWIN_CREALITY_LCD
2572 2572
 
2573 2573
 //
2574
-// ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
2574
+// Touch Screen Settings
2575 2575
 //
2576 2576
 //#define TOUCH_SCREEN
2577 2577
 #if ENABLED(TOUCH_SCREEN)

+ 1
- 1
Marlin/src/HAL/LPC1768/tft/xpt2046.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS
25
+#if HAS_TFT_XPT2046 || HAS_RES_TOUCH_BUTTONS
26 26
 
27 27
 #include "xpt2046.h"
28 28
 #include <SPI.h>

+ 202
- 0
Marlin/src/HAL/STM32/tft/gt911.cpp View File

@@ -0,0 +1,202 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
23
+
24
+#include "../../../inc/MarlinConfig.h"
25
+
26
+#if ENABLED(TFT_TOUCH_DEVICE_GT911)
27
+
28
+#include "gt911.h"
29
+#include "pinconfig.h"
30
+
31
+SW_IIC::SW_IIC(uint16_t sda, uint16_t scl) {
32
+  scl_pin = scl;
33
+  sda_pin = sda;
34
+}
35
+
36
+// Software I2C hardware io init
37
+void SW_IIC::init() {
38
+  OUT_WRITE(scl_pin, HIGH);
39
+  OUT_WRITE(sda_pin, HIGH);
40
+}
41
+
42
+// Software I2C start signal
43
+void SW_IIC::start() {
44
+  write_sda(HIGH); // SDA = 1
45
+  write_scl(HIGH); // SCL = 1
46
+  iic_delay(2);
47
+  write_sda(LOW); // SDA = 0
48
+  iic_delay(1);
49
+  write_scl(LOW); // SCL = 0  // keep SCL low, avoid false stop caused by level jump caused by SDA switching IN/OUT
50
+}
51
+
52
+// Software I2C stop signal
53
+void SW_IIC::stop() {
54
+  write_scl(LOW); // SCL = 0
55
+  iic_delay(2);
56
+  write_sda(LOW); // SDA = 0
57
+  iic_delay(2);
58
+  write_scl(HIGH); // SCL = 1
59
+  iic_delay(2);
60
+  write_sda(HIGH); // SDA = 1
61
+}
62
+
63
+// Software I2C sends ACK or NACK signal
64
+void SW_IIC::send_ack(bool ack) {
65
+  write_sda(ack ? LOW : HIGH); // SDA = !ack
66
+  iic_delay(2);
67
+  write_scl(HIGH); // SCL = 1
68
+  iic_delay(2);
69
+  write_scl(LOW); // SCL = 0
70
+}
71
+
72
+// Software I2C read ACK or NACK signal
73
+bool SW_IIC::read_ack() {
74
+  bool error = 0;
75
+  set_sda_in();
76
+
77
+  iic_delay(2);
78
+
79
+  write_scl(HIGH); // SCL = 1
80
+  error = read_sda();
81
+
82
+  iic_delay(2);
83
+
84
+  write_scl(LOW);  // SCL = 0
85
+
86
+  set_sda_out();
87
+  return error;
88
+}
89
+
90
+void SW_IIC::send_byte(uint8_t txd) {
91
+  LOOP_L_N(i, 8) {
92
+    write_sda(txd & 0x80); // write data bit
93
+    txd <<= 1;
94
+    iic_delay(1);
95
+    write_scl(HIGH); // SCL = 1
96
+    iic_delay(2);
97
+    write_scl(LOW); // SCL = 0
98
+    iic_delay(1);
99
+  }
100
+
101
+  read_ack();  // wait ack
102
+}
103
+
104
+uint8_t SW_IIC::read_byte(bool ack) {
105
+  uint8_t data = 0;
106
+
107
+  set_sda_in();
108
+  LOOP_L_N(i, 8) {
109
+    write_scl(HIGH); // SCL = 1
110
+    iic_delay(1);
111
+    data <<= 1;
112
+    if (read_sda()) data++;
113
+    write_scl(LOW); // SCL = 0
114
+    iic_delay(2);
115
+  }
116
+  set_sda_out();
117
+
118
+  send_ack(ack);
119
+
120
+  return data;
121
+}
122
+
123
+GT911_REG_MAP GT911::reg;
124
+SW_IIC GT911::sw_iic = SW_IIC(GT911_SW_I2C_SDA_PIN, GT911_SW_I2C_SCL_PIN);
125
+
126
+void GT911::write_reg(uint16_t reg, uint8_t reg_len, uint8_t* w_data, uint8_t w_len) {
127
+  sw_iic.start();
128
+  sw_iic.send_byte(gt911_slave_address);  // Set IIC Slave address
129
+  LOOP_L_N(i, reg_len) {  // Set reg address
130
+    uint8_t r = (reg >> (8 * (reg_len - 1 - i))) & 0xFF;
131
+    sw_iic.send_byte(r);
132
+  }
133
+
134
+  LOOP_L_N(i, w_len) {  // Write data to reg
135
+    sw_iic.send_byte(w_data[i]);
136
+  }
137
+  sw_iic.stop();
138
+}
139
+
140
+void GT911::read_reg(uint16_t reg, uint8_t reg_len, uint8_t* r_data, uint8_t r_len) {
141
+  sw_iic.start();
142
+  sw_iic.send_byte(gt911_slave_address);  // Set IIC Slave address
143
+  LOOP_L_N(i, reg_len) {  // Set reg address
144
+    uint8_t r = (reg >> (8 * (reg_len - 1 - i))) & 0xFF;
145
+    sw_iic.send_byte(r);
146
+  }
147
+
148
+  sw_iic.start();
149
+  sw_iic.send_byte(gt911_slave_address + 1);  // Set read mode
150
+
151
+  LOOP_L_N(i, r_len) {
152
+    r_data[i] = sw_iic.read_byte(1);  // Read data from reg
153
+  }
154
+  sw_iic.stop();
155
+}
156
+
157
+void GT911::Init() {
158
+  OUT_WRITE(GT911_RST_PIN, LOW);
159
+  OUT_WRITE(GT911_INT_PIN, LOW);
160
+  delay(20);
161
+  WRITE(GT911_RST_PIN, HIGH);
162
+  SET_INPUT(GT911_INT_PIN);
163
+
164
+  sw_iic.init();
165
+
166
+  uint8_t clear_reg = 0x0000;
167
+  write_reg(0x814E, 2, &clear_reg, 2); // Reset to 0 for start
168
+}
169
+
170
+bool GT911::getFirstTouchPoint(int16_t *x, int16_t *y) {
171
+  read_reg(0x814E, 2, &reg.REG.status, 1);
172
+
173
+  if (reg.REG.status & 0x80) {
174
+    uint8_t clear_reg = 0x00;
175
+    write_reg(0x814E, 2, &clear_reg, 1); // Reset to 0 for start
176
+    read_reg(0x8150, 2, reg.map + 2, 8 * (reg.REG.status & 0x0F));
177
+
178
+    // First touch point
179
+    *x = ((reg.REG.point[0].xh & 0x0F) << 8) | reg.REG.point[0].xl;
180
+    *y = ((reg.REG.point[0].yh & 0x0F) << 8) | reg.REG.point[0].yl;
181
+    return true;
182
+  }
183
+  return false;
184
+}
185
+
186
+bool GT911::getPoint(int16_t *x, int16_t *y) {
187
+  static bool touched = 0;
188
+  static int16_t read_x = 0, read_y = 0;
189
+  static millis_t next_time = 0;
190
+
191
+  if (ELAPSED(millis(), next_time)) {
192
+    touched = getFirstTouchPoint(&read_x, &read_y);
193
+    next_time = millis() + 20;
194
+  }
195
+
196
+  *x = read_x;
197
+  *y = read_y;
198
+  return touched;
199
+}
200
+
201
+#endif // TFT_TOUCH_DEVICE_GT911
202
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC

+ 120
- 0
Marlin/src/HAL/STM32/tft/gt911.h View File

@@ -0,0 +1,120 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../../inc/MarlinConfig.h"
25
+
26
+#define GT911_SLAVE_ADDRESS   0xBA
27
+
28
+#if !PIN_EXISTS(GT911_RST)
29
+  #error "GT911_RST_PIN is not defined."
30
+#elif !PIN_EXISTS(GT911_INT)
31
+  #error "GT911_INT_PIN is not defined."
32
+#elif !PIN_EXISTS(GT911_SW_I2C_SCL)
33
+  #error "GT911_SW_I2C_SCL_PIN is not defined."
34
+#elif !PIN_EXISTS(GT911_SW_I2C_SDA)
35
+  #error "GT911_SW_I2C_SDA_PIN is not defined."
36
+#endif
37
+
38
+class SW_IIC {
39
+  private:
40
+    uint16_t scl_pin;
41
+    uint16_t sda_pin;
42
+    void write_scl(bool level)
43
+    {
44
+      WRITE(scl_pin, level);
45
+    }
46
+    void write_sda(bool level)
47
+    {
48
+      WRITE(sda_pin, level);
49
+    }
50
+    bool read_sda()
51
+    {
52
+      return READ(sda_pin);
53
+    }
54
+    void set_sda_out()
55
+    {
56
+      SET_OUTPUT(sda_pin);
57
+    }
58
+    void set_sda_in()
59
+    {
60
+      SET_INPUT_PULLUP(sda_pin);
61
+    }
62
+    static void iic_delay(uint8_t t)
63
+    {
64
+      delayMicroseconds(t);
65
+    }
66
+
67
+  public:
68
+    SW_IIC(uint16_t sda, uint16_t scl);
69
+    // setSCL/SDA have to be called before begin()
70
+    void setSCL(uint16_t scl)
71
+    {
72
+      scl_pin = scl;
73
+    };
74
+    void setSDA(uint16_t sda)
75
+    {
76
+      sda_pin = sda;
77
+    };
78
+    void init();                // Initialize the IO port of IIC
79
+    void start();               // Send IIC start signal
80
+    void stop();                // Send IIC stop signal
81
+    void send_byte(uint8_t txd); // IIC sends a byte
82
+    uint8_t read_byte(bool ack); // IIC reads a byte
83
+    void send_ack(bool ack);            // IIC sends ACK or NACK signal
84
+    bool read_ack();
85
+};
86
+
87
+typedef struct __attribute__((__packed__)) {
88
+  uint8_t xl;
89
+  uint8_t xh;
90
+  uint8_t yl;
91
+  uint8_t yh;
92
+  uint8_t sizel;
93
+  uint8_t sizeh;
94
+  uint8_t reserved;
95
+  uint8_t track_id;
96
+} GT911_POINT;
97
+
98
+typedef union __attribute__((__packed__)) {
99
+  uint8_t map[42];
100
+  struct {
101
+    uint8_t status;    // 0x814E
102
+    uint8_t track_id;  // 0x814F
103
+
104
+    GT911_POINT point[5]; // [0]:0x8150 - 0x8157 / [1]:0x8158 - 0x815F / [2]:0x8160 - 0x8167 / [3]:0x8168 - 0x816F / [4]:0x8170 - 0x8177
105
+ } REG;
106
+} GT911_REG_MAP;
107
+
108
+class GT911 {
109
+  private:
110
+    static const uint8_t gt911_slave_address = GT911_SLAVE_ADDRESS;
111
+    static GT911_REG_MAP reg;
112
+    static SW_IIC sw_iic;
113
+    static void write_reg(uint16_t reg, uint8_t reg_len, uint8_t* w_data, uint8_t w_len);
114
+    static void read_reg(uint16_t reg, uint8_t reg_len, uint8_t* r_data, uint8_t r_len);
115
+
116
+  public:
117
+    static void Init();
118
+    static bool getFirstTouchPoint(int16_t *x, int16_t *y);
119
+    static bool getPoint(int16_t *x, int16_t *y);
120
+};

+ 1
- 1
Marlin/src/HAL/STM32/tft/xpt2046.cpp View File

@@ -23,7 +23,7 @@
23 23
 
24 24
 #include "../../../inc/MarlinConfig.h"
25 25
 
26
-#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS
26
+#if HAS_TFT_XPT2046 || HAS_RES_TOUCH_BUTTONS
27 27
 
28 28
 #include "xpt2046.h"
29 29
 #include "pinconfig.h"

+ 1
- 1
Marlin/src/HAL/STM32F1/tft/xpt2046.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_TFT_XPT2046 || HAS_TOUCH_BUTTONS
25
+#if HAS_TFT_XPT2046 || HAS_RES_TOUCH_BUTTONS
26 26
 
27 27
 #include "xpt2046.h"
28 28
 #include <SPI.h>

+ 22
- 5
Marlin/src/inc/Conditionals_LCD.h View File

@@ -1131,6 +1131,9 @@
1131 1131
   #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY)
1132 1132
   #define TFT_RES_1024x600
1133 1133
   #define TFT_INTERFACE_LTDC
1134
+  #if ENABLED(TOUCH_SCREEN)
1135
+    #define TFT_TOUCH_DEVICE_GT911
1136
+  #endif
1134 1137
 #elif ENABLED(TFT_GENERIC)
1135 1138
   #define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
1136 1139
   #if NONE(TFT_RES_320x240, TFT_RES_480x272, TFT_RES_480x320)
@@ -1219,16 +1222,30 @@
1219 1222
   #define HAS_UI_1024x600 1
1220 1223
 #endif
1221 1224
 #if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272)
1222
-  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
1225
+  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)   // Fewer lines with touch buttons onscreen
1223 1226
 #elif HAS_UI_1024x600
1224 1227
   #define LCD_HEIGHT TERN(TOUCH_SCREEN, 12, 13) // Fewer lines with touch buttons onscreen
1225 1228
 #endif
1226 1229
 
1227 1230
 // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
1228
-#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
1229
-  #undef TOUCH_SCREEN
1230
-  #if ENABLED(TFT_CLASSIC_UI)
1231
-    #define HAS_TOUCH_BUTTONS 1
1231
+#if ENABLED(TOUCH_SCREEN)
1232
+  #if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
1233
+    #define TFT_TOUCH_DEVICE_XPT2046          // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
1234
+  #endif
1235
+  #if ENABLED(TFT_TOUCH_DEVICE_GT911)         // GT911 Capacitive touch screen such as BIQU_BX_TFT70
1236
+    #undef TOUCH_SCREEN_CALIBRATION
1237
+    #undef TOUCH_CALIBRATION_AUTO_SAVE
1238
+  #endif
1239
+  #if !HAS_GRAPHICAL_TFT
1240
+    #undef TOUCH_SCREEN
1241
+    #if ENABLED(TFT_CLASSIC_UI)
1242
+      #define HAS_TOUCH_BUTTONS 1
1243
+      #if ENABLED(TFT_TOUCH_DEVICE_GT911)
1244
+        #define HAS_CAP_TOUCH_BUTTONS 1
1245
+      #else
1246
+        #define HAS_RES_TOUCH_BUTTONS 1
1247
+      #endif
1248
+    #endif
1232 1249
   #endif
1233 1250
 #endif
1234 1251
 

+ 2
- 2
Marlin/src/inc/Conditionals_adv.h View File

@@ -371,13 +371,13 @@
371 371
 #endif
372 372
 
373 373
 // Full Touch Screen needs 'tft/xpt2046'
374
-#if EITHER(TOUCH_SCREEN, HAS_TFT_LVGL_UI)
374
+#if EITHER(TFT_TOUCH_DEVICE_XPT2046, HAS_TFT_LVGL_UI)
375 375
   #define HAS_TFT_XPT2046 1
376 376
 #endif
377 377
 
378 378
 // Touch Screen or "Touch Buttons" need XPT2046 pins
379 379
 // but they use different components
380
-#if EITHER(HAS_TFT_XPT2046, HAS_TOUCH_BUTTONS)
380
+#if HAS_TFT_XPT2046 || HAS_RES_TOUCH_BUTTONS
381 381
   #define NEED_TOUCH_PINS 1
382 382
 #endif
383 383
 

+ 4
- 14
Marlin/src/inc/SanityCheck.h View File

@@ -3180,21 +3180,11 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
3180 3180
 #endif
3181 3181
 
3182 3182
 /**
3183
- * Touch Buttons
3183
+ * Touch Screen Calibration
3184 3184
  */
3185
-#if ENABLED(TOUCH_SCREEN) && DISABLED(TOUCH_SCREEN_CALIBRATION)
3186
-  #ifndef TOUCH_CALIBRATION_X
3187
-    #error "TOUCH_CALIBRATION_X must be defined with TOUCH_SCREEN."
3188
-  #endif
3189
-  #ifndef TOUCH_CALIBRATION_Y
3190
-    #error "TOUCH_CALIBRATION_Y must be defined with TOUCH_SCREEN."
3191
-  #endif
3192
-  #ifndef TOUCH_OFFSET_X
3193
-    #error "TOUCH_OFFSET_X must be defined with TOUCH_SCREEN."
3194
-  #endif
3195
-  #ifndef TOUCH_OFFSET_Y
3196
-    #error "TOUCH_OFFSET_Y must be defined with TOUCH_SCREEN."
3197
-  #endif
3185
+#if ENABLED(TFT_TOUCH_DEVICE_XPT2046) && DISABLED(TOUCH_SCREEN_CALIBRATION) \
3186
+    && (!defined(TOUCH_CALIBRATION_X) || !defined(TOUCH_CALIBRATION_Y) || !defined(TOUCH_OFFSET_X) || !defined(TOUCH_OFFSET_Y))
3187
+  #error "TOUCH_CALIBRATION_[XY] and TOUCH_OFFSET_[XY] are required for resistive touch screens with TOUCH_SCREEN_CALIBRATION disabled."
3198 3188
 #endif
3199 3189
 
3200 3190
 /**

+ 15
- 10
Marlin/src/lcd/tft/touch.cpp View File

@@ -257,18 +257,23 @@ void Touch::hold(touch_control_t *control, millis_t delay) {
257 257
 }
258 258
 
259 259
 bool Touch::get_point(int16_t *x, int16_t *y) {
260
-  #if ENABLED(TOUCH_SCREEN_CALIBRATION)
261
-    bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
260
+  #if ENABLED(TFT_TOUCH_DEVICE_XPT2046)
261
+    #if ENABLED(TOUCH_SCREEN_CALIBRATION)
262
+      bool is_touched = (touch_calibration.calibration.orientation == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
262 263
 
263
-    if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
264
-      *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
265
-      *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
266
-    }
267
-  #else
268
-    bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
269
-    *x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
270
-    *y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
264
+      if (is_touched && touch_calibration.calibration.orientation != TOUCH_ORIENTATION_NONE) {
265
+        *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
266
+        *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
267
+      }
268
+    #else
269
+      bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getRawPoint(y, x) : io.getRawPoint(x, y));
270
+      *x = uint16_t((uint32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
271
+      *y = uint16_t((uint32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
272
+    #endif
273
+  #elif ENABLED(TFT_TOUCH_DEVICE_GT911)
274
+    bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
271 275
   #endif
276
+
272 277
   return is_touched;
273 278
 }
274 279
 Touch touch;

+ 10
- 3
Marlin/src/lcd/tft/touch.h View File

@@ -30,8 +30,15 @@
30 30
   #include "../tft_io/touch_calibration.h"
31 31
 #endif
32 32
 
33
-#include HAL_PATH(../../HAL, tft/xpt2046.h)
34
-#define TOUCH_DRIVER XPT2046
33
+#if ENABLED(TFT_TOUCH_DEVICE_GT911)
34
+  #include HAL_PATH(../../HAL, tft/gt911.h)
35
+  #define TOUCH_DRIVER_CLASS GT911
36
+#elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
37
+  #include HAL_PATH(../../HAL, tft/xpt2046.h)
38
+  #define TOUCH_DRIVER_CLASS XPT2046
39
+#else
40
+  #error "Unknown Touch Screen Type."
41
+#endif
35 42
 
36 43
 // Menu Navigation
37 44
 extern int8_t encoderTopLine, encoderLine, screen_items;
@@ -85,7 +92,7 @@ typedef struct __attribute__((__packed__)) {
85 92
 
86 93
 class Touch {
87 94
   private:
88
-    static TOUCH_DRIVER io;
95
+    static TOUCH_DRIVER_CLASS io;
89 96
     static int16_t x, y;
90 97
     static bool enabled;
91 98
 

+ 24
- 19
Marlin/src/lcd/tft/ui_1024x600.cpp View File

@@ -48,9 +48,9 @@
48 48
 void MarlinUI::tft_idle() {
49 49
   #if ENABLED(TOUCH_SCREEN)
50 50
     if (draw_menu_navigation) {
51
-      add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
-      add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
53
-      add_control(224, TFT_HEIGHT - 34, BACK, imgBack);
51
+      add_control(164, TFT_HEIGHT - 50, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
+      add_control(796, TFT_HEIGHT - 50, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
53
+      add_control(480, TFT_HEIGHT - 50, BACK, imgBack);
54 54
       draw_menu_navigation = false;
55 55
     }
56 56
   #endif
@@ -60,6 +60,7 @@ void MarlinUI::tft_idle() {
60 60
 }
61 61
 
62 62
 #if ENABLED(SHOW_BOOTSCREEN)
63
+
63 64
   void MarlinUI::show_bootscreen() {
64 65
     tft.queue.reset();
65 66
 
@@ -81,9 +82,13 @@ void MarlinUI::tft_idle() {
81 82
     #endif
82 83
 
83 84
     tft.queue.sync();
84
-    safe_delay(BOOTSCREEN_TIMEOUT);
85
+  }
86
+
87
+  void MarlinUI::bootscreen_completion(const millis_t sofar) {
88
+    if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar);
85 89
     clear_lcd();
86 90
   }
91
+
87 92
 #endif
88 93
 
89 94
 void MarlinUI::draw_kill_screen() {
@@ -289,7 +294,7 @@ void MarlinUI::draw_status_screen() {
289 294
   tft_string.set(i16tostr3rj(feedrate_percentage));
290 295
   tft_string.add('%');
291 296
   tft.add_text(36, 1, color , tft_string);
292
-  TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 96, 176, 100, 32));
297
+  TERN_(TOUCH_SCREEN, touch.add_control(FEEDRATE, 274, y, 100, 32));
293 298
 
294 299
   // flow rate
295 300
   tft.canvas(650, y, 100, 32);
@@ -299,10 +304,10 @@ void MarlinUI::draw_status_screen() {
299 304
   tft_string.set(i16tostr3rj(planner.flow_percentage[active_extruder]));
300 305
   tft_string.add('%');
301 306
   tft.add_text(36, 1, color , tft_string);
302
-  TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 284, 176, 100, 32, active_extruder));
307
+  TERN_(TOUCH_SCREEN, touch.add_control(FLOWRATE, 650, y, 100, 32, active_extruder));
303 308
 
304 309
   #if ENABLED(TOUCH_SCREEN)
305
-    add_control(404, y, menu_main, imgSettings);
310
+    add_control(900, y, menu_main, imgSettings);
306 311
     TERN_(SDSUPPORT, add_control(12, y, menu_media, imgSD, !printingIsActive(), COLOR_CONTROL_ENABLED, card.isMounted() && printingIsActive() ? COLOR_BUSY : COLOR_CONTROL_DISABLED));
307 312
   #endif
308 313
 
@@ -375,8 +380,8 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const val
375 380
   extern screenFunc_t _manual_move_func_ptr;
376 381
   if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
377 382
 
378
-    #define SLIDER_LENGTH 336
379
-    #define SLIDER_Y_POSITION 186
383
+    #define SLIDER_LENGTH 600
384
+    #define SLIDER_Y_POSITION 200
380 385
 
381 386
     tft.canvas((TFT_WIDTH - SLIDER_LENGTH) / 2, SLIDER_Y_POSITION, SLIDER_LENGTH, 16);
382 387
     tft.set_background(COLOR_BACKGROUND);
@@ -398,9 +403,9 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const val
398 403
 
399 404
 void TFT::draw_edit_screen_buttons() {
400 405
   #if ENABLED(TOUCH_SCREEN)
401
-    add_control(64, TFT_HEIGHT - 64, DECREASE, imgDecrease);
402
-    add_control(352, TFT_HEIGHT - 64, INCREASE, imgIncrease);
403
-    add_control(208, TFT_HEIGHT - 64, CLICK, imgConfirm);
406
+    add_control(164, TFT_HEIGHT - 64, DECREASE, imgDecrease);
407
+    add_control(796, TFT_HEIGHT - 64, INCREASE, imgIncrease);
408
+    add_control(480, TFT_HEIGHT - 64, CLICK, imgConfirm);
404 409
   #endif
405 410
 }
406 411
 
@@ -755,7 +760,7 @@ static void z_minus() { moveAxis(Z_AXIS, -1); }
755 760
     drawMessage(GET_TEXT(MSG_LEVEL_BED_HOMING));
756 761
     queue.inject_P(G28_STR);
757 762
     // Disable touch until home is done
758
-    TERN_(HAS_TFT_XPT2046, touch.disable());
763
+    TERN_(TOUCH_SCREEN, touch.disable());
759 764
     drawAxisValue(E_AXIS);
760 765
     drawAxisValue(X_AXIS);
761 766
     drawAxisValue(Y_AXIS);
@@ -804,14 +809,14 @@ static void drawBtn(int x, int y, const char *label, intptr_t data, MarlinImage
804 809
     tft.add_image(0, 0, img, bgColor, COLOR_BACKGROUND, COLOR_DARKGREY);
805 810
   }
806 811
 
807
-  TERN_(HAS_TFT_XPT2046, if (enabled) touch.add_control(BUTTON, x, y, width, height, data));
812
+  TERN_(TOUCH_SCREEN, if (enabled) touch.add_control(BUTTON, x, y, width, height, data));
808 813
 }
809 814
 
810 815
 void MarlinUI::move_axis_screen() {
811 816
   // Reset
812 817
   defer_status_screen(true);
813 818
   motionAxisState.blocked = false;
814
-  TERN_(HAS_TFT_XPT2046, touch.enable());
819
+  TERN_(TOUCH_SCREEN, touch.enable());
815 820
 
816 821
   ui.clear_lcd();
817 822
 
@@ -849,13 +854,13 @@ void MarlinUI::move_axis_screen() {
849 854
   motionAxisState.eNamePos.x = x;
850 855
   motionAxisState.eNamePos.y = y;
851 856
   drawCurESelection();
852
-  TERN_(HAS_TFT_XPT2046, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
857
+  TERN_(TOUCH_SCREEN, if (!busy) touch.add_control(BUTTON, x, y, BTN_WIDTH, BTN_HEIGHT, (intptr_t)e_select));
853 858
 
854 859
   x += BTN_WIDTH + spacing;
855 860
   drawBtn(x, y, "X-", (intptr_t)x_minus, imgLeft, X_BTN_COLOR, !busy);
856 861
 
857 862
   x += BTN_WIDTH + spacing; //imgHome is 64x64
858
-  TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
863
+  TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH / 2 - Images[imgHome].width / 2, y - (Images[imgHome].width - BTN_HEIGHT) / 2, BUTTON, (intptr_t)do_home, imgHome, !busy));
859 864
 
860 865
   x += BTN_WIDTH + spacing;
861 866
   uint16_t xplus_x = x;
@@ -904,13 +909,13 @@ void MarlinUI::move_axis_screen() {
904 909
   motionAxisState.stepValuePos.y = y;
905 910
   if (!busy) {
906 911
     drawCurStepValue();
907
-    TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
912
+    TERN_(TOUCH_SCREEN, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
908 913
   }
909 914
 
910 915
   // aligned with x+
911 916
   drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
912 917
 
913
-  TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
918
+  TERN_(TOUCH_SCREEN, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));
914 919
 }
915 920
 
916 921
 #endif // HAS_UI_480x320

+ 9
- 2
Marlin/src/lcd/touch/touch_buttons.cpp View File

@@ -24,8 +24,15 @@
24 24
 #include "touch_buttons.h"
25 25
 #include "../scaled_tft.h"
26 26
 
27
-#include HAL_PATH(../../HAL, tft/xpt2046.h)
28
-XPT2046 touchIO;
27
+#if ENABLED(TFT_TOUCH_DEVICE_GT911)
28
+  #include HAL_PATH(../../HAL, tft/gt911.h)
29
+  GT911 touchIO;
30
+#elif ENABLED(TFT_TOUCH_DEVICE_XPT2046)
31
+  #include HAL_PATH(../../HAL, tft/xpt2046.h)
32
+  XPT2046 touchIO;
33
+#else
34
+  #error "Unknown Touch Screen Type."
35
+#endif
29 36
 
30 37
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
31 38
   #include "../tft_io/touch_calibration.h"

+ 13
- 3
Marlin/src/pins/stm32h7/pins_BTT_SKR_SE_BX.h View File

@@ -207,11 +207,21 @@
207 207
   #define LCD_B4_PIN                        PI4
208 208
   #define LCD_B3_PIN                        PG11
209 209
 
210
+  // GT911 Capacitive Touch Sensor
211
+  #if ENABLED(TFT_TOUCH_DEVICE_GT911)
212
+    #define GT911_RST_PIN                   PE4
213
+    #define GT911_INT_PIN                   PE3
214
+    #define GT911_SW_I2C_SCL_PIN            PE2
215
+    #define GT911_SW_I2C_SDA_PIN            PE6
216
+  #endif
217
+
210 218
 #endif
211 219
 
212
-#define BTN_EN1                             PH6
213
-#define BTN_EN2                             PH7
214
-#define BTN_ENC                             PH8
220
+#if IS_NEWPANEL
221
+  #define BTN_EN1                           PH6
222
+  #define BTN_EN2                           PH7
223
+  #define BTN_ENC                           PH8
224
+#endif
215 225
 
216 226
 #ifndef SDCARD_CONNECTION
217 227
   #define SDCARD_CONNECTION              ONBOARD

Loading…
Cancel
Save