1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_hal/lv_hal_disp.h

287 lines
8.5 KiB
C
Raw Normal View History

/**
2019-02-10 11:06:47 +01:00
* @file lv_hal_disp.h
*
* @description Display Driver HAL interface header file
*
*/
2019-02-10 11:06:47 +01:00
#ifndef LV_HAL_DISP_H
#define LV_HAL_DISP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stdbool.h>
#include "lv_hal.h"
2017-11-23 20:42:14 +01:00
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
2019-02-10 11:06:47 +01:00
#include "../lv_misc/lv_ll.h"
#include "../lv_misc/lv_task.h"
/*********************
* DEFINES
*********************/
#ifndef LV_INV_BUF_SIZE
2019-04-04 07:15:40 +02:00
#define LV_INV_BUF_SIZE 32 /*Buffer size for invalid areas */
#endif
2019-02-20 23:58:13 +01:00
#ifndef LV_ATTRIBUTE_FLUSH_READY
2019-04-04 07:15:40 +02:00
#define LV_ATTRIBUTE_FLUSH_READY
2019-02-20 23:58:13 +01:00
#endif
/**********************
* TYPEDEFS
**********************/
2019-02-12 16:20:59 +01:00
struct _disp_t;
struct _disp_drv_t;
2019-02-12 16:20:59 +01:00
2019-02-13 01:40:22 +01:00
typedef struct
{
void * buf1;
void * buf2;
2019-02-20 10:16:33 +01:00
/*Used by the library*/
void * buf_act;
2019-04-04 07:15:40 +02:00
uint32_t size; /*In pixel count*/
2019-02-13 01:40:22 +01:00
lv_area_t area;
2019-04-04 07:15:40 +02:00
volatile uint32_t flushing : 1;
} lv_disp_buf_t;
2019-02-13 01:40:22 +01:00
/**
* Display Driver structure to be registered by HAL
*/
2019-04-04 07:15:40 +02:00
typedef struct _disp_drv_t
{
2019-02-20 23:58:13 +01:00
/*Horizontal and vertical resolution*/
2019-02-02 04:46:19 +01:00
lv_coord_t hor_res;
lv_coord_t ver_res;
2019-02-20 23:58:13 +01:00
/* Pointer to a buffer initialized with `lv_disp_buf_init()`.
* LittlevGL will use this buffer(s) to draw the screens contents */
2019-02-20 10:16:33 +01:00
lv_disp_buf_t * buffer;
2019-02-13 01:40:22 +01:00
#if LV_ANTIALIAS
2019-04-04 07:15:40 +02:00
uint32_t antialiasing : 1;
#endif
2019-04-04 07:15:40 +02:00
uint32_t rotated : 1; /*1: turn the display by 90 degree.*/
2019-06-25 15:14:47 +02:00
#if LV_COLOR_SCREEN_TRANSP
/**Handle if the the screen doesn't have a solid (opa == LV_OPA_COVER) background.
* Use only if required because it's slower.*/
uint32_t screen_transp : 1;
#endif
2019-04-04 07:15:40 +02:00
/* MANDATORY: Write the internal buffer (VDB) to the display. 'lv_disp_flush_ready()' has to be
* called when finished */
void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
2019-02-20 23:58:13 +01:00
/* OPTIONAL: Extend the invalidated areas to match with the display drivers requirements
* E.g. round `y` to, 8, 16 ..) on a monochrome display*/
void (*rounder_cb)(struct _disp_drv_t * disp_drv, lv_area_t * area);
2019-02-20 23:58:13 +01:00
/* OPTIONAL: Set a pixel in a buffer according to the special requirements of the display
* Can be used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales
* Note: Much slower then drawing with supported color formats. */
2019-06-06 06:05:40 +02:00
void (*set_px_cb)(struct _disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
lv_color_t color, lv_opa_t opa);
2017-11-29 10:46:59 +01:00
2019-04-04 07:15:40 +02:00
/* OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the
* number of flushed pixels */
void (*monitor_cb)(struct _disp_drv_t * disp_drv, uint32_t time, uint32_t px);
2019-02-25 07:06:05 +01:00
2019-04-05 06:55:35 +02:00
#if LV_USE_GPU
/*OPTIONAL: Blend two memories using opacity (GPU only)*/
void (*gpu_blend_cb)(struct _disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length,
2019-06-06 06:05:40 +02:00
lv_opa_t opa);
2019-04-05 06:55:35 +02:00
/*OPTIONAL: Fill a memory with a color (GPU only)*/
void (*gpu_fill_cb)(struct _disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
2019-04-10 06:21:54 +02:00
const lv_area_t * fill_area, lv_color_t color);
2019-04-05 06:55:35 +02:00
#endif
/*On CHROMA_KEYED images this color will be transparent.
* `LV_COLOR_TRANSP` by default. (lv_conf.h)*/
lv_color_t color_chroma_key;
#if LV_USE_USER_DATA
2019-02-25 07:06:05 +01:00
lv_disp_drv_user_data_t user_data;
#endif
} lv_disp_drv_t;
2019-02-10 11:06:47 +01:00
struct _lv_obj_t;
2019-04-04 07:15:40 +02:00
typedef struct _disp_t
{
2019-02-21 00:21:59 +01:00
/*Driver to the display*/
lv_disp_drv_t driver;
2019-02-21 00:21:59 +01:00
/*A task which periodically checks the dirty areas and refreshes them*/
lv_task_t * refr_task;
2019-02-21 00:21:59 +01:00
/*Screens of the display*/
2019-02-02 04:46:19 +01:00
lv_ll_t scr_ll;
2019-02-10 11:06:47 +01:00
struct _lv_obj_t * act_scr;
struct _lv_obj_t * top_layer;
2019-02-12 12:21:34 +01:00
struct _lv_obj_t * sys_layer;
2019-02-21 00:21:59 +01:00
/*Invalidated (marked to redraw) areas*/
2019-02-12 16:20:59 +01:00
lv_area_t inv_areas[LV_INV_BUF_SIZE];
uint8_t inv_area_joined[LV_INV_BUF_SIZE];
2019-04-04 07:15:40 +02:00
uint32_t inv_p : 10;
/*Miscellaneous data*/
uint32_t last_activity_time;
} lv_disp_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a display driver with default values.
* It is used to surly have known values in the fields ant not memory junk.
* After it you can set the fields.
* @param driver pointer to driver variable to initialize
*/
2019-02-20 23:58:13 +01:00
void lv_disp_drv_init(lv_disp_drv_t * driver);
/**
2019-02-20 10:16:33 +01:00
* Initialize a display buffer
* @param disp_buf pointer `lv_disp_buf_t` variable to initialize
* @param buf1 A buffer to be used by LittlevGL to draw the image.
* Always has to specified and can't be NULL.
* Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]`
* Or a memory address e.g. in external SRAM
* @param buf2 Optionally specify a second buffer to make image rendering and image flushing
* (sending to the display) parallel.
* In the `disp_drv->flush` you should use DMA or similar hardware to send
* the image to the display in the background.
2019-04-04 07:15:40 +02:00
* It lets LittlevGL to render next frame into the other buffer while previous is being
* sent. Set to `NULL` if unused.
2019-04-11 05:16:31 +02:00
* @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count.
*/
2019-04-11 05:16:31 +02:00
void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt);
2019-02-20 23:58:13 +01:00
/**
* Register an initialized display driver.
* Automatically set the first display as active.
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
* @return pointer to the new display or NULL on error
*/
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver);
2019-02-20 10:16:33 +01:00
/**
* Update the driver in run time.
* @param disp pointer to a display. (return value of `lv_disp_drv_register`)
* @param new_drv pointer to the new driver
*/
void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv);
2019-03-08 06:57:16 +01:00
/**
* Remove a display
* @param disp pointer to display
*/
void lv_disp_remove(lv_disp_t * disp);
2019-02-20 23:58:13 +01:00
/**
* Set a default screen. The new screens will be created on it by default.
* @param disp pointer to a display
*/
2019-02-20 10:16:33 +01:00
void lv_disp_set_default(lv_disp_t * disp);
2019-02-20 23:58:13 +01:00
/**
* Get the default display
* @return pointer to the default display
*/
2019-02-20 10:16:33 +01:00
lv_disp_t * lv_disp_get_default(void);
2019-02-20 23:58:13 +01:00
/**
* Get the horizontal resolution of a display
* @param disp pointer to a display (NULL to use the default display)
* @return the horizontal resolution of the display
*/
lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp);
/**
* Get the vertical resolution of a display
* @param disp pointer to a display (NULL to use the default display)
* @return the vertical resolution of the display
*/
lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp);
/**
* Get if anti-aliasing is enabled for a display or not
* @param disp pointer to a display (NULL to use the default display)
* @return true: anti-aliasing is enabled; false: disabled
*/
bool lv_disp_get_antialiasing(lv_disp_t * disp);
2019-06-25 15:14:47 +02:00
//! @cond Doxygen_Suppress
2019-02-20 23:58:13 +01:00
/**
* Call in the display driver's `flush_cb` function when the flushing is finished
* @param disp_drv pointer to display driver in `flush_cb` where this function is called
2019-02-20 23:58:13 +01:00
*/
LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv);
2019-02-20 23:58:13 +01:00
2019-06-25 15:14:47 +02:00
//! @endcond
/**
2017-10-20 22:41:10 +02:00
* Get the next display.
* @param disp pointer to the current display. NULL to initialize.
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
*/
2019-02-12 12:21:34 +01:00
lv_disp_t * lv_disp_get_next(lv_disp_t * disp);
2017-10-20 22:41:10 +02:00
2019-02-20 23:58:13 +01:00
/**
* Get the internal buffer of a display
* @param disp pointer to a display
* @return pointer to the internal buffers
*/
lv_disp_buf_t * lv_disp_get_buf(lv_disp_t * disp);
/**
* Get the number of areas in the buffer
* @return number of invalid areas
*/
uint16_t lv_disp_get_inv_buf_size(lv_disp_t * disp);
2019-02-20 23:58:13 +01:00
/**
* Pop (delete) the last 'num' invalidated areas from the buffer
* @param num number of areas to delete
*/
void lv_disp_pop_from_inv_buf(lv_disp_t * disp, uint16_t num);
/**
* Check the driver configuration if it's double buffered (both `buf1` and `buf2` are set)
* @param disp pointer to to display to check
* @return true: double buffered; false: not double buffered
*/
bool lv_disp_is_double_buf(lv_disp_t * disp);
2019-02-20 23:58:13 +01:00
/**
2019-04-04 07:15:40 +02:00
* Check the driver configuration if it's TRUE double buffered (both `buf1` and `buf2` are set and
* `size` is screen sized)
2019-02-20 23:58:13 +01:00
* @param disp pointer to to display to check
* @return true: double buffered; false: not double buffered
*/
bool lv_disp_is_true_double_buf(lv_disp_t * disp);
2019-02-13 01:40:22 +01:00
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif