/**
* @file audio_service.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-24
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_- / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par 修改日志:
*
* | Date | Version | Author | Description
* |
|---|
| 2025-03-24 | v1.0 | Alvin Young | 首次创建
* |
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "audio_service.h"
#include "audio_service_process.h"
#include "imp_msg_queue.h"
#include "shell_port.h"
#include
#include
#include "es8388.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
static imp_msg_queue_t* msg_q_handle = NULL;
/* Private function(only *.c) -----------------------------------------------*/
uint8_t _read_all_codec_reg(int argc, char** argv)
{
int i = 0;
int reg_addr = 0;
uint8_t reg_data = 0;
for (i = 0; i < 53; i++) {
if (i == 0) {
cdc_printf("chip control and power---------\r\n");
} else if (i == 0x09) {
cdc_printf("ADC-----------------------------\r\n");
} else if (i == 0x17) {
cdc_printf("DAC-----------------------------\r\n");
}
reg_data = 0;
reg_addr = i;
imp_audio_service_codec_read_process_reg(reg_addr, ®_data);
cdc_printf("read 0x%02x value 0x%02x \r\n", reg_addr, reg_data);
}
cdc_printf("finish--------------------------\r\n");
es8388_read_all();
return 0;
}
uint8_t _codec_io(int argc, char** argv)
{
// codec_io 0(read)/1(write) reg_addr reg_data
if (argc < 3) {
return 1;
}
int is_write = atoi(argv[1]);
int reg_addr = atoi(argv[2]);
uint8_t reg_data = 0;
if (is_write) {
if (argc < 4) {
return 2;
}
reg_data = atoi(argv[3]);
imp_audio_service_codec_write_process_reg(reg_addr, reg_data);
cdc_printf("write 0x%02x value 0x%02x ok \r\n", reg_addr, reg_data);
} else {
imp_audio_service_codec_read_process_reg(reg_addr, ®_data);
cdc_printf("read 0x%02x value 0x%02x \r\n", reg_addr, reg_data);
}
return 0;
}
/* Exported functions --------------------------------------------------------*/
void imp_audio_service_task(void*)
{
uint8_t msg_recv_ret = 0;
imp_msg_item_t msg_item = { 0 };
imp_audio_service_codec_process_init();
msg_q_handle = imp_msg_queue_create_handle(IMP_TASK_ID_AUDIO_SERVICE_TASK);
imp_audio_service_codec_write_process_reg(ES8388_CONTROL1, 0x80);
while (1) {
msg_recv_ret = imp_msg_queue_recv_msg(msg_q_handle, &msg_item, 10);
if (!msg_recv_ret) {
cdc_printf("%s get msg from %s OK\r\n",
imp_main_task_table[msg_item.recv_id],
imp_main_task_table[msg_item.send_id]);
switch (msg_item.msg_data) {
case 1:
imp_audio_service_codec_initialize();
break;
case 2:
imp_audio_service_codec_start();
break;
case 3:
imp_audio_service_codec_stop();
break;
case 4:
imp_audio_service_codec_set_vol(100);
break;
}
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
codec_io, _codec_io, codec read write);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
read_all_codec, _read_all_codec_reg, read_all_codec_reg);
/*
* EOF
*/