lv_port_disp.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * 2021-12-24 Rb Refresh using dma2d
  10. */
  11. #include <lvgl.h>
  12. #include "drv_lcd.h"
  13. /*A static or global variable to store the buffers*/
  14. static lv_disp_draw_buf_t disp_buf;
  15. static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
  16. #define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
  17. static const lv_color_t * buf_to_flush;
  18. static lv_disp_drv_t g_disp_drv;
  19. static lv_color_t lv_disp_buf1[DISP_BUF_SIZE];
  20. static void lcd_fb_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
  21. {
  22. LCD_DisplayWindows(area->x1, area->y1, area->x2, area->y2, (uint16_t*) color_p);
  23. lv_disp_flush_ready(disp_drv);
  24. }
  25. void lv_port_disp_init(void)
  26. {
  27. rt_err_t result;
  28. SPI_Init();
  29. LCD_Init(HORIZONTAL);
  30. /*Initialize `disp_buf` with the buffer(s).*/
  31. lv_disp_draw_buf_init(&disp_buf, lv_disp_buf1, RT_NULL, DISP_BUF_SIZE);
  32. lv_disp_drv_init(&disp_drv); /*Basic initialization*/
  33. /*Set the resolution of the display*/
  34. disp_drv.hor_res = LV_VER_RES_MAX;
  35. disp_drv.ver_res = LV_HOR_RES_MAX;
  36. /*Set a display buffer*/
  37. disp_drv.draw_buf = &disp_buf;
  38. /*Used to copy the buffer's content to the display*/
  39. disp_drv.flush_cb = lcd_fb_flush;
  40. /*Finally register the driver*/
  41. lv_disp_drv_register(&disp_drv);
  42. g_disp_drv = disp_drv;
  43. }