lv_port_disp.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-02-01 Rudy Lo The first version
  9. */
  10. #include <lvgl.h>
  11. #include <rtthread.h>
  12. #include "drv_spi_ili9488.h"
  13. #define MY_DISP_HOR_RES (LCD_W)
  14. #define DISP_BUFFER_LINES (LCD_H / 5)
  15. /*A static or global variable to store the buffers*/
  16. static lv_disp_draw_buf_t disp_buf;
  17. /*Descriptor of a display driver*/
  18. static lv_disp_drv_t disp_drv;
  19. /*Static or global buffer(s). The second buffer is optional*/
  20. static lv_color_t buf_1[MY_DISP_HOR_RES * DISP_BUFFER_LINES];
  21. //static lv_color_t buf_2[MY_DISP_HOR_RES * DISP_BUFFER_LINES];
  22. /*Flush the content of the internal buffer the specific area on the display
  23. *You can use DMA or any hardware acceleration to do this operation in the background but
  24. *'lv_disp_flush_ready()' has to be called when finished.*/
  25. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
  26. {
  27. /* color_p is a buffer pointer; the buffer is provided by LVGL */
  28. lcd_fill_array(area->x1, area->y1, area->x2, area->y2, color_p);
  29. /*IMPORTANT!!!
  30. *Inform the graphics library that you are ready with the flushing*/
  31. lv_disp_flush_ready(disp_drv);
  32. }
  33. void lv_port_disp_init(void)
  34. {
  35. /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
  36. lv_disp_draw_buf_init(&disp_buf, buf_1, RT_NULL, MY_DISP_HOR_RES * DISP_BUFFER_LINES);
  37. lv_disp_drv_init(&disp_drv); /*Basic initialization*/
  38. /*Set the resolution of the display*/
  39. disp_drv.hor_res = LCD_W;
  40. disp_drv.ver_res = LCD_H;
  41. /*Set a display buffer*/
  42. disp_drv.draw_buf = &disp_buf;
  43. /*Used to copy the buffer's content to the display*/
  44. disp_drv.flush_cb = disp_flush;
  45. /*Finally register the driver*/
  46. lv_disp_drv_register(&disp_drv);
  47. }