From 34d4a1bf2faf66956243afd773f6ae439873d3f8 Mon Sep 17 00:00:00 2001 From: "qiuyiuestc@gmail.com" Date: Wed, 8 Jun 2011 00:50:04 +0000 Subject: [PATCH] change to graphic device git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1462 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/mini2440/application.c | 39 ++++---- bsp/mini2440/calibration.c | 2 +- bsp/mini2440/lcd.h | 5 - bsp/mini2440/lcd_a70.c | 184 +++++----------------------------- bsp/mini2440/lcd_n35.c | 188 ++++++----------------------------- bsp/mini2440/lcd_t35.c | 195 +++++-------------------------------- bsp/mini2440/touch.c | 14 ++- 7 files changed, 110 insertions(+), 517 deletions(-) diff --git a/bsp/mini2440/application.c b/bsp/mini2440/application.c index d12a60dcc1..79645de575 100644 --- a/bsp/mini2440/application.c +++ b/bsp/mini2440/application.c @@ -114,8 +114,17 @@ void rt_init_thread_entry(void* parameter) #endif #endif +#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) + /* NFSv3 Initialization */ + nfs_init(); + + if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0) + rt_kprintf("NFSv3 File System initialized!\n"); + else + rt_kprintf("NFSv3 File System initialzation failed!\n"); +#endif + #if defined(RT_USING_DFS_UFFS) - { /* init the uffs filesystem */ dfs_uffs_init(); @@ -124,13 +133,14 @@ void rt_init_thread_entry(void* parameter) rt_kprintf("UFFS File System initialized!\n"); else rt_kprintf("UFFS File System initialzation failed!\n"); - } #endif } #endif #ifdef RT_USING_RTGUI { + rt_device_t *lcd; + /* init lcd */ rt_hw_lcd_init(); @@ -143,6 +153,12 @@ void rt_init_thread_entry(void* parameter) /* re-init device driver */ rt_device_init_all(); + /* find lcd device */ + lcd = rt_device_find("lcd"); + + /* set lcd device as rtgui graphic driver */ + rtgui_graphic_set_device(lcd); + /* startup rtgui */ rtgui_startup(); } @@ -242,23 +258,4 @@ int rt_application_init() return 0; } -/* NFSv3 Initialization */ -#if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) -#include -void nfs_start(void) -{ - nfs_init(); - - if (dfs_mount(RT_NULL, "/nfs", "nfs", 0, RT_NFS_HOST_EXPORT) == 0) - { - rt_kprintf("NFSv3 File System initialized!\n"); - } - else - rt_kprintf("NFSv3 File System initialzation failed!\n"); -} - -#include "finsh.h" -FINSH_FUNCTION_EXPORT(nfs_start, start net filesystem); -#endif - /*@}*/ diff --git a/bsp/mini2440/calibration.c b/bsp/mini2440/calibration.c index 5e691ab23b..44f3e8c84f 100644 --- a/bsp/mini2440/calibration.c +++ b/bsp/mini2440/calibration.c @@ -176,7 +176,7 @@ void calibration_entry(void* parameter) rtgui_thread_register(rt_thread_self(), mq); - rtgui_graphic_driver_get_default_rect(&rect); + rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect); /* set screen rect */ calibration_ptr->width = rect.x2; diff --git a/bsp/mini2440/lcd.h b/bsp/mini2440/lcd.h index 053c11b438..aef7d2f625 100644 --- a/bsp/mini2440/lcd.h +++ b/bsp/mini2440/lcd.h @@ -18,9 +18,4 @@ void rt_hw_lcd_init(); -#define RT_DEVICE_CTRL_LCD_GET_WIDTH 0 -#define RT_DEVICE_CTRL_LCD_GET_HEIGHT 1 -#define RT_DEVICE_CTRL_LCD_GET_BPP 2 -#define RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER 3 - #endif diff --git a/bsp/mini2440/lcd_a70.c b/bsp/mini2440/lcd_a70.c index e31591727d..1337919ce0 100644 --- a/bsp/mini2440/lcd_a70.c +++ b/bsp/mini2440/lcd_a70.c @@ -112,22 +112,8 @@ #define S3C2410_LCDINT_FRSYNC (1<<1) static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; -static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; - -struct rtgui_lcd_device -{ - struct rt_device parent; - - /* byte per pixel */ - rt_uint16_t byte_per_pixel; - - /* screen width and height */ - rt_uint16_t width; - rt_uint16_t height; - - void* hw_framebuffer; -}; -static struct rtgui_lcd_device *lcd = RT_NULL; +//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; +static struct rt_device_graphic_info _lcd_info; static void lcd_power_enable(int invpwren, int pwren) { @@ -179,119 +165,6 @@ static void LcdBkLtSet(rt_uint32_t HiRatio) TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } -#ifdef RT_USING_RTGUI - -#include -#include - -static void rt_hw_lcd_update(rtgui_rect_t *rect) -{ - rt_uint32_t i, j; - - for (i = rect->y1; i < rect->y2; i ++) - { - for(j = rect->x1; j < rect->x2; j++) - _rt_hw_framebuffer[i][j] = _rt_framebuffer[i][j]; - } -} - -static rt_uint8_t * rt_hw_lcd_get_framebuffer(void) -{ - return (rt_uint8_t *)_rt_framebuffer; -} - -static void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - _rt_framebuffer[(y)][(x)] = rtgui_color_to_565p(*c); - } -} - -static void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - *c = rtgui_color_from_565p(_rt_framebuffer[(y)][(x)]); - } -} - -static void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_uint32_t idx; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idx = x1; idx < x2; idx ++) - { - _rt_framebuffer[y][idx] = color; - } -} - -static void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) -{ - rt_uint32_t idy; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idy = y1; idy < y2; idy ++) - { - _rt_framebuffer[idy][x] = color; - } -} - -static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_memcpy((void*)&_rt_framebuffer[y][x1], pixels, (x2 - x1) * 2); -} - -struct rtgui_graphic_driver _rtgui_lcd_driver = -{ - "lcd", - 2, - RT_HW_LCD_WIDTH, - RT_HW_LCD_HEIGHT, - rt_hw_lcd_update, - rt_hw_lcd_get_framebuffer, - rt_hw_lcd_set_pixel, - rt_hw_lcd_get_pixel, - rt_hw_lcd_draw_hline, - rt_hw_lcd_draw_vline, - rt_hw_lcd_draw_raw_hline -}; - -#include "finsh.h" -void hline(rt_uint32_t c, int x1, int x2, int y) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_hline(&color, x1, x2, y); -} -FINSH_FUNCTION_EXPORT(hline, draw a hline); - -void vline(rt_uint32_t c, int x, int y1, int y2) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_vline(&color, x, y1, y2); -} -FINSH_FUNCTION_EXPORT(vline, draw a vline); - -void clear() -{ - int y; - - for (y = 0; y < LCD_HEIGHT; y ++) - { - rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, LCD_WIDTH, y); - } -} -FINSH_FUNCTION_EXPORT(clear, clear screen); - -#endif - /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) { @@ -305,7 +178,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev) GPDCON = 0xaaaaaaaa; #define M5D(n) ((n)&0x1fffff) -#define LCD_ADDR ((rt_uint32_t)_rt_hw_framebuffer) +#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); @@ -334,21 +207,17 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args) { switch (cmd) { - case RT_DEVICE_CTRL_LCD_GET_WIDTH: - *((rt_uint16_t*)args) = lcd->width; + case RTGRAPHIC_CTRL_RECT_UPDATE: break; - - case RT_DEVICE_CTRL_LCD_GET_HEIGHT: - *((rt_uint16_t*)args) = lcd->height; + case RTGRAPHIC_CTRL_POWERON: break; - - case RT_DEVICE_CTRL_LCD_GET_BPP: - *((rt_uint16_t*)args) = lcd->byte_per_pixel; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: break; - - case RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER: - *((rt_uint16_t*)args) = lcd->hw_framebuffer; - break; } return RT_EOK; @@ -356,25 +225,24 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args) void rt_hw_lcd_init(void) { - lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device)); + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); if (lcd == RT_NULL) return; /* no memory yet */ + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; + /* init device structure */ - lcd->parent.type = RT_Device_Class_Unknown; - lcd->parent.init = rt_lcd_init; - lcd->parent.control = rt_lcd_control; - lcd->parent.user_data = RT_NULL; - lcd->byte_per_pixel = 2; - lcd->width = LCD_WIDTH; - lcd->height = LCD_HEIGHT; - lcd->hw_framebuffer = (void*)_rt_hw_framebuffer; + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* register touch device to RT-Thread */ - rt_device_register(&(lcd->parent), "lcd", RT_DEVICE_FLAG_RDWR); - -#ifdef RT_USING_RTGUI - /* add lcd driver into graphic driver */ - rtgui_graphic_driver_add(&_rtgui_lcd_driver); -#endif + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/lcd_n35.c b/bsp/mini2440/lcd_n35.c index 27976935b0..768ab932e1 100644 --- a/bsp/mini2440/lcd_n35.c +++ b/bsp/mini2440/lcd_n35.c @@ -13,10 +13,10 @@ */ #include - #include #include "lcd.h" + /* LCD driver for N3'5 */ #define LCD_WIDTH 240 #define LCD_HEIGHT 320 @@ -113,22 +113,8 @@ #define S3C2410_LCDINT_FRSYNC (1<<1) static volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; -static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; - -struct rtgui_lcd_device -{ - struct rt_device parent; - - /* byte per pixel */ - rt_uint16_t byte_per_pixel; - - /* screen width and height */ - rt_uint16_t width; - rt_uint16_t height; - - void* hw_framebuffer; -}; -static struct rtgui_lcd_device *lcd = RT_NULL; +//static volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; +static struct rt_device_graphic_info _lcd_info; static void lcd_power_enable(int invpwren, int pwren) { @@ -180,119 +166,6 @@ static void LcdBkLtSet(rt_uint32_t HiRatio) TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } -#ifdef RT_USING_RTGUI - -#include -#include - -static void rt_hw_lcd_update(rtgui_rect_t *rect) -{ - rt_uint32_t i, j; - - for (i = rect->y1; i < rect->y2; i ++) - { - for(j = rect->x1; j < rect->x2; j++) - _rt_hw_framebuffer[i][j] = _rt_framebuffer[i][j]; - } -} - -static rt_uint8_t * rt_hw_lcd_get_framebuffer(void) -{ - return (rt_uint8_t *)_rt_framebuffer; -} - -static void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - _rt_framebuffer[(y)][(x)] = rtgui_color_to_565p(*c); - } -} - -static void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - *c = rtgui_color_from_565p(_rt_framebuffer[(y)][(x)]); - } -} - -static void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_uint32_t idx; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idx = x1; idx < x2; idx ++) - { - _rt_framebuffer[y][idx] = color; - } -} - -static void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) -{ - rt_uint32_t idy; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idy = y1; idy < y2; idy ++) - { - _rt_framebuffer[idy][x] = color; - } -} - -static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_memcpy((void*)&_rt_framebuffer[y][x1], pixels, (x2 - x1) * 2); -} - -struct rtgui_graphic_driver _rtgui_lcd_driver = -{ - "lcd", - 2, - RT_HW_LCD_WIDTH, - RT_HW_LCD_HEIGHT, - rt_hw_lcd_update, - rt_hw_lcd_get_framebuffer, - rt_hw_lcd_set_pixel, - rt_hw_lcd_get_pixel, - rt_hw_lcd_draw_hline, - rt_hw_lcd_draw_vline, - rt_hw_lcd_draw_raw_hline -}; - -#include "finsh.h" -void hline(rt_uint32_t c, int x1, int x2, int y) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_hline(&color, x1, x2, y); -} -FINSH_FUNCTION_EXPORT(hline, draw a hline); - -void vline(rt_uint32_t c, int x, int y1, int y2) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_vline(&color, x, y1, y2); -} -FINSH_FUNCTION_EXPORT(vline, draw a vline); - -void clear() -{ - int y; - - for (y = 0; y < LCD_HEIGHT; y ++) - { - rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, LCD_WIDTH, y); - } -} -FINSH_FUNCTION_EXPORT(clear, clear screen); - -#endif - /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) { @@ -306,7 +179,7 @@ static rt_err_t rt_lcd_init (rt_device_t dev) GPDCON = 0xaaaaaaaa; #define M5D(n) ((n)&0x1fffff) -#define LCD_ADDR ((rt_uint32_t)_rt_hw_framebuffer) +#define LCD_ADDR ((rt_uint32_t)_rt_framebuffer) LCDCON1 = (LCD_PIXCLOCK << 8) | (3 << 5) | (12 << 1); LCDCON2 = (LCD_UPPER_MARGIN << 24) | ((LCD_HEIGHT - 1) << 14) | (LCD_LOWER_MARGIN << 6) | (LCD_VSYNC_LEN << 0); LCDCON3 = (LCD_RIGHT_MARGIN << 19) | ((LCD_WIDTH - 1) << 8) | (LCD_LEFT_MARGIN << 0); @@ -335,47 +208,42 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args) { switch (cmd) { - case RT_DEVICE_CTRL_LCD_GET_WIDTH: - *((rt_uint16_t*)args) = lcd->width; + case RTGRAPHIC_CTRL_RECT_UPDATE: break; - - case RT_DEVICE_CTRL_LCD_GET_HEIGHT: - *((rt_uint16_t*)args) = lcd->height; + case RTGRAPHIC_CTRL_POWERON: break; - - case RT_DEVICE_CTRL_LCD_GET_BPP: - *((rt_uint16_t*)args) = lcd->byte_per_pixel; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: break; - - case RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER: - *((rt_uint16_t*)args) = lcd->hw_framebuffer; - break; } return RT_EOK; } -void rtgui_lcd_hw_init(void) +void rt_hw_lcd_init(void) { - lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device)); + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); if (lcd == RT_NULL) return; /* no memory yet */ + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; + /* init device structure */ - lcd->parent.type = RT_Device_Class_Unknown; - lcd->parent.init = rt_lcd_init; - lcd->parent.control = rt_lcd_control; - lcd->parent.user_data = RT_NULL; - lcd->byte_per_pixel = 2; - lcd->width = LCD_WIDTH; - lcd->height = LCD_HEIGHT; - lcd->hw_framebuffer = (void*)_rt_hw_framebuffer; + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* register touch device to RT-Thread */ - rt_device_register(&(lcd->parent), "lcd", RT_DEVICE_FLAG_RDWR); - -#ifdef RT_USING_RTGUI - /* add lcd driver into graphic driver */ - rtgui_graphic_driver_add(&_rtgui_lcd_driver); -#endif + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/lcd_t35.c b/bsp/mini2440/lcd_t35.c index f34c3a2cc1..310bc0ee5a 100644 --- a/bsp/mini2440/lcd_t35.c +++ b/bsp/mini2440/lcd_t35.c @@ -15,7 +15,6 @@ #include #include - #include "lcd.h" /* LCD driver for T3'5 */ @@ -114,22 +113,8 @@ #define S3C2410_LCDINT_FRSYNC (1<<1) volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; -volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; - -struct rtgui_lcd_device -{ - struct rt_device parent; - - /* byte per pixel */ - rt_uint16_t byte_per_pixel; - - /* screen width and height */ - rt_uint16_t width; - rt_uint16_t height; - - void* hw_framebuffer; -}; -static struct rtgui_lcd_device *lcd = RT_NULL; +//volatile rt_uint16_t _rt_hw_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH]; +static struct rt_device_graphic_info _lcd_info; static void lcd_power_enable(int invpwren, int pwren) { @@ -181,119 +166,6 @@ static void LcdBkLtSet(rt_uint32_t HiRatio) TCON = TCON & (~(0xf<<8)) | (0x0d<<8) ; } -#ifdef RT_USING_RTGUI - -#include -#include - -static void rt_hw_lcd_update(rtgui_rect_t *rect) -{ - rt_uint32_t i, j; - - for (i = rect->y1; i < rect->y2; i ++) - { - for(j = rect->x1; j < rect->x2; j++) - _rt_hw_framebuffer[i][j] = _rt_framebuffer[i][j]; - } -} - -static rt_uint8_t * rt_hw_lcd_get_framebuffer(void) -{ - return (rt_uint8_t *)_rt_framebuffer; -} - -static void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - _rt_framebuffer[(y)][(x)] = rtgui_color_to_565p(*c); - } -} - -static void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) -{ - if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT) - { - *c = rtgui_color_from_565p(_rt_framebuffer[(y)][(x)]); - } -} - -static void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_uint32_t idx; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idx = x1; idx < x2; idx ++) - { - _rt_framebuffer[y][idx] = color; - } -} - -static void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2) -{ - rt_uint32_t idy; - rt_uint16_t color; - - /* get color pixel */ - color = rtgui_color_to_565p(*c); - - for (idy = y1; idy < y2; idy ++) - { - _rt_framebuffer[idy][x] = color; - } -} - -static void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) -{ - rt_memcpy((void*)&_rt_framebuffer[y][x1], pixels, (x2 - x1) * 2); -} - -struct rtgui_graphic_driver _rtgui_lcd_driver = -{ - "lcd", - 2, - RT_HW_LCD_WIDTH, - RT_HW_LCD_HEIGHT, - rt_hw_lcd_update, - rt_hw_lcd_get_framebuffer, - rt_hw_lcd_set_pixel, - rt_hw_lcd_get_pixel, - rt_hw_lcd_draw_hline, - rt_hw_lcd_draw_vline, - rt_hw_lcd_draw_raw_hline -}; - -#include "finsh.h" -void hline(rt_uint32_t c, int x1, int x2, int y) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_hline(&color, x1, x2, y); -} -FINSH_FUNCTION_EXPORT(hline, draw a hline); - -void vline(rt_uint32_t c, int x, int y1, int y2) -{ - rtgui_color_t color = (rtgui_color_t)c; - rt_hw_lcd_draw_vline(&color, x, y1, y2); -} -FINSH_FUNCTION_EXPORT(vline, draw a vline); - -void clear() -{ - int y; - - for (y = 0; y < LCD_HEIGHT; y ++) - { - rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, LCD_WIDTH, y); - } -} -FINSH_FUNCTION_EXPORT(clear, clear screen); - -#endif - /* RT-Thread Device Interface */ static rt_err_t rt_lcd_init (rt_device_t dev) { @@ -337,59 +209,42 @@ static rt_err_t rt_lcd_control (rt_device_t dev, rt_uint8_t cmd, void *args) { switch (cmd) { - case RT_DEVICE_CTRL_LCD_GET_WIDTH: - *((rt_uint16_t*)args) = lcd->width; + case RTGRAPHIC_CTRL_RECT_UPDATE: break; - - case RT_DEVICE_CTRL_LCD_GET_HEIGHT: - *((rt_uint16_t*)args) = lcd->height; + case RTGRAPHIC_CTRL_POWERON: break; - - case RT_DEVICE_CTRL_LCD_GET_BPP: - *((rt_uint16_t*)args) = lcd->byte_per_pixel; + case RTGRAPHIC_CTRL_POWEROFF: + break; + case RTGRAPHIC_CTRL_GET_INFO: + rt_memcpy(args, &_lcd_info, sizeof(_lcd_info)); + break; + case RTGRAPHIC_CTRL_SET_MODE: break; } return RT_EOK; } -static rt_err_t rt_lcd_open(rt_device_t dev, rt_uint16_t oflag) -{ - RT_ASSERT(dev != RT_NULL); - - return RT_EOK; -} - -static rt_err_t rt_lcd_close(rt_device_t dev) -{ - RT_ASSERT(dev != RT_NULL); - - return RT_EOK; -} - void rt_hw_lcd_init(void) { - lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device)); + rt_device_t lcd = rt_malloc(sizeof(struct rt_device)); if (lcd == RT_NULL) return; /* no memory yet */ + _lcd_info.bits_per_pixel = 16; + _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565; + _lcd_info.framebuffer = (void*)_rt_framebuffer; + _lcd_info.width = LCD_WIDTH; + _lcd_info.height = LCD_HEIGHT; + /* init device structure */ - lcd->parent.type = RT_Device_Class_Unknown; - lcd->parent.init = rt_lcd_init; - lcd->parent.open = rt_lcd_open; - lcd->parent.close = rt_lcd_close; - lcd->parent.control = rt_lcd_control; - lcd->parent.user_data = RT_NULL; - lcd->byte_per_pixel = 2; - lcd->width = LCD_WIDTH; - lcd->height = LCD_HEIGHT; - lcd->hw_framebuffer = (void*)_rt_framebuffer; + lcd->type = RT_Device_Class_Unknown; + lcd->init = rt_lcd_init; + lcd->open = RT_NULL; + lcd->close = RT_NULL; + lcd->control = rt_lcd_control; + lcd->user_data = (void*)&_lcd_info; - /* register touch device to RT-Thread */ - rt_device_register(&(lcd->parent), "lcd", RT_DEVICE_FLAG_RDWR); - -#ifdef RT_USING_RTGUI - /* add lcd driver into graphic driver */ - rtgui_graphic_driver_add(&_rtgui_lcd_driver); -#endif + /* register lcd device to RT-Thread */ + rt_device_register(lcd, "lcd", RT_DEVICE_FLAG_RDWR); } diff --git a/bsp/mini2440/touch.c b/bsp/mini2440/touch.c index 2d4be231aa..444b7fbbf9 100644 --- a/bsp/mini2440/touch.c +++ b/bsp/mini2440/touch.c @@ -415,7 +415,9 @@ static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args void rtgui_touch_hw_init(void) { + rt_err_t result = RT_FALSE; rt_device_t device = RT_NULL; + struct rt_device_graphic_info info; touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device)); if (touch == RT_NULL) return; /* no memory yet */ @@ -439,8 +441,16 @@ void rtgui_touch_hw_init(void) device = rt_device_find("lcd"); if (device == RT_NULL) return; /* no this device */ - rt_device_control(device, RT_DEVICE_CTRL_LCD_GET_WIDTH, (void*)&touch->width); - rt_device_control(device, RT_DEVICE_CTRL_LCD_GET_HEIGHT, (void*)&touch->height); + /* get graphic device info */ + result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); + if (result != RT_EOK) + { + /* get device information failed */ + return; + } + + touch->width = info.width; + touch->height = info.height; /* create 1/8 second timer */ touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL, -- GitLab