arduino-audio-tools
I2SConfigESP32.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 #if defined(ESP32) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0 , 0)
10 # include "driver/i2s.h" // for I2S_CHANNEL_FMT_RIGHT_LEFT
11 #endif
12 
13 namespace audio_tools {
14 
15 
16 
23 class I2SConfigESP32 : public AudioInfo {
24  public:
25 
26  I2SConfigESP32() {
27  channels = DEFAULT_CHANNELS;
28  sample_rate = DEFAULT_SAMPLE_RATE;
29  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
30  }
31 
33  I2SConfigESP32(const I2SConfigESP32 &cfg) = default;
34 
37  channels = DEFAULT_CHANNELS;
38  sample_rate = DEFAULT_SAMPLE_RATE;
39  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
40  rx_tx_mode = mode;
41  switch(mode){
42  case RX_MODE:
43  pin_data = PIN_I2S_DATA_IN;
44  auto_clear = false;
45  break;
46  case TX_MODE:
47  pin_data = PIN_I2S_DATA_OUT;
48  auto_clear = I2S_AUTO_CLEAR;
49  break;
50  default:
51  auto_clear = I2S_AUTO_CLEAR;
52  pin_data = PIN_I2S_DATA_OUT;
53  pin_data_rx = PIN_I2S_DATA_IN;
54  break;
55  }
56  }
57 
59  RxTxMode rx_tx_mode = RXTX_MODE;
60  I2SFormat i2s_format = I2S_STD_FORMAT;
61  I2SSignalType signal_type = Digital; // e.g. the ESP32 supports analog input or output or PDM picrophones
62  bool is_master = true;
63  int port_no = 0; // processor dependent port
64  int pin_ws = PIN_I2S_WS;
65  int pin_bck = PIN_I2S_BCK;
66  int pin_data = -1; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
67  int pin_data_rx = -1; // rx pin for RXTX_MODE
68  int pin_mck = PIN_I2S_MCK;
69  int buffer_count = I2S_BUFFER_COUNT;
70  int buffer_size = I2S_BUFFER_SIZE;
71  bool auto_clear = I2S_AUTO_CLEAR;
72  bool use_apll = I2S_USE_APLL;
73  uint32_t fixed_mclk = 0;
74 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0 , 0)
75  int channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
76 #endif
77 
78  void logInfo(const char* source="") {
79  AudioInfo::logInfo(source);
80  LOGI("rx/tx mode: %s", RxTxModeNames[rx_tx_mode]);
81  LOGI("port_no: %d", port_no);
82  LOGI("is_master: %s", is_master ? "Master":"Slave");
83  LOGI("sample rate: %d", sample_rate);
84  LOGI("bits per sample: %d", bits_per_sample);
85  LOGI("number of channels: %d", channels);
86  LOGI("signal_type: %s", i2s_signal_types[signal_type]);
87  if (signal_type==Digital){
88  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
89  }
90  LOGI("auto_clear: %s",auto_clear? "true" : "false");
91  if (use_apll) {
92  LOGI("use_apll: %s", use_apll ? "true" : "false");
93  }
94  if (fixed_mclk){
95  LOGI("fixed_mclk: %d", (int) fixed_mclk);
96  }
97  LOGI("buffer_count:%d",buffer_count);
98  LOGI("buffer_size:%d",buffer_size);
99 
100  if (pin_mck!=-1)
101  LOGI("pin_mck: %d", pin_mck);
102  if (pin_bck!=-1)
103  LOGI("pin_bck: %d", pin_bck);
104  if (pin_ws!=-1)
105  LOGI("pin_ws: %d", pin_ws);
106  if (pin_data!=-1)
107  LOGI("pin_data: %d", pin_data);
108  if (pin_data_rx!=-1 && rx_tx_mode==RXTX_MODE){
109  LOGI("pin_data_rx: %d", pin_data_rx);
110  }
111  }
112 
113 };
114 
115 using I2SConfig = I2SConfigESP32;
116 
117 }
118 
Configuration for ESP32 legacy i2s.
Definition: I2SConfigESP32.h:23
I2SConfigESP32(const I2SConfigESP32 &cfg)=default
Default Copy Constructor.
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigESP32.h:59
I2SConfigESP32(RxTxMode mode)
Constructor.
Definition: I2SConfigESP32.h:36
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
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