Browse Source

Optimize LVGL with HAL TFT IO (SPI and FSMC) (#18974)

Victor Oliveira 5 years ago
parent
commit
ff5c8d3570
No account linked to committer's email address

+ 10
- 8
Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_FSMC_TFT
25
+#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC)
26 26
 
27 27
 #include "tft_fsmc.h"
28 28
 #include <libmaple/fsmc.h>
@@ -224,13 +224,15 @@ void TFT_FSMC::Abort() {
224 224
 }
225 225
 
226 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);
227
+  #if defined(FSMC_DMA_DEV) && defined(FSMC_DMA_CHANNEL)
228
+    dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease);
229
+    dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count);
230
+    dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
231
+    dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
232
+
233
+    while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
234
+    dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
235
+  #endif
234 236
 }
235 237
 
236 238
 #endif // HAS_FSMC_TFT

+ 7
- 0
Marlin/src/HAL/STM32F1/tft/tft_fsmc.h View File

@@ -61,4 +61,11 @@ class TFT_FSMC {
61 61
 
62 62
     static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); }
63 63
     static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); }
64
+    static void WriteMultiple(uint16_t Color, uint32_t Count) {
65
+      static uint16_t Data; Data = Color;
66
+      while (Count > 0) {
67
+        TransmitDMA(DMA_CIRC_MODE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
68
+        Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
69
+      }
70
+    }
64 71
 };

+ 10
- 5
Marlin/src/HAL/STM32F1/tft/tft_spi.cpp View File

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../../../inc/MarlinConfig.h"
24 24
 
25
-#if HAS_SPI_TFT
25
+#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI)
26 26
 
27 27
 #include "tft_spi.h"
28 28
 
@@ -103,16 +103,21 @@ uint32_t TFT_SPI::ReadID(uint16_t Reg) {
103 103
   #if !PIN_EXISTS(TFT_MISO)
104 104
     return 0;
105 105
   #else
106
-    uint16_t d = 0;
106
+    uint8_t d = 0;
107
+    uint32_t data = 0;
108
+    SPIx.setClockDivider(SPI_CLOCK_DIV16);
107 109
     DataTransferBegin(DATASIZE_8BIT);
108 110
     WriteReg(Reg);
109 111
 
110
-    SPI.read((uint8_t*)&d, 1); //dummy read
111
-    SPI.read((uint8_t*)&d, 1);
112
+    LOOP_L_N(i, 4) {
113
+      SPIx.read((uint8_t*)&d, 1);
114
+      data = (data << 8) | d;
115
+    }
112 116
 
113 117
     DataTransferEnd();
118
+    SPIx.setClockDivider(SPI_CLOCK_MAX);
114 119
 
115
-    return d >> 7;
120
+    return data >> 7;
116 121
   #endif
117 122
 }
118 123
 

+ 7
- 0
Marlin/src/HAL/STM32F1/tft/tft_spi.h View File

@@ -62,4 +62,11 @@ public:
62 62
 
63 63
   static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
64 64
   static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
65
+  static void WriteMultiple(uint16_t Color, uint32_t Count) {
66
+    static uint16_t Data; Data = Color;
67
+    while (Count > 0) {
68
+      TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
69
+      Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
70
+    }
71
+  }
65 72
 };

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

@@ -252,7 +252,7 @@
252 252
 #endif
253 253
 
254 254
 // Full Touch Screen needs 'tft/xpt2046'
255
-#if ENABLED(TOUCH_SCREEN)
255
+#if EITHER(TOUCH_SCREEN, HAS_TFT_LVGL_UI)
256 256
   #define HAS_TFT_XPT2046 1
257 257
 #endif
258 258
 

+ 23
- 163
Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.cpp View File

@@ -54,112 +54,27 @@ TFT SPI_TFT;
54 54
 
55 55
 // use SPI1 for the spi tft.
56 56
 void TFT::spi_init(uint8_t spiRate) {
57
-
58
-  SPI_TFT_CS_H;
59
-
60
-  /**
61
-   * STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
62
-   * STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
63
-   * so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
64
-   */
65
-  uint8_t clock;
66
-  switch (spiRate) {
67
-    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV4;  break;
68
-    case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4; break;
69
-    case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
70
-    case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
71
-    case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
72
-    case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
73
-    default:                clock = SPI_CLOCK_DIV2;        // Default from the SPI library
74
-  }
75
-  SPI.setModule(1);
76
-  SPI.begin();
77
-  SPI.setClockDivider(clock);
78
-  SPI.setBitOrder(MSBFIRST);
79
-  SPI.setDataMode(SPI_MODE0);
80
-}
81
-
82
-uint8_t TFT::spi_Rec() {
83
-  uint8_t returnByte = SPI.transfer(ff);
84
-  return returnByte;
85
-}
86
-
87
-uint8_t TFT::spi_read_write_byte(uint8_t data) {
88
-  uint8_t returnByte = SPI.transfer(data);
89
-  return returnByte;
90
-}
91
-
92
-/**
93
- * @brief  Receive a number of bytes from the SPI port to a buffer
94
- *
95
- * @param  buf   Pointer to starting address of buffer to write to.
96
- * @param  nbyte Number of bytes to receive.
97
- * @return Nothing
98
- *
99
- * @details Uses DMA
100
- */
101
-void TFT::spi_Read(uint8_t* buf, uint16_t nbyte) {SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);}
102
-
103
-/**
104
- * @brief  Send a single byte on SPI port
105
- *
106
- * @param  b Byte to send
107
- *
108
- * @details
109
- */
110
-void TFT::spi_Send(uint8_t b) {SPI.send(b);}
111
-
112
-/**
113
- * @brief  Write token and then write from 512 byte buffer to SPI (for SD card)
114
- *
115
- * @param  buf   Pointer with buffer start address
116
- * @return Nothing
117
- *
118
- * @details Use DMA
119
- */
120
-void TFT::spi_SendBlock(uint8_t token, const uint8_t* buf) {
121
-  SPI.send(token);
122
-  SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
57
+  tftio.Init();
123 58
 }
124 59
 
125 60
 void TFT::LCD_WR_REG(uint8_t cmd) {
126
-  SPI_TFT_CS_L;
127
-  SPI_TFT_DC_L;
128
-  spi_Send(cmd);
129
-  SPI_TFT_CS_H;
61
+  tftio.WriteReg(cmd);
130 62
 }
131
-void TFT::LCD_WR_DATA(uint8_t data) {
132
-  SPI_TFT_CS_L;
133
-  SPI_TFT_DC_H;
134
-  spi_Send(data);
135
-  SPI_TFT_CS_H;
136
-}
137
-void TFT::LCD_WriteRAM_Prepare() {LCD_WR_REG(0X2C);}
138
-void TFT::SetCursor(uint16_t x, uint16_t y) {
139
-  LCD_WR_REG(0x2A);
140
-  LCD_WR_DATA(x >> 8);
141
-  LCD_WR_DATA(x);
142
-  LCD_WR_DATA(x >> 8);
143
-  LCD_WR_DATA(x);
144 63
 
145
-  LCD_WR_REG(0x2B);
146
-  LCD_WR_DATA(y >> 8);
147
-  LCD_WR_DATA(y);
148
-  LCD_WR_DATA(y >> 8);
149
-  LCD_WR_DATA(y);
64
+void TFT::LCD_WR_DATA(uint8_t data) {
65
+  tftio.WriteData(data);
150 66
 }
151 67
 
152 68
 void TFT::SetPoint(uint16_t x, uint16_t y, uint16_t point) {
153 69
   if ((x > 480) || (y > 320)) return;
154 70
 
155
-  SetCursor(x, y);
156
-
157
-  LCD_WriteRAM_Prepare();
158
-  LCD_WR_DATA((uint8_t)(point >> 8));
159
-  LCD_WR_DATA((uint8_t)point);
71
+  SetWindows(x, y, 1, 1);
72
+  tftio.WriteMultiple(point, (uint16_t)1);
160 73
 }
161 74
 
162 75
 void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
76
+  tftio.DataTransferBegin(DATASIZE_8BIT);
77
+
163 78
   LCD_WR_REG(0x2A);
164 79
   LCD_WR_DATA(x >> 8);
165 80
   LCD_WR_DATA(x);
@@ -171,6 +86,10 @@ void TFT::SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height) {
171 86
   LCD_WR_DATA(y);
172 87
   LCD_WR_DATA((y + height - 1) >> 8);
173 88
   LCD_WR_DATA(y + height - 1);
89
+
90
+  LCD_WR_REG(0X2C);
91
+
92
+  tftio.DataTransferEnd();
174 93
 }
175 94
 
176 95
 void TFT::LCD_init() {
@@ -180,6 +99,8 @@ void TFT::LCD_init() {
180 99
   delay(150);
181 100
   SPI_TFT_RST_H;
182 101
 
102
+  tftio.DataTransferBegin(DATASIZE_8BIT);
103
+
183 104
   delay(120);
184 105
   LCD_WR_REG(0x11);
185 106
   delay(120);
@@ -251,6 +172,8 @@ void TFT::LCD_init() {
251 172
   delay(120);     // Delay 120ms
252 173
   LCD_WR_REG(0x29);     // Display ON
253 174
 
175
+  tftio.DataTransferEnd();
176
+
254 177
   LCD_clear(0x0000);    //
255 178
   LCD_Draw_Logo();
256 179
   SPI_TFT_BLK_H;
@@ -258,81 +181,18 @@ void TFT::LCD_init() {
258 181
 }
259 182
 
260 183
 void TFT::LCD_clear(uint16_t color) {
261
-  unsigned int i;
262
-  uint8_t tbuf[960];
263
-
264
-  SetCursor(0, 0);
265
-  SetWindows(0, 0, 480 - 1, 320 - 1);
266
-  LCD_WriteRAM_Prepare();
267
-  SPI_TFT_CS_L;
268
-  SPI_TFT_DC_H;
269
-  for (i = 0; i < 960;) {
270
-    tbuf[i]     = color >> 8;
271
-    tbuf[i + 1] = color;
272
-    i += 2;
273
-  }
274
-  for (i = 0; i < 320; i++) {
275
-    // for (m=0;m<480;m++)
276
-    // {
277
-    // LCD_WR_DATA(color>>8);
278
-    // LCD_WR_DATA(color);
279
-    SPI.dmaSend(tbuf, 960, true);
280
-    // SPI_TFT_CS_H;
281
-    // }
282
-  }
283
-  SPI_TFT_CS_H;
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));
284 186
 }
285 187
 
286 188
 extern unsigned char bmp_public_buf[17 * 1024];
287 189
 
288 190
 void TFT::LCD_Draw_Logo() {
289
-  uint16_t i,y_off = 0;
290
-  uint16_t *p_index;
291
-  uint16_t Color;
292
-
293
-  #if 1
294
-    for (y_off = 0; y_off < 320; y_off ++) {
295
-      Pic_Logo_Read((uint8_t *)"", (uint8_t *)bmp_public_buf, 960);
296
-
297
-      SPI_TFT.spi_init(SPI_FULL_SPEED);
298
-      SetWindows(0, y_off, 480, 1);
299
-      LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
300
-      for (i = 0; i < 960;) {
301
-        p_index = (uint16_t *)(&bmp_public_buf[i]);
302
-        Color = (*p_index >> 8);
303
-        *p_index = Color | ((*p_index & 0xFF) << 8);
304
-        i+=2;
305
-      }
306
-      SPI_TFT_CS_L;
307
-      SPI_TFT_DC_H;
308
-      SPI.dmaSend(bmp_public_buf,960,true);
309
-      SPI_TFT_CS_H;
310
-    }
311
-
312
-  #else
313
-
314
-    for (index = 0; index < 40; index ++) {
315
-      Pic_Logo_Read((uint8_t *)"", bmp_public_buf, 480*8*2);
316
-      i = 0;
317
-      SetCursor(0,0);
318
-      SetWindows(0, y_off * 8, 480, 8);
319
-      LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
320
-      for (i = 0; i < 480 * 8 * 2;) {
321
-        p_index = (uint16_t *)(&bmp_public_buf[i]);
322
-        Color = (*p_index >> 8);
323
-        *p_index = Color | ((*p_index & 0xFF) << 8);
324
-        i += 2;
325
-      }
326
-      SPI_TFT_CS_L;
327
-      SPI_TFT_DC_H;
328
-      SPI.dmaSend(bmp_public_buf,480*8*2,true);
329
-      SPI_TFT_CS_H;
330
-
331
-      y_off++;
332
-    }
333
-  #endif
334
-
335
-  SetWindows(0, 0, 479, 319);
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);
195
+  }
336 196
 }
337 197
 
338 198
 #endif // HAS_TFT_LVGL_UI_SPI

+ 7
- 13
Marlin/src/lcd/extui/lib/mks_ui/SPI_TFT.h View File

@@ -21,13 +21,13 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include <stdint.h>
24
+#include "../../inc/MarlinConfigPre.h"
25 25
 
26
-#define SPI_TFT_CS_H  OUT_WRITE(SPI_TFT_CS_PIN, HIGH)
27
-#define SPI_TFT_CS_L  OUT_WRITE(SPI_TFT_CS_PIN, LOW)
28
-
29
-#define SPI_TFT_DC_H  OUT_WRITE(SPI_TFT_DC_PIN, HIGH)
30
-#define SPI_TFT_DC_L  OUT_WRITE(SPI_TFT_DC_PIN, LOW)
26
+#if ENABLED(TFT_LVGL_UI_SPI)
27
+  #include HAL_PATH(../../HAL, tft/tft_spi.h)
28
+#elif ENABLED(TFT_LVGL_UI_FSMC)
29
+  #include HAL_PATH(../../HAL, tft/tft_fsmc.h)
30
+#endif
31 31
 
32 32
 #define SPI_TFT_RST_H OUT_WRITE(SPI_TFT_RST_PIN, HIGH)
33 33
 #define SPI_TFT_RST_L OUT_WRITE(SPI_TFT_RST_PIN, LOW)
@@ -37,20 +37,14 @@
37 37
 
38 38
 class TFT {
39 39
 public:
40
+  TFT_IO tftio;
40 41
   void spi_init(uint8_t spiRate);
41
-  uint8_t spi_Rec();
42
-  uint8_t spi_read_write_byte(uint8_t data);
43
-  void spi_Read(uint8_t* buf, uint16_t nbyte);
44
-  void spi_Send(uint8_t b);
45
-  void spi_SendBlock(uint8_t token, const uint8_t* buf);
46 42
   void LCD_WR_REG(uint8_t cmd);
47 43
   void LCD_WR_DATA(uint8_t data);
48
-  void SetCursor(uint16_t x, uint16_t y);
49 44
   void SetPoint(uint16_t x, uint16_t y, uint16_t point);
50 45
   void SetWindows(uint16_t x, uint16_t y, uint16_t with, uint16_t height);
51 46
   void LCD_init();
52 47
   void LCD_clear(uint16_t color);
53
-  void LCD_WriteRAM_Prepare();
54 48
   void LCD_Draw_Logo();
55 49
 };
56 50
 

+ 2
- 0
Marlin/src/lcd/extui/lib/mks_ui/draw_dialog.cpp View File

@@ -51,6 +51,8 @@
51 51
 #endif
52 52
 #include "../../../../gcode/gcode.h"
53 53
 
54
+#include "pic_manager.h"
55
+
54 56
 static lv_obj_t * scr;
55 57
 extern uint8_t sel_id;
56 58
 extern uint8_t once_flag;

+ 8
- 61
Marlin/src/lcd/extui/lib/mks_ui/draw_ui.cpp View File

@@ -500,14 +500,9 @@ char *creat_title_text() {
500 500
           }
501 501
         }
502 502
 
503
-        //SERIAL_ECHOLNPAIR("gPicturePreviewStart: ", gPicturePreviewStart, " PREVIEW_LITTLE_PIC_SIZE: ", PREVIEW_LITTLE_PIC_SIZE);
504
-
505 503
         card.setIndex((gPicturePreviewStart + To_pre_view) + size * row + 8);
506 504
         #if ENABLED(TFT_LVGL_UI_SPI)
507
-          SPI_TFT.spi_init(SPI_FULL_SPEED);
508
-          //SPI_TFT.SetCursor(0,0);
509 505
           SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
510
-          SPI_TFT.LCD_WriteRAM_Prepare();
511 506
         #else
512 507
           ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
513 508
           LCD_WriteRAM_Prepare();
@@ -525,19 +520,11 @@ char *creat_title_text() {
525 520
           if (j >= 400) break;
526 521
         }
527 522
         #if ENABLED(TFT_LVGL_UI_SPI)
528
-          uint16_t Color, SpiColor;
529
-          SpiColor = (LV_COLOR_BACKGROUND.full >> 8) | ((LV_COLOR_BACKGROUND.full & 0xFF) << 8);
530
-          for (i = 0; i < 400;) {
523
+          for (i = 0; i < 400; i += 2) {
531 524
             p_index  = (uint16_t *)(&bmp_public_buf[i]);
532
-            Color    = (*p_index >> 8);
533
-            *p_index = Color | ((*p_index & 0xFF) << 8);
534
-            i       += 2;
535
-            if (*p_index == 0x0000) *p_index = SpiColor;
525
+            if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
536 526
           }
537
-          SPI_TFT_CS_L;
538
-          SPI_TFT_DC_H;
539
-          SPI.dmaSend(bmp_public_buf, 400, true);
540
-          SPI_TFT_CS_H;
527
+          SPI_TFT.tftio.WriteSequence((uint16_t*)bmp_public_buf, 200);
541 528
         #else
542 529
           for (i = 0; i < 400;) {
543 530
             p_index = (uint16_t *)(&bmp_public_buf[i]);
@@ -627,10 +614,7 @@ char *creat_title_text() {
627 614
 
628 615
         card.setIndex((PREVIEW_LITTLE_PIC_SIZE + To_pre_view) + size * row + 8);
629 616
         #if ENABLED(TFT_LVGL_UI_SPI)
630
-          SPI_TFT.spi_init(SPI_FULL_SPEED);
631
-          //SPI_TFT.SetCursor(0,0);
632 617
           SPI_TFT.SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
633
-          SPI_TFT.LCD_WriteRAM_Prepare();
634 618
         #else
635 619
           ili9320_SetWindows(xpos_pixel, ypos_pixel + row, 200, 1);
636 620
           LCD_WriteRAM_Prepare();
@@ -750,9 +734,6 @@ char *creat_title_text() {
750 734
   void Draw_default_preview(int xpos_pixel, int ypos_pixel, uint8_t sel) {
751 735
     int index;
752 736
     int y_off = 0;
753
-    int _y;
754
-    uint16_t *p_index;
755
-    int i;
756 737
 
757 738
     for (index = 0; index < 10; index++) { // 200*200
758 739
       #if HAS_BAK_VIEW_IN_FLASH
@@ -761,58 +742,24 @@ char *creat_title_text() {
761 742
         }
762 743
         else {
763 744
           default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k
764
-          #if ENABLED(TFT_LVGL_UI_SPI)
765
-            uint16_t Color;
766
-            for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) {
767
-              p_index = (uint16_t *)(&bmp_public_buf[i]);
768
-              Color = (*p_index >> 8);
769
-              *p_index = Color | ((*p_index & 0xff) << 8);
770
-              i += 2;
771
-            }
772
-          #endif
773 745
         }
774 746
       #else
775 747
         default_view_Read(bmp_public_buf, DEFAULT_VIEW_MAX_SIZE / 10); // 20k
776
-        #if ENABLED(TFT_LVGL_UI_SPI)
777
-          for (i = 0; i < (DEFAULT_VIEW_MAX_SIZE / 10);) {
778
-            p_index = (uint16_t *)(&bmp_public_buf[i]);
779
-            Color = (*p_index >> 8);
780
-            *p_index = Color | ((*p_index & 0xff) << 8);
781
-            i += 2;
782
-          }
783
-        #endif
784 748
       #endif
785 749
 
786
-      i = 0;
787 750
       #if ENABLED(TFT_LVGL_UI_SPI)
788
-
789
-        //SPI_TFT.spi_init(SPI_FULL_SPEED);
790
-        //SPI_TFT.SetWindows(xpos_pixel, y_off * 20+ypos_pixel, 200,20);     //200*200
791
-        //SPI_TFT.LCD_WriteRAM_Prepare();
792
-        int j = 0;
793
-        for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) {
794
-          SPI_TFT.spi_init(SPI_FULL_SPEED);
795
-          SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel + j, 200, 1); // 200*200
796
-          SPI_TFT.LCD_WriteRAM_Prepare();
797
-
798
-          j++;
799
-          //memcpy(public_buf,&bmp_public_buf[i],400);
800
-          SPI_TFT_CS_L;
801
-          SPI_TFT_DC_H;
802
-          SPI.dmaSend(&bmp_public_buf[i], 400, true);
803
-          SPI_TFT_CS_H;
804
-
805
-          i += 400;
806
-          if (i >= 8000) break;
807
-        }
751
+        SPI_TFT.SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200
752
+        SPI_TFT.tftio.WriteSequence((uint16_t*)(bmp_public_buf), DEFAULT_VIEW_MAX_SIZE / 20);
808 753
       #else
809 754
         int x_off = 0;
810 755
         uint16_t temp_p;
756
+        int i = 0;
757
+        uint16_t *p_index;
811 758
         ili9320_SetWindows(xpos_pixel, y_off * 20 + ypos_pixel, 200, 20); // 200*200
812 759
 
813 760
         LCD_WriteRAM_Prepare();
814 761
 
815
-        for (_y = y_off * 20; _y < (y_off + 1) * 20; _y++) {
762
+        for (int _y = y_off * 20; _y < (y_off + 1) * 20; _y++) {
816 763
           for (x_off = 0; x_off < 200; x_off++) {
817 764
             if (sel == 1) {
818 765
               temp_p  = (uint16_t)(bmp_public_buf[i] | bmp_public_buf[i + 1] << 8);

+ 0
- 2
Marlin/src/lcd/extui/lib/mks_ui/mks_hardware_test.cpp View File

@@ -590,8 +590,6 @@ void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint1
590 590
 }
591 591
 
592 592
 void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor) {
593
-  // Select TFT SPI so it can receive data
594
-  TERN_(TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED));
595 593
   while (*string != '\0') {
596 594
     disp_char_1624(x, y, *string, charColor, bkColor);
597 595
     string++;

+ 31
- 241
Marlin/src/lcd/extui/lib/mks_ui/tft_fsmc.cpp View File

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

+ 38
- 242
Marlin/src/lcd/extui/lib/mks_ui/tft_lvgl_configuration.cpp View File

@@ -42,9 +42,8 @@
42 42
 
43 43
 #include "../../../../inc/MarlinConfig.h"
44 44
 
45
-#if HAS_TOUCH_XPT2046
46
-  #include "../../../touch/xpt2046.h"
47
-#endif
45
+#include HAL_PATH(../../HAL, tft/xpt2046.h)
46
+XPT2046 touch;
48 47
 
49 48
 #if ENABLED(POWER_LOSS_RECOVERY)
50 49
   #include "../../../../feature/powerloss.h"
@@ -121,14 +120,14 @@ void tft_set_cursor(uint16_t x, uint16_t y) {
121 120
 
122 121
 void LCD_WriteRAM_Prepare(void) {
123 122
   #if 0
124
-  if ((DeviceCode == 0x9325) || (DeviceCode == 0x9328) || (DeviceCode == 0x8989)) {
125
-    ClrCs
126
-    LCD->LCD_REG = R34;
127
-    SetCs
128
-  }
129
-  else {
130
-    LCD_WrtReg(0x002C);
131
-  }
123
+    switch (DeviceCode) {
124
+      case 0x9325: case 0x9328: case 0x8989: {
125
+        ClrCs
126
+        LCD->LCD_REG = R34;
127
+        SetCs
128
+      } break;
129
+      default: LCD_WrtReg(0x002C);
130
+    }
132 131
   #else
133 132
     LCD_IO_WriteReg(0x002C);
134 133
   #endif
@@ -197,8 +196,8 @@ void ili9320_SetWindows(uint16_t StartX, uint16_t StartY, uint16_t width, uint16
197 196
      LCD_WriteReg(0x0053, yEnd);*/
198 197
     LCD_WriteReg(0x0050, StartY);   // Specify the start/end positions of the window address in the horizontal direction by an address unit
199 198
     LCD_WriteReg(0x0051, yEnd);     // Specify the start positions of the window address in the vertical direction by an address unit
200
-    LCD_WriteReg(0x0052, 320 - xEnd);
201
-    LCD_WriteReg(0x0053, 320 - StartX - 1); // Specify the end 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
202 201
 
203 202
   }
204 203
   else {
@@ -268,28 +267,10 @@ void LCD_Clear(uint16_t Color) {
268 267
   }
269 268
 }
270 269
 
271
-extern uint16_t ILI9488_ReadRAM();
272
-
270
+#include HAL_PATH(../../HAL, tft/tft_fsmc.h)
271
+extern TFT_IO tftio;
273 272
 void init_tft() {
274 273
   uint16_t i;
275
-  //************* Start Initial Sequence **********//
276
-
277
-  //start lcd pins and dma
278
-  #if PIN_EXISTS(LCD_BACKLIGHT)
279
-    OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away
280
-  #endif
281
-
282
-  #if PIN_EXISTS(LCD_RESET)
283
-    // Perform a clean hardware reset with needed delays
284
-    OUT_WRITE(LCD_RESET_PIN, LOW);
285
-    _delay_ms(5);
286
-    WRITE(LCD_RESET_PIN, HIGH);
287
-    _delay_ms(5);
288
-  #endif
289
-
290
-  #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
291
-    WRITE(LCD_BACKLIGHT_PIN, HIGH);
292
-  #endif
293 274
 
294 275
   TERN_(HAS_LCD_CONTRAST, refresh_contrast());
295 276
 
@@ -303,12 +284,9 @@ void init_tft() {
303 284
 
304 285
   _delay_ms(5);
305 286
 
306
-  LCD_IO_WriteReg(0x00D3);
307
-  DeviceCode = ILI9488_ReadRAM(); //dummy read
308
-  DeviceCode = ILI9488_ReadRAM();
309
-  DeviceCode = ILI9488_ReadRAM();
310
-  DeviceCode <<= 8;
311
-  DeviceCode |= ILI9488_ReadRAM();
287
+  DeviceCode = tftio.GetID() & 0xFFFF;
288
+  // Chitu and others
289
+  if (DeviceCode == 0x8066) DeviceCode = 0x9488;
312 290
 
313 291
   if (DeviceCode == 0x9488) {
314 292
     LCD_IO_WriteReg(0x00E0);
@@ -436,7 +414,7 @@ void tft_lvgl_init() {
436 414
 
437 415
   //spi_flash_read_test();
438 416
 
439
-  TERN_(HAS_TOUCH_XPT2046, touch.init());
417
+  touch.Init();
440 418
 
441 419
   lv_init();
442 420
 
@@ -492,35 +470,14 @@ void tft_lvgl_init() {
492 470
 void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
493 471
   #if ENABLED(TFT_LVGL_UI_SPI)
494 472
     uint16_t i, width, height;
495
-    uint16_t clr_temp;
496
-    uint8_t tbuf[(LCD_FULL_PIXEL_WIDTH) * 2];
497
-
498
-    SPI_TFT.spi_init(SPI_FULL_SPEED);
499 473
 
500 474
     width = area->x2 - area->x1 + 1;
501 475
     height = area->y2 - area->y1 + 1;
502 476
 
503
-    for (int j = 0; j < height; j++) {
504
-      SPI_TFT.SetCursor(0, 0);
505
-      SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1 + j, width, 1);
506
-      SPI_TFT.LCD_WriteRAM_Prepare();
507
-
508
-      for (i = 0; i < width * 2;) {
509
-        clr_temp = (uint16_t)(((uint16_t)color_p->ch.red << 11)
510
-                              | ((uint16_t)color_p->ch.green << 5)
511
-                              | ((uint16_t)color_p->ch.blue));
512
-
513
-        tbuf[i] = clr_temp >> 8;
514
-        tbuf[i + 1] = clr_temp;
515
-        i += 2;
516
-        color_p++;
517
-      }
518
-      SPI_TFT_CS_L;
519
-      SPI_TFT_DC_H;
520
-      SPI.dmaSend(tbuf, width * 2, true);
521
-      SPI_TFT_CS_H;
477
+    SPI_TFT.SetWindows((uint16_t)area->x1, (uint16_t)area->y1, width, height);
478
+    for (i = 0; i < height; i++) {
479
+      SPI_TFT.tftio.WriteSequence((uint16_t*)(color_p + width * i), width);
522 480
     }
523
-
524 481
     lv_disp_flush_ready(disp);       /* Indicate you are ready with the flushing*/
525 482
 
526 483
     W25QXX.init(SPI_QUARTER_SPEED);
@@ -556,174 +513,23 @@ unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) {
556 513
   return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick));
557 514
 }
558 515
 
559
-#if ENABLED(TFT_LVGL_UI_SPI)
560
-
561
-  #ifndef USE_XPT2046
562
-    #define USE_XPT2046       1
563
-    #define XPT2046_XY_SWAP   1
564
-    #define XPT2046_X_INV     1
565
-    #define XPT2046_Y_INV     0
566
-  #endif
567
-
568
-  #if USE_XPT2046
569
-    #define XPT2046_HOR_RES 480
570
-    #define XPT2046_VER_RES 320
571
-    #define XPT2046_X_MIN   201
572
-    #define XPT2046_Y_MIN   164
573
-    #define XPT2046_X_MAX  3919
574
-    #define XPT2046_Y_MAX  3776
575
-    #define XPT2046_AVG       4
576
-    #define XPT2046_INV       1
577
-  #endif
578
-
579
-#else
580
-
581
-  #ifndef USE_XPT2046
582
-    #define USE_XPT2046       1
583
-    #ifndef XPT2046_XY_SWAP
584
-      #define XPT2046_XY_SWAP 1
585
-    #endif
586
-    #ifndef XPT2046_X_INV
587
-      #define XPT2046_X_INV   0
588
-    #endif
589
-    #ifndef XPT2046_Y_INV
590
-      #define XPT2046_Y_INV   1
591
-    #endif
592
-  #endif
593
-
594
-  #if USE_XPT2046
595
-    #ifndef XPT2046_HOR_RES
596
-      #define XPT2046_HOR_RES 480
597
-    #endif
598
-    #ifndef XPT2046_VER_RES
599
-      #define XPT2046_VER_RES 320
600
-    #endif
601
-    #ifndef XPT2046_X_MIN
602
-      #define XPT2046_X_MIN   201
603
-    #endif
604
-    #ifndef XPT2046_Y_MIN
605
-      #define XPT2046_Y_MIN   164
606
-    #endif
607
-    #ifndef XPT2046_X_MAX
608
-      #define XPT2046_X_MAX  3919
609
-    #endif
610
-    #ifndef XPT2046_Y_MAX
611
-      #define XPT2046_Y_MAX  3776
612
-    #endif
613
-    #ifndef XPT2046_AVG
614
-      #define XPT2046_AVG       4
615
-    #endif
616
-    #ifndef XPT2046_INV
617
-      #define XPT2046_INV       0
618
-    #endif
619
-  #endif
620
-
621
-#endif
622
-
623
-static void xpt2046_corr(uint16_t *x, uint16_t *y) {
624
-  #if XPT2046_XY_SWAP
625
-    int16_t swap_tmp;
626
-    swap_tmp = *x;
627
-    *x = *y;
628
-    *y = swap_tmp;
629
-  #endif
630
-  if ((*x) > XPT2046_X_MIN) (*x) -= XPT2046_X_MIN; else (*x) = 0;
631
-  if ((*y) > XPT2046_Y_MIN) (*y) -= XPT2046_Y_MIN; else (*y) = 0;
632
-  (*x) = uint32_t(uint32_t(*x) * XPT2046_HOR_RES) / (XPT2046_X_MAX - XPT2046_X_MIN);
633
-  (*y) = uint32_t(uint32_t(*y) * XPT2046_VER_RES) / (XPT2046_Y_MAX - XPT2046_Y_MIN);
634
-  #if XPT2046_X_INV
635
-    (*x) = XPT2046_HOR_RES - (*x);
636
-  #endif
637
-  #if XPT2046_Y_INV
638
-    (*y) = XPT2046_VER_RES - (*y);
639
-  #endif
640
-}
641
-
642
-#define times 4
643
-#define CHX   0x90
644
-#define CHY   0xD0
645
-
646
-int SPI2_ReadWrite2Bytes(void) {
647
-  #define SPI_READ_WRITE_BYTE(B) TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_read_write_byte, W25QXX.spi_flash_read_write_byte)(B)
648
-  const uint16_t t1 = SPI_READ_WRITE_BYTE(0xFF),
649
-                 t2 = SPI_READ_WRITE_BYTE(0xFF);
650
-  return (((t1 << 8) | t2) >> 3) & 0x0FFF;
651
-}
516
+static bool get_point(int16_t *x, int16_t *y) {
517
+  bool is_touched = touch.getRawPoint(x, y);
652 518
 
653
-uint16_t x_addata[times], y_addata[times];
654
-void XPT2046_Rd_Addata(uint16_t *X_Addata, uint16_t *Y_Addata) {
655
-  uint16_t i, j, k;
656
-
657
-  TERN(TFT_LVGL_UI_SPI, SPI_TFT.spi_init, W25QXX.init)(SPI_SPEED_6);
658
-
659
-  for (i = 0; i < times; i++) {
660
-    #if ENABLED(TFT_LVGL_UI_SPI)
661
-      OUT_WRITE(TOUCH_CS_PIN, LOW);
662
-      SPI_TFT.spi_read_write_byte(CHX);
663
-      y_addata[i] = SPI2_ReadWrite2Bytes();
664
-      WRITE(TOUCH_CS_PIN, HIGH);
665
-
666
-      OUT_WRITE(TOUCH_CS_PIN, LOW);
667
-      SPI_TFT.spi_read_write_byte(CHY);
668
-      x_addata[i] = SPI2_ReadWrite2Bytes();
669
-      WRITE(TOUCH_CS_PIN, HIGH);
670
-    #else // #if HAS_TOUCH_XPT2046
671
-      OUT_WRITE(TOUCH_CS_PIN, LOW);
672
-      W25QXX.spi_flash_read_write_byte(CHX);
673
-      y_addata[i] = SPI2_ReadWrite2Bytes();
674
-      WRITE(TOUCH_CS_PIN, HIGH);
675
-
676
-      OUT_WRITE(TOUCH_CS_PIN, LOW);
677
-      W25QXX.spi_flash_read_write_byte(CHY);
678
-      x_addata[i] = SPI2_ReadWrite2Bytes();
679
-      WRITE(TOUCH_CS_PIN, HIGH);
680
-    #endif
681
-
682
-  }
683
-  TERN(TFT_LVGL_UI_SPI,,W25QXX.init(SPI_QUARTER_SPEED));
684
-
685
-  for (i = 0; i < times; i++)
686
-    for (j = i + 1; j < times; j++)
687
-      if (x_addata[j] > x_addata[i]) {
688
-        k = x_addata[j];
689
-        x_addata[j] = x_addata[i];
690
-        x_addata[i] = k;
691
-      }
692
-  if (x_addata[times / 2 - 1] - x_addata[times / 2] > 50) {
693
-    *X_Addata = *Y_Addata = 0;
694
-    return;
695
-  }
696
-
697
-  *X_Addata = (x_addata[times / 2 - 1] + x_addata[times / 2]) / 2;
698
-
699
-  for (i = 0; i < times; i++)
700
-    for (j = i + 1; j < times; j++)
701
-      if (y_addata[j] > y_addata[i]) {
702
-        k = y_addata[j];
703
-        y_addata[j] = y_addata[i];
704
-        y_addata[i] = k;
705
-      }
706
-
707
-  if (y_addata[times / 2 - 1] - y_addata[times / 2] > 50) {
708
-    *X_Addata = *Y_Addata = 0;
709
-    return;
519
+  if (is_touched) {
520
+    *x = int16_t((int32_t(*x) * XPT2046_X_CALIBRATION) >> 16) + XPT2046_X_OFFSET;
521
+    *y = int16_t((int32_t(*y) * XPT2046_Y_CALIBRATION) >> 16) + XPT2046_Y_OFFSET;
710 522
   }
711 523
 
712
-  *Y_Addata = (y_addata[times / 2 - 1] + y_addata[times / 2]) / 2;
713
-}
714
-
715
-#define ADC_VALID_OFFSET  10
524
+  #if ENABLED(GRAPHICAL_TFT_ROTATE_180)
525
+    x = (LCD_FULL_PIXEL_WIDTH) - x;
526
+    y = (LCD_FULL_PIXEL_HEIGHT) - y;
527
+  #endif
716 528
 
717
-uint8_t TOUCH_PressValid(uint16_t _usX, uint16_t _usY) {
718
-  if ( (_usX <= ADC_VALID_OFFSET)
719
-    || (_usY <= ADC_VALID_OFFSET)
720
-    || (_usX >= 4095 - ADC_VALID_OFFSET)
721
-    || (_usY >= 4095 - ADC_VALID_OFFSET)
722
-  ) return 0;
723
-  return 1;
529
+  return is_touched;
724 530
 }
725 531
 
726
-static lv_coord_t last_x = 0, last_y = 0;
532
+static int16_t last_x = 0, last_y = 0;
727 533
 bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
728 534
   uint32_t tmpTime, diffTime = 0;
729 535
 
@@ -735,34 +541,24 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
735 541
   //touchpad_get_xy(&last_x, &last_y);
736 542
   /*Save the pressed coordinates and the state*/
737 543
   if (diffTime > 10) {
738
-    //use marlin touch code if enabled
739
-    #if HAS_TOUCH_XPT2046
740
-      touch.getTouchPoint(reinterpret_cast<uint16_t&>(last_x), reinterpret_cast<uint16_t&>(last_y));
741
-    #else
742
-      XPT2046_Rd_Addata((uint16_t *)&last_x, (uint16_t *)&last_y);
743
-    #endif
744
-    if (TOUCH_PressValid(last_x, last_y)) {
544
+    if (get_point(&last_x, &last_y)) {
745 545
 
746 546
       data->state = LV_INDEV_STATE_PR;
747 547
 
748
-      /* Set the coordinates (if released use the last pressed coordinates) */
548
+      // Set the coordinates (if released use the last-pressed coordinates)
749 549
 
750
-      // SERIAL_ECHOLNPAIR("antes X: ", last_x, ", y: ", last_y);
751
-      xpt2046_corr((uint16_t *)&last_x, (uint16_t *)&last_y);
752
-      // SERIAL_ECHOLNPAIR("X: ", last_x, ", y: ", last_y);
753 550
       data->point.x = last_x;
754 551
       data->point.y = last_y;
755 552
 
756
-      last_x = 0;
757
-      last_y = 0;
553
+      last_x = last_y = 0;
758 554
     }
759
-    else {
555
+    else
760 556
       data->state = LV_INDEV_STATE_REL;
761
-    }
557
+
762 558
     touch_time1 = tmpTime;
763 559
   }
764 560
 
765
-  return false; /*Return `false` because we are not buffering and no more data to read*/
561
+  return false; // Return `false` since no data is buffering or left to read
766 562
 }
767 563
 
768 564
 #endif // HAS_TFT_LVGL_UI

+ 6
- 19
Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h View File

@@ -164,7 +164,6 @@
164 164
   #define HAS_LANG_SELECT_SCREEN            1
165 165
   #define HAS_BAK_VIEW_IN_FLASH             0
166 166
   #define HAS_LOGO_IN_FLASH                 0
167
-  #define HAS_TOUCH_XPT2046                 1
168 167
 
169 168
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
170 169
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
@@ -183,6 +182,8 @@
183 182
 
184 183
   #define LCD_RESET_PIN                     PF11
185 184
   #define LCD_BACKLIGHT_PIN                 PD13
185
+  #define TFT_RESET_PIN                     PF11
186
+  #define TFT_BACKLIGHT_PIN                 PD13
186 187
 
187 188
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
188 189
   #define FSMC_CS_PIN                       PD7
@@ -197,24 +198,10 @@
197 198
   #define LCD_PIXEL_OFFSET_X     48
198 199
   #define LCD_PIXEL_OFFSET_Y     48
199 200
 
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
-
205
-  #define USE_XPT2046       1
206
-  #define XPT2046_XY_SWAP   0
207
-  #define XPT2046_X_INV     1
208
-  #define XPT2046_Y_INV     0
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
214
-  #define XPT2046_X_MAX     1900
215
-  #define XPT2046_Y_MAX     1900
216
-  #define XPT2046_AVG          4
217
-  #define XPT2046_INV          0
201
+  #define XPT2046_X_CALIBRATION           -17181
202
+  #define XPT2046_Y_CALIBRATION            11434
203
+  #define XPT2046_X_OFFSET                   501
204
+  #define XPT2046_Y_OFFSET                    -9
218 205
 
219 206
 #elif ENABLED(TFT_480x320)
220 207
   #define TFT_RESET_PIN                     PF11

+ 6
- 19
Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h View File

@@ -198,7 +198,6 @@
198 198
   #define HAS_LANG_SELECT_SCREEN            0
199 199
   #define HAS_BAK_VIEW_IN_FLASH             0
200 200
   #define HAS_LOGO_IN_FLASH                 0
201
-  #define HAS_TOUCH_XPT2046                 1
202 201
 
203 202
   #define TOUCH_CS_PIN                      PB7   // SPI1_NSS
204 203
   #define TOUCH_SCK_PIN                     PA5   // SPI1_SCK
@@ -217,6 +216,8 @@
217 216
 
218 217
   #define LCD_RESET_PIN                     PF11
219 218
   #define LCD_BACKLIGHT_PIN                 PD13
219
+  #define TFT_RESET_PIN                     PF11
220
+  #define TFT_BACKLIGHT_PIN                 PD13
220 221
 
221 222
   #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
222 223
   #define FSMC_CS_PIN                       PD7
@@ -231,24 +232,10 @@
231 232
   #define LCD_PIXEL_OFFSET_X     48
232 233
   #define LCD_PIXEL_OFFSET_Y     48
233 234
 
234
-  #define XPT2046_X_CALIBRATION  -12316
235
-  #define XPT2046_Y_CALIBRATION   8981
236
-  #define XPT2046_X_OFFSET        340
237
-  #define XPT2046_Y_OFFSET        -20
238
-
239
-  #define USE_XPT2046       1
240
-  #define XPT2046_XY_SWAP   0
241
-  #define XPT2046_X_INV     1
242
-  #define XPT2046_Y_INV     0
243
-
244
-  #define XPT2046_HOR_RES   480
245
-  #define XPT2046_VER_RES   320
246
-  #define XPT2046_X_MIN     140
247
-  #define XPT2046_Y_MIN     200
248
-  #define XPT2046_X_MAX     1900
249
-  #define XPT2046_Y_MAX     1900
250
-  #define XPT2046_AVG       4
251
-  #define XPT2046_INV       0
235
+  #define XPT2046_X_CALIBRATION           -17181
236
+  #define XPT2046_Y_CALIBRATION            11434
237
+  #define XPT2046_X_OFFSET                   501
238
+  #define XPT2046_Y_OFFSET                    -9
252 239
 #endif
253 240
 
254 241
 // SPI1(PA7)=LCD & SPI3(PB5)=STUFF, are not available

+ 11
- 0
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h View File

@@ -177,6 +177,17 @@
177 177
 
178 178
   #define LCD_BACKLIGHT_PIN                 PD13
179 179
 
180
+  #define XPT2046_X_CALIBRATION            17880
181
+  #define XPT2046_Y_CALIBRATION           -12234
182
+  #define XPT2046_X_OFFSET                   -45
183
+  #define XPT2046_Y_OFFSET                   349
184
+
185
+  #define LCD_USE_DMA_FSMC                        // Use DMA transfers to send data to the TFT
186
+  #define FSMC_CS_PIN                       PD7
187
+  #define FSMC_RS_PIN                       PD11
188
+  #define FSMC_DMA_DEV                      DMA2
189
+  #define FSMC_DMA_CHANNEL               DMA_CH5
190
+
180 191
 #elif ENABLED(FSMC_GRAPHICAL_TFT)
181 192
 
182 193
   #define DOGLCD_MOSI                       -1    // prevent redefine Conditionals_post.h

+ 24
- 11
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h View File

@@ -261,17 +261,30 @@
261 261
   #define BTN_EN2                           PE11
262 262
   #define BTN_ENC                           PE13
263 263
 
264
-#elif ENABLED(TFT_LITTLE_VGL_UI)
265
-
266
-  #define FSMC_CS_PIN                       PD7   // NE4
267
-  #define FSMC_RS_PIN                       PD11  // A0
268
-
269
-  #define TOUCH_CS_PIN                      PA7   // SPI2_NSS
270
-  #define TOUCH_SCK_PIN                     PB13  // SPI2_SCK
271
-  #define TOUCH_MISO_PIN                    PB14  // SPI2_MISO
272
-  #define TOUCH_MOSI_PIN                    PB15  // SPI2_MOSI
273
-
274
-  #define LCD_BACKLIGHT_PIN                 PD13
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
279
+  #define TOUCH_BUTTONS_HW_SPI
280
+  #define TOUCH_BUTTONS_HW_SPI_DEVICE        1
281
+
282
+  #ifndef LCD_FULL_PIXEL_WIDTH
283
+    #define LCD_FULL_PIXEL_WIDTH            480
284
+  #endif
285
+  #ifndef LCD_FULL_PIXEL_HEIGHT
286
+    #define LCD_FULL_PIXEL_HEIGHT           320
287
+  #endif
275 288
 
276 289
 #endif
277 290
 

Loading…
Cancel
Save