Ver código fonte

Emulated DOGM via HAL TFT, XPT IO (#19017)

Victor Oliveira 3 anos atrás
pai
commit
a37cf24900
Nenhuma conta vinculada ao e-mail do autor do commit
28 arquivos alterados com 594 adições e 1376 exclusões
  1. 0
    331
      Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
  2. 0
    236
      Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp
  3. 2
    2
      Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
  4. 1
    1
      Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
  5. 15
    15
      Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
  6. 1
    1
      Marlin/src/HAL/STM32F1/tft/xpt2046.cpp
  7. 11
    9
      Marlin/src/HAL/STM32F1/tft/xpt2046.h
  8. 1
    1
      Marlin/src/MarlinCore.cpp
  9. 5
    4
      Marlin/src/inc/Conditionals_LCD.h
  10. 6
    0
      Marlin/src/inc/SanityCheck.h
  11. 5
    10
      Marlin/src/lcd/dogm/HAL_LCD_com_defines.h
  12. 105
    64
      Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp
  13. 10
    29
      Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp
  14. 4
    4
      Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h
  15. 3
    3
      Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp
  16. 0
    2
      Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp
  17. 15
    15
      Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp
  18. 14
    14
      Marlin/src/lcd/scaled_tft.h
  19. 112
    0
      Marlin/src/lcd/touch/touch_buttons.cpp
  20. 2
    22
      Marlin/src/lcd/touch/touch_buttons.h
  21. 0
    251
      Marlin/src/lcd/touch/xpt2046.cpp
  22. 1
    1
      Marlin/src/lcd/ultralcd.cpp
  23. 48
    83
      Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h
  24. 56
    91
      Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h
  25. 10
    10
      Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
  26. 47
    53
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h
  27. 85
    118
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h
  28. 35
    6
      buildroot/share/scripts/pinsformat.js

+ 0
- 331
Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp Ver arquivo

@@ -1,331 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (c) 2020 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
-
23
-/**
24
- * u8g_com_stm32duino_fsmc.cpp
25
- *
26
- * Communication interface for FSMC
27
- */
28
-
29
-#include "../../../inc/MarlinConfig.h"
30
-
31
-#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs
32
-
33
-#if HAS_GRAPHICAL_LCD
34
-
35
-#include <U8glib.h>
36
-#include <libmaple/fsmc.h>
37
-#include <libmaple/gpio.h>
38
-#include <libmaple/dma.h>
39
-#include <boards.h>
40
-
41
-#ifndef LCD_READ_ID
42
-  #define LCD_READ_ID 0x04   // Read display identification information (0xD3 on ILI9341)
43
-#endif
44
-
45
-/* Timing configuration */
46
-#define FSMC_ADDRESS_SETUP_TIME   15  // AddressSetupTime
47
-#define FSMC_DATA_SETUP_TIME      15  // DataSetupTime
48
-
49
-void LCD_IO_Init(uint8_t cs, uint8_t rs);
50
-void LCD_IO_WriteData(uint16_t RegValue);
51
-void LCD_IO_WriteReg(uint16_t Reg);
52
-uint16_t LCD_IO_ReadData(uint16_t RegValue);
53
-uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
54
-#ifdef LCD_USE_DMA_FSMC
55
-  void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
56
-  void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
57
-#endif
58
-
59
-static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
60
-
61
-uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
62
-  if (msgInitCount) {
63
-    if (msg == U8G_COM_MSG_INIT) msgInitCount--;
64
-    if (msgInitCount) return -1;
65
-  }
66
-
67
-  static uint8_t isCommand;
68
-
69
-  switch (msg) {
70
-    case U8G_COM_MSG_STOP: break;
71
-    case U8G_COM_MSG_INIT:
72
-      u8g_SetPIOutput(u8g, U8G_PI_RESET);
73
-
74
-      #ifdef LCD_USE_DMA_FSMC
75
-        dma_init(FSMC_DMA_DEV);
76
-        dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
77
-        dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
78
-      #endif
79
-
80
-      LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]);
81
-      u8g_Delay(50);
82
-
83
-      if (arg_ptr) {
84
-        *((uint32_t *)arg_ptr) = LCD_IO_ReadData(0x0000);
85
-        if (*((uint32_t *)arg_ptr) == 0)
86
-          *((uint32_t *)arg_ptr) = (LCD_READ_ID << 24) | LCD_IO_ReadData(LCD_READ_ID, 3);
87
-      }
88
-      isCommand = 0;
89
-      break;
90
-
91
-    case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
92
-      isCommand = arg_val == 0 ? 1 : 0;
93
-      break;
94
-
95
-    case U8G_COM_MSG_RESET:
96
-      u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
97
-      break;
98
-
99
-    case U8G_COM_MSG_WRITE_BYTE:
100
-      if (isCommand)
101
-        LCD_IO_WriteReg(arg_val);
102
-      else
103
-        LCD_IO_WriteData((uint16_t)arg_val);
104
-      break;
105
-
106
-    case U8G_COM_MSG_WRITE_SEQ:
107
-      for (uint8_t i = 0; i < arg_val; i += 2)
108
-        LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
109
-      break;
110
-  }
111
-  return 1;
112
-}
113
-
114
-/**
115
- * FSMC LCD IO
116
- */
117
-#define __ASM __asm
118
-#define __STATIC_INLINE static inline
119
-
120
-__attribute__((always_inline)) __STATIC_INLINE void __DSB() {
121
-  __ASM volatile ("dsb 0xF":::"memory");
122
-}
123
-
124
-#define FSMC_CS_NE1   PD7
125
-
126
-#if ENABLED(STM32_XL_DENSITY)
127
-  #define FSMC_CS_NE2 PG9
128
-  #define FSMC_CS_NE3 PG10
129
-  #define FSMC_CS_NE4 PG12
130
-
131
-  #define FSMC_RS_A0  PF0
132
-  #define FSMC_RS_A1  PF1
133
-  #define FSMC_RS_A2  PF2
134
-  #define FSMC_RS_A3  PF3
135
-  #define FSMC_RS_A4  PF4
136
-  #define FSMC_RS_A5  PF5
137
-  #define FSMC_RS_A6  PF12
138
-  #define FSMC_RS_A7  PF13
139
-  #define FSMC_RS_A8  PF14
140
-  #define FSMC_RS_A9  PF15
141
-  #define FSMC_RS_A10 PG0
142
-  #define FSMC_RS_A11 PG1
143
-  #define FSMC_RS_A12 PG2
144
-  #define FSMC_RS_A13 PG3
145
-  #define FSMC_RS_A14 PG4
146
-  #define FSMC_RS_A15 PG5
147
-#endif
148
-
149
-#define FSMC_RS_A16   PD11
150
-#define FSMC_RS_A17   PD12
151
-#define FSMC_RS_A18   PD13
152
-#define FSMC_RS_A19   PE3
153
-#define FSMC_RS_A20   PE4
154
-#define FSMC_RS_A21   PE5
155
-#define FSMC_RS_A22   PE6
156
-#define FSMC_RS_A23   PE2
157
-
158
-#if ENABLED(STM32_XL_DENSITY)
159
-  #define FSMC_RS_A24 PG13
160
-  #define FSMC_RS_A25 PG14
161
-#endif
162
-
163
-static uint8_t fsmcInit = 0;
164
-
165
-typedef struct {
166
-  __IO uint16_t REG;
167
-  __IO uint16_t RAM;
168
-} LCD_CONTROLLER_TypeDef;
169
-
170
-LCD_CONTROLLER_TypeDef *LCD;
171
-
172
-void LCD_IO_Init(uint8_t cs, uint8_t rs) {
173
-  uint32_t controllerAddress;
174
-  struct fsmc_nor_psram_reg_map* fsmcPsramRegion;
175
-
176
-  if (fsmcInit) return;
177
-  fsmcInit = 1;
178
-
179
-  switch (cs) {
180
-    case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; fsmcPsramRegion = FSMC_NOR_PSRAM1_BASE; break;
181
-    #if ENABLED(STM32_XL_DENSITY)
182
-      case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; fsmcPsramRegion = FSMC_NOR_PSRAM2_BASE; break;
183
-      case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; fsmcPsramRegion = FSMC_NOR_PSRAM3_BASE; break;
184
-      case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; fsmcPsramRegion = FSMC_NOR_PSRAM4_BASE; break;
185
-    #endif
186
-    default: return;
187
-  }
188
-
189
-  #define _ORADDR(N) controllerAddress |= (_BV32(N) - 2)
190
-
191
-  switch (rs) {
192
-    #if ENABLED(STM32_XL_DENSITY)
193
-      case FSMC_RS_A0:  _ORADDR( 1); break;
194
-      case FSMC_RS_A1:  _ORADDR( 2); break;
195
-      case FSMC_RS_A2:  _ORADDR( 3); break;
196
-      case FSMC_RS_A3:  _ORADDR( 4); break;
197
-      case FSMC_RS_A4:  _ORADDR( 5); break;
198
-      case FSMC_RS_A5:  _ORADDR( 6); break;
199
-      case FSMC_RS_A6:  _ORADDR( 7); break;
200
-      case FSMC_RS_A7:  _ORADDR( 8); break;
201
-      case FSMC_RS_A8:  _ORADDR( 9); break;
202
-      case FSMC_RS_A9:  _ORADDR(10); break;
203
-      case FSMC_RS_A10: _ORADDR(11); break;
204
-      case FSMC_RS_A11: _ORADDR(12); break;
205
-      case FSMC_RS_A12: _ORADDR(13); break;
206
-      case FSMC_RS_A13: _ORADDR(14); break;
207
-      case FSMC_RS_A14: _ORADDR(15); break;
208
-      case FSMC_RS_A15: _ORADDR(16); break;
209
-    #endif
210
-    case FSMC_RS_A16: _ORADDR(17); break;
211
-    case FSMC_RS_A17: _ORADDR(18); break;
212
-    case FSMC_RS_A18: _ORADDR(19); break;
213
-    case FSMC_RS_A19: _ORADDR(20); break;
214
-    case FSMC_RS_A20: _ORADDR(21); break;
215
-    case FSMC_RS_A21: _ORADDR(22); break;
216
-    case FSMC_RS_A22: _ORADDR(23); break;
217
-    case FSMC_RS_A23: _ORADDR(24); break;
218
-    #if ENABLED(STM32_XL_DENSITY)
219
-      case FSMC_RS_A24: _ORADDR(25); break;
220
-      case FSMC_RS_A25: _ORADDR(26); break;
221
-    #endif
222
-    default: return;
223
-  }
224
-
225
-  rcc_clk_enable(RCC_FSMC);
226
-
227
-  gpio_set_mode(GPIOD, 14, GPIO_AF_OUTPUT_PP);  // FSMC_D00
228
-  gpio_set_mode(GPIOD, 15, GPIO_AF_OUTPUT_PP);  // FSMC_D01
229
-  gpio_set_mode(GPIOD,  0, GPIO_AF_OUTPUT_PP);  // FSMC_D02
230
-  gpio_set_mode(GPIOD,  1, GPIO_AF_OUTPUT_PP);  // FSMC_D03
231
-  gpio_set_mode(GPIOE,  7, GPIO_AF_OUTPUT_PP);  // FSMC_D04
232
-  gpio_set_mode(GPIOE,  8, GPIO_AF_OUTPUT_PP);  // FSMC_D05
233
-  gpio_set_mode(GPIOE,  9, GPIO_AF_OUTPUT_PP);  // FSMC_D06
234
-  gpio_set_mode(GPIOE, 10, GPIO_AF_OUTPUT_PP);  // FSMC_D07
235
-  gpio_set_mode(GPIOE, 11, GPIO_AF_OUTPUT_PP);  // FSMC_D08
236
-  gpio_set_mode(GPIOE, 12, GPIO_AF_OUTPUT_PP);  // FSMC_D09
237
-  gpio_set_mode(GPIOE, 13, GPIO_AF_OUTPUT_PP);  // FSMC_D10
238
-  gpio_set_mode(GPIOE, 14, GPIO_AF_OUTPUT_PP);  // FSMC_D11
239
-  gpio_set_mode(GPIOE, 15, GPIO_AF_OUTPUT_PP);  // FSMC_D12
240
-  gpio_set_mode(GPIOD,  8, GPIO_AF_OUTPUT_PP);  // FSMC_D13
241
-  gpio_set_mode(GPIOD,  9, GPIO_AF_OUTPUT_PP);  // FSMC_D14
242
-  gpio_set_mode(GPIOD, 10, GPIO_AF_OUTPUT_PP);  // FSMC_D15
243
-
244
-  gpio_set_mode(GPIOD,  4, GPIO_AF_OUTPUT_PP);  // FSMC_NOE
245
-  gpio_set_mode(GPIOD,  5, GPIO_AF_OUTPUT_PP);  // FSMC_NWE
246
-
247
-  gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP);  //FSMC_CS_NEx
248
-  gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP);  //FSMC_RS_Ax
249
-
250
-  fsmcPsramRegion->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
251
-  fsmcPsramRegion->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
252
-
253
-  afio_remap(AFIO_REMAP_FSMC_NADV);
254
-
255
-  LCD = (LCD_CONTROLLER_TypeDef*)controllerAddress;
256
-}
257
-
258
-void LCD_IO_WriteData(uint16_t RegValue) {
259
-  LCD->RAM = RegValue;
260
-  __DSB();
261
-}
262
-
263
-void LCD_IO_WriteReg(uint16_t Reg) {
264
-  LCD->REG = Reg;
265
-  __DSB();
266
-}
267
-
268
-uint16_t LCD_IO_ReadData(uint16_t RegValue) {
269
-  LCD->REG = RegValue;
270
-  __DSB();
271
-
272
-  return LCD->RAM;
273
-}
274
-
275
-uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
276
-  volatile uint32_t data;
277
-  LCD->REG = RegValue;
278
-  __DSB();
279
-
280
-  data = LCD->RAM; // dummy read
281
-  data = LCD->RAM & 0x00FF;
282
-
283
-  while (--ReadSize) {
284
-    data <<= 8;
285
-    data |= (LCD->RAM & 0x00FF);
286
-  }
287
-  return uint32_t(data);
288
-}
289
-
290
-#ifdef LCD_USE_DMA_FSMC
291
-
292
-void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
293
-  while (count > 0) {
294
-    dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM);
295
-    dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count);
296
-    dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
297
-    dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
298
-
299
-    while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
300
-    dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
301
-
302
-    count = count > 65535 ? count - 65535 : 0;
303
-  }
304
-}
305
-
306
-void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
307
-  dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
308
-  dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
309
-  dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
310
-  dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
311
-
312
-  while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
313
-  dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
314
-}
315
-
316
-void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) {
317
-  dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
318
-  dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
319
-  dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
320
-  dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
321
-}
322
-
323
-void LCD_IO_WaitSequence_Async() {
324
-  while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
325
-  dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
326
-}
327
-
328
-#endif // LCD_USE_DMA_FSMC
329
-
330
-#endif // HAS_GRAPHICAL_LCD
331
-#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN

+ 0
- 236
Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp Ver arquivo

@@ -1,236 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
- *
18
- */
19
-#ifdef __STM32F1__
20
-
21
-#include "../../../inc/MarlinConfig.h"
22
-
23
-#if ENABLED(SPI_GRAPHICAL_TFT) && DISABLED(FORCE_SOFT_SPI)
24
-
25
-#include "../HAL.h"
26
-#include <U8glib.h>
27
-#include <SPI.h>
28
-
29
-#define SPI_TFT_CS_H  OUT_WRITE(SPI_TFT_CS_PIN, HIGH)
30
-#define SPI_TFT_CS_L  OUT_WRITE(SPI_TFT_CS_PIN, LOW)
31
-
32
-#define SPI_TFT_DC_H  OUT_WRITE(SPI_TFT_DC_PIN, HIGH)
33
-#define SPI_TFT_DC_L  OUT_WRITE(SPI_TFT_DC_PIN, LOW)
34
-
35
-#define SPI_TFT_RST_H OUT_WRITE(SPI_TFT_RST_PIN, HIGH)
36
-#define SPI_TFT_RST_L OUT_WRITE(SPI_TFT_RST_PIN, LOW)
37
-
38
-#define SPI_TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
39
-#define SPI_TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
40
-
41
-void LCD_IO_Init(uint8_t cs, uint8_t rs);
42
-void LCD_IO_WriteData(uint16_t RegValue);
43
-void LCD_IO_WriteReg(uint16_t Reg);
44
-uint16_t LCD_IO_ReadData(uint16_t RegValue);
45
-uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
46
-#ifdef LCD_USE_DMA_SPI
47
-  void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
48
-  void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
49
-#endif
50
-
51
-void LCD_WR_REG(uint8_t cmd) {
52
-  SPI_TFT_CS_L;
53
-  SPI_TFT_DC_L;
54
-  SPI.send(cmd);
55
-  SPI_TFT_CS_H;
56
-}
57
-void LCD_WR_DATA(uint8_t data) {
58
-  SPI_TFT_CS_L;
59
-  SPI_TFT_DC_H;
60
-  SPI.send(data);
61
-  SPI_TFT_CS_H;
62
-}
63
-
64
-void spi1Init(uint8_t spiRate) {
65
-  SPI_TFT_CS_H;
66
-
67
-  /**
68
-   * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
69
-   * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
70
-   * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
71
-   */
72
-  uint8_t clock;
73
-  switch (spiRate) {
74
-    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV4;  break;
75
-    case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4; break;
76
-    case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
77
-    case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
78
-    case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
79
-    case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
80
-    default:                clock = SPI_CLOCK_DIV2;        // Default from the SPI library
81
-  }
82
-  SPI.setModule(1);
83
-  SPI.begin();
84
-  SPI.setClockDivider(clock);
85
-  SPI.setBitOrder(MSBFIRST);
86
-  SPI.setDataMode(SPI_MODE0);
87
-}
88
-
89
-void LCD_IO_Init(uint8_t cs, uint8_t rs) {
90
-  spi1Init(SPI_FULL_SPEED);
91
-}
92
-
93
-void LCD_IO_WriteData(uint16_t RegValue) {
94
-  LCD_WR_DATA(RegValue);
95
-}
96
-
97
-void LCD_IO_WriteReg(uint16_t Reg) {
98
-  LCD_WR_REG(Reg);
99
-}
100
-
101
-uint16_t LCD_IO_ReadData(uint16_t RegValue) {
102
-  uint16_t d = 0;
103
-  SPI_TFT_CS_L;
104
-
105
-  SPI_TFT_DC_L;
106
-  SPI.send(RegValue);
107
-  SPI_TFT_DC_H;
108
-
109
-  SPI.read((uint8_t*)&d, 1); //dummy read
110
-  SPI.read((uint8_t*)&d, 1);
111
-
112
-  SPI_TFT_CS_H;
113
-  return d >> 7;
114
-}
115
-
116
-uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
117
-  uint32_t data = 0;
118
-  uint8_t d = 0;
119
-  SPI_TFT_CS_L;
120
-
121
-  SPI_TFT_DC_L;
122
-  SPI.send(RegValue);
123
-  SPI_TFT_DC_H;
124
-
125
-  SPI.read((uint8_t*)&d, 1); //dummy read
126
-  SPI.read((uint8_t*)&d, 1);
127
-  data = d;
128
-  while (--ReadSize) {
129
-    data <<= 8;
130
-    SPI.read((uint8_t*)&d, 1);
131
-    data |= (d & 0xFF);
132
-  }
133
-
134
-  SPI_TFT_CS_H;
135
-  return uint32_t(data >> 7);
136
-}
137
-
138
-#ifdef LCD_USE_DMA_SPI
139
-  void LCD_IO_WriteMultiple(uint16_t data, uint32_t count) {
140
-    if (SPI.getDataSize() == DATA_SIZE_8BIT) {
141
-      count *= 2;
142
-    }
143
-    while (count > 0) {
144
-      SPI_TFT_CS_L;
145
-      SPI_TFT_DC_H;
146
-      SPI.dmaSend(&data, 1, true);
147
-      SPI_TFT_CS_H;
148
-      count--;
149
-    }
150
-  }
151
-
152
-  void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
153
-    if (SPI.getDataSize() == DATA_SIZE_8BIT) {
154
-      length *= 2;
155
-    }
156
-    SPI_TFT_CS_L;
157
-    SPI_TFT_DC_H;
158
-    SPI.dmaSend(data, length, true);
159
-    SPI_TFT_CS_H;
160
-  }
161
-
162
-  void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) {
163
-    if (SPI.getDataSize() == DATA_SIZE_8BIT) {
164
-      length *= 2;
165
-    }
166
-    SPI_TFT_CS_L;
167
-    SPI_TFT_DC_H;
168
-    SPI.dmaSendAsync(data, length, true);
169
-    SPI_TFT_CS_H;
170
-  }
171
-
172
-  void LCD_IO_WaitSequence_Async() {
173
-    SPI_TFT_CS_L;
174
-    SPI_TFT_DC_H;
175
-    SPI.dmaSendAsync(NULL, 0, true);
176
-    SPI_TFT_CS_H;
177
-  }
178
-#endif
179
-
180
-static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
181
-
182
-#ifndef LCD_READ_ID
183
-  #define LCD_READ_ID 0x04   // Read display identification information (0xD3 on ILI9341)
184
-#endif
185
-
186
-uint8_t u8g_com_stm32duino_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
187
-  if (msgInitCount) {
188
-    if (msg == U8G_COM_MSG_INIT) msgInitCount--;
189
-    if (msgInitCount) return -1;
190
-  }
191
-
192
-  static uint8_t isCommand;
193
-
194
-  LCD_IO_Init(-1, -1);
195
-
196
-  switch (msg) {
197
-    case U8G_COM_MSG_STOP: break;
198
-    case U8G_COM_MSG_INIT:
199
-      u8g_SetPIOutput(u8g, U8G_PI_RESET);
200
-
201
-      u8g_Delay(50);
202
-
203
-      if (arg_ptr) {
204
-        spi1Init(SPI_EIGHTH_SPEED);
205
-        *((uint32_t *)arg_ptr) = (LCD_READ_ID << 24) | LCD_IO_ReadData(LCD_READ_ID, 3);
206
-        spi1Init(SPI_FULL_SPEED);
207
-      }
208
-      isCommand = 0;
209
-      break;
210
-
211
-    case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
212
-      isCommand = arg_val == 0 ? 1 : 0;
213
-      break;
214
-
215
-    case U8G_COM_MSG_RESET:
216
-      u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
217
-      break;
218
-
219
-    case U8G_COM_MSG_WRITE_BYTE:
220
-      if (isCommand)
221
-        LCD_IO_WriteReg(arg_val);
222
-      else
223
-        LCD_IO_WriteData((uint16_t)arg_val);
224
-      break;
225
-
226
-    case U8G_COM_MSG_WRITE_SEQ:
227
-      for (uint8_t i = 0; i < arg_val; i += 2)
228
-        LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
229
-      break;
230
-
231
-  }
232
-  return 1;
233
-}
234
-
235
-#endif // SPI_GRAPHICAL_TFT && !FORCE_SOFT_SPI
236
-#endif // STM32F1

+ 2
- 2
Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h Ver arquivo

@@ -26,8 +26,8 @@
26 26
   #undef SD_CHECK_AND_RETRY
27 27
 #endif
28 28
 
29
-// This platform has 'touch/xpt2046', not 'tft/xpt2046'
30
-#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT && !HAS_SPI_TFT
29
+// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
30
+#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
31 31
   #undef TOUCH_SCREEN
32 32
   #undef TOUCH_SCREEN_CALIBRATION
33 33
   #define HAS_TOUCH_XPT2046 1

+ 1
- 1
Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp Ver arquivo

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC)
25
+#if HAS_FSMC_TFT
26 26
 
27 27
 #include "tft_fsmc.h"
28 28
 #include <libmaple/fsmc.h>

+ 15
- 15
Marlin/src/HAL/STM32F1/tft/tft_spi.cpp Ver arquivo

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI)
25
+#if HAS_SPI_TFT
26 26
 
27 27
 #include "tft_spi.h"
28 28
 
@@ -30,32 +30,32 @@
30 30
 
31 31
 SPIClass TFT_SPI::SPIx(1);
32 32
 
33
-#define SPI_TFT_CS_H  OUT_WRITE(TFT_CS_PIN, HIGH)
34
-#define SPI_TFT_CS_L  OUT_WRITE(TFT_CS_PIN, LOW)
33
+#define TFT_CS_H  OUT_WRITE(TFT_CS_PIN, HIGH)
34
+#define TFT_CS_L  OUT_WRITE(TFT_CS_PIN, LOW)
35 35
 
36
-#define SPI_TFT_DC_H  OUT_WRITE(TFT_DC_PIN, HIGH)
37
-#define SPI_TFT_DC_L  OUT_WRITE(TFT_DC_PIN, LOW)
36
+#define TFT_DC_H  OUT_WRITE(TFT_DC_PIN, HIGH)
37
+#define TFT_DC_L  OUT_WRITE(TFT_DC_PIN, LOW)
38 38
 
39
-#define SPI_TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH)
40
-#define SPI_TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW)
39
+#define TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH)
40
+#define TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW)
41 41
 
42
-#define SPI_TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH)
43
-#define SPI_TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW)
42
+#define TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH)
43
+#define TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW)
44 44
 
45 45
 void TFT_SPI::Init() {
46 46
   #if PIN_EXISTS(TFT_RESET)
47 47
     // OUT_WRITE(TFT_RESET_PIN, HIGH);
48
-    SPI_TFT_RST_H;
48
+    TFT_RST_H;
49 49
     delay(100);
50 50
   #endif
51 51
 
52 52
   #if PIN_EXISTS(TFT_BACKLIGHT)
53 53
     // OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
54
-    SPI_TFT_BLK_H;
54
+    TFT_BLK_H;
55 55
   #endif
56 56
 
57
-  SPI_TFT_DC_H;
58
-  SPI_TFT_CS_H;
57
+  TFT_DC_H;
58
+  TFT_CS_H;
59 59
 
60 60
   /**
61 61
    * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
@@ -87,7 +87,7 @@ void TFT_SPI::Init() {
87 87
 void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
88 88
   SPIx.setDataSize(DataSize);
89 89
   SPIx.begin();
90
-  SPI_TFT_CS_L;
90
+  TFT_CS_L;
91 91
 }
92 92
 
93 93
 uint32_t TFT_SPI::GetID() {
@@ -135,7 +135,7 @@ void TFT_SPI::Transmit(uint16_t Data) {
135 135
 
136 136
 void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
137 137
   DataTransferBegin();
138
-  SPI_TFT_DC_H;
138
+  TFT_DC_H;
139 139
   if (MemoryIncrease == DMA_MINC_ENABLE) {
140 140
     SPIx.dmaSend(Data, Count, true);
141 141
   }

+ 1
- 1
Marlin/src/HAL/STM32F1/tft/xpt2046.cpp Ver arquivo

@@ -19,7 +19,7 @@
19 19
 
20 20
 #include "../../../inc/MarlinConfig.h"
21 21
 
22
-#if HAS_TFT_XPT2046
22
+#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046
23 23
 
24 24
 #include "xpt2046.h"
25 25
 #include <SPI.h>

+ 11
- 9
Marlin/src/HAL/STM32F1/tft/xpt2046.h Ver arquivo

@@ -24,16 +24,18 @@
24 24
   #include <SPI.h>
25 25
 #endif
26 26
 
27
-#if !PIN_EXISTS(TOUCH_MISO)
28
-  #error "TOUCH_MISO_PIN is not defined."
29
-#elif !PIN_EXISTS(TOUCH_MOSI)
30
-  #error "TOUCH_MOSI_PIN is not defined."
31
-#elif !PIN_EXISTS(TOUCH_SCK)
32
-  #error "TOUCH_SCK_PIN is not defined."
33
-#elif !PIN_EXISTS(TOUCH_CS)
34
-  #error "TOUCH_CS_PIN is not defined."
27
+#ifndef TOUCH_MISO_PIN
28
+  #define TOUCH_MISO_PIN MISO_PIN
29
+#endif
30
+#ifndef TOUCH_MOSI_PIN
31
+  #define TOUCH_MOSI_PIN MOSI_PIN
32
+#endif
33
+#ifndef TOUCH_SCK_PIN
34
+  #define TOUCH_SCK_PIN  SCK_PIN
35
+#endif
36
+#ifndef TOUCH_CS_PIN
37
+  #define TOUCH_CS_PIN   CS_PIN
35 38
 #endif
36
-
37 39
 #ifndef TOUCH_INT_PIN
38 40
   #define TOUCH_INT_PIN  -1
39 41
 #endif

+ 1
- 1
Marlin/src/MarlinCore.cpp Ver arquivo

@@ -57,7 +57,7 @@
57 57
 
58 58
 #include "lcd/ultralcd.h"
59 59
 #if HAS_TOUCH_XPT2046
60
-  #include "lcd/touch/xpt2046.h"
60
+  #include "lcd/touch/touch_buttons.h"
61 61
 #endif
62 62
 
63 63
 #if HAS_TFT_LVGL_UI

+ 5
- 4
Marlin/src/inc/Conditionals_LCD.h Ver arquivo

@@ -286,14 +286,15 @@
286 286
   #define DELAYED_BACKLIGHT_INIT
287 287
 #endif
288 288
 
289
-// FSMC/SPI TFT Panels (HAL STM32)
290
-#if EITHER(TFT_320x240, TFT_480x320)
289
+// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi).h
290
+#if ANY(TFT_320x240, TFT_480x320, TFT_LVGL_UI_FSMC, FSMC_GRAPHICAL_TFT)
291 291
   #define HAS_FSMC_TFT 1
292
-#elif EITHER(TFT_320x240_SPI, TFT_480x320_SPI)
292
+#elif ANY(TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_SPI, SPI_GRAPHICAL_TFT)
293 293
   #define HAS_SPI_TFT 1
294 294
 #endif
295 295
 
296
-#if HAS_FSMC_TFT || HAS_SPI_TFT
296
+// Color UI
297
+#if ANY(TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI)
297 298
   #define HAS_GRAPHICAL_TFT 1
298 299
   #define IS_ULTIPANEL
299 300
 #endif

+ 6
- 0
Marlin/src/inc/SanityCheck.h Ver arquivo

@@ -515,6 +515,12 @@
515 515
   #error "DIGIPOT_I2C is now DIGIPOT_MCP4451 (or DIGIPOT_MCP4018). Please update Configuration_adv.h."
516 516
 #elif defined(TOUCH_BUTTONS)
517 517
   #error "TOUCH_BUTTONS is now TOUCH_SCREEN. Please update your Configuration.h."
518
+#elif defined(LCD_FULL_PIXEL_HEIGHT)
519
+  #error "LCD_FULL_PIXEL_HEIGHT is deprecated and should be removed. Please update your Configuration.h."
520
+#elif defined(LCD_FULL_PIXEL_WIDTH)
521
+  #error "LCD_FULL_PIXEL_WIDTH is deprecated and should be removed. Please update your Configuration.h."
522
+#elif defined(FSMC_UPSCALE)
523
+  #error "FSMC_UPSCALE is now GRAPHICAL_TFT_UPSCALE. Please update your Configuration.h."
518 524
 #elif defined(ANYCUBIC_TFT_MODEL)
519 525
   #error "ANYCUBIC_TFT_MODEL is now ANYCUBIC_LCD_I3MEGA. Please update your Configuration.h."
520 526
 #elif defined(EVENT_GCODE_SD_STOP)

+ 5
- 10
Marlin/src/lcd/dogm/HAL_LCD_com_defines.h Ver arquivo

@@ -82,14 +82,9 @@
82 82
 
83 83
   #define U8G_COM_SSD_I2C_HAL         u8g_com_arduino_ssd_i2c_fn
84 84
 
85
-  #if PIN_EXISTS(FSMC_CS)
86
-    uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
87
-    #define U8G_COM_HAL_FSMC_FN       u8g_com_stm32duino_fsmc_fn
88
-  #endif
89
-
90
-  #if ENABLED(SPI_GRAPHICAL_TFT)
91
-    uint8_t u8g_com_stm32duino_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
92
-    #define U8G_COM_HAL_FSMC_FN       u8g_com_stm32duino_spi_fn
85
+  #if EITHER(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT)
86
+    uint8_t u8g_com_stm32duino_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
87
+    #define U8G_COM_HAL_TFT_FN       u8g_com_stm32duino_tft_fn
93 88
   #endif
94 89
 
95 90
 #elif defined(TARGET_LPC1768)
@@ -122,6 +117,6 @@
122 117
 #ifndef U8G_COM_SSD_I2C_HAL
123 118
   #define U8G_COM_SSD_I2C_HAL       u8g_com_null_fn
124 119
 #endif
125
-#ifndef U8G_COM_HAL_FSMC_FN
126
-  #define U8G_COM_HAL_FSMC_FN       u8g_com_null_fn
120
+#ifndef U8G_COM_HAL_TFT_FN
121
+  #define U8G_COM_HAL_TFT_FN       u8g_com_null_fn
127 122
 #endif

+ 105
- 64
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp Ver arquivo

@@ -67,28 +67,24 @@
67 67
   #define HAS_LCD_IO 1
68 68
 #endif
69 69
 
70
-#if HAS_LCD_IO
71
-  extern void LCD_IO_Init(uint8_t cs, uint8_t rs);
72
-  extern uint16_t LCD_IO_ReadData(uint16_t Reg);
73
-  extern uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
74
-  extern void LCD_IO_WriteReg(uint16_t Reg);
75
-  extern void LCD_IO_WriteData(uint16_t RegValue);
76
-  extern void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
77
-  extern void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length);
78
-  extern void LCD_IO_WaitSequence_Async();
79
-  extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
70
+#if ENABLED(SPI_GRAPHICAL_TFT)
71
+  #include HAL_PATH(../../HAL, tft/tft_spi.h)
72
+#elif ENABLED(FSMC_GRAPHICAL_TFT)
73
+  #include HAL_PATH(../../HAL, tft/tft_fsmc.h)
80 74
 #endif
81 75
 
76
+TFT_IO tftio;
77
+
82 78
 #define WIDTH  LCD_PIXEL_WIDTH
83 79
 #define HEIGHT LCD_PIXEL_HEIGHT
84 80
 #define PAGE_HEIGHT 8
85 81
 
86 82
 #include "../scaled_tft.h"
87 83
 
88
-#define UPSCALE0(M) ((M) * (FSMC_UPSCALE))
84
+#define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
89 85
 #define UPSCALE(A,M) (UPSCALE0(M) + (A))
90
-#define X_HI (UPSCALE(LCD_PIXEL_OFFSET_X, WIDTH) - 1)
91
-#define Y_HI (UPSCALE(LCD_PIXEL_OFFSET_Y, HEIGHT) - 1)
86
+#define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
87
+#define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
92 88
 
93 89
 // see https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
94 90
 
@@ -156,7 +152,8 @@ static uint32_t lcd_id = 0;
156 152
 
157 153
 static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
158 154
   #if HAS_LCD_IO
159
-    #define IO_REG_DATA(R,D) do { LCD_IO_WriteReg(R); LCD_IO_WriteData(D); }while(0)
155
+    tftio.DataTransferBegin(DATASIZE_8BIT);
156
+    #define IO_REG_DATA(R,D) do { tftio.WriteReg(R); tftio.WriteData(D); }while(0)
160 157
   #else
161 158
     #define IO_REG_DATA(R,D) do { u8g_WriteByte(u8g, dev, R); u8g_WriteSequence(u8g, dev, 2, (uint8_t *)&D); }while(0)
162 159
   #endif
@@ -174,7 +171,8 @@ static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_
174 171
   IO_REG_DATA(ILI9328_VASET,   Xmin);
175 172
 
176 173
   #if HAS_LCD_IO
177
-    LCD_IO_WriteReg(ILI9328_WRITE_RAM);
174
+    tftio.WriteReg(ILI9328_WRITE_RAM);
175
+    tftio.DataTransferEnd();
178 176
   #else
179 177
     u8g_WriteByte(u8g, dev, ILI9328_WRITE_RAM);
180 178
     u8g_SetAddress(u8g, dev, 1);
@@ -183,19 +181,21 @@ static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_
183 181
 
184 182
 static void setWindow_st7789v(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
185 183
   #if HAS_LCD_IO
186
-    LCD_IO_WriteReg(ST7789V_CASET);
187
-    LCD_IO_WriteData((Xmin >> 8) & 0xFF);
188
-    LCD_IO_WriteData(Xmin & 0xFF);
189
-    LCD_IO_WriteData((Xmax >> 8) & 0xFF);
190
-    LCD_IO_WriteData(Xmax & 0xFF);
191
-
192
-    LCD_IO_WriteReg(ST7789V_RASET);
193
-    LCD_IO_WriteData((Ymin >> 8) & 0xFF);
194
-    LCD_IO_WriteData(Ymin & 0xFF);
195
-    LCD_IO_WriteData((Ymax >> 8) & 0xFF);
196
-    LCD_IO_WriteData(Ymax & 0xFF);
197
-
198
-    LCD_IO_WriteReg(ST7789V_WRITE_RAM);
184
+    tftio.DataTransferBegin(DATASIZE_8BIT);
185
+    tftio.WriteReg(ST7789V_CASET);
186
+    tftio.WriteData((Xmin >> 8) & 0xFF);
187
+    tftio.WriteData(Xmin & 0xFF);
188
+    tftio.WriteData((Xmax >> 8) & 0xFF);
189
+    tftio.WriteData(Xmax & 0xFF);
190
+
191
+    tftio.WriteReg(ST7789V_RASET);
192
+    tftio.WriteData((Ymin >> 8) & 0xFF);
193
+    tftio.WriteData(Ymin & 0xFF);
194
+    tftio.WriteData((Ymax >> 8) & 0xFF);
195
+    tftio.WriteData(Ymax & 0xFF);
196
+
197
+    tftio.WriteReg(ST7789V_WRITE_RAM);
198
+    tftio.DataTransferEnd();
199 199
   #else
200 200
     u8g_SetAddress(u8g, dev, 0); u8g_WriteByte(u8g, dev, ST7789V_CASET); u8g_SetAddress(u8g, dev, 1);
201 201
     u8g_WriteByte(u8g, dev, (Xmin >> 8) & 0xFF);
@@ -227,17 +227,17 @@ void (*setWindow)(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint
227 227
     for (;;) {
228 228
       data = *sequence++;
229 229
       if (data != 0xFFFF) {
230
-        LCD_IO_WriteData(data);
230
+        tftio.WriteData(data);
231 231
         continue;
232 232
       }
233 233
       data = *sequence++;
234 234
       if (data == 0x7FFF) return;
235 235
       if (data == 0xFFFF) {
236
-        LCD_IO_WriteData(data);
236
+        tftio.WriteData(data);
237 237
       } else if (data & 0x8000) {
238 238
         delay(data & 0x7FFF);
239 239
       } else if ((data & 0xFF00) == 0) {
240
-        LCD_IO_WriteReg(data);
240
+        tftio.WriteReg(data);
241 241
       }
242 242
     }
243 243
   }
@@ -591,7 +591,7 @@ static const uint16_t st7796_init[] = {
591 591
   #define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1)
592 592
 
593 593
   void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
594
-    uint16_t buffer[BUTTON_SIZE_X * sq(FSMC_UPSCALE)];
594
+    uint16_t buffer[BUTTON_SIZE_X * sq(GRAPHICAL_TFT_UPSCALE)];
595 595
 
596 596
     if (length > BUTTON_SIZE_X) return;
597 597
 
@@ -603,16 +603,16 @@ static const uint16_t st7796_init[] = {
603 603
           v = color;
604 604
         else
605 605
           v = TFT_MARLINBG_COLOR;
606
-        LOOP_L_N(n, FSMC_UPSCALE) buffer[k++] = v;
606
+        LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = v;
607 607
       }
608 608
       #if HAS_LCD_IO
609
-        LOOP_S_L_N(n, 1, FSMC_UPSCALE)
609
+        LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
610 610
           for (uint16_t l = 0; l < UPSCALE0(length); l++)
611 611
             buffer[l + n * UPSCALE0(length)] = buffer[l];
612 612
 
613
-        LCD_IO_WriteSequence(buffer, length * sq(FSMC_UPSCALE));
613
+        tftio.WriteSequence(buffer, length * sq(GRAPHICAL_TFT_UPSCALE));
614 614
       #else
615
-        for (uint8_t i = FSMC_UPSCALE; i--;)
615
+        for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;)
616 616
           u8g_WriteSequence(u8g, dev, k << 1, (uint8_t*)buffer);
617 617
       #endif
618 618
     }
@@ -632,22 +632,17 @@ static uint8_t page;
632 632
 uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
633 633
   u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
634 634
 
635
-  #if ENABLED(SPI_GRAPHICAL_TFT)
636
-    LCD_IO_Init(-1, -1);
637
-  #endif
638
-
639 635
   #if HAS_LCD_IO
640
-    static uint16_t bufferA[WIDTH * sq(FSMC_UPSCALE)], bufferB[WIDTH * sq(FSMC_UPSCALE)];
636
+    static uint16_t bufferA[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)], bufferB[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)];
641 637
     uint16_t* buffer = &bufferA[0];
642
-    bool allow_async = DISABLED(SPI_GRAPHICAL_TFT);
643 638
   #else
644
-    uint16_t buffer[WIDTH * FSMC_UPSCALE]; // 16-bit RGB 565 pixel line buffer
639
+    uint16_t buffer[WIDTH * GRAPHICAL_TFT_UPSCALE]; // 16-bit RGB 565 pixel line buffer
645 640
   #endif
646 641
 
647 642
   switch (msg) {
648 643
     case U8G_DEV_MSG_INIT:
649 644
       dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, &lcd_id);
650
-
645
+      tftio.DataTransferBegin(DATASIZE_8BIT);
651 646
       switch (lcd_id & 0xFFFF) {
652 647
         case 0x8552:   // ST7789V
653 648
           WRITE_ESC_SEQUENCE(st7789v_init);
@@ -682,6 +677,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
682 677
           setWindow = (lcd_id & 0xFF000000) ? setWindow_st7789v : setWindow_ili9328;
683 678
           break;
684 679
       }
680
+      tftio.DataTransferEnd();
685 681
 
686 682
       if (preinit) {
687 683
         preinit = false;
@@ -689,13 +685,13 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
689 685
       }
690 686
 
691 687
       // Clear Screen
692
-      setWindow(u8g, dev, 0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
688
+      setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
693 689
       #if HAS_LCD_IO
694
-        LCD_IO_WriteMultiple(TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
690
+        tftio.WriteMultiple(TFT_MARLINBG_COLOR, uint32_t(TFT_WIDTH) * (TFT_HEIGHT));
695 691
       #else
696
-        memset2(buffer, TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) / 2);
697
-        for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT) * sq(FSMC_UPSCALE); i++)
698
-          u8g_WriteSequence(u8g, dev, LCD_FULL_PIXEL_WIDTH / 2, (uint8_t *)buffer);
692
+        memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2);
693
+        for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
694
+          u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
699 695
       #endif
700 696
 
701 697
       // Bottom buttons
@@ -719,7 +715,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
719 715
 
720 716
     case U8G_DEV_MSG_PAGE_FIRST:
721 717
       page = 0;
722
-      setWindow(u8g, dev, LCD_PIXEL_OFFSET_X, LCD_PIXEL_OFFSET_Y, X_HI, Y_HI);
718
+      setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
723 719
       break;
724 720
 
725 721
     case U8G_DEV_MSG_PAGE_NEXT:
@@ -733,26 +729,18 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
733 729
         for (uint16_t i = 0; i < (uint32_t)pb->width; i++) {
734 730
           const uint8_t b = *(((uint8_t *)pb->buf) + i);
735 731
           const uint16_t c = TEST(b, y) ? TFT_MARLINUI_COLOR : TFT_MARLINBG_COLOR;
736
-          LOOP_L_N(n, FSMC_UPSCALE) buffer[k++] = c;
732
+          LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = c;
737 733
         }
738 734
         #if HAS_LCD_IO
739
-          LOOP_S_L_N(n, 1, FSMC_UPSCALE)
735
+          LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
740 736
             for (uint16_t l = 0; l < UPSCALE0(WIDTH); l++)
741 737
               buffer[l + n * UPSCALE0(WIDTH)] = buffer[l];
742 738
 
743
-          if (allow_async) {
744
-            if (y > 0 || page > 1) LCD_IO_WaitSequence_Async();
745
-            if (y == 7 && page == 8)
746
-              LCD_IO_WriteSequence(buffer, COUNT(bufferA)); // last line of last page
747
-            else
748
-              LCD_IO_WriteSequence_Async(buffer, COUNT(bufferA));
749
-          }
750
-          else
751
-            LCD_IO_WriteSequence(buffer, COUNT(bufferA));
739
+          tftio.WriteSequence(buffer, COUNT(bufferA));
752 740
         #else
753 741
           uint8_t* bufptr = (uint8_t*) buffer;
754
-          for (uint8_t i = FSMC_UPSCALE; i--;) {
755
-            LOOP_S_L_N(n, 0, FSMC_UPSCALE * 2) {
742
+          for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;) {
743
+            LOOP_S_L_N(n, 0, GRAPHICAL_TFT_UPSCALE * 2) {
756 744
               u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH * n]);
757 745
             }
758 746
           }
@@ -770,6 +758,59 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
770 758
   return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
771 759
 }
772 760
 
773
-U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_FSMC_FN);
761
+static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
762
+
763
+uint8_t u8g_com_stm32duino_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
764
+  if (msgInitCount) {
765
+    if (msg == U8G_COM_MSG_INIT) msgInitCount--;
766
+    if (msgInitCount) return -1;
767
+  }
768
+
769
+  static uint8_t isCommand;
770
+
771
+  switch (msg) {
772
+    case U8G_COM_MSG_STOP: break;
773
+    case U8G_COM_MSG_INIT:
774
+      u8g_SetPIOutput(u8g, U8G_PI_RESET);
775
+
776
+      u8g_Delay(50);
777
+
778
+      tftio.Init();
779
+
780
+      if (arg_ptr) {
781
+        *((uint32_t *)arg_ptr) = tftio.GetID();
782
+      }
783
+      isCommand = 0;
784
+      break;
785
+
786
+    case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
787
+      isCommand = arg_val == 0 ? 1 : 0;
788
+      break;
789
+
790
+    case U8G_COM_MSG_RESET:
791
+      u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
792
+      break;
793
+
794
+    case U8G_COM_MSG_WRITE_BYTE:
795
+      tftio.DataTransferBegin(DATASIZE_8BIT);
796
+      if (isCommand)
797
+        tftio.WriteReg(arg_val);
798
+      else
799
+        tftio.WriteData((uint16_t)arg_val);
800
+      tftio.DataTransferEnd();
801
+      break;
802
+
803
+    case U8G_COM_MSG_WRITE_SEQ:
804
+      tftio.DataTransferBegin(DATASIZE_8BIT);
805
+      for (uint8_t i = 0; i < arg_val; i += 2)
806
+        tftio.WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
807
+      tftio.DataTransferEnd();
808
+      break;
809
+
810
+  }
811
+  return 1;
812
+}
813
+
814
+U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN);
774 815
 
775 816
 #endif // HAS_GRAPHICAL_LCD && FSMC_CS

+ 10
- 29
Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp Ver arquivo

@@ -33,25 +33,6 @@
33 33
 
34 34
 TFT SPI_TFT;
35 35
 
36
-#ifndef SPI_TFT_MISO_PIN
37
-  #define SPI_TFT_MISO_PIN PA6
38
-#endif
39
-#ifndef SPI_TFT_MOSI_PIN
40
-  #define SPI_TFT_MOSI_PIN PA7
41
-#endif
42
-#ifndef SPI_TFT_SCK_PIN
43
-  #define SPI_TFT_SCK_PIN  PA5
44
-#endif
45
-#ifndef SPI_TFT_CS_PIN
46
-  #define SPI_TFT_CS_PIN   PD11
47
-#endif
48
-#ifndef SPI_TFT_DC_PIN
49
-  #define SPI_TFT_DC_PIN   PD10
50
-#endif
51
-#ifndef SPI_TFT_RST_PIN
52
-  #define SPI_TFT_RST_PIN  PC6
53
-#endif
54
-
55 36
 // use SPI1 for the spi tft.
56 37
 void TFT::spi_init(uint8_t spiRate) {
57 38
   tftio.Init();
@@ -93,11 +74,11 @@ void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
93 74
 }
94 75
 
95 76
 void TFT::LCD_init() {
96
-  SPI_TFT_RST_H;
77
+  TFT_RST_H;
97 78
   delay(150);
98
-  SPI_TFT_RST_L;
79
+  TFT_RST_L;
99 80
   delay(150);
100
-  SPI_TFT_RST_H;
81
+  TFT_RST_H;
101 82
 
102 83
   tftio.DataTransferBegin(DATASIZE_8BIT);
103 84
 
@@ -176,22 +157,22 @@ void TFT::LCD_init() {
176 157
 
177 158
   LCD_clear(0x0000);    //
178 159
   LCD_Draw_Logo();
179
-  SPI_TFT_BLK_H;
160
+  TFT_BLK_H;
180 161
   delay(2000);
181 162
 }
182 163
 
183 164
 void TFT::LCD_clear(uint16_t color) {
184
-  SetWindows(0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
185
-  tftio.WriteMultiple(color, (uint32_t)(LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
165
+  SetWindows(0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
166
+  tftio.WriteMultiple(color, (uint32_t)(TFT_WIDTH) * (TFT_HEIGHT));
186 167
 }
187 168
 
188 169
 extern unsigned char bmp_public_buf[17 * 1024];
189 170
 
190 171
 void TFT::LCD_Draw_Logo() {
191
-  SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
192
-  for (uint16_t i = 0; i < (LCD_FULL_PIXEL_HEIGHT); i ++) {
193
-    Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (LCD_FULL_PIXEL_WIDTH) * 2);
194
-    tftio.WriteSequence((uint16_t *)bmp_public_buf, LCD_FULL_PIXEL_WIDTH);
172
+  SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
173
+  for (uint16_t i = 0; i < (TFT_HEIGHT); i ++) {
174
+    Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, (TFT_WIDTH) * 2);
175
+    tftio.WriteSequence((uint16_t *)bmp_public_buf, TFT_WIDTH);
195 176
   }
196 177
 }
197 178
 

+ 4
- 4
Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h Ver arquivo

@@ -29,11 +29,11 @@
29 29
   #include HAL_PATH(../../HAL, tft/tft_fsmc.h)
30 30
 #endif
31 31
 
32
-#define SPI_TFT_RST_H OUT_WRITE(SPI_TFT_RST_PIN, HIGH)
33
-#define SPI_TFT_RST_L OUT_WRITE(SPI_TFT_RST_PIN, LOW)
32
+#define TFT_RST_H OUT_WRITE(TFT_RESET_PIN, HIGH)
33
+#define TFT_RST_L OUT_WRITE(TFT_RESET_PIN, LOW)
34 34
 
35
-#define SPI_TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
36
-#define SPI_TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
35
+#define TFT_BLK_H OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH)
36
+#define TFT_BLK_L OUT_WRITE(LCD_BACKLIGHT_PIN, LOW)
37 37
 
38 38
 class TFT {
39 39
 public:

+ 3
- 3
Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp Ver arquivo

@@ -653,10 +653,10 @@ char *creat_title_text() {
653 653
             i       += 2;
654 654
             if (*p_index == 0x0000) *p_index = 0xC318;
655 655
           }
656
-          SPI_TFT_CS_L;
657
-          SPI_TFT_DC_H;
656
+          TFT_CS_L;
657
+          TFT_DC_H;
658 658
           SPI.dmaSend(bmp_public_buf, 400, true);
659
-          SPI_TFT_CS_H;
659
+          TFT_CS_H;
660 660
 
661 661
         #else
662 662
           for (i = 0; i < 400;) {

+ 0
- 2
Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp Ver arquivo

@@ -34,8 +34,6 @@
34 34
 #include "pic_manager.h"
35 35
 #include <lvgl.h>
36 36
 
37
-#include "../../../touch/xpt2046.h"
38
-
39 37
 #include "../../../../MarlinCore.h"
40 38
 #include "../../../../module/temperature.h"
41 39
 #include "../../../../sd/cardreader.h"

+ 15
- 15
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp Ver arquivo

@@ -51,11 +51,11 @@ XPT2046 touch;
51 51
 
52 52
 #include <SPI.h>
53 53
 
54
-#ifndef LCD_FULL_PIXEL_WIDTH
55
-  #define LCD_FULL_PIXEL_WIDTH  480
54
+#ifndef TFT_WIDTH
55
+  #define TFT_WIDTH  480
56 56
 #endif
57
-#ifndef LCD_FULL_PIXEL_HEIGHT
58
-  #define LCD_FULL_PIXEL_HEIGHT 320
57
+#ifndef TFT_HEIGHT
58
+  #define TFT_HEIGHT 320
59 59
 #endif
60 60
 
61 61
 #if HAS_SPI_FLASH_FONT
@@ -135,7 +135,7 @@ void LCD_WriteRAM_Prepare(void) {
135 135
 
136 136
 void tft_set_point(uint16_t x, uint16_t y, uint16_t point) {
137 137
   //if (DeviceCode == 0x9488) {
138
-  if (x > (LCD_FULL_PIXEL_WIDTH) || y > (LCD_FULL_PIXEL_HEIGHT)) return;
138
+  if (x > (TFT_WIDTH) || y > (TFT_HEIGHT)) return;
139 139
   //}
140 140
   tft_set_cursor(x, y);
141 141
 
@@ -196,8 +196,8 @@ void ili9320_SetWindows(uint16_t StartX, uint16_t StartY, uint16_t width, uint16
196 196
      LCD_WriteReg(0x0053, yEnd);*/
197 197
     LCD_WriteReg(0x0050, StartY);   // Specify the start/end positions of the window address in the horizontal direction by an address unit
198 198
     LCD_WriteReg(0x0051, yEnd);     // Specify the start positions of the window address in the vertical direction by an address unit
199
-    LCD_WriteReg(0x0052, (LCD_FULL_PIXEL_HEIGHT) - xEnd);
200
-    LCD_WriteReg(0x0053, (LCD_FULL_PIXEL_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
199
+    LCD_WriteReg(0x0052, (TFT_HEIGHT) - xEnd);
200
+    LCD_WriteReg(0x0053, (TFT_HEIGHT) - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
201 201
 
202 202
   }
203 203
   else {
@@ -231,16 +231,16 @@ void LCD_Clear(uint16_t Color) {
231 231
 
232 232
   if (DeviceCode == 0x9488) {
233 233
     tft_set_cursor(0, 0);
234
-    ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
234
+    ili9320_SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
235 235
     LCD_WriteRAM_Prepare();
236 236
     #ifdef LCD_USE_DMA_FSMC
237
-      LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
237
+      LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
238 238
     #else
239
-      //index = (LCD_FULL_PIXEL_HEIGHT) / 2 * (LCD_FULL_PIXEL_WIDTH);
240
-      for (index = 0; index < (LCD_FULL_PIXEL_HEIGHT) * (LCD_FULL_PIXEL_WIDTH); index++)
239
+      //index = (TFT_HEIGHT) / 2 * (TFT_WIDTH);
240
+      for (index = 0; index < (TFT_HEIGHT) * (TFT_WIDTH); index++)
241 241
         LCD_IO_WriteData(Color);
242 242
     #endif
243
-    //LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
243
+    //LCD_IO_WriteMultiple(Color, (TFT_WIDTH) * (TFT_HEIGHT));
244 244
     //while(index --) LCD_IO_WriteData(Color);
245 245
   }
246 246
   else if (DeviceCode == 0x5761) {
@@ -378,7 +378,7 @@ void init_tft() {
378 378
     for (i = 0; i < 65535; i++);
379 379
     LCD_IO_WriteReg(0x0029);
380 380
 
381
-    ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
381
+    ili9320_SetWindows(0, 0, TFT_WIDTH, TFT_HEIGHT);
382 382
     LCD_Clear(0x0000);
383 383
 
384 384
     OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
@@ -522,8 +522,8 @@ static bool get_point(int16_t *x, int16_t *y) {
522 522
   }
523 523
 
524 524
   #if ENABLED(GRAPHICAL_TFT_ROTATE_180)
525
-    x = (LCD_FULL_PIXEL_WIDTH) - x;
526
-    y = (LCD_FULL_PIXEL_HEIGHT) - y;
525
+    x = (TFT_WIDTH) - x;
526
+    y = (TFT_HEIGHT) - y;
527 527
   #endif
528 528
 
529 529
   return is_touched;

+ 14
- 14
Marlin/src/lcd/scaled_tft.h Ver arquivo

@@ -23,28 +23,28 @@
23 23
 
24 24
 #include "../inc/MarlinConfig.h"
25 25
 
26
-#ifndef FSMC_UPSCALE
27
-  #define FSMC_UPSCALE 2
26
+#ifndef GRAPHICAL_TFT_UPSCALE
27
+  #define GRAPHICAL_TFT_UPSCALE 2
28 28
 #endif
29 29
 
30
-#ifndef LCD_FULL_PIXEL_WIDTH
31
-  #if FSMC_UPSCALE == 3
32
-    #define LCD_FULL_PIXEL_WIDTH 480
30
+#ifndef TFT_WIDTH
31
+  #if GRAPHICAL_TFT_UPSCALE == 3
32
+    #define TFT_WIDTH 480
33 33
   #else
34
-    #define LCD_FULL_PIXEL_WIDTH 320
34
+    #define TFT_WIDTH 320
35 35
   #endif
36 36
 #endif
37
-#ifndef LCD_FULL_PIXEL_HEIGHT
38
-  #if FSMC_UPSCALE == 3
39
-    #define LCD_FULL_PIXEL_HEIGHT 320
37
+#ifndef TFT_HEIGHT
38
+  #if GRAPHICAL_TFT_UPSCALE == 3
39
+    #define TFT_HEIGHT 320
40 40
   #else
41
-    #define LCD_FULL_PIXEL_HEIGHT 240
41
+    #define TFT_HEIGHT 240
42 42
   #endif
43 43
 #endif
44 44
 
45
-#ifndef LCD_PIXEL_OFFSET_X
46
-  #define LCD_PIXEL_OFFSET_X 48
45
+#ifndef TFT_PIXEL_OFFSET_X
46
+  #define TFT_PIXEL_OFFSET_X 48
47 47
 #endif
48
-#ifndef LCD_PIXEL_OFFSET_Y
49
-  #define LCD_PIXEL_OFFSET_Y 48
48
+#ifndef TFT_PIXEL_OFFSET_Y
49
+  #define TFT_PIXEL_OFFSET_Y 48
50 50
 #endif

+ 112
- 0
Marlin/src/lcd/touch/touch_buttons.cpp Ver arquivo

@@ -0,0 +1,112 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+#include "../../inc/MarlinConfig.h"
21
+
22
+#if HAS_TOUCH_XPT2046
23
+
24
+#include "touch_buttons.h"
25
+#include "../scaled_tft.h"
26
+
27
+#include HAL_PATH(../../HAL, tft/xpt2046.h)
28
+XPT2046 touchIO;
29
+
30
+#include "../../lcd/ultralcd.h" // For EN_C bit mask
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))
67
+
68
+// Coordinates in terms of 240-unit-tall touch area
69
+#define BUTTON_AREA_TOP 175
70
+#define BUTTON_AREA_BOT 234
71
+
72
+TouchButtons touch;
73
+
74
+void TouchButtons::init() { touchIO.Init(); }
75
+
76
+uint8_t TouchButtons::read_buttons() {
77
+  #ifdef HAS_SPI_LCD
78
+    int16_t x, y;
79
+
80
+    if (!touchIO.getRawPoint(&x, &y)) return 0;
81
+
82
+    x = uint16_t((uint32_t(x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET;
83
+    y = uint16_t((uint32_t(y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
84
+
85
+    #if ENABLED(GRAPHICAL_TFT_ROTATE_180)
86
+      x = TOUCH_SENSOR_WIDTH - x;
87
+      y = TOUCH_SENSOR_HEIGHT - y;
88
+    #endif
89
+
90
+    // Touch within the button area simulates an encoder button
91
+    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
96
+           : 0;
97
+
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)
100
+    ) return 0;
101
+
102
+    // 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);
105
+
106
+    // Send the touch to the UI (which will simulate the encoder wheel)
107
+    MarlinUI::screen_click(row, col, x, y);
108
+  #endif
109
+  return 0;
110
+}
111
+
112
+#endif // HAS_TOUCH_XPT2046

Marlin/src/lcd/touch/xpt2046.h → Marlin/src/lcd/touch/touch_buttons.h Ver arquivo

@@ -20,30 +20,10 @@
20 20
 
21 21
 #include <stdint.h>
22 22
 
23
-// Relies on XPT2046-compatible mode of ADS7843,
24
-// hence no Z1 / Z2 measurements are possible.
25
-
26
-#define XPT2046_DFR_MODE 0x00
27
-#define XPT2046_SER_MODE 0x04
28
-#define XPT2046_CONTROL  0x80
29
-
30
-enum XPTCoordinate : uint8_t {
31
-  XPT2046_X  = 0x10,
32
-  XPT2046_Y  = 0x50,
33
-  XPT2046_Z1 = 0x30,
34
-  XPT2046_Z2 = 0x40
35
-};
36
-
37
-class XPT2046 {
23
+class TouchButtons {
38 24
 public:
39 25
   static void init();
40 26
   static uint8_t read_buttons();
41
-  bool getTouchPoint(uint16_t &x, uint16_t &y);
42
-  static bool isTouched();
43
-  inline void waitForRelease() { while (isTouched()) { /* nada */ } }
44
-  inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } }
45
-private:
46
-  static uint16_t getInTouch(const XPTCoordinate coordinate);
47 27
 };
48 28
 
49
-extern XPT2046 touch;
29
+extern TouchButtons touch;

+ 0
- 251
Marlin/src/lcd/touch/xpt2046.cpp Ver arquivo

@@ -1,251 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
- *
18
- */
19
-
20
-#include "../../inc/MarlinConfig.h"
21
-
22
-#if HAS_TOUCH_XPT2046
23
-
24
-#include "xpt2046.h"
25
-#include "../scaled_tft.h"
26
-
27
-#ifndef XPT2046_Z1_THRESHOLD
28
-  #define XPT2046_Z1_THRESHOLD 10
29
-#endif
30
-
31
-/**
32
- * Draw and Touch processing
33
- *
34
- *      LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
35
- *   TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
36
- * LCD_FULL_PIXEL_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
37
- *
38
- *  - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
39
- *  - The DOGM pixels are is upscaled 2-3x (as needed) for display.
40
- *  - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to
41
- *    click and scroll-wheel events (emulating of a common DOGM display).
42
- *
43
- *  TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
44
- *  and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
45
- *  new calibration values will be needed.
46
- *
47
- *  The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
48
- *  fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
49
- *  navigate and select menu items. Both regions are touchable.
50
- *
51
- * The Marlin screen touchable area starts at LCD_PIXEL_OFFSET_X/Y (translated to SCREEN_START_LEFT/TOP)
52
- * and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_WIDTH/HEIGHT).
53
- */
54
-
55
-// Coordinates in terms of touch area
56
-#define BUTTON_AREA_TOP 175
57
-#define BUTTON_AREA_BOT 234
58
-
59
-// Touch sensor resolution independent of display resolution
60
-#define TOUCH_SENSOR_WIDTH  320
61
-#define TOUCH_SENSOR_HEIGHT 240
62
-
63
-#define SCREEN_WIDTH_PCT(X) ((X) * (TOUCH_SENSOR_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
64
-#define SCREEN_HEIGHT_PCT(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
65
-
66
-#define SCREEN_START_LEFT SCREEN_WIDTH_PCT(LCD_PIXEL_OFFSET_X)
67
-#define SCREEN_START_TOP  SCREEN_HEIGHT_PCT(LCD_PIXEL_OFFSET_Y)
68
-#define SCREEN_WIDTH      SCREEN_WIDTH_PCT((LCD_PIXEL_WIDTH) * (FSMC_UPSCALE))
69
-#define SCREEN_HEIGHT     SCREEN_HEIGHT_PCT((LCD_PIXEL_HEIGHT) * (FSMC_UPSCALE))
70
-
71
-#define TOUCHABLE_X_WIDTH  SCREEN_WIDTH
72
-#define TOUCHABLE_Y_HEIGHT SCREEN_HEIGHT
73
-
74
-#ifndef TOUCH_INT_PIN
75
-  #define TOUCH_INT_PIN  -1
76
-#endif
77
-#ifndef TOUCH_MISO_PIN
78
-  #define TOUCH_MISO_PIN MISO_PIN
79
-#endif
80
-#ifndef TOUCH_MOSI_PIN
81
-  #define TOUCH_MOSI_PIN MOSI_PIN
82
-#endif
83
-#ifndef TOUCH_SCK_PIN
84
-  #define TOUCH_SCK_PIN  SCK_PIN
85
-#endif
86
-#ifndef TOUCH_CS_PIN
87
-  #define TOUCH_CS_PIN   CS_PIN
88
-#endif
89
-
90
-XPT2046 touch;
91
-
92
-void XPT2046::init() {
93
-  SET_INPUT(TOUCH_MISO_PIN);
94
-  SET_OUTPUT(TOUCH_MOSI_PIN);
95
-  SET_OUTPUT(TOUCH_SCK_PIN);
96
-  OUT_WRITE(TOUCH_CS_PIN, HIGH);
97
-
98
-  #if PIN_EXISTS(TOUCH_INT)
99
-    // Optional Pendrive interrupt pin
100
-    SET_INPUT(TOUCH_INT_PIN);
101
-  #endif
102
-
103
-  // Read once to enable pendrive status pin
104
-  getInTouch(XPT2046_X);
105
-}
106
-
107
-#include "../../lcd/ultralcd.h" // For EN_C bit mask
108
-
109
-uint8_t XPT2046::read_buttons() {
110
-  #ifdef HAS_SPI_LCD
111
-    int16_t tsoffsets[4] = { 0 };
112
-
113
-    if (tsoffsets[0] + tsoffsets[1] == 0) {
114
-      // Not yet set, so use defines as fallback...
115
-      tsoffsets[0] = XPT2046_X_CALIBRATION;
116
-      tsoffsets[1] = XPT2046_X_OFFSET;
117
-      tsoffsets[2] = XPT2046_Y_CALIBRATION;
118
-      tsoffsets[3] = XPT2046_Y_OFFSET;
119
-    }
120
-
121
-    // We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
122
-
123
-    if (!isTouched()) return 0;
124
-    uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
125
-             y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
126
-    if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
127
-
128
-    #if ENABLED(GRAPHICAL_TFT_ROTATE_180)
129
-      x = TOUCH_SENSOR_WIDTH - x;
130
-      y = TOUCH_SENSOR_HEIGHT - y;
131
-    #endif
132
-
133
-    // Touch within the button area simulates an encoder button
134
-    if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
135
-      return WITHIN(x,  14,  77) ? EN_D
136
-           : WITHIN(x,  90, 153) ? EN_A
137
-           : WITHIN(x, 166, 229) ? EN_B
138
-           : WITHIN(x, 242, 305) ? EN_C
139
-           : 0;
140
-
141
-    if ( !WITHIN(x, SCREEN_START_LEFT, SCREEN_START_LEFT + SCREEN_WIDTH)
142
-      || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)
143
-    ) return 0;
144
-
145
-    // Column and row above BUTTON_AREA_TOP
146
-    int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
147
-           row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
148
-
149
-    // Send the touch to the UI (which will simulate the encoder wheel)
150
-    MarlinUI::screen_click(row, col, x, y);
151
-  #endif
152
-  return 0;
153
-}
154
-
155
-bool XPT2046::isTouched() {
156
-  return (
157
-    #if PIN_EXISTS(TOUCH_INT)
158
-      READ(TOUCH_INT_PIN) != HIGH
159
-    #else
160
-      getInTouch(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
161
-    #endif
162
-  );
163
-}
164
-
165
-#if ENABLED(TOUCH_BUTTONS_HW_SPI)
166
-
167
-  #include <SPI.h>
168
-
169
-  static void touch_spi_init(uint8_t spiRate) {
170
-    /**
171
-     * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
172
-     * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
173
-     * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
174
-     */
175
-    uint8_t clock;
176
-    switch (spiRate) {
177
-      case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV4;  break;
178
-      case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4; break;
179
-      case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
180
-      case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
181
-      case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
182
-      case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
183
-      default:                clock = SPI_CLOCK_DIV2;        // Default from the SPI library
184
-    }
185
-    SPI.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
186
-    SPI.begin();
187
-    SPI.setClockDivider(clock);
188
-    SPI.setBitOrder(MSBFIRST);
189
-    SPI.setDataMode(SPI_MODE0);
190
-  }
191
-#endif // TOUCH_BUTTONS_HW_SPI
192
-
193
-uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
194
-  uint16_t data[3];
195
-  const uint8_t coord = uint8_t(coordinate) | XPT2046_CONTROL | XPT2046_DFR_MODE;
196
-
197
-  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
198
-
199
-    touch_spi_init(SPI_SPEED_6);
200
-    for (uint16_t i = 0; i < 3; i++) {
201
-      OUT_WRITE(TOUCH_CS_PIN, LOW);
202
-      SPI.transfer(coord);
203
-      data[i] = (((SPI.transfer(0xFF) << 8) | SPI.transfer(0xFF)) >> 3) & 0x0FFF;
204
-      WRITE(TOUCH_CS_PIN, HIGH);
205
-    }
206
-
207
-  #else // !TOUCH_BUTTONS_HW_SPI
208
-
209
-    OUT_WRITE(TOUCH_CS_PIN, LOW);
210
-    for (uint16_t i = 0; i < 3; i++) {
211
-      for (uint8_t j = 0x80; j; j >>= 1) {
212
-        WRITE(TOUCH_SCK_PIN, LOW);
213
-        WRITE(TOUCH_MOSI_PIN, bool(coord & j));
214
-        WRITE(TOUCH_SCK_PIN, HIGH);
215
-      }
216
-
217
-      data[i] = 0;
218
-      for (uint16_t j = 0x8000; j; j >>= 1) {
219
-        WRITE(TOUCH_SCK_PIN, LOW);
220
-        if (READ(TOUCH_MISO_PIN)) data[i] |= j;
221
-        WRITE(TOUCH_SCK_PIN, HIGH);
222
-      }
223
-      WRITE(TOUCH_SCK_PIN, LOW);
224
-      data[i] >>= 4;
225
-    }
226
-    WRITE(TOUCH_CS_PIN, HIGH);
227
-
228
-  #endif // !TOUCH_BUTTONS_HW_SPI
229
-
230
-  uint16_t delta01 = _MAX(data[0], data[1]) - _MIN(data[0], data[1]),
231
-           delta02 = _MAX(data[0], data[2]) - _MIN(data[0], data[2]),
232
-           delta12 = _MAX(data[1], data[2]) - _MIN(data[1], data[2]);
233
-
234
-  if (delta01 <= delta02 && delta01 <= delta12)
235
-    return (data[0] + data[1]) >> 1;
236
-
237
-  if (delta02 <= delta12)
238
-    return (data[0] + data[2]) >> 1;
239
-
240
-  return (data[1] + data[2]) >> 1;
241
-}
242
-
243
-bool XPT2046::getTouchPoint(uint16_t &x, uint16_t &y) {
244
-  if (isTouched()) {
245
-    x = getInTouch(XPT2046_X);
246
-    y = getInTouch(XPT2046_Y);
247
-  }
248
-  return isTouched();
249
-}
250
-
251
-#endif // HAS_TOUCH_XPT2046

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp Ver arquivo

@@ -150,7 +150,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
150 150
     volatile uint8_t MarlinUI::slow_buttons;
151 151
   #endif
152 152
   #if HAS_TOUCH_XPT2046
153
-    #include "touch/xpt2046.h"
153
+    #include "touch/touch_buttons.h"
154 154
     bool MarlinUI::on_edit_screen = false;
155 155
   #endif
156 156
 #endif

+ 48
- 83
Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h Ver arquivo

@@ -44,7 +44,7 @@
44 44
   #define EEPROM_PAGE_SIZE     (0x800U)           // 2KB, but will use 2x more (4KB)
45 45
   #define MARLIN_EEPROM_SIZE    EEPROM_PAGE_SIZE
46 46
 #else
47
-  #define MARLIN_EEPROM_SIZE 0x800U               // On SD, Limit to 2KB, require this amount of RAM
47
+  #define MARLIN_EEPROM_SIZE              0x800U  // On SD, Limit to 2KB, require this amount of RAM
48 48
 #endif
49 49
 
50 50
 //
@@ -104,49 +104,6 @@
104 104
 //#define POWER_LOSS_PIN                    -1
105 105
 #define FIL_RUNOUT_PIN                      PA15
106 106
 
107
-//
108
-// TronXY TFT Support
109
-//
110
-//#define FSMC_GRAPHICAL_TFT
111
-//#define HAS_TOUCH_XPT2046 1
112
-
113
-#if ENABLED(FSMC_GRAPHICAL_TFT)
114
-  #define FSMC_UPSCALE 3
115
-
116
-  #define LCD_RESET_PIN                     PF11
117
-  #define LCD_BACKLIGHT_PIN                 PD13
118
-  #define FSMC_CS_PIN                       PD7
119
-  #define FSMC_RS_PIN                       PD11
120
-
121
-  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
122
-  #define FSMC_DMA_DEV                      DMA2
123
-  #define FSMC_DMA_CHANNEL               DMA_CH5
124
-
125
-  #if NEED_TOUCH_PINS
126
-    #define TOUCH_CS_PIN                    PB7   // SPI1_NSS
127
-    #define TOUCH_SCK_PIN                   PA5   // SPI1_SCK
128
-    #define TOUCH_MISO_PIN                  PA6   // SPI1_MISO
129
-    #define TOUCH_MOSI_PIN                  PA7   // SPI1_MOSI
130
-
131
-    #define BUTTON_DELAY_EDIT 50                  // (ms) Button repeat delay for edit screens
132
-    #define BUTTON_DELAY_MENU 250                 // (ms) Button repeat delay for menus
133
-
134
-    #ifndef XPT2046_X_CALIBRATION
135
-      #define XPT2046_X_CALIBRATION       -12316
136
-    #endif
137
-    #ifndef XPT2046_Y_CALIBRATION
138
-      #define XPT2046_Y_CALIBRATION         8981
139
-    #endif
140
-    #ifndef XPT2046_X_OFFSET
141
-      #define XPT2046_X_OFFSET               340
142
-    #endif
143
-    #ifndef XPT2046_Y_OFFSET
144
-      #define XPT2046_Y_OFFSET               -20
145
-    #endif
146
-
147
-  #endif
148
-#endif
149
-
150 107
 // SPI Flash
151 108
 #define SPI_FLASH_SIZE                  0x200000  // 2MB
152 109
 #define HAS_SPI_FLASH                          1
@@ -157,28 +114,18 @@
157 114
 #define W25QXX_MISO_PIN                     PB14
158 115
 #define W25QXX_SCK_PIN                      PB13
159 116
 
160
-#if HAS_TFT_LVGL_UI
161
-  #define HAS_SPI_FLASH_FONT                1
162
-  #define HAS_GCODE_PREVIEW                 1
163
-  #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH   0
164
-  #define HAS_LANG_SELECT_SCREEN            1
165
-  #define HAS_BAK_VIEW_IN_FLASH             0
166
-  #define HAS_LOGO_IN_FLASH                 0
117
+//
118
+// TronXY TFT Support
119
+//
120
+
121
+#if HAS_FSMC_TFT
122
+
123
+  // Shared FSMC
167 124
 
168 125
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
169 126
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
170 127
   #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
171 128
   #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
172
-  //#define TOUCH_INT_PIN                   PB6
173
-
174
-  #if ENABLED(TFT_LVGL_UI_SPI)
175
-    #define SPI_TFT_CS_PIN          TOUCH_CS_PIN
176
-    #define SPI_TFT_SCK_PIN        TOUCH_SCK_PIN
177
-    #define SPI_TFT_MISO_PIN      TOUCH_MISO_PIN
178
-    #define SPI_TFT_MOSI_PIN      TOUCH_MOSI_PIN
179
-    #define SPI_TFT_DC_PIN                  PB6
180
-    #define SPI_TFT_RST_PIN                 PF11
181
-  #endif
182 129
 
183 130
   #define LCD_RESET_PIN                     PF11
184 131
   #define LCD_BACKLIGHT_PIN                 PD13
@@ -191,12 +138,23 @@
191 138
   #define FSMC_DMA_DEV                      DMA2
192 139
   #define FSMC_DMA_CHANNEL               DMA_CH5
193 140
 
194
-  #define LCD_PIXEL_WIDTH       480
195
-  #define LCD_PIXEL_HEIGHT      320
196
-  #define LCD_FULL_PIXEL_WIDTH  LCD_PIXEL_WIDTH
197
-  #define LCD_FULL_PIXEL_HEIGHT LCD_PIXEL_HEIGHT
198
-  #define LCD_PIXEL_OFFSET_X     48
199
-  #define LCD_PIXEL_OFFSET_Y     48
141
+  #define TFT_WIDTH                          480
142
+  #define TFT_HEIGHT                         320
143
+  #define TFT_PIXEL_OFFSET_X                  48
144
+  #define TFT_PIXEL_OFFSET_Y                  32
145
+
146
+#endif
147
+
148
+#if HAS_TFT_LVGL_UI
149
+
150
+  // LVGL
151
+
152
+  #define HAS_SPI_FLASH_FONT                   1
153
+  #define HAS_GCODE_PREVIEW                    1
154
+  #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH      0
155
+  #define HAS_LANG_SELECT_SCREEN               1
156
+  #define HAS_BAK_VIEW_IN_FLASH                0
157
+  #define HAS_LOGO_IN_FLASH                    0
200 158
 
201 159
   #define XPT2046_X_CALIBRATION           -17181
202 160
   #define XPT2046_Y_CALIBRATION            11434
@@ -204,31 +162,38 @@
204 162
   #define XPT2046_Y_OFFSET                    -9
205 163
 
206 164
 #elif ENABLED(TFT_480x320)
207
-  #define TFT_RESET_PIN                     PF11
208
-  #define TFT_BACKLIGHT_PIN                 PD13
209 165
 
210
-  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
211
-  #define FSMC_CS_PIN                       PD7
212
-  #define FSMC_RS_PIN                       PD11
213
-  #define FSMC_DMA_DEV                      DMA2
214
-  #define FSMC_DMA_CHANNEL               DMA_CH5
166
+  // Color UI
167
+
168
+  #define TFT_DRIVER                     ILI9488
169
+  #define TFT_BUFFER_SIZE                  14400
215 170
 
216 171
   #define XPT2046_X_CALIBRATION           -17181
217 172
   #define XPT2046_Y_CALIBRATION            11434
218 173
   #define XPT2046_X_OFFSET                   501
219 174
   #define XPT2046_Y_OFFSET                    -9
220 175
 
221
-  #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
222
-  #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
223
-  #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
224
-  #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
176
+#elif ENABLED(FSMC_GRAPHICAL_TFT)
225 177
 
226
-  #define TFT_DRIVER                     ILI9488
227
-  #define TFT_BUFFER_SIZE                  14400
178
+  // Emulated DOGM
179
+
180
+  #define GRAPHICAL_TFT_UPSCALE                         3
181
+  #ifndef XPT2046_X_CALIBRATION
182
+    #define XPT2046_X_CALIBRATION         -12316
183
+  #endif
184
+  #ifndef XPT2046_Y_CALIBRATION
185
+    #define XPT2046_Y_CALIBRATION           8981
186
+  #endif
187
+  #ifndef XPT2046_X_OFFSET
188
+    #define XPT2046_X_OFFSET                 340
189
+  #endif
190
+  #ifndef XPT2046_Y_OFFSET
191
+    #define XPT2046_Y_OFFSET                 -20
192
+  #endif
228 193
 #endif
229 194
 
230 195
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available
231
-// We nee to use the SPI2
196
+// Needs to use SPI2
232 197
 #define ENABLE_SPI2
233 198
 #define SCK_PIN                             PB13
234 199
 #define MISO_PIN                            PB14
@@ -240,5 +205,5 @@
240 205
 //
241 206
 #define SDIO_SUPPORT
242 207
 #define SD_DETECT_PIN                       -1    // PF0, but it isn't connected
243
-#define SDIO_CLOCK 4500000
244
-#define SDIO_READ_RETRIES 16
208
+#define SDIO_CLOCK                       4500000
209
+#define SDIO_READ_RETRIES                     16

+ 56
- 91
Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h Ver arquivo

@@ -48,7 +48,7 @@
48 48
   #define EEPROM_PAGE_SIZE     (0x800U)           // 2KB, but will use 2x more (4KB)
49 49
   #define MARLIN_EEPROM_SIZE    EEPROM_PAGE_SIZE
50 50
 #else
51
-  #define MARLIN_EEPROM_SIZE 0x800U               // On SD, Limit to 2KB, require this amount of RAM
51
+  #define MARLIN_EEPROM_SIZE              0x800U  // On SD, Limit to 2KB, require this amount of RAM
52 52
 #endif
53 53
 
54 54
 //
@@ -96,7 +96,7 @@
96 96
 //
97 97
 #define HEATER_0_PIN                        PG12  // HEATER1
98 98
 #define HEATER_BED_PIN                      PG11  // HOT BED
99
-//#define HEATER_BED_INVERTING true
99
+//#define HEATER_BED_INVERTING              true
100 100
 
101 101
 //
102 102
 // Fans
@@ -119,71 +119,9 @@
119 119
   #define FIL_RUNOUT2_PIN                   PF13
120 120
 #endif
121 121
 
122
-//
123
-// TronXY TFT Support
124
-//
125
-#if ENABLED(FSMC_GRAPHICAL_TFT)
126
-  #define FSMC_UPSCALE 3
127
-
128
-  #define LCD_RESET_PIN                     PF11
129
-  #define LCD_BACKLIGHT_PIN                 PD13
130
-  #define FSMC_CS_PIN                       PD7
131
-  #define FSMC_RS_PIN                       PD11
132
-
133
-  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
134
-  #define FSMC_DMA_DEV                      DMA2
135
-  #define FSMC_DMA_CHANNEL               DMA_CH5
136
-
137
-  #if NEED_TOUCH_PINS
138
-    #define TOUCH_CS_PIN                    PB7   // SPI1_NSS
139
-    #define TOUCH_SCK_PIN                   PA5   // SPI1_SCK
140
-    #define TOUCH_MISO_PIN                  PA6   // SPI1_MISO
141
-    #define TOUCH_MOSI_PIN                  PA7   // SPI1_MOSI
142
-
143
-    #define BUTTON_DELAY_EDIT 50                  // (ms) Button repeat delay for edit screens
144
-    #define BUTTON_DELAY_MENU 250                 // (ms) Button repeat delay for menus
145
-
146
-    #ifndef XPT2046_X_CALIBRATION
147
-      #define XPT2046_X_CALIBRATION       -12316
148
-    #endif
149
-    #ifndef XPT2046_Y_CALIBRATION
150
-      #define XPT2046_Y_CALIBRATION         8981
151
-    #endif
152
-    #ifndef XPT2046_X_OFFSET
153
-      #define XPT2046_X_OFFSET               340
154
-    #endif
155
-    #ifndef XPT2046_Y_OFFSET
156
-      #define XPT2046_Y_OFFSET               -20
157
-    #endif
158
-  #endif
159
-
160
-#elif ENABLED(TFT_480x320)
161
-  #define TFT_RESET_PIN                     PF11
162
-  #define TFT_BACKLIGHT_PIN                 PD13
163
-
164
-  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
165
-  #define FSMC_CS_PIN                       PD7
166
-  #define FSMC_RS_PIN                       PD11
167
-  #define FSMC_DMA_DEV                      DMA2
168
-  #define FSMC_DMA_CHANNEL               DMA_CH5
169
-
170
-  #define XPT2046_X_CALIBRATION           -17181
171
-  #define XPT2046_Y_CALIBRATION            11434
172
-  #define XPT2046_X_OFFSET                   501
173
-  #define XPT2046_Y_OFFSET                    -9
174
-
175
-  #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
176
-  #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
177
-  #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
178
-  #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
179
-
180
-  #define TFT_DRIVER                        ILI9488
181
-  #define TFT_BUFFER_SIZE                   14400
182
-#endif
183
-
184 122
 // SPI Flash
185
-#define SPI_FLASH_SIZE                      0x200000  // 2MB
186
-#define HAS_SPI_FLASH                       1
123
+#define SPI_FLASH_SIZE                  0x200000  // 2MB
124
+#define HAS_SPI_FLASH                          1
187 125
 
188 126
 // SPI 2
189 127
 #define W25QXX_CS_PIN                       PB12
@@ -191,28 +129,16 @@
191 129
 #define W25QXX_MISO_PIN                     PB14
192 130
 #define W25QXX_SCK_PIN                      PB13
193 131
 
194
-#if HAS_TFT_LVGL_UI
195
-  #define HAS_SPI_FLASH_FONT                0
196
-  #define HAS_GCODE_PREVIEW                 1
197
-  #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH   0
198
-  #define HAS_LANG_SELECT_SCREEN            0
199
-  #define HAS_BAK_VIEW_IN_FLASH             0
200
-  #define HAS_LOGO_IN_FLASH                 0
132
+//
133
+// TronXY TFT Support
134
+//
201 135
 
136
+// Shared FSMC Configs
137
+#if HAS_FSMC_TFT
202 138
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
203 139
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
204 140
   #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
205 141
   #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
206
-  //#define TOUCH_INT_PIN                   PB6
207
-
208
-  #if ENABLED(TFT_LVGL_UI_SPI)
209
-    #define SPI_TFT_CS_PIN          TOUCH_CS_PIN
210
-    #define SPI_TFT_SCK_PIN        TOUCH_SCK_PIN
211
-    #define SPI_TFT_MISO_PIN      TOUCH_MISO_PIN
212
-    #define SPI_TFT_MOSI_PIN      TOUCH_MOSI_PIN
213
-    #define SPI_TFT_DC_PIN                  PB6
214
-    #define SPI_TFT_RST_PIN                 PF11
215
-  #endif
216 142
 
217 143
   #define LCD_RESET_PIN                     PF11
218 144
   #define LCD_BACKLIGHT_PIN                 PD13
@@ -225,17 +151,56 @@
225 151
   #define FSMC_DMA_DEV                      DMA2
226 152
   #define FSMC_DMA_CHANNEL               DMA_CH5
227 153
 
228
-  #define LCD_PIXEL_WIDTH       480
229
-  #define LCD_PIXEL_HEIGHT      320
230
-  #define LCD_FULL_PIXEL_WIDTH  LCD_PIXEL_WIDTH
231
-  #define LCD_FULL_PIXEL_HEIGHT LCD_PIXEL_HEIGHT
232
-  #define LCD_PIXEL_OFFSET_X     48
233
-  #define LCD_PIXEL_OFFSET_Y     48
154
+  #define TFT_WIDTH                          480
155
+  #define TFT_HEIGHT                         320
156
+  #define TFT_PIXEL_OFFSET_X                  48
157
+  #define TFT_PIXEL_OFFSET_Y                  32
158
+
159
+#endif
160
+
161
+// LVGL Configs
162
+#if HAS_TFT_LVGL_UI
163
+
164
+  #define HAS_SPI_FLASH_FONT                   1
165
+  #define HAS_GCODE_PREVIEW                    1
166
+  #define HAS_GCODE_DEFAULT_VIEW_IN_FLASH      0
167
+  #define HAS_LANG_SELECT_SCREEN               1
168
+  #define HAS_BAK_VIEW_IN_FLASH                0
169
+  #define HAS_LOGO_IN_FLASH                    0
234 170
 
235 171
   #define XPT2046_X_CALIBRATION           -17181
236 172
   #define XPT2046_Y_CALIBRATION            11434
237 173
   #define XPT2046_X_OFFSET                   501
238 174
   #define XPT2046_Y_OFFSET                    -9
175
+
176
+// Color UI Configs
177
+#elif ENABLED(TFT_480x320)
178
+
179
+  #define TFT_DRIVER                     ILI9488
180
+  #define TFT_BUFFER_SIZE                  14400
181
+
182
+  #define XPT2046_X_CALIBRATION           -17181
183
+  #define XPT2046_Y_CALIBRATION            11434
184
+  #define XPT2046_X_OFFSET                   501
185
+  #define XPT2046_Y_OFFSET                    -9
186
+
187
+// Emulated DOGM
188
+#elif ENABLED(FSMC_GRAPHICAL_TFT)
189
+  #define GRAPHICAL_TFT_UPSCALE                         3
190
+
191
+  #ifndef XPT2046_X_CALIBRATION
192
+    #define XPT2046_X_CALIBRATION         -12316
193
+  #endif
194
+  #ifndef XPT2046_Y_CALIBRATION
195
+    #define XPT2046_Y_CALIBRATION           8981
196
+  #endif
197
+  #ifndef XPT2046_X_OFFSET
198
+    #define XPT2046_X_OFFSET                 340
199
+  #endif
200
+  #ifndef XPT2046_Y_OFFSET
201
+    #define XPT2046_Y_OFFSET                 -20
202
+  #endif
203
+
239 204
 #endif
240 205
 
241 206
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available
@@ -251,5 +216,5 @@
251 216
 //
252 217
 #define SDIO_SUPPORT
253 218
 #define SD_DETECT_PIN                       -1    // PF0, but it isn't connected
254
-#define SDIO_CLOCK 4500000
255
-#define SDIO_READ_RETRIES 16
219
+#define SDIO_CLOCK                       4500000
220
+#define SDIO_READ_RETRIES                     16

+ 10
- 10
Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h Ver arquivo

@@ -86,8 +86,8 @@
86 86
 
87 87
 #define FAN_PIN                             PA15  // pin 77 (4cm Fan)
88 88
 #define FAN_SOFT_PWM                              // Required to avoid issues with heating or STLink
89
-#define FAN_MIN_PWM 35                            // Fan will not start in 1-30 range
90
-#define FAN_MAX_PWM 255
89
+#define FAN_MIN_PWM                           35  // Fan will not start in 1-30 range
90
+#define FAN_MAX_PWM                          255
91 91
 
92 92
 //#define BEEPER_PIN                        PD13  // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor
93 93
                                  // Can drive a PC Buzzer, if connected between PWM and 5V pins
@@ -130,11 +130,11 @@
130 130
 #define DOGLCD_MOSI                         -1    // Prevent auto-define by Conditionals_post.h
131 131
 #define DOGLCD_SCK                          -1
132 132
 
133
-#define FSMC_UPSCALE                           2
134
-#define LCD_FULL_PIXEL_WIDTH                 320
135
-#define LCD_FULL_PIXEL_HEIGHT                240
136
-#define LCD_PIXEL_OFFSET_X                    32
137
-#define LCD_PIXEL_OFFSET_Y                    32
133
+#define GRAPHICAL_TFT_UPSCALE                           2
134
+#define TFT_WIDTH                            320
135
+#define TFT_HEIGHT                           240
136
+#define TFT_PIXEL_OFFSET_X                    32
137
+#define TFT_PIXEL_OFFSET_Y                    32
138 138
 
139 139
 /**
140 140
  * Note: Alfawise U20/U30 boards DON'T use SPI2, as the hardware designer
@@ -160,12 +160,12 @@
160 160
 
161 161
 #if ENABLED(SPI_EEPROM)
162 162
   // SPI1 EEPROM Winbond W25Q64 (8MB/64Mbits)
163
-  #define SPI_CHAN_EEPROM1 1
163
+  #define SPI_CHAN_EEPROM1                     1
164 164
   #define SPI_EEPROM1_CS                    PC5   // pin 34
165 165
   #define EEPROM_SCK          BOARD_SPI1_SCK_PIN  // PA5 pin 30
166 166
   #define EEPROM_MISO        BOARD_SPI1_MISO_PIN  // PA6 pin 31
167 167
   #define EEPROM_MOSI        BOARD_SPI1_MOSI_PIN  // PA7 pin 32
168
-  #define EEPROM_PAGE_SIZE 0x1000U                // 4KB (from datasheet)
168
+  #define EEPROM_PAGE_SIZE               0x1000U  // 4KB (from datasheet)
169 169
   #define MARLIN_EEPROM_SIZE 16UL * (EEPROM_PAGE_SIZE)   // Limit to 64KB for now...
170 170
 #elif ENABLED(FLASH_EEPROM_EMULATION)
171 171
   // SoC Flash (framework-arduinoststm32-maple/STM32F1/libraries/EEPROM/EEPROM.h)
@@ -173,5 +173,5 @@
173 173
   #define EEPROM_START_ADDRESS (0x8000000UL + (STM32_FLASH_SIZE) * 1024UL - (EEPROM_PAGE_SIZE) * 2UL)
174 174
   #define MARLIN_EEPROM_SIZE (EEPROM_PAGE_SIZE)
175 175
 #else
176
-  #define MARLIN_EEPROM_SIZE 0x800U               // On SD, Limit to 2KB, require this amount of RAM
176
+  #define MARLIN_EEPROM_SIZE              0x800U  // On SD, Limit to 2KB, require this amount of RAM
177 177
 #endif

+ 47
- 53
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h Ver arquivo

@@ -127,10 +127,10 @@
127 127
 #define PS_ON_PIN                           PA3   // PW_OFF
128 128
 
129 129
 //#define SUICIDE_PIN                       PB2   // Enable MKSPWC support ROBIN NANO v1.2 ONLY
130
-//#define SUICIDE_PIN_INVERTING false
130
+//#define SUICIDE_PIN_INVERTING            false
131 131
 
132 132
 //#define KILL_PIN                          PA2   // Enable MKSPWC support ROBIN NANO v1.2 ONLY
133
-//#define KILL_PIN_INVERTING true                 // Enable MKSPWC support ROBIN NANO v1.2 ONLY
133
+//#define KILL_PIN_INVERTING                true  // Enable MKSPWC support ROBIN NANO v1.2 ONLY
134 134
 
135 135
 #define SERVO0_PIN                          PA8   // Enable BLTOUCH support ROBIN NANO v1.2 ONLY
136 136
 
@@ -138,7 +138,7 @@
138 138
 
139 139
 #define MT_DET_1_PIN                        PA4
140 140
 #define MT_DET_2_PIN                        PE6
141
-#define MT_DET_PIN_INVERTING false
141
+#define MT_DET_PIN_INVERTING               false
142 142
 
143 143
 #define WIFI_IO0_PIN                        PC13
144 144
 
@@ -150,7 +150,7 @@
150 150
 #endif
151 151
 
152 152
 #define SDIO_SUPPORT
153
-#define SDIO_CLOCK 4500000                        // 4.5 MHz
153
+#define SDIO_CLOCK                       4500000  // 4.5 MHz
154 154
 #define SD_DETECT_PIN                       PD12
155 155
 #define ONBOARD_SD_CS_PIN                   PC11
156 156
 
@@ -165,8 +165,8 @@
165 165
  * to let the bootloader init the screen.
166 166
  */
167 167
 
168
-#if ENABLED(TFT_LVGL_UI_FSMC)
169
-
168
+// Shared FSMC Configs
169
+#if HAS_FSMC_TFT
170 170
   #define FSMC_CS_PIN                       PD7   // NE4
171 171
   #define FSMC_RS_PIN                       PD11  // A0
172 172
 
@@ -175,12 +175,11 @@
175 175
   #define TOUCH_MISO_PIN                    PB14  // SPI2_MISO
176 176
   #define TOUCH_MOSI_PIN                    PB15  // SPI2_MOSI
177 177
 
178
+  #define LCD_RESET_PIN                     PC6   // FSMC_RST
178 179
   #define LCD_BACKLIGHT_PIN                 PD13
179 180
 
180
-  #define XPT2046_X_CALIBRATION            17880
181
-  #define XPT2046_Y_CALIBRATION           -12234
182
-  #define XPT2046_X_OFFSET                   -45
183
-  #define XPT2046_Y_OFFSET                   349
181
+  #define TFT_RESET_PIN                     PC6   // FSMC_RST
182
+  #define TFT_BACKLIGHT_PIN                 PD13
184 183
 
185 184
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
186 185
   #define FSMC_CS_PIN                       PD7
@@ -188,71 +187,66 @@
188 187
   #define FSMC_DMA_DEV                      DMA2
189 188
   #define FSMC_DMA_CHANNEL               DMA_CH5
190 189
 
190
+  #define TOUCH_BUTTONS_HW_SPI
191
+  #define TOUCH_BUTTONS_HW_SPI_DEVICE       2
192
+#endif
193
+
194
+// LVGL Configs
195
+#if ENABLED(TFT_LVGL_UI_FSMC)
196
+
197
+  #define XPT2046_X_CALIBRATION            17880
198
+  #define XPT2046_Y_CALIBRATION           -12234
199
+  #define XPT2046_X_OFFSET                   -45
200
+  #define XPT2046_Y_OFFSET                   349
201
+
202
+// Emulated DOGM Configs
191 203
 #elif ENABLED(FSMC_GRAPHICAL_TFT)
192 204
 
193 205
   #define DOGLCD_MOSI                       -1    // prevent redefine Conditionals_post.h
194 206
   #define DOGLCD_SCK                        -1
195 207
 
196
-  #ifndef FSMC_UPSCALE
197
-    #define FSMC_UPSCALE                    3
208
+  #ifndef GRAPHICAL_TFT_UPSCALE
209
+    #define GRAPHICAL_TFT_UPSCALE                       3
198 210
   #endif
199
-  #ifndef LCD_FULL_PIXEL_WIDTH
200
-    #define LCD_FULL_PIXEL_WIDTH            480
211
+  #ifndef TFT_WIDTH
212
+    #define TFT_WIDTH                        480
201 213
   #endif
202
-  #ifndef LCD_PIXEL_OFFSET_X
203
-    #define LCD_PIXEL_OFFSET_X              48
214
+  #ifndef TFT_PIXEL_OFFSET_X
215
+    #define TFT_PIXEL_OFFSET_X                48
204 216
   #endif
205
-  #ifndef LCD_FULL_PIXEL_HEIGHT
206
-    #define LCD_FULL_PIXEL_HEIGHT           320
217
+  #ifndef TFT_HEIGHT
218
+    #define TFT_HEIGHT                       320
207 219
   #endif
208
-  #ifndef LCD_PIXEL_OFFSET_Y
209
-    #define LCD_PIXEL_OFFSET_Y              32
220
+  #ifndef TFT_PIXEL_OFFSET_Y
221
+    #define TFT_PIXEL_OFFSET_Y                32
210 222
   #endif
211 223
 
212
-  #define FSMC_CS_PIN                       PD7   // NE4
213
-  #define FSMC_RS_PIN                       PD11  // A0
214
-
215
-  #define LCD_USE_DMA_FSMC                  // Use DMA transfers to send data to the TFT
216
-  #define FSMC_DMA_DEV                      DMA2
217
-  #define FSMC_DMA_CHANNEL                  DMA_CH5
218
-
219
-  #define LCD_RESET_PIN                     PC6   // FSMC_RST
220
-  #define LCD_BACKLIGHT_PIN                 PD13
221
-
222
-  #if NEED_TOUCH_PINS
223
-    #define TOUCH_CS_PIN                    PA7   // SPI2_NSS
224
-    #define TOUCH_SCK_PIN                   PB13  // SPI2_SCK
225
-    #define TOUCH_MISO_PIN                  PB14  // SPI2_MISO
226
-    #define TOUCH_MOSI_PIN                  PB15  // SPI2_MOSI
224
+  #ifndef XPT2046_X_CALIBRATION
225
+    #define XPT2046_X_CALIBRATION          12149
226
+  #endif
227
+  #ifndef XPT2046_Y_CALIBRATION
228
+    #define XPT2046_Y_CALIBRATION          -8746
229
+  #endif
230
+  #ifndef XPT2046_X_OFFSET
231
+    #define XPT2046_X_OFFSET                 -35
232
+  #endif
233
+  #ifndef XPT2046_Y_OFFSET
234
+    #define XPT2046_Y_OFFSET                 256
227 235
   #endif
228 236
 
229 237
 #elif ENABLED(TFT_480x320)
230
-  #define TFT_RESET_PIN                     PC6
231
-  #define TFT_BACKLIGHT_PIN                 PD13
232
-
233
-  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
234
-  #define FSMC_CS_PIN                       PD7
235
-  #define FSMC_RS_PIN                       PD11
236
-  #define FSMC_DMA_DEV                      DMA2
237
-  #define FSMC_DMA_CHANNEL               DMA_CH5
238
-
239 238
   #define XPT2046_X_CALIBRATION            17880
240 239
   #define XPT2046_Y_CALIBRATION           -12234
241 240
   #define XPT2046_X_OFFSET                   -45
242 241
   #define XPT2046_Y_OFFSET                   349
243 242
 
244
-  #define TOUCH_CS_PIN                      PA7   // SPI2_NSS
245
-  #define TOUCH_SCK_PIN                     PB13   // SPI2_SCK
246
-  #define TOUCH_MISO_PIN                    PB14   // SPI2_MISO
247
-  #define TOUCH_MOSI_PIN                    PB15   // SPI2_MOSI
248
-
249
-  #define TFT_DRIVER                        ILI9488
250
-  #define TFT_BUFFER_SIZE                   14400
243
+  #define TFT_DRIVER                     ILI9488
244
+  #define TFT_BUFFER_SIZE                  14400
251 245
   #define ILI9488_ORIENTATION               ILI9488_MADCTL_MX | ILI9488_MADCTL_MV
252 246
 #endif
253 247
 
254
-#define HAS_SPI_FLASH                       1
255
-#define SPI_FLASH_SIZE                      0x1000000 // 16MB
248
+#define HAS_SPI_FLASH                          1
249
+#define SPI_FLASH_SIZE                 0x1000000  // 16MB
256 250
 #if HAS_SPI_FLASH
257 251
   #define W25QXX_CS_PIN                     PB12
258 252
   #define W25QXX_MOSI_PIN                   PB15

+ 85
- 118
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h Ver arquivo

@@ -29,6 +29,8 @@
29 29
   #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
30 30
 #elif HOTENDS > 2 || E_STEPPERS > 2
31 31
   #error "MKS Robin nano supports up to 2 hotends / E-steppers. Comment out this line to continue."
32
+#elif HAS_FSMC_TFT
33
+  #error "MKS Robin nano v2 doesn't support FSMC-based TFT displays."
32 34
 #endif
33 35
 
34 36
 #define BOARD_INFO_NAME "MKS Robin nano V2.0"
@@ -47,13 +49,13 @@
47 49
 
48 50
 #if EITHER(NO_EEPROM_SELECTED, I2C_EEPROM)
49 51
   #define I2C_EEPROM                              // EEPROM on I2C-0
50
-  #define MARLIN_EEPROM_SIZE 0x1000               // 4KB
52
+  #define MARLIN_EEPROM_SIZE              0x1000  // 4KB
51 53
 #endif
52 54
 
53 55
 //
54 56
 // Note: MKS Robin board is using SPI2 interface.
55 57
 //
56
-//#define SPI_MODULE 2
58
+//#define SPI_MODULE                           2
57 59
 #define ENABLE_SPI2
58 60
 
59 61
 //
@@ -162,7 +164,7 @@
162 164
   #define E1_SERIAL_RX_PIN                  PD8
163 165
 
164 166
   // Reduce baud rate to improve software serial reliability
165
-  #define TMC_BAUD_RATE 19200
167
+  #define TMC_BAUD_RATE                    19200
166 168
 #endif // TMC2208 || TMC2209
167 169
 
168 170
 //
@@ -194,10 +196,10 @@
194 196
 #define PS_ON_PIN                           PA3   // PW_OFF
195 197
 
196 198
 //#define SUICIDE_PIN                       PB2   // Enable MKSPWC support ROBIN NANO v1.2 ONLY
197
-//#define SUICIDE_PIN_INVERTING false
199
+//#define SUICIDE_PIN_INVERTING            false
198 200
 
199 201
 //#define KILL_PIN                          PA2   // Enable MKSPWC support ROBIN NANO v1.2 ONLY
200
-//#define KILL_PIN_INVERTING true                 // Enable MKSPWC support ROBIN NANO v1.2 ONLY
202
+//#define KILL_PIN_INVERTING                true  // Enable MKSPWC support ROBIN NANO v1.2 ONLY
201 203
 
202 204
 #define SERVO0_PIN                          PA8   // Enable BLTOUCH support ROBIN NANO v1.2 ONLY
203 205
 
@@ -205,7 +207,7 @@
205 207
 
206 208
 #define MT_DET_1_PIN                        PA4
207 209
 #define MT_DET_2_PIN                        PE6
208
-#define MT_DET_PIN_INVERTING false
210
+#define MT_DET_PIN_INVERTING               false
209 211
 
210 212
 #ifndef FIL_RUNOUT_PIN
211 213
   #define FIL_RUNOUT_PIN            MT_DET_1_PIN
@@ -224,7 +226,7 @@
224 226
 #endif
225 227
 
226 228
 #define SDIO_SUPPORT
227
-#define SDIO_CLOCK 4500000                        // 4.5 MHz
229
+#define SDIO_CLOCK                       4500000  // 4.5 MHz
228 230
 #define SD_DETECT_PIN                       PD12
229 231
 #define ONBOARD_SD_CS_PIN                   PC11
230 232
 
@@ -241,14 +243,9 @@
241 243
  * to let the bootloader init the screen.
242 244
  */
243 245
 
244
-#if ENABLED(TFT_LVGL_UI_SPI)
246
+#if HAS_SPI_TFT
245 247
 
246
-  #define SPI_TFT_CS_PIN                    PD11
247
-  #define SPI_TFT_SCK_PIN                   PA5
248
-  #define SPI_TFT_MISO_PIN                  PA6
249
-  #define SPI_TFT_MOSI_PIN                  PA7
250
-  #define SPI_TFT_DC_PIN                    PD10
251
-  #define SPI_TFT_RST_PIN                   PC6
248
+  // Shared SPI TFT
252 249
 
253 250
   #define LCD_BACKLIGHT_PIN                 PD13
254 251
 
@@ -261,132 +258,102 @@
261 258
   #define BTN_EN2                           PE11
262 259
   #define BTN_ENC                           PE13
263 260
 
264
-  #define TFT_CS_PIN                      PD11
265
-  #define TFT_SCK_PIN                     PA5
266
-  #define TFT_MISO_PIN                    PA6
267
-  #define TFT_MOSI_PIN                    PA7
268
-  #define TFT_DC_PIN                      PD10
269
-  #define TFT_RST_PIN                     PC6
270
-  #define TFT_A0_PIN                TFT_DC_PIN
271
-
272
-  #define TFT_RESET_PIN                   PC6
273
-  #define TFT_BACKLIGHT_PIN               PD13
274
-
275
-  #define XPT2046_X_CALIBRATION         -17253
276
-  #define XPT2046_Y_CALIBRATION          11579
277
-  #define XPT2046_X_OFFSET                 514
278
-  #define XPT2046_Y_OFFSET                 -24
261
+  #define TFT_CS_PIN                        PD11
262
+  #define TFT_SCK_PIN                       PA5
263
+  #define TFT_MISO_PIN                      PA6
264
+  #define TFT_MOSI_PIN                      PA7
265
+  #define TFT_DC_PIN                        PD10
266
+  #define TFT_RST_PIN                       PC6
267
+  #define TFT_A0_PIN                  TFT_DC_PIN
268
+
269
+  #define TFT_RESET_PIN                     PC6
270
+  #define TFT_BACKLIGHT_PIN                 PD13
271
+
279 272
   #define TOUCH_BUTTONS_HW_SPI
280
-  #define TOUCH_BUTTONS_HW_SPI_DEVICE        1
273
+  #define TOUCH_BUTTONS_HW_SPI_DEVICE          1
281 274
 
282
-  #ifndef LCD_FULL_PIXEL_WIDTH
283
-    #define LCD_FULL_PIXEL_WIDTH            480
275
+  #ifndef TFT_WIDTH
276
+    #define TFT_WIDTH                        480
284 277
   #endif
285
-  #ifndef LCD_FULL_PIXEL_HEIGHT
286
-    #define LCD_FULL_PIXEL_HEIGHT           320
278
+  #ifndef TFT_HEIGHT
279
+    #define TFT_HEIGHT                       320
287 280
   #endif
288 281
 
289
-#endif
282
+  #define LCD_READ_ID                       0xD3
283
+  #define LCD_USE_DMA_SPI
290 284
 
291
-#if HAS_SPI_LCD
292
-
293
-  #if ENABLED(SPI_GRAPHICAL_TFT)                  // Emulated DOGM SPI
294
-    #define SPI_TFT_CS_PIN                  PD11
295
-    #define SPI_TFT_SCK_PIN                 PA5
296
-    #define SPI_TFT_MISO_PIN                PA6
297
-    #define SPI_TFT_MOSI_PIN                PA7
298
-    #define SPI_TFT_DC_PIN                  PD10
299
-    #define SPI_TFT_RST_PIN                 PC6
300
-
301
-    #define LCD_BACKLIGHT_PIN               PD13
302
-
303
-    #define LCD_READ_ID                     0xD3
304
-    #define LCD_USE_DMA_SPI
305
-
306
-    #define TOUCH_BUTTONS_HW_SPI
307
-    #define TOUCH_BUTTONS_HW_SPI_DEVICE     1
308
-
309
-    //#define TOUCH_SCREEN
310
-    #if EITHER(TOUCH_SCREEN, NEED_TOUCH_PINS)
311
-      #define TOUCH_CS_PIN                  PE14  // SPI1_NSS
312
-      #define TOUCH_SCK_PIN                 PA5   // SPI1_SCK
313
-      #define TOUCH_MISO_PIN                PA6   // SPI1_MISO
314
-      #define TOUCH_MOSI_PIN                PA7   // SPI1_MOSI
315
-
316
-      #ifndef XPT2046_X_CALIBRATION
317
-        #define XPT2046_X_CALIBRATION      -5481
318
-      #endif
319
-      #ifndef XPT2046_Y_CALIBRATION
320
-        #define XPT2046_Y_CALIBRATION       4000
321
-      #endif
322
-      #ifndef XPT2046_X_OFFSET
323
-        #define XPT2046_X_OFFSET             343
324
-      #endif
325
-      #ifndef XPT2046_Y_OFFSET
326
-        #define XPT2046_Y_OFFSET               0
327
-      #endif
328
-    #endif
285
+#endif
329 286
 
330
-    #ifndef FSMC_UPSCALE
331
-      #define FSMC_UPSCALE                     3
332
-    #endif
333
-    #ifndef LCD_PIXEL_OFFSET_Y
334
-      #define LCD_PIXEL_OFFSET_Y              32
335
-    #endif
287
+#if ENABLED(TFT_LVGL_UI_SPI)
336 288
 
337
-    #define BTN_ENC                         PE13
338
-    #define BTN_EN1                         PE8
339
-    #define BTN_EN2                         PE11
289
+  // LVGL
340 290
 
341
-    #define LCD_PINS_ENABLE                 PD13
342
-    #define LCD_PINS_RS                     PC6
291
+  #define XPT2046_X_CALIBRATION           -17253
292
+  #define XPT2046_Y_CALIBRATION            11579
293
+  #define XPT2046_X_OFFSET                   514
294
+  #define XPT2046_Y_OFFSET                   -24
343 295
 
344
-  #elif ENABLED(MKS_MINI_12864)
296
+#elif ENABLED(SPI_GRAPHICAL_TFT)
345 297
 
346
-    // MKS MINI12864 and MKS LCD12864B
347
-    // If using MKS LCD12864A (Need to remove RPK2 resistor)
298
+  // Emulated DOGM SPI
348 299
 
349
-    #define LCD_BACKLIGHT_PIN               -1
350
-    #define LCD_RESET_PIN                   -1
351
-    #define DOGLCD_A0                       PD11
352
-    #define DOGLCD_CS                       PE15
353
-    #define DOGLCD_SCK                      PA5
354
-    #define DOGLCD_MOSI                     PA7
300
+  #ifndef XPT2046_X_CALIBRATION
301
+    #define XPT2046_X_CALIBRATION         -11386
302
+  #endif
303
+  #ifndef XPT2046_Y_CALIBRATION
304
+    #define XPT2046_Y_CALIBRATION           8684
305
+  #endif
306
+  #ifndef XPT2046_X_OFFSET
307
+    #define XPT2046_X_OFFSET                 339
308
+  #endif
309
+  #ifndef XPT2046_Y_OFFSET
310
+    #define XPT2046_Y_OFFSET                 -18
311
+  #endif
355 312
 
356
-    // Required for MKS_MINI_12864 with this board
357
-    #define MKS_LCD12864B
358
-    #undef SHOW_BOOTSCREEN
313
+  #ifndef GRAPHICAL_TFT_UPSCALE
314
+    #define GRAPHICAL_TFT_UPSCALE                       3
315
+  #endif
316
+  #ifndef TFT_PIXEL_OFFSET_Y
317
+    #define TFT_PIXEL_OFFSET_Y                32
318
+  #endif
359 319
 
360
-  #elif ENABLED(TFT_480x320_SPI)
361
-    #define TFT_CS_PIN                      PD11
362
-    #define TFT_SCK_PIN                     PA5
363
-    #define TFT_MISO_PIN                    PA6
364
-    #define TFT_MOSI_PIN                    PA7
365
-    #define TFT_DC_PIN                      PD10
366
-    #define TFT_RST_PIN                     PC6
367
-    #define TFT_A0_PIN                TFT_DC_PIN
320
+  #define BTN_ENC                           PE13
321
+  #define BTN_EN1                           PE8
322
+  #define BTN_EN2                           PE11
368 323
 
369
-    #define TFT_RESET_PIN                   PC6
370
-    #define TFT_BACKLIGHT_PIN               PD13
324
+  #define LCD_PINS_ENABLE                   PD13
325
+  #define LCD_PINS_RS                       PC6
371 326
 
327
+#elif ENABLED(TFT_480x320_SPI)
372 328
     #define XPT2046_X_CALIBRATION         -17253
373 329
     #define XPT2046_Y_CALIBRATION          11579
374 330
     #define XPT2046_X_OFFSET                 514
375 331
     #define XPT2046_Y_OFFSET                 -24
376 332
 
377
-    #define TOUCH_CS_PIN                    PE14  // SPI1_NSS
378
-    #define TOUCH_SCK_PIN                   PA5   // SPI1_SCK
379
-    #define TOUCH_MISO_PIN                  PA6   // SPI1_MISO
380
-    #define TOUCH_MOSI_PIN                  PA7   // SPI1_MOSI
381
-
382 333
     #define TFT_DRIVER                    ST7796
383 334
     #define TFT_BUFFER_SIZE                14400
384 335
 
385
-    #define LCD_READ_ID                     0xD3
386
-    #define LCD_USE_DMA_SPI
336
+#endif
337
+
338
+#if HAS_SPI_LCD && !HAS_SPI_TFT
339
+
340
+  // NON TFT Displays
387 341
 
388
-    #define TOUCH_BUTTONS_HW_SPI
389
-    #define TOUCH_BUTTONS_HW_SPI_DEVICE        1
342
+  #if ENABLED(MKS_MINI_12864)
343
+
344
+    // MKS MINI12864 and MKS LCD12864B
345
+    // If using MKS LCD12864A (Need to remove RPK2 resistor)
346
+
347
+    #define LCD_BACKLIGHT_PIN               -1
348
+    #define LCD_RESET_PIN                   -1
349
+    #define DOGLCD_A0                       PD11
350
+    #define DOGLCD_CS                       PE15
351
+    #define DOGLCD_SCK                      PA5
352
+    #define DOGLCD_MOSI                     PA7
353
+
354
+    // Required for MKS_MINI_12864 with this board
355
+    #define MKS_LCD12864B
356
+    #undef SHOW_BOOTSCREEN
390 357
 
391 358
   #else                                           // !MKS_MINI_12864
392 359
 
@@ -409,10 +376,10 @@
409 376
 
410 377
   #endif // !MKS_MINI_12864
411 378
 
412
-#endif // HAS_SPI_LCD
379
+#endif // HAS_SPI_LCD && !HAS_SPI_TFT
413 380
 
414
-#define HAS_SPI_FLASH                       1
415
-#define SPI_FLASH_SIZE                      0x1000000 // 16MB
381
+#define HAS_SPI_FLASH                          1
382
+#define SPI_FLASH_SIZE                 0x1000000  // 16MB
416 383
 #if HAS_SPI_FLASH
417 384
   #define W25QXX_CS_PIN                     PB12
418 385
   #define W25QXX_MOSI_PIN                   PB15

+ 35
- 6
buildroot/share/scripts/pinsformat.js Ver arquivo

@@ -38,10 +38,12 @@ for (let m of mpatt) mexpr.push(new RegExp('^' + m + '$'));
38 38
 
39 39
 const argv = process.argv.slice(2), argc = argv.length;
40 40
 
41
-var src_file = 0, src_name = 'STDIN', dst_file;
41
+var src_file = 0, src_name = 'STDIN', dst_file, do_log = false;
42 42
 if (argc > 0) {
43
-  src_file = src_name = argv[0];
44
-  dst_file = argv[argc > 1 ? 1 : 0];
43
+  let ind = 0;
44
+  if (argv[0] == '-v') { do_log = true; ind++; }
45
+  dst_file = src_file = src_name = argv[ind++];
46
+  if (ind < argc) dst_file = argv[ind];
45 47
 }
46 48
 
47 49
 // Read from file or STDIN until it terminates
@@ -81,7 +83,7 @@ function process_text(txt) {
81 83
          aliasPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([A-Z_][A-Z0-9_()]+)\\s*(//.*)?$'),
82 84
         switchPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'),
83 85
          undefPatt = new RegExp('^(\\s*(//)?#undef)\\s+([A-Z_][A-Z0-9_]+)\\s*(//.*)?$'),
84
-           defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+(\\w+)\\s*(//.*)?$'),
86
+           defPatt = new RegExp('^(\\s*(//)?#define)\\s+([A-Z_][A-Z0-9_]+)\\s+([-_\\w]+)\\s*(//.*)?$'),
85 87
           condPatt = new RegExp('^(\\s*(//)?#(if|ifn?def|else|elif)(\\s+\\S+)*)\\s+(//.*)$'),
86 88
           commPatt = new RegExp('^\\s{20,}(//.*)?$');
87 89
   const col_value_lj = col_comment - patt.pad - 2;
@@ -98,6 +100,7 @@ function process_text(txt) {
98 100
       //
99 101
       // #define MY_PIN [pin]
100 102
       //
103
+      if (do_log) console.log("pin:", line);
101 104
       const pinnum = r[4].charAt(0) == 'P' ? r[4] : r[4].lpad(patt.pad);
102 105
       line = r[1] + ' ' + r[3];
103 106
       line = line.rpad(col_value_lj) + pinnum;
@@ -107,31 +110,57 @@ function process_text(txt) {
107 110
       //
108 111
       // #define MY_PIN -1
109 112
       //
113
+      if (do_log) console.log("pin -1:", line);
110 114
       line = r[1] + ' ' + r[3];
111 115
       line = line.rpad(col_value_lj) + '-1';
112 116
       if (r[5]) line = line.rpad(col_comment) + r[5];
113 117
     }
114 118
     else if ((r = skipPatt.exec(line)) !== null) {
119
+      //
120
+      // #define SKIP_ME
121
+      //
122
+      if (do_log) console.log("skip:", line);
115 123
     }
116 124
     else if ((r = aliasPatt.exec(line)) !== null) {
125
+      //
126
+      // #define ALIAS OTHER
127
+      //
128
+      if (do_log) console.log("alias:", line);
117 129
       line = r[1] + ' ' + r[3];
118 130
       line += r[4].lpad(col_value_rj + 1 - line.length);
119 131
       if (r[5]) line = line.rpad(col_comment) + r[5];
120 132
     }
121 133
     else if ((r = switchPatt.exec(line)) !== null) {
134
+      //
135
+      // #define SWITCH
136
+      //
137
+      if (do_log) console.log("switch:", line);
122 138
       line = r[1] + ' ' + r[3];
123 139
       if (r[4]) line = line.rpad(col_comment) + r[4];
124 140
       check_comment_next = true;
125 141
     }
126 142
     else if ((r = defPatt.exec(line)) !== null) {
127
-      line = r[1] + ' ' + r[3] + ' ' + r[4];
128
-      if (r[5]) line = line.rpad(col_comment) + r[5];
143
+      //
144
+      // #define ...
145
+      //
146
+      if (do_log) console.log("def:", line);
147
+      line = r[1] + ' ' + r[3] + ' ';
148
+      line += r[4].lpad(col_value_rj + 1 - line.length);
149
+      if (r[5]) line = line.rpad(col_comment - 1) + ' ' + r[5];
129 150
     }
130 151
     else if ((r = undefPatt.exec(line)) !== null) {
152
+      //
153
+      // #undef ...
154
+      //
155
+      if (do_log) console.log("undef:", line);
131 156
       line = r[1] + ' ' + r[3];
132 157
       if (r[4]) line = line.rpad(col_comment) + r[4];
133 158
     }
134 159
     else if ((r = condPatt.exec(line)) !== null) {
160
+      //
161
+      // #if ...
162
+      //
163
+      if (do_log) console.log("cond:", line);
135 164
       line = r[1].rpad(col_comment) + r[5];
136 165
       check_comment_next = true;
137 166
     }

Carregando…
Cancelar
Salvar