feat: audio files

This commit is contained in:
Alvin Young 2025-04-14 17:33:55 +08:00
parent 0013e8d9ed
commit f8b8af14ff
18 changed files with 2282 additions and 8 deletions

View File

@ -37,6 +37,7 @@
#include "imp_msg_queue.h"
#include "ext_trans_service.h"
#include "display_service.h"
#include "audio_service.h"
#include <string.h>
#include "imp_out_port.h"
@ -109,6 +110,9 @@ uint8_t _main_task_wake_up_services()
xTaskCreate(imp_display_service_task,
imp_main_task_table[IMP_TASK_ID_DISP_SERVICE_TASK], 8192, NULL,
11, NULL);
xTaskCreate(imp_audio_service_task,
imp_main_task_table[IMP_TASK_ID_AUDIO_SERVICE_TASK], 2048, NULL,
12, NULL);
return 0;
}

View File

@ -16,6 +16,8 @@ idf_component_register(
"services/display_service"
"components/screen_pages/test_page"
"components/imp_esp_i2c_master_dev_op"
"services/audio_service"
"components/Codec/ES8388"
EXCLUDE_SRCS
"utilities/imp_util_ring_queue/ring_queue_test.c"
@ -38,13 +40,16 @@ idf_component_register(
"services/display_service"
"components/screen_pages/test_page"
"components/imp_esp_i2c_master_dev_op"
"services/audio_service"
"components/Codec/ES8388"
"components/Codec"
LDFRAGMENTS
"utilities/letter_shell/port/esp-idf/shell.lf"
)
#
#
set(SOURCE_FILE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/main.c
${CMAKE_CURRENT_SOURCE_DIR}/services/display_service/display_service.c

View File

@ -0,0 +1,668 @@
/**
* @file es8388.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-22
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-22 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "es8388.h"
#include "imp_codec.h"
#include <stdlib.h>
#include <string.h>
#include <esp_log.h>
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
static imp_es8388_cfg_t handle = { 0 };
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void es8388_read_all()
{
if (!handle.is_init) {
return;
}
for (int i = 0; i < 50; i++) {
uint8_t reg = 0;
handle.read_reg(i, &reg);
ESP_LOGI("ES8388", "%x: %x", i, reg);
}
}
int es8388_write_reg(uint8_t reg_add, uint8_t data)
{
if (!handle.is_init) {
return 1;
}
return handle.write_reg(reg_add, data);
}
/**
* @brief Configure ES8388 ADC and DAC volume. Basicly you can consider this as ADC and DAC gain
*
* @param mode: set ADC or DAC or all
* @param volume: -96 ~ 0 for example Es8388SetAdcDacVolume(ES_MODULE_ADC, 30, 6); means set ADC volume -30.5db
* @param dot: whether include 0.5. for example Es8388SetAdcDacVolume(ES_MODULE_ADC, 30, 4); means set ADC volume -30db
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
static int es8388_set_adc_dac_volume(int mode, int volume, int dot)
{
if (!handle.is_init) {
return 1;
}
int res = 0;
if (volume < -96 || volume > 0) {
ESP_LOGW("ES8388", "Warning: volume < -96! or > 0!\n");
if (volume < -96)
volume = -96;
else
volume = 0;
}
dot = (dot >= 5 ? 1 : 0);
volume = (-volume << 1) + dot;
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
res |= handle.write_reg(ES8388_ADCCONTROL8, volume);
res |= handle.write_reg(ES8388_ADCCONTROL9,
volume); //ADC Right Volume=0db
}
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
res |= handle.write_reg(ES8388_DACCONTROL5, volume);
res |= handle.write_reg(ES8388_DACCONTROL4, volume);
}
return res;
}
/**
* @brief Power Management
*
* @param mod: if ES_POWER_CHIP, the whole chip including ADC and DAC is enabled
* @param enable: false to disable true to enable
*
* @return
* - (-1) Error
* - (0) Success
*/
int es8388_start(es_module_t mode)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t prev_data = 0, data = 0;
handle.read_reg(ES8388_DACCONTROL21, &prev_data);
if (mode == ES_MODULE_LINE) {
// 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2 by pass enable
res |= handle.write_reg(ES8388_DACCONTROL16, 0x09);
// left DAC to left mixer enable and LIN signal to left mixer enable 0db : bupass enable
res |= handle.write_reg(ES8388_DACCONTROL17, 0x50);
// right DAC to right mixer enable and LIN signal to right mixer enable 0db : bupass enable
res |= handle.write_reg(ES8388_DACCONTROL20, 0x50);
res |= handle.write_reg(ES8388_DACCONTROL21, 0xC0); //enable adc
} else {
res |= handle.write_reg(ES8388_DACCONTROL21, 0x80); //enable dac
}
handle.read_reg(ES8388_DACCONTROL21, &data);
if (prev_data != data) {
//start state machine
res |= handle.write_reg(ES8388_CHIPPOWER, 0xF0);
// res |= handle.write_reg(ES8388_CONTROL1, 0x16);
// res |= handle.write_reg(ES8388_CONTROL2, 0x50);
//start state machine
res |= handle.write_reg(ES8388_CHIPPOWER, 0x00);
}
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC
|| mode == ES_MODULE_LINE) {
//power up adc and line in
res |= handle.write_reg(ES8388_ADCPOWER, 0x00);
}
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC
|| mode == ES_MODULE_LINE) {
//power up dac and line out
res |= handle.write_reg(ES8388_DACPOWER, 0x3c);
res |= es8388_set_voice_mute(false);
ESP_LOGD("ES8388", "es8388_start default is mode:%d", mode);
}
return res;
}
/**
* @brief Power Management
*
* @param mod: if ES_POWER_CHIP, the whole chip including ADC and DAC is enabled
* @param enable: false to disable true to enable
*
* @return
* - (-1) Error
* - (0) Success
*/
int es8388_stop(es_module_t mode)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
if (mode == ES_MODULE_LINE) {
//enable dac
res |= handle.write_reg(ES8388_DACCONTROL21, 0x80);
// 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2
res |= handle.write_reg(ES8388_DACCONTROL16, 0x00);
// only left DAC to left mixer enable 0db
res |= handle.write_reg(ES8388_DACCONTROL17, 0x90);
// only right DAC to right mixer enable 0db
res |= handle.write_reg(ES8388_DACCONTROL20, 0x90);
return res;
}
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
res |= handle.write_reg(ES8388_DACPOWER, 0x00);
res |= es8388_set_voice_mute(
true); //res |= Es8388SetAdcDacVolume(ES_MODULE_DAC, -96, 5); // 0db
//res |= handle.write_reg(ES8388_DACPOWER, 0xC0); //power down dac and line out
}
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
//res |= Es8388SetAdcDacVolume(ES_MODULE_ADC, -96, 5); // 0db
res |= handle.write_reg(ES8388_ADCPOWER,
0xFF); //power down adc and line in
}
if (mode == ES_MODULE_ADC_DAC) {
//disable mclk
res |= handle.write_reg(ES8388_DACCONTROL21, 0x9C);
// res |= handle.write_reg(ES8388_CONTROL1, 0x00);
// res |= handle.write_reg(ES8388_CONTROL2, 0x58);
// res |= handle.write_reg(ES8388_CHIPPOWER, 0xF3); //stop state machine
}
return res;
}
/**
* @brief Config I2s clock in MSATER mode
*
* @param cfg.sclkDiv: generate SCLK by dividing MCLK in MSATER mode
* @param cfg.lclkDiv: generate LCLK by dividing MCLK in MSATER mode
*
* @return
* - (-1) Error
* - (0) Success
*/
int es8388_i2s_config_clock(es_i2s_clock_t cfg)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
res |= handle.write_reg(ES8388_MASTERMODE, cfg.sclk_div);
res |= handle.write_reg(ES8388_ADCCONTROL5,
cfg.lclk_div); //ADCFsMode,singel SPEED,RATIO=256
res |= handle.write_reg(ES8388_DACCONTROL2,
cfg.lclk_div); //ADCFsMode,singel SPEED,RATIO=256
return res;
}
int es8388_deinit(void)
{
if (!handle.is_init) {
return 1;
}
int res = 0;
res = handle.write_reg(ES8388_CHIPPOWER,
0xFF); //reset and stop es8388
// i2c_bus_delete(i2c_handle);
#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
headphone_detect_deinit();
#endif
// audio_codec_volume_deinit(dac_vol_handle);
return res;
}
/**
* @return
* - (-1) Error
* - (0) Success
*/
static int es8388_init_regs(imp_es8388_cfg_t* cfg)
{
if (!handle.is_init) {
return 1;
}
int res = 0;
#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
headphone_detect_init(get_headphone_detect_gpio());
#endif
ESP_LOGI("ES8388", "run %s at line %d", __FUNCTION__, __LINE__);
res = 0; // ESP32 in master mode
// 0x04 mute/0x00 unmute&ramp;DAC unmute and disabled digital volume control soft ramp
res |= handle.write_reg(ES8388_DACCONTROL3, 0x04);
/* Chip Control and Power Management */
res |= handle.write_reg(ES8388_CONTROL2, 0x50);
//normal all and power up all
res |= handle.write_reg(ES8388_CHIPPOWER, 0x00);
// Disable the internal DLL to improve 8K sample rate
res |= handle.write_reg(0x35, 0xA0);
res |= handle.write_reg(0x37, 0xD0);
res |= handle.write_reg(0x39, 0xD0);
//CODEC IN I2S SLAVE MODE TODO
res |= handle.write_reg(ES8388_MASTERMODE, cfg->mode);
/* dac */
//disable DAC and disable Lout/Rout/1/2
res |= handle.write_reg(ES8388_DACPOWER, 0xC0);
//Enfr=0,Play&Record Mode,(0x17-both of mic&paly)
res |= handle.write_reg(ES8388_CONTROL1, 0x12);
// res |= handle.write_reg(ES8388_CONTROL2, 0); //LPVrefBuf=0,Pdn_ana=0
//1a 0x18:16bit iis , 0x00:24
res |= handle.write_reg(ES8388_DACCONTROL1, 0x18);
//DACFsMode,SINGLE SPEED; DACFsRatio,256
res |= handle.write_reg(ES8388_DACCONTROL2, 0x02);
// 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2
res |= handle.write_reg(ES8388_DACCONTROL16, 0x00);
// only left DAC to left mixer enable 0db
res |= handle.write_reg(ES8388_DACCONTROL17, 0x90);
// only right DAC to right mixer enable 0db
res |= handle.write_reg(ES8388_DACCONTROL20, 0x90);
// set internal ADC and DAC use the same LRCK clock, ADC LRCK as internal LRCK
res |= handle.write_reg(ES8388_DACCONTROL21, 0x80);
res |= handle.write_reg(ES8388_DACCONTROL23, 0x00); // vroi=0
// Set L1 R1 L2 R2 volume. 0x00: -30dB, 0x1E: 0dB, 0x21: 3dB
res |= handle.write_reg(ES8388_DACCONTROL24, 0x1E);
res |= handle.write_reg(ES8388_DACCONTROL25, 0x1E);
res |= handle.write_reg(ES8388_DACCONTROL26, 0);
res |= handle.write_reg(ES8388_DACCONTROL27, 0);
// res |= es8388_set_adc_dac_volume(ES_MODULE_DAC, 0, 0); // 0db
int tmp = 0;
if (EM_IMP_ES8388_LINE_OUT_1 == cfg->dac_output) {
tmp = DAC_OUTPUT_LOUT1 | DAC_OUTPUT_ROUT1;
} else if (EM_IMP_ES8388_LINE_OUT_2 == cfg->dac_output) {
tmp = DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT2;
} else {
tmp = DAC_OUTPUT_LOUT1 | DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT1
| DAC_OUTPUT_ROUT2;
}
//0x3c Enable DAC and Enable Lout/Rout/1/2
res |= handle.write_reg(ES8388_DACPOWER, tmp);
/* adc */
res |= handle.write_reg(ES8388_ADCPOWER, 0xFF);
// MIC Left and Right channel PGA gain
res |= handle.write_reg(ES8388_ADCCONTROL1, 0xbb);
tmp = 0;
if (EM_IMP_ES8388_LINE_IN_1 == cfg->adc_input) {
tmp = ADC_INPUT_LINPUT1_RINPUT1;
} else if (EM_IMP_ES8388_LINE_IN_2 == cfg->adc_input) {
tmp = ADC_INPUT_LINPUT2_RINPUT2;
} else {
tmp = ADC_INPUT_DIFFERENCE;
}
//0x00 LINSEL & RINSEL, LIN1/RIN1 as ADC Input; DSSEL,use one DS Reg11; DSR, LINPUT1-RINPUT1
res |= handle.write_reg(ES8388_ADCCONTROL2, tmp);
res |= handle.write_reg(ES8388_ADCCONTROL3, 0x02);
// 16 Bits length and I2S serial audio data format
res |= handle.write_reg(ES8388_ADCCONTROL4, 0x0c);
//ADCFsMode,singel SPEED,RATIO=256
res |= handle.write_reg(ES8388_ADCCONTROL5, 0x02);
//ALC for Microphone
res |= es8388_set_adc_dac_volume(ES_MODULE_ADC, 0, 0); // 0db
// Power on ADC, enable LIN&RIN, power off MICBIAS, and set int1lp to low power mode
res |= handle.write_reg(ES8388_ADCPOWER, 0x09);
/* es8388 PA gpio_config */
// gpio_config_t io_conf;
// memset(&io_conf, 0, sizeof(io_conf));
// io_conf.mode = GPIO_MODE_OUTPUT;
// io_conf.pin_bit_mask = BIT64(get_pa_enable_gpio());
// io_conf.pull_down_en = 0;
// io_conf.pull_up_en = 0;
// gpio_config(&io_conf);
// /* enable es8388 PA */
// es8388_pa_power(true);
// codec_dac_volume_config_t vol_cfg = ES8388_DAC_VOL_CFG_DEFAULT();
// dac_vol_handle = audio_codec_volume_init(&vol_cfg);
ESP_LOGI("ES8388", "init,out:%02x, in:%02x", cfg->dac_output,
cfg->adc_input);
return res;
}
/**
* @brief Configure ES8388 I2S format
*
* @param mode: set ADC or DAC or all
* @param bitPerSample: see Es8388I2sFmt
*
* @return
* - (-1) Error
* - (0) Success
*/
int es8388_config_fmt(es_module_t mode, es_i2s_fmt_t fmt)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t reg = 0;
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
res = handle.read_reg(ES8388_ADCCONTROL4, &reg);
reg = reg & 0xfc;
res |= handle.write_reg(ES8388_ADCCONTROL4, reg | fmt);
}
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
res = handle.read_reg(ES8388_DACCONTROL1, &reg);
reg = reg & 0xf9;
res |= handle.write_reg(ES8388_DACCONTROL1, reg | (fmt << 1));
}
return res;
}
/**
* @brief Set voice volume
*
* @note Register values. 0xC0: -96 dB, 0x64: -50 dB, 0x00: 0 dB
* @note Accuracy of gain is 0.5 dB
*
* @param volume: voice volume (0~100)
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_set_voice_volume(int volume)
{
if (!handle.is_init) {
return 1;
}
// (min/mute)4 - 100(max)
if (volume < 4) {
volume = 4;
}
if (volume > 100) {
volume = 100;
}
// 0 - 96
volume = volume - 4;
int res = ESP_OK;
uint8_t reg = 0;
reg = 192 - (volume * 2); // TODO 转换配置
res |= handle.write_reg(ES8388_DACCONTROL5, reg);
res |= handle.write_reg(ES8388_DACCONTROL4, reg);
ESP_LOGD("ES8388", "Set volume:%.2d reg_value:0x%.2x dB:%.1f", (int)volume,
reg, 0);
return res;
}
int es8388_get_voice_volume(int* volume)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t reg = 0;
res = handle.read_reg(ES8388_DACCONTROL4, &reg);
// TODO: 转换reg到值
*volume = (reg - 192) / 2;
// if (res == ESP_FAIL) {
// *volume = 0;
// } else {
// if (reg == dac_vol_handle->reg_value) {
// *volume = dac_vol_handle->user_volume;
// } else {
// *volume = 0;
// res = ESP_FAIL;
// }
// }
ESP_LOGD("ES8388", "Get volume:%.2d reg_value:0x%.2x", *volume, reg);
return res;
}
/**
* @brief Configure ES8388 data sample bits
*
* @param mode: set ADC or DAC or all
* @param bitPerSample: see BitsLength
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_set_bits_per_sample(es_module_t mode, es_bits_length_t bits_length)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t reg = 0;
int bits = (int)bits_length;
if (mode == ES_MODULE_ADC || mode == ES_MODULE_ADC_DAC) {
res = handle.read_reg(ES8388_ADCCONTROL4, &reg);
reg = reg & 0xe3;
res |= handle.write_reg(ES8388_ADCCONTROL4, reg | (bits << 2));
}
if (mode == ES_MODULE_DAC || mode == ES_MODULE_ADC_DAC) {
res = handle.read_reg(ES8388_DACCONTROL1, &reg);
reg = reg & 0xc7;
res |= handle.write_reg(ES8388_DACCONTROL1, reg | (bits << 3));
}
return res;
}
/**
* @brief Configure ES8388 DAC mute or not. Basically you can use this function to mute the output or unmute
*
* @param enable: enable or disable
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_set_voice_mute(bool enable)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t reg = 0;
res = handle.read_reg(ES8388_DACCONTROL3, &reg);
reg = reg & 0xFB;
res |= handle.write_reg(ES8388_DACCONTROL3, reg | (((int)enable) << 2));
return res;
}
int es8388_get_voice_mute(void)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
uint8_t reg = 0;
res = handle.read_reg(ES8388_DACCONTROL3, &reg);
if (res == ESP_OK) {
reg = (reg & 0x04) >> 2;
}
return res == ESP_OK ? reg : res;
}
/**
* @param gain: Config DAC Output
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_config_dac_output(es_dac_output_t output)
{
if (!handle.is_init) {
return 1;
}
int res;
uint8_t reg = 0;
res = handle.read_reg(ES8388_DACPOWER, &reg);
reg = reg & 0xc3;
res |= handle.write_reg(ES8388_DACPOWER, reg | output);
return res;
}
/**
* @param gain: Config ADC input
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_config_adc_input(es_adc_input_t input)
{
if (!handle.is_init) {
return 1;
}
int res;
uint8_t reg = 0;
res = handle.read_reg(ES8388_ADCCONTROL2, &reg);
reg = reg & 0x0f;
res |= handle.write_reg(ES8388_ADCCONTROL2, reg | input);
return res;
}
/**
* @param gain: see es_mic_gain_t
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_set_mic_gain(es_mic_gain_t gain)
{
if (!handle.is_init) {
return 1;
}
int res, gain_n;
gain_n = (int)gain / 3;
gain_n = (gain_n << 4) + gain_n;
res = handle.write_reg(ES8388_ADCCONTROL1, gain_n); //MIC PGA
return res;
}
int es8388_ctrl_state(codec_work_mode_t mode, uint8_t start_flag)
{
if (!handle.is_init) {
return 1;
}
int res = 0;
int es_mode_t = 0;
switch (mode) {
case EM_IMP_CODEC_DEV_WORK_MODE_ADC:
es_mode_t = ES_MODULE_ADC;
break;
case EM_IMP_CODEC_DEV_WORK_MODE_LINE:
es_mode_t = ES_MODULE_LINE;
break;
case EM_IMP_CODEC_DEV_WORK_MODE_DAC:
es_mode_t = ES_MODULE_DAC;
break;
case EM_IMP_CODEC_DEV_WORK_MODE_BOTH:
es_mode_t = ES_MODULE_ADC_DAC;
break;
default:
es_mode_t = ES_MODULE_DAC;
ESP_LOGW("ES8388",
"Codec mode not support, default is decode mode");
break;
}
if (start_flag) {
res = es8388_start(es_mode_t);
ESP_LOGD("ES8388", "start default is decode mode:%d", es_mode_t);
} else {
res = es8388_stop(es_mode_t);
}
return res;
}
int es8388_config_i2s(es_i2s_fmt_t fmt, es_bits_length_t bit)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
int tmp = 0;
res |= es8388_config_fmt(handle.mode, fmt);
if (bit == BIT_LENGTH_16BITS) {
tmp = BIT_LENGTH_16BITS;
} else if (bit == BIT_LENGTH_24BITS) {
tmp = BIT_LENGTH_24BITS;
} else {
tmp = BIT_LENGTH_32BITS;
}
res |= es8388_set_bits_per_sample(handle.mode, tmp);
return res;
}
int es8388_pa_power(bool enable)
{
if (!handle.is_init) {
return 1;
}
int res = ESP_OK;
// if (enable) {
// res = gpio_set_level(get_pa_enable_gpio(), 1);
// } else {
// res = gpio_set_level(get_pa_enable_gpio(), 0);
// }
return res;
}
int es8388_init(es_mode_t mode, imp_es_8388_io_port_e dac_output,
imp_es_8388_io_port_e adc_input,
uint8_t (*read_reg)(uint8_t reg_addr, uint8_t* reg_data),
uint8_t (*write_reg)(uint8_t reg_addr, uint8_t reg_data))
{
ESP_LOGI("ES8388", "run %s at line %d", __FUNCTION__, __LINE__);
if (NULL == read_reg || NULL == write_reg) {
return 1;
}
ESP_LOGI("ES8388", "run %s at line %d", __FUNCTION__, __LINE__);
handle.mode = mode;
handle.dac_output = dac_output;
handle.adc_input = adc_input;
handle.read_reg = read_reg;
handle.write_reg = write_reg;
handle.is_init = 1;
es8388_init_regs(&handle);
return 0;
}
/*
* EOF
*/

View File

@ -0,0 +1,611 @@
/**
* @file es8388.h
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-22
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-22 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ES8388_H__
#define __ES8388_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include "imp_codec.h"
/* define --------------------------------------------------------------------*/
/* ES8388 register */
/* chip control and power */
#define ES8388_CONTROL1 0x00
#define ES8388_CONTROL1_DEFAULT_VALUE 0x06
/// @brief reset all reg data to default
#define ES8388_CONTROL1_SET_ALL_RESET(origin, value) \
((origin) & 0x7F | (value) << 7) & 0xFF;
#define ES8388_CONTROL2 0x01
#define ES8388_CONTROL2_DEFAULT_VALUE 0x5C
/// @brief set internal bias?
#define ES8388_CONTROL2_SET_PDN_IBIAS_GEN(origin, value) \
((origin) & 0xFD | (value) << 1) & 0xFF;
#define ES8388_CHIPPOWER 0x02
#define ES8388_CHIPPOWER_DEFAULT_VALUE 0xC3
#define ES8388_ADCPOWER 0x03
#define ES8388_ADCPOWER_DEFAULT_VALUE 0xFC
#define ES8388_DACPOWER 0x04
#define ES8388_DACPOWER_DEFAULT_VALUE 0xC0
#define ES8388_CHIPLOPOW1 0x05
#define ES8388_CHIPLOPOW1_DEFAULT_VALUE 0x00
#define ES8388_CHIPLOPOW2 0x06
#define ES8388_CHIPLOPOW2_DEFAULT_VALUE 0x00
#define ES8388_ANAVOLMANAG 0x07
#define ES8388_ANAVOLMANAG_DEFAULT_VALUE 0x7C
#define ES8388_MASTERMODE 0x08
#define ES8388_MASTERMODE_DEFAULT_VALUE 0x80
/* ADC */
#define ES8388_ADCCONTROL1 0x09
#define ES8388_ADCCONTROL1_DEFAULT_VALUE 0x00
#define ES8388_ADCCONTROL2 0x0a
#define ES8388_ADCCONTROL2_DEFAULT_VALUE 0x00
#define ES8388_ADCCONTROL3 0x0b
#define ES8388_ADCCONTROL3_DEFAULT_VALUE 0x00
#define ES8388_ADCCONTROL4 0x0c
#define ES8388_ADCCONTROL4_DEFAULT_VALUE 0x06
#define ES8388_ADCCONTROL5 0x0d
#define ES8388_ADCCONTROL5_DEFAULT_VALUE 0x30
#define ES8388_ADCCONTROL6 0x0e
#define ES8388_ADCCONTROL6_DEFAULT_VALUE 0x20
#define ES8388_ADCCONTROL7 0x0f
#define ES8388_ADCCONTROL7_DEFAULT_VALUE 0x20
#define ES8388_ADCCONTROL8 0x10
#define ES8388_ADCCONTROL8_DEFAULT_VALUE 0xC0
#define ES8388_ADCCONTROL9 0x11
#define ES8388_ADCCONTROL9_DEFAULT_VALUE 0xC0
#define ES8388_ADCCONTROL10 0x12
#define ES8388_ADCCONTROL10_DEFAULT_VALUE 0x38
#define ES8388_ADCCONTROL11 0x13
#define ES8388_ADCCONTROL11_DEFAULT_VALUE 0xB0
#define ES8388_ADCCONTROL12 0x14
#define ES8388_ADCCONTROL12_DEFAULT_VALUE 0x32
#define ES8388_ADCCONTROL13 0x15
#define ES8388_ADCCONTROL13_DEFAULT_VALUE 0x06
#define ES8388_ADCCONTROL14 0x16
#define ES8388_ADCCONTROL14_DEFAULT_VALUE 0x00
/* DAC */
#define ES8388_DACCONTROL1 0x17
#define ES8388_DACCONTROL1_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL2 0x18
#define ES8388_DACCONTROL2_DEFAULT_VALUE 0x06
#define ES8388_DACCONTROL3 0x19
#define ES8388_DACCONTROL3_DEFAULT_VALUE 0x22
#define ES8388_DACCONTROL4 0x1a
#define ES8388_DACCONTROL4_DEFAULT_VALUE 0xC0
#define ES8388_DACCONTROL5 0x1b
#define ES8388_DACCONTROL5_DEFAULT_VALUE 0xC0
#define ES8388_DACCONTROL6 0x1c
#define ES8388_DACCONTROL6_DEFAULT_VALUE 0x08
#define ES8388_DACCONTROL7 0x1d
#define ES8388_DACCONTROL7_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL8 0x1e
#define ES8388_DACCONTROL8_DEFAULT_VALUE 0x1F
#define ES8388_DACCONTROL9 0x1f
#define ES8388_DACCONTROL9_DEFAULT_VALUE 0xF7
#define ES8388_DACCONTROL10 0x20
#define ES8388_DACCONTROL10_DEFAULT_VALUE 0xFD
#define ES8388_DACCONTROL11 0x21
#define ES8388_DACCONTROL11_DEFAULT_VALUE 0xFF
#define ES8388_DACCONTROL12 0x22
#define ES8388_DACCONTROL12_DEFAULT_VALUE 0x1F
#define ES8388_DACCONTROL13 0x23
#define ES8388_DACCONTROL13_DEFAULT_VALUE 0xF7
#define ES8388_DACCONTROL14 0x24
#define ES8388_DACCONTROL14_DEFAULT_VALUE 0xFD
#define ES8388_DACCONTROL15 0x25
#define ES8388_DACCONTROL15_DEFAULT_VALUE 0xFF
#define ES8388_DACCONTROL16 0x26
#define ES8388_DACCONTROL16_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL17 0x27
#define ES8388_DACCONTROL17_DEFAULT_VALUE 0x38
#define ES8388_DACCONTROL18 0x28
#define ES8388_DACCONTROL18_DEFAULT_VALUE 0x28
#define ES8388_DACCONTROL19 0x29
#define ES8388_DACCONTROL19_DEFAULT_VALUE 0x28
#define ES8388_DACCONTROL20 0x2a
#define ES8388_DACCONTROL20_DEFAULT_VALUE 0x38
#define ES8388_DACCONTROL21 0x2b
#define ES8388_DACCONTROL21_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL22 0x2c
#define ES8388_DACCONTROL22_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL23 0x2d
#define ES8388_DACCONTROL23_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL24 0x2e
#define ES8388_DACCONTROL24_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL25 0x2f
#define ES8388_DACCONTROL25_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL26 0x30
#define ES8388_DACCONTROL26_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL27 0x31
#define ES8388_DACCONTROL27_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL28 0x32
#define ES8388_DACCONTROL28_DEFAULT_VALUE 0x00
#define ES8388_DACCONTROL29 0x33
#define ES8388_DACCONTROL29_DEFAULT_VALUE 0xAA
#define ES8388_DACCONTROL30 0x34
#define ES8388_DACCONTROL30_DEFAULT_VALUE 0xAA
/* typedef -------------------------------------------------------------------*/
#define CODEC_MEM_CHECK(ptr) \
if (ptr == NULL) { \
ESP_LOGE("ES8388", "Fail to alloc memory at %s:%d", __FUNCTION__, \
__LINE__); \
}
#define BITS(n) (1 << n)
#define MCLK_DEFAULT_DIV (256)
typedef enum
{
BIT_LENGTH_MIN = -1,
BIT_LENGTH_16BITS = 0x03,
BIT_LENGTH_18BITS = 0x02,
BIT_LENGTH_20BITS = 0x01,
BIT_LENGTH_24BITS = 0x00,
BIT_LENGTH_32BITS = 0x04,
BIT_LENGTH_MAX,
} es_bits_length_t;
typedef enum
{
MCLK_DIV_MIN = -1,
MCLK_DIV_1 = 1,
MCLK_DIV_2 = 2,
MCLK_DIV_3 = 3,
MCLK_DIV_4 = 4,
MCLK_DIV_6 = 5,
MCLK_DIV_8 = 6,
MCLK_DIV_9 = 7,
MCLK_DIV_11 = 8,
MCLK_DIV_12 = 9,
MCLK_DIV_16 = 10,
MCLK_DIV_18 = 11,
MCLK_DIV_22 = 12,
MCLK_DIV_24 = 13,
MCLK_DIV_33 = 14,
MCLK_DIV_36 = 15,
MCLK_DIV_44 = 16,
MCLK_DIV_48 = 17,
MCLK_DIV_66 = 18,
MCLK_DIV_72 = 19,
MCLK_DIV_5 = 20,
MCLK_DIV_10 = 21,
MCLK_DIV_15 = 22,
MCLK_DIV_17 = 23,
MCLK_DIV_20 = 24,
MCLK_DIV_25 = 25,
MCLK_DIV_30 = 26,
MCLK_DIV_32 = 27,
MCLK_DIV_34 = 28,
MCLK_DIV_7 = 29,
MCLK_DIV_13 = 30,
MCLK_DIV_14 = 31,
MCLK_DIV_MAX,
} es_sclk_div_t;
typedef enum
{
LCLK_DIV_MIN = -1,
LCLK_DIV_128 = 0,
LCLK_DIV_192 = 1,
LCLK_DIV_256 = 2,
LCLK_DIV_384 = 3,
LCLK_DIV_512 = 4,
LCLK_DIV_576 = 5,
LCLK_DIV_768 = 6,
LCLK_DIV_1024 = 7,
LCLK_DIV_1152 = 8,
LCLK_DIV_1408 = 9,
LCLK_DIV_1536 = 10,
LCLK_DIV_2112 = 11,
LCLK_DIV_2304 = 12,
LCLK_DIV_125 = 16,
LCLK_DIV_136 = 17,
LCLK_DIV_250 = 18,
LCLK_DIV_272 = 19,
LCLK_DIV_375 = 20,
LCLK_DIV_500 = 21,
LCLK_DIV_544 = 22,
LCLK_DIV_750 = 23,
LCLK_DIV_1000 = 24,
LCLK_DIV_1088 = 25,
LCLK_DIV_1496 = 26,
LCLK_DIV_1500 = 27,
LCLK_DIV_MAX,
} es_lclk_div_t;
typedef enum
{
D2SE_PGA_GAIN_MIN = -1,
D2SE_PGA_GAIN_DIS = 0,
D2SE_PGA_GAIN_EN = 1,
D2SE_PGA_GAIN_MAX = 2,
} es_d2se_pga_t;
typedef enum
{
ADC_INPUT_MIN = -1,
ADC_INPUT_LINPUT1_RINPUT1 = 0x00,
ADC_INPUT_MIC1 = 0x05,
ADC_INPUT_MIC2 = 0x06,
ADC_INPUT_LINPUT2_RINPUT2 = 0x50,
ADC_INPUT_DIFFERENCE = 0xf0,
ADC_INPUT_MAX,
} es_adc_input_t;
typedef enum
{
DAC_OUTPUT_MIN = -1,
DAC_OUTPUT_LOUT1 = 0x04,
DAC_OUTPUT_LOUT2 = 0x08,
DAC_OUTPUT_SPK = 0x09,
DAC_OUTPUT_ROUT1 = 0x10,
DAC_OUTPUT_ROUT2 = 0x20,
DAC_OUTPUT_ALL = 0x3c,
DAC_OUTPUT_MAX,
} es_dac_output_t;
typedef enum
{
MIC_GAIN_MIN = -1,
MIC_GAIN_0DB = 0,
MIC_GAIN_3DB = 3,
MIC_GAIN_6DB = 6,
MIC_GAIN_9DB = 9,
MIC_GAIN_12DB = 12,
MIC_GAIN_15DB = 15,
MIC_GAIN_18DB = 18,
MIC_GAIN_21DB = 21,
MIC_GAIN_24DB = 24,
MIC_GAIN_MAX,
} es_mic_gain_t;
typedef enum
{
ES_MODULE_MIN = -1,
ES_MODULE_ADC = 0x01,
ES_MODULE_DAC = 0x02,
ES_MODULE_ADC_DAC = 0x03,
ES_MODULE_LINE = 0x04,
ES_MODULE_MAX
} es_module_t;
typedef enum
{
ES_MODE_MIN = -1,
ES_MODE_SLAVE = 0x00,
ES_MODE_MASTER = 0x01,
ES_MODE_MAX,
} es_mode_t;
typedef enum
{
ES_I2S_MIN = -1,
ES_I2S_NORMAL = 0,
ES_I2S_LEFT = 1,
ES_I2S_RIGHT = 2,
ES_I2S_DSP = 3,
ES_I2S_MAX
} es_i2s_fmt_t;
typedef struct
{
es_sclk_div_t sclk_div; /*!< bits clock divide */
es_lclk_div_t lclk_div; /*!< WS clock divide */
} es_i2s_clock_t;
typedef enum
{
ES_PA_SETUP = 1,
ES_PA_ENABLE = (1 << 1),
ES_PA_DISABLE = (1 << 2),
} es_pa_setting_t;
typedef enum __imp_es_8388_io_port_e__
{
EM_IMP_ES8388_LINE_IN_1 = 0x00,
EM_IMP_ES8388_LINE_IN_2,
EM_IMP_ES8388_LINE_IN_ALL,
EM_IMP_ES8388_LINE_OUT_1,
EM_IMP_ES8388_LINE_OUT_2,
} imp_es_8388_io_port_e;
typedef struct __imp_es8388_cfg_t__
{
uint8_t is_init;
es_mode_t mode;
imp_es_8388_io_port_e dac_output;
imp_es_8388_io_port_e adc_input;
es_i2s_fmt_t fmt;
es_bits_length_t bit;
uint8_t (*read_reg)(uint8_t reg_addr, uint8_t* reg_data);
uint8_t (*write_reg)(uint8_t reg_addr, uint8_t reg_data);
} imp_es8388_cfg_t;
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/**
* @brief Initialize ES8388 codec chip
*
* @param cfg configuration of ES8388
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_init(es_mode_t mode, imp_es_8388_io_port_e dac_output,
imp_es_8388_io_port_e adc_input,
uint8_t (*read_reg)(uint8_t reg_addr, uint8_t* reg_data),
uint8_t (*write_reg)(uint8_t reg_addr, uint8_t reg_data));
/**
* @brief Deinitialize ES8388 codec chip
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_deinit(void);
/**
* @brief Configure ES8388 I2S format
*
* @param mod: set ADC or DAC or both
* @param cfg: ES8388 I2S format
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_config_fmt(es_module_t mod, es_i2s_fmt_t cfg);
/**
* @brief Configure I2s clock in MSATER mode
*
* @param cfg: set bits clock and WS clock
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_i2s_config_clock(es_i2s_clock_t cfg);
/**
* @brief Configure ES8388 data sample bits
*
* @param mode: set ADC or DAC or both
* @param bit_per_sample: bit number of per sample
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_set_bits_per_sample(es_module_t mode,
es_bits_length_t bit_per_sample);
/**
* @brief Start ES8388 codec chip
*
* @param mode: set ADC or DAC or both
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_start(es_module_t mode);
/**
* @brief Stop ES8388 codec chip
*
* @param mode: set ADC or DAC or both
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_stop(es_module_t mode);
/**
* @brief Set voice volume
*
* @param volume: voice volume (0~100)
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_set_voice_volume(int volume);
/**
* @brief Get voice volume
*
* @param[out] *volume: voice volume (0~100)
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
int es8388_get_voice_volume(int* volume);
/**
* @brief Configure ES8388 DAC mute or not. Basically you can use this function to mute the output or unmute
*
* @param enable enable(1) or disable(0)
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_set_voice_mute(bool enable);
/**
* @brief Get ES8388 DAC mute status
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_get_voice_mute(void);
/**
* @brief Set ES8388 mic gain
*
* @param gain db of mic gain
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_set_mic_gain(es_mic_gain_t gain);
/**
* @brief Set ES8388 adc input mode
*
* @param input adc input mode
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_config_adc_input(es_adc_input_t input);
/**
* @brief Set ES8388 dac output mode
*
* @param output dac output mode
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_config_dac_output(es_dac_output_t output);
/**
* @brief Print all ES8388 registers
*/
void es8388_read_all(void);
/**
* @brief Configure ES8388 codec mode and I2S interface
*
* @param fmt codec fmt
* @param bit I2S bit
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_config_i2s(es_i2s_fmt_t fmt, es_bits_length_t bit);
/**
* @brief Control ES8388 codec chip
*
* @param mode codec mode
* @param start_flag start or stop decode or encode progress
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
int es8388_ctrl_state(codec_work_mode_t mode, uint8_t start_flag);
/**
* @brief Set ES8388 PA power
*
* @param enable true for enable PA power, false for disable PA power
*
* @return
* - ESP_ERR_INVALID_ARG
* - ESP_OK
*/
int es8388_pa_power(bool enable);
#ifdef __cplusplus
}
#endif
#endif //__ES8388_H__
/*
* EOF
*/

View File

View File

@ -0,0 +1,67 @@
/**
* @file imp_codec.h
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-25
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-25 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __IMP_CODEC_H__
#define __IMP_CODEC_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <esp_err.h>
/* define --------------------------------------------------------------------*/
#define ESP_CODEC_DEV_OK (0)
#define ESP_CODEC_DEV_DRV_ERR (ESP_FAIL)
#define ESP_CODEC_DEV_INVALID_ARG (ESP_ERR_INVALID_ARG)
#define ESP_CODEC_DEV_NO_MEM (ESP_ERR_NO_MEM)
#define ESP_CODEC_DEV_NOT_SUPPORT (ESP_ERR_NOT_SUPPORTED)
#define ESP_CODEC_DEV_NOT_FOUND (ESP_ERR_NOT_FOUND)
#define ESP_CODEC_DEV_WRONG_STATE (ESP_ERR_INVALID_STATE)
#define ESP_CODEC_DEV_WRITE_FAIL (0x10D)
#define ESP_CODEC_DEV_READ_FAIL (0x10E)
/* typedef -------------------------------------------------------------------*/
typedef enum
{
EM_IMP_CODEC_DEV_WORK_MODE_NONE,
EM_IMP_CODEC_DEV_WORK_MODE_ADC =
(1 << 0), /*!< Enable ADC, only support input */
EM_IMP_CODEC_DEV_WORK_MODE_DAC =
(1 << 1), /*!< Enable DAC, only support output */
EM_IMP_CODEC_DEV_WORK_MODE_BOTH =
(EM_IMP_CODEC_DEV_WORK_MODE_ADC
| EM_IMP_CODEC_DEV_WORK_MODE_DAC), /*!< Support both DAC and ADC */
EM_IMP_CODEC_DEV_WORK_MODE_LINE = (1 << 2), /*!< Line mode */
} codec_work_mode_t;
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif //__IMP_CODEC_H__
/*
* EOF
*/

View File

@ -31,13 +31,17 @@
/* define --------------------------------------------------------------------*/
#define I2C_BUS_0_SCL_PIN 34
#define I2C_BUS_0_SDA_PIN 33
#define I2C_BUS_1_SCL_PIN 12
#define I2C_BUS_1_SDA_PIN 13
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
static uint8_t is_bus_0_inited = 0;
static uint8_t is_bus_1_inited = 0;
i2c_master_bus_handle_t bus0_handle;
static imp_esp_i2c_master_dev_op_t i2c_bus_0_handle = { 0 };
i2c_master_bus_handle_t bus1_handle;
/* Private function(only *.c) -----------------------------------------------*/
void _imp_esp_i2c_master_dev_op_bus_init(
@ -53,6 +57,16 @@ void _imp_esp_i2c_master_dev_op_bus_init(
.flags.enable_internal_pullup = true,
};
i2c_new_master_bus(&bus_config, &bus0_handle);
} else if (port == EM_IMP_ESP_I2C_PORT_1) {
i2c_master_bus_config_t bus_config = {
.i2c_port = I2C_NUM_1,
.sda_io_num = I2C_BUS_1_SDA_PIN,
.scl_io_num = I2C_BUS_1_SCL_PIN,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_new_master_bus(&bus_config, &bus1_handle);
}
}
@ -89,11 +103,20 @@ imp_esp_i2c_master_dev_op_init(imp_esp_i2c_master_dev_op_t* handle,
handle->bus_handle = bus0_handle;
_imp_esp_i2c_master_dev_op_handle_init(handle);
break;
case EM_IMP_ESP_I2C_PORT_1:
if (!is_bus_1_inited) {
_imp_esp_i2c_master_dev_op_bus_init(EM_IMP_ESP_I2C_PORT_1);
is_bus_1_inited = 1;
}
handle->bus_handle = bus1_handle;
_imp_esp_i2c_master_dev_op_handle_init(handle);
break;
default:
break;
}
return 0;
}
uint8_t imp_esp_i2c_master_dev_op_read(imp_esp_i2c_master_dev_op_t* handle,
uint8_t* reg, uint16_t reg_len,
uint8_t* data, uint16_t data_len)
@ -107,6 +130,7 @@ uint8_t imp_esp_i2c_master_dev_op_read(imp_esp_i2c_master_dev_op_t* handle,
return 0;
}
uint8_t imp_esp_i2c_master_dev_op_write(imp_esp_i2c_master_dev_op_t* handle,
uint8_t* data, uint16_t data_len)
{

View File

View File

@ -0,0 +1,474 @@
<svg host="65bd71144e" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="700px" height="572px" viewBox="-0.5 -0.5 700 572" content="&lt;mxfile&gt;&lt;diagram id=&quot;4lzMezdkBWo0tUiM_ga_&quot; name=&quot;第 1 页&quot;&gt;7Vxfj6M2EP80ka4PWfEf8rjZzbWV0na1uVN7TysCToKW4BTY26SfvjbYAWOckOAkyx2rkw4PtrHHMz/PjMcZ6A/r7a+xu1n9AX0QDjTF3w70x4Gmqbpjof8wZZdTbFPJCcs48EmlgjAL/gOESKu9BT5ImIophGEabFiiB6MIeClDc+MYvrPVFjBkv7pxl4AjzDw35Kl/B366yqmOZhf030CwXNEvq9Yof7N2aWUyk2Tl+vC9RNInA/0hhjDNn9bbBxBi5lG+5O0+C97uBxaDKG3SQMsbfHfDNzI3Mq50RyeLGiC+osJ4la5DRFPRIxr3Br8HkT9L3RS/XQRh+ABDGGfNdN8FzsLDVdMYvoLSG8tzwHyxf0M5qOE+YJTOyKfJXL6DOAVb4fTUPdOQtAG4Bmm8Q1VoA8PMmxBBMx3C9/di2XRCWpVWjNJcIijLfc8FL9EDYWc9a3WOtU/Pk9mM42/yHqxDNwLc9PWxGwbLCD17aLoAcW+MmREgObwnL9aB7+PaY28VhP7U3cE3PIMkdb1XWhqvYBz8h3p294uXunFKtArNtFxjhlsiMqbGIEF1niizC9LUTVLSlYdbBREeXFbBg2HobpJgns0hawLfIh/4dEaxV/6wWDaE0kS49Zl9v0B/Hu7Rj+HmixsvAR2yBCkybJWRIoMXItWqkSJbghQZIikaZ/+sEK/wPEZPS/z0CnYvaJHeEJnUqEgb4kJaUWVmDSIYVZWZkJoLY7JxvSBaTsECM8IoKM+EN5j0vgpSMEN0PLB3tE8gGkRdLsIMD1eoMxBl8oPwxS3kCetIaeGV7O8s6NDrF33HQsCxRTYkLLLm8Kjrox2HFGGcruASRm44KajlJQTbIP0H8+fOJKVvhFv4+XFbLuxoIUKDLDXCxW+0P1wommUl2u4kOBcocc1a4fkeVk/EHvgWe6QWsSBSquqoOKpfzxiEbhp8Z3tvBexUvEo6iXQuKWtjaSmtf99gRoaxD+Khl/PjPusg/jQclum/ZIBFW1ClDhHeviTZNou2c9yn8jyZ3s8mvP77YI7w1isqKrWSNXXnyCRjZKi5emebQEkjNzCI0oyf5nhgPjbWRWKdkZ4Km6i88rlmCJFZuTNMCpE7pvPGq076fsKTKDoeUuymvepsD3CxSJDcVaVmP8JmgmS3VHuqwmpZgZXOKrButdTgrOl9HLu7UgUinsKl1hV2qU2lYjKfVh895CM4VyoMi4OXOq223DXeMqN5ssmgQhnYDxdDIAQ3kwxvig8v8/cKYsc64YdzyDDpMiDlOisEpKFyp1kW63QMJUGSarHd6qMLYJJpyjFF6HOGSHcatUuO2CIskBWGSeegzLgFku3DKNRPccyDSFatP5ILZGYDIFNrpa0zaJBryyE0cCyVtU8koYFd6dS6ABbw64f3AbwN9CGMa4YweDATCm2LoIbd0OG1JDi8dq1kZRZGH7U4vKoCG/nEqIWMAKdW71ue7r4od/ZJIYgi3GE3j3d8EFvBkW8rNI5b8BFpaqcjSY9qXQY842GSwR32F1Rts83N/jkC2WUGjGV/Il7OP2kmGisajFJ+qHcr2JhGOcwhjmtU31AKmn0+C0rusl1ROguqD3sg202KGVGxANVKB1LMCIcTu8fJ+K+vfz70hkT3z0Ia7ziqImHLGXGi1BxCCqETHZ2Azcsr2OVIVuepVFtE8AU3EjTgd8feitkLmSCse6IVI+OAjbpnEqwYjbFimsVhm5gdB5ChvUFCcyrKFomqXckkoR8/O/8gh++PnIGgsMFAixftSyUgqG1DeXvJPl2sb25nqxov1m0PCM8Kyhkqa2JRCRAF5Y7Ubx2VU/moDnd6KTx2/P1x+hMcOqpHo3q642hS7G+HWethVe2l2N9GDaZeL7tg0MWIfh16CNJFpO+JBu+mNzFGiRJ3We8Mgdmx93pV02Hj3i1j6fvo+SVO0tS2p/tU7QZnnaTdKYpW0b2RfSywhktPIA7QNPdu7AdRyRGvkWZblTyyobdJ7dBqDNuOxNqEEbWbjr8aAfxYo/tJ4pLq4ewHnPygXCT5QWdt4kuEKekmICEQcEYc4Ob4avD4KgjSyD+Y4KMAzyAEblIDTjVOCUmI/uG9EoH7WvJKbFb35LgoQ0tjejUvoHtaW92rPxGkr45mQNtd1Ngai6htAmVjjeWvJfTmTW/edN28EUUIC4i1FKMSspEDsiaLsapzAZDV294y6faNEd3k8fJqBx3040zG0+zr9Au3JP0RePdy6Rw2ZH/VVDqjPoW2XcJ2M7upi9dOatwcgU974VztygUj+/CpULW67EsnJn+n7cMYROKY9w9phBiHsQbnlOsWexWkpQ0i97RJ1l3WMh7dNYx6d9STqwGlq1kmBp9T1eS6Wac17NilUtOmzrXUS6UXubCl8+f5CYh8RDlw5a7PRDvPsqPb7lXy6826IEtlIfE2u5GqHCfxo3GmngxLlx7Kl/iR56P0HtQ1PahGWmUKLjVcQ05MPoGiDIX7Pa1mG+tx8egK3uCikclfFxMC4bkZnd2GRpO/Y9FDY2eCS6YgAnEVyeHN/x4sTwdLwQreACxpv/11q67CwUe+gGXxccL+BlYnIcsSXDG9wRUsmmDS/1TmT4BX1/zxTEv4G6z9r2e2xg9BgPryP5+JisUPJOcR0+JnpvXJ/w==&lt;/diagram&gt;&lt;/mxfile&gt;">
<defs/>
<g>
<ellipse cx="81" cy="556" rx="11" ry="11" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" pointer-events="all"/>
<ellipse cx="81" cy="556" rx="15" ry="15" fill="none" stroke="#6c8ebf" stroke-width="2" pointer-events="all"/>
<path d="M 552 31 L 552 28 Q 552 1 525 1 L 419 1 Q 392 1 392 28 L 392 31" fill="#dae8fc" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 31 L 392 44 Q 392 71 419 71 L 525 71 Q 552 71 552 44 L 552 31" fill="#ffffc0" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 31 L 552 31" fill="none" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" text-anchor="middle" font-size="12px">
<text x="471.5" y="20.5">
PRESS
</text>
</g>
<rect x="392" y="31" width="160" height="40" fill="none" stroke="none" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 51px; margin-left: 397px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 36px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;">
PRESS++
<br/>
key_result++
</div>
</div>
</div>
</foreignObject>
<text x="472" y="55" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
PRESS++...
</text>
</switch>
</g>
<path d="M 472 431 L 472 299.24" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 472 293.24 L 476 301.24 L 472 299.24 L 468 301.24 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 343px; margin-left: 402px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
Press
<br style="border-color: var(--border-color);"/>
last_state = RELASE
<br/>
debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="402" y="346" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
Press...
</text>
</switch>
</g>
<path d="M 392 461 L 231 461 Q 221 461 211 461 L 169.24 461" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 163.24 461 L 171.24 457 L 169.24 461 L 171.24 465 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 422px; margin-left: 292px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
debounce = 0  |
<br style="border-color: var(--border-color);"/>
RELEASE &gt; 300ms
<br/>
key_result
</div>
</div>
</div>
</foreignObject>
<text x="292" y="425" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
debounce = 0  |...
</text>
</switch>
</g>
<path d="M 552 446 L 661 446 Q 671 446 671 436 L 671 61 Q 671 51 661 51 L 560.24 51" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 554.24 51 L 562.24 47 L 560.24 51 L 562.24 55 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 432px; margin-left: 604px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
debounce = 1
</div>
</div>
</div>
</foreignObject>
<text x="604" y="435" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
debounce = 1
</text>
</switch>
</g>
<path d="M 552 461 L 552 458 Q 552 431 525 431 L 419 431 Q 392 431 392 458 L 392 461" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 461 L 392 464 Q 392 491 419 491 L 525 491 Q 552 491 552 464 L 552 461" fill="#ffffc0" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 461 L 552 461" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" text-anchor="middle" font-size="12px">
<text x="471.5" y="450.5">
RELESE
</text>
</g>
<rect x="392" y="461" width="160" height="30" fill="none" stroke="none" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 476px; margin-left: 397px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 26px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;">
RELEASE++
</div>
</div>
</div>
</foreignObject>
<text x="472" y="480" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
RELEASE++
</text>
</switch>
</g>
<path d="M 512 191 L 512 79.24" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 512 73.24 L 516 81.24 L 512 79.24 L 508 81.24 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 126px; margin-left: 563px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
state = last_state
<br/>
debounce
<br/>
</span>
</div>
</div>
</div>
</foreignObject>
<text x="563" y="129" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
state = last_state...
</text>
</switch>
</g>
<path d="M 552 221 L 552 218 Q 552 191 525 191 L 419 191 Q 392 191 392 218 L 392 221" fill="#dae8fc" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 221 L 392 264 Q 392 291 419 291 L 525 291 Q 552 291 552 264 L 552 221" fill="#ffffc0" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 392 221 L 552 221" fill="none" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="all"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" text-anchor="middle" font-size="12px">
<text x="471.5" y="210.5">
DEBOUNCE
</text>
</g>
<rect x="392" y="221" width="160" height="70" fill="none" stroke="none" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 256px; margin-left: 397px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 66px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;">
state = last_state
<br/>
DEBOUNCE++
<br/>
keep_key: debounce = 1
<br/>
no_keep: debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="472" y="260" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
state = last_state...
</text>
</switch>
</g>
<path d="M 41 51 L 41 182.76" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 41 188.76 L 37 180.76 L 41 182.76 L 45 180.76 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<ellipse cx="41" cy="36" rx="11" ry="11" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" pointer-events="all"/>
<path d="M 161 221 L 321 221 Q 331 221 341 221 L 383.76 221" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 389.76 221 L 381.76 225 L 383.76 221 L 381.76 217 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 192px; margin-left: 241px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
Press
<br/>
last_state = IDLE
<br/>
debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="241" y="195" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
Press...
</text>
</switch>
</g>
<path d="M 81 191 L 81 46 Q 81 36 91 36 L 383.76 36" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 389.76 36 L 381.76 40 L 383.76 36 L 381.76 32 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 17px; margin-left: 197px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
debounce = 1
<br/>
Press
</div>
</div>
</div>
</foreignObject>
<text x="197" y="20" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
debounce = 1...
</text>
</switch>
</g>
<path d="M 392 238.5 L 286.5 238.5 Q 276.5 238.5 266.5 238.54 L 169.56 238.88" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 163.56 238.9 L 171.54 234.87 L 169.56 238.88 L 171.57 242.87 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 259px; margin-left: 250px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
state = last_state
<br/>
</span>
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
debounce
</span>
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
<br/>
</span>
</div>
</div>
</div>
</foreignObject>
<text x="250" y="263" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
state = last_state...
</text>
</switch>
</g>
<path d="M 472 71 L 472 182.76" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 472 188.76 L 468 180.76 L 472 182.76 L 476 180.76 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 115px; margin-left: 413px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
Release
<br/>
last_state = PRESS
<br/>
debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="413" y="118" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
Release...
</text>
</switch>
</g>
<path d="M 512 291 L 512 422.76" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 512 428.76 L 508 420.76 L 512 422.76 L 516 420.76 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 338px; margin-left: 563px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
state = last_state
<br/>
</span>
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
debounce
</span>
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
<br/>
</span>
</div>
</div>
</div>
</foreignObject>
<text x="563" y="341" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
state = last_state...
</text>
</switch>
</g>
<path d="M 81 431 L 81 259.24" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 81 253.24 L 85 261.24 L 81 259.24 L 77 261.24 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 161 461 L 161 458 Q 161 431 134 431 L 28 431 Q 1 431 1 458 L 1 461" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 1 461 L 1 464 Q 1 491 28 491 L 134 491 Q 161 491 161 464 L 161 461" fill="#ffffc0" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<path d="M 1 461 L 161 461" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" text-anchor="middle" font-size="12px">
<text x="80.5" y="450.5">
RESULT
</text>
</g>
<path d="M 552 31 L 681 31 Q 691 31 691 41 L 691 451 Q 691 461 681 461 L 560.24 461" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 554.24 461 L 562.24 457 L 560.24 461 L 562.24 465 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 30px; margin-left: 611px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
<span style="font-size: 12px; background-color: rgb(251, 251, 251);">
debounce = 1
<br/>
</span>
</div>
</div>
</div>
</foreignObject>
<text x="611" y="33" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
debounce = 1
</text>
</switch>
</g>
<path d="M 392 51 L 131 51 Q 121 51 121 61 L 121 182.76" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="stroke"/>
<path d="M 121 188.76 L 117 180.76 L 121 182.76 L 125 180.76 Z" fill="#6c8ebf" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 104px; margin-left: 162px;">
<div data-drawio-colors="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); " style="box-sizing: border-box; font-size: 0px; text-align: center;">
<div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; background-color: rgb(255, 255, 255); white-space: nowrap;">
debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="162" y="107" fill="rgb(0, 0, 0)" font-family="Helvetica" font-size="11px" text-anchor="middle" font-weight="bold">
debounce = 0
</text>
</switch>
</g>
<rect x="1" y="461" width="160" height="30" fill="none" stroke="none" pointer-events="all"/>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 476px; margin-left: 6px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 26px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: all; font-weight: bold; white-space: normal; overflow-wrap: normal;">
send key_result
</div>
</div>
</div>
</foreignObject>
<text x="81" y="480" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
send key_result
</text>
</switch>
</g>
<path d="M 161 221 L 161 218 Q 161 191 134 191 L 28 191 Q 1 191 1 218 L 1 221" fill="#dae8fc" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 1 221 L 1 224 Q 1 251 28 251 L 134 251 Q 161 251 161 224 L 161 221" fill="#ffffc0" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 1 221 L 161 221" fill="none" stroke="#6c8ebf" stroke-miterlimit="10" pointer-events="none"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" pointer-events="none" text-anchor="middle" font-size="12px">
<text x="80.5" y="210.5">
IDLE
</text>
</g>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 236px; margin-left: 6px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 26px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; font-weight: bold; white-space: normal; overflow-wrap: normal;">
key_result = 0;
</div>
</div>
</div>
</foreignObject>
<text x="81" y="240" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
key_result = 0;
</text>
</switch>
</g>
<path d="M 161 221 L 161 218 Q 161 191 134 191 L 28 191 Q 1 191 1 218 L 1 221" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 1 221 L 1 224 Q 1 251 28 251 L 134 251 Q 161 251 161 224 L 161 221" fill="#ffffc0" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 1 221 L 161 221" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" pointer-events="none" text-anchor="middle" font-size="12px">
<text x="80.5" y="210.5">
IDLE
</text>
</g>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 236px; margin-left: 6px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 26px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; font-weight: bold; white-space: normal; overflow-wrap: normal;">
key_result = 0;
</div>
</div>
</div>
</foreignObject>
<text x="81" y="240" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
key_result = 0;
</text>
</switch>
</g>
<path d="M 552 221 L 552 218 Q 552 191 525 191 L 419 191 Q 392 191 392 218 L 392 221" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 392 221 L 392 264 Q 392 291 419 291 L 525 291 Q 552 291 552 264 L 552 221" fill="#ffffc0" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 392 221 L 552 221" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" pointer-events="none" text-anchor="middle" font-size="12px">
<text x="471.5" y="210.5">
DEBOUNCE
</text>
</g>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 256px; margin-left: 397px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 66px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; font-weight: bold; white-space: normal; overflow-wrap: normal;">
state = last_state
<br/>
DEBOUNCE++
<br/>
keep_key: debounce = 1
<br/>
no_keep: debounce = 0
</div>
</div>
</div>
</foreignObject>
<text x="472" y="260" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
state = last_state...
</text>
</switch>
</g>
<path d="M 552 31 L 552 28 Q 552 1 525 1 L 419 1 Q 392 1 392 28 L 392 31" fill="#dae8fc" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 392 31 L 392 44 Q 392 71 419 71 L 525 71 Q 552 71 552 44 L 552 31" fill="#ffffc0" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<path d="M 392 31 L 552 31" fill="none" stroke="#6c8ebf" stroke-width="2" stroke-miterlimit="10" pointer-events="none"/>
<g fill="rgb(0, 0, 0)" font-family="Helvetica" font-weight="bold" pointer-events="none" text-anchor="middle" font-size="12px">
<text x="471.5" y="20.5">
PRESS
</text>
</g>
<g transform="translate(-0.5 -0.5)">
<switch>
<foreignObject pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility" style="overflow: visible; text-align: left;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 150px; height: 1px; padding-top: 51px; margin-left: 397px;">
<div data-drawio-colors="color: #000000; " style="box-sizing: border-box; font-size: 0px; text-align: center; max-height: 36px; overflow: hidden;">
<div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; pointer-events: none; font-weight: bold; white-space: normal; overflow-wrap: normal;">
PRESS++
<br/>
key_result++
</div>
</div>
</div>
</foreignObject>
<text x="472" y="55" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle" font-weight="bold">
PRESS++...
</text>
</switch>
</g>
</g>
<switch>
<g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/>
<a transform="translate(0,-5)" xlink:href="https://www.diagrams.net/doc/faq/svg-export-text-problems" target="_blank">
<text text-anchor="middle" font-size="10px" x="50%" y="100%">
Text is not SVG - cannot display
</text>
</a>
</switch>
</svg>

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -0,0 +1,71 @@
/**
* @file key_scan.h
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-23
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-23 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __KEY_SCAN_H__
#define __KEY_SCAN_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
typedef enum __key_scan_key_result_e__
{
EM_KEY_SCAN_RESULT_IDLE = 0x00,
EM_KEY_SCAN_RESULT_ONSHOT,
EM_KEY_SCAN_RESULT_DOUBLE,
EM_KEY_SCAN_RESULT_LONG,
} key_scan_key_result_e;
typedef enum __key_scan_key_stm_e__
{
EM_KEY_SCAN_KEY_STM_IDLE = 0x00,
EM_KEY_SCAN_KEY_STM_DEBOUNCE,
EM_KEY_SCAN_KEY_STM_PRESS,
EM_KEY_SCAN_KEY_STM_RELEASE,
EM_KEY_SCAN_KEY_STM_SEND_KEY,
} key_scan_key_stm_e;
typedef struct __key_scan_key_state_t__
{
key_scan_key_stm_e state;
key_scan_key_stm_e last_state;
uint16_t press_cnt;
uint16_t release_cnt;
uint8_t debounce_ret;
} key_scan_key_state_t;
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
uint8_t key_scan_init();
#ifdef __cplusplus
}
#endif
#endif //__KEY_SCAN_H__
/*
* EOF
*/

View File

@ -0,0 +1,32 @@
/**
* @file key_scan_cfg.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-23
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-23 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "key_scan.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/*
* EOF
*/

View File

@ -37,14 +37,11 @@
/// @brief 所有Task的命名集合名字长度不能超过configMAX_TASK_NAME_LEN = 16
char* imp_main_task_table[] = {
"idle",
"main_task",
"ext_trans_task",
"display",
"idle", "main_task", "ext_trans_task", "display", "audio",
};
/* Private function(only *.c) -----------------------------------------------*/
char cdc_print_buf[1024] = { 0 };
char cdc_print_buf[1024] = { 0 };
uint8_t _imp_set_out_port(int argc, char** argv)
{

View File

@ -36,6 +36,7 @@ extern "C" {
#define IMP_TASK_ID_MAIN_TASK (1)
#define IMP_TASK_ID_EXT_TRANS_SERVICE_TASK (2)
#define IMP_TASK_ID_DISP_SERVICE_TASK (3)
#define IMP_TASK_ID_AUDIO_SERVICE_TASK (4)
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
@ -46,6 +47,7 @@ extern char* imp_main_task_table[];
/* Exported functions --------------------------------------------------------*/
uint8_t imp_main_common_init();
int cdc_printf(const char* fmt, ...);
#ifdef __cplusplus

View File

@ -0,0 +1,125 @@
/**
* @file audio_service.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-24
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-24 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* 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 <stdlib.h>
#include <stdio.h>
#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, &reg_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, &reg_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
*/

View File

@ -0,0 +1,46 @@
/**
* @file audio_service.h
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-24
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-24 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __AUDIO_SERVICE_H__
#define __AUDIO_SERVICE_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include "main_common.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void imp_audio_service_task(void*);
#ifdef __cplusplus
}
#endif
#endif //__AUDIO_SERVICE_H__
/*
* EOF
*/

View File

@ -0,0 +1,93 @@
/**
* @file audio_service_codec_process.c
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-24
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-24 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "audio_service.h"
#include "imp_esp_i2c_master_dev_op.h"
#include "es8388.h"
#include "audio_service_process.h"
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
imp_esp_i2c_master_dev_op_t i2c_codec_handle;
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
uint8_t imp_audio_service_codec_process_init()
{
imp_esp_i2c_master_dev_op_init(&i2c_codec_handle, EM_IMP_ESP_I2C_PORT_1, 1,
0x11, 400000);
return 0;
}
uint8_t imp_audio_service_codec_read_process_reg(uint8_t reg_addr,
uint8_t* reg_data)
{
imp_esp_i2c_master_dev_op_read(&i2c_codec_handle, &reg_addr, 1, reg_data,
1);
return 0;
}
uint8_t imp_audio_service_codec_write_process_reg(uint8_t reg_addr,
uint8_t reg_data)
{
uint8_t data[2] = { 0 };
data[0] = reg_addr;
data[1] = reg_data;
imp_esp_i2c_master_dev_op_write(&i2c_codec_handle, data, 2);
return 0;
}
void imp_audio_service_codec_initialize()
{
es_mode_t mode = ES_MODE_SLAVE;
es_module_t io_mode = ES_MODULE_ADC_DAC;
es_i2s_fmt_t fmt = ES_I2S_NORMAL;
imp_es_8388_io_port_e dac_output = EM_IMP_ES8388_LINE_OUT_1;
imp_es_8388_io_port_e adc_input = EM_IMP_ES8388_LINE_IN_1;
// es_i2s_clock_t cfg =
es8388_init(mode, dac_output, adc_input,
imp_audio_service_codec_read_process_reg,
imp_audio_service_codec_write_process_reg);
es8388_start(io_mode);
}
void imp_audio_service_codec_start()
{
es_module_t io_mode = ES_MODULE_ADC_DAC;
es8388_start(io_mode);
}
void imp_audio_service_codec_stop()
{
es_module_t io_mode = ES_MODULE_ADC_DAC;
es8388_stop(io_mode);
}
void imp_audio_service_codec_set_vol(uint8_t vol)
{
es8388_set_voice_volume(vol);
}
/*
* EOF
*/

View File

@ -0,0 +1,55 @@
/**
* @file audio_service_process.h
* @author Alvin Young (impressionyang@outlook.com)
* @brief
* @version 0.1
* @date 2025-03-26
*
* _ _
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
* /_/ /___/ /___/
* @copyright Copyright (c) 2025 impressionyang
*
* @par :
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-03-26 <td>v1.0 <td>Alvin Young <td>
* </table>
*
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __AUDIO_SERVICE_PROCESS_H__
#define __AUDIO_SERVICE_PROCESS_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* define --------------------------------------------------------------------*/
/* typedef -------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/* Private function(only *.c) -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
uint8_t imp_audio_service_codec_process_init();
uint8_t imp_audio_service_codec_read_process_reg(uint8_t reg_addr,
uint8_t* reg_data);
uint8_t imp_audio_service_codec_write_process_reg(uint8_t reg_addr,
uint8_t reg_data);
void imp_audio_service_codec_initialize();
void imp_audio_service_codec_start();
void imp_audio_service_codec_stop();
void imp_audio_service_codec_set_vol(uint8_t vol);
#ifdef __cplusplus
}
#endif
#endif //__AUDIO_SERVICE_PROCESS_H__
/*
* EOF
*/

View File

@ -75,7 +75,7 @@ static void _imp_i2c_ssd_oled_init(void)
// i2c_param_config(I2C_NUM_0, &i2c_config);
// i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
imp_esp_i2c_master_dev_op_init(&i2c_oled_handle, EM_IMP_ESP_I2C_PORT_0, 1,
0x3C, 4000000);
0x3C, 400000);
}
/* Exported functions --------------------------------------------------------*/