lnn800x480.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * File : lcd_800480.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, RT-Thread Develop 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. * 2010-01-01 bernard first version from QiuYi's driver
  13. */
  14. #include <rtthread.h>
  15. #ifdef RT_USING_RTGUI
  16. #include <soc3210.h>
  17. #include <rtgui/driver.h>
  18. #include <rtgui/color.h>
  19. /* LCD driver for 800x480 16bit */
  20. #define RT_HW_LCD_WIDTH 800
  21. #define RT_HW_LCD_HEIGHT 480
  22. ALIGN(4)
  23. volatile rt_uint16_t _rt_framebuffer[RT_HW_LCD_HEIGHT][RT_HW_LCD_WIDTH];
  24. #define K1BASE 0xA0000000
  25. #define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr)))
  26. #define HW_FB_ADDR KSEG1(_rt_framebuffer)
  27. #define HW_FB_PIXEL(x, y) *(volatile rt_uint16_t*)((rt_uint8_t*)HW_FB_ADDR + (y * RT_HW_LCD_WIDTH * 2) + x * 2)
  28. void rt_hw_lcd_update(rtgui_rect_t *rect)
  29. {
  30. }
  31. rt_uint8_t * rt_hw_lcd_get_framebuffer(void)
  32. {
  33. return (rt_uint8_t *)HW_FB_ADDR;
  34. }
  35. void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
  36. {
  37. if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT)
  38. {
  39. HW_FB_PIXEL(x, y) = rtgui_color_to_565p(*c);
  40. }
  41. }
  42. void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
  43. {
  44. if (x < RT_HW_LCD_WIDTH && y < RT_HW_LCD_HEIGHT)
  45. {
  46. *c = rtgui_color_from_565p(HW_FB_PIXEL(x, y));
  47. }
  48. return ;
  49. }
  50. void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
  51. {
  52. rt_uint32_t idx;
  53. rt_uint16_t color;
  54. /* get color pixel */
  55. color = rtgui_color_to_565p(*c);
  56. for (idx = x1; idx < x2; idx ++)
  57. {
  58. HW_FB_PIXEL(idx, y) = color;
  59. }
  60. }
  61. void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2)
  62. {
  63. rt_uint32_t idy;
  64. rt_uint16_t color;
  65. /* get color pixel */
  66. color = rtgui_color_to_565p(*c);
  67. for (idy = y1; idy < y2; idy ++)
  68. {
  69. HW_FB_PIXEL(x, idy) = color;
  70. }
  71. }
  72. void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
  73. {
  74. rt_uint8_t* ptr;
  75. ptr = (rt_uint8_t*)&HW_FB_PIXEL(x1, y);
  76. rt_memcpy(ptr, pixels, (x2 - x1) * 2);
  77. }
  78. struct rtgui_graphic_driver _rtgui_lcd_driver =
  79. {
  80. "lcd",
  81. 2,
  82. RT_HW_LCD_WIDTH,
  83. RT_HW_LCD_HEIGHT,
  84. rt_hw_lcd_update,
  85. rt_hw_lcd_get_framebuffer,
  86. rt_hw_lcd_set_pixel,
  87. rt_hw_lcd_get_pixel,
  88. rt_hw_lcd_draw_hline,
  89. rt_hw_lcd_draw_vline,
  90. rt_hw_lcd_draw_raw_hline
  91. };
  92. #include "finsh.h"
  93. void hline(rt_uint32_t c, int x1, int x2, int y)
  94. {
  95. rtgui_color_t color = (rtgui_color_t)c;
  96. rt_hw_lcd_draw_hline(&color, x1, x2, y);
  97. }
  98. FINSH_FUNCTION_EXPORT(hline, draw a hline);
  99. void vline(rt_uint32_t c, int x, int y1, int y2)
  100. {
  101. rtgui_color_t color = (rtgui_color_t)c;
  102. rt_hw_lcd_draw_vline(&color, x, y1, y2);
  103. }
  104. FINSH_FUNCTION_EXPORT(vline, draw a vline);
  105. void clear()
  106. {
  107. int y;
  108. for (y = 0; y < _rtgui_lcd_driver.height; y ++)
  109. {
  110. rt_hw_lcd_draw_hline((rtgui_color_t*)&white, 0, 240, y);
  111. }
  112. }
  113. FINSH_FUNCTION_EXPORT(clear, clear screen);
  114. void fill(rt_uint32_t c)
  115. {
  116. int y;
  117. rtgui_color_t color = (rtgui_color_t)c;
  118. for (y = 0; y < _rtgui_lcd_driver.height; y ++)
  119. {
  120. rt_hw_lcd_draw_hline(&color, 0, _rtgui_lcd_driver.width, y);
  121. }
  122. }
  123. FINSH_FUNCTION_EXPORT(fill, fill screen with color);
  124. void lcd_init()
  125. {
  126. /* disable LCD controller */
  127. LCD_CTRL = LCD_CTRL & 0xfffe;
  128. /* set LCD clock */
  129. HSB_MISC_REG = (HSB_MISC_REG & 0xFFFD01FF) |
  130. (0x01 << 17) | /* enable LCD */
  131. (0x05 << 9); /* clock */
  132. LCD_VBARA = (rt_uint32_t)_rt_framebuffer - 0x80000000;
  133. LCD_VBARB = (rt_uint32_t)_rt_framebuffer - 0x80000000;
  134. LCD_HTIM = 0x12c031f;
  135. LCD_VTIM = 0x11501df;
  136. LCD_HVLEN = 0x41e0279;
  137. LCD_CTRL = 0x8709;
  138. rt_kprintf("VBARA 0x%08x\n", LCD_VBARA);
  139. rt_kprintf("CTRL 0x%08x\n", LCD_CTRL);
  140. rt_kprintf("HTIM 0x%08x\n", LCD_HTIM);
  141. rt_kprintf("VTIM 0x%08x\n", LCD_VTIM);
  142. rt_kprintf("HVLEN 0x%08x\n", LCD_HVLEN);
  143. rt_kprintf("HSB_MISC 0x%08x\n", HSB_MISC_REG);
  144. /* add lcd driver into graphic driver */
  145. rtgui_graphic_driver_add(&_rtgui_lcd_driver);
  146. }
  147. FINSH_FUNCTION_EXPORT(lcd_init, init lcd);
  148. void rt_hw_lcd_init()
  149. {
  150. lcd_init();
  151. }
  152. #endif