driver.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <rtthread.h>
  15. #include <rtgui/driver.h>
  16. struct rtgui_graphic_driver _driver;
  17. extern const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format);
  18. extern const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format);
  19. /* get default driver */
  20. struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
  21. {
  22. return &_driver;
  23. }
  24. void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
  25. {
  26. RT_ASSERT(rect != RT_NULL);
  27. RT_ASSERT(driver != RT_NULL);
  28. rect->x1 = rect->y1 = 0;
  29. rect->x2 = driver->width;
  30. rect->y2 = driver->height;
  31. }
  32. rt_err_t rtgui_graphic_set_device(rt_device_t device)
  33. {
  34. rt_err_t result;
  35. struct rt_device_graphic_info info;
  36. /* get framebuffer address */
  37. result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info);
  38. if (result != RT_EOK)
  39. {
  40. /* get device information failed */
  41. return -RT_ERROR;
  42. }
  43. /* initialize framebuffer driver */
  44. _driver.device = device;
  45. _driver.pixel_format = info.pixel_format;
  46. _driver.bits_per_pixel = info.bits_per_pixel;
  47. _driver.width = info.width;
  48. _driver.height = info.height;
  49. _driver.pitch = _driver.width * _driver.bits_per_pixel/8;
  50. _driver.framebuffer = info.framebuffer;
  51. if (info.framebuffer != RT_NULL)
  52. {
  53. /* is a frame buffer device */
  54. _driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format);
  55. }
  56. else
  57. {
  58. /* is a pixel device */
  59. _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format);
  60. }
  61. return RT_EOK;
  62. }
  63. /* screen update */
  64. void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* driver, rtgui_rect_t *rect)
  65. {
  66. struct rt_device_rect_info rect_info;
  67. rect_info.x = rect->x1; rect_info.y = rect->y1;
  68. rect_info.width = rect->x2 - rect->x1;
  69. rect_info.height = rect->y2 - rect->y1;
  70. rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);
  71. }
  72. /* get video frame buffer */
  73. rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver* driver)
  74. {
  75. return (rt_uint8_t*)driver->framebuffer;
  76. }