arduino-audio-tools
AnalogConfigESP32.h
1 #pragma once
2 
3 #include "AudioConfig.h"
4 #if defined(USE_ANALOG) && defined(ESP32) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0 , 0) || defined(DOXYGEN)
5 
6 # include "driver/i2s.h"
7 # include "driver/adc.h"
8 # include "soc/dac_channel.h"
9 # include "soc/adc_channel.h"
10 
11 namespace audio_tools {
12 
21 class AnalogConfigESP32 : public AudioInfo {
22  public:
23  int buffer_count = ANALOG_BUFFER_COUNT;
24  int buffer_size = ANALOG_BUFFER_SIZE;
25  RxTxMode rx_tx_mode;
26  bool is_blocking_write = true;
27  bool is_auto_center_read = true;
28 
29  // allow ADC to access the protected methods
30  friend class AnalogDriverESP32;
31  bool use_apll = false;
32 
33  // public config parameters
34  int port_no = I2S_NUM_0; // Analog input and output only supports 0!
35  bool auto_clear = I2S_AUTO_CLEAR;
36  bool uninstall_driver_on_end = true;
37  int mode_internal;
38  int adc_pin;
39 
41  AnalogConfigESP32(RxTxMode rxtxMode=TX_MODE) {
42  sample_rate = 44100;
43  bits_per_sample = 16;
44  channels = 2;
45  rx_tx_mode = rxtxMode;
46  if (rx_tx_mode == RX_MODE) {
47  mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
48  adc_pin = PIN_ADC1;
49  auto_clear = false;
50  LOGI("I2S_MODE_ADC_BUILT_IN");
51  } else {
52  mode_internal = (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN);
53  LOGI("I2S_MODE_DAC_BUILT_IN");
54  }
55  }
56 
58  AnalogConfigESP32(const AnalogConfigESP32 &cfg) = default;
59 
60  void logInfo() {
61  AudioInfo::logInfo();
62  if (rx_tx_mode == TX_MODE){
63  LOGI("analog left output pin: %d", 25);
64  LOGI("analog right output pin: %d", 26);
65  }
66  }
67 
69  void setInputPin1(int pin){
70  this->adc_pin = pin;
71  }
72 
73 };
74 
75 #ifndef ANALOG_CONFIG
76 #define ANALOG_CONFIG
77 using AnalogConfig = AnalogConfigESP32;
78 #endif
79 
80 } // ns
81 #endif
ESP32 specific configuration for i2s input via adc. The default input pin is GPIO34....
Definition: AnalogConfigESP32.h:21
AnalogConfigESP32(const AnalogConfigESP32 &cfg)=default
Copy constructor.
void setInputPin1(int pin)
Defines an alternative input pin (for the left channel)
Definition: AnalogConfigESP32.h:69
AnalogConfigESP32(RxTxMode rxtxMode=TX_MODE)
Default constructor.
Definition: AnalogConfigESP32.h:41
Please use AnalogAudioStream: A very fast ADC and DAC using the ESP32 I2S interface.
Definition: AnalogDriverESP32.h:35
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:28
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:823
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:52
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:55
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:57
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:59