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