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
|
|
|
|
*/
|
2011-06-06 17:10:13 +08:00
|
|
|
#include <rtthread.h>
|
2009-11-24 07:34:58 +08:00
|
|
|
#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 */
|
2012-11-26 10:42:52 +08:00
|
|
|
struct rtgui_graphic_driver *rtgui_graphic_driver_get_default()
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
return &_driver;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_driver_get_default);
|
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
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
RT_ASSERT(rect != RT_NULL);
|
|
|
|
RT_ASSERT(driver != RT_NULL);
|
2011-06-05 23:16:41 +08:00
|
|
|
|
2012-11-26 10:42:52 +08:00
|
|
|
rect->x1 = rect->y1 = 0;
|
|
|
|
rect->x2 = driver->width;
|
|
|
|
rect->y2 = driver->height;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_driver_get_rect);
|
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
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
rt_err_t result;
|
|
|
|
struct rt_device_graphic_info info;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2012-11-26 10:42:52 +08:00
|
|
|
/* get framebuffer address */
|
|
|
|
result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
/* get device information failed */
|
|
|
|
return -RT_ERROR;
|
|
|
|
}
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2012-11-26 10:42:52 +08:00
|
|
|
/* initialize framebuffer driver */
|
|
|
|
_driver.device = device;
|
|
|
|
_driver.pixel_format = info.pixel_format;
|
|
|
|
_driver.bits_per_pixel = info.bits_per_pixel;
|
|
|
|
_driver.width = info.width;
|
|
|
|
_driver.height = info.height;
|
|
|
|
_driver.pitch = _driver.width * _driver.bits_per_pixel / 8;
|
|
|
|
_driver.framebuffer = info.framebuffer;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2012-11-26 10:42:52 +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
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_set_device);
|
2010-07-05 07:58:35 +08:00
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* screen update */
|
2012-11-26 10:42:52 +08:00
|
|
|
void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
|
2010-07-05 07:58:35 +08:00
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
struct rt_device_rect_info rect_info;
|
2011-06-06 17:10:13 +08:00
|
|
|
|
2012-11-26 10:42:52 +08:00
|
|
|
rect_info.x = rect->x1;
|
|
|
|
rect_info.y = rect->y1;
|
|
|
|
rect_info.width = rect->x2 - rect->x1;
|
|
|
|
rect_info.height = rect->y2 - rect->y1;
|
|
|
|
rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_driver_screen_update);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2011-06-05 23:16:41 +08:00
|
|
|
/* get video frame buffer */
|
2012-11-26 10:42:52 +08:00
|
|
|
rt_uint8_t *rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver *driver)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
return (rt_uint8_t *)driver->framebuffer;
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_driver_get_framebuffer);
|
2010-07-05 07:58:35 +08:00
|
|
|
|
2012-11-26 10:42:52 +08:00
|
|
|
rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void)
|
2012-07-20 20:37:56 +08:00
|
|
|
{
|
2012-11-26 10:42:52 +08:00
|
|
|
return rtgui_graphic_driver_get_framebuffer(&_driver);
|
2012-07-20 20:37:56 +08:00
|
|
|
}
|
2012-08-27 15:57:19 +08:00
|
|
|
RTM_EXPORT(rtgui_graphic_driver_get_default_framebuffer);
|
|
|
|
|