ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
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#include <freertos/FreeRTOS.h>
11#include <freertos/event_groups.h>
12#include <freertos/semphr.h>
13#include <freertos/task.h>
14
15namespace esphome {
16namespace i2s_audio {
17
19 public:
20 void setup() override;
21 void dump_config() override;
22 void start() override;
23 void stop() override;
24
25 void loop() override;
26
27 void set_correct_dc_offset(bool correct_dc_offset) { this->correct_dc_offset_ = correct_dc_offset; }
28
29#ifdef USE_I2S_LEGACY
30 void set_din_pin(int8_t pin) { this->din_pin_ = pin; }
31#else
32 void set_din_pin(int8_t pin) { this->din_pin_ = (gpio_num_t) pin; }
33#endif
34
35 void set_pdm(bool pdm) { this->pdm_ = pdm; }
36
37#ifdef USE_I2S_LEGACY
38#if SOC_I2S_SUPPORTS_ADC
39 void set_adc_channel(adc_channel_t channel) {
40 this->adc_channel_ = (adc1_channel_t) channel;
41 this->adc_ = true;
42 }
43#endif
44#endif
45
46 protected:
49 bool start_driver_();
50
52 void stop_driver_();
53
57 void fix_dc_offset_(std::vector<uint8_t> &data);
58
59 size_t read_(uint8_t *buf, size_t len, TickType_t ticks_to_wait);
60
63
64 static void mic_task(void *params);
65
66 SemaphoreHandle_t active_listeners_semaphore_{nullptr};
67 EventGroupHandle_t event_group_{nullptr};
68
69 TaskHandle_t task_handle_{nullptr};
70
71#ifdef USE_I2S_LEGACY
72 int8_t din_pin_{I2S_PIN_NO_CHANGE};
73#if SOC_I2S_SUPPORTS_ADC
74 adc1_channel_t adc_channel_{ADC1_CHANNEL_MAX};
75 bool adc_{false};
76#endif
77#else
78 gpio_num_t din_pin_{I2S_GPIO_UNUSED};
79 i2s_chan_handle_t rx_handle_;
80#endif
81 bool pdm_{false};
82
84 bool locked_driver_{false};
87};
88
89} // namespace i2s_audio
90} // namespace esphome
91
92#endif // USE_ESP32
void set_adc_channel(adc_channel_t channel)
void set_correct_dc_offset(bool correct_dc_offset)
void configure_stream_settings_()
Starts the I2S driver.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:279