2009-11-24 07:34:58 +08:00
|
|
|
/*
|
|
|
|
* File : driver.c
|
|
|
|
* This file is part of RTGUI in RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development 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
|
|
|
|
* 2009-10-04 Bernard first version
|
|
|
|
*/
|
|
|
|
#include <rtgui/driver.h>
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
struct rtgui_graphic_driver _driver;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
extern const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format);
|
|
|
|
extern const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format);
|
|
|
|
|
|
|
|
/* get default driver */
|
|
|
|
struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
return &_driver;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
RT_ASSERT(rect != RT_NULL);
|
|
|
|
RT_ASSERT(driver != RT_NULL);
|
|
|
|
|
|
|
|
rect->x1 = rect->y1 = 0;
|
|
|
|
rect->x2 = driver->width;
|
|
|
|
rect->y2 = driver->height;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
rt_err_t rtgui_graphic_set_device(rt_device_t device)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
rt_err_t result;
|
|
|
|
struct rt_lcd_info info;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* get framebuffer address */
|
|
|
|
result = rt_device_control(device, LCD_GET_INFO, &info);
|
|
|
|
if (result != RT_EOK)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
/* get device information failed */
|
|
|
|
return -RT_ERROR;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* initialize framebuffer driver */
|
|
|
|
_driver.device = device;
|
|
|
|
_driver.pixel_format = info.pixel_format;
|
|
|
|
_driver.byte_per_pixel = info.byte_per_pixel;
|
|
|
|
_driver.width = info.width;
|
|
|
|
_driver.height = info.height;
|
|
|
|
_driver.pitch = _driver.width * _driver.byte_per_pixel;
|
|
|
|
_driver.framebuffer = info.framebuffer;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
if (info.framebuffer != RT_NULL)
|
|
|
|
{
|
|
|
|
/* is a frame buffer device */
|
|
|
|
_driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* is a pixel device */
|
|
|
|
_driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return RT_EOK;
|
2010-07-05 07:58:35 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* screen update */
|
|
|
|
void rtgui_graphic_driver_screen_update(struct rtgui_graphic_driver* driver, rtgui_rect_t *rect)
|
2010-07-05 07:58:35 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
rt_device_control(driver->device, LCD_RECT_UPDATE, rect);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* get video frame buffer */
|
|
|
|
rt_uint8_t* rtgui_graphic_driver_get_framebuffer(struct rtgui_graphic_driver* driver)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2011-06-05 23:16:41 +08:00
|
|
|
return (rt_uint8_t*)driver->framebuffer;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2010-07-05 07:58:35 +08:00
|
|
|
|