arduino-audio-tools
I2SConfigStd.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 namespace audio_tools {
10 
17 class I2SConfigStd : public AudioInfo {
18  public:
19 
20  I2SConfigStd() = default;
22  I2SConfigStd(const I2SConfigStd &cfg) = default;
23 
26  channels = DEFAULT_CHANNELS;
27  sample_rate = DEFAULT_SAMPLE_RATE;
28  bits_per_sample = DEFAULT_BITS_PER_SAMPLE;
29  rx_tx_mode = mode;
30 
31 #ifndef STM32
32  switch(mode){
33  case RX_MODE:
34  pin_data = PIN_I2S_DATA_IN;
35  break;
36  case TX_MODE:
37  pin_data = PIN_I2S_DATA_OUT;
38  break;
39  default:
40  pin_data = PIN_I2S_DATA_OUT;
41  pin_data_rx = PIN_I2S_DATA_IN;
42  break;
43  }
44 #endif
45  }
46 
48  RxTxMode rx_tx_mode = TX_MODE;
49  bool is_master = true;
50  I2SFormat i2s_format = I2S_STD_FORMAT;
51  int buffer_count = I2S_BUFFER_COUNT;
52  int buffer_size = I2S_BUFFER_SIZE;
53 
54  int pin_ws = PIN_I2S_WS;
55  int pin_bck = PIN_I2S_BCK;
56  int pin_data = -1; // rx or tx pin dependent on mode: tx pin for RXTX_MODE
57  int pin_data_rx = -1; // rx pin for RXTX_MODE
58  int pin_mck = PIN_I2S_MCK;
59 #ifdef STM32
60  int pin_alt_function = -1;
61 #endif
62 
63 #if defined(RP2040_HOWER)
65  int mck_multiplier = 64;
66  I2SSignalType signal_type = Digital; // e.g. the RP2040 supports digial or PDM
67 #endif
68 
69 #if defined(USE_ALT_PIN_SUPPORT)
70  bool is_arduino_pin_numbers = true;
71 #endif
72 
73  void logInfo(const char* source="") {
74  AudioInfo::logInfo(source);
75  LOGI("rx/tx mode: %s", RxTxModeNames[rx_tx_mode]);
76  //LOGI("port_no: %d", port_no);
77  LOGI("is_master: %s", is_master ? "Master":"Slave");
78  LOGI("sample rate: %d", (int)sample_rate);
79  LOGI("bits per sample: %d", (int)bits_per_sample);
80  LOGI("number of channels: %d", (int)channels);
81  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
82  LOGI("buffer_count:%d",buffer_count);
83  LOGI("buffer_size:%d",buffer_size);
84 
85 #ifndef STM32
86  if (pin_mck!=-1)
87  LOGI("pin_mck: %d", pin_mck);
88  if (pin_bck!=-1)
89  LOGI("pin_bck: %d", pin_bck);
90  if (pin_ws!=-1)
91  LOGI("pin_ws: %d", pin_ws);
92  if (pin_data!=-1)
93  LOGI("pin_data: %d", pin_data);
94  if (pin_data_rx!=-1 && rx_tx_mode==RXTX_MODE){
95  LOGI("pin_data_rx: %d", pin_data_rx);
96  }
97 #endif
98  }
99 
100 };
101 
102 using I2SConfig = I2SConfigStd;
103 
104 }
105 
Configuration for i2s.
Definition: I2SConfigStd.h:17
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigStd.h:48
I2SConfigStd(const I2SConfigStd &cfg)=default
Default Copy Constructor.
I2SConfigStd(RxTxMode mode)
Constructor.
Definition: I2SConfigStd.h:25
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