arduino-audio-tools
I2SConfigESP32V1.h
1 #pragma once
2 #include "AudioConfig.h"
3 #include "AudioTools/AudioTypes.h"
4 
5 #ifndef PIN_I2S_MCK
6 # define PIN_I2S_MCK -1
7 #endif
8 
9 namespace audio_tools {
10 
17 class I2SConfigESP32V1 : public AudioInfo {
18  public:
19 
21  channels = DEFAULT_CHANNELS;
22  sample_rate = DEFAULT_SAMPLE_RATE;
23  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
24  }
25 
27  I2SConfigESP32V1(const I2SConfigESP32V1 &cfg) = default;
28 
31  channels = DEFAULT_CHANNELS;
32  sample_rate = DEFAULT_SAMPLE_RATE;
33  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
34  rx_tx_mode = mode;
35  switch(mode){
36  case RX_MODE:
37  pin_data = PIN_I2S_DATA_IN;
38  break;
39  case TX_MODE:
40  pin_data = PIN_I2S_DATA_OUT;
41  break;
42  default:
43  pin_data = PIN_I2S_DATA_OUT;
44  pin_data_rx = PIN_I2S_DATA_IN;
45  break;
46  }
47  }
48 
50  RxTxMode rx_tx_mode = TX_MODE;
51  I2SFormat i2s_format = I2S_STD_FORMAT;
52  I2SSignalType signal_type = Digital; // e.g. the ESP32 supports analog input or output or PDM picrophones
53  bool is_master = true;
54  int port_no = 0; // processor dependent port
55  int pin_ws = PIN_I2S_WS;
56  int pin_bck = PIN_I2S_BCK;
57  int pin_data; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
58  int pin_data_rx; // rx pin for RXTX_MODE
59  int pin_mck = PIN_I2S_MCK;
60  int buffer_count = I2S_BUFFER_COUNT;
61  int buffer_size = I2S_BUFFER_SIZE;
62  bool use_apll = I2S_USE_APLL;
63 
64  void logInfo(const char* source="") {
65  AudioInfo::logInfo(source);
66  LOGI("rx/tx mode: %s", RxTxModeNames[rx_tx_mode]);
67  LOGI("port_no: %d", port_no);
68  LOGI("is_master: %s", is_master ? "Master":"Slave");
69  LOGI("sample rate: %d", (int) sample_rate);
70  LOGI("bits per sample: %d", bits_per_sample);
71  LOGI("number of channels: %d", channels);
72  LOGI("signal_type: %s", i2s_signal_types[signal_type]);
73  if (signal_type==Digital){
74  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
75  }
76  if (use_apll) {
77  LOGI("use_apll: %s", use_apll ? "true" : "false");
78  }
79  LOGI("buffer_count:%d",buffer_count);
80  LOGI("buffer_size:%d",buffer_size);
81 
82  if (pin_mck!=-1)
83  LOGI("pin_mck: %d", pin_mck);
84  if (pin_bck!=-1)
85  LOGI("pin_bck: %d", pin_bck);
86  if (pin_ws!=-1)
87  LOGI("pin_ws: %d", pin_ws);
88  if (pin_data!=-1)
89  LOGI("pin_data: %d", pin_data);
90  if (pin_data_rx!=-1){
91  LOGI("pin_data_rx: %d", pin_data_rx);
92  }
93  }
94 
95 };
96 
97 using I2SConfig = I2SConfigESP32V1;
98 
99 }
100 
Configuration for ESP32 i2s for IDF > 5.0.
Definition: I2SConfigESP32V1.h:17
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigESP32V1.h:50
I2SConfigESP32V1(const I2SConfigESP32V1 &cfg)=default
Default Copy Constructor.
I2SConfigESP32V1(RxTxMode mode)
Constructor.
Definition: I2SConfigESP32V1.h:30
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:26
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudio.h:10
I2SSignalType
I2S Signal Types: Digital, Analog, PDM.
Definition: AudioTypes.h:405
I2SFormat
I2S Formats.
Definition: AudioTypes.h:390
static const char * RxTxModeNames[]
Text string (description) for RxTxMode.
Definition: AudioTypes.h:38
Basic Audio information which drives e.g. I2S.
Definition: AudioTypes.h:50
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition: AudioTypes.h:53
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition: AudioTypes.h:55
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition: AudioTypes.h:57