瀏覽代碼

Marlin Color UI (FSMC) for STM32F1 (#18952)

Victor Oliveira 4 年之前
父節點
當前提交
ee69fb00a6
沒有連結到貢獻者的電子郵件帳戶。

+ 3
- 3
Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h 查看文件

@@ -26,12 +26,12 @@
26 26
   #undef SD_CHECK_AND_RETRY
27 27
 #endif
28 28
 
29
-#if HAS_GRAPHICAL_TFT
30
-  #error "Sorry! TFT displays are not available for HAL/STM32F1."
29
+#if HAS_SPI_TFT
30
+  #error "Sorry! SPI TFT displays are not available for HAL/STM32F1 (yet)."
31 31
 #endif
32 32
 
33 33
 // This platform has 'touch/xpt2046', not 'tft/xpt2046'
34
-#if ENABLED(TOUCH_SCREEN)
34
+#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT
35 35
   #undef TOUCH_SCREEN
36 36
   #undef TOUCH_SCREEN_CALIBRATION
37 37
   #define HAS_TOUCH_XPT2046 1

+ 236
- 0
Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp 查看文件

@@ -0,0 +1,236 @@
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
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if HAS_FSMC_TFT
26
+
27
+#include "tft_fsmc.h"
28
+#include <libmaple/fsmc.h>
29
+#include <libmaple/gpio.h>
30
+#include <libmaple/dma.h>
31
+
32
+LCD_CONTROLLER_TypeDef *TFT_FSMC::LCD;
33
+
34
+/**
35
+ * FSMC LCD IO
36
+ */
37
+#define __ASM __asm
38
+#define __STATIC_INLINE static inline
39
+
40
+__attribute__((always_inline)) __STATIC_INLINE void __DSB() {
41
+  __ASM volatile ("dsb 0xF":::"memory");
42
+}
43
+
44
+#define FSMC_CS_NE1   PD7
45
+
46
+#if ENABLED(STM32_XL_DENSITY)
47
+  #define FSMC_CS_NE2 PG9
48
+  #define FSMC_CS_NE3 PG10
49
+  #define FSMC_CS_NE4 PG12
50
+
51
+  #define FSMC_RS_A0  PF0
52
+  #define FSMC_RS_A1  PF1
53
+  #define FSMC_RS_A2  PF2
54
+  #define FSMC_RS_A3  PF3
55
+  #define FSMC_RS_A4  PF4
56
+  #define FSMC_RS_A5  PF5
57
+  #define FSMC_RS_A6  PF12
58
+  #define FSMC_RS_A7  PF13
59
+  #define FSMC_RS_A8  PF14
60
+  #define FSMC_RS_A9  PF15
61
+  #define FSMC_RS_A10 PG0
62
+  #define FSMC_RS_A11 PG1
63
+  #define FSMC_RS_A12 PG2
64
+  #define FSMC_RS_A13 PG3
65
+  #define FSMC_RS_A14 PG4
66
+  #define FSMC_RS_A15 PG5
67
+#endif
68
+
69
+#define FSMC_RS_A16   PD11
70
+#define FSMC_RS_A17   PD12
71
+#define FSMC_RS_A18   PD13
72
+#define FSMC_RS_A19   PE3
73
+#define FSMC_RS_A20   PE4
74
+#define FSMC_RS_A21   PE5
75
+#define FSMC_RS_A22   PE6
76
+#define FSMC_RS_A23   PE2
77
+
78
+#if ENABLED(STM32_XL_DENSITY)
79
+  #define FSMC_RS_A24 PG13
80
+  #define FSMC_RS_A25 PG14
81
+#endif
82
+
83
+/* Timing configuration */
84
+#define FSMC_ADDRESS_SETUP_TIME   15  // AddressSetupTime
85
+#define FSMC_DATA_SETUP_TIME      15  // DataSetupTime
86
+
87
+static uint8_t fsmcInit = 0;
88
+void TFT_FSMC::Init() {
89
+  uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN;
90
+  uint32_t controllerAddress;
91
+
92
+  #if PIN_EXISTS(TFT_RESET)
93
+    OUT_WRITE(TFT_RESET_PIN, HIGH);
94
+    delay(100);
95
+  #endif
96
+
97
+  #if PIN_EXISTS(TFT_BACKLIGHT)
98
+    OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
99
+  #endif
100
+
101
+  struct fsmc_nor_psram_reg_map* fsmcPsramRegion;
102
+
103
+  if (fsmcInit) return;
104
+  fsmcInit = 1;
105
+
106
+  switch (cs) {
107
+    case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; fsmcPsramRegion = FSMC_NOR_PSRAM1_BASE; break;
108
+    #if ENABLED(STM32_XL_DENSITY)
109
+      case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; fsmcPsramRegion = FSMC_NOR_PSRAM2_BASE; break;
110
+      case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; fsmcPsramRegion = FSMC_NOR_PSRAM3_BASE; break;
111
+      case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; fsmcPsramRegion = FSMC_NOR_PSRAM4_BASE; break;
112
+    #endif
113
+    default: return;
114
+  }
115
+
116
+  #define _ORADDR(N) controllerAddress |= (_BV32(N) - 2)
117
+
118
+  switch (rs) {
119
+    #if ENABLED(STM32_XL_DENSITY)
120
+      case FSMC_RS_A0:  _ORADDR( 1); break;
121
+      case FSMC_RS_A1:  _ORADDR( 2); break;
122
+      case FSMC_RS_A2:  _ORADDR( 3); break;
123
+      case FSMC_RS_A3:  _ORADDR( 4); break;
124
+      case FSMC_RS_A4:  _ORADDR( 5); break;
125
+      case FSMC_RS_A5:  _ORADDR( 6); break;
126
+      case FSMC_RS_A6:  _ORADDR( 7); break;
127
+      case FSMC_RS_A7:  _ORADDR( 8); break;
128
+      case FSMC_RS_A8:  _ORADDR( 9); break;
129
+      case FSMC_RS_A9:  _ORADDR(10); break;
130
+      case FSMC_RS_A10: _ORADDR(11); break;
131
+      case FSMC_RS_A11: _ORADDR(12); break;
132
+      case FSMC_RS_A12: _ORADDR(13); break;
133
+      case FSMC_RS_A13: _ORADDR(14); break;
134
+      case FSMC_RS_A14: _ORADDR(15); break;
135
+      case FSMC_RS_A15: _ORADDR(16); break;
136
+    #endif
137
+    case FSMC_RS_A16: _ORADDR(17); break;
138
+    case FSMC_RS_A17: _ORADDR(18); break;
139
+    case FSMC_RS_A18: _ORADDR(19); break;
140
+    case FSMC_RS_A19: _ORADDR(20); break;
141
+    case FSMC_RS_A20: _ORADDR(21); break;
142
+    case FSMC_RS_A21: _ORADDR(22); break;
143
+    case FSMC_RS_A22: _ORADDR(23); break;
144
+    case FSMC_RS_A23: _ORADDR(24); break;
145
+    #if ENABLED(STM32_XL_DENSITY)
146
+      case FSMC_RS_A24: _ORADDR(25); break;
147
+      case FSMC_RS_A25: _ORADDR(26); break;
148
+    #endif
149
+    default: return;
150
+  }
151
+
152
+  rcc_clk_enable(RCC_FSMC);
153
+
154
+  gpio_set_mode(GPIOD, 14, GPIO_AF_OUTPUT_PP);  // FSMC_D00
155
+  gpio_set_mode(GPIOD, 15, GPIO_AF_OUTPUT_PP);  // FSMC_D01
156
+  gpio_set_mode(GPIOD,  0, GPIO_AF_OUTPUT_PP);  // FSMC_D02
157
+  gpio_set_mode(GPIOD,  1, GPIO_AF_OUTPUT_PP);  // FSMC_D03
158
+  gpio_set_mode(GPIOE,  7, GPIO_AF_OUTPUT_PP);  // FSMC_D04
159
+  gpio_set_mode(GPIOE,  8, GPIO_AF_OUTPUT_PP);  // FSMC_D05
160
+  gpio_set_mode(GPIOE,  9, GPIO_AF_OUTPUT_PP);  // FSMC_D06
161
+  gpio_set_mode(GPIOE, 10, GPIO_AF_OUTPUT_PP);  // FSMC_D07
162
+  gpio_set_mode(GPIOE, 11, GPIO_AF_OUTPUT_PP);  // FSMC_D08
163
+  gpio_set_mode(GPIOE, 12, GPIO_AF_OUTPUT_PP);  // FSMC_D09
164
+  gpio_set_mode(GPIOE, 13, GPIO_AF_OUTPUT_PP);  // FSMC_D10
165
+  gpio_set_mode(GPIOE, 14, GPIO_AF_OUTPUT_PP);  // FSMC_D11
166
+  gpio_set_mode(GPIOE, 15, GPIO_AF_OUTPUT_PP);  // FSMC_D12
167
+  gpio_set_mode(GPIOD,  8, GPIO_AF_OUTPUT_PP);  // FSMC_D13
168
+  gpio_set_mode(GPIOD,  9, GPIO_AF_OUTPUT_PP);  // FSMC_D14
169
+  gpio_set_mode(GPIOD, 10, GPIO_AF_OUTPUT_PP);  // FSMC_D15
170
+
171
+  gpio_set_mode(GPIOD,  4, GPIO_AF_OUTPUT_PP);  // FSMC_NOE
172
+  gpio_set_mode(GPIOD,  5, GPIO_AF_OUTPUT_PP);  // FSMC_NWE
173
+
174
+  gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP);  //FSMC_CS_NEx
175
+  gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP);  //FSMC_RS_Ax
176
+
177
+  fsmcPsramRegion->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
178
+  fsmcPsramRegion->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
179
+
180
+  afio_remap(AFIO_REMAP_FSMC_NADV);
181
+
182
+  LCD = (LCD_CONTROLLER_TypeDef*)controllerAddress;
183
+}
184
+
185
+void TFT_FSMC::Transmit(uint16_t Data) {
186
+  LCD->RAM = Data;
187
+  __DSB();
188
+}
189
+
190
+void TFT_FSMC::WriteReg(uint16_t Reg) {
191
+  LCD->REG = Reg;
192
+  __DSB();
193
+}
194
+
195
+uint32_t TFT_FSMC::GetID() {
196
+  uint32_t id;
197
+  WriteReg(0x0000);
198
+  id = LCD->RAM;
199
+
200
+  if (id == 0)
201
+    id = ReadID(LCD_READ_ID);
202
+  if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
203
+    id = ReadID(LCD_READ_ID4);
204
+  return id;
205
+}
206
+
207
+ uint32_t TFT_FSMC::ReadID(uint16_t Reg) {
208
+   uint32_t id;
209
+   WriteReg(Reg);
210
+   id = LCD->RAM; // dummy read
211
+   id = Reg << 24;
212
+   id |= (LCD->RAM & 0x00FF) << 16;
213
+   id |= (LCD->RAM & 0x00FF) << 8;
214
+   id |= LCD->RAM & 0x00FF;
215
+   return id;
216
+ }
217
+
218
+bool TFT_FSMC::isBusy() {
219
+  return false;
220
+}
221
+
222
+void TFT_FSMC::Abort() {
223
+
224
+}
225
+
226
+void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
227
+  dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease);
228
+  dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count);
229
+  dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
230
+  dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
231
+
232
+  while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
233
+  dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
234
+}
235
+
236
+#endif // HAS_FSMC_TFT

+ 64
- 0
Marlin/src/HAL/STM32F1/tft/tft_fsmc.h 查看文件

@@ -0,0 +1,64 @@
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
+#pragma once
23
+
24
+#ifndef LCD_READ_ID
25
+  #define LCD_READ_ID 0x04   // Read display identification information (0xD3 on ILI9341)
26
+#endif
27
+#ifndef LCD_READ_ID4
28
+  #define LCD_READ_ID4 0xD3   // Read display identification information (0xD3 on ILI9341)
29
+#endif
30
+
31
+#include <libmaple/dma.h>
32
+
33
+#define DATASIZE_8BIT    DMA_SIZE_8BITS
34
+#define DATASIZE_16BIT   DMA_SIZE_16BITS
35
+#define TFT_IO TFT_FSMC
36
+
37
+typedef struct {
38
+  __IO uint16_t REG;
39
+  __IO uint16_t RAM;
40
+} LCD_CONTROLLER_TypeDef;
41
+
42
+class TFT_FSMC {
43
+  private:
44
+    static LCD_CONTROLLER_TypeDef *LCD;
45
+
46
+    static uint32_t ReadID(uint16_t Reg);
47
+    static void Transmit(uint16_t Data);
48
+    static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
49
+
50
+  public:
51
+    static void Init();
52
+    static uint32_t GetID();
53
+    static bool isBusy();
54
+    static void Abort();
55
+
56
+    static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) {};
57
+    static void DataTransferEnd() {};
58
+
59
+    static void WriteData(uint16_t Data) { Transmit(Data); }
60
+    static void WriteReg(uint16_t Reg);
61
+
62
+    static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); }
63
+    static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); }
64
+};

+ 143
- 0
Marlin/src/HAL/STM32F1/tft/xpt2046.cpp 查看文件

@@ -0,0 +1,143 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 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_TFT_XPT2046
23
+
24
+#include "xpt2046.h"
25
+#include <SPI.h>
26
+
27
+uint16_t delta(uint16_t a, uint16_t b) { return a > b ? a - b : b - a; }
28
+
29
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
30
+  #include <SPI.h>
31
+
32
+  SPIClass XPT2046::SPIx(TOUCH_BUTTONS_HW_SPI_DEVICE);
33
+
34
+  static void touch_spi_init(uint8_t spiRate) {
35
+    /**
36
+     * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
37
+     * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
38
+     * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
39
+     */
40
+    uint8_t clock;
41
+    switch (spiRate) {
42
+      case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV4;  break;
43
+      case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4; break;
44
+      case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
45
+      case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
46
+      case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
47
+      case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
48
+      default:                clock = SPI_CLOCK_DIV2;        // Default from the SPI library
49
+    }
50
+    XPT2046::SPIx.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
51
+    XPT2046::SPIx.setClockDivider(clock);
52
+    XPT2046::SPIx.setBitOrder(MSBFIRST);
53
+    XPT2046::SPIx.setDataMode(SPI_MODE0);
54
+  }
55
+#endif // TOUCH_BUTTONS_HW_SPI
56
+
57
+void XPT2046::Init() {
58
+  SET_INPUT(TOUCH_MISO_PIN);
59
+  SET_OUTPUT(TOUCH_MOSI_PIN);
60
+  SET_OUTPUT(TOUCH_SCK_PIN);
61
+  OUT_WRITE(TOUCH_CS_PIN, HIGH);
62
+
63
+  #if PIN_EXISTS(TOUCH_INT)
64
+    // Optional Pendrive interrupt pin
65
+    SET_INPUT(TOUCH_INT_PIN);
66
+  #endif
67
+
68
+  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
69
+    touch_spi_init(SPI_SPEED_6);
70
+  #endif
71
+
72
+  // Read once to enable pendrive status pin
73
+  getRawData(XPT2046_X);
74
+}
75
+
76
+bool XPT2046::isTouched() {
77
+  return isBusy() ? false : (
78
+    #if PIN_EXISTS(TOUCH_INT)
79
+      READ(TOUCH_INT_PIN) != HIGH
80
+    #else
81
+      getRawData(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
82
+    #endif
83
+  );
84
+}
85
+
86
+bool XPT2046::getRawPoint(int16_t *x, int16_t *y) {
87
+  if (isBusy()) return false;
88
+  if (!isTouched()) return false;
89
+  *x = getRawData(XPT2046_X);
90
+  *y = getRawData(XPT2046_Y);
91
+  return isTouched();
92
+}
93
+
94
+uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
95
+  uint16_t data[3];
96
+
97
+  DataTransferBegin();
98
+
99
+  for (uint16_t i = 0; i < 3 ; i++) {
100
+    IO(coordinate);
101
+    data[i] = (IO() << 4) | (IO() >> 4);
102
+  }
103
+
104
+  DataTransferEnd();
105
+
106
+  uint16_t delta01 = delta(data[0], data[1]),
107
+           delta02 = delta(data[0], data[2]),
108
+           delta12 = delta(data[1], data[2]);
109
+
110
+  if (delta01 > delta02 || delta01 > delta12)
111
+    data[delta02 > delta12 ? 0 : 1] = data[2];
112
+
113
+  return (data[0] + data[1]) >> 1;
114
+}
115
+
116
+uint16_t XPT2046::IO(uint16_t data) {
117
+  TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data);
118
+}
119
+
120
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
121
+  uint16_t XPT2046::HardwareIO(uint16_t data) {
122
+    SPIx.begin();
123
+    uint16_t result = SPIx.transfer(data);
124
+    SPIx.end();
125
+    return result;
126
+  }
127
+#endif
128
+
129
+uint16_t XPT2046::SoftwareIO(uint16_t data) {
130
+  uint16_t result = 0;
131
+
132
+  for (uint8_t j = 0x80; j; j >>= 1) {
133
+    WRITE(TOUCH_SCK_PIN, LOW);
134
+    WRITE(TOUCH_MOSI_PIN, data & j ? HIGH : LOW);
135
+    if (READ(TOUCH_MISO_PIN)) result |= j;
136
+    WRITE(TOUCH_SCK_PIN, HIGH);
137
+  }
138
+  WRITE(TOUCH_SCK_PIN, LOW);
139
+
140
+  return result;
141
+}
142
+
143
+#endif // HAS_TFT_XPT2046

+ 78
- 0
Marlin/src/HAL/STM32F1/tft/xpt2046.h 查看文件

@@ -0,0 +1,78 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2019 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
+#pragma once
20
+
21
+#include "../../../inc/MarlinConfig.h"
22
+
23
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
24
+  #include <SPI.h>
25
+#endif
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."
35
+#endif
36
+
37
+#ifndef TOUCH_INT_PIN
38
+  #define TOUCH_INT_PIN  -1
39
+#endif
40
+
41
+#define XPT2046_DFR_MODE        0x00
42
+#define XPT2046_SER_MODE        0x04
43
+#define XPT2046_CONTROL         0x80
44
+
45
+enum XPTCoordinate : uint8_t {
46
+  XPT2046_X  = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
47
+  XPT2046_Y  = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
48
+  XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
49
+  XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
50
+};
51
+
52
+#if !defined(XPT2046_Z1_THRESHOLD)
53
+  #define XPT2046_Z1_THRESHOLD 10
54
+#endif
55
+
56
+class XPT2046 {
57
+private:
58
+  static bool isBusy() { return false; }
59
+
60
+  static uint16_t getRawData(const XPTCoordinate coordinate);
61
+  static bool isTouched();
62
+
63
+  static inline void DataTransferBegin() { WRITE(TOUCH_CS_PIN, LOW); };
64
+  static inline void DataTransferEnd() { WRITE(TOUCH_CS_PIN, HIGH); };
65
+  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
66
+    static uint16_t HardwareIO(uint16_t data);
67
+  #endif
68
+  static uint16_t SoftwareIO(uint16_t data);
69
+  static uint16_t IO(uint16_t data = 0);
70
+
71
+public:
72
+  #if ENABLED(TOUCH_BUTTONS_HW_SPI)
73
+    static SPIClass SPIx;
74
+  #endif
75
+
76
+  static void Init();
77
+  static bool getRawPoint(int16_t *x, int16_t *y);
78
+};

+ 0
- 1
Marlin/src/lcd/tft/touch.cpp 查看文件

@@ -22,7 +22,6 @@
22 22
 #if ENABLED(TOUCH_SCREEN)
23 23
 
24 24
 #include "touch.h"
25
-#include "pinconfig.h"
26 25
 
27 26
 #include "../ultralcd.h"
28 27
 #include "../menu/menu.h"

+ 35
- 12
Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h 查看文件

@@ -148,8 +148,8 @@
148 148
 #endif
149 149
 
150 150
 // SPI Flash
151
-#define SPI_FLASH_SIZE                      0x200000  // 2MB
152
-#define HAS_SPI_FLASH                       1
151
+#define SPI_FLASH_SIZE                  0x200000  // 2MB
152
+#define HAS_SPI_FLASH                          1
153 153
 
154 154
 // SPI 2
155 155
 #define W25QXX_CS_PIN                       PB12
@@ -197,24 +197,47 @@
197 197
   #define LCD_PIXEL_OFFSET_X     48
198 198
   #define LCD_PIXEL_OFFSET_Y     48
199 199
 
200
-  #define XPT2046_X_CALIBRATION  -12316
201
-  #define XPT2046_Y_CALIBRATION   8981
202
-  #define XPT2046_X_OFFSET        340
203
-  #define XPT2046_Y_OFFSET        -20
200
+  #define XPT2046_X_CALIBRATION           -12316
201
+  #define XPT2046_Y_CALIBRATION             8981
202
+  #define XPT2046_X_OFFSET                   340
203
+  #define XPT2046_Y_OFFSET                   -20
204 204
 
205 205
   #define USE_XPT2046       1
206 206
   #define XPT2046_XY_SWAP   0
207 207
   #define XPT2046_X_INV     1
208 208
   #define XPT2046_Y_INV     0
209 209
 
210
-  #define XPT2046_HOR_RES   480
211
-  #define XPT2046_VER_RES   320
212
-  #define XPT2046_X_MIN     140
213
-  #define XPT2046_Y_MIN     200
210
+  #define XPT2046_HOR_RES    480
211
+  #define XPT2046_VER_RES    320
212
+  #define XPT2046_X_MIN      140
213
+  #define XPT2046_Y_MIN      200
214 214
   #define XPT2046_X_MAX     1900
215 215
   #define XPT2046_Y_MAX     1900
216
-  #define XPT2046_AVG       4
217
-  #define XPT2046_INV       0
216
+  #define XPT2046_AVG          4
217
+  #define XPT2046_INV          0
218
+
219
+#elif ENABLED(TFT_480x320)
220
+  #define TFT_RESET_PIN                     PF11
221
+  #define TFT_BACKLIGHT_PIN                 PD13
222
+
223
+  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
224
+  #define FSMC_CS_PIN                       PD7
225
+  #define FSMC_RS_PIN                       PD11
226
+  #define FSMC_DMA_DEV                      DMA2
227
+  #define FSMC_DMA_CHANNEL               DMA_CH5
228
+
229
+  #define XPT2046_X_CALIBRATION           -17181
230
+  #define XPT2046_Y_CALIBRATION            11434
231
+  #define XPT2046_X_OFFSET                   501
232
+  #define XPT2046_Y_OFFSET                    -9
233
+
234
+  #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
235
+  #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
236
+  #define TOUCH_MISO_PIN                    PA6   // SPI1_MISO
237
+  #define TOUCH_MOSI_PIN                    PA7   // SPI1_MOSI
238
+
239
+  #define TFT_DRIVER                     ILI9488
240
+  #define TFT_BUFFER_SIZE                  14400
218 241
 #endif
219 242
 
220 243
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

+ 23
- 0
Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h 查看文件

@@ -156,6 +156,29 @@
156 156
       #define XPT2046_Y_OFFSET               -20
157 157
     #endif
158 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
159 182
 #endif
160 183
 
161 184
 // SPI Flash

+ 22
- 0
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h 查看文件

@@ -215,6 +215,28 @@
215 215
     #define TOUCH_MOSI_PIN                  PB15  // SPI2_MOSI
216 216
   #endif
217 217
 
218
+#elif ENABLED(TFT_480x320)
219
+  #define TFT_RESET_PIN                     PC6
220
+  #define TFT_BACKLIGHT_PIN                 PD13
221
+
222
+  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
223
+  #define FSMC_CS_PIN                       PD7
224
+  #define FSMC_RS_PIN                       PD11
225
+  #define FSMC_DMA_DEV                      DMA2
226
+  #define FSMC_DMA_CHANNEL               DMA_CH5
227
+
228
+  #define XPT2046_X_CALIBRATION           -17181
229
+  #define XPT2046_Y_CALIBRATION            11434
230
+  #define XPT2046_X_OFFSET                   501
231
+  #define XPT2046_Y_OFFSET                    -9
232
+
233
+  #define TOUCH_CS_PIN                      PA7   // SPI2_NSS
234
+  #define TOUCH_SCK_PIN                     PB13   // SPI2_SCK
235
+  #define TOUCH_MISO_PIN                    PB14   // SPI2_MISO
236
+  #define TOUCH_MOSI_PIN                    PB15   // SPI2_MOSI
237
+
238
+  #define TFT_DRIVER                        ILI9488
239
+  #define TFT_BUFFER_SIZE                   14400
218 240
 #endif
219 241
 
220 242
 #define SPI_FLASH

Loading…
取消
儲存