lpc17xx_lcd.c 2.3 KB

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