ESP 设备板级适配
公共头文件:
#include "brookesia/hal_adaptor.hpp"
概述
brookesia_hal_adaptor 是 ESP-Brookesia 的板级 HAL 适配实现,基于 HAL 接口 的设备/接口模型,通过 esp_board_manager 与 ESP-IDF 驱动初始化真实外设,并将 系统、 网络、 音频、 显示、 存储、 电源、 视频、 Wi-Fi 等能力注册到全局 HAL 表,供上层按名称发现和使用。
功能特性
内置设备
本组件提供多台板级设备,每台设备以单例形式注册,初始化后将对应的接口发布到全局表:
设备类(逻辑名) |
注册的接口实现 |
说明 |
|---|---|---|
|
|
读取静态开发板元信息,并发布系统级板级信息接口。 |
|
|
为 Service 提供平台 SNTP 与 HTTP/HTTPS 客户端能力。 |
|
|
播放经板级 Audio DAC;录音经 Audio ADC。子实现可在 Kconfig 中独立关闭,并依赖板级能力符号 |
|
|
LEDC 背光、LCD 面板、I2C 触摸可分别开关;分别依赖 |
|
|
通用文件系统实现支持 LittleFS、可选 SPIFFS、Flash FATFS 与 SD 卡 FATFS;KV 实现基于 ESP-IDF NVS。文件系统后端按 Kconfig 启用,其中 LittleFS 与 Flash FATFS 由 adaptor 直接挂载。 |
|
|
电池与充电器能力实现,支持 ADC 电压估算或 AXP2101 电源管理芯片实现;可查询电量、电压、电源来源、充电状态,并在底层支持时控制充电配置。 |
|
|
当所选开发板暴露对应能力时,发布摄像头与视频处理接口。 |
|
|
基于 ESP-IDF 的 Wi-Fi 后端,负责单次生命周期、STA、扫描、SoftAP 与配网动作。重试、fallback 与自动连接策略由 |
配置与参数
各设备与子接口可在 menuconfig 的 ESP-Brookesia: Hal Adaptor Configurations 中独立开启或关闭;默认能力参数(音量范围、录音格式、背光亮度范围、电池低电量阈值、ADC 电压换算参数等)也可在 menuconfig 中调整,由 macro_configs.h 映射为编译宏供实现使用。
若需在初始化前覆盖默认能力参数,可在对应设备单例上调用 set_codec_player_info、set_codec_recorder_info 或 set_ledc_backlight_info。初始化完成后再调用通常不会生效。
API 参考
Header File
Classes
Header File
Classes
Header File
Classes
-
class DisplayDevice : public esp_brookesia::hal::Device
Board-backed display device: registers panel, touch, and backlight HAL interfaces after board bring-up.
Obtained via get_instance(). Not copyable or movable.
Public Static Functions
-
static inline DisplayDevice &get_instance()
Returns the process-wide singleton display device.
- 返回
Reference to the unique DisplayDevice instance.
Public Static Attributes
-
static constexpr const char *DEVICE_NAME = "Display"
Logical device name passed to the base Device constructor.
-
static constexpr const char *LEDC_BACKLIGHT_IMPL_NAME = "Display:LedcBacklight"
Registry key for the LEDC-based backlight HAL implementation (
"Display:LedcBacklight").
-
static constexpr const char *LCD_PANEL_IMPL_NAME = "Display:LcdPanel"
Registry key for the LCD panel HAL implementation (
"Display:LcdPanel").
-
static constexpr const char *LCD_TOUCH_IMPL_NAME = "Display:LcdTouch"
Registry key for the LCD touch HAL implementation (
"Display:LcdTouch").
-
static inline DisplayDevice &get_instance()
Header File
Classes
-
class AudioDevice : public esp_brookesia::hal::Device
Board-backed audio device: registers codec player and recorder HAL interfaces after board bring-up.
Obtained via get_instance(). Not copyable or movable.
Public Functions
-
bool set_codec_recorder_info(audio::CodecRecorderIface::Info info)
Overrides default static recording capability information used when constructing the codec recorder implementation.
- 参数
info -- [in] Codec recorder capability descriptor (format, channels, gains, etc.).
- 返回
trueif the value was stored;falseon invalid input or if the recorder is already initialized.
-
bool set_processor_config(AudioProcessorConfig config)
Set the ESP audio processor backend configuration.
This must be called before the audio processor playback, encoder, or decoder HAL interfaces are initialized.
- 参数
config -- [in] Complete processor configuration.
- 返回
trueif the value was stored;falseafter processor initialization.
Public Static Functions
-
static inline AudioDevice &get_instance()
Returns the process-wide singleton audio device.
- 返回
Reference to the unique AudioDevice instance.
Public Static Attributes
-
static constexpr const char *DEVICE_NAME = "Audio"
Logical device name passed to the base Device constructor.
-
static constexpr const char *CODEC_PLAYER_IMPL_NAME = "Audio:CodecPlayer"
Registry key for the codec player HAL implementation (
"Audio:CodecPlayer").
-
static constexpr const char *CODEC_RECORDER_IMPL_NAME = "Audio:CodecRecorder"
Registry key for the codec recorder HAL implementation (
"Audio:CodecRecorder").
-
static constexpr const char *PLAYBACK_IMPL_NAME = "Audio:Playback"
Registry key for the audio playback HAL implementation.
-
static constexpr const char *ENCODER_IMPL_NAME = "Audio:Encoder:0"
Registry key for the audio encoder HAL implementation.
-
static constexpr const char *DECODER_IMPL_NAME = "Audio:Decoder:0"
Registry key for the audio decoder HAL implementation.
-
bool set_codec_recorder_info(audio::CodecRecorderIface::Info info)
Header File
Classes
-
class StorageDevice : public esp_brookesia::hal::Device
Board-backed storage device: publishes filesystem and key-value HAL interfaces after bring-up.
Obtained via get_instance(). Not copyable or movable.
Public Static Functions
-
static inline StorageDevice &get_instance()
Returns the process-wide singleton storage device.
- 返回
Reference to the unique StorageDevice instance.
-
static inline StorageDevice &get_instance()
Header File
Classes
-
class PowerDevice : public esp_brookesia::hal::Device
Power-backed metadata device: publishes a power HAL interface.
Obtained via get_instance(). Not copyable or movable.
Public Static Functions
-
static inline PowerDevice &get_instance()
Returns the process-wide singleton power device.
- 返回
Reference to the unique PowerDevice instance.
-
static inline PowerDevice &get_instance()