mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update
This commit is contained in:
169
software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c
Normal file
169
software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* @file lv_port_disp_templ.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*Copy this file as "lv_port_disp.c" and set this value to "1" to enable content*/
|
||||
#if 1
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_port_disp.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
// lcd
|
||||
#include "lcd.h"
|
||||
#include "lcd_init.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef MY_DISP_HOR_RES
|
||||
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen width, default value 320 is used for now.
|
||||
#define MY_DISP_HOR_RES 240
|
||||
#endif
|
||||
|
||||
#ifndef MY_DISP_VER_RES
|
||||
#warning Please define or replace the macro MY_DISP_VER_RES with the actual screen height, default value 240 is used for now.
|
||||
#define MY_DISP_VER_RES 240
|
||||
#endif
|
||||
|
||||
#define BYTE_PER_PIXEL (LV_COLOR_FORMAT_GET_SIZE(LV_COLOR_FORMAT_RGB565)) /*will be 2 for RGB565 */
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void disp_init(void);
|
||||
|
||||
static void disp_flush(lv_display_t * disp, const lv_area_t * area, uint8_t * px_map);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
// 1. 定义一个静态变量来保存当前的 driver 句柄
|
||||
static lv_display_t *g_current_disp_drv = NULL;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_port_disp_init(void)
|
||||
{
|
||||
/*-------------------------
|
||||
* Initialize your display
|
||||
* -----------------------*/
|
||||
disp_init();
|
||||
|
||||
/*------------------------------------
|
||||
* Create a display and set a flush_cb
|
||||
* -----------------------------------*/
|
||||
lv_display_t * disp = lv_display_create(MY_DISP_HOR_RES, MY_DISP_VER_RES);
|
||||
lv_display_set_flush_cb(disp, disp_flush);
|
||||
g_current_disp_drv = disp;
|
||||
#define BUFFER_METHOD 1
|
||||
#if BUFFER_METHOD == 1
|
||||
/* Example 1
|
||||
* One buffer for partial rendering*/
|
||||
LV_ATTRIBUTE_MEM_ALIGN
|
||||
static uint8_t buf_1_1[MY_DISP_HOR_RES * MY_DISP_VER_RES / 4 * BYTE_PER_PIXEL];
|
||||
lv_display_set_buffers(disp, buf_1_1, NULL, sizeof(buf_1_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
#elif BUFFER_METHOD == 2
|
||||
|
||||
/* Example 2
|
||||
* Two buffers for partial rendering
|
||||
* In flush_cb DMA or similar hardware should be used to update the display in the background.*/
|
||||
LV_ATTRIBUTE_MEM_ALIGN
|
||||
static uint8_t buf_2_1[MY_DISP_HOR_RES * MY_DISP_VER_RES / 8 * BYTE_PER_PIXEL];
|
||||
|
||||
LV_ATTRIBUTE_MEM_ALIGN
|
||||
static uint8_t buf_2_2[MY_DISP_HOR_RES * MY_DISP_VER_RES / 8 * BYTE_PER_PIXEL];
|
||||
lv_display_set_buffers(disp, buf_2_1, buf_2_2, sizeof(buf_2_1), LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
|
||||
#elif BUFFER_METHOD == 3
|
||||
/* Example 3
|
||||
* Two buffers screen sized buffer for double buffering.
|
||||
* Both LV_DISPLAY_RENDER_MODE_DIRECT and LV_DISPLAY_RENDER_MODE_FULL works, see their comments*/
|
||||
LV_ATTRIBUTE_MEM_ALIGN
|
||||
static uint8_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES * BYTE_PER_PIXEL];
|
||||
|
||||
LV_ATTRIBUTE_MEM_ALIGN
|
||||
static uint8_t buf_3_2[MY_DISP_HOR_RES * MY_DISP_VER_RES * BYTE_PER_PIXEL];
|
||||
lv_display_set_buffers(disp, buf_3_1, buf_3_2, sizeof(buf_3_1), LV_DISPLAY_RENDER_MODE_DIRECT);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lcd_flush_ready_callback(void)
|
||||
{
|
||||
if (g_current_disp_drv != NULL) {
|
||||
lv_display_flush_ready(g_current_disp_drv);
|
||||
}
|
||||
}
|
||||
|
||||
/*Initialize your display and the required peripherals.*/
|
||||
static void disp_init(void)
|
||||
{
|
||||
/*You code here*/
|
||||
LCD_Init();
|
||||
LCD_Fill(0,0, LCD_W, LCD_H, BLACK);
|
||||
LCD_Close_Light();
|
||||
LCD_Set_Flush_Complete_Callback(lcd_flush_ready_callback);
|
||||
}
|
||||
|
||||
volatile bool disp_flush_enabled = true;
|
||||
|
||||
/* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
|
||||
*/
|
||||
void disp_enable_update(void)
|
||||
{
|
||||
disp_flush_enabled = true;
|
||||
}
|
||||
|
||||
/* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
|
||||
*/
|
||||
void disp_disable_update(void)
|
||||
{
|
||||
disp_flush_enabled = false;
|
||||
}
|
||||
|
||||
/*Flush the content of the internal buffer the specific area on the display.
|
||||
*`px_map` contains the rendered image as raw pixel map and it should be copied to `area` on the display.
|
||||
*You can use DMA or any hardware acceleration to do this operation in the background but
|
||||
*'lv_display_flush_ready()' has to be called when it's finished.*/
|
||||
static void disp_flush(lv_display_t * disp_drv, const lv_area_t * area, uint8_t * px_map)
|
||||
{
|
||||
static lv_display_rotation_t last_rotation = LV_DISPLAY_ROTATION_0;
|
||||
lv_display_rotation_t current_rotation = lv_display_get_rotation(disp_drv);
|
||||
lv_area_t rotated_area;
|
||||
if (current_rotation != last_rotation) {
|
||||
LCD_SetRotation(current_rotation * 90); // 仅在旋转状态改变时调用
|
||||
last_rotation = current_rotation; // 更新上次状态
|
||||
}
|
||||
if(disp_flush_enabled) {
|
||||
LCD_Color_Render_Async(area->x1,area->y1,area->x2,area->y2, (uint16_t *)px_map);
|
||||
}
|
||||
|
||||
/*IMPORTANT!!!
|
||||
*Inform the graphics library that you are ready with the flushing*/
|
||||
// lv_display_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
#else /*Enable this file at the top*/
|
||||
|
||||
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
||||
typedef int keep_pedantic_happy;
|
||||
#endif
|
||||
58
software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.h
Normal file
58
software/Power_Pico/Middlewares/LVGL/porting/lv_port_disp.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file lv_port_disp_templ.h
|
||||
*
|
||||
*/
|
||||
|
||||
/*Copy this file as "lv_port_disp.h" and set this value to "1" to enable content*/
|
||||
#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"
|
||||
#include "lvgl.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/* Initialize low level display driver */
|
||||
void lv_port_disp_init(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*/
|
||||
Reference in New Issue
Block a user