/** * @file lv_port_disp_templ.c * */ /********************* * INCLUDES *********************/ #include "lv_port_disp_cntrl.h" #include #include #include // display header file need to add here /********************* * DEFINES *********************/ #define TICK_MS_TIME 5 #define MY_DISP_HOR_RES 800 // 800 #define MY_DISP_VER_RES 480 //480 #define COLOR_BUFFER (MY_DISP_HOR_RES * MY_DISP_VER_RES) /********************** * 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 **********************/ //DISPLAY DRIVER static lv_disp_drv_t disp_drv; //DRAW BUFFER static lv_disp_draw_buf_t disp_buf; static lv_color_t buf_1[COLOR_BUFFER]; /* const display_status_t* displayStatus; uint8_t * frameBuffer; */ /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ void lv_port_disp_init(void) { /*------------------------- * Initialize your display * -----------------------*/ //START LVGL disp_init(); /*----------------------------- * Create a buffer for drawing *----------------------------*/ /** * LVGL requires a buffer where it internally draws the widgets. * Later this buffer will passed to your display driver's `flush_cb` to copy its content to your display. * The buffer has to be greater than 1 display row * * There are 3 buffering configurations: * 1. Create ONE buffer: * LVGL will draw the display's content here and writes it to your display * * 2. Create TWO buffer: * LVGL will draw the display's content to a buffer and writes it your display. * You should use DMA to write the buffer's content to the display. * It will enable LVGL to draw the next part of the screen to the other buffer while * the data is being sent form the first buffer. It makes rendering and flushing parallel. * * 3. Double buffering * Set 2 screens sized buffers and set disp_drv.full_refresh = 1. * This way LVGL will always provide the whole rendered screen in `flush_cb` * and you only need to change the frame buffer's address. */ /* Example for 1) */ //INIT DRAW BUFFER lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, COLOR_BUFFER); /*Initialize the display buffer*/ #if 0 /* Example for 2) */ static lv_disp_draw_buf_t draw_buf_dsc_2; static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/ static lv_color_t buf_2_2[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/ lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ /* Example for 3) also set disp_drv.full_refresh = 1 below*/ static lv_disp_draw_buf_t draw_buf_dsc_3; static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/ static lv_color_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*Another screen sized buffer*/ lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX); /*Initialize the display buffer*/ #endif /*----------------------------------- * Register the display in LVGL *----------------------------------*/ //INIT DISPLAY DRIVER lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*Set the resolution of the display*/ disp_drv.hor_res = MY_DISP_HOR_RES; disp_drv.ver_res = MY_DISP_VER_RES; /*Set a display buffer*/ disp_drv.draw_buf = &disp_buf; /*Used to copy the buffer's content to the display*/ disp_drv.flush_cb = disp_flush; /*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; /*Finally register the driver*/ lv_disp_drv_register(&disp_drv); while (1) { lv_timer_handler(); vTaskDelay (pdMS_TO_TICKS(TICK_MS_TIME)); } } void g_timer_lvgl_callback(TimerHandle_t xTimer) { lv_tick_inc(TICK_MS_TIME); } /********************** * STATIC FUNCTIONS **********************/ /*Initialize your display and the required peripherals.*/ static void disp_init(void) { /* display init call 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) { #ifdef PKG_USING_ILI9341 lcd_fill_array_spi(area->x1, area->y1, area->x2, area->y2, color_p); #elif LV_USE_GPU_RA6M3_G2D lv_port_gpu_blit(area->x1, area->y1, color_p, area); #else ...... #endif /*IMPORTANT!!! *Inform the graphics library that you are ready with the flushing*/ lv_disp_flush_ready(disp_drv); }