| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- /**
- * @file lv_port_disp_templ.c
- *
- */
- /*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
- #if 1
- /*********************
- * INCLUDES
- *********************/
- #include "lv_port_disp.h"
- #include <stdbool.h>
- #include "luat_mem.h"
- #define LUAT_LOG_TAG "lvgl"
- #include "luat_log.h"
- /*********************
- * DEFINES
- *********************/
- /**********************
- * TYPEDEFS
- **********************/
- /**********************
- * STATIC PROTOTYPES
- **********************/
- static void disp_init(void);
- static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
- /**********************
- * STATIC VARIABLES
- **********************/
- /**********************
- * MACROS
- **********************/
- /**********************
- * GLOBAL FUNCTIONS
- **********************/
- void lv_port_disp_init(luat_lcd_conf_t* lcd_conf)
- {
- /*-------------------------
- * Initialize your display
- * -----------------------*/
- disp_init();
- /*-----------------------------
- * Create a buffer for drawing
- *----------------------------*/
- static lv_disp_draw_buf_t lv_disp_draw_buf;
- lv_color_t* buf_2_1 = NULL;
- lv_color_t* buf_2_2 = NULL;
- #define SIZE_IN_PX_CNT (lcd_conf->w * 10)
- #define DRAW_BUFFER_SIZE SIZE_IN_PX_CNT * sizeof(lv_color_t)
- buf_2_1 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
- buf_2_2 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
- lv_disp_draw_buf_init(&lv_disp_draw_buf, buf_2_1, buf_2_2, SIZE_IN_PX_CNT);
- // lv_disp_draw_buf_init(&lv_disp_draw_buf, lcd_conf->buff, lcd_conf->buff1, lcd_conf->w * lcd_conf->h);
- /*-----------------------------------
- * Register the display in LVGL
- *----------------------------------*/
- static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
- lv_disp_drv_init(&disp_drv); /*Basic initialization*/
- /*Set up the functions to access to your display*/
- /*Set the resolution of the display*/
- disp_drv.hor_res = lcd_conf->w;
- disp_drv.ver_res = lcd_conf->h;
- /*Used to copy the buffer's content to the display*/
- disp_drv.flush_cb = disp_flush;
- /*Set a display buffer*/
- disp_drv.draw_buf = &lv_disp_draw_buf;
- /*Required for Example 3)*/
- //disp_drv.full_refresh = 1;
- /* Fill a memory array with a color if you have GPU.
- * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
- * But if you have a different GPU you can use with this callback.*/
- //disp_drv.gpu_fill_cb = gpu_fill;
- disp_drv.user_data = lcd_conf;
- /*Finally register the driver*/
- lv_disp_drv_register(&disp_drv);
- }
- /**********************
- * STATIC FUNCTIONS
- **********************/
- /*Initialize your display and the required peripherals.*/
- static void disp_init(void)
- {
- /*You code here*/
- }
- volatile bool disp_flush_enabled = true;
- /* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
- */
- void disp_enable_update(void)
- {
- disp_flush_enabled = true;
- }
- /* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
- */
- void disp_disable_update(void)
- {
- disp_flush_enabled = false;
- }
- /*Flush the content of the internal buffer the specific area on the display
- *You can use DMA or any hardware acceleration to do this operation in the background but
- *'lv_disp_flush_ready()' has to be called when finished.*/
- static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
- {
- if(disp_flush_enabled) {
- luat_lcd_conf_t* lcd_conf = disp_drv->user_data;
- luat_lcd_draw(lcd_conf, area->x1, area->y1, area->x2, area->y2, color_p);
- if (lv_disp_flush_is_last(disp_drv))
- luat_lcd_flush(lcd_conf);
- }
- /*IMPORTANT!!!
- *Inform the graphics library that you are ready with the flushing*/
- lv_disp_flush_ready(disp_drv);
- }
- /*OPTIONAL: GPU INTERFACE*/
- /*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
- //static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
- // const lv_area_t * fill_area, lv_color_t color)
- //{
- // /*It's an example code which should be done by your GPU*/
- // int32_t x, y;
- // dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
- //
- // for(y = fill_area->y1; y <= fill_area->y2; y++) {
- // for(x = fill_area->x1; x <= fill_area->x2; x++) {
- // dest_buf[x] = color;
- // }
- // dest_buf+=dest_width; /*Go to the next line*/
- // }
- //}
- #else /*Enable this file at the top*/
- /*This dummy typedef exists purely to silence -Wpedantic.*/
- typedef int keep_pedantic_happy;
- #endif
|