ESPHome  2024.4.2
i2s_audio_microphone.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP32
4 
5 #include "../i2s_audio.h"
6 
9 
10 namespace esphome {
11 namespace i2s_audio {
12 
14  public:
15  void setup() override;
16  void start() override;
17  void stop() override;
18 
19  void loop() override;
20 
21  void set_din_pin(int8_t pin) { this->din_pin_ = pin; }
22  void set_pdm(bool pdm) { this->pdm_ = pdm; }
23 
24  size_t read(int16_t *buf, size_t len) override;
25 
26 #if SOC_I2S_SUPPORTS_ADC
27  void set_adc_channel(adc1_channel_t channel) {
28  this->adc_channel_ = channel;
29  this->adc_ = true;
30  }
31 #endif
32 
33  void set_channel(i2s_channel_fmt_t channel) { this->channel_ = channel; }
34  void set_sample_rate(uint32_t sample_rate) { this->sample_rate_ = sample_rate; }
35  void set_bits_per_sample(i2s_bits_per_sample_t bits_per_sample) { this->bits_per_sample_ = bits_per_sample; }
36  void set_use_apll(uint32_t use_apll) { this->use_apll_ = use_apll; }
37 
38  protected:
39  void start_();
40  void stop_();
41  void read_();
42 
43  int8_t din_pin_{I2S_PIN_NO_CHANGE};
44 #if SOC_I2S_SUPPORTS_ADC
45  adc1_channel_t adc_channel_{ADC1_CHANNEL_MAX};
46  bool adc_{false};
47 #endif
48  bool pdm_{false};
49  i2s_channel_fmt_t channel_;
50  uint32_t sample_rate_;
51  i2s_bits_per_sample_t bits_per_sample_;
52  bool use_apll_;
53 
55 };
56 
57 } // namespace i2s_audio
58 } // namespace esphome
59 
60 #endif // USE_ESP32
void set_bits_per_sample(i2s_bits_per_sample_t bits_per_sample)
Helper class to request loop() to be called as fast as possible.
Definition: helpers.h:603
void set_adc_channel(adc1_channel_t channel)
void set_channel(i2s_channel_fmt_t channel)
void set_sample_rate(uint32_t sample_rate)
size_t read(int16_t *buf, size_t len) override
std::string size_t len
Definition: helpers.h:292
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7