ESPHome  2024.4.1
i2s_audio_media_player.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP32_FRAMEWORK_ARDUINO
4 
5 #include "../i2s_audio.h"
6 
7 #include <driver/i2s.h>
8 
10 #include "esphome/core/component.h"
11 #include "esphome/core/gpio.h"
12 #include "esphome/core/helpers.h"
13 
14 #include <Audio.h>
15 
16 namespace esphome {
17 namespace i2s_audio {
18 
19 enum I2SState : uint8_t {
24 };
25 
27  public:
28  void setup() override;
29  float get_setup_priority() const override { return esphome::setup_priority::LATE; }
30 
31  void loop() override;
32 
33  void dump_config() override;
34 
35  void set_dout_pin(uint8_t pin) { this->dout_pin_ = pin; }
36  void set_mute_pin(GPIOPin *mute_pin) { this->mute_pin_ = mute_pin; }
37 #if SOC_I2S_SUPPORTS_DAC
38  void set_internal_dac_mode(i2s_dac_mode_t mode) { this->internal_dac_mode_ = mode; }
39 #endif
40  void set_external_dac_channels(uint8_t channels) { this->external_dac_channels_ = channels; }
41 
42  void set_i2s_comm_fmt_lsb(bool lsb) { this->i2s_comm_fmt_lsb_ = lsb; }
43 
45 
46  bool is_muted() const override { return this->muted_; }
47 
48  void start();
49  void stop();
50 
51  protected:
52  void control(const media_player::MediaPlayerCall &call) override;
53 
54  void mute_();
55  void unmute_();
56  void set_volume_(float volume, bool publish = true);
57 
58  void start_();
59  void stop_();
60  void play_();
61 
63  std::unique_ptr<Audio> audio_;
64 
65  uint8_t dout_pin_{0};
66 
67  GPIOPin *mute_pin_{nullptr};
68  bool muted_{false};
69  float unmuted_volume_{0};
70 
71 #if SOC_I2S_SUPPORTS_DAC
72  i2s_dac_mode_t internal_dac_mode_{I2S_DAC_CHANNEL_DISABLE};
73 #endif
75 
77 
79 
81 };
82 
83 } // namespace i2s_audio
84 } // namespace esphome
85 
86 #endif // USE_ESP32_FRAMEWORK_ARDUINO
void control(const media_player::MediaPlayerCall &call) override
Helper class to request loop() to be called as fast as possible.
Definition: helpers.h:603
const float LATE
For components that should be initialized at the very end of the setup process.
Definition: component.cpp:28
media_player::MediaPlayerTraits get_traits() override
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_volume_(float volume, bool publish=true)