lpc17xx_lcd.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <rtthread.h>
  2. #include "LPC177x_8x.h"
  3. #include "lpc177x_8x_pinsel.h"
  4. #include "drv_glcd.h"
  5. #define RT_HW_LCD_WIDTH 480
  6. #define RT_HW_LCD_HEIGHT 272
  7. static struct rt_device_graphic_info _lcd_info;
  8. static struct rt_device lcd;
  9. /* RT-Thread Device Interface */
  10. static rt_err_t rt_lcd_init (rt_device_t dev)
  11. {
  12. PINSEL_ConfigPin(5, 4, 0);
  13. LPC_GPIO5->DIR |= 1<<4;
  14. LPC_GPIO5->CLR = 1<<4;
  15. LPC_GPIO5->SET = 1<<4;
  16. /*Disable LCD controller*/
  17. GLCD_Ctrl (FALSE);
  18. /*Init LCD and copy picture in video RAM*/
  19. GLCD_Init (_lcd_info.framebuffer);
  20. /*Enable LCD*/
  21. GLCD_Ctrl (TRUE);
  22. return RT_EOK;
  23. }
  24. static rt_err_t rt_lcd_control (rt_device_t dev, int cmd, void *args)
  25. {
  26. switch (cmd)
  27. {
  28. case RTGRAPHIC_CTRL_RECT_UPDATE:
  29. break;
  30. case RTGRAPHIC_CTRL_POWERON:
  31. break;
  32. case RTGRAPHIC_CTRL_POWEROFF:
  33. break;
  34. case RTGRAPHIC_CTRL_GET_INFO:
  35. rt_memcpy(args, &_lcd_info, sizeof(_lcd_info));
  36. break;
  37. case RTGRAPHIC_CTRL_SET_MODE:
  38. break;
  39. }
  40. return RT_EOK;
  41. }
  42. /* LCD BL P5_4 */
  43. void rt_hw_lcd_init(void)
  44. {
  45. rt_uint16_t * _rt_framebuffer = RT_NULL;
  46. // _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8);
  47. // if (_rt_framebuffer == RT_NULL) return; /* no memory yet */
  48. _rt_framebuffer = (rt_uint16_t *)0xA0000000;
  49. _lcd_info.bits_per_pixel = 16;
  50. _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
  51. _lcd_info.framebuffer = (void*)_rt_framebuffer;
  52. _lcd_info.width = RT_HW_LCD_WIDTH;
  53. _lcd_info.height = RT_HW_LCD_HEIGHT;
  54. /* init device structure */
  55. lcd.type = RT_Device_Class_Graphic;
  56. lcd.init = rt_lcd_init;
  57. lcd.open = RT_NULL;
  58. lcd.close = RT_NULL;
  59. lcd.control = rt_lcd_control;
  60. lcd.user_data = (void*)&_lcd_info;
  61. /* register lcd device to RT-Thread */
  62. rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
  63. }
  64. void lcd_fill(uint8_t * start, uint8_t * end, uint8_t pixel)
  65. {
  66. while(start<end)
  67. {
  68. *start++ = pixel;
  69. }
  70. }
  71. #ifdef RT_USING_FINSH
  72. #include <finsh.h>
  73. FINSH_FUNCTION_EXPORT(lcd_fill, lcd_fill );
  74. #endif