ESPHome  2024.4.1
i2s_audio.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP32
4 
5 #include <driver/i2s.h>
7 #include "esphome/core/helpers.h"
8 
9 namespace esphome {
10 namespace i2s_audio {
11 
12 class I2SAudioComponent;
13 
14 class I2SAudioIn : public Parented<I2SAudioComponent> {};
15 
16 class I2SAudioOut : public Parented<I2SAudioComponent> {};
17 
18 class I2SAudioComponent : public Component {
19  public:
20  void setup() override;
21 
22  i2s_pin_config_t get_pin_config() const {
23  return {
24  .mck_io_num = this->mclk_pin_,
25  .bck_io_num = this->bclk_pin_,
26  .ws_io_num = this->lrclk_pin_,
27  .data_out_num = I2S_PIN_NO_CHANGE,
28  .data_in_num = I2S_PIN_NO_CHANGE,
29  };
30  }
31 
32  void set_mclk_pin(int pin) { this->mclk_pin_ = pin; }
33  void set_bclk_pin(int pin) { this->bclk_pin_ = pin; }
34  void set_lrclk_pin(int pin) { this->lrclk_pin_ = pin; }
35 
36  void lock() { this->lock_.lock(); }
37  bool try_lock() { return this->lock_.try_lock(); }
38  void unlock() { this->lock_.unlock(); }
39 
40  i2s_port_t get_port() const { return this->port_; }
41 
42  protected:
44 
45  I2SAudioIn *audio_in_{nullptr};
46  I2SAudioOut *audio_out_{nullptr};
47 
48  int mclk_pin_{I2S_PIN_NO_CHANGE};
49  int bclk_pin_{I2S_PIN_NO_CHANGE};
51  i2s_port_t port_{};
52 };
53 
54 } // namespace i2s_audio
55 } // namespace esphome
56 
57 #endif // USE_ESP32
void setup()
i2s_pin_config_t get_pin_config() const
Definition: i2s_audio.h:22
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
Helper class to easily give an object a parent of type T.
Definition: helpers.h:515
Mutex implementation, with API based on the unavailable std::mutex.
Definition: helpers.h:538