espressif / esp-adf

Espressif Audio Development Framework
Other
1.52k stars 669 forks source link

guru meditation error (AUD-4819) #1055

Closed be-inexplicable closed 1 year ago

be-inexplicable commented 1 year ago

rst:0x1 (POWERON_RESET),boot:0x1f (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:7084 ho 0 tail 12 room 4 load:0x40078000,len:15576 ho 0 tail 12 room 4 load:0x40080400,len:4 load:0x40080404,len:3876 entry 0x4008064c I (33) boot: ESP-IDF v5.1-dirty 2nd stage bootloader I (33) boot: compile time Aug 15 2023 08:36:22 I (33) boot: Multicore bootloader I (38) boot: chip revision: v3.0 I (41) boot.esp32: SPI Speed : 40MHz I (46) boot.esp32: SPI Mode : DIO I (51) boot.esp32: SPI Flash Size : 8MB I (55) boot: Enabling RNG early entropy source... I (61) boot: Partition Table: I (64) boot: ## Label Usage Type ST Offset Length I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (79) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (86) boot: 2 factory factory app 00 00 00010000 005a0000 I (94) boot: End of partition table I (98) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=364b0h (222384) map I (152) esp_image: segment 1: paddr=000464d8 vaddr=3ffb0000 size=04304h ( 17156) load I (157) esp_image: segment 2: paddr=0004a7e4 vaddr=40080000 size=05834h ( 22580) load I (164) esp_image: segment 3: paddr=00050020 vaddr=400d0020 size=d2bd8h (863192) map I (344) esp_image: segment 4: paddr=00122c00 vaddr=40085834 size=1215ch ( 74076) load I (376) boot: Loaded app from partition at offset 0x10000 I (376) boot: Disabling RNG early entropy source... I (387) cpu_start: Multicore app I (388) quad_psram: This chip is ESP32-D0WD I (390) esp_psram: Found 8MB PSRAM device I (390) esp_psram: Speed: 40MHz I (393) esp_psram: PSRAM initialized, cache is in low/high (2-core) mode. W (401) esp_psram: Virtual address not enough for PSRAM, map as much as we can. 4MB is mapped I (410) cpu_start: Pro cpu up. I (414) cpu_start: Starting app cpu, entry point is 0x4008198c I (0) cpu_start: App cpu up. I (1326) esp_psram: SPI SRAM memory test OK I (1334) cpu_start: Pro cpu start user code I (1334) cpu_start: cpu freq: 240000000 Hz I (1334) cpu_start: Application information: I (1337) cpu_start: Project name: play_http_mp3 I (1343) cpu_start: App version: 1 I (1347) cpu_start: Compile time: Aug 15 2023 08:34:42 I (1354) cpu_start: ELF file SHA256: 911aba91c697095b... I (1360) cpu_start: ESP-IDF: v5.1-dirty I (1365) cpu_start: Min chip rev: v0.0 I (1370) cpu_start: Max chip rev: v3.99 I (1375) cpu_start: Chip rev: v3.0 I (1380) heap_init: Initializing. RAM available for dynamic allocation: I (1387) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (1393) heap_init: At 3FFB8D40 len 000272C0 (156 KiB): DRAM I (1399) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM I (1406) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (1412) heap_init: At 40097990 len 00008670 (33 KiB): IRAM I (1419) esp_psram: Adding pool of 4096K of PSRAM memory to heap allocator I (1427) spi_flash: detected chip: gd I (1430) spi_flash: flash io: dio W (1435) ADC: legacy driver is deprecated, please migrate to esp_adc/adc_oneshot.h W (1443) i2s(legacy): legacy i2s driver is deprecated, please migrate to use driver/i2s_std.h, driver/i2s_pdm.h or driver/i2s_tdm.h I (1456) app_start: Starting scheduler on CPU0 I (1461) app_start: Starting scheduler on CPU1 I (1461) main_task: Started on CPU0 I (1471) esp_psram: Reserving pool of 32K of internal memory for DMA/internal allocations I (1471) main_task: Calling app_main() I (1481) code: [ 1 ] nvs flash I (1521) code: [ 2 ] Start codec chip E (1551) gpio: gpio_install_isr_service(498): GPIO isr service already installed I (1551) code: [ 3 ] Start and wait for Wi-Fi network W (3861) PERIPH_WIFI: WiFi Event cb, Unhandle event_base:WIFI_EVENT, event_id:4 I (4861) code: [4] Mount sdcard I (5361) code: [ 5 ] Initialize Button peripheral with board init I (5361) code: [ 6 ] Create and start input key service W (5361) code: [ 7 ] Waiting for a button to be pressed ... W (5381) PERIPH_TOUCH: _touch_init I (9851) code: Selected mode: Play from HTTP E (9851) code: Pipeline initialization failed I (9851) code: Initializing HTTP Stream Element E (9851) code: Pipeline initialization failed Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump: PC : 0x4018a46b PS : 0x00060630 A0 : 0x800df934 A1 : 0x3ffd6840
A2 : 0x0000000c A3 : 0x0000000c A4 : 0x00000020 A5 : 0x3f816ab8
A6 : 0x00000000 A7 : 0x00000002 A8 : 0x800931cf A9 : 0x3ffd6820
A10 : 0x00001068 A11 : 0x00000000 A12 : 0x00000010 A13 : 0x3f816b94
A14 : 0x00000000 A15 : 0x00000001 SAR : 0x0000000c EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000068 LBEG : 0x4008be3a LEND : 0x4008be45 LCOUNT : 0x00000000

Backtrace: 0x4018a468:0x3ffd6840 0x400df931:0x3ffd6860 0x400dff8d:0x3ffd6890 0x400dd160:0x3ffd68e0 0x400dd4df:0x3ffd69a0 0x400dd809:0x3ffd69c0 0x400e4f79:0x3ffd69f0 0x40090b96:0x3ffd6a40

`#include "esp_log.h"

include "board.h"

include "esp_wifi.h"

include "nvs_flash.h"

include "esp_peripherals.h"

include "periph_adc_button.h"

include "input_key_service.h"

include "periph_wifi.h"

include "periph_sdcard.h"

include "audio_pipeline.h"

include

include "freertos/FreeRTOS.h"

include "freertos/task.h"

include "freertos/timers.h"

include "sdkconfig.h"

include "audio_element.h"

include "audio_event_iface.h"

include "audio_mem.h"

include "audio_common.h"

include "http_stream.h"

include "fatfs_stream.h"

include "i2s_stream.h"

include "wav_encoder.h"

include "wav_decoder.h"

include "filter_resample.h"

include "periph_button.h"

include "esp_netif.h"

define RECORD_TIME_SECONDS 130

define RECORD_RATE 48000

define RECORD_CHANNEL 2

define RECORD_BITS 16

define SAVE_FILE_RATE 16000

define SAVE_FILE_CHANNEL 1

define SAVE_FILE_BITS 16

define PLAYBACK_RATE 48000

define PLAYBACK_CHANNEL 2

define PLAYBACK_BITS 16

define CONFIG_WIFI_SSID "Pixel_2261"

define CONFIG_WIFI_PASSWORD "123412341234"

static const char *TAG = "code"; static bool r = false; esp_periph_set_handle_t set; esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();

/***/

static audio_element_handle_t create_filter(int source_rate, int source_channel, int dest_rate, int dest_channel, int mode) { rsp_filter_cfg_t rsp_cfg = DEFAULT_RESAMPLE_FILTER_CONFIG(); rsp_cfg.src_rate = source_rate; rsp_cfg.src_ch = source_channel; rsp_cfg.dest_rate = dest_rate; rsp_cfg.dest_ch = dest_channel; rsp_cfg.mode = mode; rsp_cfg.complexity = 0; return rsp_filter_init(&rsp_cfg); }

static audio_element_handle_t create_fatfs_stream(int sample_rates, int bits, int channels, audio_stream_type_t type) { fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT(); fatfs_cfg.type = type; audio_element_handle_t fatfs_stream = fatfs_stream_init(&fatfs_cfg); mem_assert(fatfs_stream); audio_element_info_t writer_info = {0}; audio_element_getinfo(fatfs_stream, &writer_info); writer_info.bits = bits; writer_info.channels = channels; writer_info.sample_rates = sample_rates; audio_element_setinfo(fatfs_stream, &writer_info); return fatfs_stream; }

static audio_element_handle_t create_i2s_stream(int sample_rates, int bits, int channels, audio_stream_type_t type) { i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT(); i2s_cfg.type = type; audio_element_handle_t i2s_stream = i2s_stream_init(&i2s_cfg); mem_assert(i2s_stream); audio_element_set_music_info(i2s_stream, sample_rates, channels, bits); return i2s_stream; }

static audio_element_handle_t create_wav_encoder() { wav_encoder_cfg_t wav_cfg = DEFAULT_WAV_ENCODER_CONFIG(); return wav_encoder_init(&wav_cfg); }

static audio_element_handle_t create_wav_decoder() { wav_decoder_cfg_t wav_cfg = DEFAULT_WAV_DECODER_CONFIG(); return wav_decoder_init(&wav_cfg); }

static audio_element_handle_t create_http_stream() { ESP_LOGI(TAG, "Initializing HTTP Stream Element"); http_stream_cfg_t http_cfg = HTTP_STREAM_CFG_DEFAULT(); http_cfg.multi_out_num = 1; audio_element_handle_t http_stream = http_stream_init(&http_cfg); audio_element_set_uri(http_stream,"https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.mp3"); return http_stream; }

//*listening**///

static void sd(const char *filename) { // Create audio elements audio_element_handle_t fatfas = create_fatfs_stream(SAVE_FILE_RATE, SAVE_FILE_BITS, SAVE_FILE_CHANNEL, AUDIO_STREAM_WRITER); audio_element_handle_t wav_decoder = create_wav_decoder(); audio_element_handle_t filter = create_filter(SAVE_FILE_RATE, SAVE_FILE_CHANNEL, PLAYBACK_RATE, PLAYBACK_CHANNEL, RESAMPLE_DECODE_MODE); audio_element_handle_t i2s_stream_writer = create_i2s_stream(PLAYBACK_RATE, PLAYBACK_BITS, PLAYBACK_CHANNEL, AUDIO_STREAM_WRITER);

// Initialize pipeline and memory
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
audio_pipeline_handle_t pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(pipeline);

// Register and link audio elements
audio_pipeline_register_more(pipeline, fatfas, wav_decoder, filter, i2s_stream_writer);
esp_err_t link_result = audio_pipeline_link_more(pipeline, fatfas, wav_decoder, filter, i2s_stream_writer);
if (link_result != ESP_OK) {
    ESP_LOGE(TAG, "Pipeline link failed: %d", link_result);
    return;
}

// Set URI for fatfs_stream_writer
audio_element_set_uri(fatfas, filename);

// Set up event listeners
audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg);
audio_pipeline_set_listener(pipeline, evt);

// Start pipeline
audio_pipeline_run(pipeline);
 while (1) {
    audio_event_iface_msg_t msg;
    esp_err_t ret = audio_event_iface_listen(evt, &msg, portMAX_DELAY);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "[ * ] Event interface error : %d", ret);
        continue;
    }
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT
        && msg.source == (void *)wav_decoder
        && msg.cmd == AEL_MSG_CMD_REPORT_MUSIC_INFO) {
        audio_element_info_t music_info = {0};
        audio_element_getinfo(wav_decoder, &music_info);

        ESP_LOGI(TAG, "[ * ] Receive music info from mp3 decoder, sample_rates=%d, bits=%d, ch=%d",
                 music_info.sample_rates, music_info.bits, music_info.channels);
        // Adjust settings based on music info, e.g., set I2S clock
        i2s_stream_set_clk( i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels);
        continue;
    }
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT
        && msg.source == (void *) wav_decoder
        && msg.cmd == AEL_MSG_CMD_REPORT_STATUS
        && (((int)msg.data == AEL_STATUS_STATE_STOPPED) || ((int)msg.data == AEL_STATUS_STATE_FINISHED))) {
        ESP_LOGW(TAG, "[ * ] Stop event received");
        break;
    }
}
// Clean up resources
audio_pipeline_terminate(pipeline);
audio_pipeline_unregister_more(pipeline, fatfas, wav_decoder, filter, i2s_stream_writer, NULL);
 audio_pipeline_remove_listener(pipeline);
audio_event_iface_remove_listener(esp_periph_set_get_event_iface(set), evt);
audio_event_iface_destroy(evt);
audio_pipeline_deinit(pipeline);

}

static void rec(){ audio_element_handle_t i2s_reader = create_i2s_stream(RECORD_RATE, RECORD_BITS, RECORD_CHANNEL, AUDIO_STREAM_READER); audio_element_handle_t filter = create_filter(RECORD_RATE, RECORD_CHANNEL, SAVE_FILE_RATE, SAVE_FILE_CHANNEL, RESAMPLE_ENCODE_MODE); audio_element_handle_t wav_encoder = create_wav_encoder(); audio_element_handle_t fatfas_writer = create_fatfs_stream(SAVE_FILE_RATE, SAVE_FILE_BITS, SAVE_FILE_CHANNEL, AUDIO_STREAM_WRITER); audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG(); audio_pipeline_handle_t pipeline = audio_pipeline_init(&pipeline_cfg); if (pipeline == NULL) { ESP_LOGE(TAG, "Pipeline initialization failed"); }; // Register and link audio elements audio_pipeline_register_more(pipeline, i2s_reader,filter,wav_encoder,fatfas_writer); esp_err_t link_result = audio_pipeline_link_more(pipeline,i2s_reader,filter,wav_encoder,fatfas_writer); if (link_result != ESP_OK) { ESP_LOGE(TAG, "Pipeline link failed: %d", link_result); }; audio_element_set_uri(fatfas_writer, "/sdcard/rec.wav"); // Set up event listeners and process based on stream type audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG(); audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg); audio_pipeline_set_listener(pipeline, evt); audio_pipeline_run(pipeline); int second_recorded = 0;

while (1) {
    audio_event_iface_msg_t msg;
    if (audio_event_iface_listen(evt, &msg, 1000 / portTICK_RATE_MS) != ESP_OK) {
        second_recorded++;
        ESP_LOGI(TAG, "[ * ] Recording ... %d", second_recorded);

        if (second_recorded >= RECORD_TIME_SECONDS) {
            ESP_LOGI(TAG, "Finishing recording");
            audio_element_set_ringbuf_done(i2s_reader);
        }

        continue;
    }

    /* Stop when the last pipeline element (i2s_stream_reader in this case) receives stop event */
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && msg.source == (void *)i2s_reader
        && msg.cmd == AEL_MSG_CMD_REPORT_STATUS
        && (((int)msg.data == AEL_STATUS_STATE_STOPPED) || ((int)msg.data == AEL_STATUS_STATE_FINISHED))) {
        ESP_LOGW(TAG, "[ * ] Stop event received");
        break;
    }
}

    // Clean up resources
    audio_pipeline_stop(pipeline);
    audio_pipeline_wait_for_stop(pipeline);
    audio_pipeline_terminate(pipeline);
    audio_pipeline_unregister_more(pipeline,i2s_reader,filter,wav_encoder,fatfas_writer);
    audio_pipeline_remove_listener(pipeline);
    audio_event_iface_remove_listener(esp_periph_set_get_event_iface(set), evt);
    audio_event_iface_destroy(evt);

}

static void http() { ESP_LOGE(TAG, "Pipeline initialization failed"); audio_element_handle_t http_stream = create_http_stream(); ESP_LOGE(TAG, "Pipeline initialization failed"); audio_element_handle_t wav_decoder = create_wav_decoder(); audio_element_handle_t i2s_stream_writer = create_i2s_stream(PLAYBACK_RATE, PLAYBACK_BITS, PLAYBACK_CHANNEL, AUDIO_STREAM_WRITER); audio_element_handle_t fatfas_writer = create_fatfs_stream(SAVE_FILE_RATE, SAVE_FILE_BITS, SAVE_FILE_CHANNEL, AUDIO_STREAM_WRITER);

// Initialize pipelines
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
audio_pipeline_handle_t pipeline  = audio_pipeline_init(&pipeline_cfg);
audio_pipeline_handle_t pipeline1 = audio_pipeline_init(&pipeline_cfg);

if (!pipeline || !pipeline1) {
    ESP_LOGE(TAG, "Pipeline initialization failed");
    return;
}

// Set up output ringbuf
ringbuf_handle_t rb = audio_element_get_output_ringbuf(http_stream);
audio_element_set_multi_output_ringbuf(wav_decoder, rb, 0);

// Register and link audio elements in pipelines
audio_pipeline_register_more(pipeline, http_stream, wav_decoder, i2s_stream_writer);
audio_pipeline_register_more(pipeline1, wav_decoder,fatfas_writer);

esp_err_t link_result = audio_pipeline_link_more(pipeline, http_stream, wav_decoder, i2s_stream_writer);
audio_pipeline_link_more(pipeline1, wav_decoder,fatfas_writer);

if (link_result != ESP_OK) {
    ESP_LOGE(TAG, "Pipeline link failed: %d", link_result);
    return;
}

// Set up event listeners
audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg);
audio_pipeline_set_listener(pipeline, evt);

// Start pipelines
audio_pipeline_run(pipeline);
audio_pipeline_run(pipeline1);

 while (1) {
    audio_event_iface_msg_t msg;
    esp_err_t ret = audio_event_iface_listen(evt, &msg, portMAX_DELAY);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "[ * ] Event interface error : %d", ret);
        continue;
    }
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT
        && msg.source == (void *)wav_decoder
        && msg.cmd == AEL_MSG_CMD_REPORT_MUSIC_INFO) {
        audio_element_info_t music_info = {0};
        audio_element_getinfo(wav_decoder, &music_info);

        ESP_LOGI(TAG, "[ * ] Receive music info from mp3 decoder, sample_rates=%d, bits=%d, ch=%d",
                 music_info.sample_rates, music_info.bits, music_info.channels);
        // Adjust settings based on music info, e.g., set I2S clock
        i2s_stream_set_clk( i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels);
        continue;
    }
    if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT
        && msg.source == (void *) wav_decoder
        && msg.cmd == AEL_MSG_CMD_REPORT_STATUS
        && (((int)msg.data == AEL_STATUS_STATE_STOPPED) || ((int)msg.data == AEL_STATUS_STATE_FINISHED))) {
        ESP_LOGW(TAG, "[ * ] Stop event received");
        break;
    }
}

// Clean up resources
audio_pipeline_stop(pipeline);
audio_pipeline_wait_for_stop(pipeline);
audio_pipeline_terminate(pipeline);
audio_pipeline_terminate(pipeline1);
audio_pipeline_unregister_more(pipeline, http_stream, wav_decoder, i2s_stream_writer);
audio_pipeline_unregister_more(pipeline1,wav_decoder, fatfas_writer);
audio_pipeline_remove_listener(pipeline);
audio_event_iface_remove_listener(evt, esp_periph_set_get_event_iface(set));
audio_event_iface_destroy(evt);

}

static esp_err_t input_key_service_cb(periph_service_handle_t handle, periph_service_event_t evt, void ctx) { audio_element_handle_t wav_encoder = (audio_element_handle_t)ctx;

ESP_LOGD(TAG, "[ * ] input key id is %d, %d", (int)evt->data, evt->type);

switch ((int)evt->data) {
    case INPUT_KEY_USER_ID_MODE:
        if (evt->type == PERIPH_ADC_BUTTON_RELEASE || evt->type == PERIPH_ADC_BUTTON_LONG_RELEASE) {
            int mode=0;
            mode = (mode + 1) % 4;
            mode = (mode == 0) ? 1 : mode;
            // Handle mode selection
            switch (mode) {
                case 1:
                    if (r==true) {
                        ESP_LOGI(TAG, "Selected mode: Play from HTTP");
                        http();
                    } else if(r==false) {
                        ESP_LOGI(TAG, "Selected mode: Play from SD Card (Wi-Fi not connected)");
                        sd("/sdcard/httpmusic.wav");
                    }
                    break;
                case 2:
                    ESP_LOGI(TAG, "Selected mode: Audio Recording");
                    rec();
                    break;
                case 3:
                    ESP_LOGI(TAG, "Selected mode: Play from SD Card");
                    sd("/sdcard/rec.wav");
                    break;
            }
        }
        break;

    case INPUT_KEY_USER_ID_PLAY:
        ESP_LOGE(TAG, "[ * ] [Play/Pause] input key event, toggling pause state ...");
         audio_element_state_t current_state = audio_element_get_state(wav_encoder);
        if (current_state == AEL_STATE_RUNNING) {
            audio_element_pause(wav_encoder);
            } else if (current_state == AEL_STATE_PAUSED) {
            audio_element_resume(wav_encoder, 0, 0);
            }
        break;
}

return ESP_OK;

}

//**** //****

void app_main(void) { esp_log_level_set("*", ESP_LOG_WARN); esp_log_level_set(TAG, ESP_LOG_INFO);

ESP_LOGI(TAG, "[ 1 ] nvs flash");
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
    ESP_ERROR_CHECK(nvs_flash_erase());
    err = nvs_flash_init();
}
ESP_ERROR_CHECK(esp_netif_init());

ESP_LOGI(TAG, "[ 2 ] Start codec chip");
audio_board_handle_t board_handle = audio_board_init();
audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);

esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);

ESP_LOGI(TAG, "[ 3 ] Start and wait for Wi-Fi network");

periph_wifi_cfg_t wifi_cfg = {
    .ssid = CONFIG_WIFI_SSID,
    .password = CONFIG_WIFI_PASSWORD,
};
esp_periph_handle_t wifi_handle = periph_wifi_init(&wifi_cfg);;
esp_periph_start(set, wifi_handle);
periph_wifi_wait_for_connected(wifi_handle, portMAX_DELAY);
if (periph_wifi_is_connected(wifi_handle) == PERIPH_WIFI_CONNECTED) {
    r = true;
} else {
    r = false;
}

ESP_LOGI(TAG, "[4] Mount sdcard");
// Initialize SD Card peripheral
audio_board_sdcard_init(set, SD_MODE_1_LINE);

ESP_LOGI(TAG, "[ 5 ] Initialize Button peripheral with board init");
audio_board_key_init(set);

ESP_LOGI(TAG, "[ 6 ] Create and start input key service");
input_key_service_info_t input_key_info[] = INPUT_KEY_DEFAULT_INFO();
input_key_service_cfg_t input_cfg = INPUT_KEY_SERVICE_DEFAULT_CONFIG();
input_cfg.handle = set;
input_cfg.based_cfg.task_stack = 4 * 1024;
periph_service_handle_t input_ser = input_key_service_create(&input_cfg);

input_key_service_add_key(input_ser, input_key_info, INPUT_KEY_NUM);
periph_service_set_callback(input_ser, input_key_service_cb, NULL);

ESP_LOGW(TAG, "[ 7 ] Waiting for a button to be pressed ...");

}`

CMakeLists.txt