lpc17xx_lcd.c 2.1 KB

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