mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
refactor(i2s): refactor of the private i2s caps
This commit is contained in:
@@ -227,13 +227,13 @@ static esp_err_t i2s_destroy_controller_obj(i2s_controller_t **i2s_obj)
|
||||
* @param id i2s port id
|
||||
* @param search_reverse reverse the sequence of port acquirement
|
||||
* set false to acquire from I2S_NUM_0 first
|
||||
* set true to acquire from SOC_I2S_ATTR(INST_NUM) - 1 first
|
||||
* set true to acquire from I2S_LL_GET(INST_NUM) - 1 first
|
||||
* @return
|
||||
* - pointer of acquired i2s controller object
|
||||
*/
|
||||
static i2s_controller_t *i2s_acquire_controller_obj(int id)
|
||||
{
|
||||
if (id < 0 || id >= SOC_I2S_ATTR(INST_NUM)) {
|
||||
if (id < 0 || id >= I2S_LL_GET(INST_NUM)) {
|
||||
return NULL;
|
||||
}
|
||||
/* pre-alloc controller object */
|
||||
@@ -792,17 +792,17 @@ esp_err_t i2s_init_dma_intr(i2s_chan_handle_t handle, int intr_flag)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
int port_id = handle->controller->id;
|
||||
ESP_RETURN_ON_FALSE((port_id >= 0) && (port_id < SOC_I2S_ATTR(INST_NUM)), ESP_ERR_INVALID_ARG, TAG, "invalid handle");
|
||||
ESP_RETURN_ON_FALSE((port_id >= 0) && (port_id < I2S_LL_GET(INST_NUM)), ESP_ERR_INVALID_ARG, TAG, "invalid handle");
|
||||
/* Set GDMA trigger module */
|
||||
gdma_trigger_t trig = {.periph = GDMA_TRIG_PERIPH_I2S};
|
||||
|
||||
switch (port_id) {
|
||||
#if SOC_I2S_ATTR(INST_NUM) > 2
|
||||
#if I2S_LL_GET(INST_NUM) > 2
|
||||
case I2S_NUM_2:
|
||||
trig.instance_id = SOC_GDMA_TRIG_PERIPH_I2S2;
|
||||
break;
|
||||
#endif
|
||||
#if SOC_I2S_ATTR(INST_NUM) > 1
|
||||
#if I2S_LL_GET(INST_NUM) > 1
|
||||
case I2S_NUM_1:
|
||||
trig.instance_id = SOC_GDMA_TRIG_PERIPH_I2S1;
|
||||
break;
|
||||
@@ -863,7 +863,7 @@ esp_err_t i2s_init_dma_intr(i2s_chan_handle_t handle, int intr_flag)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
int port_id = handle->controller->id;
|
||||
ESP_RETURN_ON_FALSE((port_id >= 0) && (port_id < SOC_I2S_ATTR(INST_NUM)), ESP_ERR_INVALID_ARG, TAG, "invalid handle");
|
||||
ESP_RETURN_ON_FALSE((port_id >= 0) && (port_id < I2S_LL_GET(INST_NUM)), ESP_ERR_INVALID_ARG, TAG, "invalid handle");
|
||||
intr_flag |= handle->intr_prio_flags;
|
||||
/* Initialize I2S module interrupt */
|
||||
if (handle->dir == I2S_DIR_TX) {
|
||||
@@ -985,7 +985,7 @@ esp_err_t i2s_new_channel(const i2s_chan_config_t *chan_cfg, i2s_chan_handle_t *
|
||||
/* Parameter validity check */
|
||||
I2S_NULL_POINTER_CHECK(TAG, chan_cfg);
|
||||
I2S_NULL_POINTER_CHECK(TAG, tx_handle || rx_handle);
|
||||
ESP_RETURN_ON_FALSE((chan_cfg->id >= 0 && chan_cfg->id < SOC_I2S_ATTR(INST_NUM)) || chan_cfg->id == I2S_NUM_AUTO, ESP_ERR_INVALID_ARG, TAG, "invalid I2S port id");
|
||||
ESP_RETURN_ON_FALSE((chan_cfg->id >= 0 && chan_cfg->id < I2S_LL_GET(INST_NUM)) || chan_cfg->id == I2S_NUM_AUTO, ESP_ERR_INVALID_ARG, TAG, "invalid I2S port id");
|
||||
ESP_RETURN_ON_FALSE(chan_cfg->dma_desc_num >= 2, ESP_ERR_INVALID_ARG, TAG, "there should be at least 2 DMA buffers");
|
||||
ESP_RETURN_ON_FALSE(chan_cfg->intr_priority >= 0 && chan_cfg->intr_priority <= 7, ESP_ERR_INVALID_ARG, TAG, "intr_priority should be within 0~7");
|
||||
#if !SOC_HAS(PAU)
|
||||
@@ -1003,7 +1003,7 @@ esp_err_t i2s_new_channel(const i2s_chan_config_t *chan_cfg, i2s_chan_handle_t *
|
||||
/* Channel will be registered to one i2s port automatically if id is I2S_NUM_AUTO
|
||||
* Otherwise, the channel will be registered to the specific port. */
|
||||
if (id == I2S_NUM_AUTO) {
|
||||
for (int i = 0; i < SOC_I2S_ATTR(INST_NUM) && !channel_found; i++) {
|
||||
for (int i = 0; i < I2S_LL_GET(INST_NUM) && !channel_found; i++) {
|
||||
i2s_obj = i2s_acquire_controller_obj(i);
|
||||
if (!i2s_obj) {
|
||||
continue;
|
||||
@@ -1062,7 +1062,7 @@ esp_err_t i2s_new_channel(const i2s_chan_config_t *chan_cfg, i2s_chan_handle_t *
|
||||
err:
|
||||
/* if the controller object has no channel, find the corresponding global object and destroy it */
|
||||
if (i2s_obj != NULL && i2s_obj->rx_chan == NULL && i2s_obj->tx_chan == NULL) {
|
||||
for (int i = 0; i < SOC_I2S_ATTR(INST_NUM); i++) {
|
||||
for (int i = 0; i < I2S_LL_GET(INST_NUM); i++) {
|
||||
if (i2s_obj == g_i2s.controller[i]) {
|
||||
i2s_destroy_controller_obj(&g_i2s.controller[i]);
|
||||
break;
|
||||
@@ -1173,7 +1173,7 @@ esp_err_t i2s_channel_get_info(i2s_chan_handle_t handle, i2s_chan_info_t *chan_i
|
||||
I2S_NULL_POINTER_CHECK(TAG, chan_info);
|
||||
|
||||
/* Find whether the handle is a registered i2s handle or still available */
|
||||
for (int i = 0; i < SOC_I2S_ATTR(INST_NUM); i++) {
|
||||
for (int i = 0; i < I2S_LL_GET(INST_NUM); i++) {
|
||||
if (g_i2s.controller[i] != NULL) {
|
||||
if (g_i2s.controller[i]->tx_chan == handle ||
|
||||
g_i2s.controller[i]->rx_chan == handle) {
|
||||
|
||||
@@ -16,8 +16,8 @@ static const char *TAG = "i2s_platform";
|
||||
*/
|
||||
i2s_platform_t g_i2s = {
|
||||
.spinlock = (portMUX_TYPE)portMUX_INITIALIZER_UNLOCKED,
|
||||
.controller[0 ...(SOC_I2S_ATTR(INST_NUM) - 1)] = NULL, // groups will be lazy installed
|
||||
.comp_name[0 ...(SOC_I2S_ATTR(INST_NUM) - 1)] = NULL,
|
||||
.controller[0 ...(I2S_LL_GET(INST_NUM) - 1)] = NULL, // groups will be lazy installed
|
||||
.comp_name[0 ...(I2S_LL_GET(INST_NUM) - 1)] = NULL,
|
||||
#if SOC_LP_I2S_SUPPORTED
|
||||
.lp_controller[0 ...(SOC_LP_I2S_NUM - 1)] = NULL,
|
||||
.lp_comp_name[0 ...(SOC_LP_I2S_NUM - 1)] = NULL,
|
||||
@@ -34,7 +34,7 @@ esp_err_t i2s_platform_acquire_occupation(i2s_ctlr_t type, int id, const char *c
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
const char *occupied_comp = NULL;
|
||||
ESP_RETURN_ON_FALSE(id < SOC_I2S_ATTR(INST_NUM), ESP_ERR_INVALID_ARG, TAG, "invalid i2s port id");
|
||||
ESP_RETURN_ON_FALSE(id < I2S_LL_GET(INST_NUM), ESP_ERR_INVALID_ARG, TAG, "invalid i2s port id");
|
||||
|
||||
if (type == I2S_CTLR_HP) {
|
||||
portENTER_CRITICAL(&g_i2s.spinlock);
|
||||
@@ -79,7 +79,7 @@ esp_err_t i2s_platform_acquire_occupation(i2s_ctlr_t type, int id, const char *c
|
||||
esp_err_t i2s_platform_release_occupation(i2s_ctlr_t type, int id)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_RETURN_ON_FALSE(id < SOC_I2S_ATTR(INST_NUM), ESP_ERR_INVALID_ARG, TAG, "invalid i2s port id");
|
||||
ESP_RETURN_ON_FALSE(id < I2S_LL_GET(INST_NUM), ESP_ERR_INVALID_ARG, TAG, "invalid i2s port id");
|
||||
|
||||
if (type == I2S_CTLR_HP) {
|
||||
portENTER_CRITICAL(&g_i2s.spinlock);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "soc/lldesc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/soc_caps_full.h"
|
||||
#include "hal/i2s_periph.h"
|
||||
#include "hal/i2s_hal.h"
|
||||
#include "hal/lp_i2s_hal.h"
|
||||
#if SOC_LP_I2S_SUPPORTED
|
||||
@@ -225,11 +226,11 @@ struct lp_i2s_channel_obj_t {
|
||||
*/
|
||||
typedef struct {
|
||||
portMUX_TYPE spinlock; /*!< Platform level lock */
|
||||
i2s_controller_t *controller[SOC_I2S_ATTR(INST_NUM)]; /*!< Controller object */
|
||||
const char *comp_name[SOC_I2S_ATTR(INST_NUM)]; /*!< The component name that occupied i2s controller */
|
||||
i2s_controller_t *controller[I2S_LL_GET(INST_NUM)]; /*!< Controller object */
|
||||
const char *comp_name[I2S_LL_GET(INST_NUM)]; /*!< The component name that occupied i2s controller */
|
||||
#if SOC_LP_I2S_SUPPORTED
|
||||
lp_i2s_controller_t *lp_controller[SOC_LP_I2S_NUM]; /*!< LP controller object*/
|
||||
const char *lp_comp_name[SOC_I2S_ATTR(INST_NUM)]; /*!< The component name that occupied lp i2s controller */
|
||||
const char *lp_comp_name[I2S_LL_GET(INST_NUM)]; /*!< The component name that occupied lp i2s controller */
|
||||
#endif
|
||||
} i2s_platform_t;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ static void i2s_test_io_config(int mode)
|
||||
gpio_set_direction(DATA_OUT_IO, GPIO_MODE_INPUT_OUTPUT);
|
||||
|
||||
switch (mode) {
|
||||
#if SOC_I2S_ATTR(INST_NUM) > 1
|
||||
#if I2S_LL_GET(INST_NUM) > 1
|
||||
case I2S_TEST_MODE_SLAVE_TO_MASTER: {
|
||||
esp_rom_gpio_connect_out_signal(MASTER_BCK_IO, i2s_periph_signal[0].m_rx_bck_sig, 0, 0);
|
||||
esp_rom_gpio_connect_in_signal(MASTER_BCK_IO, i2s_periph_signal[1].s_tx_bck_sig, 0);
|
||||
@@ -169,14 +169,14 @@ TEST_CASE("I2S_basic_channel_allocation_reconfig_deleting_test", "[i2s]")
|
||||
|
||||
/* Exhaust test */
|
||||
std_cfg.gpio_cfg.mclk = -1;
|
||||
i2s_chan_handle_t tx_ex[SOC_I2S_ATTR(INST_NUM)] = {};
|
||||
for (int i = 0; i < SOC_I2S_ATTR(INST_NUM); i++) {
|
||||
i2s_chan_handle_t tx_ex[I2S_LL_GET(INST_NUM)] = {};
|
||||
for (int i = 0; i < I2S_LL_GET(INST_NUM); i++) {
|
||||
TEST_ESP_OK(i2s_new_channel(&chan_cfg, &tx_ex[i], NULL));
|
||||
TEST_ESP_OK(i2s_channel_init_std_mode(tx_ex[i], &std_cfg));
|
||||
TEST_ESP_OK(i2s_channel_enable(tx_ex[i]));
|
||||
}
|
||||
TEST_ESP_ERR(ESP_ERR_NOT_FOUND, i2s_new_channel(&chan_cfg, &tx_handle, NULL));
|
||||
for (int i = 0; i < SOC_I2S_ATTR(INST_NUM); i++) {
|
||||
for (int i = 0; i < I2S_LL_GET(INST_NUM); i++) {
|
||||
TEST_ESP_OK(i2s_channel_disable(tx_ex[i]));
|
||||
TEST_ESP_OK(i2s_del_channel(tx_ex[i]));
|
||||
}
|
||||
@@ -812,7 +812,7 @@ TEST_CASE("I2S_loopback_test", "[i2s]")
|
||||
TEST_ESP_OK(i2s_del_channel(rx_handle));
|
||||
}
|
||||
|
||||
#if SOC_I2S_ATTR(INST_NUM) > 1 && !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
#if I2S_LL_GET(INST_NUM) > 1 && !CONFIG_ESP32P4_SELECTS_REV_LESS_V3
|
||||
TEST_CASE("I2S_master_write_slave_read_test", "[i2s]")
|
||||
{
|
||||
i2s_chan_handle_t tx_handle;
|
||||
|
||||
Reference in New Issue
Block a user