From 6a511f63c6d4d5e3839a3918b3cbe15d1f7bad6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Wed, 25 Mar 2026 15:59:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88DMA=E4=BC=A0=E8=BE=93?= =?UTF-8?q?=E4=B8=AD=E6=96=AD=E4=B8=AD=EF=BC=8CLVGL=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=9A=84=E7=BD=AE=E4=BD=8D=E3=80=82=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E6=94=B9=E4=B8=BALVGL=E7=BA=BF=E7=A8=8B=E4=B8=AD?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=88=B7=E6=96=B0=E5=AE=8C=E6=88=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- software/Power_Pico/BSP/LCD/lcd.c | 32 +++---------------- .../Middlewares/LVGL/porting/lv_port_disp.c | 17 ++-------- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/software/Power_Pico/BSP/LCD/lcd.c b/software/Power_Pico/BSP/LCD/lcd.c index 50fb138..ce30b19 100644 --- a/software/Power_Pico/BSP/LCD/lcd.c +++ b/software/Power_Pico/BSP/LCD/lcd.c @@ -50,35 +50,11 @@ void LCD_Color_Render_Async(u16 xsta, u16 ysta, u16 xend, u16 yend, u16 *color_p LCD_Address_Set(xsta, ysta, xend, yend); // 计算像素总数 uint32_t pixel_count = (xend - xsta + 1) * (yend - ysta + 1); - // 发送给 DMA 前,利用 CPU 极速翻转内存数组的高低字节! + // 发送前,利用 CPU 翻转内存数组的高低字节 swap_rgb565_buffer_fast(color_p, pixel_count); - // 启动 DMA 传输 - // 注意:因为现在是纯 8-bit 发送,1 个像素(16位)要发 2 个字节,所以 count = pixel_count * 2 - HAL_SPI_Transmit_DMA(&hspi2, (uint8_t*)color_p, pixel_count * 2); -} - -static void *lcd_ready_cb = NULL; - -// 设置通知的回调函数 -void LCD_Set_Flush_Complete_Callback(void *cb) -{ - // 保存回调指针 - lcd_ready_cb = cb; -} - -// DMA 传输完成中断回调 -void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) -{ - if (hspi->Instance == SPI2) - { - // 确保最后一位数据离开 STM32 的移位寄存器 - while (hspi->Instance->SR & SPI_FLAG_BSY); - // 通知 LVGL 渲染结束,执行回调函数 - if (lcd_ready_cb) { - LCD_CallbackFunc_t func = (LCD_CallbackFunc_t)lcd_ready_cb; - func(); - } - } + // 注意:因为是 8-bit 发送,1 个像素(16位)要发 2 个字节 + HAL_SPI_Transmit_DMA(&hspi2, (uint8_t*)color_p, pixel_count * 2); + while(__HAL_DMA_GET_COUNTER(&hdma_spi2_tx)!=0); } /****************************************************************************** diff --git a/software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c b/software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c index 8101e41..8c72928 100644 --- a/software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c +++ b/software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c @@ -107,13 +107,6 @@ void lv_port_disp_init(void) * STATIC FUNCTIONS **********************/ -void lcd_flush_ready_callback(void) -{ - if (g_current_disp_drv != NULL) { - lv_display_flush_ready(g_current_disp_drv); - } -} - /*Initialize your display and the required peripherals.*/ static void disp_init(void) { @@ -121,7 +114,6 @@ static void disp_init(void) LCD_Init(); LCD_Fill(0,0, LCD_W, LCD_H, BLACK); LCD_Close_Light(); - LCD_Set_Flush_Complete_Callback(lcd_flush_ready_callback); } volatile bool disp_flush_enabled = true; @@ -148,18 +140,15 @@ static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t { static lv_display_rotation_t last_rotation = LV_DISPLAY_ROTATION_0; lv_display_rotation_t current_rotation = lv_display_get_rotation(disp_drv); - lv_area_t rotated_area; + if (current_rotation != last_rotation) { LCD_SetRotation(current_rotation * 90); // 仅在旋转状态改变时调用 last_rotation = current_rotation; // 更新上次状态 } - if(disp_flush_enabled) { - LCD_Color_Render_Async(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map); - } - + LCD_Color_Render_Async(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map); /*IMPORTANT!!! *Inform the graphics library that you are ready with the flushing*/ - // lv_display_flush_ready(disp_drv); + lv_display_flush_ready(disp_drv); } #else /*Enable this file at the top*/