driver.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * File : driver.c
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-04 Bernard first version
  13. */
  14. #include <rtgui/driver.h>
  15. struct rtgui_graphic_driver _driver;
  16. extern const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format);
  17. extern const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format);
  18. /* get default driver */
  19. struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
  20. {
  21. return &_driver;
  22. }
  23. void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
  24. {
  25. RT_ASSERT(rect != RT_NULL);
  26. RT_ASSERT(driver != RT_NULL);
  27. rect->x1 = rect->y1 = 0;
  28. rect->x2 = driver->width;
  29. rect->y2 = driver->height;
  30. }
  31. rt_err_t rtgui_graphic_set_device(rt_device_t device)
  32. {
  33. rt_err_t result;
  34. struct rt_lcd_info info;
  35. /* get framebuffer address */
  36. result = rt_device_control(device, LCD_GET_INFO, &info);
  37. if (result != RT_EOK)
  38. {
  39. /* get device information failed */
  40. return -RT_ERROR;
  41. }
  42. /* initialize framebuffer driver */
  43. _driver.device = device;
  44. _driver.pixel_format = info.pixel_format;
  45. _driver.byte_per_pixel = info.byte_per_pixel;
  46. _driver.width = info.width;
  47. _driver.height = info.height;
  48. _driver.pitch = _driver.width * _driver.byte_per_pixel;
  49. _driver.framebuffer = info.framebuffer;
  50. if (info.framebuffer != RT_NULL)
  51. {
  52. /* is a frame buffer device */
  53. _driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format);
  54. }
  55. else
  56. {
  57. /* is a pixel device */
  58. _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format);
  59. }
  60. return RT_EOK;
  61. }
  62. /* screen update */
  63. void rtgui_graphic_driver_screen_update(struct rtgui_graphic_driver* driver, rtgui_rect_t *rect)
  64. {
  65. rt_device_control(driver->device, LCD_RECT_UPDATE, rect);
  66. }
  67. /* get video frame buffer */
  68. rt_uint8_t* rtgui_graphic_driver_get_framebuffer(struct rtgui_graphic_driver* driver)
  69. {
  70. return (rt_uint8_t*)driver->framebuffer;
  71. }