@@ -600,6 +600,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
600
600
601
601
return size ;
602
602
} else { // blocking or asyncio mode
603
+
603
604
mp_buffer_info_t appbuf ;
604
605
appbuf .buf = (void * )buf_in ;
605
606
appbuf .len = size ;
@@ -608,6 +609,7 @@ STATIC mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
608
609
#else
609
610
uint32_t num_bytes_written = copy_appbuf_to_dma (self , & appbuf );
610
611
#endif
612
+
611
613
return num_bytes_written ;
612
614
}
613
615
}
@@ -623,6 +625,7 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
623
625
624
626
if (flags & MP_STREAM_POLL_RD ) {
625
627
if (self -> mode != MICROPY_PY_MACHINE_I2S_CONSTANT_RX ) {
628
+
626
629
* errcode = MP_EPERM ;
627
630
return MP_STREAM_ERROR ;
628
631
}
@@ -632,21 +635,14 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
632
635
ret |= MP_STREAM_POLL_RD ;
633
636
}
634
637
#else
635
- // check event queue to determine if a DMA buffer has been filled
636
- // (which is an indication that at least one DMA buffer is available to be read)
637
- // note: timeout = 0 so the call is non-blocking
638
- i2s_event_t i2s_event ;
639
- if (xQueueReceive (self -> i2s_event_queue , & i2s_event , 0 )) {
640
- if (i2s_event .type == I2S_EVENT_RX_DONE ) {
641
- // getting here means that at least one DMA buffer is now full
642
- // indicating that audio samples can be read from the I2S object
643
- ret |= MP_STREAM_POLL_RD ;
644
- }
638
+ if (self -> dma_buffer_status == DMA_MEMORY_NOT_EMPTY ) {
639
+ ret |= MP_STREAM_POLL_RD ;
645
640
}
646
641
#endif
647
642
}
648
643
649
644
if (flags & MP_STREAM_POLL_WR ) {
645
+
650
646
if (self -> mode != MICROPY_PY_MACHINE_I2S_CONSTANT_TX ) {
651
647
* errcode = MP_EPERM ;
652
648
return MP_STREAM_ERROR ;
@@ -657,20 +653,14 @@ STATIC mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
657
653
ret |= MP_STREAM_POLL_WR ;
658
654
}
659
655
#else
660
- // check event queue to determine if a DMA buffer has been emptied
661
- // (which is an indication that at least one DMA buffer is available to be written)
662
- // note: timeout = 0 so the call is non-blocking
663
- i2s_event_t i2s_event ;
664
- if (xQueueReceive (self -> i2s_event_queue , & i2s_event , 0 )) {
665
- if (i2s_event .type == I2S_EVENT_TX_DONE ) {
666
- // getting here means that at least one DMA buffer is now empty
667
- // indicating that audio samples can be written to the I2S object
668
- ret |= MP_STREAM_POLL_WR ;
669
- }
656
+
657
+ if (self -> dma_buffer_status == DMA_MEMORY_NOT_FULL ) {
658
+ ret |= MP_STREAM_POLL_WR ;
670
659
}
671
660
#endif
672
661
}
673
662
} else {
663
+
674
664
* errcode = MP_EINVAL ;
675
665
ret = MP_STREAM_ERROR ;
676
666
}
0 commit comments