From 8b7d1bfada6a923bedfd847e38b4c67eac94e593 Mon Sep 17 00:00:00 2001 From: raul Date: Sun, 2 Feb 2025 19:58:35 +0100 Subject: [PATCH] Fix tests --- esphome/components/i2s_audio/__init__.py | 5 +---- .../microphone/i2s_audio_microphone.cpp | 19 ++++++++++--------- .../microphone/i2s_audio_microphone.h | 2 +- esphome/core/defines.h | 1 + tests/components/micro_wake_word/common.yaml | 1 + .../components/microphone/test.esp32-idf.yaml | 11 ++++++++++- tests/components/mixer/common.yaml | 1 + tests/components/resampler/common.yaml | 1 + .../components/speaker/common-audio_dac.yaml | 1 + tests/components/speaker/common.yaml | 1 + tests/components/voice_assistant/common.yaml | 1 + 11 files changed, 29 insertions(+), 15 deletions(-) diff --git a/esphome/components/i2s_audio/__init__.py b/esphome/components/i2s_audio/__init__.py index 854b554a4d..a2959e3a92 100644 --- a/esphome/components/i2s_audio/__init__.py +++ b/esphome/components/i2s_audio/__init__.py @@ -170,7 +170,6 @@ def i2s_audio_component_schema( async def register_i2s_audio_component(var, config): await cg.register_parented(var, config[CONF_I2S_AUDIO_ID]) if use_legacy(): - print("Use legacy") cg.add(var.set_i2s_mode(I2S_MODE_OPTIONS[config[CONF_I2S_MODE]])) cg.add(var.set_channel(I2S_CHANNELS[config[CONF_CHANNEL]])) cg.add( @@ -181,7 +180,6 @@ async def register_i2s_audio_component(var, config): I2S_BITS_PER_CHANNEL[config[CONF_BITS_PER_CHANNEL]] ) ) - cg.add(var.set_use_apll(config[CONF_USE_APLL])) else: cg.add(var.set_i2s_role(I2S_ROLE_OPTIONS[config[CONF_I2S_MODE]])) slot_mode = config[CONF_CHANNEL] @@ -196,9 +194,8 @@ async def register_i2s_audio_component(var, config): cg.add( var.set_slot_bit_width(I2S_SLOT_BIT_WIDTH[config[CONF_BITS_PER_CHANNEL]]) ) - # cg.add(var.set_use_apll(config[CONF_USE_APLL])) - cg.add_define("USE_I2S_APLL") cg.add(var.set_sample_rate(config[CONF_SAMPLE_RATE])) + cg.add(var.set_use_apll(config[CONF_USE_APLL])) def validate_use_legacy(value): diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp index 39dae44333..ce05d5d23e 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp @@ -127,7 +127,7 @@ void I2SAudioMicrophone::start_() { .auto_clear = false, }; /* Allocate a new RX channel and get the handle of this channel */ - err = i2s_new_channel(&chan_cfg, NULL, &this->rx_handle); + err = i2s_new_channel(&chan_cfg, NULL, &this->rx_handle_); if (err != ESP_OK) { ESP_LOGW(TAG, "Error creating new I2S channel: %s", esp_err_to_name(err)); this->status_set_error(); @@ -137,10 +137,11 @@ void I2SAudioMicrophone::start_() { /* Setting the configurations, the slot configuration and clock configuration can be generated by the macros * These two helper macros are defined in 'i2s_std.h' which can only be used in STD mode. * They can help to specify the slot and clock configurations for initialization or updating */ -#ifdef USE_I2S_APLL - i2s_clock_src_t clk_src = I2S_CLK_SRC_APLL; -#else i2s_clock_src_t clk_src = I2S_CLK_SRC_DEFAULT; +#ifdef I2S_CLK_SRC_APLL + if (this->use_apll_) { + clk_src = I2S_CLK_SRC_APLL; + } #endif i2s_std_clk_config_t clk_cfg = { .sample_rate_hz = this->sample_rate_, @@ -160,7 +161,7 @@ void I2SAudioMicrophone::start_() { .gpio_cfg = pin_config, }; /* Initialize the channel */ - err = i2s_channel_init_std_mode(this->rx_handle, &std_cfg); + err = i2s_channel_init_std_mode(this->rx_handle_, &std_cfg); if (err != ESP_OK) { ESP_LOGW(TAG, "Error initializing I2S channel: %s", esp_err_to_name(err)); this->status_set_error(); @@ -168,7 +169,7 @@ void I2SAudioMicrophone::start_() { } /* Before reading data, start the RX channel first */ - i2s_channel_enable(this->rx_handle); + i2s_channel_enable(this->rx_handle_); if (err != ESP_OK) { ESP_LOGW(TAG, "Error enabling I2S Microphone: %s", esp_err_to_name(err)); this->status_set_error(); @@ -218,14 +219,14 @@ void I2SAudioMicrophone::stop_() { } #else /* Have to stop the channel before deleting it */ - err = i2s_channel_disable(this->rx_handle); + err = i2s_channel_disable(this->rx_handle_); if (err != ESP_OK) { ESP_LOGW(TAG, "Error stopping I2S microphone: %s", esp_err_to_name(err)); this->status_set_error(); return; } /* If the handle is not needed any more, delete it to release the channel resources */ - err = i2s_del_channel(this->rx_handle); + err = i2s_del_channel(this->rx_handle_); if (err != ESP_OK) { ESP_LOGW(TAG, "Error deleting I2S channel: %s", esp_err_to_name(err)); this->status_set_error(); @@ -243,7 +244,7 @@ size_t I2SAudioMicrophone::read(int16_t *buf, size_t len) { #ifdef USE_I2S_LEGACY esp_err_t err = i2s_read(this->parent_->get_port(), buf, len, &bytes_read, (100 / portTICK_PERIOD_MS)); #else - esp_err_t err = i2s_channel_read(this->rx_handle, buf, len, &bytes_read, (100 / portTICK_PERIOD_MS)); + esp_err_t err = i2s_channel_read(this->rx_handle_, buf, len, &bytes_read, (100 / portTICK_PERIOD_MS)); #endif if (err != ESP_OK) { ESP_LOGW(TAG, "Error reading from I2S microphone: %s", esp_err_to_name(err)); diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h index 54dd9defaf..2ff46fabab 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h @@ -49,7 +49,7 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub #endif #else gpio_num_t din_pin_{I2S_GPIO_UNUSED}; - i2s_chan_handle_t rx_handle; + i2s_chan_handle_t rx_handle_; #endif bool pdm_{false}; diff --git a/esphome/core/defines.h b/esphome/core/defines.h index dc0ac3c1e8..1b9fff2b7c 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -94,6 +94,7 @@ #ifdef USE_ARDUINO #define USE_PROMETHEUS #define USE_WIFI_WPA2_EAP +#define USE_I2S_LEGACY #endif // IDF-specific feature flags diff --git a/tests/components/micro_wake_word/common.yaml b/tests/components/micro_wake_word/common.yaml index 8bd7345307..ab72334458 100644 --- a/tests/components/micro_wake_word/common.yaml +++ b/tests/components/micro_wake_word/common.yaml @@ -1,6 +1,7 @@ i2s_audio: i2s_lrclk_pin: GPIO18 i2s_bclk_pin: GPIO19 + use_legacy: true microphone: - platform: i2s_audio diff --git a/tests/components/microphone/test.esp32-idf.yaml b/tests/components/microphone/test.esp32-idf.yaml index 392df582cc..fe9feb9888 100644 --- a/tests/components/microphone/test.esp32-idf.yaml +++ b/tests/components/microphone/test.esp32-idf.yaml @@ -4,9 +4,18 @@ substitutions: i2s_mclk_pin: GPIO17 i2s_din_pin: GPIO33 -<<: !include common.yaml +i2s_audio: + i2s_bclk_pin: ${i2s_bclk_pin} + i2s_lrclk_pin: ${i2s_lrclk_pin} + i2s_mclk_pin: ${i2s_mclk_pin} + use_legacy: true microphone: + - platform: i2s_audio + id: mic_id_external + i2s_din_pin: ${i2s_din_pin} + adc_type: external + pdm: false - platform: i2s_audio id: mic_id_adc adc_pin: 32 diff --git a/tests/components/mixer/common.yaml b/tests/components/mixer/common.yaml index e171b9499c..91e6f8c3f4 100644 --- a/tests/components/mixer/common.yaml +++ b/tests/components/mixer/common.yaml @@ -10,6 +10,7 @@ i2s_audio: i2s_lrclk_pin: ${lrclk_pin} i2s_bclk_pin: ${bclk_pin} i2s_mclk_pin: ${mclk_pin} + use_legacy: true speaker: - platform: i2s_audio diff --git a/tests/components/resampler/common.yaml b/tests/components/resampler/common.yaml index 8ff09ed256..db324b9f02 100644 --- a/tests/components/resampler/common.yaml +++ b/tests/components/resampler/common.yaml @@ -2,6 +2,7 @@ i2s_audio: i2s_lrclk_pin: ${lrclk_pin} i2s_bclk_pin: ${bclk_pin} i2s_mclk_pin: ${mclk_pin} + use_legacy: true speaker: - platform: i2s_audio diff --git a/tests/components/speaker/common-audio_dac.yaml b/tests/components/speaker/common-audio_dac.yaml index 41b994d4d4..3dd216928a 100644 --- a/tests/components/speaker/common-audio_dac.yaml +++ b/tests/components/speaker/common-audio_dac.yaml @@ -23,6 +23,7 @@ i2s_audio: i2s_lrclk_pin: ${i2s_bclk_pin} i2s_bclk_pin: ${i2s_lrclk_pin} i2s_mclk_pin: ${i2s_mclk_pin} + use_legacy: true audio_dac: - platform: aic3204 diff --git a/tests/components/speaker/common.yaml b/tests/components/speaker/common.yaml index c04674ee29..18a67947bd 100644 --- a/tests/components/speaker/common.yaml +++ b/tests/components/speaker/common.yaml @@ -18,6 +18,7 @@ i2s_audio: i2s_lrclk_pin: ${i2s_bclk_pin} i2s_bclk_pin: ${i2s_lrclk_pin} i2s_mclk_pin: ${i2s_mclk_pin} + use_legacy: true speaker: - platform: i2s_audio diff --git a/tests/components/voice_assistant/common.yaml b/tests/components/voice_assistant/common.yaml index e7374941f7..cbc46918be 100644 --- a/tests/components/voice_assistant/common.yaml +++ b/tests/components/voice_assistant/common.yaml @@ -15,6 +15,7 @@ i2s_audio: i2s_lrclk_pin: ${i2s_lrclk_pin} i2s_bclk_pin: ${i2s_bclk_pin} i2s_mclk_pin: ${i2s_mclk_pin} + use_legacy: true microphone: - platform: i2s_audio