mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
186 lines
5.3 KiB
C
186 lines
5.3 KiB
C
/**
|
|
* @file lv_port_disp_templ.c
|
|
*
|
|
*/
|
|
|
|
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
|
|
#if 0
|
|
|
|
/*********************
|
|
* INCLUDES
|
|
*********************/
|
|
#include "lv_port_disp_templ.h"
|
|
|
|
/*********************
|
|
* DEFINES
|
|
*********************/
|
|
|
|
/**********************
|
|
* TYPEDEFS
|
|
**********************/
|
|
|
|
/**********************
|
|
* STATIC PROTOTYPES
|
|
**********************/
|
|
static void disp_init(void);
|
|
|
|
static void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
|
static void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
|
static void disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
|
|
#if USE_LV_GPU
|
|
static void mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
|
|
static void mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
|
|
#endif
|
|
|
|
/**********************
|
|
* STATIC VARIABLES
|
|
**********************/
|
|
|
|
/**********************
|
|
* MACROS
|
|
**********************/
|
|
|
|
/**********************
|
|
* GLOBAL FUNCTIONS
|
|
**********************/
|
|
|
|
void lv_port_disp_init(void)
|
|
{
|
|
/*-------------------------
|
|
* Initialize your display
|
|
* -----------------------*/
|
|
disp_init();
|
|
|
|
/*-----------------------------------
|
|
* Register the display in LittlevGL
|
|
*----------------------------------*/
|
|
|
|
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*/
|
|
|
|
/*Used in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
|
|
disp_drv.disp_flush = disp_flush;
|
|
|
|
/*Used in unbuffered mode (LV_VDB_SIZE == 0 in lv_conf.h)*/
|
|
disp_drv.disp_fill = disp_fill;
|
|
|
|
/*Used in unbuffered mode (LV_VDB_SIZE == 0 in lv_conf.h)*/
|
|
disp_drv.disp_map = disp_map;
|
|
|
|
#if USE_LV_GPU
|
|
/*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/
|
|
|
|
/*Blend two color array using opacity*/
|
|
disp_drv.mem_blend = mem_blend;
|
|
|
|
/*Fill a memory array with a color*/
|
|
disp_drv.mem_fill = mem_fill;
|
|
#endif
|
|
|
|
/*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*/
|
|
}
|
|
|
|
/* 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_flush_ready()' has to be called when finished
|
|
* This function is required only when LV_VDB_SIZE != 0 in lv_conf.h*/
|
|
static void disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
|
|
{
|
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
|
|
|
int32_t x;
|
|
int32_t y;
|
|
for(y = y1; y <= y2; y++) {
|
|
for(x = x1; x <= x2; x++) {
|
|
/* Put a pixel to the display. For example: */
|
|
/* put_px(x, y, *color_p)*/
|
|
color_p++;
|
|
}
|
|
}
|
|
|
|
/* IMPORTANT!!!
|
|
* Inform the graphics library that you are ready with the flushing*/
|
|
lv_flush_ready();
|
|
}
|
|
|
|
|
|
/* Write a pixel array (called 'map') to the a specific area on the display
|
|
* This function is required only when LV_VDB_SIZE == 0 in lv_conf.h*/
|
|
static void disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
|
|
{
|
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
|
|
|
int32_t x;
|
|
int32_t y;
|
|
for(y = y1; y <= y2; y++) {
|
|
for(x = x1; x <= x2; x++) {
|
|
/* Put a pixel to the display. For example: */
|
|
/* put_px(x, y, *color_p)*/
|
|
color_p++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* Write a pixel array (called 'map') to the a specific area on the display
|
|
* This function is required only when LV_VDB_SIZE == 0 in lv_conf.h*/
|
|
static void disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
|
|
{
|
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
|
|
|
int32_t x;
|
|
int32_t y;
|
|
for(y = y1; y <= y2; y++) {
|
|
for(x = x1; x <= x2; x++) {
|
|
/* Put a pixel to the display. For example: */
|
|
/* put_px(x, y, *color)*/
|
|
}
|
|
}
|
|
|
|
(void)color; /*Just to avid warnings*/
|
|
}
|
|
|
|
/*OPTIONAL: GPU INTERFACE*/
|
|
#if USE_LV_GPU
|
|
|
|
/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
|
|
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
|
|
static void mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
|
|
{
|
|
/*It's an example code which should be done by your GPU*/
|
|
|
|
uint32_t i;
|
|
for(i = 0; i < length; i++) {
|
|
dest[i] = lv_color_mix(dest[i], src[i], opa);
|
|
}
|
|
}
|
|
|
|
/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color
|
|
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
|
|
static void mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
|
|
{
|
|
/*It's an example code which should be done by your GPU*/
|
|
|
|
uint32_t i;
|
|
for(i = 0; i < length; i++) {
|
|
dest[i] = color;
|
|
}
|
|
}
|
|
|
|
#endif /*USE_LV_GPU*/
|
|
|
|
#endif
|