#define WHITE 0xffff
#define BLACK 0x0000
#define BLUE 0x001f
#define GREEN 0x07e0
#define RED 0xf800
#define YELLOW 0xffe0
#define BROWN 0xbc40
#define LCD_DEVICE_NAME "lcd" /* keep your lcd device name */
static void lcd_device_test(void)
{
int y;
rt_device_t dev;
dev = rt_device_find(LCD_DEVICE_NAME);
if(dev == RT_NULL)
{
return;
}
if(rt_device_open(dev, RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
return;
}
rt_uint8_t *ptr;
struct rt_device_graphic_info info = { 0 };
if(rt_device_control(dev, RTGRAPHIC_CTRL_GET_INFO, &info) != RT_EOK)
{
return;
}
ptr = info.framebuffer;
for (int cnt = 0; cnt < 10; cnt++)
{
/* RED */
for (y = 0; y < (info.width * info.height * info.bits_per_pixel / 8); y += info.bits_per_pixel / 8)
{
ptr[y] = (rt_uint8_t)(RED >> 8) ;
ptr[y + 1] = (rt_uint8_t)(RED & 0xff);
}
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, NULL);
rt_thread_mdelay(100);
/* GREEN */
for (y = 0; y < (info.width * info.height * info.bits_per_pixel / 8); y += info.bits_per_pixel / 8)
{
ptr[y] = (rt_uint8_t)(GREEN >> 8) ;
ptr[y + 1] = (rt_uint8_t)(GREEN & 0xff);
}
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, NULL);
rt_thread_mdelay(100);
/* BLUE */
for (y = 0; y < (info.width * info.height * info.bits_per_pixel / 8); y += info.bits_per_pixel / 8)
{
ptr[y] = (rt_uint8_t)(BLUE >> 8) ;
ptr[y + 1] = (rt_uint8_t)(BLUE & 0xff);
}
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, NULL);
rt_thread_mdelay(100);
/* BLACK */
for (y = 0; y < (info.width * info.height * info.bits_per_pixel / 8); y += info.bits_per_pixel / 8)
{
ptr[y] = (rt_uint8_t)(BLACK >> 8) ;
ptr[y + 1] = (rt_uint8_t)(BLACK & 0xff);
}
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, NULL);
rt_thread_mdelay(100);
/* WHITE */
for (y = 0; y < (info.width * info.height * info.bits_per_pixel / 8); y += info.bits_per_pixel / 8)
{
ptr[y] = (rt_uint8_t)(WHITE >> 8) ;
ptr[y + 1] = (rt_uint8_t)(WHITE & 0xff);
}
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, NULL);
rt_thread_mdelay(100);
}
rt_device_close(dev);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
MSH_CMD_EXPORT(lcd_device_test, lcd device test);
#endif /* RT_USING_FINSH */
RT-Thread--RGB565LCD测试程序
于 2021-02-22 09:44:31 首次发布