Ubiquitous/RT_Thread/: add lcd test example update main.c function when it starts.

This commit is contained in:
chunyexixiaoyu 2021-10-14 11:20:06 +08:00
parent a184611226
commit 43f19c4b55
3 changed files with 117 additions and 10 deletions

View File

@ -0,0 +1,100 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <stdint.h>
#include <stdlib.h>
#include "drv_lcd.h"
static void drawarea(rt_device_t dev, struct rt_device_graphic_info *info,
int x, int y, int w, int h, uint16_t c)
{
struct rt_device_rect_info rect;
uint16_t *fb;
int i, j;
fb = (uint16_t *)info->framebuffer;
fb += (info->width * y);
fb += x;
for (j = 0; j < h; j++)
{
for (i = 0; i < w; i++)
{
fb[i] = c;
}
fb += info->width;
}
rect.x = x;
rect.y = y;
rect.width = w;
rect.height = h;
rt_device_control(dev, RTGRAPHIC_CTRL_RECT_UPDATE, &rect);
}
#define RGB_BUF_SIZE (320*240*2)
static int showcolor(int argc, char **argv)
{
unsigned char r = 0, g = 0, b = 0;
char *devname = "lcd";
rt_device_t dev;
struct rt_device_graphic_info info;
int result;
int x = 0, y = 0;
int i;
uint16_t c;
for (i = 1; i < argc; i++)
{
switch (i)
{
case 1:
r = atoi(argv[i]);
break;
case 2:
g = atoi(argv[i]);
break;
case 3:
b = atoi(argv[i]);
break;
}
}
dev = rt_device_find(devname);
if (!dev)
{
rt_kprintf("lcd: %s not found\n", devname);
return -1;
}
if (rt_device_open(dev, 0) != 0)
{
rt_kprintf("lcd open fail\n");
return -1;
}
result = rt_device_control(dev, RTGRAPHIC_CTRL_GET_INFO, &info);
if (result != RT_EOK)
{
rt_kprintf("get device information failed\n");
return result;
}
c = (uint16_t)(((r >> 3) << 11) | ((g >> 2) << 6) | ((b >> 3)));
drawarea(dev, &info, x, y, 24, 24, c);
lcd_set_color(BLACK, BLUE);
lcd_show_string(0, 40, 16, "hello world");
lcd_show_string(0, 60, 24, "hello world");
lcd_show_string(0, 90, 32, "hello world");
lcd_draw_line(0, 200, 319, 200);
lcd_draw_circle(270, 120, 30);
lcd_set_color(BLACK, RED);
lcd_show_string(0, 130, 32, "after set color");
lcd_draw_line(0, 0, 319, 239);
lcd_draw_rectangle(50, 10, 170, 145);
lcd_draw_circle(160, 120, 50);
rt_device_close(dev);
return 0;
}
MSH_CMD_EXPORT(showcolor, showcolor R G B-- R / G / B : 0 ~255);

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2021-10-11 22:04:25
* @LastEditTime: 2021-10-14 11:12:52
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiuos\Ubiquitous\RT_Thread\bsp\k210\applications\main.c
*/
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
@ -21,14 +29,13 @@ int main(void)
rt_thread_mdelay(100);
char info1[25] ={0};
char info2[25] ={0};
sprintf(info1,"xuos-intelligence k210 build ");
sprintf(info2,"%s %s",__DATE__,__TIME__);
sprintf(info1,"xuos-intelligence k210 ");
sprintf(info2,"build %s %s",__DATE__,__TIME__);
printf("%s %s \n",info1,info2);
#ifdef BSP_USING_LCD
#include<drv_lcd.h>
lcd_clear(PINK);
lcd_draw_string(70,100,info1,BLACK);
lcd_draw_string(70,120,info2,BLACK);
lcd_show_string(0,60,24,info1);
lcd_show_string(0,90,24,info2);
#endif
while(1)
{

View File

@ -21,10 +21,10 @@
static int g_fd = 0;
static _ioctl_shoot_para shoot_para_t = {0};
extern void lcd_show_image(int x, int y, int wide, int height,const rt_uint8_t *buf);
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr);
void ov2640_test(int argc, char **argv)
{
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr);
g_fd = open("/dev/ov2640",O_RDONLY);
if(g_fd < 0)
@ -71,7 +71,7 @@ void ov2640_test(int argc, char **argv)
close(g_fd);
return;
}
lcd_draw_picture(0, 0, 320, 240, rgbbuffer);
lcd_show_image(0, 0, 320, 240, rgbbuffer);
rt_thread_mdelay(100);
printf("the lcd has shown the image \n");
rt_free(rgbbuffer);
@ -82,7 +82,6 @@ MSH_CMD_EXPORT(ov2640_test,lcd show camera shot image);
void lcd_show_ov2640_thread(uint32_t* rgbbuffer)
{
extern void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr);
rt_err_t ret = 0;
while(1)
{
@ -94,8 +93,9 @@ void lcd_show_ov2640_thread(uint32_t* rgbbuffer)
rt_free(rgbbuffer);
return;
}
//lcd_show_image(0, 0, 320, 240, rgbbuffer);
lcd_draw_picture(0, 0, 320, 240, rgbbuffer);
rt_thread_mdelay(2);
rt_thread_mdelay(1);
}
}