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