取消DMA传输中断中,LVGL刷新完成的置位。直接改为LVGL线程中等待刷新完成。

This commit is contained in:
不吃油炸鸡
2026-03-25 15:59:11 +08:00
parent baf4fee442
commit 6a511f63c6
2 changed files with 7 additions and 42 deletions

View File

@@ -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);
}
/******************************************************************************

View File

@@ -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*/