@@ -291,21 +291,15 @@ static int IRAM_ATTR i2s_out_start() {
291
291
292
292
// Attach I2S to specified GPIO pin
293
293
i2s_out_gpio_attach (i2s_out_ws_pin, i2s_out_bck_pin, i2s_out_data_pin);
294
- // start DMA link
295
- i2s_out_reset_fifo_without_lock ();
296
294
297
- # ifdef USE_I2S_OUT_STREAM_IMPL
298
- if (i2s_out_pulser_status == PASSTHROUGH) {
299
- I2S0.conf_chan .tx_chan_mod = 3 ; // 3:right+constant 4:left+constant (when tx_msb_right = 1)
300
- I2S0.conf_single_data = port_data;
301
- } else {
302
- I2S0.conf_chan .tx_chan_mod = 4 ; // 3:right+constant 4:left+constant (when tx_msb_right = 1)
303
- I2S0.conf_single_data = 0 ;
304
- }
305
- # endif
295
+ // reest TX/RX module
296
+ I2S0.conf .tx_reset = 1 ;
297
+ I2S0.conf .tx_reset = 0 ;
298
+ I2S0.conf .rx_reset = 1 ;
299
+ I2S0.conf .rx_reset = 0 ;
306
300
307
301
# ifdef USE_I2S_OUT_STREAM_IMPL
308
- // reset DMA
302
+ // reset DMA
309
303
I2S0.lc_conf .in_rst = 1 ;
310
304
I2S0.lc_conf .in_rst = 0 ;
311
305
I2S0.lc_conf .out_rst = 1 ;
@@ -314,10 +308,19 @@ static int IRAM_ATTR i2s_out_start() {
314
308
I2S0.out_link .addr = (uint32_t )o_dma.desc [0 ];
315
309
# endif
316
310
317
- I2S0.conf .tx_reset = 1 ;
318
- I2S0.conf .tx_reset = 0 ;
319
- I2S0.conf .rx_reset = 1 ;
320
- I2S0.conf .rx_reset = 0 ;
311
+ // reset FIFO
312
+ i2s_out_reset_fifo_without_lock ();
313
+
314
+ // start DMA link
315
+ # ifdef USE_I2S_OUT_STREAM_IMPL
316
+ if (i2s_out_pulser_status == PASSTHROUGH) {
317
+ I2S0.conf_chan .tx_chan_mod = 3 ; // 3:right+constant 4:left+constant (when tx_msb_right = 1)
318
+ I2S0.conf_single_data = port_data;
319
+ } else {
320
+ I2S0.conf_chan .tx_chan_mod = 4 ; // 3:right+constant 4:left+constant (when tx_msb_right = 1)
321
+ I2S0.conf_single_data = 0 ;
322
+ }
323
+ # endif
321
324
322
325
I2S0.conf1 .tx_stop_en = 1 ; // BCK and WCK are suppressed while FIFO is empty
323
326
@@ -339,13 +342,14 @@ static int IRAM_ATTR i2s_out_start() {
339
342
}
340
343
341
344
# ifdef USE_I2S_OUT_STREAM_IMPL
342
-
345
+ // Fill out one DMA buffer
346
+ // Call with the I2S_OUT_PULSER lock acquired.
347
+ // Note that the lock is temporarily released while calling the callback function.
343
348
static int IRAM_ATTR i2s_fillout_dma_buffer (lldesc_t * dma_desc) {
344
349
uint32_t * buf = (uint32_t *)dma_desc->buf ;
345
350
o_dma.rw_pos = 0 ;
346
351
// It reuses the oldest (just transferred) buffer with the name "current"
347
352
// and fills the buffer for later DMA.
348
- I2S_OUT_PULSER_ENTER_CRITICAL (); // Lock pulser status
349
353
if (i2s_out_pulser_status == STEPPING) {
350
354
//
351
355
// Fillout the buffer for pulse
@@ -408,7 +412,6 @@ static int IRAM_ATTR i2s_fillout_dma_buffer(lldesc_t* dma_desc) {
408
412
o_dma.rw_pos = 0 ; // If someone calls i2s_out_push_sample, make sure there is no buffer overflow
409
413
i2s_out_remain_time_until_next_pulse = 0 ;
410
414
}
411
- I2S_OUT_PULSER_EXIT_CRITICAL (); // Unlock pulser status
412
415
413
416
return 0 ;
414
417
}
@@ -591,10 +594,18 @@ i2s_out_pulser_status_t IRAM_ATTR i2s_out_get_pulser_status() {
591
594
int IRAM_ATTR i2s_out_set_passthrough () {
592
595
I2S_OUT_PULSER_ENTER_CRITICAL ();
593
596
# ifdef USE_I2S_OUT_STREAM_IMPL
597
+ // Triggers a change of mode if it is compiled to use I2S stream.
598
+ // The mode is not changed directly by this function.
599
+ // Pull the trigger
594
600
if (i2s_out_pulser_status == STEPPING) {
595
- i2s_out_pulser_status = WAITING; // Start stopping the pulser
601
+ i2s_out_pulser_status = WAITING; // Start stopping the pulser (trigger)
596
602
}
603
+ // It is a function that may be called via i2sOutTask().
604
+ // (i2sOutTask() -> stepper_pulse_func() -> st_go_idle() -> Stepper_Timer_Stop() -> this function)
605
+ // And only i2sOutTask() can change the state to PASSTHROUGH.
606
+ // So, to change the state, you need to return to i2sOutTask() as soon as possible.
597
607
# else
608
+ // If it is compiled to not use I2S streams, change the mode directly.
598
609
i2s_out_pulser_status = PASSTHROUGH;
599
610
# endif
600
611
I2S_OUT_PULSER_EXIT_CRITICAL ();
@@ -627,6 +638,7 @@ int IRAM_ATTR i2s_out_set_stepping() {
627
638
I2S_OUT_PULSER_EXIT_CRITICAL ();
628
639
return 0 ;
629
640
}
641
+ // Now, DMA completed. Fallthrough.
630
642
}
631
643
632
644
// Change I2S state from PASSTHROUGH to STEPPING
@@ -772,7 +784,6 @@ int IRAM_ATTR i2s_out_init(i2s_out_init_t& init_param) {
772
784
//
773
785
774
786
// configure I2S data port interface.
775
- i2s_out_reset_fifo ();
776
787
777
788
// reset i2s
778
789
I2S0.conf .tx_reset = 1 ;
@@ -786,6 +797,8 @@ int IRAM_ATTR i2s_out_init(i2s_out_init_t& init_param) {
786
797
I2S0.lc_conf .out_rst = 1 ; // Set this bit to reset out DMA FSM. (R/W)
787
798
I2S0.lc_conf .out_rst = 0 ;
788
799
800
+ i2s_out_reset_fifo_without_lock ();
801
+
789
802
// Enable and configure DMA
790
803
I2S0.lc_conf .check_owner = 0 ;
791
804
I2S0.lc_conf .out_loop_test = 0 ;
0 commit comments