Skip to content

Commit

Permalink
fix:[stm32][lcd]Error in control call of lcd test function (#10040)
Browse files Browse the repository at this point in the history
* Optimize the lcd_test function to call it in thread to prevent the CLI environment from being unavailable after execution.
  • Loading branch information
wdfk-prog authored Feb 26, 2025
1 parent 272c9e2 commit 5068329
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions bsp/stm32/libraries/HAL_Drivers/drivers/drv_lcd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -363,11 +363,9 @@ INIT_DEVICE_EXPORT(drv_lcd_hw_init);
#ifndef ART_PI_TouchGFX_LIB
#ifdef DRV_DEBUG
#ifdef FINSH_USING_MSH
int lcd_test()
static void lcd_thread(void *arg)
{
struct drv_lcd_device *lcd;
lcd = (struct drv_lcd_device *)rt_device_find("lcd");

struct drv_lcd_device *lcd = (struct drv_lcd_device *)arg;
while (1)
{
if (lcd->lcd_info.pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
Expand All @@ -378,15 +376,15 @@ int lcd_test()
lcd->lcd_info.framebuffer[2 * i] = 0x00;
lcd->lcd_info.framebuffer[2 * i + 1] = 0xF8;
}
lcd->parent.control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_thread_mdelay(1000);
/* green */
for (int i = 0; i < LCD_BUF_SIZE / 2; i++)
{
lcd->lcd_info.framebuffer[2 * i] = 0xE0;
lcd->lcd_info.framebuffer[2 * i + 1] = 0x07;
}
lcd->parent.control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_thread_mdelay(1000);
/* blue */
for (int i = 0; i < LCD_BUF_SIZE / 2; i++)
Expand All @@ -404,7 +402,7 @@ int lcd_test()
lcd->lcd_info.framebuffer[3 * i + 1] = 0x00;
lcd->lcd_info.framebuffer[3 * i + 2] = 0xff;
}
lcd->parent.control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_thread_mdelay(1000);
/* green */
for (int i = 0; i < LCD_BUF_SIZE / 3; i++)
Expand All @@ -413,7 +411,7 @@ int lcd_test()
lcd->lcd_info.framebuffer[3 * i + 1] = 0xff;
lcd->lcd_info.framebuffer[3 * i + 2] = 0x00;
}
lcd->parent.control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_thread_mdelay(1000);
/* blue */
for (int i = 0; i < LCD_BUF_SIZE / 3; i++)
Expand All @@ -424,11 +422,34 @@ int lcd_test()
}
}

lcd->parent.control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_device_control(&lcd->parent, RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
rt_thread_mdelay(1000);
}
}
MSH_CMD_EXPORT(lcd_test, lcd_test);
int lcd_test(void)
{
struct drv_lcd_device *lcd;
lcd = (struct drv_lcd_device *)rt_device_find("lcd");
if(lcd == RT_NULL)
{
LOG_E("Failed to find LCD device!\n");
return -RT_ERROR;
}

const char *thread_name = "lcd_test";
rt_thread_t thread = rt_thread_create(thread_name, lcd_thread, lcd, 256, RT_THREAD_PRIORITY_MAX - 1, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("%s created failed.", thread_name);
return -RT_ERROR;
}
return RT_EOK;
}
MSH_CMD_EXPORT(lcd_test, Create thread test lcd);
#endif /* FINSH_USING_MSH */
#endif /* DRV_DEBUG */
#endif /* BSP_USING_LCD */
Expand Down

0 comments on commit 5068329

Please sign in to comment.