diff --git a/_i2_s_config_e_s_p32_v1_8h_source.html b/_i2_s_config_e_s_p32_v1_8h_source.html index bfe15aa57..4970c4745 100644 --- a/_i2_s_config_e_s_p32_v1_8h_source.html +++ b/_i2_s_config_e_s_p32_v1_8h_source.html @@ -136,34 +136,36 @@
79  LOGI("bits per sample: %d", bits_per_sample);
80  LOGI("number of channels: %d", channels);
81  LOGI("signal_type: %s", i2s_signal_types[signal_type]);
-
82  if (signal_type==Digital){
-
83  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
-
84  }
-
85  if (use_apll) {
-
86  LOGI("use_apll: %s", use_apll ? "true" : "false");
-
87  }
-
88  // LOGI("buffer_count:%d",buffer_count);
-
89  // LOGI("buffer_size:%d",buffer_size);
-
90 
-
91  if (pin_mck!=-1)
-
92  LOGI("pin_mck: %d", pin_mck);
-
93  if (pin_bck!=-1)
-
94  LOGI("pin_bck: %d", pin_bck);
-
95  if (pin_ws!=-1)
-
96  LOGI("pin_ws: %d", pin_ws);
-
97  if (pin_data!=-1)
-
98  LOGI("pin_data: %d", pin_data);
-
99  if (pin_data_rx!=-1){
-
100  LOGI("pin_data_rx: %d", pin_data_rx);
-
101  }
-
102  }
-
103 
-
104 };
+
82  LOGI("buffer_count:%d", buffer_count);
+
83  LOGI("buffer_size:%d", buffer_size);
+
84  if (signal_type==Digital){
+
85  LOGI("i2s_format: %s", i2s_formats[i2s_format]);
+
86  }
+
87  if (use_apll) {
+
88  LOGI("use_apll: %s", use_apll ? "true" : "false");
+
89  }
+
90  // LOGI("buffer_count:%d",buffer_count);
+
91  // LOGI("buffer_size:%d",buffer_size);
+
92 
+
93  if (pin_mck!=-1)
+
94  LOGI("pin_mck: %d", pin_mck);
+
95  if (pin_bck!=-1)
+
96  LOGI("pin_bck: %d", pin_bck);
+
97  if (pin_ws!=-1)
+
98  LOGI("pin_ws: %d", pin_ws);
+
99  if (pin_data!=-1)
+
100  LOGI("pin_data: %d", pin_data);
+
101  if (pin_data_rx!=-1){
+
102  LOGI("pin_data_rx: %d", pin_data_rx);
+
103  }
+
104  }
105 
-
106 using I2SConfig = I2SConfigESP32V1;
+
106 };
107 
-
108 }
+
108 using I2SConfig = I2SConfigESP32V1;
109 
+
110 }
+
111 
audio_tools::I2SConfigESP32V1
Configuration for ESP32 i2s for IDF > 5.0.
Definition: I2SConfigESP32V1.h:20
audio_tools::I2SConfigESP32V1::buffer_count
int buffer_count
not used any more
Definition: I2SConfigESP32V1.h:64
audio_tools::I2SConfigESP32V1::rx_tx_mode
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigESP32V1.h:53
diff --git a/_i2_s_e_s_p32_v1_8h_source.html b/_i2_s_e_s_p32_v1_8h_source.html index 71dc944fa..df2267988 100644 --- a/_i2_s_e_s_p32_v1_8h_source.html +++ b/_i2_s_e_s_p32_v1_8h_source.html @@ -248,291 +248,298 @@
195 
196  i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
197  TRACED();
-
198  return I2S_CHANNEL_DEFAULT_CONFIG(
+
198  i2s_chan_config_t result = I2S_CHANNEL_DEFAULT_CONFIG(
199  (i2s_port_t)cfg.port_no,
200  cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
-
201  }
-
202 
-
203  i2s_std_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {
-
204  TRACED();
-
205  i2s_std_clk_config_t clk_cfg =
-
206  I2S_STD_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
-
207  if (cfg.mclk_multiple > 0){
-
208  clk_cfg.mclk_multiple = (i2s_mclk_multiple_t) cfg.mclk_multiple;
-
209  } else {
-
210  if (cfg.pin_mck !=-1 && cfg.bits_per_sample == 24) {
-
211  // mclk_multiple' should be the multiple of 3 while using 24-bit
-
212  clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
-
213  LOGI("mclk_multiple=384");
-
214  }
-
215  }
-
216  return clk_cfg;
-
217  }
-
218 
-
219  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
-
220  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
-
221  TRACED();
-
222  LOGI("tx: %d, rx: %d", txPin, rxPin);
-
223  i2s_std_config_t std_cfg = {
-
224  .clk_cfg = getClockConfig(cfg),
-
225  .slot_cfg = getSlotConfig(cfg),
-
226  .gpio_cfg =
-
227  {
-
228  .mclk = (gpio_num_t)cfg.pin_mck,
-
229  .bclk = (gpio_num_t)cfg.pin_bck,
-
230  .ws = (gpio_num_t)cfg.pin_ws,
-
231  .dout = (gpio_num_t)txPin,
-
232  .din = (gpio_num_t)rxPin,
-
233  .invert_flags =
-
234  {
-
235  .mclk_inv = false,
-
236  .bclk_inv = false,
-
237  .ws_inv = false,
-
238  },
-
239  },
-
240  };
-
241 
-
242  if (cfg.rx_tx_mode == RXTX_MODE || cfg.rx_tx_mode == TX_MODE) {
-
243  if (i2s_channel_init_std_mode(tx_chan, &std_cfg) != ESP_OK) {
-
244  LOGE("i2s_channel_init_std_mode %s", "tx");
-
245  return false;
-
246  }
-
247  if (i2s_channel_enable(tx_chan) != ESP_OK) {
-
248  LOGE("i2s_channel_enable %s", "tx");
-
249  return false;
-
250  }
-
251  }
-
252 
-
253  if (cfg.rx_tx_mode == RXTX_MODE || cfg.rx_tx_mode == RX_MODE) {
-
254  if (i2s_channel_init_std_mode(rx_chan, &std_cfg) != ESP_OK) {
-
255  LOGE("i2s_channel_init_std_mode %s", "rx");
-
256  return false;
-
257  }
-
258  if (i2s_channel_enable(rx_chan) != ESP_OK) {
-
259  LOGE("i2s_channel_enable %s", "rx");
-
260  return false;
-
261  }
-
262  }
-
263 
-
264  LOGD("%s - %s", __func__, "started");
-
265  return true;
-
266  }
-
267 
-
268  bool changeSampleRate(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
-
269  i2s_chan_handle_t &rx_chan) override {
-
270  bool rc = false;
-
271  auto clock_cfg = getClockConfig(cfg);
-
272  if (tx_chan != nullptr) {
-
273  i2s_channel_disable(tx_chan);
-
274  rc = i2s_channel_reconfig_std_clock(tx_chan, &clock_cfg) == ESP_OK;
-
275  i2s_channel_enable(tx_chan);
-
276  }
-
277  if (rx_chan != nullptr) {
-
278  i2s_channel_disable(rx_chan);
-
279  rc = i2s_channel_reconfig_std_clock(rx_chan, &clock_cfg) == ESP_OK;
-
280  i2s_channel_enable(rx_chan);
+
201  // use the legicy size parameters for frame num
+
202  int size = cfg.buffer_size * cfg.buffer_count;
+
203  int frame_size = cfg.bits_per_sample * cfg.channels / 8;
+
204  if (size > 0) result.dma_frame_num = size / frame_size;
+
205  return result;
+
206  }
+
207 
+
208  i2s_std_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {
+
209  TRACED();
+
210  i2s_std_clk_config_t clk_cfg =
+
211  I2S_STD_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
+
212  if (cfg.mclk_multiple > 0){
+
213  clk_cfg.mclk_multiple = (i2s_mclk_multiple_t) cfg.mclk_multiple;
+
214  } else {
+
215  if (cfg.pin_mck !=-1 && cfg.bits_per_sample == 24) {
+
216  // mclk_multiple' should be the multiple of 3 while using 24-bit
+
217  clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
+
218  LOGI("mclk_multiple=384");
+
219  }
+
220  }
+
221  return clk_cfg;
+
222  }
+
223 
+
224  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
+
225  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
+
226  TRACED();
+
227  LOGI("tx: %d, rx: %d", txPin, rxPin);
+
228  i2s_std_config_t std_cfg = {
+
229  .clk_cfg = getClockConfig(cfg),
+
230  .slot_cfg = getSlotConfig(cfg),
+
231  .gpio_cfg =
+
232  {
+
233  .mclk = (gpio_num_t)cfg.pin_mck,
+
234  .bclk = (gpio_num_t)cfg.pin_bck,
+
235  .ws = (gpio_num_t)cfg.pin_ws,
+
236  .dout = (gpio_num_t)txPin,
+
237  .din = (gpio_num_t)rxPin,
+
238  .invert_flags =
+
239  {
+
240  .mclk_inv = false,
+
241  .bclk_inv = false,
+
242  .ws_inv = false,
+
243  },
+
244  },
+
245  };
+
246 
+
247  if (cfg.rx_tx_mode == RXTX_MODE || cfg.rx_tx_mode == TX_MODE) {
+
248  if (i2s_channel_init_std_mode(tx_chan, &std_cfg) != ESP_OK) {
+
249  LOGE("i2s_channel_init_std_mode %s", "tx");
+
250  return false;
+
251  }
+
252  if (i2s_channel_enable(tx_chan) != ESP_OK) {
+
253  LOGE("i2s_channel_enable %s", "tx");
+
254  return false;
+
255  }
+
256  }
+
257 
+
258  if (cfg.rx_tx_mode == RXTX_MODE || cfg.rx_tx_mode == RX_MODE) {
+
259  if (i2s_channel_init_std_mode(rx_chan, &std_cfg) != ESP_OK) {
+
260  LOGE("i2s_channel_init_std_mode %s", "rx");
+
261  return false;
+
262  }
+
263  if (i2s_channel_enable(rx_chan) != ESP_OK) {
+
264  LOGE("i2s_channel_enable %s", "rx");
+
265  return false;
+
266  }
+
267  }
+
268 
+
269  LOGD("%s - %s", __func__, "started");
+
270  return true;
+
271  }
+
272 
+
273  bool changeSampleRate(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
+
274  i2s_chan_handle_t &rx_chan) override {
+
275  bool rc = false;
+
276  auto clock_cfg = getClockConfig(cfg);
+
277  if (tx_chan != nullptr) {
+
278  i2s_channel_disable(tx_chan);
+
279  rc = i2s_channel_reconfig_std_clock(tx_chan, &clock_cfg) == ESP_OK;
+
280  i2s_channel_enable(tx_chan);
281  }
-
282  return rc;
-
283  }
-
284 
-
285  } i2s;
-
286 
-
287 #ifdef USE_PDM
-
288 
-
289  struct DriverPDM : public DriverCommon {
-
290  i2s_pdm_tx_slot_config_t getTxSlotConfig(I2SConfigESP32V1 &cfg) {
-
291  return I2S_PDM_TX_SLOT_DEFAULT_CONFIG(
-
292  (i2s_data_bit_width_t)cfg.bits_per_sample,
-
293  (i2s_slot_mode_t)cfg.channels);
-
294  }
-
295 
-
296  i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
-
297  return I2S_CHANNEL_DEFAULT_CONFIG(
-
298  (i2s_port_t)cfg.port_no,
-
299  cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
-
300  }
-
301 
-
302  i2s_pdm_tx_clk_config_t getTxClockConfig(I2SConfigESP32V1 &cfg) {
-
303  return I2S_PDM_TX_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
-
304  }
-
305 
-
306  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
-
307  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
-
308  if (cfg.rx_tx_mode == TX_MODE) {
-
309  i2s_pdm_tx_config_t pdm_tx_cfg = {
-
310  .clk_cfg = getTxClockConfig(cfg),
-
311  .slot_cfg = getTxSlotConfig(cfg),
-
312  .gpio_cfg =
-
313  {
-
314  .clk = (gpio_num_t)cfg.pin_bck,
-
315  .dout = (gpio_num_t)txPin,
-
316  .invert_flags =
-
317  {
-
318  .clk_inv = false,
-
319  },
-
320  },
-
321  };
-
322 
-
323  if (i2s_channel_init_pdm_tx_mode(tx_chan, &pdm_tx_cfg) != ESP_OK) {
-
324  LOGE("i2s_channel_init_pdm_tx_mode %s", "tx");
-
325  return false;
-
326  }
-
327  if (i2s_channel_enable(tx_chan) != ESP_OK) {
-
328  LOGE("i2s_channel_enable %s", "tx");
-
329  return false;
-
330  }
-
331  } else {
-
332  LOGE("Only TX supported for PDM");
-
333  return false;
-
334  }
-
335  return true;
-
336  }
-
337  } pdm;
-
338 
-
339 #endif
-
340 
-
341 #ifdef USE_TDM
-
342  // example at
-
343  // https://github.com/espressif/esp-idf/blob/v5.3-dev/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c
-
344  struct DriverTDM : public DriverCommon {
-
345  i2s_tdm_slot_config_t getSlotConfig(I2SConfigESP32V1 &cfg) {
-
346  int slots = 0;
-
347  for (int j = 0; j < cfg.channels; j++) {
-
348  slots |= 1 << j;
-
349  }
-
350  return I2S_TDM_MSB_SLOT_DEFAULT_CONFIG(
-
351  (i2s_data_bit_width_t)cfg.bits_per_sample, I2S_SLOT_MODE_STEREO,
-
352  (i2s_tdm_slot_mask_t)slots);
-
353  }
-
354 
-
355  i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
-
356  return I2S_CHANNEL_DEFAULT_CONFIG(
-
357  (i2s_port_t)cfg.port_no,
-
358  cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
-
359  }
-
360 
-
361  i2s_tdm_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {
-
362  return I2S_TDM_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
-
363  }
-
364 
-
365  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
-
366  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
-
367  i2s_tdm_config_t tdm_cfg = {
-
368  .clk_cfg = getClockConfig(cfg),
-
369  .slot_cfg = getSlotConfig(cfg),
-
370  .gpio_cfg =
-
371  {
-
372  .mclk = (gpio_num_t)cfg.pin_mck,
-
373  .bclk = (gpio_num_t)cfg.pin_bck,
-
374  .ws = (gpio_num_t)cfg.pin_ws,
-
375  .dout = (gpio_num_t)txPin,
-
376  .din = (gpio_num_t)rxPin,
-
377  .invert_flags =
-
378  {
-
379  .mclk_inv = false,
-
380  .bclk_inv = false,
-
381  .ws_inv = false,
-
382  },
-
383  },
-
384  };
-
385 
-
386  if (cfg.rx_tx_mode == TX_MODE) {
-
387  if (i2s_channel_init_tdm_mode(tx_chan, &tdm_cfg) != ESP_OK) {
-
388  LOGE("i2s_channel_init_tdm_tx_mode %s", "tx");
-
389  return false;
-
390  }
-
391  }
-
392  if (cfg.rx_tx_mode == RX_MODE) {
-
393  if (i2s_channel_init_tdm_mode(rx_chan, &tdm_cfg) != ESP_OK) {
-
394  LOGE("i2s_channel_init_tdm_tx_mode %s", "rx");
-
395  return false;
-
396  }
-
397  return true;
-
398  }
-
399  return false;
-
400  }
-
401  } tdm;
-
402 
-
403 #endif
-
404 
-
406 
-
408  bool begin(I2SConfigESP32V1 cfg, int txPin, int rxPin) {
-
409  TRACED();
-
410  cfg.logInfo();
-
411  this->cfg = cfg;
-
412  if (cfg.channels <= 0 || cfg.channels > 2) {
-
413  LOGE("invalid channels: %d", cfg.channels);
-
414  return false;
-
415  }
-
416 
-
417  DriverCommon &driver = getDriver(cfg);
-
418  if (!newChannels(cfg, driver)) {
-
419  end();
-
420  return false;
-
421  }
-
422 
-
423  is_started = driver.startChannels(cfg, tx_chan, rx_chan, txPin, rxPin);
-
424  if (!is_started) {
-
425  end();
-
426  LOGE("Channels not started");
-
427  }
-
428  return is_started;
-
429  }
-
430 
-
431  bool newChannels(I2SConfigESP32V1 &cfg, DriverCommon &driver) {
-
432  i2s_chan_config_t chan_cfg = driver.getChannelConfig(cfg);
-
433  switch (cfg.rx_tx_mode) {
-
434  case RX_MODE:
-
435  if (i2s_new_channel(&chan_cfg, NULL, &rx_chan) != ESP_OK) {
-
436  LOGE("i2s_channel");
-
437  return false;
-
438  }
-
439  break;
-
440  case TX_MODE:
-
441  if (i2s_new_channel(&chan_cfg, &tx_chan, NULL) != ESP_OK) {
-
442  LOGE("i2s_channel");
-
443  return false;
-
444  }
-
445  break;
-
446  default:
-
447  if (i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan) != ESP_OK) {
-
448  LOGE("i2s_channel");
-
449  return false;
-
450  }
-
451  }
-
452  return true;
-
453  }
-
454 
-
455  DriverCommon &getDriver(I2SConfigESP32V1 &cfg) {
-
456  switch (cfg.signal_type) {
-
457  case Digital:
-
458  return i2s;
-
459 #ifdef USE_PDM
-
460  case Analog:
-
461  case PDM:
-
462  return pdm;
-
463 #endif
-
464 #ifdef USE_TDM
-
465  case TDM:
-
466  return tdm;
-
467 #endif
-
468  default:
-
469  break;
-
470  }
-
471  LOGE("Unsupported singal_type");
-
472  return i2s;
-
473  }
-
474 };
-
475 
-
476 using I2SDriver = I2SDriverESP32V1;
-
477 
-
478 } // namespace audio_tools
-
479 
-
480 #endif
+
282  if (rx_chan != nullptr) {
+
283  i2s_channel_disable(rx_chan);
+
284  rc = i2s_channel_reconfig_std_clock(rx_chan, &clock_cfg) == ESP_OK;
+
285  i2s_channel_enable(rx_chan);
+
286  }
+
287  return rc;
+
288  }
+
289 
+
290  } i2s;
+
291 
+
292 #ifdef USE_PDM
+
293 
+
294  struct DriverPDM : public DriverCommon {
+
295  i2s_pdm_tx_slot_config_t getTxSlotConfig(I2SConfigESP32V1 &cfg) {
+
296  return I2S_PDM_TX_SLOT_DEFAULT_CONFIG(
+
297  (i2s_data_bit_width_t)cfg.bits_per_sample,
+
298  (i2s_slot_mode_t)cfg.channels);
+
299  }
+
300 
+
301  i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
+
302  return I2S_CHANNEL_DEFAULT_CONFIG(
+
303  (i2s_port_t)cfg.port_no,
+
304  cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
+
305  }
+
306 
+
307  i2s_pdm_tx_clk_config_t getTxClockConfig(I2SConfigESP32V1 &cfg) {
+
308  return I2S_PDM_TX_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
+
309  }
+
310 
+
311  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
+
312  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
+
313  if (cfg.rx_tx_mode == TX_MODE) {
+
314  i2s_pdm_tx_config_t pdm_tx_cfg = {
+
315  .clk_cfg = getTxClockConfig(cfg),
+
316  .slot_cfg = getTxSlotConfig(cfg),
+
317  .gpio_cfg =
+
318  {
+
319  .clk = (gpio_num_t)cfg.pin_bck,
+
320  .dout = (gpio_num_t)txPin,
+
321  .invert_flags =
+
322  {
+
323  .clk_inv = false,
+
324  },
+
325  },
+
326  };
+
327 
+
328  if (i2s_channel_init_pdm_tx_mode(tx_chan, &pdm_tx_cfg) != ESP_OK) {
+
329  LOGE("i2s_channel_init_pdm_tx_mode %s", "tx");
+
330  return false;
+
331  }
+
332  if (i2s_channel_enable(tx_chan) != ESP_OK) {
+
333  LOGE("i2s_channel_enable %s", "tx");
+
334  return false;
+
335  }
+
336  } else {
+
337  LOGE("Only TX supported for PDM");
+
338  return false;
+
339  }
+
340  return true;
+
341  }
+
342  } pdm;
+
343 
+
344 #endif
+
345 
+
346 #ifdef USE_TDM
+
347  // example at
+
348  // https://github.com/espressif/esp-idf/blob/v5.3-dev/examples/peripherals/i2s/i2s_basic/i2s_tdm/main/i2s_tdm_example_main.c
+
349  struct DriverTDM : public DriverCommon {
+
350  i2s_tdm_slot_config_t getSlotConfig(I2SConfigESP32V1 &cfg) {
+
351  int slots = 0;
+
352  for (int j = 0; j < cfg.channels; j++) {
+
353  slots |= 1 << j;
+
354  }
+
355  return I2S_TDM_MSB_SLOT_DEFAULT_CONFIG(
+
356  (i2s_data_bit_width_t)cfg.bits_per_sample, I2S_SLOT_MODE_STEREO,
+
357  (i2s_tdm_slot_mask_t)slots);
+
358  }
+
359 
+
360  i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
+
361  return I2S_CHANNEL_DEFAULT_CONFIG(
+
362  (i2s_port_t)cfg.port_no,
+
363  cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
+
364  }
+
365 
+
366  i2s_tdm_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {
+
367  return I2S_TDM_CLK_DEFAULT_CONFIG((uint32_t)cfg.sample_rate);
+
368  }
+
369 
+
370  bool startChannels(I2SConfigESP32V1 &cfg, i2s_chan_handle_t &tx_chan,
+
371  i2s_chan_handle_t &rx_chan, int txPin, int rxPin) {
+
372  i2s_tdm_config_t tdm_cfg = {
+
373  .clk_cfg = getClockConfig(cfg),
+
374  .slot_cfg = getSlotConfig(cfg),
+
375  .gpio_cfg =
+
376  {
+
377  .mclk = (gpio_num_t)cfg.pin_mck,
+
378  .bclk = (gpio_num_t)cfg.pin_bck,
+
379  .ws = (gpio_num_t)cfg.pin_ws,
+
380  .dout = (gpio_num_t)txPin,
+
381  .din = (gpio_num_t)rxPin,
+
382  .invert_flags =
+
383  {
+
384  .mclk_inv = false,
+
385  .bclk_inv = false,
+
386  .ws_inv = false,
+
387  },
+
388  },
+
389  };
+
390 
+
391  if (cfg.rx_tx_mode == TX_MODE) {
+
392  if (i2s_channel_init_tdm_mode(tx_chan, &tdm_cfg) != ESP_OK) {
+
393  LOGE("i2s_channel_init_tdm_tx_mode %s", "tx");
+
394  return false;
+
395  }
+
396  }
+
397  if (cfg.rx_tx_mode == RX_MODE) {
+
398  if (i2s_channel_init_tdm_mode(rx_chan, &tdm_cfg) != ESP_OK) {
+
399  LOGE("i2s_channel_init_tdm_tx_mode %s", "rx");
+
400  return false;
+
401  }
+
402  return true;
+
403  }
+
404  return false;
+
405  }
+
406  } tdm;
+
407 
+
408 #endif
+
409 
+
411 
+
413  bool begin(I2SConfigESP32V1 cfg, int txPin, int rxPin) {
+
414  TRACED();
+
415  cfg.logInfo();
+
416  this->cfg = cfg;
+
417  if (cfg.channels <= 0 || cfg.channels > 2) {
+
418  LOGE("invalid channels: %d", cfg.channels);
+
419  return false;
+
420  }
+
421 
+
422  DriverCommon &driver = getDriver(cfg);
+
423  if (!newChannels(cfg, driver)) {
+
424  end();
+
425  return false;
+
426  }
+
427 
+
428  is_started = driver.startChannels(cfg, tx_chan, rx_chan, txPin, rxPin);
+
429  if (!is_started) {
+
430  end();
+
431  LOGE("Channels not started");
+
432  }
+
433  return is_started;
+
434  }
+
435 
+
436  bool newChannels(I2SConfigESP32V1 &cfg, DriverCommon &driver) {
+
437  i2s_chan_config_t chan_cfg = driver.getChannelConfig(cfg);
+
438  switch (cfg.rx_tx_mode) {
+
439  case RX_MODE:
+
440  if (i2s_new_channel(&chan_cfg, NULL, &rx_chan) != ESP_OK) {
+
441  LOGE("i2s_channel");
+
442  return false;
+
443  }
+
444  break;
+
445  case TX_MODE:
+
446  if (i2s_new_channel(&chan_cfg, &tx_chan, NULL) != ESP_OK) {
+
447  LOGE("i2s_channel");
+
448  return false;
+
449  }
+
450  break;
+
451  default:
+
452  if (i2s_new_channel(&chan_cfg, &tx_chan, &rx_chan) != ESP_OK) {
+
453  LOGE("i2s_channel");
+
454  return false;
+
455  }
+
456  }
+
457  return true;
+
458  }
+
459 
+
460  DriverCommon &getDriver(I2SConfigESP32V1 &cfg) {
+
461  switch (cfg.signal_type) {
+
462  case Digital:
+
463  return i2s;
+
464 #ifdef USE_PDM
+
465  case Analog:
+
466  case PDM:
+
467  return pdm;
+
468 #endif
+
469 #ifdef USE_TDM
+
470  case TDM:
+
471  return tdm;
+
472 #endif
+
473  default:
+
474  break;
+
475  }
+
476  LOGE("Unsupported singal_type");
+
477  return i2s;
+
478  }
+
479 };
+
480 
+
481 using I2SDriver = I2SDriverESP32V1;
+
482 
+
483 } // namespace audio_tools
+
484 
+
485 #endif
audio_tools::I2SConfigESP32V1
Configuration for ESP32 i2s for IDF > 5.0.
Definition: I2SConfigESP32V1.h:20
+
audio_tools::I2SConfigESP32V1::buffer_count
int buffer_count
not used any more
Definition: I2SConfigESP32V1.h:64
audio_tools::I2SConfigESP32V1::rx_tx_mode
RxTxMode rx_tx_mode
public settings
Definition: I2SConfigESP32V1.h:53
audio_tools::I2SConfigESP32V1::mclk_multiple
int mclk_multiple
masterclock multiple (-1 = use default)
Definition: I2SConfigESP32V1.h:71
audio_tools::I2SConfigESP32V1::channel_format
I2SChannelSelect channel_format
Select left or right channel when channels == 1.
Definition: I2SConfigESP32V1.h:69
+
audio_tools::I2SConfigESP32V1::buffer_size
int buffer_size
not used any more
Definition: I2SConfigESP32V1.h:66
audio_tools::I2SDriverESP32V1
Basic I2S API for the ESP32 (using the new API). https://docs.espressif.com/projects/esp-idf/en/v5....
Definition: I2SESP32V1.h:26
audio_tools::I2SDriverESP32V1::defaultConfig
I2SConfigESP32V1 defaultConfig(RxTxMode mode)
Provides the default configuration.
Definition: I2SESP32V1.h:29
audio_tools::I2SDriverESP32V1::begin
bool begin(I2SConfigESP32V1 cfg)
starts the DAC
Definition: I2SESP32V1.h:57
@@ -543,7 +550,7 @@
audio_tools::I2SDriverESP32V1::config
I2SConfigESP32V1 config()
provides the actual configuration
Definition: I2SESP32V1.h:103
audio_tools::I2SDriverESP32V1::end
void end()
stops the I2C and unistalls the driver
Definition: I2SESP32V1.h:86
audio_tools::I2SDriverESP32V1::begin
bool begin(RxTxMode mode)
starts the DAC with the default config
Definition: I2SESP32V1.h:50
-
audio_tools::I2SDriverESP32V1::begin
bool begin(I2SConfigESP32V1 cfg, int txPin, int rxPin)
-> protected methods from I2SDriverESP32V1
Definition: I2SESP32V1.h:408
+
audio_tools::I2SDriverESP32V1::begin
bool begin(I2SConfigESP32V1 cfg, int txPin, int rxPin)
-> protected methods from I2SDriverESP32V1
Definition: I2SESP32V1.h:413
audio_tools::I2SDriverESP32V1::writeBytes
size_t writeBytes(const void *src, size_t size_bytes)
writes the data to the I2S interface
Definition: I2SESP32V1.h:106
audio_tools::RxTxMode
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:26
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AnalogAudioArduino.h:12