CogletESP-camera-version/main/uart_component.cc

39 lines
1.4 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.

#include "uart_component.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <string.h>
// 初始化 ESP32 → RP2040 的 UART 通信
// 波特率 1152008 数据位无校验1 停止位,无流控
void uart_init_component() {
uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
};
uart_param_config(UART_PORT_NUM, &uart_config);
// GPIO17=TX发送到 RP2040 的 GP5/RXGPIO18=RX接收 RP2040 的 GP4/TX
uart_set_pin(UART_PORT_NUM, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_PORT_NUM, BUF_SIZE, 0, 0, NULL, 0);
}
// 发送状态字符串给 RP2040末尾自动添加 \r\n
// RP2040 的 main.py 通过 coms.esp_read() 按 \n 分割解析
// 支持的状态字符串idle / listening / speaking / thinking / neutral / happy 等
void uart_send_string(const char* str) {
uart_write_bytes(UART_PORT_NUM, str, strlen(str));
uart_write_bytes(UART_PORT_NUM, "\r\n", 2);
}
// 发送说话开始信号预留接口RP2040 当前未使用)
void uart_signal_start() {
uart_send_string("[SPEAK_START]\n");
}
// 发送说话停止信号预留接口RP2040 当前未使用)
void uart_signal_stop() {
uart_send_string("[SPEAK_STOP]\n");
}