MCPcopy Create free account
hub / github.com/SmingHub/Sming / initialiseI2S

Function initialiseI2S

samples/Basic_Audio/app/application.cpp:167–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void initialiseI2S()
168{
169 i2s_config_t config;
170 memset(&config, 0, sizeof(config));
171 const i2s_module_config_t modcfg = {
172 .mode = I2S_MODE_MASTER,
173 .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
174 .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
175 .communication_format = I2S_COMM_FORMAT_I2S_MSB,
176 .dma_buf_len = 128,
177 .dma_buf_count = 4,
178 .callback_threshold = 1,
179 };
180
181 /*
182 * Not clear exactly what this setting does.
183 * I think, additional bits written out.
184 *
185 * For example, 16-bit channel data + bits_mod=8 produces 24-bits per channel.
186 * Where do additional 8 bits come from? Scope says 0.
187 */
188 config.bits_mod = 16;
189
190 config.tx = modcfg;
191 config.sample_rate = targetSampleRate;
192 // config.rx = modcfg;
193 // config.rx.mode = I2S_MODE_SLAVE;
194 // config.tx_desc_auto_clear = true;
195 // config.auto_start = true;
196 config.callback = i2sCallback;
197 config.param = nullptr; // If you want to pass a parameter to the callback routine
198 if(!i2s_driver_install(&config)) {
199 debug_e("i2s_driver_install failed");
200 return;
201 }
202
203#ifdef ENABLE_DELTA_SIGMA
204 // We're doing delta mod so only need one pin
205 i2s_set_pins(I2S_PIN_DATA_OUT, true);
206#else
207 // Real I2S DACs require channel select (assuming its stereo) and clock lines
208 i2s_set_pins(I2S_PIN_DATA_OUT | I2S_PIN_WS_OUT | I2S_PIN_BCK_OUT, true);
209#endif
210
211 auto realSampleRate = i2s_get_real_rate();
212 Serial << _F("I2S initialised, rate = ") << realSampleRate << endl;
213
214#ifndef GENERATE_FIXED_VALUES
215 /*
216 * Generate sine wave data using the actual sample rate, which may be
217 * different to that requested.
218 */
219 if(!sineWaveTable.generate(realSampleRate, sineWaveFrequency)) {
220 return;
221 }
222#endif
223
224 // Pre-fill the buffers

Callers

nothing calls this directly

Calls 9

fillBuffersFunction · 0.85
printlnMethod · 0.80
i2s_driver_installFunction · 0.50
i2s_set_pinsFunction · 0.50
i2s_get_real_rateFunction · 0.50
i2s_startFunction · 0.50
generateMethod · 0.45
startMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected