|
@@ -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
|
|
|
}
|
|
|
+
|