arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
AnalogConfigESP32.h
1#pragma once
2
3#include "AudioToolsConfig.h"
4#if defined(USE_ANALOG) && defined(ESP32) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0 , 0) || defined(DOXYGEN)
5#include "AudioTools/CoreAudio/AudioTypes.h"
6
7# include "driver/i2s.h"
8# include "driver/adc.h"
9# include "soc/dac_channel.h"
10# include "soc/adc_channel.h"
11
12namespace audio_tools {
13
23 public:
24 TickType_t timeout = portMAX_DELAY;
25 int buffer_count = ANALOG_BUFFER_COUNT;
26 int buffer_size = ANALOG_BUFFER_SIZE;
27 RxTxMode rx_tx_mode;
28 bool is_blocking_write = true;
29 bool is_auto_center_read = true;
30
31 // allow ADC to access the protected methods
32 friend class AnalogDriverESP32;
33 bool use_apll = false;
34
35 // public config parameters
36 int port_no = I2S_NUM_0; // Analog input and output only supports 0!
37 bool auto_clear = I2S_AUTO_CLEAR;
38 bool uninstall_driver_on_end = true;
39 int mode_internal;
40 int adc_pin;
41
43 AnalogConfigESP32(RxTxMode rxtxMode=TX_MODE) {
44 sample_rate = 44100;
45 bits_per_sample = 16;
46 channels = 2;
47 rx_tx_mode = rxtxMode;
48 if (rx_tx_mode == RX_MODE) {
49 mode_internal = (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN);
50 adc_pin = PIN_ADC1;
51 auto_clear = false;
52 LOGI("I2S_MODE_ADC_BUILT_IN");
53 } else {
54 mode_internal = (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN);
55 LOGI("I2S_MODE_DAC_BUILT_IN");
56 }
57 }
58
60 AnalogConfigESP32(const AnalogConfigESP32 &cfg) = default;
61
62 void logInfo() {
63 AudioInfo::logInfo();
64 if (rx_tx_mode == TX_MODE){
65 LOGI("analog left output pin: %d", 25);
66 LOGI("analog right output pin: %d", 26);
67 }
68 }
69
71 void setInputPin1(int pin){
72 this->adc_pin = pin;
73 }
74
75};
76
77#ifndef ANALOG_CONFIG
78#define ANALOG_CONFIG
79using AnalogConfig = AnalogConfigESP32;
80#endif
81
82} // ns
83#endif
ESP32 specific configuration for i2s input via adc. The default input pin is GPIO34....
Definition AnalogConfigESP32.h:22
AnalogConfigESP32(const AnalogConfigESP32 &cfg)=default
Copy constructor.
void setInputPin1(int pin)
Defines an alternative input pin (for the left channel)
Definition AnalogConfigESP32.h:71
AnalogConfigESP32(RxTxMode rxtxMode=TX_MODE)
Default constructor.
Definition AnalogConfigESP32.h:43
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 AudioCodecsBase.h:10
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:53
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