Files
ai-passport/components/bsp/include/bsp_display.h
T
hex2077 6a7f4e010b chore: 新增大量静态资源、测试桩文件与配置文件,清理旧无用资源
本次提交新增了多种字体、UI图片、音频剪辑等静态资源,添加了测试桩文件与项目配置文件,同时清理了部分已废弃的旧图片与测试桩代码文件。
2026-09-22 00:42:26 +08:00

64 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// components/bsp/include/bsp_display.h
// ST7789P3 240x320 显示:SPI 面板初始化 + 厂商专属寄存器 + LEDC 背光调光。
#pragma once
#include "esp_err.h"
#include "esp_lcd_types.h"
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
// The final LVGL frame is masked to this radius; pixels outside are pure black.
#define BSP_LVGL_SCREEN_RADIUS 30
// 初始化 SPI 总线、面板、厂商寄存器、背光 LEDC。成功调用可重复;失败会回滚本次
// 已创建的显示资源,修正故障后可重试。成功后屏幕已上电但内容未定。
esp_err_t bsp_display_init(void);
// 取底层面板句柄。想直接 esp_lcd_panel_draw_bitmap 画,或接 LVGL 以外的 GUI 时用。
// 未初始化返回 NULL。
esp_lcd_panel_handle_t bsp_display_panel(void);
// 取底层 panel io 句柄(LVGL 接入需要)。未初始化返回 NULL。
esp_lcd_panel_io_handle_t bsp_display_io(void);
// 背光亮度 0..100(%)。LEDC PWM,0=全灭。
void bsp_display_backlight(uint8_t percent);
uint8_t bsp_display_brightness(void);
/* Reversible panel/LVGL standby, from a worker without the LVGL lock.
* Stops both LVGL task and tick. Resume restores saved brightness, or 80%. */
esp_err_t bsp_display_suspend(void);
esp_err_t bsp_display_resume(void);
// deep sleep 专用:关闭显示、让 ST7789 进入 Sleep In,停止背光 PWM,
// 将 CS/SCLK/MOSI/DC/背光设为安全电平并在 deep sleep 中保持。调用时必须
// 已阻止 LVGL 刷屏,调用后必须立即进入 deep sleep 或重启。
esp_err_t bsp_display_prepare_deep_sleep(void);
// ---------------------------------------------------------------------------
// LVGL 接入(可选层)。必须先 bsp_display_init() 成功后再调。
// 不想用 LVGL 的开发者可忽略本段,直接用 bsp_display_panel() 自己画。
// ---------------------------------------------------------------------------
// 前向声明:LVGL 里 lv_display_t 是 `typedef struct _lv_display_t lv_display_t;`,
// 故此处用 struct 形式即可,避免本头文件强行 include lvgl.h。
struct _lv_display_t;
// 启动 LVGL 与其渲染任务,返回 lv_display_t*。失败返回 NULL;display 注册失败会回滚 port。
struct _lv_display_t *bsp_lvgl_init(void);
// LVGL 非线程安全:在【非 LVGL 任务】里操作任何 lv_* 对象前后必须加解锁。
// LVGL 尚未就绪或超时时 lock 返回 false;只有 lock 成功后才调用 unlock。
bool bsp_lvgl_lock(int timeout_ms);
void bsp_lvgl_unlock(void);
/* Capture the actual device-rendered RGB565LE flush stream. Caller MUST hold
* the LVGL lock, from a worker (not a draw/timer callback). The synchronous
* sink must have a bounded timeout and must not call LVGL. Uses the existing
* partial draw buffer, no full framebuffer. Does not wake a sleeping display
* or change page/settings. Returns an error on incomplete output. */
typedef bool (*bsp_display_capture_write_fn)(const uint8_t *, size_t, void *);
esp_err_t bsp_display_capture_rgb565(bsp_display_capture_write_fn write, void *context);
/* Actual task/panel transition state, including a failed rollback. */
bool bsp_display_is_suspended(void);