lv_port_disp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * @file lv_port_disp_templ.c
  3. *
  4. */
  5. /*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
  6. #if 1
  7. /*********************
  8. * INCLUDES
  9. *********************/
  10. #include "lv_port_disp.h"
  11. #include <stdbool.h>
  12. #include "luat_mem.h"
  13. #define LUAT_LOG_TAG "lvgl"
  14. #include "luat_log.h"
  15. /*********************
  16. * DEFINES
  17. *********************/
  18. /**********************
  19. * TYPEDEFS
  20. **********************/
  21. /**********************
  22. * STATIC PROTOTYPES
  23. **********************/
  24. static void disp_init(void);
  25. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
  26. /**********************
  27. * STATIC VARIABLES
  28. **********************/
  29. /**********************
  30. * MACROS
  31. **********************/
  32. /**********************
  33. * GLOBAL FUNCTIONS
  34. **********************/
  35. void lv_port_disp_init(luat_lcd_conf_t* lcd_conf)
  36. {
  37. /*-------------------------
  38. * Initialize your display
  39. * -----------------------*/
  40. disp_init();
  41. /*-----------------------------
  42. * Create a buffer for drawing
  43. *----------------------------*/
  44. static lv_disp_draw_buf_t lv_disp_draw_buf;
  45. lv_color_t* buf_2_1 = NULL;
  46. lv_color_t* buf_2_2 = NULL;
  47. #define SIZE_IN_PX_CNT (lcd_conf->w * 10)
  48. #define DRAW_BUFFER_SIZE SIZE_IN_PX_CNT * sizeof(lv_color_t)
  49. buf_2_1 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
  50. buf_2_2 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
  51. lv_disp_draw_buf_init(&lv_disp_draw_buf, buf_2_1, buf_2_2, SIZE_IN_PX_CNT);
  52. // lv_disp_draw_buf_init(&lv_disp_draw_buf, lcd_conf->buff, lcd_conf->buff1, lcd_conf->w * lcd_conf->h);
  53. /*-----------------------------------
  54. * Register the display in LVGL
  55. *----------------------------------*/
  56. static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
  57. lv_disp_drv_init(&disp_drv); /*Basic initialization*/
  58. /*Set up the functions to access to your display*/
  59. /*Set the resolution of the display*/
  60. disp_drv.hor_res = lcd_conf->w;
  61. disp_drv.ver_res = lcd_conf->h;
  62. /*Used to copy the buffer's content to the display*/
  63. disp_drv.flush_cb = disp_flush;
  64. /*Set a display buffer*/
  65. disp_drv.draw_buf = &lv_disp_draw_buf;
  66. /*Required for Example 3)*/
  67. //disp_drv.full_refresh = 1;
  68. /* Fill a memory array with a color if you have GPU.
  69. * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
  70. * But if you have a different GPU you can use with this callback.*/
  71. //disp_drv.gpu_fill_cb = gpu_fill;
  72. disp_drv.user_data = lcd_conf;
  73. /*Finally register the driver*/
  74. lv_disp_drv_register(&disp_drv);
  75. }
  76. /**********************
  77. * STATIC FUNCTIONS
  78. **********************/
  79. /*Initialize your display and the required peripherals.*/
  80. static void disp_init(void)
  81. {
  82. /*You code here*/
  83. }
  84. volatile bool disp_flush_enabled = true;
  85. /* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
  86. */
  87. void disp_enable_update(void)
  88. {
  89. disp_flush_enabled = true;
  90. }
  91. /* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
  92. */
  93. void disp_disable_update(void)
  94. {
  95. disp_flush_enabled = false;
  96. }
  97. /*Flush the content of the internal buffer the specific area on the display
  98. *You can use DMA or any hardware acceleration to do this operation in the background but
  99. *'lv_disp_flush_ready()' has to be called when finished.*/
  100. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
  101. {
  102. if(disp_flush_enabled) {
  103. luat_lcd_conf_t* lcd_conf = disp_drv->user_data;
  104. luat_lcd_draw(lcd_conf, area->x1, area->y1, area->x2, area->y2, color_p);
  105. if (lv_disp_flush_is_last(disp_drv))
  106. luat_lcd_flush(lcd_conf);
  107. }
  108. /*IMPORTANT!!!
  109. *Inform the graphics library that you are ready with the flushing*/
  110. lv_disp_flush_ready(disp_drv);
  111. }
  112. /*OPTIONAL: GPU INTERFACE*/
  113. /*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
  114. //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
  115. // const lv_area_t * fill_area, lv_color_t color)
  116. //{
  117. // /*It's an example code which should be done by your GPU*/
  118. // int32_t x, y;
  119. // dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
  120. //
  121. // for(y = fill_area->y1; y <= fill_area->y2; y++) {
  122. // for(x = fill_area->x1; x <= fill_area->x2; x++) {
  123. // dest_buf[x] = color;
  124. // }
  125. // dest_buf+=dest_width; /*Go to the next line*/
  126. // }
  127. //}
  128. #else /*Enable this file at the top*/
  129. /*This dummy typedef exists purely to silence -Wpedantic.*/
  130. typedef int keep_pedantic_happy;
  131. #endif