mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Added i2s_comm_fmt parameter to i2s speaker component (#7449)
Co-authored-by: PxPert <pxpert@pxpert.cloud>
This commit is contained in:
parent
446f7e0a7e
commit
ddde64a48d
3 changed files with 22 additions and 1 deletions
|
@ -25,6 +25,7 @@ I2SAudioSpeaker = i2s_audio_ns.class_(
|
|||
|
||||
|
||||
CONF_DAC_TYPE = "dac_type"
|
||||
CONF_I2S_COMM_FMT = "i2s_comm_fmt"
|
||||
|
||||
i2s_dac_mode_t = cg.global_ns.enum("i2s_dac_mode_t")
|
||||
INTERNAL_DAC_OPTIONS = {
|
||||
|
@ -33,6 +34,20 @@ INTERNAL_DAC_OPTIONS = {
|
|||
CONF_STEREO: i2s_dac_mode_t.I2S_DAC_CHANNEL_BOTH_EN,
|
||||
}
|
||||
|
||||
i2s_comm_format_t = cg.global_ns.enum("i2s_comm_format_t")
|
||||
I2C_COMM_FMT_OPTIONS = {
|
||||
"stand_i2s": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_I2S,
|
||||
"stand_msb": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_MSB,
|
||||
"stand_pcm_short": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_PCM_SHORT,
|
||||
"stand_pcm_long": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_PCM_LONG,
|
||||
"stand_max": i2s_comm_format_t.I2S_COMM_FORMAT_STAND_MAX,
|
||||
"i2s_msb": i2s_comm_format_t.I2S_COMM_FORMAT_I2S_MSB,
|
||||
"i2s_lsb": i2s_comm_format_t.I2S_COMM_FORMAT_I2S_LSB,
|
||||
"pcm": i2s_comm_format_t.I2S_COMM_FORMAT_PCM,
|
||||
"pcm_short": i2s_comm_format_t.I2S_COMM_FORMAT_PCM_SHORT,
|
||||
"pcm_long": i2s_comm_format_t.I2S_COMM_FORMAT_PCM_LONG,
|
||||
}
|
||||
|
||||
NO_INTERNAL_DAC_VARIANTS = [esp32.const.VARIANT_ESP32S2]
|
||||
|
||||
|
||||
|
@ -77,6 +92,9 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.Required(
|
||||
CONF_I2S_DOUT_PIN
|
||||
): pins.internal_gpio_output_pin_number,
|
||||
cv.Optional(CONF_I2S_COMM_FMT, default="stand_i2s"): cv.enum(
|
||||
I2C_COMM_FMT_OPTIONS, lower=True
|
||||
),
|
||||
}
|
||||
),
|
||||
},
|
||||
|
@ -96,4 +114,5 @@ async def to_code(config):
|
|||
cg.add(var.set_internal_dac_mode(config[CONF_CHANNEL]))
|
||||
else:
|
||||
cg.add(var.set_dout_pin(config[CONF_I2S_DOUT_PIN]))
|
||||
cg.add(var.set_i2s_comm_fmt(config[CONF_I2S_COMM_FMT]))
|
||||
cg.add(var.set_timeout(config[CONF_TIMEOUT]))
|
||||
|
|
|
@ -83,7 +83,7 @@ void I2SAudioSpeaker::player_task(void *params) {
|
|||
.sample_rate = this_speaker->sample_rate_,
|
||||
.bits_per_sample = this_speaker->bits_per_sample_,
|
||||
.channel_format = this_speaker->channel_,
|
||||
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
|
||||
.communication_format = this_speaker->i2s_comm_fmt_,
|
||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
.dma_buf_count = 8,
|
||||
.dma_buf_len = 256,
|
||||
|
|
|
@ -49,6 +49,7 @@ class I2SAudioSpeaker : public I2SAudioOut, public speaker::Speaker, public Comp
|
|||
#if SOC_I2S_SUPPORTS_DAC
|
||||
void set_internal_dac_mode(i2s_dac_mode_t mode) { this->internal_dac_mode_ = mode; }
|
||||
#endif
|
||||
void set_i2s_comm_fmt(i2s_comm_format_t mode) { this->i2s_comm_fmt_ = mode; }
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
|
@ -76,6 +77,7 @@ class I2SAudioSpeaker : public I2SAudioOut, public speaker::Speaker, public Comp
|
|||
#if SOC_I2S_SUPPORTS_DAC
|
||||
i2s_dac_mode_t internal_dac_mode_{I2S_DAC_CHANNEL_DISABLE};
|
||||
#endif
|
||||
i2s_comm_format_t i2s_comm_fmt_;
|
||||
};
|
||||
|
||||
} // namespace i2s_audio
|
||||
|
|
Loading…
Reference in a new issue