功能:集成SU-03T语音模块,完善UI代码文档
- 在CMakeLists.txt中添加SU-03T语音模块依赖。 - 在main.cpp中实现SU-03T接收回调函数,处理接收消息。 - 完善各UI源文件文档,包括动作、屏幕和字体,明确模块作用与数据流向。 - 更新主应用逻辑,初始化并启动SU-03T接收器。 - 修改过程中确保兼容性,保留原有接口。
This commit is contained in:
113
components/su-03t/include/su-03t.h
Normal file
113
components/su-03t/include/su-03t.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 文件: components/su-03t/include/su-03t.h
|
||||
* 角色: SU-03T 语音模块串口协议适配
|
||||
* 说明:
|
||||
* - 本文件用于实现当前模块的核心功能或接口定义。
|
||||
* - 修改前请先确认该模块与其它任务/外设之间的数据流关系。
|
||||
* - 涉及协议与硬件时,优先保持现有接口兼容,避免联调回归。
|
||||
*/
|
||||
|
||||
/*
|
||||
* SU-03T 语音模块接口声明
|
||||
*
|
||||
* 说明:
|
||||
* 1) 固定使用 UART2,默认引脚 RX=IO41 / TX=IO42,波特率 115200。
|
||||
* 2) 提供固定帧协议封装与原始十六进制发送两种方式。
|
||||
* 3) 提供同步收帧与后台异步回调,便于语音事件实时上报。
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/uart.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SU03T_UART_PORT UART_NUM_2
|
||||
#define SU03T_UART_BAUD 115200
|
||||
#define SU03T_UART_TX_IO GPIO_NUM_42
|
||||
#define SU03T_UART_RX_IO GPIO_NUM_41
|
||||
|
||||
#define SU03T_DEFAULT_HEAD_H 0xAA
|
||||
#define SU03T_DEFAULT_HEAD_L 0x55
|
||||
#define SU03T_DEFAULT_TAIL_H 0x55
|
||||
#define SU03T_DEFAULT_TAIL_L 0xAA
|
||||
|
||||
#define SU03T_MAX_PARAM_LEN 256
|
||||
|
||||
typedef struct {
|
||||
uint8_t head_h;
|
||||
uint8_t head_l;
|
||||
uint8_t tail_h;
|
||||
uint8_t tail_l;
|
||||
} su03t_frame_format_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t msgno;
|
||||
uint8_t params[SU03T_MAX_PARAM_LEN];
|
||||
size_t params_len;
|
||||
} su03t_frame_t;
|
||||
|
||||
/* 异步接收回调: 每收到一帧完整数据触发一次。 */
|
||||
typedef void (*su03t_rx_callback_t)(const su03t_frame_t *frame, void *user_ctx);
|
||||
|
||||
/**
|
||||
* @brief 初始化 SU-03T 串口驱动
|
||||
* @return ESP_OK 成功;其它为驱动安装或串口配置错误
|
||||
*/
|
||||
esp_err_t su03t_init(void);
|
||||
|
||||
/**
|
||||
* @brief 配置帧头帧尾(默认 AA55 ... 55AA)
|
||||
*/
|
||||
esp_err_t su03t_set_frame_format(const su03t_frame_format_t *fmt);
|
||||
|
||||
/**
|
||||
* @brief 获取当前帧格式配置
|
||||
*/
|
||||
esp_err_t su03t_get_frame_format(su03t_frame_format_t *fmt_out);
|
||||
|
||||
/**
|
||||
* @brief 发送固定格式消息
|
||||
* @param msgno 消息编号(1字节)
|
||||
* @param params 参数区首地址,可为 NULL(当 params_len 为 0)
|
||||
* @param params_len 参数区长度
|
||||
*/
|
||||
esp_err_t su03t_send_frame(uint8_t msgno, const uint8_t *params, size_t params_len);
|
||||
|
||||
/**
|
||||
* @brief 发送十六进制字符串(支持空格分隔)
|
||||
* @param hex_string 十六进制文本,例如 "AA 55 01 11 22 55 AA"
|
||||
*/
|
||||
esp_err_t su03t_send_hex_string(const char *hex_string);
|
||||
|
||||
/**
|
||||
* @brief 同步接收并解析一帧消息
|
||||
* @param out_frame 输出帧
|
||||
* @param timeout_ms 超时时间(毫秒)
|
||||
*/
|
||||
esp_err_t su03t_recv_frame(su03t_frame_t *out_frame, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief 启动后台接收任务,持续解析并回调
|
||||
* @param callback 收到完整帧时的回调函数
|
||||
* @param user_ctx 回调透传上下文指针
|
||||
* @param task_stack_size 接收任务栈大小,传 0 使用默认值
|
||||
* @param task_priority 接收任务优先级,传 0 使用默认值
|
||||
*/
|
||||
esp_err_t su03t_start_receiver(su03t_rx_callback_t callback, void *user_ctx, uint32_t task_stack_size, UBaseType_t task_priority);
|
||||
|
||||
/**
|
||||
* @brief 停止后台接收任务
|
||||
*/
|
||||
esp_err_t su03t_stop_receiver(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user