CARPLAY版本整理

This commit is contained in:
2025-01-21 16:49:37 +08:00
commit f0fb64e4e6
26542 changed files with 13719676 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/**
* @file lv_hal.h
*
*/
#ifndef LV_HAL_H
#define LV_HAL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_hal_disp.h"
#include "lv_hal_indev.h"
#include "lv_hal_tick.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -0,0 +1,474 @@
/**
* @file hal_disp.c
*
* @description HAL layer for display driver
*
*/
/*********************
* INCLUDES
*********************/
#include <stdint.h>
#include <stddef.h>
#include "lv_hal.h"
#include "../lv_misc/lv_mem.h"
#include "../lv_misc/lv_gc.h"
#include "../lv_misc/lv_debug.h"
#include "../lv_core/lv_obj.h"
#include "../lv_core/lv_refr.h"
#include "../lv_themes/lv_theme.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_disp_t * disp_def;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* 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
*/
void lv_disp_drv_init(lv_disp_drv_t * driver)
{
_lv_memset_00(driver, sizeof(lv_disp_drv_t));
driver->flush_cb = NULL;
driver->hor_res = LV_HOR_RES_MAX;
driver->ver_res = LV_VER_RES_MAX;
driver->buffer = NULL;
driver->rotated = LV_DISP_ROT_NONE;
driver->sw_rotate = 0;
driver->color_chroma_key = LV_COLOR_TRANSP;
driver->dpi = LV_DPI;
#if LV_ANTIALIAS
driver->antialiasing = true;
#endif
#if LV_COLOR_SCREEN_TRANSP
driver->screen_transp = 1;
#endif
#if LV_USE_GPU
driver->gpu_blend_cb = NULL;
driver->gpu_fill_cb = NULL;
#endif
#if LV_USE_USER_DATA
driver->user_data = NULL;
#endif
driver->set_px_cb = NULL;
}
/**
* Initialize a display buffer
* @param disp_buf pointer `lv_disp_buf_t` variable to initialize
* @param buf1 A buffer to be used by LVGL 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.
* It lets LVGL to render next frame into the other buffer while previous is being
* sent. Set to `NULL` if unused.
* @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count.
*/
void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt)
{
_lv_memset_00(disp_buf, sizeof(lv_disp_buf_t));
disp_buf->buf1 = buf1;
disp_buf->buf2 = buf2;
disp_buf->buf_act = disp_buf->buf1;
disp_buf->size = size_in_px_cnt;
}
/**
* 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)
{
lv_disp_t * disp = _lv_ll_ins_head(&LV_GC_ROOT(_lv_disp_ll));
if(!disp) {
LV_ASSERT_MEM(disp);
return NULL;
}
_lv_memset_00(disp, sizeof(lv_disp_t));
_lv_memcpy(&disp->driver, driver, sizeof(lv_disp_drv_t));
_lv_ll_init(&disp->scr_ll, sizeof(lv_obj_t));
disp->last_activity_time = 0;
if(disp_def == NULL) disp_def = disp;
lv_disp_t * disp_def_tmp = disp_def;
disp_def = disp; /*Temporarily change the default screen to create the default screens on the
new display*/
/*Create a refresh task*/
disp->refr_task = lv_task_create(_lv_disp_refr_task, LV_DISP_DEF_REFR_PERIOD, LV_REFR_TASK_PRIO, disp);
LV_ASSERT_MEM(disp->refr_task);
if(disp->refr_task == NULL) return NULL;
disp->inv_p = 0;
disp->last_activity_time = 0;
disp->bg_color = LV_COLOR_WHITE;
disp->bg_img = NULL;
#if LV_COLOR_SCREEN_TRANSP
disp->bg_opa = LV_OPA_TRANSP;
#else
disp->bg_opa = LV_OPA_COVER;
#endif
disp->prev_scr = NULL;
disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/
disp->top_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/
disp->sys_layer = lv_obj_create(NULL, NULL); /*Create sys layer on the display*/
lv_obj_reset_style_list(disp->top_layer, LV_OBJ_PART_MAIN);
lv_obj_reset_style_list(disp->sys_layer, LV_OBJ_PART_MAIN);
lv_obj_set_click(disp->top_layer, false);
lv_obj_set_click(disp->sys_layer, false);
lv_obj_invalidate(disp->act_scr);
disp_def = disp_def_tmp; /*Revert the default display*/
lv_task_ready(disp->refr_task); /*Be sure the screen will be refreshed immediately on start up*/
/*Can't handle this case later so add an error*/
if(lv_disp_is_true_double_buf(disp) && disp->driver.set_px_cb) {
LV_LOG_ERROR("Can't handle 2 screen sized buffers with set_px_cb. Display will not be refreshed.");
}
return disp;
}
/**
* 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)
{
if(new_drv != &disp->driver)
memcpy(&disp->driver, new_drv, sizeof(lv_disp_drv_t));
lv_obj_t * scr;
_LV_LL_READ(disp->scr_ll, scr) {
lv_obj_set_size(scr, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp));
}
/*
* This method is usually called upon orientation change, thus the screen is now a
* different size.
* The object invalidated its previous area. That area is now out of the screen area
* so we reset all invalidated areas and invalidate the active screen's new area only.
*/
_lv_memset_00(disp->inv_areas, sizeof(disp->inv_areas));
_lv_memset_00(disp->inv_area_joined, sizeof(disp->inv_area_joined));
disp->inv_p = 0;
if(disp->act_scr != NULL)
lv_obj_invalidate(disp->act_scr);
}
/**
* Remove a display
* @param disp pointer to display
*/
void lv_disp_remove(lv_disp_t * disp)
{
bool was_default = false;
if(disp == lv_disp_get_default()) was_default = true;
/*Detach the input devices */
lv_indev_t * indev;
indev = lv_indev_get_next(NULL);
while(indev) {
if(indev->driver.disp == disp) {
indev->driver.disp = NULL;
}
indev = lv_indev_get_next(indev);
}
_lv_ll_remove(&LV_GC_ROOT(_lv_disp_ll), disp);
lv_mem_free(disp);
if(was_default) lv_disp_set_default(_lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll)));
}
/**
* Set a default screen. The new screens will be created on it by default.
* @param disp pointer to a display
*/
void lv_disp_set_default(lv_disp_t * disp)
{
disp_def = disp;
}
/**
* Get the default display
* @return pointer to the default display
*/
lv_disp_t * lv_disp_get_default(void)
{
return disp_def;
}
/**
* 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)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL)
return LV_HOR_RES_MAX;
else {
switch(disp->driver.rotated) {
case LV_DISP_ROT_90:
case LV_DISP_ROT_270:
return disp->driver.ver_res;
default:
return disp->driver.hor_res;
}
}
}
/**
* 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)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL)
return LV_VER_RES_MAX;
else {
switch(disp->driver.rotated) {
case LV_DISP_ROT_90:
case LV_DISP_ROT_270:
return disp->driver.hor_res;
default:
return disp->driver.ver_res;
}
}
}
/**
* 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)
{
#if LV_ANTIALIAS == 0
LV_UNUSED(disp);
return false;
#else
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return false;
return disp->driver.antialiasing ? true : false;
#endif
}
/**
* Get the DPI of the display
* @param disp pointer to a display (NULL to use the default display)
* @return dpi of the display
*/
lv_coord_t lv_disp_get_dpi(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return LV_DPI; /*Do not return 0 because it might be a divider*/
return disp->driver.dpi;
}
/**
* Get the size category of the display based on it's hor. res. and dpi.
* @param disp pointer to a display (NULL to use the default display)
* @return LV_DISP_SIZE_SMALL/MEDIUM/LARGE/EXTRA_LARGE
*/
lv_disp_size_t lv_disp_get_size_category(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
uint32_t w;
if(disp == NULL) w = LV_HOR_RES_MAX;
else w = lv_disp_get_hor_res(disp);
uint32_t dpi = lv_disp_get_dpi(disp);
w = w * 10 / dpi;
if(w < LV_DISP_SMALL_LIMIT) return LV_DISP_SIZE_SMALL;
if(w < LV_DISP_MEDIUM_LIMIT) return LV_DISP_SIZE_MEDIUM;
if(w < LV_DISP_LARGE_LIMIT) return LV_DISP_SIZE_LARGE;
else return LV_DISP_SIZE_EXTRA_LARGE;
}
/**
* 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
*/
LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv)
{
/*If the screen is transparent initialize it when the flushing is ready*/
#if LV_COLOR_SCREEN_TRANSP
if(disp_drv->screen_transp) {
_lv_memset_00(disp_drv->buffer->buf_act, disp_drv->buffer->size * sizeof(lv_color32_t));
}
#endif
disp_drv->buffer->flushing = 0;
disp_drv->buffer->flushing_last = 0;
}
/**
* Tell if it's the last area of the refreshing process.
* Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed.
* @param disp_drv pointer to display driver
* @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon
*/
LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv)
{
return disp_drv->buffer->flushing_last;
}
/**
* 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
*/
lv_disp_t * lv_disp_get_next(lv_disp_t * disp)
{
if(disp == NULL)
return _lv_ll_get_head(&LV_GC_ROOT(_lv_disp_ll));
else
return _lv_ll_get_next(&LV_GC_ROOT(_lv_disp_ll), disp);
}
/**
* 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)
{
return disp->driver.buffer;
}
/**
* 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)
{
return disp->inv_p;
}
/**
* 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)
{
if(disp->inv_p < num)
disp->inv_p = 0;
else
disp->inv_p -= 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)
{
if(disp->driver.buffer->buf1 && disp->driver.buffer->buf2)
return true;
else
return false;
}
/**
* Check the driver configuration if it's TRUE double buffered (both `buf1` and `buf2` are set and
* `size` is screen sized)
* @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)
{
uint32_t scr_size = disp->driver.hor_res * disp->driver.ver_res;
if(lv_disp_is_double_buf(disp) && disp->driver.buffer->size == scr_size) {
return true;
}
else {
return false;
}
}
/**
* Set the rotation of this display.
* @param disp pointer to a display (NULL to use the default display)
* @param rotation rotation angle
*/
void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation)
{
if(disp == NULL) disp = lv_disp_get_default();
disp->driver.rotated = rotation;
lv_disp_drv_update(disp, &disp->driver);
}
/**
* Get the current rotation of this display.
* @param disp pointer to a display (NULL to use the default display)
* @return rotation angle
*/
lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
return disp->driver.rotated;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -0,0 +1,374 @@
/**
* @file lv_hal_disp.h
*
* @description Display Driver HAL interface header file
*
*/
#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"
#include "../lv_misc/lv_color.h"
#include "../lv_misc/lv_area.h"
#include "../lv_misc/lv_ll.h"
#include "../lv_misc/lv_task.h"
/*********************
* DEFINES
*********************/
#ifndef LV_INV_BUF_SIZE
#define LV_INV_BUF_SIZE 32 /*Buffer size for invalid areas */
#endif
#ifndef LV_ATTRIBUTE_FLUSH_READY
#define LV_ATTRIBUTE_FLUSH_READY
#endif
/**********************
* TYPEDEFS
**********************/
struct _disp_t;
struct _disp_drv_t;
/**
* Structure for holding display buffer information.
*/
typedef struct {
void * buf1; /**< First display buffer. */
void * buf2; /**< Second display buffer. */
/*Internal, used by the library*/
void * buf_act;
uint32_t size; /*In pixel count*/
lv_area_t area;
/*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
volatile int flushing;
/*1: It was the last chunk to flush. (It can't be a bi tfield because when it's cleared from IRQ Read-Modify-Write issue might occur)*/
volatile int flushing_last;
volatile uint32_t last_area : 1; /*1: the last area is being rendered*/
volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/
} lv_disp_buf_t;
typedef enum {
LV_DISP_ROT_NONE = 0,
LV_DISP_ROT_90,
LV_DISP_ROT_180,
LV_DISP_ROT_270
} lv_disp_rot_t;
/**
* Display Driver structure to be registered by HAL
*/
typedef struct _disp_drv_t {
lv_coord_t hor_res; /**< Horizontal resolution. */
lv_coord_t ver_res; /**< Vertical resolution. */
/** Pointer to a buffer initialized with `lv_disp_buf_init()`.
* LVGL will use this buffer(s) to draw the screens contents */
lv_disp_buf_t * buffer;
#if LV_ANTIALIAS
uint32_t antialiasing : 1; /**< 1: antialiasing is enabled on this display. */
#endif
uint32_t rotated : 2;
uint32_t sw_rotate : 1; /**< 1: use software rotation (slower) */
#if LV_COLOR_SCREEN_TRANSP
/**Handle if 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
/** DPI (dot per inch) of the display.
* Set to `LV_DPI` from `lv_Conf.h` by default.
*/
uint32_t dpi : 10;
/** 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);
/** 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);
/** 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. */
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);
/** 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);
/** OPTIONAL: Called periodically while lvgl waits for operation to be completed.
* For example flushing or GPU
* User can execute very simple tasks here or yield the task */
void (*wait_cb)(struct _disp_drv_t * disp_drv);
/** OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned */
void (*clean_dcache_cb)(struct _disp_drv_t * disp_drv);
/** OPTIONAL: called to wait while the gpu is working */
void (*gpu_wait_cb)(struct _disp_drv_t * disp_drv);
#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,
lv_opa_t opa);
/** 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,
const lv_area_t * fill_area, lv_color_t color);
#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
lv_disp_drv_user_data_t user_data; /**< Custom display driver user data */
#endif
} lv_disp_drv_t;
struct _lv_obj_t;
/**
* Display structure.
* @note `lv_disp_drv_t` should be the first member of the structure.
*/
typedef struct _disp_t {
/**< Driver to the display*/
lv_disp_drv_t driver;
/**< A task which periodically checks the dirty areas and refreshes them*/
lv_task_t * refr_task;
/** Screens of the display*/
lv_ll_t scr_ll;
struct _lv_obj_t * act_scr; /**< Currently active screen on this display */
struct _lv_obj_t * prev_scr; /**< Previous screen. Used during screen animations */
#if LV_USE_ANIMATION
struct _lv_obj_t * scr_to_load; /**< The screen prepared to load in lv_scr_load_anim*/
#endif
struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top */
struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys */
uint8_t del_prev :
1; /**< 1: Automatically delete the previous screen when the screen load animation is ready */
lv_color_t bg_color; /**< Default display color when screens are transparent*/
const void * bg_img; /**< An image source to display as wallpaper*/
lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper */
/** Invalidated (marked to redraw) areas*/
lv_area_t inv_areas[LV_INV_BUF_SIZE];
uint8_t inv_area_joined[LV_INV_BUF_SIZE];
uint32_t inv_p : 10;
/*Miscellaneous data*/
uint32_t last_activity_time; /**< Last time there was activity on this display */
} lv_disp_t;
typedef enum {
LV_DISP_SIZE_SMALL,
LV_DISP_SIZE_MEDIUM,
LV_DISP_SIZE_LARGE,
LV_DISP_SIZE_EXTRA_LARGE,
} lv_disp_size_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a display driver with default values.
* It is used to have known values in the fields and not junk in memory.
* After it you can safely set only the fields you need.
* @param driver pointer to driver variable to initialize
*/
void lv_disp_drv_init(lv_disp_drv_t * driver);
/**
* Initialize a display buffer
* @param disp_buf pointer `lv_disp_buf_t` variable to initialize
* @param buf1 A buffer to be used by LVGL 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.
* It lets LVGL to render next frame into the other buffer while previous is being
* sent. Set to `NULL` if unused.
* @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count.
*/
void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt);
/**
* 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);
/**
* 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);
/**
* Remove a display
* @param disp pointer to display
*/
void lv_disp_remove(lv_disp_t * disp);
/**
* Set a default screen. The new screens will be created on it by default.
* @param disp pointer to a display
*/
void lv_disp_set_default(lv_disp_t * disp);
/**
* Get the default display
* @return pointer to the default display
*/
lv_disp_t * lv_disp_get_default(void);
/**
* 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);
/**
* Get the DPI of the display
* @param disp pointer to a display (NULL to use the default display)
* @return dpi of the display
*/
lv_coord_t lv_disp_get_dpi(lv_disp_t * disp);
/**
* Get the size category of the display based on it's hor. res. and dpi.
* @param disp pointer to a display (NULL to use the default display)
* @return LV_DISP_SIZE_SMALL/MEDIUM/LARGE/EXTRA_LARGE
*/
lv_disp_size_t lv_disp_get_size_category(lv_disp_t * disp);
/**
* Set the rotation of this display.
* @param disp pointer to a display (NULL to use the default display)
* @param rotation rotation angle
*/
void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation);
/**
* Get the current rotation of this display.
* @param disp pointer to a display (NULL to use the default display)
* @return rotation angle
*/
lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp);
//! @cond Doxygen_Suppress
/**
* 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
*/
LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv);
/**
* Tell if it's the last area of the refreshing process.
* Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed.
* @param disp_drv pointer to display driver
* @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon
*/
LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv);
//! @endcond
/**
* 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
*/
lv_disp_t * lv_disp_get_next(lv_disp_t * disp);
/**
* 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);
/**
* 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);
/**
* Check the driver configuration if it's TRUE double buffered (both `buf1` and `buf2` are set and
* `size` is screen sized)
* @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);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -0,0 +1,162 @@
/**
* @file hal_indev.c
*
* @description Input device HAL interface
*
*/
/*********************
* INCLUDES
*********************/
#include "../lv_misc/lv_debug.h"
#include "../lv_hal/lv_hal_indev.h"
#include "../lv_core/lv_indev.h"
#include "../lv_misc/lv_mem.h"
#include "../lv_misc/lv_gc.h"
#include "lv_hal_disp.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize an input device 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
*/
void lv_indev_drv_init(lv_indev_drv_t * driver)
{
_lv_memset_00(driver, sizeof(lv_indev_drv_t));
driver->type = LV_INDEV_TYPE_NONE;
driver->drag_limit = LV_INDEV_DEF_DRAG_LIMIT;
driver->drag_throw = LV_INDEV_DEF_DRAG_THROW;
driver->long_press_time = LV_INDEV_DEF_LONG_PRESS_TIME;
driver->long_press_rep_time = LV_INDEV_DEF_LONG_PRESS_REP_TIME;
driver->gesture_limit = LV_INDEV_DEF_GESTURE_LIMIT;
driver->gesture_min_velocity = LV_INDEV_DEF_GESTURE_MIN_VELOCITY;
}
/**
* Register an initialized input device driver.
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
* @return pointer to the new input device or NULL on error
*/
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver)
{
if(driver->disp == NULL) driver->disp = lv_disp_get_default();
if(driver->disp == NULL) {
LV_LOG_WARN("lv_indev_drv_register: no display registered hence can't attach the indev to "
"a display");
return NULL;
}
lv_indev_t * indev = _lv_ll_ins_head(&LV_GC_ROOT(_lv_indev_ll));
if(!indev) {
LV_ASSERT_MEM(indev);
return NULL;
}
_lv_memset_00(indev, sizeof(lv_indev_t));
_lv_memcpy(&indev->driver, driver, sizeof(lv_indev_drv_t));
indev->proc.reset_query = 1;
indev->cursor = NULL;
indev->group = NULL;
indev->btn_points = NULL;
indev->driver.read_task = lv_task_create(_lv_indev_read_task, LV_INDEV_DEF_READ_PERIOD, LV_TASK_PRIO_HIGH, indev);
return indev;
}
/**
* Update the driver in run time.
* @param indev pointer to a input device. (return value of `lv_indev_drv_register`)
* @param new_drv pointer to the new driver
*/
void lv_indev_drv_update(lv_indev_t * indev, lv_indev_drv_t * new_drv)
{
memcpy(&indev->driver, new_drv, sizeof(lv_indev_drv_t));
}
/**
* Get the next input device.
* @param indev pointer to the current input device. NULL to initialize.
* @return the next input devise or NULL if no more. Give the first input device when the parameter
* is NULL
*/
lv_indev_t * lv_indev_get_next(lv_indev_t * indev)
{
if(indev == NULL)
return _lv_ll_get_head(&LV_GC_ROOT(_lv_indev_ll));
else
return _lv_ll_get_next(&LV_GC_ROOT(_lv_indev_ll), indev);
}
/**
* Read data from an input device.
* @param indev pointer to an input device
* @param data input device will write its data here
* @return false: no more data; true: there more data to read (buffered)
*/
bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
{
bool cont = false;
_lv_memset_00(data, sizeof(lv_indev_data_t));
/* For touchpad sometimes users don't the last pressed coordinate on release.
* So be sure a coordinates are initialized to the last point */
if(indev->driver.type == LV_INDEV_TYPE_POINTER) {
data->point.x = indev->proc.types.pointer.last_raw_point.x;
data->point.y = indev->proc.types.pointer.last_raw_point.y;
}
/*Similarly set at least the last key in case of the user doesn't set it on release*/
else if(indev->driver.type == LV_INDEV_TYPE_KEYPAD) {
data->key = indev->proc.types.keypad.last_key;
}
/*For compatibility assume that used button was enter (encoder push) */
else if(indev->driver.type == LV_INDEV_TYPE_ENCODER) {
data->key = LV_KEY_ENTER;
data->enc_diff = 0;
}
if(indev->driver.read_cb) {
LV_LOG_TRACE("indev read started");
cont = indev->driver.read_cb(&indev->driver, data);
LV_LOG_TRACE("indev read finished");
}
else {
LV_LOG_WARN("indev function registered");
}
return cont;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -0,0 +1,232 @@
/**
* @file lv_hal_indev.h
*
* @description Input Device HAL interface layer header file
*
*/
#ifndef LV_HAL_INDEV_H
#define LV_HAL_INDEV_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdbool.h>
#include <stdint.h>
#include "../lv_misc/lv_area.h"
#include "../lv_misc/lv_task.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct _lv_obj_t;
struct _disp_t;
struct _lv_indev_t;
struct _lv_indev_drv_t;
/** Possible input device types*/
enum {
LV_INDEV_TYPE_NONE, /**< Uninitialized state*/
LV_INDEV_TYPE_POINTER, /**< Touch pad, mouse, external button*/
LV_INDEV_TYPE_KEYPAD, /**< Keypad or keyboard*/
LV_INDEV_TYPE_BUTTON, /**< External (hardware button) which is assigned to a specific point of the
screen*/
LV_INDEV_TYPE_ENCODER, /**< Encoder with only Left, Right turn and a Button*/
};
typedef uint8_t lv_indev_type_t;
/** States for input devices*/
enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR };
typedef uint8_t lv_indev_state_t;
enum {
LV_DRAG_DIR_HOR = 0x1, /**< Object can be dragged horizontally. */
LV_DRAG_DIR_VER = 0x2, /**< Object can be dragged vertically. */
LV_DRAG_DIR_BOTH = 0x3, /**< Object can be dragged in all directions. */
LV_DRAG_DIR_ONE = 0x4, /**< Object can be dragged only one direction (the first move). */
};
typedef uint8_t lv_drag_dir_t;
enum {
LV_GESTURE_DIR_TOP, /**< Gesture dir up. */
LV_GESTURE_DIR_BOTTOM, /**< Gesture dir down. */
LV_GESTURE_DIR_LEFT, /**< Gesture dir left. */
LV_GESTURE_DIR_RIGHT, /**< Gesture dir right. */
};
typedef uint8_t lv_gesture_dir_t;
/** Data structure passed to an input driver to fill */
typedef struct {
lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/
uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/
int16_t enc_diff; /**< For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/
lv_indev_state_t state; /**< LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
} lv_indev_data_t;
/** Initialized by the user and registered by 'lv_indev_add()'*/
typedef struct _lv_indev_drv_t {
/**< Input device type*/
lv_indev_type_t type;
/**< Function pointer to read input device data.
* Return 'true' if there is more data to be read (buffered).
* Most drivers can safely return 'false' */
bool (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/** Called when an action happened on the input device.
* The second parameter is the event from `lv_event_t`*/
void (*feedback_cb)(struct _lv_indev_drv_t *, uint8_t);
#if LV_USE_USER_DATA
lv_indev_drv_user_data_t user_data;
#endif
/**< Pointer to the assigned display*/
struct _disp_t * disp;
/**< Task to read the periodically read the input device*/
lv_task_t * read_task;
/**< Number of pixels to slide before actually drag the object*/
uint8_t drag_limit;
/**< Drag throw slow-down in [%]. Greater value means faster slow-down */
uint8_t drag_throw;
/**< At least this difference should between two points to evaluate as gesture */
uint8_t gesture_min_velocity;
/**< At least this difference should be to send a gesture */
uint8_t gesture_limit;
/**< Long press time in milliseconds*/
uint16_t long_press_time;
/**< Repeated trigger period in long press [ms] */
uint16_t long_press_rep_time;
} lv_indev_drv_t;
/** Run time data of input devices
* Internally used by the library, you should not need to touch it.
*/
typedef struct _lv_indev_proc_t {
lv_indev_state_t state; /**< Current state of the input device. */
union {
struct {
/*Pointer and button data*/
lv_point_t act_point; /**< Current point of input device. */
lv_point_t last_point; /**< Last point of input device. */
lv_point_t last_raw_point; /**< Last point read from read_cb. */
lv_point_t vect; /**< Difference between `act_point` and `last_point`. */
lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DEF_DRAG_LIMIT*/
lv_point_t drag_throw_vect;
struct _lv_obj_t * act_obj; /*The object being pressed*/
struct _lv_obj_t * last_obj; /*The last object which was pressed (used by drag_throw and
other post-release event)*/
struct _lv_obj_t * last_pressed; /*The lastly pressed object*/
lv_gesture_dir_t gesture_dir;
lv_point_t gesture_sum; /*Count the gesture pixels to check LV_INDEV_DEF_GESTURE_LIMIT*/
/*Flags*/
uint8_t drag_limit_out : 1;
uint8_t drag_in_prog : 1;
lv_drag_dir_t drag_dir : 3;
uint8_t gesture_sent : 1;
} pointer;
struct {
/*Keypad data*/
lv_indev_state_t last_state;
uint32_t last_key;
} keypad;
} types;
uint32_t pr_timestamp; /**< Pressed time stamp*/
uint32_t longpr_rep_timestamp; /**< Long press repeat time stamp*/
/*Flags*/
uint8_t long_pr_sent : 1;
uint8_t reset_query : 1;
uint8_t disabled : 1;
uint8_t wait_until_release : 1;
} lv_indev_proc_t;
struct _lv_obj_t;
struct _lv_group_t;
/** The main input device descriptor with driver, runtime data ('proc') and some additional
* information*/
typedef struct _lv_indev_t {
lv_indev_drv_t driver;
lv_indev_proc_t proc;
struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/
struct _lv_group_t * group; /**< Keypad destination group*/
const lv_point_t * btn_points; /**< Array points assigned to the button ()screen will be pressed
here by the buttons*/
} lv_indev_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize an input device 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
*/
void lv_indev_drv_init(lv_indev_drv_t * driver);
/**
* Register an initialized input device driver.
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
* @return pointer to the new input device or NULL on error
*/
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver);
/**
* Update the driver in run time.
* @param indev pointer to a input device. (return value of `lv_indev_drv_register`)
* @param new_drv pointer to the new driver
*/
void lv_indev_drv_update(lv_indev_t * indev, lv_indev_drv_t * new_drv);
/**
* Get the next input device.
* @param indev pointer to the current input device. NULL to initialize.
* @return the next input devise or NULL if no more. Give the first input device when the parameter
* is NULL
*/
lv_indev_t * lv_indev_get_next(lv_indev_t * indev);
/**
* Read data from an input device.
* @param indev pointer to an input device
* @param data input device will write its data here
* @return false: no more data; true: there more data to read (buffered)
*/
bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif

View File

@ -0,0 +1,103 @@
/**
* @file lv_hal_tick.c
* Provide access to the system tick with 1 millisecond resolution
*/
/*********************
* INCLUDES
*********************/
#include "lv_hal_tick.h"
#include <stddef.h>
#if LV_TICK_CUSTOM == 1
#include LV_TICK_CUSTOM_INCLUDE
#ifdef LV_TICK_CUSTOM_INCLUDE_MORE
#include LV_TICK_CUSTOM_INCLUDE_MORE
#endif
#endif
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static uint32_t sys_time = 0;
static volatile uint8_t tick_irq_flag;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* You have to call this function periodically
* @param tick_period the call period of this function in milliseconds
*/
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)
{
tick_irq_flag = 0;
sys_time += tick_period;
}
/**
* Get the elapsed milliseconds since start up
* @return the elapsed milliseconds
*/
uint32_t lv_tick_get(void)
{
#if LV_TICK_CUSTOM == 0
/* If `lv_tick_inc` is called from an interrupt while `sys_time` is read
* the result might be corrupted.
* This loop detects if `lv_tick_inc` was called while reading `sys_time`.
* If `tick_irq_flag` was cleared in `lv_tick_inc` try to read again
* until `tick_irq_flag` remains `1`. */
uint32_t result;
do {
tick_irq_flag = 1;
result = sys_time;
} while(!tick_irq_flag); /*Continue until see a non interrupted cycle */
return result;
#else
return LV_TICK_CUSTOM_SYS_TIME_EXPR;
#endif
}
/**
* Get the elapsed milliseconds since a previous time stamp
* @param prev_tick a previous time stamp (return value of lv_tick_get() )
* @return the elapsed milliseconds since 'prev_tick'
*/
uint32_t lv_tick_elaps(uint32_t prev_tick)
{
uint32_t act_time = lv_tick_get();
/*If there is no overflow in sys_time simple subtract*/
if(act_time >= prev_tick) {
prev_tick = act_time - prev_tick;
}
else {
prev_tick = UINT32_MAX - prev_tick + 1;
prev_tick += act_time;
}
return prev_tick;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -0,0 +1,67 @@
/**
* @file lv_hal_tick.h
* Provide access to the system tick with 1 millisecond resolution
*/
#ifndef LV_HAL_TICK_H
#define LV_HAL_TICK_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
#ifndef LV_ATTRIBUTE_TICK_INC
#define LV_ATTRIBUTE_TICK_INC
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
//! @cond Doxygen_Suppress
/**
* You have to call this function periodically
* @param tick_period the call period of this function in milliseconds
*/
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period);
//! @endcond
/**
* Get the elapsed milliseconds since start up
* @return the elapsed milliseconds
*/
uint32_t lv_tick_get(void);
/**
* Get the elapsed milliseconds since a previous time stamp
* @param prev_tick a previous time stamp (return value of lv_tick_get() )
* @return the elapsed milliseconds since 'prev_tick'
*/
uint32_t lv_tick_elaps(uint32_t prev_tick);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_HAL_TICK_H*/