chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
listenai_library_sources(
lv_port_disp.c
lv_port_indev.c
)
listenai_library_sources_ifdef(CONFIG_LV_USE_GPU_CSK_DMA2D lv_gpu_csk_dma2d.c)
listenai_library_sources_ifdef(CONFIG_LV_CSK_SW_LETTER lv_draw_sw_csk_letter.c)
listenai_library_sources_ifdef(CONFIG_LVFS_POSIX_API lv_port_fs.c)
listenai_library_sources(lv_port_mem.c)
listenai_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(CONFIG_LV_USE_RPC)
add_subdirectory(func_proxy)
endif()

View File

@@ -0,0 +1,63 @@
#ifndef CSK_MONITOR_LV_H
#define CSK_MONITOR_LV_H
#include <stdint.h>
#include "core_feature_base.h"
#include "ClockManager.h"
#if CONFIG_LV_CUSTOM_MONITOR
extern volatile uint64_t g_dma2d_fill_total_time;
extern volatile uint64_t g_dma2d_fill_dma_time;
extern volatile uint32_t g_dma2d_fill_call_cnt;
extern volatile uint64_t g_dma2d_copy_total_time;
extern volatile uint64_t g_dma2d_copy_dma_time;
extern volatile uint32_t g_dma2d_copy_call_cnt;
extern volatile uint64_t g_draw_letter_time;
extern volatile uint32_t g_draw_letter_call_cnt;
extern volatile uint64_t g_draw_image_time;
extern volatile uint32_t g_draw_image_call_cnt;
extern volatile uint64_t g_draw_rect_time;
extern volatile uint32_t g_draw_rect_call_cnt;
#ifdef CONFIG_LV_USE_RPC
extern volatile uint64_t g_rpc_fill_normal_total_time;
extern volatile uint64_t g_rpc_fill_normal_proxy_time;
extern volatile uint32_t g_rpc_fill_normal_call_cnt;
extern volatile uint64_t g_rpc_map_normal_total_time;
extern volatile uint64_t g_rpc_map_normal_proxy_time;
extern volatile uint32_t g_rpc_map_normal_call_cnt;
extern volatile uint64_t g_rpc_fill_blended_total_time;
extern volatile uint64_t g_rpc_fill_blended_proxy_time;
extern volatile uint32_t g_rpc_fill_blended_call_cnt;
extern volatile uint64_t g_rpc_map_blended_total_time;
extern volatile uint64_t g_rpc_map_blended_proxy_time;
extern volatile uint32_t g_rpc_map_blended_call_cnt;
#endif
#endif
#define _CORE_CLK 300000000
static inline uint64_t get_time_cycle(void)
{
return __get_rv_cycle();
}
static inline uint64_t calc_time_elapsed_cycle(uint64_t cycle)
{
return __get_rv_cycle() - cycle;
}
static inline uint32_t clk_2_us(uint64_t clk)
{
return (uint32_t)(clk * 1000 * 1000 / _CORE_CLK);
}
#endif

View File

@@ -0,0 +1,7 @@
if(CONFIG_HARTID EQUAL 0)
listenai_library_sources(lv_func_proxy_server.c)
else()
listenai_library_sources(lv_func_proxy.c)
endif()
listenai_include_directories(${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -0,0 +1,237 @@
#include "func_proxy.h"
#include "lisa_log.h"
#include "lv_func_proxy.h"
#include "cache.h"
#if CONFIG_LV_CUSTOM_MONITOR
#include "csk_monitor_lv.h"
volatile uint64_t g_rpc_fill_normal_total_time;
volatile uint64_t g_rpc_fill_normal_proxy_time;
volatile uint32_t g_rpc_fill_normal_call_cnt;
volatile uint64_t g_rpc_map_normal_total_time;
volatile uint64_t g_rpc_map_normal_proxy_time;
volatile uint32_t g_rpc_map_normal_call_cnt;
volatile uint64_t g_rpc_fill_blended_total_time;
volatile uint64_t g_rpc_fill_blended_proxy_time;
volatile uint32_t g_rpc_fill_blended_call_cnt;
volatile uint64_t g_rpc_map_blended_total_time;
volatile uint64_t g_rpc_map_blended_proxy_time;
volatile uint32_t g_rpc_map_blended_call_cnt;
#endif
int lv_rpc_fill_normal(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_coord_t mask_stride)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
struct sw_fill_normal_args fill_args;
fill_args.dest_buf = dest_buf;
memcpy(&fill_args.dest_area, dest_area, sizeof(lv_area_t));
fill_args.dest_stride = dest_stride;
fill_args.color.full = color.full;
fill_args.opa = opa;
fill_args.mask = (lv_opa_t *)mask;
fill_args.mask_stride = mask_stride;
dcache_flush_range((uint32_t )dest_buf, (uint32_t)dest_buf + dest_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
dcache_flush_range((uint32_t )mask, (uint32_t)mask + mask_stride * lv_area_get_height(dest_area));
func_proxy_data_t in = {
.data = &fill_args,
.size = sizeof(fill_args)
};
struct sw_fill_normal_result result;
func_proxy_data_t out = {
.data = &result,
.size = sizeof(result)
};
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t proxy_time = get_time_cycle();
#endif
int32_t ret = func_proxy_call(FUNC_NAME_FILL_NORMAL, &in, &out);
if(ret){
LOGE("[%s]error %d", __FUNCTION__, ret);
return -1;
}
#if CONFIG_LV_CUSTOM_MONITOR
g_rpc_fill_normal_total_time += calc_time_elapsed_cycle(start_time);
g_rpc_fill_normal_proxy_time += calc_time_elapsed_cycle(proxy_time);
g_rpc_fill_normal_call_cnt++;
#endif
return 0;
}
int lv_rpc_map_normal(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, const lv_color_t * src_buf,
lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t * mask,
lv_coord_t mask_stride)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
struct sw_map_normal_args map_args;
map_args.dest_buf = dest_buf;
memcpy(&map_args.dest_area, dest_area, sizeof(lv_area_t));
map_args.dest_stride = dest_stride;
map_args.src_buf = (lv_color_t *)src_buf;
map_args.src_stride = src_stride;
map_args.opa = opa;
map_args.mask = (lv_opa_t *)mask;
map_args.mask_stride = mask_stride;
dcache_flush_range((uint32_t )dest_buf, (uint32_t)dest_buf + dest_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
dcache_flush_range((uint32_t )mask, (uint32_t)mask + mask_stride * lv_area_get_height(dest_area));
dcache_flush_range((uint32_t )src_buf, (uint32_t)src_buf + src_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
func_proxy_data_t in = {
.data = &map_args,
.size = sizeof(map_args)
};
struct sw_map_normal_result result;
func_proxy_data_t out = {
.data = &result,
.size = sizeof(result)
};
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t proxy_time = get_time_cycle();
#endif
int32_t ret = func_proxy_call(FUNC_NAME_MAP_NORMAL, &in, &out);
if(ret){
LOGE("[%s]error %d", __FUNCTION__, ret);
return -1;
}
#if CONFIG_LV_CUSTOM_MONITOR
g_rpc_map_normal_total_time += calc_time_elapsed_cycle(start_time);
g_rpc_map_normal_proxy_time += calc_time_elapsed_cycle(proxy_time);
g_rpc_map_normal_call_cnt++;
#endif
return 0;
}
int lv_rpc_fill_blended(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_coord_t mask_stride, lv_blend_mode_t blend_mode)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
struct sw_fill_blended_args fill_args;
fill_args.dest_buf = dest_buf;
memcpy(&fill_args.dest_area, dest_area, sizeof(lv_area_t));
fill_args.dest_stride = dest_stride;
fill_args.color = color;
fill_args.opa = opa;
fill_args.mask = (lv_opa_t *)mask;
fill_args.mask_stride = mask_stride;
fill_args.blend_mode = blend_mode;
dcache_flush_range((uint32_t )dest_buf, (uint32_t)dest_buf + dest_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
dcache_flush_range((uint32_t )mask, (uint32_t)mask + mask_stride * lv_area_get_height(dest_area));
func_proxy_data_t in = {
.data = &fill_args,
.size = sizeof(fill_args)
};
struct sw_fill_blended_result result;
func_proxy_data_t out = {
.data = &result,
.size = sizeof(result)
};
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t proxy_time = get_time_cycle();
#endif
int32_t ret = func_proxy_call(FUNC_NAME_FILL_BLEND, &in, &out);
if(ret){
LOGE("[%s]error %d", __FUNCTION__, ret);
return -1;
}
#if CONFIG_LV_CUSTOM_MONITOR
g_rpc_fill_blended_total_time += calc_time_elapsed_cycle(start_time);
g_rpc_fill_blended_proxy_time += calc_time_elapsed_cycle(proxy_time);
g_rpc_fill_blended_call_cnt++;
#endif
return 0;
}
int lv_rpc_map_blended(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, const lv_color_t * src_buf,
lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t * mask,
lv_coord_t mask_stride, lv_blend_mode_t blend_mode)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
struct sw_map_blended_args map_args;
map_args.dest_buf = dest_buf;
memcpy(&map_args.dest_area, dest_area, sizeof(lv_area_t));
map_args.dest_stride = dest_stride;
map_args.src_buf = (lv_color_t *)src_buf;
map_args.src_stride = src_stride;
map_args.opa = opa;
map_args.mask = (lv_opa_t *)mask;
map_args.mask_stride = mask_stride;
map_args.blend_mode = blend_mode;
dcache_flush_range((uint32_t )dest_buf, (uint32_t)dest_buf + dest_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
dcache_flush_range((uint32_t )mask, (uint32_t)mask + mask_stride * lv_area_get_height(dest_area));
dcache_flush_range((uint32_t )src_buf, (uint32_t)src_buf + src_stride * lv_area_get_height(dest_area) * sizeof(lv_color_t));
func_proxy_data_t in = {
.data = &map_args,
.size = sizeof(map_args)
};
struct sw_map_blended_result result;
func_proxy_data_t out = {
.data = &result,
.size = sizeof(result)
};
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t proxy_time = get_time_cycle();
#endif
int32_t ret = func_proxy_call(FUNC_NAME_MAP_BLEND, &in, &out);
if(ret){
LOGE("[%s]error %d", __FUNCTION__, ret);
return -1;
}
#if CONFIG_LV_CUSTOM_MONITOR
g_rpc_map_blended_total_time += calc_time_elapsed_cycle(start_time);
g_rpc_map_blended_proxy_time += calc_time_elapsed_cycle(proxy_time);
g_rpc_map_blended_call_cnt++;
#endif
return 0;
}
void lv_rpc_init(void)
{
func_proxy_init();
}

View File

@@ -0,0 +1,93 @@
#ifndef LV_FUNC_PROXY_H
#define LV_FUNC_PROXY_H
#include <stdint.h>
#include "../src/misc/lv_color.h"
#include "../src/hal/lv_hal_disp.h"
#include "../src/draw/sw/lv_draw_sw.h"
#define FUNC_NAME_FILL_NORMAL "fill_normal"
struct sw_fill_normal_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t color;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
};
struct sw_fill_normal_result {
int32_t reserved;
};
#define FUNC_NAME_MAP_NORMAL "map_normal"
struct sw_map_normal_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t * src_buf;
lv_coord_t src_stride;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
};
struct sw_map_normal_result {
int32_t reserved;
};
#define FUNC_NAME_FILL_BLEND "fill_blend"
struct sw_fill_blended_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t color;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
lv_blend_mode_t blend_mode;
};
struct sw_fill_blended_result {
int32_t reserved;
};
#define FUNC_NAME_MAP_BLEND "map_blended"
struct sw_map_blended_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t * src_buf;
lv_coord_t src_stride;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
lv_blend_mode_t blend_mode;
};
struct sw_map_blended_result {
int32_t reserved;
};
void lv_rpc_init(void);
int lv_rpc_fill_normal(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_coord_t mask_stride);
int lv_rpc_map_normal(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, const lv_color_t * src_buf,
lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t * mask,
lv_coord_t mask_stride);
int lv_rpc_fill_blended(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_coord_t mask_stride, lv_blend_mode_t blend_mode);
int lv_rpc_map_blended(lv_color_t * dest_buf, const lv_area_t * dest_area,
lv_coord_t dest_stride, const lv_color_t * src_buf,
lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t * mask,
lv_coord_t mask_stride, lv_blend_mode_t blend_mode);
#endif /* LV_FUNC_PROXY_H */

View File

@@ -0,0 +1,125 @@
#include "cache.h"
#include "func_proxy.h"
#include "lv_func_proxy_server.h"
#include <string.h>
extern void fill_normal(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride, lv_color_t color,
lv_opa_t opa, const lv_opa_t *mask, lv_coord_t mask_stride);
static int32_t fill_normal_handler(func_proxy_data_t *in, func_proxy_data_t *out)
{
// 参数检查
if (!in || !in->data || in->size != sizeof(struct sw_fill_normal_args) || !out || !out->data ||
out->size < sizeof(struct sw_fill_normal_result)) {
return -1;
}
struct sw_fill_normal_args *args = (struct sw_fill_normal_args *)in->data;
dcache_invalidate_range((uint32_t)args->dest_buf,
(uint32_t)args->dest_buf +
args->dest_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
dcache_invalidate_range((uint32_t)args->mask,
(uint32_t)args->mask + args->mask_stride * lv_area_get_height(&args->dest_area));
fill_normal(args->dest_buf, &args->dest_area, args->dest_stride, args->color, args->opa, args->mask,
args->mask_stride);
dcache_clean_range((uint32_t)args->dest_buf, (uint32_t)args->dest_buf + args->dest_stride *
lv_area_get_height(&args->dest_area) *
sizeof(lv_color_t));
return 0;
}
extern void map_normal(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride,
const lv_color_t *src_buf, lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t *mask,
lv_coord_t mask_stride);
static int32_t map_normal_handler(func_proxy_data_t *in, func_proxy_data_t *out)
{
// 参数检查
if (!in || !in->data || in->size != sizeof(struct sw_map_normal_args) || !out || !out->data ||
out->size < sizeof(struct sw_map_normal_result)) {
return -1;
}
struct sw_map_normal_args *args = (struct sw_map_normal_args *)in->data;
dcache_invalidate_range((uint32_t)args->dest_buf,
(uint32_t)args->dest_buf +
args->dest_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
dcache_invalidate_range((uint32_t)args->mask,
(uint32_t)args->mask + args->mask_stride * lv_area_get_height(&args->dest_area));
dcache_invalidate_range((uint32_t)args->src_buf,
(uint32_t)args->src_buf +
args->src_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
map_normal(args->dest_buf, &args->dest_area, args->dest_stride, args->src_buf, args->src_stride, args->opa,
args->mask, args->mask_stride);
dcache_clean_range((uint32_t)args->dest_buf, (uint32_t)args->dest_buf + args->dest_stride *
lv_area_get_height(&args->dest_area) *
sizeof(lv_color_t));
return 0;
}
extern void fill_blended(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride, lv_color_t color,
lv_opa_t opa, const lv_opa_t *mask, lv_coord_t mask_stride, lv_blend_mode_t blend_mode);
static int32_t fill_blended_handler(func_proxy_data_t *in, func_proxy_data_t *out)
{
// 参数检查
if (!in || !in->data || in->size != sizeof(struct sw_fill_blended_args) || !out || !out->data ||
out->size < sizeof(struct sw_fill_blended_result)) {
return -1;
}
struct sw_fill_blended_args *args = (struct sw_fill_blended_args *)in->data;
dcache_invalidate_range((uint32_t)args->dest_buf,
(uint32_t)args->dest_buf +
args->dest_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
dcache_invalidate_range((uint32_t)args->mask,
(uint32_t)args->mask + args->mask_stride * lv_area_get_height(&args->dest_area));
fill_blended(args->dest_buf, &args->dest_area, args->dest_stride, args->color, args->opa, args->mask,
args->mask_stride, args->blend_mode);
dcache_clean_range((uint32_t)args->dest_buf, (uint32_t)args->dest_buf + args->dest_stride *
lv_area_get_height(&args->dest_area) *
sizeof(lv_color_t));
return 0;
}
extern void map_blended(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride,
const lv_color_t *src_buf, lv_coord_t src_stride, lv_opa_t opa, const lv_opa_t *mask,
lv_coord_t mask_stride, lv_blend_mode_t blend_mode);
static int32_t map_blended_handler(func_proxy_data_t *in, func_proxy_data_t *out)
{
// 参数检查
if (!in || !in->data || in->size != sizeof(struct sw_map_blended_args) || !out || !out->data ||
out->size < sizeof(struct sw_map_blended_result)) {
return -1;
}
struct sw_map_blended_args *args = (struct sw_map_blended_args *)in->data;
dcache_invalidate_range((uint32_t)args->dest_buf,
(uint32_t)args->dest_buf +
args->dest_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
dcache_invalidate_range((uint32_t)args->mask,
(uint32_t)args->mask + args->mask_stride * lv_area_get_height(&args->dest_area));
dcache_invalidate_range((uint32_t)args->src_buf,
(uint32_t)args->src_buf +
args->src_stride * lv_area_get_height(&args->dest_area) * sizeof(lv_color_t));
map_blended(args->dest_buf, &args->dest_area, args->dest_stride, args->src_buf, args->src_stride, args->opa,
args->mask, args->mask_stride, args->blend_mode);
dcache_clean_range((uint32_t)args->dest_buf, (uint32_t)args->dest_buf + args->dest_stride *
lv_area_get_height(&args->dest_area) *
sizeof(lv_color_t));
return 0;
}
void lv_rpc_server_init(void)
{
func_proxy_init();
func_proxy_register(FUNC_NAME_FILL_NORMAL, fill_normal_handler);
func_proxy_register(FUNC_NAME_MAP_NORMAL, map_normal_handler);
func_proxy_register(FUNC_NAME_FILL_BLEND, fill_blended_handler);
func_proxy_register(FUNC_NAME_MAP_BLEND, map_blended_handler);
}

View File

@@ -0,0 +1,76 @@
#ifndef LVGL_FUNC_PROXY_SERVER_H
#define LVGL_FUNC_PROXY_SERVER_H
#include <stdint.h>
#include "../src/draw/sw/lv_draw_sw.h"
#define FUNC_NAME_FILL_NORMAL "fill_normal"
struct sw_fill_normal_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t color;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
};
struct sw_fill_normal_result {
int32_t reserved;
};
#define FUNC_NAME_MAP_NORMAL "map_normal"
struct sw_map_normal_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t * src_buf;
lv_coord_t src_stride;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
};
struct sw_map_normal_result {
int32_t reserved;
};
#define FUNC_NAME_FILL_BLEND "fill_blend"
struct sw_fill_blended_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t color;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
lv_blend_mode_t blend_mode;
};
struct sw_fill_blended_result {
int32_t reserved;
};
#define FUNC_NAME_MAP_BLEND "map_blended"
struct sw_map_blended_args {
lv_color_t *dest_buf;
lv_area_t dest_area;
lv_coord_t dest_stride;
lv_color_t * src_buf;
lv_coord_t src_stride;
lv_opa_t opa;
lv_opa_t *mask;
lv_coord_t mask_stride;
lv_blend_mode_t blend_mode;
};
struct sw_map_blended_result {
int32_t reserved;
};
void lv_rpc_server_init(void);
#endif /* LVGL_FUNC_PROXY_SERVER_H */

View File

@@ -0,0 +1,357 @@
/**
* @file lv_draw_sw_csk_letter.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_gpu_csk_dma2d.h"
#include "log_print.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void /* LV_ATTRIBUTE_FAST_MEM */ csk_draw_letter_normal(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc,
const lv_point_t * pos, lv_font_glyph_dsc_t * g, const uint8_t * map_p, uint8_t * mask_buf);
static void /* LV_ATTRIBUTE_FAST_MEM */ draw_letter_mask_buf(lv_font_glyph_dsc_t *g, const uint8_t *map_p, uint8_t *mask_buf);
/**********************
* STATIC VARIABLES
**********************/
#define MASK_CACHE_ITEM_CNT 150
#define MASK_CACHE_BUF_SIZE 512
typedef struct {
uint32_t letter;
int32_t col;
int32_t row;
bool valid;
uint8_t mask_buf[MASK_CACHE_BUF_SIZE];
} mask_cache_item_t;
static __attribute__((section(".psram.data"))) mask_cache_item_t mask_cache[MASK_CACHE_ITEM_CNT];
static uint16_t cache_next_idx = 0;
static uint16_t cache_valid_count = 0; // 记录有效数据数量
static bool cache_initialized = false;
/**********************
* GLOBAL VARIABLES
**********************/
static const uint8_t _lv_bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
static const uint8_t _lv_bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
static const uint8_t _lv_bpp3_opa_table[8] = {0, 36, 73, 109, /*Opacity mapping with bpp = 3*/
146, 182, 219, 255
};
static const uint8_t _lv_bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119,
136, 153, 170, 187,
204, 221, 238, 255
};
static const uint8_t _lv_bpp8_opa_table[256] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void LV_ATTRIBUTE_FAST_MEM lv_draw_sw_csk_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
uint32_t letter)
{
lv_font_glyph_dsc_t g;
bool g_ret = lv_font_get_glyph_dsc(dsc->font, &g, letter, '\0');
if(g_ret == false) {
/*Add warning if the dsc is not found
*but do not print warning for non printable ASCII chars (e.g. '\n')*/
if(letter >= 0x20 &&
letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/
letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/
// LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" LV_PRIX32, letter);
#if LV_USE_FONT_PLACEHOLDER
/* draw placeholder */
lv_area_t glyph_coords;
lv_draw_rect_dsc_t glyph_dsc;
lv_coord_t begin_x = pos_p->x + g.ofs_x;
lv_coord_t begin_y = pos_p->y + g.ofs_y;
lv_area_set(&glyph_coords, begin_x, begin_y, begin_x + g.box_w, begin_y + g.box_h);
lv_draw_rect_dsc_init(&glyph_dsc);
glyph_dsc.bg_opa = LV_OPA_MIN;
glyph_dsc.outline_opa = LV_OPA_MIN;
glyph_dsc.shadow_opa = LV_OPA_MIN;
glyph_dsc.bg_img_opa = LV_OPA_MIN;
glyph_dsc.border_color = dsc->color;
glyph_dsc.border_width = 1;
draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords);
#endif
}
return;
}
/*Don't draw anything if the character is empty. E.g. space*/
if((g.box_h == 0) || (g.box_w == 0)) return;
lv_point_t gpos;
gpos.x = pos_p->x + g.ofs_x;
gpos.y = pos_p->y + (dsc->font->line_height - dsc->font->base_line) - g.box_h - g.ofs_y;
/*If the letter is completely out of mask don't draw it*/
if(gpos.x + g.box_w < draw_ctx->clip_area->x1 ||
gpos.x > draw_ctx->clip_area->x2 ||
gpos.y + g.box_h < draw_ctx->clip_area->y1 ||
gpos.y > draw_ctx->clip_area->y2) {
return;
}
const uint8_t * map_p = lv_font_get_glyph_bitmap(g.resolved_font, letter);
if(map_p == NULL) {
LV_LOG_WARN("lv_draw_letter: character's bitmap not found");
return;
}
// Initialize cache if not done yet
if (!cache_initialized) {
for (int i = 0; i < MASK_CACHE_ITEM_CNT; i++) {
mask_cache[i].valid = false;
}
cache_initialized = true;
cache_valid_count = 0;
}
// Try to find letter in cache
uint8_t *mask_buf = NULL;
if(dsc->opa == LV_OPA_MAX){
for (int i = 0; i < cache_valid_count; i++) { // 只遍历有效数据
if (mask_cache[i].valid && mask_cache[i].letter == letter && mask_cache[i].col == g.box_w && mask_cache[i].row == g.box_h) {
mask_buf = mask_cache[i].mask_buf;
break;
}
}
}
// If not found in cache, calculate and store in cache
if (mask_buf == NULL) {
// Use the next available cache slot
mask_cache_item_t *cache_item = &mask_cache[cache_next_idx];
cache_item->letter = letter;
cache_item->valid = true;
draw_letter_mask_buf(&g, map_p, cache_item->mask_buf);
mask_buf = cache_item->mask_buf;
cache_item->row = g.box_h;
cache_item->col = g.box_w;
if(dsc->opa == LV_OPA_MAX){
// 更新缓存计数
if (cache_next_idx >= cache_valid_count) {
cache_valid_count++;
if (cache_valid_count > MASK_CACHE_ITEM_CNT) {
cache_valid_count = MASK_CACHE_ITEM_CNT;
}
}
// Move to next cache slot, wrap around if needed
cache_next_idx = (cache_next_idx + 1) % MASK_CACHE_ITEM_CNT;
}
}else{
// CLOGD("letter(0x%x) found in cache", letter);
}
if(g.resolved_font->subpx) {
#if LV_DRAW_COMPLEX && LV_USE_FONT_SUBPX
draw_letter_subpx(draw_ctx, dsc, &gpos, &g, map_p);
#else
LV_LOG_WARN("Can't draw sub-pixel rendered letter because LV_USE_FONT_SUBPX == 0 in lv_conf.h");
#endif
}
else {
csk_draw_letter_normal(draw_ctx, dsc, &gpos, &g, map_p, mask_buf);
}
}
/**********************
* STATIC FUNCTIONS
**********************/
static LV_ATTRIBUTE_FAST_MEM void draw_letter_mask_buf(lv_font_glyph_dsc_t *g, const uint8_t *map_p, uint8_t *mask_buf)
{
const uint8_t * bpp_opa_table_p;
uint32_t bitmask_init;
uint32_t bitmask;
uint32_t bpp = g->bpp;
uint32_t shades;
if(bpp == 3) bpp = 4;
switch(bpp) {
case 1:
bpp_opa_table_p = _lv_bpp1_opa_table;
bitmask_init = 0x80;
shades = 2;
break;
case 2:
bpp_opa_table_p = _lv_bpp2_opa_table;
bitmask_init = 0xC0;
shades = 4;
break;
case 4:
bpp_opa_table_p = _lv_bpp4_opa_table;
bitmask_init = 0xF0;
shades = 16;
break;
case 8:
bpp_opa_table_p = _lv_bpp8_opa_table;
bitmask_init = 0xFF;
shades = 256;
break; /*No opa table, pixel value will be used directly*/
default:
LV_LOG_WARN("lv_draw_letter: invalid bpp");
return; /*Invalid bpp. Can't render the letter*/
}
int32_t col, row;
int32_t box_w = g->box_w;
int32_t box_h = g->box_h;
int32_t width_bit = box_w * bpp; /*Letter width in bits*/
/*Calculate the col/row start/end on the map*/
int32_t col_start = 0;
int32_t col_end = box_w;
int32_t row_start = 0;
int32_t row_end = box_h;
/*Move on the map too*/
uint32_t bit_ofs = (row_start * width_bit) + (col_start * bpp);
map_p += bit_ofs >> 3;
uint8_t letter_px;
uint32_t col_bit;
col_bit = bit_ofs & 0x7; /*"& 0x7" equals to "% 8" just faster*/
int32_t mask_p = 0;
uint32_t col_bit_max = 8 - bpp;
uint32_t col_bit_row_ofs = (box_w + col_start - col_end) * bpp;
for(row = row_start ; row < row_end; row++) {
bitmask = bitmask_init >> col_bit;
for(col = col_start; col < col_end; col++) {
/*Load the pixel's opacity into the mask*/
letter_px = (*map_p & bitmask) >> (col_bit_max - col_bit);
if(letter_px) {
mask_buf[mask_p] = bpp_opa_table_p[letter_px];
}
else {
mask_buf[mask_p] = 0;
}
/*Go to the next column*/
if(col_bit < col_bit_max) {
col_bit += bpp;
bitmask = bitmask >> bpp;
}
else {
col_bit = 0;
bitmask = bitmask_init;
map_p++;
}
/*Next mask byte*/
mask_p++;
}
col_bit += col_bit_row_ofs;
map_p += (col_bit >> 3);
col_bit = col_bit & 0x7;
}
}
static void LV_ATTRIBUTE_FAST_MEM csk_draw_letter_normal(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc,
const lv_point_t * pos, lv_font_glyph_dsc_t * g, const uint8_t * map_p,
uint8_t * mask_buf)
{
#if LV_USE_IMGFONT
if(bpp == LV_IMGFONT_BPP) { //is imgfont
lv_area_t fill_area;
fill_area.x1 = pos->x;
fill_area.y1 = pos->y;
fill_area.x2 = pos->x + g->box_w - 1;
fill_area.y2 = pos->y + g->box_h - 1;
lv_draw_img_dsc_t img_dsc;
lv_draw_img_dsc_init(&img_dsc);
img_dsc.angle = 0;
img_dsc.zoom = LV_IMG_ZOOM_NONE;
img_dsc.opa = dsc->opa;
img_dsc.blend_mode = dsc->blend_mode;
lv_draw_img(draw_ctx, &img_dsc, &fill_area, map_p);
return;
}
#endif
int32_t box_w = g->box_w;
int32_t box_h = g->box_h;
/*Calculate the col/row start/end on the map*/
int32_t col_start = pos->x >= draw_ctx->clip_area->x1 ? 0 : draw_ctx->clip_area->x1 - pos->x;
int32_t col_end = pos->x + box_w <= draw_ctx->clip_area->x2 ? box_w : draw_ctx->clip_area->x2 - pos->x + 1;
int32_t row_start = pos->y >= draw_ctx->clip_area->y1 ? 0 : draw_ctx->clip_area->y1 - pos->y;
int32_t row_end = pos->y + box_h <= draw_ctx->clip_area->y2 ? box_h : draw_ctx->clip_area->y2 - pos->y + 1;
lv_draw_sw_blend_dsc_t blend_dsc;
lv_memset_00(&blend_dsc, sizeof(blend_dsc));
blend_dsc.color = dsc->color;
blend_dsc.opa = dsc->opa;
blend_dsc.blend_mode = dsc->blend_mode;
blend_dsc.mask_buf = mask_buf;
lv_area_t fill_area;
fill_area.x1 = col_start + pos->x;
fill_area.x2 = col_end + pos->x - 1;
fill_area.y1 = row_start + pos->y;
fill_area.y2 = row_end + pos->y - 1;
#if LV_DRAW_COMPLEX
lv_coord_t fill_w = lv_area_get_width(&fill_area);
lv_area_t mask_area;
lv_area_copy(&mask_area, &fill_area);
bool mask_any = lv_draw_mask_is_any(&mask_area);
#endif
blend_dsc.blend_area = &fill_area;
blend_dsc.mask_area = &fill_area;
/*Do the blend*/
blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
lv_draw_sw_blend(draw_ctx, &blend_dsc);
}

View File

@@ -0,0 +1,316 @@
/**
* @file lv_gpu_csk_dma2d.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_gpu_csk_dma2d.h"
#include "../src/core/lv_refr.h"
#include "lisa_log.h"
#include "cache.h"
#include "dma.h"
#include "FreeRTOS.h"
#include "semphr.h"
#if CONFIG_LV_USE_RPC
#include "lv_func_proxy.h"
#endif
/*********************
* DEFINES
*********************/
static SemaphoreHandle_t dma_sem = NULL;
static void lv_draw_csk_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc);
static void lv_draw_csk_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
uint32_t letter);
static int32_t lv_gpu_dma2d_fill(void *buf, uint16_t buf_w, uint32_t color, uint16_t fill_w, uint16_t fill_h);
static int32_t lv_gpu_dma2d_blend(void *buf, uint16_t buf_w, void *map, uint8_t opa, uint16_t map_w, uint16_t copy_w, uint16_t copy_h);
static void DMA_DrvEvent(uint32_t event_info, uint32_t xfer_bytes, uint32_t usr_param)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(dma_sem, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
void lv_draw_csk_dma2d_init(void)
{
#if CONFIG_LV_USE_RPC
lv_rpc_init();
#endif
dma_initialize();
uint8_t ch = dma_channel_reserve(CONFIG_LVGL_GPU_CSK_CPDMA_DMA2D_CH, DMA_DrvEvent, 0, DMA_CACHE_SYNC_NOP);
if (ch == DMA_CHANNEL_ANY) {
LOGE("[FAILED] NO free CP DMA channel for lvgl blend!!");
return;
}
// Create binary semaphore for DMA synchronization
dma_sem = xSemaphoreCreateBinary();
if (dma_sem == NULL) {
LOGE("[%s] Failed to create DMA semaphore", __FUNCTION__);
return;
}
}
#if CONFIG_LV_CUSTOM_MONITOR
#include "csk_monitor_lv.h"
volatile uint64_t g_dma2d_fill_total_time;
volatile uint64_t g_dma2d_fill_dma_time;
volatile uint32_t g_dma2d_fill_call_cnt;
volatile uint64_t g_dma2d_copy_total_time;
volatile uint64_t g_dma2d_copy_dma_time;
volatile uint32_t g_dma2d_copy_call_cnt;
static void lv_draw_csk_dma2d_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords)
{
uint64_t start_time = get_time_cycle();
lv_draw_sw_rect(draw_ctx, dsc, coords);
g_draw_rect_time += calc_time_elapsed_cycle(start_time);
g_draw_rect_call_cnt++;
}
static void lv_draw_csk_dma2d_img_decoded(lv_draw_ctx_t * draw_ctx,
const lv_draw_img_dsc_t * draw_dsc,
const lv_area_t * coords, const uint8_t * src_buf,
lv_img_cf_t cf)
{
uint64_t start_time = get_time_cycle();
lv_draw_sw_img_decoded(draw_ctx, draw_dsc, coords, src_buf, cf);
g_draw_image_time += calc_time_elapsed_cycle(start_time);
g_draw_image_call_cnt++;
}
#endif
void lv_draw_csk_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
{
lv_draw_sw_init_ctx(drv, draw_ctx);
lv_draw_csk_dma2d_ctx_t * dma2d_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
#if CONFIG_LV_CUSTOM_MONITOR
dma2d_draw_ctx->base_draw.draw_rect = lv_draw_csk_dma2d_rect;
dma2d_draw_ctx->base_draw.draw_img_decoded = lv_draw_csk_dma2d_img_decoded;
#endif
dma2d_draw_ctx->base_draw.draw_letter = lv_draw_csk_letter;
dma2d_draw_ctx->blend = lv_draw_csk_dma2d_blend;
}
static LV_ATTRIBUTE_FAST_MEM void lv_draw_csk_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
uint32_t letter)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
#if CONFIG_LV_CSK_SW_LETTER
extern void lv_draw_sw_csk_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
uint32_t letter);
lv_draw_sw_csk_letter(draw_ctx, dsc, pos_p, letter);
#else
lv_draw_sw_letter(draw_ctx, dsc, pos_p, letter);
#endif
#if CONFIG_LV_CUSTOM_MONITOR
g_draw_letter_time += calc_time_elapsed_cycle(start_time);
g_draw_letter_call_cnt++;
#endif
}
static int _lv_draw_csk_dma2d_blend_fill(const lv_color_t * dest_buf, lv_coord_t dest_stride,
const lv_area_t * draw_area, lv_color_t color, lv_opa_t opa)
{
lv_color_t *dest_bufc = (lv_color_t *)dest_buf;
dest_bufc += dest_stride * draw_area->y1;
dest_bufc += draw_area->x1;
if(((uint32_t)dest_bufc % 4 == 0) && (lv_area_get_width(draw_area) % 2 == 0) && (uint32_t)dest_stride % 2 == 0){
dcache_flush_range((uint32_t)dest_bufc, ((uint32_t)dest_bufc + dest_stride * lv_area_get_height(draw_area) * sizeof(lv_color_t)));
return lv_gpu_dma2d_fill(dest_bufc, dest_stride, (uint32_t)(color.full), lv_area_get_width(draw_area), lv_area_get_height(draw_area));
}
return -1;
}
static int _lv_draw_csk_dma2d_blend(const lv_color_t * dest_buf, lv_coord_t dest_stride,
const lv_area_t * draw_area, const void * src_buf, lv_coord_t src_stride, const lv_point_t * src_offset, lv_opa_t opa)
{
lv_color_t *dest_bufc = (lv_color_t *)dest_buf;
lv_color_t *src_bufc = (lv_color_t *)src_buf;
dest_bufc += dest_stride * draw_area->y1;
dest_bufc += draw_area->x1;
src_bufc += src_stride * src_offset->y;
src_bufc += src_offset->x;
if(((uint32_t)dest_bufc % 4 == 0) && (lv_area_get_width(draw_area) % 2 == 0) && (uint32_t)src_bufc % 4 == 0
&& (uint32_t)dest_stride % 2 == 0 && (uint32_t)src_stride % 2 == 0){
dcache_flush_range((uint32_t)dest_bufc, ((uint32_t)dest_bufc + dest_stride * lv_area_get_height(draw_area) * sizeof(lv_color_t)));
dcache_flush_range((uint32_t)src_bufc, ((uint32_t)src_bufc + src_stride * lv_area_get_height(draw_area) * sizeof(lv_color_t)));
return lv_gpu_dma2d_blend(dest_bufc, dest_stride, src_bufc, opa, src_stride, lv_area_get_width(draw_area), lv_area_get_height(draw_area));
}
return -1;
}
static lv_point_t lv_area_get_offset(const lv_area_t * area1, const lv_area_t * area2)
{
lv_point_t offset = {x: area2->x1 - area1->x1, y: area2->y1 - area1->y1};
return offset;
}
static LV_ATTRIBUTE_FAST_MEM void lv_draw_csk_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc)
{
int done = -1;
lv_area_t draw_area;
/*Let's get the blend area which is the intersection of the area to draw and the clip area*/
if(!_lv_area_intersect(&draw_area, dsc->blend_area, draw_ctx->clip_area))
return;
const lv_opa_t * mask = dsc->mask_buf;
lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
if(lv_area_get_size(&draw_area) >= 4096){
if(mask != NULL) {
}else{
if(dsc->src_buf == NULL) {
lv_area_move(&draw_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
if (dsc->opa == LV_OPA_COVER) {
done = _lv_draw_csk_dma2d_blend_fill(draw_ctx->buf, dest_stride, &draw_area, dsc->color, dsc->opa);
}
}else{
lv_coord_t src_stride = lv_area_get_width(dsc->blend_area);
lv_point_t src_offset = lv_area_get_offset(dsc->blend_area, &draw_area);
lv_area_move(&draw_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
if (dsc->opa == LV_OPA_COVER) {
done = _lv_draw_csk_dma2d_blend(draw_ctx->buf, dest_stride, &draw_area, dsc->src_buf, src_stride, &src_offset, dsc->opa);
}
}
}
}else{
}
if(done != 0){
lv_draw_sw_blend_basic(draw_ctx, dsc);
}
}
static int32_t lv_gpu_dma2d_fill(void *buf, uint16_t buf_w, uint32_t color, uint16_t fill_w, uint16_t fill_h)
{
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
int ret = 0;
uint32_t control, config_low, config_high;
uint32_t src_width = DMA_WIDTH_WORD;
uint32_t src_bsize = DMA_BSIZE_16;
uint32_t dst_width = DMA_WIDTH_WORD;
uint32_t dst_bsize = DMA_BSIZE_16;
uint32_t dst_gath = (((buf_w - fill_w) / 2 ) << SG_INTERVAL_POS) | ((fill_w / 2) << SG_COUNT_POS);
//Use sram as much as possible
static __attribute__((aligned(4), section(".dtcm.bss"))) uint32_t fill_color;
fill_color = color + color * 65536;
control = DMA_CH_CTLL_INT_EN | DMA_CH_CTLL_DST_WIDTH(dst_width) | DMA_CH_CTLL_SRC_WIDTH(src_width) |
DMA_CH_CTLL_DST_INC | DMA_CH_CTLL_SRC_FIX | DMA_CH_CTLL_DST_BSIZE(dst_bsize) | DMA_CH_CTLL_SRC_BSIZE(src_bsize) |
DMA_CH_CTLL_TTFC_M2M | DMA_CH_CTLL_DMS(0) | DMA_CH_CTLL_SMS(0);
config_low = DMA_CH_CFGL_CH_PRIOR(0);
config_high = DMA_CH_CFGH_FIFO_MODE;
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t dma2d_ready = get_time_cycle();
#endif
uint8_t stat = 0;
if (buf_w == fill_w) {
stat = dma_channel_configure (CONFIG_LVGL_GPU_CSK_CPDMA_DMA2D_CH, (uint32_t)&fill_color, (uint32_t)buf, fill_w * fill_h / 2,
control, config_low, config_high, 0, 0);
} else {
control |= DMA_CH_CTLL_D_SCAT_EN;
stat = dma_channel_configure (CONFIG_LVGL_GPU_CSK_CPDMA_DMA2D_CH, (uint32_t)&fill_color, (uint32_t)buf, fill_w * fill_h / 2,
control, config_low, config_high, 0, dst_gath);
}
if(stat == -1) {
LOGE("[FAILED] dma_channel_configure failed!!\r\n");
ret = -2;
goto error;
}
if (xSemaphoreTake(dma_sem, pdMS_TO_TICKS(500)) != pdTRUE) {
ret = -3;
goto error;
}
error:
#if CONFIG_LV_CUSTOM_MONITOR
g_dma2d_fill_total_time += calc_time_elapsed_cycle(start_time);
g_dma2d_fill_dma_time += calc_time_elapsed_cycle(dma2d_ready);
g_dma2d_fill_call_cnt++;
#endif
return ret;
}
static int32_t lv_gpu_dma2d_blend(void *buf, uint16_t buf_w, void *map, uint8_t opa, uint16_t map_w, uint16_t copy_w, uint16_t copy_h)
{
int ret = 0;
uint32_t control, config_low, config_high;
uint32_t src_width = DMA_WIDTH_WORD;
uint32_t src_bsize = DMA_BSIZE_16;
uint32_t dst_width = DMA_WIDTH_WORD;
uint32_t dst_bsize = DMA_BSIZE_16;
uint32_t src_gath = (((map_w - copy_w) / 2) << SG_INTERVAL_POS) | ((copy_w / 2) << SG_COUNT_POS);
uint32_t dst_gath = (((buf_w - copy_w) / 2) << SG_INTERVAL_POS) | ((copy_w / 2) << SG_COUNT_POS);
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t start_time = get_time_cycle();
#endif
control = DMA_CH_CTLL_INT_EN | DMA_CH_CTLL_DST_WIDTH(dst_width) | DMA_CH_CTLL_SRC_WIDTH(src_width) |
DMA_CH_CTLL_DST_INC | DMA_CH_CTLL_SRC_INC | DMA_CH_CTLL_DST_BSIZE(dst_bsize) | DMA_CH_CTLL_SRC_BSIZE(src_bsize) |
DMA_CH_CTLL_TTFC_M2M | DMA_CH_CTLL_DMS(0) | DMA_CH_CTLL_SMS(0);
control |= DMA_CH_CTLL_S_GATH_EN;
control |= DMA_CH_CTLL_D_SCAT_EN;
config_low = DMA_CH_CFGL_CH_PRIOR(0);
config_high = DMA_CH_CFGH_FIFO_MODE;
#if CONFIG_LV_CUSTOM_MONITOR
uint64_t dma2d_ready = get_time_cycle();
#endif
uint8_t stat = dma_channel_configure (CONFIG_LVGL_GPU_CSK_CPDMA_DMA2D_CH, (uint32_t)map, (uint32_t)buf, copy_w * copy_h / 2,
control, config_low, config_high, src_gath, dst_gath);
if(stat == -1) {
ret = -2;
goto error;
}
if (xSemaphoreTake(dma_sem, pdMS_TO_TICKS(500)) != pdTRUE) {
ret = -3;
goto error;
}
error:
#if CONFIG_LV_CUSTOM_MONITOR
g_dma2d_copy_total_time += calc_time_elapsed_cycle(start_time);
g_dma2d_copy_dma_time += calc_time_elapsed_cycle(dma2d_ready);
g_dma2d_copy_call_cnt++;
#endif
return ret;
}

View File

@@ -0,0 +1,51 @@
/**
* @file lv_gpu_csk_dma2d.h
*
*/
#ifndef LV_GPU_CSK_DMA2D_H
#define LV_GPU_CSK_DMA2D_H
#ifdef __cplusplus
extern "C" {
#endif
#include "../src/misc/lv_color.h"
#include "../src/hal/lv_hal_disp.h"
#include "../src/draw/sw/lv_draw_sw.h"
#if CONFIG_LV_USE_GPU_CSK_DMA2D
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef lv_draw_sw_ctx_t lv_draw_csk_dma2d_ctx_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_draw_csk_dma2d_init(void);
void lv_draw_csk_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
void lv_draw_csk_dma2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
/**********************
* MACROS
**********************/
#endif /*CONFIG_LV_USE_GPU_CSK_DMA2D*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_GPU_STM32_DMA2D_H*/

View File

@@ -0,0 +1,377 @@
/**
* @file lv_port_disp.c
*
*/
#if 1
/*********************
* INCLUDES
*********************/
#include "lv_port_disp.h"
#include "lisa_display.h"
#include <stdlib.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p);
/**********************
* STATIC VARIABLES
**********************/
lisa_device_t *lv_display_device = NULL;
/* Display buffers */
static lv_disp_draw_buf_t disp_buf;
static lv_color_t *buf_1;
#if CONFIG_LV_DOUBLE_VDB
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
static lv_color_t *buf_2;
static QueueHandle_t flush_queue;
static TaskHandle_t flush_task_handle;
static SemaphoreHandle_t flush_sem; // Add semaphore handle
typedef struct {
lv_area_t area;
lv_color_t *color_p;
lv_disp_drv_t *disp_drv;
} flush_msg_t;
static void flush_thread(void *arg)
{
flush_msg_t msg;
lisa_display_buffer_desc_t desc;
while (1) {
if (xQueueReceive(flush_queue, &msg, portMAX_DELAY) == pdTRUE) {
desc.width = msg.area.x2 - msg.area.x1 + 1;
desc.height = msg.area.y2 - msg.area.y1 + 1;
desc.pitch = desc.width * sizeof(lv_color_t);
desc.buf_size = desc.height * desc.width * sizeof(lv_color_t);
lisa_display_write(lv_display_device, msg.area.x1, msg.area.y1, &desc, msg.color_p);
xSemaphoreGive(flush_sem);
}
}
}
#endif
#if CONFIG_LV_CUSTOM_MONITOR
#include "lisa_log.h"
#include "csk_monitor_lv.h"
volatile uint64_t g_draw_letter_time;
volatile uint32_t g_draw_letter_call_cnt;
volatile uint64_t g_draw_image_time;
volatile uint32_t g_draw_image_call_cnt;
volatile uint64_t g_draw_rect_time;
volatile uint32_t g_draw_rect_call_cnt;
static void monitor_cb(lv_disp_drv_t * drv, uint32_t time, uint32_t px)
{
LOGI("[%s] time:%dms px:%d", __func__, time, px);
LOGI("draw letter: cnt = %d, time = %dus", g_draw_letter_call_cnt, clk_2_us(g_draw_letter_time));
g_draw_letter_time = 0;
g_draw_letter_call_cnt = 0;
LOGI("draw image: cnt = %d, time = %dus", g_draw_image_call_cnt, clk_2_us(g_draw_image_time));
g_draw_image_time = 0;
g_draw_image_call_cnt = 0;
LOGI("draw rect: cnt = %d, time = %dus", g_draw_rect_call_cnt, clk_2_us(g_draw_rect_time));
g_draw_rect_time = 0;
g_draw_rect_call_cnt = 0;
#ifdef CONFIG_LV_USE_GPU_CSK_DMA2D
LOGI("dam2d fill: cnt = %d, time = %dus, dma_time = %dus", g_dma2d_fill_call_cnt, clk_2_us(g_dma2d_fill_total_time), clk_2_us(g_dma2d_fill_dma_time));
g_dma2d_fill_total_time = 0;
g_dma2d_fill_dma_time = 0;
g_dma2d_fill_call_cnt = 0;
LOGI("dam2d copy: cnt = %d, time = %dus, dma_time = %dus", g_dma2d_copy_call_cnt, clk_2_us(g_dma2d_copy_total_time), clk_2_us(g_dma2d_copy_dma_time));
g_dma2d_copy_total_time = 0;
g_dma2d_copy_dma_time = 0;
g_dma2d_copy_call_cnt = 0;
#endif
#ifdef CONFIG_LV_USE_RPC
LOGI("rpc fill normal : cnt = %d, time = %dus, proxy_time = %dus", g_rpc_fill_normal_call_cnt, clk_2_us(g_rpc_fill_normal_total_time), clk_2_us(g_rpc_fill_normal_proxy_time));
g_rpc_fill_normal_total_time = 0;
g_rpc_fill_normal_proxy_time = 0;
g_rpc_fill_normal_call_cnt = 0;
LOGI("rpc map normal: cnt = %d, time = %dus, proxy_time = %dus", g_rpc_map_normal_call_cnt, clk_2_us(g_rpc_map_normal_total_time), clk_2_us(g_rpc_map_normal_proxy_time));
g_rpc_map_normal_total_time = 0;
g_rpc_map_normal_proxy_time = 0;
g_rpc_map_normal_call_cnt = 0;
LOGI("rpc fill blended: cnt = %d, time = %dus, proxy_time = %dus", g_rpc_fill_blended_call_cnt, clk_2_us(g_rpc_fill_blended_total_time), clk_2_us(g_rpc_fill_blended_proxy_time));
g_rpc_fill_blended_total_time = 0;
g_rpc_fill_blended_proxy_time = 0;
g_rpc_fill_blended_call_cnt = 0;
LOGI("rpc map blended: cnt = %d, time = %dus, proxy_time = %dus", g_rpc_map_blended_call_cnt, clk_2_us(g_rpc_map_blended_total_time), clk_2_us(g_rpc_map_blended_proxy_time));
g_rpc_map_blended_total_time = 0;
g_rpc_map_blended_proxy_time = 0;
g_rpc_map_blended_call_cnt = 0;
#endif
}
#endif
#if CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE > 1
static void disp_rounder(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
area->y1 &= ~(CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE - 1);
area->y2 |= (CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE - 1);
area->x1 &= ~(CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE - 1);
area->x2 |= (CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE - 1);
/* Clamp to screen boundaries to prevent overflow */
lv_coord_t max_x, max_y;
if(disp_drv->rotated == LV_DISP_ROT_90 || disp_drv->rotated == LV_DISP_ROT_270) {
max_x = disp_drv->ver_res - 1;
max_y = disp_drv->hor_res - 1;
} else {
max_x = disp_drv->hor_res - 1;
max_y = disp_drv->ver_res - 1;
}
if(area->x2 > max_x) area->x2 = max_x;
if(area->y2 > max_y) area->y2 = max_y;
}
#endif
lisa_device_t *lv_port_get_display_device(void)
{
return lv_display_device;
}
void lv_port_disp_init(lisa_device_t *display_dev)
{
lisa_display_capabilities_t caps = {0};
/*-------------------------
* Initialize your display
* -----------------------*/
lv_display_device = display_dev;
if (lv_display_device == NULL) {
LV_LOG_ERROR("[%s] display device create faild", __FUNCTION__);
return;
}
lisa_display_get_capabilities(lv_display_device, &caps);
lisa_display_blanking_on(lv_display_device);
/*-----------------------------
* Create a buffer for drawing
*----------------------------*/
uint32_t size = caps.width * caps.height * sizeof(lv_color_t);
buf_1 = (lv_color_t *)lv_mem_alloc(size);
if (buf_1 == NULL) {
LV_LOG_ERROR("[%s] buf_1 malloc faild", __FUNCTION__);
return;
}
#if CONFIG_LV_DOUBLE_VDB
buf_2 = lv_mem_alloc(size);
if(buf_2 == NULL) {
LV_LOG_ERROR("[%s] lv_mem malloc faild", __FUNCTION__);
lv_mem_free(buf_1);
return;
}
/* Create message queue for flush commands */
flush_queue = xQueueCreate(2, sizeof(flush_msg_t));
if (flush_queue == NULL) {
LV_LOG_ERROR("[%s] Failed to create flush queue", __FUNCTION__);
lv_mem_free(buf_1);
lv_mem_free(buf_2);
return;
}
/* Create semaphore for flush synchronization */
flush_sem = xSemaphoreCreateBinary();
if (flush_sem == NULL) {
LV_LOG_ERROR("[%s] Failed to create flush semaphore", __FUNCTION__);
vQueueDelete(flush_queue);
lv_mem_free(buf_1);
lv_mem_free(buf_2);
return;
}
/* Initialize semaphore as available */
xSemaphoreGive(flush_sem);
/* Create flush thread */
BaseType_t ret = xTaskCreate(flush_thread, "lvgl_flush", 2048, NULL,
configMAX_PRIORITIES - 1, &flush_task_handle);
if (ret != pdPASS) {
LV_LOG_ERROR("[%s] Failed to create flush thread", __FUNCTION__);
vQueueDelete(flush_queue);
vSemaphoreDelete(flush_sem);
lv_mem_free(buf_1);
lv_mem_free(buf_2);
return;
}
lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, size / sizeof(lv_color_t));
#else
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, size / sizeof(lv_color_t));
#endif
#if 1
/*-----------------------------------
* Register the display in LVGL
*----------------------------------*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
/*Set up the functions to access to your display*/
disp_drv.flush_cb = disp_flush;
#if CONFIG_LV_DRIVER_PIXEL_ALIGN_SIZE > 1
disp_drv.rounder_cb = disp_rounder;
#endif
#if CONFIG_LV_DRIVER_ROTATE_NORMAL
disp_drv.rotated = LV_DISP_ROT_NONE;
lisa_display_set_orientation(lv_display_device, LISA_DISPLAY_ORIENTATION_0);
#elif CONFIG_LV_DRIVER_ROTATE_90
disp_drv.rotated = LV_DISP_ROT_90;
lisa_display_set_orientation(lv_display_device, LISA_DISPLAY_ORIENTATION_90);
#elif CONFIG_LV_DRIVER_ROTATE_270
disp_drv.rotated = LV_DISP_ROT_270;
lisa_display_set_orientation(lv_display_device, LISA_DISPLAY_ORIENTATION_270);
#endif
#if CONFIG_LV_DRIVER_FULL_REFRESH
disp_drv.full_refresh = 1;
#endif
#if CONFIG_LV_CUSTOM_MONITOR
disp_drv.monitor_cb = monitor_cb;
#endif
/*Set the resolution of the display*/
disp_drv.hor_res = caps.width;
disp_drv.ver_res = caps.height;
/*Used to copy the buffer's content to the display*/
disp_drv.draw_buf = &disp_buf;
#if CONFIG_LV_COLOR_DEPTH_1
uint8_t *fb_buffer_mono = lv_mem_alloc(caps.width * caps.height / 8);
if (fb_buffer_mono == NULL) {
LV_LOG_ERROR("[%s] lv_mem malloc faild", __FUNCTION__);
} else {
disp_drv.user_data = fb_buffer_mono;
}
#endif
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
#endif
}
#if CONFIG_LV_COLOR_DEPTH_1
int framebuffer_convert_to_mono(const void *src, void *dst, uint32_t width, uint32_t height)
{
const uint8_t *src_buf = (const uint8_t *)src;
uint8_t *dst_buf = (uint8_t *)dst;
if (src == NULL || dst == NULL || width == 0 || height == 0) {
return -1;
}
uint32_t src_pitch = width * sizeof(lv_color_t);
uint32_t dst_pitch = (width + 7) / 8; // 1bpp: 8个像素占1字节,向上取整
for (uint32_t y = 0; y < height; y++) {
for (uint32_t x = 0; x < width; x++) {
uint32_t src_idx = y * src_pitch + x * sizeof(lv_color_t);
uint32_t dst_idx = y * dst_pitch + x / 8;
uint8_t bit_pos = 7 - (x % 8);
lv_color_t color = *((lv_color_t *)(src_buf + src_idx));
if (lv_color_to1(color) == 0) {
dst_buf[dst_idx] &= ~(1 << bit_pos);
} else {
dst_buf[dst_idx] |= (1 << bit_pos);
}
}
}
return 0;
}
#endif
/*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)
{
#if CONFIG_LV_DOUBLE_VDB
flush_msg_t msg;
msg.area.x1 = area->x1;
msg.area.y1 = area->y1;
msg.area.x2 = area->x2;
msg.area.y2 = area->y2;
msg.disp_drv = disp_drv;
msg.color_p = color_p;
if (xSemaphoreTake(flush_sem, portMAX_DELAY) != pdTRUE) {
LV_LOG_ERROR("[%s] Failed to take flush semaphore", __FUNCTION__);
}
if (xQueueSend(flush_queue, &msg, portMAX_DELAY) != pdPASS) {
LV_LOG_ERROR("[%s] Failed to send flush message", __FUNCTION__);
}
lv_disp_flush_ready(msg.disp_drv);
#else
lisa_display_buffer_desc_t desc = {0};
/* Update descriptor for the current area */
desc.width = area->x2 - area->x1 + 1;
desc.height = area->y2 - area->y1 + 1;
desc.pitch = desc.width * sizeof(lv_color_t);
desc.buf_size = desc.height * desc.width * sizeof(lv_color_t);
#if CONFIG_LV_COLOR_DEPTH_1
uint8_t *fb_buffer_mono = (uint8_t *)disp_drv->user_data;
if (fb_buffer_mono == NULL) {
LV_LOG_ERROR("[%s] fb_buffer_mono is NULL", __FUNCTION__);
lv_disp_flush_ready(disp_drv);
return;
}
if (framebuffer_convert_to_mono(color_p, fb_buffer_mono, desc.width, desc.height) != 0) {
LV_LOG_ERROR("[%s] framebuffer_convert_to_mono faild", __FUNCTION__);
lv_disp_flush_ready(disp_drv);
return;
}
color_p = (lv_color_t *)fb_buffer_mono;
#endif
/* Write data to display */
lisa_display_write(lv_display_device, area->x1, area->y1, &desc, color_p);
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
#endif
}
#endif

View File

@@ -0,0 +1,61 @@
/**
* @file lv_port_disp_templ.h
*
*/
/*Copy this file as "lv_port_disp.h" and set this value to "1" to enable content*/
#include "lisa_device.h"
#if 1
#ifndef LV_PORT_DISP_TEMPL_H
#define LV_PORT_DISP_TEMPL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#include "lisa_display.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/* Initialize low level display driver */
void lv_port_disp_init(lisa_device_t *display_dev);
lisa_device_t *lv_port_get_display_device(void);
/* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_enable_update(void);
/* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_disable_update(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_PORT_DISP_TEMPL_H*/
#endif /*Disable/Enable content*/

View File

@@ -0,0 +1,312 @@
/**
* @file lv_fs_posix.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_port_fs.h"
#include "lisa_log.h"
#if CONFIG_LVFS_POSIX_API && CONFIG_LV_USE_FS_POSIX
#include <fcntl.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode);
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p);
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br);
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw);
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence);
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p);
static void *fs_dir_open(lv_fs_drv_t *drv, const char *path);
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn);
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Register a driver for the File system interface
*/
void lv_port_fs_init(void)
{
/*---------------------------------------------------
* Register the file system interface in LVGL
*--------------------------------------------------*/
/*Add a simple drive to open images*/
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
lv_fs_drv_init(&fs_drv);
/*Set up fields...*/
fs_drv.letter = CONFIG_LV_FS_POSIX_LETTER;
fs_drv.cache_size = 10 * 1024;
fs_drv.open_cb = fs_open;
fs_drv.close_cb = fs_close;
fs_drv.read_cb = fs_read;
fs_drv.write_cb = fs_write;
fs_drv.seek_cb = fs_seek;
fs_drv.tell_cb = fs_tell;
fs_drv.dir_close_cb = fs_dir_close;
fs_drv.dir_open_cb = fs_dir_open;
fs_drv.dir_read_cb = fs_dir_read;
lv_fs_drv_register(&fs_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Open a file
* @param drv pointer to a driver where this function belongs
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
* @return a file handle or -1 in case of fail
*/
static void *fs_open(lv_fs_drv_t *drv, const char *path, lv_fs_mode_t mode)
{
LV_UNUSED(drv);
uint32_t flags = 0;
if (mode == LV_FS_MODE_WR) {
flags = O_WRONLY | O_CREAT;
} else if (mode == LV_FS_MODE_RD) {
flags = O_RDONLY;
} else if (mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) {
flags = O_RDWR | O_CREAT;
}
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s", path);
int f = open(buf, flags, 0666);
if (f < 0) {
return NULL;
}
return (void *)(lv_uintptr_t)f;
}
/**
* Close an opened file
* @param drv pointer to a driver where this function belongs
* @param file_p a file handle. (opened with fs_open)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_close(lv_fs_drv_t *drv, void *file_p)
{
LV_UNUSED(drv);
close((lv_uintptr_t)file_p);
return LV_FS_RES_OK;
}
/**
* Read data from an opened file
* @param drv pointer to a driver where this function belongs
* @param file_p a file handle variable.
* @param buf pointer to a memory block where to store the read data
* @param btr number of Bytes To Read
* @param br the real number of read bytes (Byte Read)
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_read(lv_fs_drv_t *drv, void *file_p, void *buf, uint32_t btr, uint32_t *br)
{
LV_UNUSED(drv);
*br = read((lv_uintptr_t)file_p, buf, btr);
return (int32_t)(*br) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}
/**
* Write into a file
* @param drv pointer to a driver where this function belongs
* @param file_p a file handle variable
* @param buf pointer to a buffer with the bytes to write
* @param btw Bytes To Write
* @param bw the number of real written bytes (Bytes Written). NULL if unused.
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_write(lv_fs_drv_t *drv, void *file_p, const void *buf, uint32_t btw, uint32_t *bw)
{
LV_UNUSED(drv);
*bw = write((lv_uintptr_t)file_p, buf, btw);
return (int32_t)(*bw) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}
/**
* Set the read write pointer. Also expand the file size if necessary.
* @param drv pointer to a driver where this function belongs
* @param file_p a file handle variable. (opened with fs_open )
* @param pos the new position of read write pointer
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_seek(lv_fs_drv_t *drv, void *file_p, uint32_t pos, lv_fs_whence_t whence)
{
LV_UNUSED(drv);
off_t offset = lseek((lv_uintptr_t)file_p, pos, whence);
return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
}
/**
* Give the position of the read write pointer
* @param drv pointer to a driver where this function belongs
* @param file_p a file handle variable.
* @param pos_p pointer to to store the result
* @return LV_FS_RES_OK: no error, the file is read
* any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_tell(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p)
{
LV_UNUSED(drv);
off_t offset = lseek((lv_uintptr_t)file_p, 0, SEEK_CUR);
*pos_p = offset;
return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
}
#ifdef WIN32
static char next_fn[256];
#endif
/**
* Initialize a 'fs_read_dir_t' variable for directory reading
* @param drv pointer to a driver where this function belongs
* @param path path to a directory
* @return pointer to an initialized 'DIR' or 'HANDLE' variable
*/
static void *fs_dir_open(lv_fs_drv_t *drv, const char *path)
{
LV_UNUSED(drv);
#ifndef WIN32
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s", path);
return opendir(buf);
#else
HANDLE d = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA fdata;
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s\\*", path);
strcpy(next_fn, "");
d = FindFirstFile(buf, &fdata);
do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue;
} else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName);
} else {
sprintf(next_fn, "%s", fdata.cFileName);
}
break;
}
} while (FindNextFileA(d, &fdata));
return d;
#endif
}
/**
* Read the next filename from a directory.
* The name of the directories will begin with '/'
* @param drv pointer to a driver where this function belongs
* @param dir_p pointer to an initialized 'DIR' or 'HANDLE' variable
* @param fn pointer to a buffer to store the filename
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_read(lv_fs_drv_t *drv, void *dir_p, char *fn)
{
LV_UNUSED(drv);
#ifndef WIN32
struct dirent *entry;
do {
entry = readdir(dir_p);
if (entry) {
if (entry->d_type == DT_DIR) {
sprintf(fn, "/%s", entry->d_name);
} else {
strcpy(fn, entry->d_name);
}
} else {
strcpy(fn, "");
}
} while (strcmp(fn, "/.") == 0 || strcmp(fn, "/..") == 0);
#else
strcpy(fn, next_fn);
strcpy(next_fn, "");
WIN32_FIND_DATA fdata;
if (FindNextFile(dir_p, &fdata) == false) {
return LV_FS_RES_OK;
}
do {
if (strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
continue;
} else {
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
sprintf(next_fn, "/%s", fdata.cFileName);
} else {
sprintf(next_fn, "%s", fdata.cFileName);
}
break;
}
} while (FindNextFile(dir_p, &fdata));
#endif
return LV_FS_RES_OK;
}
/**
* Close the directory reading
* @param drv pointer to a driver where this function belongs
* @param dir_p pointer to an initialized 'DIR' or 'HANDLE' variable
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
*/
static lv_fs_res_t fs_dir_close(lv_fs_drv_t *drv, void *dir_p)
{
LV_UNUSED(drv);
#ifndef WIN32
closedir(dir_p);
#else
FindClose(dir_p);
#endif
return LV_FS_RES_OK;
}
#else /*LV_USE_FS_POSIX == 0*/
#endif /*LV_USE_FS_POSIX*/

View File

@@ -0,0 +1,38 @@
/**
* @file lv_port_fs_templ.h
*
*/
#ifndef __LV_PORT_FS_H__
#define __LV_PORT_FS_H__
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
void lv_port_fs_init(void);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __LV_PORT_FS_H__ */

View File

@@ -0,0 +1,199 @@
/**
* @file lv_port_indev.c
*
*/
#if 1
/*********************
* INCLUDES
*********************/
#include "lv_port_indev.h"
#include "lisa_touch.h"
#include "lisa_device.h"
#include "lisa_display.h"
#include <FreeRTOS.h>
#include <semphr.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
struct touch_msg {
uint16_t x;
uint16_t y;
bool pressed;
};
/**********************
* STATIC PROTOTYPES
**********************/
static void touchpad_init(lisa_device_t *touch_dev);
static void touchpad_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static void touchpad_transform_coordinates(lv_coord_t *x, lv_coord_t *y);
/**********************
* STATIC VARIABLES
**********************/
static lisa_device_t *touch_device = NULL;
static lv_indev_drv_t indev_drv;
static uint16_t last_x = 0;
static uint16_t last_y = 0;
static uint8_t last_state = 0;
static SemaphoreHandle_t touchpad_sem = NULL;
static QueueHandle_t touchpad_queue = NULL;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* @brief Touch interrupt callback function
*
* This callback is called from interrupt context when touch event occurs.
* It should be kept as short as possible.
*/
static void touch_int_callback(const lisa_touch_event_t *event, void *user_data)
{
struct touch_msg msg;
static bool last_pressed = false;
if (event->type == LISA_TOUCH_EVENT_PRESS && event->point_count > 0) {
msg.x = event->points[0].x;
msg.y = event->points[0].y;
msg.pressed = true;
last_pressed = true;
} else if (event->type == LISA_TOUCH_EVENT_RELEASE) {
if (last_pressed) {
msg.pressed = false;
last_pressed = false;
}
}
xQueueSend(touchpad_queue, &msg, portMAX_DELAY);
}
void lv_port_indev_init(lisa_device_t *touch_dev)
{
/*Initialize your touchpad*/
touchpad_init(touch_dev);
if (touch_device == NULL) {
return;
}
/*Register a touchpad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_read;
lv_indev_drv_register(&indev_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/*Initialize your touchpad*/
static void touchpad_init(lisa_device_t *touch_dev)
{
touch_device = touch_dev;
if (touch_device == NULL) {
return;
}
int ret = lisa_touch_set_callback(touch_dev, touch_int_callback, NULL);
if (ret != 0) {
printf("Error: Touch callback set failed (code: %d)\n", ret);
return;
}
ret = lisa_touch_set_int_mode(touch_dev, LISA_TOUCH_INT_MODE_INTERRUPT);
if (ret != 0) {
printf("Error: Touch interrupt mode set failed (code: %d)\n", ret);
return;
}
ret = lisa_touch_enable(touch_dev);
if (ret != 0) {
printf("Error: Touch enable failed (code: %d)\n", ret);
return;
}
touchpad_sem = xSemaphoreCreateBinary();
touchpad_queue = xQueueCreate(CONFIG_LS_LV_INDEV_TASK_QUEUE_SIZE, sizeof(struct touch_msg));
}
/* Will be called by the library to read the touchpad */
static void touchpad_read(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
struct touch_msg msg;
if (xQueueReceive(touchpad_queue, &msg, 0) == pdPASS) {
data->point.x = (lv_coord_t)msg.x;
data->point.y = (lv_coord_t)msg.y;
data->state = msg.pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->continue_reading = (uxQueueMessagesWaiting(touchpad_queue) > 0 ? 1 : 0);
touchpad_transform_coordinates(&data->point.x, &data->point.y);
last_x = data->point.x;
last_y = data->point.y;
last_state = data->state;
return;
}
data->point.x = (lv_coord_t)last_x;
data->point.y = (lv_coord_t)last_y;
data->state = last_state;
data->continue_reading = 0;
}
/**
* @brief 触摸坐标系转换
* @param x 输入/输出 X 坐标
* @param y 输入/输出 Y 坐标
*
* @note 该函数处理硬件坐标系校正(触摸屏与显示屏坐标系不一致)
*/
static void touchpad_transform_coordinates(lv_coord_t *x, lv_coord_t *y)
{
if (!x || !y) {
return;
}
extern lisa_device_t *lv_display_device;
lisa_display_capabilities_t caps = {0};
lisa_display_get_capabilities(lv_display_device, &caps);
#if CONFIG_LV_POINTER_SWAP_XY
lv_coord_t cur_x = *y;
lv_coord_t cur_y = *x;
#else
lv_coord_t cur_x = *x;
lv_coord_t cur_y = *y;
#endif
#if CONFIG_LV_POINTER_INVERT_X
cur_x = caps.x_resolution - cur_x;
#endif
#if CONFIG_LV_POINTER_INVERT_Y
cur_y = caps.y_resolution - cur_y;
#endif
*x = cur_x;
*y = cur_y;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif

View File

@@ -0,0 +1,46 @@
/**
* @file lv_port_indev.h
*
*/
/*Copy this file as "lv_port_indev.h" and set this value to "1" to enable content*/
#if 1
#ifndef LV_PORT_INDEV_TEMPL_H
#define LV_PORT_INDEV_TEMPL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl.h"
#include "lisa_touch.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**********************
* MACROS
**********************/
void lv_port_indev_init(lisa_device_t *touch_dev);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_PORT_INDEV_TEMPL_H*/
#endif /*Disable/Enable content*/

View File

@@ -0,0 +1,224 @@
#include "lv_port_mem.h"
#if CONFIG_LV_DEMO_SYS_HEAP
#include "sysheap.h"
#else
#include "xutils.h"
#endif
#include "esp_heap_caps.h"
#include "multi_heap.h"
#include "lisa_log.h"
#define TAG "lvgl_heap"
#define MEM_BASE_CAPS (MALLOC_CAP_32BIT | MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_EXEC)
/* 使用Kconfig配置LVGL heap大小 */
#if CONFIG_LV_DEMO_SYS_HEAP
#ifdef CONFIG_LVGL_HEAP_SIZE
#define LVGL_HEAP_SIZE CONFIG_LVGL_HEAP_SIZE
#else
#define LVGL_HEAP_SIZE (1 * 1024 * 1024) /* 默认1MB */
#endif
static uint8_t lvgl_port_mem[LVGL_HEAP_SIZE] __attribute__((section(".psram.bss")));
#endif
/* 内存统计 */
static struct {
size_t total_size;
size_t alloc_count;
size_t free_count;
size_t realloc_count;
size_t failed_count;
size_t peak_used; /* 历史最大使用量 */
size_t min_free; /* 历史最小剩余量 */
} lvgl_mem_stats = {0};
int lvgl_port_mem_init(void)
{
#if CONFIG_LV_DEMO_SYS_HEAP
static bool initialized = false;
/* 防止重复初始化 */
if (initialized) {
LISA_LOGW(TAG, "LVGL heap already initialized, skipping");
return 0;
}
const uint32_t psram_caps[] = {
MEM_BASE_CAPS | MALLOC_CAP_PID2,
MEM_BASE_CAPS | MALLOC_CAP_PID2,
0,
};
/* 初始化内存统计 */
lvgl_mem_stats.total_size = LVGL_HEAP_SIZE;
lvgl_mem_stats.alloc_count = 0;
lvgl_mem_stats.free_count = 0;
lvgl_mem_stats.realloc_count = 0;
lvgl_mem_stats.failed_count = 0;
lvgl_mem_stats.peak_used = 0;
lvgl_mem_stats.min_free = LVGL_HEAP_SIZE; /* 初始为总大小 */
/* 添加LVGL独立heap到heap_caps系统 */
heap_caps_add_region_with_caps(psram_caps, (intptr_t)lvgl_port_mem,
(intptr_t)lvgl_port_mem + sizeof(lvgl_port_mem));
initialized = true;
LISA_LOGI(TAG, "LVGL heap initialized: %d bytes at 0x%p", LVGL_HEAP_SIZE, lvgl_port_mem);
return 0;
#else
LISA_LOGW(TAG, "LVGL independent heap is disabled");
return -1;
#endif
}
void *lvgl_port_malloc(size_t size)
{
void *ptr = heap_caps_malloc(size, MALLOC_CAP_PID2);
if (ptr) {
lvgl_mem_stats.alloc_count++;
/* 更新历史峰值统计 */
size_t free_size = heap_caps_get_free_size(MALLOC_CAP_PID2);
size_t used_size = lvgl_mem_stats.total_size - free_size;
if (used_size > lvgl_mem_stats.peak_used) {
lvgl_mem_stats.peak_used = used_size;
}
if (free_size < lvgl_mem_stats.min_free) {
lvgl_mem_stats.min_free = free_size;
}
} else {
lvgl_mem_stats.failed_count++;
/* 获取heap状态用于调试 */
size_t free_size = heap_caps_get_free_size(MALLOC_CAP_PID2);
size_t largest_free = heap_caps_get_largest_free_block(MALLOC_CAP_PID2);
LISA_LOGE(TAG, "malloc FAILED: size=%d, free=%d, largest_free=%d, alloc=%d, free=%d, failed=%d",
size, free_size, largest_free,
lvgl_mem_stats.alloc_count, lvgl_mem_stats.free_count,
lvgl_mem_stats.failed_count);
/* 打印详细heap统计 */
lvgl_port_mem_print_stats();
}
return ptr;
}
void *lvgl_port_realloc(void *ptr, size_t size)
{
void *new_ptr = heap_caps_realloc(ptr, size, MALLOC_CAP_PID2);
if (new_ptr) {
lvgl_mem_stats.realloc_count++;
/* 更新历史峰值统计 */
size_t free_size = heap_caps_get_free_size(MALLOC_CAP_PID2);
size_t used_size = lvgl_mem_stats.total_size - free_size;
if (used_size > lvgl_mem_stats.peak_used) {
lvgl_mem_stats.peak_used = used_size;
}
if (free_size < lvgl_mem_stats.min_free) {
lvgl_mem_stats.min_free = free_size;
}
} else {
lvgl_mem_stats.failed_count++;
LISA_LOGW(TAG, "realloc failed: size=%d", size);
}
return new_ptr;
}
void lvgl_port_free(void *ptr)
{
if (ptr) {
lvgl_mem_stats.free_count++;
heap_caps_free(ptr);
}
}
/* 获取LVGL heap统计信息 */
void lvgl_port_mem_get_stats(size_t *total, size_t *alloc_cnt, size_t *free_cnt, size_t *failed_cnt)
{
if (total) *total = lvgl_mem_stats.total_size;
if (alloc_cnt) *alloc_cnt = lvgl_mem_stats.alloc_count;
if (free_cnt) *free_cnt = lvgl_mem_stats.free_count;
if (failed_cnt) *failed_cnt = lvgl_mem_stats.failed_count;
}
/* 打印LVGL heap统计信息 */
void lvgl_port_mem_print_stats(void)
{
size_t free_size = heap_caps_get_free_size(MALLOC_CAP_PID2);
size_t largest_free = heap_caps_get_largest_free_block(MALLOC_CAP_PID2);
size_t used_size = lvgl_mem_stats.total_size - free_size;
LISA_LOGI(TAG, "========== LVGL Heap Statistics ==========");
LISA_LOGI(TAG, "Total size: %d bytes (%.2f MB)",
lvgl_mem_stats.total_size, lvgl_mem_stats.total_size / (1024.0 * 1024.0));
LISA_LOGI(TAG, "Used size: %d bytes (%.2f MB, %.1f%%)",
used_size, used_size / (1024.0 * 1024.0),
(used_size * 100.0) / lvgl_mem_stats.total_size);
LISA_LOGI(TAG, "Free size: %d bytes (%.2f MB, %.1f%%)",
free_size, free_size / (1024.0 * 1024.0),
(free_size * 100.0) / lvgl_mem_stats.total_size);
LISA_LOGI(TAG, "Largest free: %d bytes (%.2f KB)",
largest_free, largest_free / 1024.0);
LISA_LOGI(TAG, "--- Historical Peak Statistics ---");
LISA_LOGI(TAG, "Peak used: %d bytes (%.2f MB, %.1f%%)",
lvgl_mem_stats.peak_used, lvgl_mem_stats.peak_used / (1024.0 * 1024.0),
(lvgl_mem_stats.peak_used * 100.0) / lvgl_mem_stats.total_size);
LISA_LOGI(TAG, "Min free: %d bytes (%.2f KB)",
lvgl_mem_stats.min_free, lvgl_mem_stats.min_free / 1024.0);
LISA_LOGI(TAG, "--- Operation Statistics ---");
LISA_LOGI(TAG, "Alloc count: %d", lvgl_mem_stats.alloc_count);
LISA_LOGI(TAG, "Free count: %d", lvgl_mem_stats.free_count);
LISA_LOGI(TAG, "Realloc count: %d", lvgl_mem_stats.realloc_count);
LISA_LOGI(TAG, "Failed count: %d", lvgl_mem_stats.failed_count);
LISA_LOGI(TAG, "=========================================");
}
/* LVGL heap monitor thread (temporary debug) */
#include "FreeRTOS.h"
#include "task.h"
static void lvgl_heap_monitor_task(void *arg)
{
(void)arg;
LISA_LOGI(TAG, "LVGL heap monitor task started");
while (1) {
/* Sleep for 5 seconds */
vTaskDelay(pdMS_TO_TICKS(5000));
/* Print heap statistics */
lvgl_port_mem_print_stats();
}
}
void lvgl_heap_monitor_start(void)
{
BaseType_t ret;
ret = xTaskCreate(lvgl_heap_monitor_task,
"lvgl_heap_mon",
2048, /* Stack size in words */
NULL,
5, /* Priority */
NULL);
if (ret != pdPASS) {
LISA_LOGE(TAG, "Failed to create LVGL heap monitor task");
}
}

View File

@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef PORT_GUI_LVGL_MEM_H_
#define LV_PORT_MEM_H
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
int lvgl_port_mem_init(void);
void *lvgl_port_malloc(size_t size);
void *lvgl_port_realloc(void *ptr, size_t size);
void lvgl_port_free(void *ptr);
/**
* @brief Get LVGL heap statistics
* @param total Total heap size
* @param alloc_cnt Allocation count
* @param free_cnt Free count
* @param failed_cnt Failed allocation count
*/
void lvgl_port_mem_get_stats(size_t *total, size_t *alloc_cnt, size_t *free_cnt, size_t *failed_cnt);
/**
* @brief Print LVGL heap statistics to log
*/
void lvgl_port_mem_print_stats(void);
/**
* @brief Start LVGL heap monitor thread (prints stats every 5 seconds)
*/
void lvgl_heap_monitor_start(void);
#ifdef __cplusplus
}
#endif
#endif /* PORT_GUI_LVGL_MEM_H_ */