2018-12-31 18:19:38 +01:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*********************/
|
2020-02-13 06:31:37 +01:00
|
|
|
#include "lv_port_disp_template.h"
|
2018-12-31 18:19:38 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
static void disp_init(void);
|
|
|
|
|
2019-03-23 01:19:57 +01:00
|
|
|
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GPU
|
2020-02-13 06:31:37 +01:00
|
|
|
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
|
|
|
|
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);
|
2018-12-31 18:19:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
void lv_port_disp_init(void)
|
|
|
|
{
|
|
|
|
/*-------------------------
|
|
|
|
* Initialize your display
|
|
|
|
* -----------------------*/
|
|
|
|
disp_init();
|
|
|
|
|
2019-02-20 23:58:13 +01:00
|
|
|
/*-----------------------------
|
|
|
|
* Create a buffer for drawing
|
|
|
|
*----------------------------*/
|
|
|
|
|
2019-03-04 16:56:02 +01:00
|
|
|
/* LittlevGL requires a buffer where it draws the objects. The buffer's has to be greater than 1 display row
|
2019-02-20 23:58:13 +01:00
|
|
|
*
|
|
|
|
* There are three buffering configurations:
|
2019-03-04 16:55:29 +01:00
|
|
|
* 1. Create ONE buffer with some rows:
|
|
|
|
* LittlevGL will draw the display's content here and writes it to your display
|
|
|
|
*
|
|
|
|
* 2. Create TWO buffer with some rows:
|
|
|
|
* LittlevGL 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 LittlevGL 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. Create TWO screen-sized buffer:
|
|
|
|
* Similar to 2) but the buffer have to be screen sized. When LittlevGL is ready it will give the
|
|
|
|
* whole frame to display. This way you only need to change the frame buffer's address instead of
|
|
|
|
* copying the pixels.
|
2019-02-20 23:58:13 +01:00
|
|
|
* */
|
|
|
|
|
|
|
|
/* Example for 1) */
|
|
|
|
static lv_disp_buf_t disp_buf_1;
|
|
|
|
static lv_color_t buf1_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/
|
|
|
|
lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
|
|
|
|
|
|
|
|
/* Example for 2) */
|
|
|
|
static lv_disp_buf_t disp_buf_2;
|
|
|
|
static lv_color_t buf2_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/
|
|
|
|
static lv_color_t buf2_2[LV_HOR_RES_MAX * 10]; /*An other buffer for 10 rows*/
|
|
|
|
lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/
|
|
|
|
|
|
|
|
/* Example for 3) */
|
|
|
|
static lv_disp_buf_t disp_buf_3;
|
|
|
|
static lv_color_t buf3_1[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*A screen sized buffer*/
|
|
|
|
static lv_color_t buf3_2[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*An other screen sized buffer*/
|
|
|
|
lv_disp_buf_init(&disp_buf_3, buf3_1, buf3_2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/
|
|
|
|
|
|
|
|
|
2018-12-31 18:19:38 +01:00
|
|
|
/*-----------------------------------
|
|
|
|
* 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*/
|
|
|
|
|
2019-02-22 14:22:11 +01:00
|
|
|
/*Set the resolution of the display*/
|
|
|
|
disp_drv.hor_res = 480;
|
|
|
|
disp_drv.ver_res = 320;
|
|
|
|
|
2019-02-20 23:58:13 +01:00
|
|
|
/*Used to copy the buffer's content to the display*/
|
|
|
|
disp_drv.flush_cb = disp_flush;
|
2018-12-31 18:19:38 +01:00
|
|
|
|
2019-02-21 00:50:14 +01:00
|
|
|
/*Set a display buffer*/
|
|
|
|
disp_drv.buffer = &disp_buf_2;
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GPU
|
2018-12-31 18:19:38 +01:00
|
|
|
/*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/
|
|
|
|
|
|
|
|
/*Blend two color array using opacity*/
|
2020-02-13 06:31:37 +01:00
|
|
|
disp_drv.gpu_blend_cb = gpu_blend;
|
2018-12-31 18:19:38 +01:00
|
|
|
|
|
|
|
/*Fill a memory array with a color*/
|
2020-02-13 06:31:37 +01:00
|
|
|
disp_drv.gpu_fill_cb = gpu_fill;
|
2018-12-31 18:19:38 +01:00
|
|
|
#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
|
2019-02-20 23:58:13 +01:00
|
|
|
* 'lv_disp_flush_ready()' has to be called when finished. */
|
2019-03-23 01:19:57 +01:00
|
|
|
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
|
2018-12-31 18:19:38 +01:00
|
|
|
{
|
|
|
|
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
|
|
|
|
|
|
|
|
int32_t x;
|
|
|
|
int32_t y;
|
2019-02-20 23:58:13 +01:00
|
|
|
for(y = area->y1; y <= area->y2; y++) {
|
|
|
|
for(x = area->x1; x <= area->x2; x++) {
|
2018-12-31 18:19:38 +01:00
|
|
|
/* 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*/
|
2020-02-13 06:31:37 +01:00
|
|
|
lv_disp_flush_ready(disp_drv);
|
2018-12-31 18:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*OPTIONAL: GPU INTERFACE*/
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_GPU
|
2018-12-31 18:19:38 +01:00
|
|
|
|
|
|
|
/* 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)*/
|
2019-06-25 17:57:42 +02:00
|
|
|
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
|
2018-12-31 18:19:38 +01:00
|
|
|
{
|
|
|
|
/*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)*/
|
2020-02-13 06:31:37 +01:00
|
|
|
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)
|
2018-12-31 18:19:38 +01:00
|
|
|
{
|
|
|
|
/*It's an example code which should be done by your GPU*/
|
2020-02-13 06:31:37 +01:00
|
|
|
int32_t x, y;
|
2019-06-24 13:50:13 -04:00
|
|
|
dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
|
2019-06-13 19:25:23 +02:00
|
|
|
|
|
|
|
for(y = fill_area->y1; y < fill_area->y2; y++) {
|
|
|
|
for(x = fill_area->x1; x < fill_area->x2; x++) {
|
|
|
|
dest_buf[x] = color;
|
|
|
|
}
|
2019-06-24 13:50:13 -04:00
|
|
|
dest_buf+=dest_width; /*Go to the next line*/
|
2019-06-13 19:25:23 +02:00
|
|
|
}
|
2018-12-31 18:19:38 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#endif /*LV_USE_GPU*/
|
2018-12-31 18:19:38 +01:00
|
|
|
|
2019-03-15 19:41:54 -04:00
|
|
|
#else /* Enable this file at the top */
|
|
|
|
|
|
|
|
/* This dummy typedef exists purely to silence -Wpedantic. */
|
|
|
|
typedef int keep_pedantic_happy;
|
2018-12-31 18:19:38 +01:00
|
|
|
#endif
|