mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
mp3_decoder = mp3_decoder_init(&mp3_cfg); // 初始化mp3 decoder元素
audio_element_set_read_cb(mp3_decoder, mp3_music_read_cb, NULL);
ESP_LOGI(TAG, “[2.2] Create i2s stream to write data to codec chip”);
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg); // 初始化i2s stream元素
ESP_LOGI(TAG, “[2.3] Register all elements to audio pipeline”); // 注册元素到管道中去
audio_pipeline_register(pipeline, mp3_decoder, “mp3”);
audio_pipeline_register(pipeline, i2s_stream_writer, “i2s”);
ESP_LOGI(TAG, “[2.4] Link it together [mp3_music_read_cb]–>mp3_decoder–>i2s_stream–>[codec_chip]”);
audio_pipeline_link(pipeline, (const char *[]) {“mp3”, “i2s”}, 2); // 将mp3_music_read_cb mp3_decoder i2s_stream codec_chip关联在一起
ESP_LOGI(TAG, “[ 3 ] Initialize peripherals”);
esp_periph_config_t periph_cfg = { 0 };
esp_periph_init(&periph_cfg);
ESP_LOGI(TAG, “[3.1] Initialize Touch peripheral”);
periph_touch_cfg_t touch_cfg = {
.touch_mask = TOUCH_SEL_SET | TOUCH_SEL_PLAY | TOUCH_SEL_VOLUP | TOUCH_SEL_VOLDWN,
.tap_threshold_percent = 70,
};
esp_periph_handle_t touch_periph = periph_touch_init(&touch_cfg); // 初始化按键
ESP_LOGI(TAG, “[3.2] Start all peripherals”);