add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,157 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port
*/
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#include "esp_lvgl_port_disp.h"
#include "esp_lvgl_port_touch.h"
#include "esp_lvgl_port_knob.h"
#include "esp_lvgl_port_button.h"
#include "esp_lvgl_port_usbhid.h"
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief LVGL Port task event type
*/
typedef enum {
LVGL_PORT_EVENT_DISPLAY = 0x01,
LVGL_PORT_EVENT_TOUCH = 0x02,
LVGL_PORT_EVENT_USER = 0x80,
} lvgl_port_event_type_t;
/**
* @brief LVGL Port task events
*/
typedef struct {
lvgl_port_event_type_t type;
void *param;
} lvgl_port_event_t;
/**
* @brief Init configuration structure
*/
typedef struct {
int task_priority; /*!< LVGL task priority */
int task_stack; /*!< LVGL task stack size */
int task_affinity; /*!< LVGL task pinned to core (-1 is no affinity) */
int task_max_sleep_ms; /*!< Maximum sleep in LVGL task */
int timer_period_ms; /*!< LVGL timer tick period in ms */
} lvgl_port_cfg_t;
/**
* @brief LVGL port configuration structure
*
*/
#define ESP_LVGL_PORT_INIT_CONFIG() \
{ \
.task_priority = 4, \
.task_stack = 7168, \
.task_affinity = -1, \
.task_max_sleep_ms = 500, \
.timer_period_ms = 5, \
}
/**
* @brief Initialize LVGL portation
*
* @note This function initialize LVGL and create timer and task for LVGL right working.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if some of the create_args are not valid
* - ESP_ERR_INVALID_STATE if esp_timer library is not initialized yet
* - ESP_ERR_NO_MEM if memory allocation fails
*/
esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg);
/**
* @brief Deinitialize LVGL portation
*
* @note This function deinitializes LVGL and stops the task if running.
* Some deinitialization will be done after the task will be stopped.
*
* @return
* - ESP_OK on success
* - ESP_ERR_TIMEOUT when stopping the LVGL task times out
*/
esp_err_t lvgl_port_deinit(void);
/**
* @brief Take LVGL mutex
*
* @param timeout_ms Timeout in [ms]. 0 will block indefinitely.
* @return
* - true Mutex was taken
* - false Mutex was NOT taken
*/
bool lvgl_port_lock(uint32_t timeout_ms);
/**
* @brief Give LVGL mutex
*
*/
void lvgl_port_unlock(void);
/**
* @brief Notify LVGL, that data was flushed to LCD display
*
* @note It should be used only when not called inside LVGL port (more in README).
*
* @param disp LVGL display handle (returned from lvgl_port_add_disp)
*/
void lvgl_port_flush_ready(lv_display_t *disp);
/**
* @brief Stop lvgl timer
*
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if the timer is not running
*/
esp_err_t lvgl_port_stop(void);
/**
* @brief Resume lvgl timer
*
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if the timer is not running
*/
esp_err_t lvgl_port_resume(void);
/**
* @brief Notify LVGL task, that display need reload
*
* @note It is called from LVGL events and touch interrupts
*
* @param event event type
* @param param parameter is not used, keep for backwards compatibility
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if it is not implemented
* - ESP_ERR_INVALID_STATE if queue is not initialized (can be returned after LVGL deinit)
*/
esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,70 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port button
*/
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#if __has_include ("iot_button.h")
#include "iot_button.h"
#define ESP_LVGL_PORT_BUTTON_COMPONENT 1
#endif
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_LVGL_PORT_BUTTON_COMPONENT
/**
* @brief Configuration of the navigation buttons structure
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
#if BUTTON_VER_MAJOR < 4
const button_config_t *button_prev; /*!< Navigation button for previous */
const button_config_t *button_next; /*!< Navigation button for next */
const button_config_t *button_enter; /*!< Navigation button for enter */
#else
button_handle_t button_prev; /*!< Handle for navigation button for previous */
button_handle_t button_next; /*!< Handle for navigation button for next */
button_handle_t button_enter; /*!< Handle for navigation button for enter */
#endif
} lvgl_port_nav_btns_cfg_t;
/**
* @brief Add buttons as an input device
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_navigation_buttons for free all memory!
*
* @param buttons_cfg Buttons configuration structure
* @return Pointer to LVGL buttons input device or NULL when error occurred
*/
lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *buttons_cfg);
/**
* @brief Remove selected buttons from input devices
*
* @note Free all memory used for this input device.
*
* @return
* - ESP_OK on success
*/
esp_err_t lvgl_port_remove_navigation_buttons(lv_indev_t *buttons);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port compatibility
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Backward compatibility with LVGL 8
*/
typedef lv_disp_t lv_display_t;
typedef enum {
LV_DISPLAY_ROTATION_0 = LV_DISP_ROT_NONE,
LV_DISPLAY_ROTATION_90 = LV_DISP_ROT_90,
LV_DISPLAY_ROTATION_180 = LV_DISP_ROT_180,
LV_DISPLAY_ROTATION_270 = LV_DISP_ROT_270
} lv_disp_rotation_t;
typedef lv_disp_rotation_t lv_display_rotation_t;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,132 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port display
*/
#pragma once
#include "esp_err.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "lvgl.h"
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Rotation configuration
*/
typedef struct {
bool swap_xy; /*!< LCD Screen swapped X and Y (in esp_lcd driver) */
bool mirror_x; /*!< LCD Screen mirrored X (in esp_lcd driver) */
bool mirror_y; /*!< LCD Screen mirrored Y (in esp_lcd driver) */
} lvgl_port_rotation_cfg_t;
/**
* @brief Configuration display structure
*/
typedef struct {
esp_lcd_panel_io_handle_t io_handle; /*!< LCD panel IO handle */
esp_lcd_panel_handle_t panel_handle; /*!< LCD panel handle */
esp_lcd_panel_handle_t control_handle; /*!< LCD panel control handle */
uint32_t buffer_size; /*!< Size of the buffer for the screen in pixels */
bool double_buffer; /*!< True, if should be allocated two buffers */
uint32_t trans_size; /*!< Allocated buffer will be in SRAM to move framebuf (optional) */
uint32_t hres; /*!< LCD display horizontal resolution */
uint32_t vres; /*!< LCD display vertical resolution */
bool monochrome; /*!< True, if display is monochrome and using 1bit for 1px */
lvgl_port_rotation_cfg_t rotation; /*!< Default values of the screen rotation (Only HW state. Not supported for default SW rotation!) */
#if LVGL_VERSION_MAJOR >= 9
lv_color_format_t color_format; /*!< The color format of the display */
#endif
struct {
unsigned int buff_dma: 1; /*!< Allocated LVGL buffer will be DMA capable */
unsigned int buff_spiram: 1; /*!< Allocated LVGL buffer will be in PSRAM */
unsigned int sw_rotate: 1; /*!< Use software rotation (slower) or PPA if available */
#if LVGL_VERSION_MAJOR >= 9
unsigned int swap_bytes: 1; /*!< Swap bytes in RGB565 (16-bit) color format before send to LCD driver */
#endif
unsigned int full_refresh: 1;/*!< 1: Always make the whole screen redrawn */
unsigned int direct_mode: 1; /*!< 1: Use screen-sized buffers and draw to absolute coordinates */
} flags;
} lvgl_port_display_cfg_t;
/**
* @brief Configuration RGB display structure
*/
typedef struct {
struct {
unsigned int bb_mode: 1; /*!< 1: Use bounce buffer mode */
unsigned int avoid_tearing: 1; /*!< 1: Use internal RGB buffers as a LVGL draw buffers to avoid tearing effect, enabling this option requires over two LCD buffers and may reduce the frame rate */
} flags;
} lvgl_port_display_rgb_cfg_t;
/**
* @brief Configuration MIPI-DSI display structure
*/
typedef struct {
struct {
unsigned int avoid_tearing: 1; /*!< 1: Use internal MIPI-DSI buffers as a LVGL draw buffers to avoid tearing effect, enabling this option requires over two LCD buffers and may reduce the frame rate */
} flags;
} lvgl_port_display_dsi_cfg_t;
/**
* @brief Add I2C/SPI/I8080 display handling to LVGL
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_disp for free all memory!
*
* @param disp_cfg Display configuration structure
* @return Pointer to LVGL display or NULL when error occurred
*/
lv_display_t *lvgl_port_add_disp(const lvgl_port_display_cfg_t *disp_cfg);
/**
* @brief Add MIPI-DSI display handling to LVGL
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_disp for free all memory!
*
* @param disp_cfg Display configuration structure
* @param dsi_cfg MIPI-DSI display specific configuration structure
* @return Pointer to LVGL display or NULL when error occurred
*/
lv_display_t *lvgl_port_add_disp_dsi(const lvgl_port_display_cfg_t *disp_cfg, const lvgl_port_display_dsi_cfg_t *dsi_cfg);
/**
* @brief Add RGB display handling to LVGL
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_disp for free all memory!
*
* @param disp_cfg Display configuration structure
* @param rgb_cfg RGB display specific configuration structure
* @return Pointer to LVGL display or NULL when error occurred
*/
lv_display_t *lvgl_port_add_disp_rgb(const lvgl_port_display_cfg_t *disp_cfg, const lvgl_port_display_rgb_cfg_t *rgb_cfg);
/**
* @brief Remove display handling from LVGL
*
* @note Free all memory used for this display.
*
* @return
* - ESP_OK on success
*/
esp_err_t lvgl_port_remove_disp(lv_display_t *disp);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,71 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port knob
*/
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#if __has_include ("iot_knob.h")
#if !__has_include("iot_button.h")
#error LVLG Knob requires button component. Please add it with idf.py add-dependency espressif/button
#endif
#include "iot_knob.h"
#include "iot_button.h"
#define ESP_LVGL_PORT_KNOB_COMPONENT 1
#endif
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_LVGL_PORT_KNOB_COMPONENT
/**
* @brief Configuration of the encoder structure
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
const knob_config_t *encoder_a_b; /*!< Encoder knob configuration */
#if BUTTON_VER_MAJOR < 4
const button_config_t *encoder_enter; /*!< Navigation button for enter */
#else
button_handle_t encoder_enter; /*!< Handle for enter button */
#endif
} lvgl_port_encoder_cfg_t;
/**
* @brief Add encoder as an input device
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_encoder for free all memory!
*
* @param encoder_cfg Encoder configuration structure
* @return Pointer to LVGL encoder input device or NULL when error occurred
*/
lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg);
/**
* @brief Remove encoder from input devices
*
* @note Free all memory used for this input device.
*
* @return
* - ESP_OK on success
*/
esp_err_t lvgl_port_remove_encoder(lv_indev_t *encoder);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,158 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#if !CONFIG_LV_DRAW_SW_ASM_CUSTOM
#warning "esp_lvgl_port_lv_blend.h included, but CONFIG_LV_DRAW_SW_ASM_CUSTOM not set. Assembly rendering not used"
#else
/*********************
* DEFINES
*********************/
#ifndef LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888
#define LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888(dsc) \
_lv_color_blend_to_argb8888_esp(dsc)
#endif
#ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB565
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB565(dsc) \
_lv_color_blend_to_rgb565_esp(dsc)
#endif
#ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB888
#define LV_DRAW_SW_COLOR_BLEND_TO_RGB888(dsc, dest_px_size) \
_lv_color_blend_to_rgb888_esp(dsc, dest_px_size)
#endif
#ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565
#define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565(dsc) \
_lv_rgb565_blend_normal_to_rgb565_esp(dsc)
#endif
#ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB888
#define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB888(dsc, dest_px_size, src_px_size) \
_lv_rgb888_blend_normal_to_rgb888_esp(dsc, dest_px_size, src_px_size)
#endif
/**********************
* TYPEDEFS
**********************/
typedef struct {
uint32_t opa;
void *dst_buf;
uint32_t dst_w;
uint32_t dst_h;
uint32_t dst_stride;
const void *src_buf;
uint32_t src_stride;
const lv_opa_t *mask_buf;
uint32_t mask_stride;
} asm_dsc_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
extern int lv_color_blend_to_argb8888_esp(asm_dsc_t *asm_dsc);
static inline lv_result_t _lv_color_blend_to_argb8888_esp(_lv_draw_sw_blend_fill_dsc_t *dsc)
{
asm_dsc_t asm_dsc = {
.dst_buf = dsc->dest_buf,
.dst_w = dsc->dest_w,
.dst_h = dsc->dest_h,
.dst_stride = dsc->dest_stride,
.src_buf = &dsc->color,
};
return lv_color_blend_to_argb8888_esp(&asm_dsc);
}
extern int lv_color_blend_to_rgb565_esp(asm_dsc_t *asm_dsc);
static inline lv_result_t _lv_color_blend_to_rgb565_esp(_lv_draw_sw_blend_fill_dsc_t *dsc)
{
asm_dsc_t asm_dsc = {
.dst_buf = dsc->dest_buf,
.dst_w = dsc->dest_w,
.dst_h = dsc->dest_h,
.dst_stride = dsc->dest_stride,
.src_buf = &dsc->color,
};
return lv_color_blend_to_rgb565_esp(&asm_dsc);
}
extern int lv_color_blend_to_rgb888_esp(asm_dsc_t *asm_dsc);
static inline lv_result_t _lv_color_blend_to_rgb888_esp(_lv_draw_sw_blend_fill_dsc_t *dsc, uint32_t dest_px_size)
{
if (dest_px_size != 3) {
return LV_RESULT_INVALID;
}
asm_dsc_t asm_dsc = {
.dst_buf = dsc->dest_buf,
.dst_w = dsc->dest_w,
.dst_h = dsc->dest_h,
.dst_stride = dsc->dest_stride,
.src_buf = &dsc->color,
};
return lv_color_blend_to_rgb888_esp(&asm_dsc);
}
extern int lv_rgb565_blend_normal_to_rgb565_esp(asm_dsc_t *asm_dsc);
static inline lv_result_t _lv_rgb565_blend_normal_to_rgb565_esp(_lv_draw_sw_blend_image_dsc_t *dsc)
{
asm_dsc_t asm_dsc = {
.dst_buf = dsc->dest_buf,
.dst_w = dsc->dest_w,
.dst_h = dsc->dest_h,
.dst_stride = dsc->dest_stride,
.src_buf = dsc->src_buf,
.src_stride = dsc->src_stride
};
return lv_rgb565_blend_normal_to_rgb565_esp(&asm_dsc);
}
extern int lv_rgb888_blend_normal_to_rgb888_esp(asm_dsc_t *asm_dsc);
static inline lv_result_t _lv_rgb888_blend_normal_to_rgb888_esp(_lv_draw_sw_blend_image_dsc_t *dsc, uint32_t dest_px_size, uint32_t src_px_size)
{
if (!(dest_px_size == 3 && src_px_size == 3)) {
return LV_RESULT_INVALID;
}
asm_dsc_t asm_dsc = {
.dst_buf = dsc->dest_buf,
.dst_w = dsc->dest_w,
.dst_h = dsc->dest_h,
.dst_stride = dsc->dest_stride,
.src_buf = dsc->src_buf,
.src_stride = dsc->src_stride
};
return lv_rgb888_blend_normal_to_rgb888_esp(&asm_dsc);
}
#endif // CONFIG_LV_DRAW_SW_ASM_CUSTOM
#ifdef __cplusplus
} /*extern "C"*/
#endif

View File

@@ -0,0 +1,66 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port touch
*/
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#if __has_include ("esp_lcd_touch.h")
#include "esp_lcd_touch.h"
#define ESP_LVGL_PORT_TOUCH_COMPONENT 1
#endif
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_LVGL_PORT_TOUCH_COMPONENT
/**
* @brief Configuration touch structure
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
esp_lcd_touch_handle_t handle; /*!< LCD touch IO handle */
struct {
float x;
float y;
} scale; /*!< Touch scale */
} lvgl_port_touch_cfg_t;
/**
* @brief Add LCD touch as an input device
*
* @note Allocated memory in this function is not free in deinit. You must call lvgl_port_remove_touch for free all memory!
*
* @param touch_cfg Touch configuration structure
* @return Pointer to LVGL touch input device or NULL when error occurred
*/
lv_indev_t *lvgl_port_add_touch(const lvgl_port_touch_cfg_t *touch_cfg);
/**
* @brief Remove selected LCD touch from input devices
*
* @note Free all memory used for this display.
*
* @return
* - ESP_OK on success
*/
esp_err_t lvgl_port_remove_touch(lv_indev_t *touch);
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,80 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LVGL port USB HID
*/
#pragma once
#include "esp_err.h"
#include "lvgl.h"
#if __has_include ("usb/hid_host.h")
#define ESP_LVGL_PORT_USB_HOST_HID_COMPONENT 1
#endif
#if LVGL_VERSION_MAJOR == 8
#include "esp_lvgl_port_compatibility.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_LVGL_PORT_USB_HOST_HID_COMPONENT
/**
* @brief Configuration of the mouse input
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
uint8_t sensitivity; /*!< Mouse sensitivity (cannot be zero) */
lv_obj_t *cursor_img; /*!< Mouse cursor image, if NULL then used default */
} lvgl_port_hid_mouse_cfg_t;
/**
* @brief Configuration of the keyboard input
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
} lvgl_port_hid_keyboard_cfg_t;
/**
* @brief Add USB HID mouse as an input device
*
* @note The USB host must be initialized before. Use `usb_host_install` for host initialization.
*
* @param mouse_cfg mouse configuration structure
* @return Pointer to LVGL buttons input device or NULL when error occurred
*/
lv_indev_t *lvgl_port_add_usb_hid_mouse_input(const lvgl_port_hid_mouse_cfg_t *mouse_cfg);
/**
* @brief Add USB HID keyboard as an input device
*
* @note The USB host must be initialized before. Use `usb_host_install` for host initialization.
*
* @param keyboard_cfg keyboard configuration structure
* @return Pointer to LVGL buttons input device or NULL when error occurred
*/
lv_indev_t *lvgl_port_add_usb_hid_keyboard_input(const lvgl_port_hid_keyboard_cfg_t *keyboard_cfg);
/**
* @brief Remove selected USB HID from input devices
*
* @note Free all memory used for this input device. When removed all HID devices, the HID task will be freed.
*
* @return
* - ESP_OK on success
*/
esp_err_t lvgl_port_remove_usb_hid_input(lv_indev_t *hid);
#endif
#ifdef __cplusplus
}
#endif