mirror of
https://github.com/esphome/esphome.git
synced 2024-12-23 05:54:56 +01:00
commit
3807350c61
5 changed files with 16 additions and 4 deletions
|
@ -2,7 +2,7 @@ import esphome.config_validation as cv
|
|||
import esphome.codegen as cg
|
||||
|
||||
from esphome import pins
|
||||
from esphome.const import CONF_ID, CONF_NUMBER
|
||||
from esphome.const import CONF_CHANNEL, CONF_ID, CONF_NUMBER
|
||||
from esphome.components import microphone, esp32
|
||||
from esphome.components.adc import ESP32_VARIANT_ADC1_PIN_TO_CHANNEL, validate_adc_pin
|
||||
|
||||
|
@ -25,6 +25,12 @@ I2SAudioMicrophone = i2s_audio_ns.class_(
|
|||
"I2SAudioMicrophone", I2SAudioIn, microphone.Microphone, cg.Component
|
||||
)
|
||||
|
||||
i2s_channel_fmt_t = cg.global_ns.enum("i2s_channel_fmt_t")
|
||||
CHANNELS = {
|
||||
"left": i2s_channel_fmt_t.I2S_CHANNEL_FMT_ONLY_LEFT,
|
||||
"right": i2s_channel_fmt_t.I2S_CHANNEL_FMT_ONLY_RIGHT,
|
||||
}
|
||||
|
||||
INTERNAL_ADC_VARIANTS = [esp32.const.VARIANT_ESP32]
|
||||
PDM_VARIANTS = [esp32.const.VARIANT_ESP32, esp32.const.VARIANT_ESP32S3]
|
||||
|
||||
|
@ -47,6 +53,7 @@ BASE_SCHEMA = microphone.MICROPHONE_SCHEMA.extend(
|
|||
{
|
||||
cv.GenerateID(): cv.declare_id(I2SAudioMicrophone),
|
||||
cv.GenerateID(CONF_I2S_AUDIO_ID): cv.use_id(I2SAudioComponent),
|
||||
cv.Optional(CONF_CHANNEL, default="right"): cv.enum(CHANNELS),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
@ -86,4 +93,6 @@ async def to_code(config):
|
|||
cg.add(var.set_din_pin(config[CONF_I2S_DIN_PIN]))
|
||||
cg.add(var.set_pdm(config[CONF_PDM]))
|
||||
|
||||
cg.add(var.set_channel(CHANNELS[config[CONF_CHANNEL]]))
|
||||
|
||||
await microphone.register_microphone(var, config)
|
||||
|
|
|
@ -49,7 +49,7 @@ void I2SAudioMicrophone::start_() {
|
|||
.mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_RX),
|
||||
.sample_rate = 16000,
|
||||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
|
||||
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
|
||||
.channel_format = this->channel_,
|
||||
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
|
||||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
.dma_buf_count = 4,
|
||||
|
|
|
@ -28,6 +28,8 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub
|
|||
}
|
||||
#endif
|
||||
|
||||
void set_channel(i2s_channel_fmt_t channel) { this->channel_ = channel; }
|
||||
|
||||
protected:
|
||||
void start_();
|
||||
void stop_();
|
||||
|
@ -40,6 +42,7 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub
|
|||
#endif
|
||||
bool pdm_{false};
|
||||
std::vector<uint8_t> buffer_;
|
||||
i2s_channel_fmt_t channel_;
|
||||
|
||||
HighFrequencyLoopRequester high_freq_;
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ void PsramComponent::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
|
||||
if (available) {
|
||||
ESP_LOGCONFIG(TAG, " Size: %d MB", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024 / 1024);
|
||||
ESP_LOGCONFIG(TAG, " Size: %d KB", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2023.5.2"
|
||||
__version__ = "2023.5.3"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
|
||||
|
|
Loading…
Reference in a new issue