From 8822b6c808881390b1bf77423ac78430bc0b6346 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Thu, 11 May 2023 07:17:59 +1200 Subject: [PATCH] Make i2s_audio bclk_pin optional (#4801) --- esphome/components/i2s_audio/__init__.py | 5 +++-- esphome/components/i2s_audio/i2s_audio.h | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/esphome/components/i2s_audio/__init__.py b/esphome/components/i2s_audio/__init__.py index 1773d3082f..39d81ef1a1 100644 --- a/esphome/components/i2s_audio/__init__.py +++ b/esphome/components/i2s_audio/__init__.py @@ -42,8 +42,8 @@ I2S_PORTS = { CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(): cv.declare_id(I2SAudioComponent), - cv.Required(CONF_I2S_BCLK_PIN): pins.internal_gpio_output_pin_number, cv.Required(CONF_I2S_LRCLK_PIN): pins.internal_gpio_output_pin_number, + cv.Optional(CONF_I2S_BCLK_PIN): pins.internal_gpio_output_pin_number, } ) @@ -66,5 +66,6 @@ async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - cg.add(var.set_bclk_pin(config[CONF_I2S_BCLK_PIN])) 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])) diff --git a/esphome/components/i2s_audio/i2s_audio.h b/esphome/components/i2s_audio/i2s_audio.h index b2fb1ca27c..f030ed4e75 100644 --- a/esphome/components/i2s_audio/i2s_audio.h +++ b/esphome/components/i2s_audio/i2s_audio.h @@ -29,8 +29,8 @@ class I2SAudioComponent : public Component { }; } - void set_bclk_pin(uint8_t pin) { this->bclk_pin_ = pin; } - void set_lrclk_pin(uint8_t pin) { this->lrclk_pin_ = pin; } + void set_bclk_pin(int pin) { this->bclk_pin_ = pin; } + void set_lrclk_pin(int pin) { this->lrclk_pin_ = pin; } void lock() { this->lock_.lock(); } bool try_lock() { return this->lock_.try_lock(); } @@ -41,8 +41,11 @@ class I2SAudioComponent : public Component { protected: Mutex lock_; - uint8_t bclk_pin_; - uint8_t lrclk_pin_; + I2SAudioIn *audio_in_{nullptr}; + I2SAudioOut *audio_out_{nullptr}; + + int bclk_pin_{I2S_PIN_NO_CHANGE}; + int lrclk_pin_; i2s_port_t port_{}; };