lv_port_disp.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * 2021-10-18 Meco Man The first version
  9. */
  10. #include <lvgl.h>
  11. #include <board.h>
  12. #include <drv_lcd.h>
  13. #define LCD_DEV_NAME "lcd"
  14. // #define MY_DISP_HOR_RES LCD_W
  15. // #define DISP_BUFFER_LINES 70
  16. /*A static or global variable to store the buffers*/
  17. static lv_disp_draw_buf_t disp_buf;
  18. /*Descriptor of a display driver*/
  19. static lv_disp_drv_t disp_drv;
  20. /*Static or global buffer(s). The second buffer is optional*/
  21. #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  22. #pragma location=0x68000000
  23. lv_color_t buf_1[LCD_H * LCD_W];
  24. #elif defined ( __CC_ARM ) /* MDK ARM Compiler */
  25. __attribute__((at(0x68000000))) lv_color_t buf_1[LCD_H * LCD_W];
  26. #elif defined ( __clang__ ) /* MDK ARM Compiler v6 */
  27. __attribute__((section(".ARM.__at_0x68000000"))) lv_color_t buf_1[LCD_H * LCD_W];
  28. #elif defined ( __GNUC__ ) /* GNU Compiler */
  29. lv_color_t buf_1[LCD_H * LCD_W] __attribute__((section(".MCUlcdgrambysram")));
  30. #ifdef RT_USING_MEMHEAP_AS_HEAP
  31. #error "You should modify this logic, such as use 'rt_malloc' to create lvgl buf"
  32. #endif
  33. #endif
  34. /*Flush the content of the internal buffer the specific area on the display
  35. *You can use DMA or any hardware acceleration to do this operation in the background but
  36. *'lv_disp_flush_ready()' has to be called when finished.*/
  37. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
  38. {
  39. /* color_p is a buffer pointer; the buffer is provided by LVGL */
  40. lcd_fill_array(area->x1, area->y1, area->x2, area->y2, color_p);
  41. /*IMPORTANT!!!
  42. *Inform the graphics library that you are ready with the flushing*/
  43. lv_disp_flush_ready(disp_drv);
  44. }
  45. void lv_port_disp_init(void)
  46. {
  47. /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
  48. lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, LCD_H * LCD_W);
  49. lv_disp_drv_init(&disp_drv); /*Basic initialization*/
  50. /*Set the resolution of the display*/
  51. disp_drv.hor_res = LCD_W;
  52. disp_drv.ver_res = LCD_H;
  53. /*Set a display buffer*/
  54. disp_drv.draw_buf = &disp_buf;
  55. /*Used to copy the buffer's content to the display*/
  56. disp_drv.flush_cb = disp_flush;
  57. /*Init lcd device*/
  58. rt_device_t lcd_dev = rt_device_find(LCD_DEV_NAME);
  59. rt_device_open(lcd_dev, RT_DEVICE_FLAG_STANDALONE);
  60. disp_drv.user_data = lcd_dev;
  61. /*Finally register the driver*/
  62. lv_disp_drv_register(&disp_drv);
  63. }