diff --git a/esphome/components/i2s_audio/__init__.py b/esphome/components/i2s_audio/__init__.py index 39d81ef1a1..d72e13630f 100644 --- a/esphome/components/i2s_audio/__init__.py +++ b/esphome/components/i2s_audio/__init__.py @@ -18,6 +18,7 @@ MULTI_CONF = True CONF_I2S_DOUT_PIN = "i2s_dout_pin" CONF_I2S_DIN_PIN = "i2s_din_pin" +CONF_I2S_MCLK_PIN = "i2s_mclk_pin" CONF_I2S_BCLK_PIN = "i2s_bclk_pin" CONF_I2S_LRCLK_PIN = "i2s_lrclk_pin" @@ -44,6 +45,7 @@ CONFIG_SCHEMA = cv.Schema( cv.GenerateID(): cv.declare_id(I2SAudioComponent), cv.Required(CONF_I2S_LRCLK_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_I2S_BCLK_PIN): pins.internal_gpio_output_pin_number, + cv.Optional(CONF_I2S_MCLK_PIN): pins.internal_gpio_output_pin_number, } ) @@ -69,3 +71,5 @@ async def to_code(config): cg.add(var.set_lrclk_pin(config[CONF_I2S_LRCLK_PIN])) if CONF_I2S_BCLK_PIN in config: cg.add(var.set_bclk_pin(config[CONF_I2S_BCLK_PIN])) + if CONF_I2S_MCLK_PIN in config: + cg.add(var.set_mclk_pin(config[CONF_I2S_MCLK_PIN])) diff --git a/esphome/components/i2s_audio/i2s_audio.h b/esphome/components/i2s_audio/i2s_audio.h index f030ed4e75..d8d4a23dde 100644 --- a/esphome/components/i2s_audio/i2s_audio.h +++ b/esphome/components/i2s_audio/i2s_audio.h @@ -21,7 +21,7 @@ class I2SAudioComponent : public Component { i2s_pin_config_t get_pin_config() const { return { - .mck_io_num = I2S_PIN_NO_CHANGE, + .mck_io_num = this->mclk_pin_, .bck_io_num = this->bclk_pin_, .ws_io_num = this->lrclk_pin_, .data_out_num = I2S_PIN_NO_CHANGE, @@ -29,6 +29,7 @@ class I2SAudioComponent : public Component { }; } + void set_mclk_pin(int pin) { this->mclk_pin_ = pin; } void set_bclk_pin(int pin) { this->bclk_pin_ = pin; } void set_lrclk_pin(int pin) { this->lrclk_pin_ = pin; } @@ -44,6 +45,7 @@ class I2SAudioComponent : public Component { I2SAudioIn *audio_in_{nullptr}; I2SAudioOut *audio_out_{nullptr}; + int mclk_pin_{I2S_PIN_NO_CHANGE}; int bclk_pin_{I2S_PIN_NO_CHANGE}; int lrclk_pin_; i2s_port_t port_{}; diff --git a/tests/test4.yaml b/tests/test4.yaml index c1d49a4349..8e76a5fd66 100644 --- a/tests/test4.yaml +++ b/tests/test4.yaml @@ -666,6 +666,7 @@ touchscreen: i2s_audio: i2s_lrclk_pin: GPIO26 i2s_bclk_pin: GPIO27 + i2s_mclk_pin: GPIO25 media_player: - platform: i2s_audio