-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bsp: Added support for IDF v4.4 into ESP-BOX-Lite
- Loading branch information
Showing
9 changed files
with
252 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "esp_err.h" | ||
#include "bsp/esp-box-lite.h" | ||
#include "bsp_err_check.h" | ||
#include "esp_codec_dev_defaults.h" | ||
|
||
static const char *TAG = "ESP-BOX"; | ||
|
||
/* This configuration is used by default in bsp_audio_init() */ | ||
#define BSP_I2S_DUPLEX_MONO_CFG(_sample_rate) \ | ||
{ \ | ||
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX, \ | ||
.sample_rate = _sample_rate, \ | ||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, \ | ||
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, \ | ||
.communication_format = I2S_COMM_FORMAT_STAND_I2S, \ | ||
.dma_buf_count = 3, \ | ||
.dma_buf_len = 1024, \ | ||
.use_apll = true, \ | ||
.tx_desc_auto_clear = true, \ | ||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM \ | ||
} | ||
|
||
static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */ | ||
|
||
esp_err_t bsp_audio_init(const i2s_config_t *i2s_config) | ||
{ | ||
esp_err_t ret = ESP_FAIL; | ||
|
||
if (i2s_data_if != NULL) { | ||
/* Audio was initialized before */ | ||
return ESP_OK; | ||
} | ||
|
||
/* Setup I2S peripheral */ | ||
const i2s_pin_config_t i2s_pin_config = { | ||
.mck_io_num = BSP_I2S_MCLK, | ||
.bck_io_num = BSP_I2S_SCLK, | ||
.ws_io_num = BSP_I2S_LCLK, | ||
.data_out_num = BSP_I2S_DOUT, | ||
.data_in_num = BSP_I2S_DSIN | ||
}; | ||
|
||
/* Setup I2S channels */ | ||
const i2s_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG(22050); | ||
const i2s_config_t *p_i2s_cfg = &std_cfg_default; | ||
if (i2s_config != NULL) { | ||
p_i2s_cfg = i2s_config; | ||
} | ||
|
||
ESP_ERROR_CHECK(i2s_driver_install(CONFIG_BSP_I2S_NUM, p_i2s_cfg, 0, NULL)); | ||
ESP_GOTO_ON_ERROR(i2s_set_pin(CONFIG_BSP_I2S_NUM, &i2s_pin_config), err, TAG, "I2S set pin failed"); | ||
|
||
audio_codec_i2s_cfg_t i2s_cfg = { | ||
.port = CONFIG_BSP_I2S_NUM, | ||
}; | ||
i2s_data_if = audio_codec_new_i2s_data(&i2s_cfg); | ||
BSP_NULL_CHECK_GOTO(i2s_data_if, err); | ||
|
||
return ESP_OK; | ||
|
||
err: | ||
i2s_driver_uninstall(CONFIG_BSP_I2S_NUM); | ||
return ret; | ||
} | ||
|
||
const audio_codec_data_if_t *bsp_audio_get_codec_itf(void) | ||
{ | ||
return i2s_data_if; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "esp_err.h" | ||
#include "bsp/esp-box-lite.h" | ||
#include "bsp_err_check.h" | ||
#include "esp_codec_dev_defaults.h" | ||
|
||
static const char *TAG = "ESP-BOX"; | ||
|
||
static i2s_chan_handle_t i2s_tx_chan = NULL; | ||
static i2s_chan_handle_t i2s_rx_chan = NULL; | ||
static const audio_codec_data_if_t *i2s_data_if = NULL; /* Codec data interface */ | ||
|
||
|
||
/* Can be used for i2s_std_gpio_config_t and/or i2s_std_config_t initialization */ | ||
#define BSP_I2S_GPIO_CFG \ | ||
{ \ | ||
.mclk = BSP_I2S_MCLK, \ | ||
.bclk = BSP_I2S_SCLK, \ | ||
.ws = BSP_I2S_LCLK, \ | ||
.dout = BSP_I2S_DOUT, \ | ||
.din = BSP_I2S_DSIN, \ | ||
.invert_flags = { \ | ||
.mclk_inv = false, \ | ||
.bclk_inv = false, \ | ||
.ws_inv = false, \ | ||
}, \ | ||
} | ||
|
||
/* This configuration is used by default in bsp_audio_init() */ | ||
#define BSP_I2S_DUPLEX_MONO_CFG(_sample_rate) \ | ||
{ \ | ||
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(_sample_rate), \ | ||
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO), \ | ||
.gpio_cfg = BSP_I2S_GPIO_CFG, \ | ||
} | ||
|
||
esp_err_t bsp_audio_init(const i2s_std_config_t *i2s_config) | ||
{ | ||
esp_err_t ret = ESP_FAIL; | ||
if (i2s_tx_chan && i2s_rx_chan) { | ||
/* Audio was initialized before */ | ||
return ESP_OK; | ||
} | ||
|
||
/* Setup I2S peripheral */ | ||
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(CONFIG_BSP_I2S_NUM, I2S_ROLE_MASTER); | ||
chan_cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer | ||
BSP_ERROR_CHECK_RETURN_ERR(i2s_new_channel(&chan_cfg, &i2s_tx_chan, &i2s_rx_chan)); | ||
|
||
/* Setup I2S channels */ | ||
const i2s_std_config_t std_cfg_default = BSP_I2S_DUPLEX_MONO_CFG(22050); | ||
const i2s_std_config_t *p_i2s_cfg = &std_cfg_default; | ||
if (i2s_config != NULL) { | ||
p_i2s_cfg = i2s_config; | ||
} | ||
|
||
if (i2s_tx_chan != NULL) { | ||
ESP_GOTO_ON_ERROR(i2s_channel_init_std_mode(i2s_tx_chan, p_i2s_cfg), err, TAG, "I2S channel initialization failed"); | ||
ESP_GOTO_ON_ERROR(i2s_channel_enable(i2s_tx_chan), err, TAG, "I2S enabling failed"); | ||
} | ||
if (i2s_rx_chan != NULL) { | ||
ESP_GOTO_ON_ERROR(i2s_channel_init_std_mode(i2s_rx_chan, p_i2s_cfg), err, TAG, "I2S channel initialization failed"); | ||
ESP_GOTO_ON_ERROR(i2s_channel_enable(i2s_rx_chan), err, TAG, "I2S enabling failed"); | ||
} | ||
|
||
audio_codec_i2s_cfg_t i2s_cfg = { | ||
.port = CONFIG_BSP_I2S_NUM, | ||
.rx_handle = i2s_rx_chan, | ||
.tx_handle = i2s_tx_chan, | ||
}; | ||
i2s_data_if = audio_codec_new_i2s_data(&i2s_cfg); | ||
BSP_NULL_CHECK_GOTO(i2s_data_if, err); | ||
|
||
return ESP_OK; | ||
|
||
err: | ||
if (i2s_tx_chan) { | ||
i2s_del_channel(i2s_tx_chan); | ||
} | ||
if (i2s_rx_chan) { | ||
i2s_del_channel(i2s_rx_chan); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
const audio_codec_data_if_t *bsp_audio_get_codec_itf(void) | ||
{ | ||
return i2s_data_if; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.