1、先看看与智能语音
开发板CB5654板级适配组件,这个要多看看熟悉
其中一部分
boo
timgs文件夹 - 引导固件
configs文件夹 - 默认的系统分区及编译链接文件
dspalg_cxc文件夹 - 士兰语音识别方案核间通讯接口
include文件夹 - 包含引脚配置定义、OS配置文件、LWIP配置文件
audio文件夹 - 音频初始化及 软VAD低功耗框架
base_init.c - 板级初始化
pinmux_init.c - 引脚复用配置
soc_lpm.c - 低功耗适配
board_lpm.c - 板级低功耗处理
package.yaml - 组件配置文件
2、开发板上有一排插针,其中两个引脚是UART3,先解决引脚复用。
pinmux_init.c文件增加
关键部分代码位置:
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include "board.h"
- extern void ioreuse_initial(void);
- static void board_pinmux_config(void)
- {
- //console
- drv_pinmux_config(CONSOLE_TXD, CONSOLE_TXD_FUNC);
- drv_pinmux_config(CONSOLE_RXD, CONSOLE_RXD_FUNC);
- //UART3
- drv_pinmux_config(UART3_TXD, UART3_TXD_FUNC);
- drv_pinmux_config(UART3_RXD, UART3_RXD_FUNC);
- // BT
- drv_pinmux_config(BT_UART_TXD, BT_UART_TXD_FUNC);
- drv_pinmux_config(BT_UART_RXD, BT_UART_RXD_FUNC);
include/board_config.h文件增加:
关键部分代码位置:
- #ifndef __BOARD_CONFIG_H__
- #define __BOARD_CONFIG_H__
- #include
- /* 系统 */
- //1:1.2V 2:1.0V 3:1.4V
- #define SOC_DSP_LDO_LEVEL 3
- /* console */
- #define CONSOLE_TXD PA4
- #define CONSOLE_RXD PA5
- #define CONSOLE_TXD_FUNC PA4_UART2_TX
- #define CONSOLE_RXD_FUNC PA5_UART2_RX
- #define CONSOLE_UART_IDX 1
- //UART3
- #define UART3_TXD PD7
- #define UART3_RXD PD8
- #define UART3_TXD_FUNC PD7_UART3_TX
- #define UART3_RXD_FUNC PD8_UART3_RX
- #define UART3_IDX 2
- /* LED */
- #define PIN_LED_R LED_PIN_NOT_SET
- #define PIN_LED_G PD4
- #define PIN_LED_B LED_PIN_NOT_SET
- #define LED_FLIP_FLAG 1 /* 低电平亮 */
3、串口UART3接的是红外学习模块
4、appsrcaui_cloudaliyunnlsaui_nlp_action_audio.c 语音触发关键部分代码位置:
- /**
- * 解析ASR&NLP信息
- */
- int aui_nlp_action_set_volume(cJSON *js, uint8_t *need_resume)
- {
- aos_dev_t *comm_handleB = NULL;
- char my1[] = {0xFA,0xFD,0x02,0x01,0xDF};
- char my2[] = {0xFA,0xFD,0x02,0x00,0xDF};
-
- comm_handleB = uart_open_id("uart", 2);
- uart_config_t configabc;
- uart_config_default(&configabc);
- configabc.baud_rate = 115200;
- uart_config(comm_handleB, &configabc);
- uart_set_type(comm_handleB, UART_TYPE_GENERAL);
-
- int ret = -1;
- int vol_step = 10;
- cJSON *action_params = cJSON_GetObjectItemByPath(js, "payload.action_params");
- if(cJSON_IsArray(action_params)) {
- cJSON *param = NULL;
- cJSON *param_name = NULL, *param_value = NULL;
- char *action = NULL;
- cJSON_ArrayForEach(param, action_params) {
- if (cJSON_HasObjectItem(param, "name")) {
- param_name = cJSON_GetObjectItemCaseSensitive(param, "name");
- if (json_string_eq(param_name, "sound") && cJSON_HasObjectItem(param, "value")) {
- param_value = cJSON_GetObjectItemCaseSensitive(param, "value");
- action = param_value->valuestring;
- LOGD(TAG, "volume action [%s]000", action);
- if (strcmp(action, "down")==0){
- //LOGD(TAG, "---down---");
- uart_send(comm_handleB, &my1, 5);
- }
- if (strcmp(action, "up")==0){
- //LOGD(TAG, "---up---");
- uart_send(comm_handleB, &my2, 5);
- }
- }
- if ((json_string_eq(param_name, "degree") && cJSON_HasObjectItem(param, "value"))
- || (json_string_eq(param_name, "volumn") && cJSON_HasObjectItem(param, "value"))){
- param_value = cJSON_GetObjectItemCaseSensitive(param, "value");
- vol_step = atoi(param_value->valuestring);
- LOGD(TAG, "volume degree [%d]", vol_step);
- }
- }
- }
- if (strcmp(action, "up") == 0) {
- smtaudio_vol_up(vol_step);
- ret = 0;
- } else if (strcmp(action, "down") == 0) {
- smtaudio_vol_down(vol_step);
- ret = 0;
- } else if (strcmp(action, "max") == 0) {
- smtaudio_vol_set(100);
- ret = 0;
- } else if (strcmp(action, "min") == 0) {
- smtaudio_vol_set(0);
- ret = 0;
- } else if (strcmp(action, "mute") == 0) {
- *need_resume = 0;
- ret = 0;
- } else if (strcmp(action, "unmute") == 0) {
- *need_resume = 1;
- ret = 0;
- } else if (strcmp(action, "set") == 0) {
- smtaudio_vol_set(20);
- ret = 0;
- }
- } else {
- LOGE(TAG, "set_volume payload error!");
- return -1;
- }
- return ret;
- }
经过较漫长的编译与烧录之后,就可以愉快的玩耍了。
附上视频链接:
https://www.bilibili.com/video/BV1o44y1E7Rb/