Browse Source

update mini2440 bsp

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1224 bbd45198-f89e-11dd-88c7-29a3b14d5316
qiuyiuestc 14 years ago
parent
commit
e73771f261
7 changed files with 340 additions and 126 deletions
  1. 18 12
      bsp/mini2440/application.c
  2. 5 0
      bsp/mini2440/lcd.h
  3. 99 40
      bsp/mini2440/lcd_a70.c
  4. 81 21
      bsp/mini2440/lcd_n35.c
  5. 82 22
      bsp/mini2440/lcd_t35.c
  6. 4 4
      bsp/mini2440/sdcard.c
  7. 51 27
      bsp/mini2440/touch.c

+ 18 - 12
bsp/mini2440/application.c

@@ -19,9 +19,10 @@
 /*@{*/
 
 #include <rtthread.h>
-#include "dm9000.h"
 #include "touch.h"
+#include "lcd.h"
 #include "led.h"
+#include "dm9000.h"
 
 #ifdef RT_USING_DFS
 /* dfs init */
@@ -45,11 +46,7 @@ extern void rt_hw_touch_init(void);
 #include "ftk.h"
 #endif
 
-#ifdef RT_USING_FTK
-#define RT_INIT_THREAD_STACK_SIZE (10*1024)
-#else
 #define RT_INIT_THREAD_STACK_SIZE (2*1024)
-#endif
 
 #ifdef RT_USING_DFS_ROMFS
 #include <dfs_romfs.h>
@@ -102,12 +99,15 @@ void rt_init_thread_entry(void* parameter)
 
 #ifdef RT_USING_RTGUI
 	{
+		/* init lcd */
+		rt_hw_lcd_init();
+			
 		/* init touch panel */
 		rtgui_touch_hw_init();	
 
 		/* re-init device driver */
-		rt_device_init_all();		
-		
+		rt_device_init_all();
+
 		/* startup rtgui */
 		rtgui_startup();
 	}
@@ -133,7 +133,8 @@ void rt_init_thread_entry(void* parameter)
 
 #ifdef RT_USING_FTK
 	{
-		void rt_hw_lcd_init();	
+		rt_thread_t ftk_thread;
+
 		int FTK_MAIN(int argc, char* argv[]);
 
 		/* init lcd */
@@ -144,9 +145,15 @@ void rt_init_thread_entry(void* parameter)
 
 		/* re-init device driver */
 		rt_device_init_all();
-		
-		/* enter ftk main */
-		FTK_MAIN(0, NULL);
+
+		/* create ftk thread */
+		ftk_thread = rt_thread_create("ftk",
+									FTK_MAIN, RT_NULL,
+									10 * 1024, 8, 20);	
+
+		/* startup ftk thread */
+		if(ftk_thread != RT_NULL)
+			rt_thread_startup(ftk_thread);		
 	}
 #endif
 }
@@ -164,7 +171,6 @@ void rt_led_thread_entry(void* parameter)
 		rt_hw_led_off(LED2|LED3);
 		rt_hw_led_on(LED1|LED4);
 		rt_thread_delay(100);
-
 	}
 }
 

+ 5 - 0
bsp/mini2440/lcd.h

@@ -18,4 +18,9 @@
 
 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

+ 99 - 40
bsp/mini2440/lcd_a70.c

@@ -13,9 +13,10 @@
  */
 
 #include <rtthread.h>
-
 #include <s3c24x0.h>
 
+#include "lcd.h"
+
 /* LCD driver for A7' */
 #define LCD_WIDTH 800
 #define LCD_HEIGHT 480
@@ -108,13 +109,27 @@
 #define S3C2410_LCDCON5_ENLEND	    (1<<2)
 #define S3C2410_LCDCON5_BSWP	    (1<<1)
 #define S3C2410_LCDCON5_HWSWP	    (1<<0)
+#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];
 
-#define	S3C2410_LCDINT_FRSYNC	(1<<1)
+struct rtgui_lcd_device
+{
+	struct rt_device parent;
+
+	/* byte per pixel */
+	rt_uint16_t byte_per_pixel;
 
-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];
+	/* screen width and height */
+	rt_uint16_t width;
+	rt_uint16_t height;
 
-void lcd_power_enable(int invpwren,int pwren)
+	void* hw_framebuffer;
+};
+static struct rtgui_lcd_device *lcd = RT_NULL;
+
+static void lcd_power_enable(int invpwren, int pwren)
 {
     //GPG4 is setted as LCD_PWREN
     GPGUP  = GPGUP | (1<<4); // Pull-up disable
@@ -125,7 +140,7 @@ void lcd_power_enable(int invpwren,int pwren)
     LCDCON5 = LCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
 }
 
-void lcd_envid_on_off(int onoff)
+static void lcd_envid_on_off(int onoff)
 {
 	if(onoff==1)
 		/*ENVID=ON*/
@@ -136,7 +151,7 @@ void lcd_envid_on_off(int onoff)
 }
 
 //********************** BOARD LCD backlight ****************************
-void LcdBkLtSet(rt_uint32_t HiRatio)
+static void LcdBkLtSet(rt_uint32_t HiRatio)
 {
 #define FREQ_PWM1		1000
 	if(!HiRatio)
@@ -169,9 +184,8 @@ void LcdBkLtSet(rt_uint32_t HiRatio)
 #include <rtgui/driver.h>
 #include <rtgui/color.h>
 
-void rt_hw_lcd_update(rtgui_rect_t *rect)
+static void rt_hw_lcd_update(rtgui_rect_t *rect)
 {
-	volatile rt_uint16_t *src_ptr, *dst_ptr;
 	rt_uint32_t i, j;
 
 	for (i = rect->y1; i < rect->y2; i ++)
@@ -181,30 +195,28 @@ void rt_hw_lcd_update(rtgui_rect_t *rect)
 	}
 }
 
-rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
+static rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
 {
 	return (rt_uint8_t *)_rt_framebuffer;
 }
 
-void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)
+	if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT)
 	{
 		_rt_framebuffer[(y)][(x)] = rtgui_color_to_565p(*c);
 	}
 }
 
-void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)
+	if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT)
 	{
 		*c = rtgui_color_from_565p(_rt_framebuffer[(y)][(x)]);
 	}
-
-    return ;
 }
 
-void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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;
@@ -218,9 +230,9 @@ void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_
 	}
 }
 
-void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
+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_uint32_t idy;
 	rt_uint16_t color;
 
 	/* get color pixel */
@@ -232,9 +244,9 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t
 	}
 }
 
-void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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);
+	rt_memcpy((void*)&_rt_framebuffer[y][x1], pixels, (x2 - x1) * 2);
 }
 
 struct rtgui_graphic_driver _rtgui_lcd_driver =
@@ -255,33 +267,34 @@ struct rtgui_graphic_driver _rtgui_lcd_driver =
 #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);
+	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);
+	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;
+	int y;
 
-    for (y = 0; y < 320; y ++)
-    {
-        rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, 240, 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
 
-void rt_hw_lcd_init()
-{
+/* RT-Thread Device Interface */
+static rt_err_t rt_lcd_init (rt_device_t dev)
+{	
 	GPB1_TO_OUT();
 	GPB1_TO_1();
 
@@ -294,17 +307,17 @@ void rt_hw_lcd_init()
 #define	M5D(n)	((n)&0x1fffff)
 #define LCD_ADDR ((rt_uint32_t)_rt_hw_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);
-   	LCDCON4 = (13 <<  8) | (LCD_HSYNC_LEN << 0);
+	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);
+	LCDCON4 = (13 <<  8) | (LCD_HSYNC_LEN << 0);
 #if !defined(LCD_CON5)
-    #define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
+#define LCD_CON5 ((1<<11) | (1 << 9) | (1 << 8) | (1 << 3) | (1 << 0))
 #endif
-    LCDCON5   =  LCD_CON5;
+	LCDCON5   =  LCD_CON5;
 
-    LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) <<  0);
-    LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
-    LCDSADDR3 = LCD_WIDTH;
+	LCDSADDR1 = ((LCD_ADDR >> 22) << 21) | ((M5D(LCD_ADDR >> 1)) <<  0);
+	LCDSADDR2 = M5D((LCD_ADDR + LCD_WIDTH * LCD_HEIGHT * 2) >> 1);
+	LCDSADDR3 = LCD_WIDTH;
 
 	LCDINTMSK |= (3);
 	LPCSEL &= (~7) ;
@@ -314,8 +327,54 @@ void rt_hw_lcd_init()
 	lcd_power_enable(0, 1);
 	lcd_envid_on_off(1);
 
+	return RT_EOK;
+}
+
+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;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_HEIGHT:
+		*((rt_uint16_t*)args) = lcd->height;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_BPP:
+		*((rt_uint16_t*)args) = lcd->byte_per_pixel;			
+		break;
+		
+	case RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER:
+		*((rt_uint16_t*)args) = lcd->hw_framebuffer;			
+		break;		
+	}
+
+	return RT_EOK;
+}
+
+void rt_hw_lcd_init(void)
+{
+	lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device));
+	if (lcd == RT_NULL) return; /* no memory yet */
+
+	/* 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;
+	
+	/* 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
 }
+

+ 81 - 21
bsp/mini2440/lcd_n35.c

@@ -16,6 +16,7 @@
 
 #include <s3c24x0.h>
 
+#include "lcd.h"
 /* LCD driver for N3'5 */
 #define LCD_WIDTH 240
 #define LCD_HEIGHT 320
@@ -111,10 +112,25 @@
 
 #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];
+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];
 
-void lcd_power_enable(int invpwren,int pwren)
+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 void lcd_power_enable(int invpwren, int pwren)
 {
     //GPG4 is setted as LCD_PWREN
     GPGUP  = GPGUP | (1<<4); // Pull-up disable
@@ -125,7 +141,7 @@ void lcd_power_enable(int invpwren,int pwren)
     LCDCON5 = LCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
 }
 
-void lcd_envid_on_off(int onoff)
+static void lcd_envid_on_off(int onoff)
 {
 	if(onoff==1)
 		/*ENVID=ON*/
@@ -136,7 +152,7 @@ void lcd_envid_on_off(int onoff)
 }
 
 //********************** BOARD LCD backlight ****************************
-void LcdBkLtSet(rt_uint32_t HiRatio)
+static void LcdBkLtSet(rt_uint32_t HiRatio)
 {
 #define FREQ_PWM1		1000
 	if(!HiRatio)
@@ -169,9 +185,8 @@ void LcdBkLtSet(rt_uint32_t HiRatio)
 #include <rtgui/driver.h>
 #include <rtgui/color.h>
 
-void rt_hw_lcd_update(rtgui_rect_t *rect)
+static void rt_hw_lcd_update(rtgui_rect_t *rect)
 {
-	volatile rt_uint16_t *src_ptr, *dst_ptr;
 	rt_uint32_t i, j;
 
 	for (i = rect->y1; i < rect->y2; i ++)
@@ -181,12 +196,12 @@ void rt_hw_lcd_update(rtgui_rect_t *rect)
 	}
 }
 
-rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
+static rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
 {
 	return (rt_uint8_t *)_rt_framebuffer;
 }
 
-void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)
 	{
@@ -194,17 +209,15 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
 	}
 }
 
-void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)]);
 	}
-
-    return ;
 }
 
-void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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;
@@ -218,7 +231,7 @@ void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_
 	}
 }
 
-void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
+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;
@@ -232,7 +245,7 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t
 	}
 }
 
-void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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);
 }
@@ -271,17 +284,18 @@ void clear()
 {
     int y;
 
-    for (y = 0; y < 320; y ++)
-    {
-        rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, 240, 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
 
-void rt_hw_lcd_init()
-{
+/* RT-Thread Device Interface */
+static rt_err_t rt_lcd_init (rt_device_t dev)
+{	
 	GPB1_TO_OUT();
 	GPB1_TO_1();
 
@@ -314,8 +328,54 @@ void rt_hw_lcd_init()
 	lcd_power_enable(0, 1);
 	lcd_envid_on_off(1);
 
+	return RT_EOK;
+}
+
+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;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_HEIGHT:
+		*((rt_uint16_t*)args) = lcd->height;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_BPP:
+		*((rt_uint16_t*)args) = lcd->byte_per_pixel;			
+		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)
+{
+	lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device));
+	if (lcd == RT_NULL) return; /* no memory yet */
+
+	/* 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;
+	
+	/* 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
 }
+

+ 82 - 22
bsp/mini2440/lcd_t35.c

@@ -15,7 +15,8 @@
 #include <rtthread.h>
 
 #include <s3c24x0.h>
-#include <string.h>
+
+#include "lcd.h"
 
 /* LCD driver for T3'5 */
 #define LCD_WIDTH 240
@@ -112,10 +113,25 @@
 
 #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];
+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];
 
-void lcd_power_enable(int invpwren,int pwren)
+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 void lcd_power_enable(int invpwren, int pwren)
 {
     //GPG4 is setted as LCD_PWREN
     GPGUP  = GPGUP | (1<<4); // Pull-up disable
@@ -126,7 +142,7 @@ void lcd_power_enable(int invpwren,int pwren)
     LCDCON5 = LCDCON5&(~(1<<5))|(invpwren<<5);   // INVPWREN
 }
 
-void lcd_envid_on_off(int onoff)
+static void lcd_envid_on_off(int onoff)
 {
 	if(onoff==1)
 		/*ENVID=ON*/
@@ -137,7 +153,7 @@ void lcd_envid_on_off(int onoff)
 }
 
 //********************** BOARD LCD backlight ****************************
-void LcdBkLtSet(rt_uint32_t HiRatio)
+static void LcdBkLtSet(rt_uint32_t HiRatio)
 {
 #define FREQ_PWM1		1000
 	if(!HiRatio)
@@ -170,9 +186,8 @@ void LcdBkLtSet(rt_uint32_t HiRatio)
 #include <rtgui/driver.h>
 #include <rtgui/color.h>
 
-void rt_hw_lcd_update(rtgui_rect_t *rect)
+static void rt_hw_lcd_update(rtgui_rect_t *rect)
 {
-	volatile rt_uint16_t *src_ptr, *dst_ptr;
 	rt_uint32_t i, j;
 
 	for (i = rect->y1; i < rect->y2; i ++)
@@ -182,12 +197,12 @@ void rt_hw_lcd_update(rtgui_rect_t *rect)
 	}
 }
 
-rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
+static rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
 {
 	return (rt_uint8_t *)_rt_framebuffer;
 }
 
-void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)
 	{
@@ -195,17 +210,15 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
 	}
 }
 
-void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
+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)]);
 	}
-
-    return ;
 }
 
-void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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;
@@ -219,7 +232,7 @@ void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_
 	}
 }
 
-void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
+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;
@@ -233,7 +246,7 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t
 	}
 }
 
-void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
+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);
 }
@@ -272,17 +285,18 @@ void clear()
 {
     int y;
 
-    for (y = 0; y < 320; y ++)
-    {
-        rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, 240, 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
 
-void rt_hw_lcd_init()
-{
+/* RT-Thread Device Interface */
+static rt_err_t rt_lcd_init (rt_device_t dev)
+{	
 	GPB1_TO_OUT();
 	GPB1_TO_1();
 
@@ -316,8 +330,54 @@ void rt_hw_lcd_init()
 	lcd_power_enable(0, 1);
 	lcd_envid_on_off(1);
 
+	return RT_EOK;
+}
+
+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;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_HEIGHT:
+		*((rt_uint16_t*)args) = lcd->height;			
+		break;
+
+	case RT_DEVICE_CTRL_LCD_GET_BPP:
+		*((rt_uint16_t*)args) = lcd->byte_per_pixel;			
+		break;
+		
+	case RT_DEVICE_CTRL_LCD_GET_FRAMEBUFFER:
+		*((rt_uint16_t*)args) = lcd->hw_framebuffer;			
+		break;		
+	}
+
+	return RT_EOK;
+}
+
+void rt_hw_lcd_init(void)
+{
+	lcd = (struct rtgui_lcd_device*)rt_malloc(sizeof(struct rtgui_lcd_device));
+	if (lcd == RT_NULL) return; /* no memory yet */
+
+	/* 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;
+	
+	/* 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
 }
+

+ 4 - 4
bsp/mini2440/sdcard.c

@@ -159,7 +159,7 @@ static void sd_setbus(void)
     SDICSTA=0xa00;	    /* Clear cmd_end(with rsp) */
 }
 
-int sd_ocr(void)
+static int sd_ocr(void)
 {
 	int i;
 
@@ -186,7 +186,7 @@ int sd_ocr(void)
 	return RT_ERROR;
 }
 
-rt_uint8_t sd_init(void)
+static rt_uint8_t sd_init(void)
 {
 	//-- SD controller & card initialize
 	int i;
@@ -241,7 +241,7 @@ RECMD3:
 	return RT_EOK;
 }
 
-rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
+static rt_uint8_t sd_readblock(rt_uint32_t address, rt_uint8_t* buf)
 {
 	rt_uint32_t status, tmp;
 
@@ -290,7 +290,7 @@ RERDCMD:
 	return RT_EOK;
 }
 
-rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t* buf)
+static rt_uint8_t sd_writeblock(rt_uint32_t address, rt_uint8_t* buf)
 {
 	rt_uint32_t status, tmp;
 

+ 51 - 27
bsp/mini2440/touch.c

@@ -1,4 +1,17 @@
-
+/*
+ * File      : touch.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2010, RT-Thread Develop Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2010-01-01     Yi.Qiu      first version
+ */
+ 
 #include <rthw.h>
 #include <rtthread.h>
 #include <s3c24x0.h>
@@ -9,6 +22,7 @@
 #include <rtgui/event.h>
 #endif
 
+#include "lcd.h"
 #include "touch.h"
 
 /* ADCCON Register Bits */
@@ -69,28 +83,31 @@ struct s3c2410ts
 
 	char phys[32];
 };
-static struct s3c2410ts ts;
+static struct s3c2410ts ts = RT_NULL;
 
 struct rtgui_touch_device
 {
-    struct rt_device parent;
+	struct rt_device parent;
 
-    rt_timer_t poll_timer;
-    rt_uint16_t x, y;
+	rt_timer_t poll_timer;
+	rt_uint16_t x, y;
 
-    rt_bool_t calibrating;
-    rt_touch_calibration_func_t calibration_func;
+	rt_bool_t calibrating;
+	rt_touch_calibration_func_t calibration_func;
 
 	rt_touch_eventpost_func_t eventpost_func;
 	void *eventpost_param;
 
-    rt_uint16_t min_x, max_x;
-    rt_uint16_t min_y, max_y;
+	rt_uint16_t min_x, max_x;
+	rt_uint16_t min_y, max_y;
+
+	rt_uint16_t width;
+	rt_uint16_t height;
+	
+	rt_bool_t first_down_report;
 };
 static struct rtgui_touch_device *touch = RT_NULL;
 
-static int first_down_report;
-
 #ifdef RT_USING_RTGUI
 static void report_touch_input(int updown)
 {
@@ -112,13 +129,13 @@ static void report_touch_input(int updown)
 		}
 		else
 		{	
-			touch->x = 240 * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
-			touch->y = 320 - (320*(ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
+			touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
+			touch->y = touch->height - (touch->height * (ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
 		}
 
 		emouse.x = touch->x;
 		emouse.y = touch->y;
-		if(first_down_report == 1)
+		if(touch->first_down_report == RT_TRUE)
 		{
 			emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
 			emouse.button |= RTGUI_MOUSE_BUTTON_DOWN;
@@ -142,10 +159,8 @@ static void report_touch_input(int updown)
 		}
 	}
 
-	/*	
-		rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
-		touch->x, touch->y);
-	*/
+	/* rt_kprintf("touch %s: ts.x: %d, ts.y: %d\n", updown? "down" : "up",
+	touch->x, touch->y); */	
 	
 	/* send event to server */
 	if (touch->calibrating != RT_TRUE)
@@ -170,15 +185,15 @@ static void report_touch_input(int updown)
 		}
 		else
 		{	
-			touch->x = 240 * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
-			touch->y = 320 - (320*(ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
+			touch->x = touch->width * (ts.xp-touch->min_x)/(touch->max_x-touch->min_x);
+			touch->y = touch->height - (touch->height * (ts.yp-touch->min_y)/(touch->max_y-touch->min_y));
 		}
 
 		touch_event.x = touch->x;
 		touch_event.y = touch->y;
 		touch_event.pressed = 1;
 
-		if(first_down_report == 1)
+		if(touch->first_down_report == RT_TRUE)
 		{
 			if (touch->calibrating != RT_TRUE && touch->eventpost_func)
 			{	
@@ -191,7 +206,7 @@ static void report_touch_input(int updown)
 		touch_event.x = touch->x;
 		touch_event.y = touch->y;
 		touch_event.pressed = 0;
-
+		
 		if ((touch->calibrating == RT_TRUE) && (touch->calibration_func != RT_NULL))
 		{
 			/* callback function */
@@ -252,13 +267,13 @@ static void s3c2410_adc_stylus_action(void)
 	}
 	else
 	{
-		if (first_down_report)
+		if (touch->first_down_report)
 		{
 			report_touch_input(1);
 			ts.xp = 0;
 			ts.yp = 0;
 			ts.count = 0;
-			first_down_report = 0;
+			touch->first_down_report = 0;
 		}
 		/* start timer */
 		rt_timer_start(touch->poll_timer);
@@ -289,7 +304,7 @@ static void s3c2410_intc_stylus_updown(void)
 	{
 		/* stop timer */
 		rt_timer_stop(touch->poll_timer);
-		first_down_report = 1;
+		touch->first_down_report = RT_TRUE;
 		if (ts.xp >= 0 && ts.yp >= 0)
 		{
 			report_touch_input(updown);
@@ -349,7 +364,7 @@ static rt_err_t rtgui_touch_init (rt_device_t dev)
 	INTSUBMSK &= ~BIT_SUB_ADC;
 	INTSUBMSK &= ~BIT_SUB_TC;
 
-	first_down_report = 1;
+	touch->first_down_report = RT_TRUE;
 
 	return RT_EOK;
 }
@@ -373,7 +388,7 @@ static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args
 
 		data = (struct calibration_data*) args;
 
-		//update
+		/* update */
 		touch->min_x = data->min_x;
 		touch->max_x = data->max_x;
 		touch->min_y = data->max_y;
@@ -400,6 +415,8 @@ static rt_err_t rtgui_touch_control (rt_device_t dev, rt_uint8_t cmd, void *args
 
 void rtgui_touch_hw_init(void)
 {
+	rt_device_t device = RT_NULL;
+
 	touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
 	if (touch == RT_NULL) return; /* no memory yet */
 
@@ -419,6 +436,12 @@ void rtgui_touch_hw_init(void)
 	touch->parent.control = rtgui_touch_control;
 	touch->parent.user_data = RT_NULL;
 
+	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);
+	
 	/* create 1/8 second timer */
 	touch->poll_timer = rt_timer_create("touch", touch_timer_fire, RT_NULL,
 	                                    RT_TICK_PER_SECOND/8, RT_TIMER_FLAG_PERIODIC);
@@ -426,3 +449,4 @@ void rtgui_touch_hw_init(void)
 	/* register touch device to RT-Thread */
 	rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
 }
+