arduino-audio-tools
I2SConfigESP32V1.h
1 #pragma once
2 #include "AudioConfig.h"
3 #include "AudioTools/CoreAudio/AudioTypes.h"
4 
5 #ifndef PIN_I2S_MCK
6 # define PIN_I2S_MCK -1
7 #endif
8 
9 
10 
11 namespace audio_tools {
12 
14 enum class I2SChannelSelect { Stereo, Left, Right, Default };
15 
22 class I2SConfigESP32V1 : public AudioInfo {
23  public:
24 
26  channels = DEFAULT_CHANNELS;
27  sample_rate = DEFAULT_SAMPLE_RATE;
28  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
29  }
30 
32  I2SConfigESP32V1(const I2SConfigESP32V1 &cfg) = default;
33 
36  channels = DEFAULT_CHANNELS;
37  sample_rate = DEFAULT_SAMPLE_RATE;
38  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
39  rx_tx_mode = mode;
40  switch(mode){
41  case RX_MODE:
42  pin_data = PIN_I2S_DATA_IN;
43  break;
44  case TX_MODE:
45  pin_data = PIN_I2S_DATA_OUT;
46  break;
47  default:
48  pin_data = PIN_I2S_DATA_OUT;
49  pin_data_rx = PIN_I2S_DATA_IN;
50  break;
51  }
52  }
53 
55  RxTxMode rx_tx_mode = TX_MODE;
56  I2SFormat i2s_format = I2S_STD_FORMAT;
57  I2SSignalType signal_type = Digital; // e.g. the ESP32 supports analog input or output or PDM picrophones
58  bool is_master = true;
59  int port_no = 0; // processor dependent port
60  int pin_ws = PIN_I2S_WS;
61  int pin_bck = PIN_I2S_BCK;
62  int pin_data = -1; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
63  int pin_data_rx = -1; // rx pin for RXTX_MODE
64  int pin_mck = PIN_I2S_MCK;
66  int buffer_count = I2S_BUFFER_COUNT;
68  int buffer_size = I2S_BUFFER_SIZE;
69  bool use_apll = I2S_USE_APLL;
70  bool auto_clear = I2S_AUTO_CLEAR;
72  I2SChannelSelect channel_format = I2SChannelSelect::Default;
74  int mclk_multiple = -1;
75 
76  void logInfo(const char* source="") {
77  AudioInfo::logInfo(source);
78  LOGI("rx/tx mode: %s", RxTxModeNames[rx_tx_mode]);
79  LOGI("port_no: %d", port_no);
80  LOGI("is_master: %s", is_master ? "Master":"Slave");
81  LOGI("sample rate: %d", (int) sample_rate);
82  LOGI("bits per sample: %d", bits_per_sample);
83  LOGI("number of channels: %d", channels);
84  LOGI("signal_type: %s", i2s_signal_types[signal_type]);
85  LOGI("buffer_count:%d", buffer_count);
86  LOGI("buffer_size:%d", buffer_size);
87  LOGI("auto_clear: %s",auto_clear? "true" : "false");
88  if (signal_type==Digital){
89  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
90  }
91  if (use_apll) {
92  LOGI("use_apll: %s", use_apll ? "true" : "false");
93  }
94  // LOGI("buffer_count:%d",buffer_count);
95  // LOGI("buffer_size:%d",buffer_size);
96 
97  if (pin_mck!=-1)
98  LOGI("pin_mck: %d", pin_mck);
99  if (pin_bck!=-1)
100  LOGI("pin_bck: %d", pin_bck);
101  if (pin_ws!=-1)
102  LOGI("pin_ws: %d", pin_ws);
103  if (pin_data!=-1)
104  LOGI("pin_data: %d", pin_data);
105  if (pin_data_rx!=-1){
106  LOGI("pin_data_rx: %d", pin_data_rx);
107  }
108  }
109 
110 };
111 
112 using I2SConfig = I2SConfigESP32V1;
113 
114 }
115 
Configuration for ESP32 i2s for IDF > 5.0.
Definition: I2SConfigESP32V1.h:22
int buffer_count
not used any more
Definition: I2SConfigESP32V1.h:66
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigESP32V1.h:55
int mclk_multiple
masterclock multiple (-1 = use default)
Definition: I2SConfigESP32V1.h:74
I2SChannelSelect channel_format
Select left or right channel when channels == 1.
Definition: I2SConfigESP32V1.h:72
int buffer_size
not used any more
Definition: I2SConfigESP32V1.h:68
I2SConfigESP32V1(const I2SConfigESP32V1 &cfg)=default
Default Copy Constructor.
I2SConfigESP32V1(RxTxMode mode)
Constructor.
Definition: I2SConfigESP32V1.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
I2SSignalType
I2S Signal Types: Digital, Analog, PDM.
Definition: AudioTypes.h:451
static const char * RxTxModeNames[4]
Text string (description) for RxTxMode.
Definition: AudioTypes.h:40
I2SFormat
I2S Formats.
Definition: AudioTypes.h:436
I2SChannelSelect
Select left or right channel when number of channels = 1.
Definition: I2SConfigESP32V1.h:14
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