Просмотр исходного кода

⚡️ SPI+DMA+interrupt method (STM32 / MKS UI) (#23464)

Sola 2 лет назад
Родитель
Сommit
c79174e862
Аккаунт пользователя с таким Email не найден

+ 24
- 0
Marlin/src/HAL/STM32/tft/tft_spi.cpp Просмотреть файл

@@ -242,5 +242,29 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
242 242
   Abort();
243 243
 }
244 244
 
245
+#if ENABLED(USE_SPI_DMA_TC)
246
+
247
+  void TFT_SPI::TransmitDMA_IT(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
248
+
249
+    DMAtx.Init.MemInc = MemoryIncrease;
250
+    HAL_DMA_Init(&DMAtx);
251
+
252
+    if (TFT_MISO_PIN == TFT_MOSI_PIN)
253
+      SPI_1LINE_TX(&SPIx);
254
+
255
+    DataTransferBegin();
256
+
257
+    HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 5, 0);
258
+    HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
259
+    HAL_DMA_Start_IT(&DMAtx, (uint32_t)Data, (uint32_t)&(SPIx.Instance->DR), Count);
260
+    __HAL_SPI_ENABLE(&SPIx);
261
+
262
+    SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN);   // Enable Tx DMA Request
263
+  }
264
+
265
+  extern "C" void DMA2_Stream3_IRQHandler(void) { HAL_DMA_IRQHandler(&TFT_SPI::DMAtx); }
266
+
267
+#endif
268
+
245 269
 #endif // HAS_SPI_TFT
246 270
 #endif // HAL_STM32

+ 14
- 4
Marlin/src/HAL/STM32/tft/tft_spi.h Просмотреть файл

@@ -36,20 +36,25 @@
36 36
   #define LCD_READ_ID4 0xD3   // Read display identification information (0xD3 on ILI9341)
37 37
 #endif
38 38
 
39
-#define DATASIZE_8BIT    SPI_DATASIZE_8BIT
40
-#define DATASIZE_16BIT   SPI_DATASIZE_16BIT
41
-#define TFT_IO_DRIVER TFT_SPI
39
+#define DATASIZE_8BIT  SPI_DATASIZE_8BIT
40
+#define DATASIZE_16BIT SPI_DATASIZE_16BIT
41
+#define TFT_IO_DRIVER  TFT_SPI
42 42
 
43 43
 class TFT_SPI {
44 44
 private:
45 45
   static SPI_HandleTypeDef SPIx;
46
-  static DMA_HandleTypeDef DMAtx;
46
+
47 47
 
48 48
   static uint32_t ReadID(uint16_t Reg);
49 49
   static void Transmit(uint16_t Data);
50 50
   static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
51
+  #if ENABLED(USE_SPI_DMA_TC)
52
+    static void TransmitDMA_IT(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
53
+  #endif
51 54
 
52 55
 public:
56
+  static DMA_HandleTypeDef DMAtx;
57
+
53 58
   static void Init();
54 59
   static uint32_t GetID();
55 60
   static bool isBusy();
@@ -63,6 +68,11 @@ public:
63 68
   static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }
64 69
 
65 70
   static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
71
+
72
+  #if ENABLED(USE_SPI_DMA_TC)
73
+    static void WriteSequenceIT(uint16_t *Data, uint16_t Count) { TransmitDMA_IT(DMA_MINC_ENABLE, Data, Count); }
74
+  #endif
75
+
66 76
   static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
67 77
   static void WriteMultiple(uint16_t Color, uint32_t Count) {
68 78
     static uint16_t Data; Data = Color;

+ 3
- 2
Marlin/src/lcd/extui/mks_ui/draw_ui.cpp Просмотреть файл

@@ -1331,7 +1331,6 @@ void lv_screen_menu_item_onoff_update(lv_obj_t *btn, const bool curValue) {
1331 1331
   lv_label_set_text((lv_obj_t*)btn->child_ll.head, curValue ? machine_menu.enable : machine_menu.disable);
1332 1332
 }
1333 1333
 
1334
-
1335 1334
 #if ENABLED(SDSUPPORT)
1336 1335
 
1337 1336
   void sd_detection() {
@@ -1360,7 +1359,9 @@ void print_time_count() {
1360 1359
 }
1361 1360
 
1362 1361
 void LV_TASK_HANDLER() {
1363
-  lv_task_handler();
1362
+
1363
+  if (TERN1(USE_SPI_DMA_TC, !get_lcd_dma_lock()))
1364
+    lv_task_handler();
1364 1365
 
1365 1366
   #if BOTH(MKS_TEST, SDSUPPORT)
1366 1367
     if (mks_test_flag == 0x1E) mks_hardware_test();

+ 49
- 3
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp Просмотреть файл

@@ -133,6 +133,27 @@ void tft_lvgl_init() {
133 133
 
134 134
   watchdog_refresh();     // LVGL init takes time
135 135
 
136
+  #if ENABLED(USB_FLASH_DRIVE_SUPPORT)
137
+    uint16_t usb_flash_loop = 1000;
138
+    #if ENABLED(MULTI_VOLUME) && !HAS_SD_HOST_DRIVE
139
+      SET_INPUT_PULLUP(SD_DETECT_PIN);
140
+      if (READ(SD_DETECT_PIN) == LOW) card.changeMedia(&card.media_driver_sdcard);
141
+      else card.changeMedia(&card.media_driver_usbFlash);
142
+    #endif
143
+    do {
144
+      card.media_driver_usbFlash.idle();
145
+      watchdog_refresh();
146
+      delay(2);
147
+    } while (!card.media_driver_usbFlash.isInserted() && usb_flash_loop--);
148
+    card.mount();
149
+  #elif HAS_LOGO_IN_FLASH
150
+    delay(1000);
151
+    watchdog_refresh();
152
+    delay(1000);
153
+  #endif
154
+
155
+  watchdog_refresh();     // LVGL init takes time
156
+
136 157
   #if ENABLED(SDSUPPORT)
137 158
     UpdateAssets();
138 159
     watchdog_refresh();   // LVGL init takes time
@@ -231,19 +252,44 @@ void tft_lvgl_init() {
231 252
   #endif
232 253
 }
233 254
 
255
+static lv_disp_drv_t* disp_drv_p;
256
+
257
+#if ENABLED(USE_SPI_DMA_TC)
258
+  bool lcd_dma_trans_lock = false;
259
+#endif
260
+
261
+void dmc_tc_handler(struct __DMA_HandleTypeDef * hdma) {
262
+  #if ENABLED(USE_SPI_DMA_TC)
263
+    lv_disp_flush_ready(disp_drv_p);
264
+    lcd_dma_trans_lock = false;
265
+    TFT_SPI::Abort();
266
+  #endif
267
+}
268
+
234 269
 void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
235 270
   uint16_t width = area->x2 - area->x1 + 1,
236 271
           height = area->y2 - area->y1 + 1;
237 272
 
238
-  SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height);
273
+  TERN_(USE_SPI_DMA_TC, disp_drv_p = disp);
239 274
 
240
-  SPI_TFT.tftio.WriteSequence((uint16_t*)color_p, width * height);
275
+  SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height);
241 276
 
242
-  lv_disp_flush_ready(disp); // Indicate you are ready with the flushing
277
+  #if ENABLED(USE_SPI_DMA_TC)
278
+    lcd_dma_trans_lock = true;
279
+    SPI_TFT.tftio.WriteSequenceIT((uint16_t*)color_p, width * height);
280
+    TFT_SPI::DMAtx.XferCpltCallback = dmc_tc_handler;
281
+  #else
282
+    SPI_TFT.tftio.WriteSequence((uint16_t*)color_p, width * height);
283
+    lv_disp_flush_ready(disp_drv_p); // Indicate you are ready with the flushing
284
+  #endif
243 285
 
244 286
   W25QXX.init(SPI_QUARTER_SPEED);
245 287
 }
246 288
 
289
+#if ENABLED(USE_SPI_DMA_TC)
290
+  bool get_lcd_dma_lock() { return lcd_dma_trans_lock; }
291
+#endif
292
+
247 293
 void lv_fill_rect(lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2, lv_color_t bk_color) {
248 294
   uint16_t width, height;
249 295
   width = x2 - x1 + 1;

+ 2
- 0
Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.h Просмотреть файл

@@ -64,6 +64,8 @@ lv_fs_res_t sd_tell_cb(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
64 64
 
65 65
 void lv_fill_rect(lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2, lv_color_t bk_color);
66 66
 
67
+bool get_lcd_dma_lock();
68
+
67 69
 #ifdef __cplusplus
68 70
   } /* C-declarations for C++ */
69 71
 #endif

+ 5
- 0
Marlin/src/lcd/tft_io/tft_io.h Просмотреть файл

@@ -121,6 +121,11 @@ public:
121 121
   inline static void WriteReg(uint16_t Reg) { io.WriteReg(Reg); };
122 122
 
123 123
   inline static void WriteSequence(uint16_t *Data, uint16_t Count) { io.WriteSequence(Data, Count); };
124
+
125
+  #if ENABLED(USE_SPI_DMA_TC)
126
+    inline static void WriteSequenceIT(uint16_t *Data, uint16_t Count) { io.WriteSequenceIT(Data, Count); };
127
+  #endif
128
+
124 129
   // static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
125 130
   inline static void WriteMultiple(uint16_t Color, uint32_t Count) { io.WriteMultiple(Color, Count); };
126 131
 

+ 4
- 0
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h Просмотреть файл

@@ -44,6 +44,10 @@
44 44
 
45 45
 //#define LED_PIN                           PB2
46 46
 
47
+#if HAS_TFT_LVGL_UI
48
+  #define BOARD_INIT OUT_WRITE(PB0, LOW)
49
+#endif
50
+
47 51
 #include "pins_MKS_ROBIN_NANO_common.h"
48 52
 
49 53
 #if HAS_TFT_LVGL_UI && FAN1_PIN != PB0 && HEATER_1_PIN != PB0

+ 9
- 3
Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3_common.h Просмотреть файл

@@ -366,9 +366,15 @@
366 366
 
367 367
 #endif // HAS_WIRED_LCD
368 368
 
369
+#if HAS_TFT_LVGL_UI
370
+  #define USE_SPI_DMA_TC
371
+#endif
372
+
369 373
 #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI, HAS_WIRED_LCD)
370 374
   #define BEEPER_PIN                 EXP1_10_PIN
371
-  #define BTN_EN1                    EXP2_08_PIN
372
-  #define BTN_EN2                    EXP2_06_PIN
373
-  #define BTN_ENC                    EXP1_09_PIN
375
+  #if DISABLED(USE_SPI_DMA_TC)
376
+    #define BTN_EN1                  EXP2_08_PIN
377
+    #define BTN_EN2                  EXP2_06_PIN
378
+    #define BTN_ENC                  EXP1_09_PIN
379
+  #endif
374 380
 #endif

Загрузка…
Отмена
Сохранить