Skip to content

Commit 989fb82

Browse files
committed
Revamp background writing
Now a 'once' and a 'loop' buffer can be specified. 'once' is useful for things like writing a neopixel strip in the background, if you can guarantee the buffer contents are stable until the write is complete. 'loop' is useful for periodic things, like pwm & servos. both together are useful for some special cases of pwm/servo, where a transitional waveform needs to be played for one repetition and then a new waveform needs to be played after that. The API is renamed to reflect that it's a more generic 'background' operation.
1 parent 457aba7 commit 989fb82

File tree

7 files changed

+179
-81
lines changed

7 files changed

+179
-81
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,11 @@ msgstr ""
15301530
msgid "Microphone startup delay must be in range 0.0 to 1.0"
15311531
msgstr ""
15321532

1533+
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
1534+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1535+
msgid "Mismatched data size"
1536+
msgstr ""
1537+
15331538
#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/stm/common-hal/busio/SPI.c
15341539
msgid "Missing MISO or MOSI Pin"
15351540
msgstr ""
@@ -3019,7 +3024,7 @@ msgstr ""
30193024
msgid "complex values not supported"
30203025
msgstr ""
30213026

3022-
#: extmod/moduzlib.c shared-module/zlib/DecompIO.c
3027+
#: extmod/moduzlib.c
30233028
msgid "compression header"
30243029
msgstr ""
30253030

ports/raspberrypi/audio_dma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ void isr_dma_0(void) {
459459
dma->channels_to_load_mask |= mask;
460460
background_callback_add(&dma->callback, dma_callback_fun, (void *)dma);
461461
}
462-
if (MP_STATE_PORT(continuous_pio)[i] != NULL) {
463-
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(continuous_pio)[i];
462+
if (MP_STATE_PORT(background_pio)[i] != NULL) {
463+
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(background_pio)[i];
464464
rp2pio_statemachine_dma_complete(pio, i);
465465
}
466466
}

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 97 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -426,63 +426,79 @@ STATIC mp_obj_t rp2pio_statemachine_write(size_t n_args, const mp_obj_t *pos_arg
426426
}
427427
MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_write_obj, 2, rp2pio_statemachine_write);
428428

429-
//| def start_continuous_write(self, buffer: Optional[ReadableBuffer], *, start: int = 0, end: Optional[int] = None) -> None:
430-
//| """Write the data contained in ``buffer`` to the state machine repeatedly until stopped. If the buffer is empty or None, an existing continuous_write is canceled.
429+
//| def background_write(self, once: Optional[ReadableBuffer]=None, *, loop=Optional[ReadableBuffer]=None) -> None:
430+
//| """Write data to the TX fifo in the background, with optional looping.
431+
//|
432+
//| First, if any previous ``once`` or ``loop`` buffer has not been started, this function blocks until they have.
433+
//| This means that any ``once`` or ``loop`` buffer will be written at least once.
434+
//| Then the ``once`` and/or ``loop`` buffers are queued. and the function returns.
435+
//| The ``once`` buffer (if specified) will be written just once.
436+
//| Finally, the ``loop`` buffer (if specified) will continue being looped indefinitely.
431437
//|
432438
//| Writes to the FIFO will match the input buffer's element size. For example, bytearray elements
433439
//| will perform 8 bit writes to the PIO FIFO. The RP2040's memory bus will duplicate the value into
434440
//| the other byte positions. So, pulling more data in the PIO assembly will read the duplicated values.
435441
//|
436442
//| To perform 16 or 32 bits writes into the FIFO use an `array.array` with a type code of the desired
437-
//| size, or use `memoryview.cast` to change the interpretation of an existing buffer.
438-
//|
439-
//| To atomically change from one buffer to another, simply call
440-
//| `StateMachine.start_continuous_write` again with a different buffer with the same element size.
441-
//| The call will only return once DMA has started putting the previous
442-
//| buffer's data into the PIO FIFO.
443+
//| size, or use `memoryview.cast` to change the interpretation of an
444+
//| existing buffer. To send just part of a larger buffer, slice a `memoryview`
445+
//| of it.
443446
//|
444-
//| If the buffer is modified while it is being written out, the updated
447+
//| If a buffer is modified while it is being written out, the updated
445448
//| values will be used. However, because of interactions between CPU
446449
//| writes, DMA and the PIO FIFO are complex, it is difficult to predict
447450
//| the result of modifying multiple values. Instead, alternate between
448451
//| a pair of buffers.
449452
//|
450-
//| :param ~circuitpython_typing.ReadableBuffer buffer: Write out the data in this buffer
451-
//| :param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]``
452-
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``"""
453+
//| Having both a ``once`` and a ``loop`` parameter is to support a special case in PWM generation
454+
//| where a change in duty cycle requires a special transitional buffer to be used exactly once. Most
455+
//| use cases will probably only use one of ``once`` or ``loop``.
456+
//|
457+
//| :param ~Optional[circuitpython_typing.ReadableBuffer] once: Data to be written once
458+
//| :param ~Optional[circuitpython_typing.ReadableBuffer] loop: Data to be written repeatedly
459+
//| """
453460
//| ...
454461
//|
455-
STATIC mp_obj_t rp2pio_statemachine_start_continuous_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
456-
enum { ARG_buffer, ARG_start, ARG_end };
462+
463+
STATIC void fill_buf_info(sm_buf_info *info, mp_obj_t obj, size_t *stride_in_bytes) {
464+
if (obj != mp_const_none) {
465+
info->obj = obj;
466+
mp_get_buffer_raise(obj, &info->info, MP_BUFFER_READ);
467+
size_t stride = mp_binary_get_size('@', info->info.typecode, NULL);
468+
if (stride > 4) {
469+
mp_raise_ValueError(translate("Buffer elements must be 4 bytes long or less"));
470+
}
471+
if (*stride_in_bytes && stride != *stride_in_bytes) {
472+
mp_raise_ValueError(translate("Mismatched data size"));
473+
}
474+
*stride_in_bytes = stride;
475+
} else {
476+
memset(info, 0, sizeof(*info));
477+
}
478+
}
479+
480+
STATIC mp_obj_t rp2pio_statemachine_background_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
481+
enum { ARG_once, ARG_loop };
457482
static const mp_arg_t allowed_args[] = {
458-
{ MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
459-
{ MP_QSTR_start, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
460-
{ MP_QSTR_end, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = INT_MAX} },
483+
{ MP_QSTR_once, MP_ARG_OBJ, {.u_obj = mp_const_none} },
484+
{ MP_QSTR_loop, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
461485
};
462486
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
463487
check_for_deinit(self);
464488
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
465489
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
466490

467-
mp_buffer_info_t bufinfo = {};
468-
if (args[ARG_buffer].u_obj != mp_const_none) {
469-
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
491+
sm_buf_info once_info;
492+
sm_buf_info loop_info;
493+
size_t stride_in_bytes = 0;
494+
fill_buf_info(&once_info, args[ARG_once].u_obj, &stride_in_bytes);
495+
fill_buf_info(&loop_info, args[ARG_loop].u_obj, &stride_in_bytes);
496+
if (!stride_in_bytes) {
497+
return mp_const_none;
470498
}
471-
int32_t start = args[ARG_start].u_int;
472-
size_t length = bufinfo.len;
473-
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
474-
bool ok = true;
475-
if (length == 0) {
476-
ok = common_hal_rp2pio_statemachine_end_continuous_write(self);
477-
} else {
478-
uint8_t *original_pointer = bufinfo.buf;
479-
int stride_in_bytes = mp_binary_get_size('@', bufinfo.typecode, NULL);
480-
if (stride_in_bytes > 4) {
481-
mp_raise_ValueError(translate("Buffer elements must be 4 bytes long or less"));
482-
}
483499

484-
ok = common_hal_rp2pio_statemachine_start_continuous_write(self, args[ARG_buffer].u_obj, ((uint8_t *)bufinfo.buf) + start, length, stride_in_bytes);
485-
}
500+
bool ok = common_hal_rp2pio_statemachine_background_write(self, &once_info, &loop_info, stride_in_bytes);
501+
486502
if (mp_hal_is_interrupted()) {
487503
return mp_const_none;
488504
}
@@ -491,14 +507,14 @@ STATIC mp_obj_t rp2pio_statemachine_start_continuous_write(size_t n_args, const
491507
}
492508
return mp_const_none;
493509
}
494-
MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_start_continuous_write_obj, 2, rp2pio_statemachine_start_continuous_write);
510+
MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_background_write_obj, 1, rp2pio_statemachine_background_write);
495511

496-
//| def end_continuous_write(self) -> None:
497-
//| """Stop a continuous write, if one is in progress."""
512+
//| def stop_background_write(self) -> None:
513+
//| """Immediately stop a background write, if one is in progress. Items already in the TX FIFO are not affected."""
498514
//|
499-
STATIC mp_obj_t rp2pio_statemachine_obj_end_continuous_write(mp_obj_t self_in) {
515+
STATIC mp_obj_t rp2pio_statemachine_obj_stop_background_write(mp_obj_t self_in) {
500516
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
501-
bool ok = common_hal_rp2pio_statemachine_end_continuous_write(self);
517+
bool ok = common_hal_rp2pio_statemachine_stop_background_write(self);
502518
if (mp_hal_is_interrupted()) {
503519
return mp_const_none;
504520
}
@@ -507,8 +523,45 @@ STATIC mp_obj_t rp2pio_statemachine_obj_end_continuous_write(mp_obj_t self_in) {
507523
}
508524
return mp_const_none;
509525
}
526+
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_stop_background_write_obj, rp2pio_statemachine_obj_stop_background_write);
527+
528+
//| @property
529+
//| def writing(self) -> bool:
530+
//| """Returns True if a background write is in progress"""
531+
//|
532+
STATIC mp_obj_t rp2pio_statemachine_obj_get_writing(mp_obj_t self_in) {
533+
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
534+
return mp_obj_new_bool(common_hal_rp2pio_statemachine_get_writing(self));
535+
}
536+
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_writing_obj, rp2pio_statemachine_obj_get_writing);
537+
538+
const mp_obj_property_t rp2pio_statemachine_writing_obj = {
539+
.base.type = &mp_type_property,
540+
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_writing_obj,
541+
MP_ROM_NONE,
542+
MP_ROM_NONE},
543+
};
544+
545+
546+
//| @property
547+
//| def pending(self) -> int:
548+
//| """Returns the number of pending buffers for background writing.
549+
//|
550+
//| If the number is 0, then a `StateMachine.background_write` call will not block."""
551+
//|
552+
STATIC mp_obj_t rp2pio_statemachine_obj_get_pending(mp_obj_t self_in) {
553+
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
554+
return mp_obj_new_int(common_hal_rp2pio_statemachine_get_pending(self));
555+
}
556+
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_pending_obj, rp2pio_statemachine_obj_get_pending);
557+
558+
const mp_obj_property_t rp2pio_statemachine_pending_obj = {
559+
.base.type = &mp_type_property,
560+
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_pending_obj,
561+
MP_ROM_NONE,
562+
MP_ROM_NONE},
563+
};
510564

511-
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_end_continuous_write_obj, rp2pio_statemachine_obj_end_continuous_write);
512565
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
513566
//| """Read into ``buffer``. If the number of bytes to read is 0, nothing happens. The buffer
514567
//| includes any data added to the fifo even if it was added before this was called.
@@ -728,8 +781,10 @@ STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
728781
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&rp2pio_statemachine_readinto_obj) },
729782
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&rp2pio_statemachine_write_obj) },
730783
{ MP_ROM_QSTR(MP_QSTR_write_readinto), MP_ROM_PTR(&rp2pio_statemachine_write_readinto_obj) },
731-
{ MP_ROM_QSTR(MP_QSTR_start_continuous_write), MP_ROM_PTR(&rp2pio_statemachine_start_continuous_write_obj) },
732-
{ MP_ROM_QSTR(MP_QSTR_end_continuous_write), MP_ROM_PTR(&rp2pio_statemachine_end_continuous_write_obj) },
784+
{ MP_ROM_QSTR(MP_QSTR_background_write), MP_ROM_PTR(&rp2pio_statemachine_background_write_obj) },
785+
{ MP_ROM_QSTR(MP_QSTR_stop_background_write), MP_ROM_PTR(&rp2pio_statemachine_stop_background_write_obj) },
786+
{ MP_ROM_QSTR(MP_QSTR_writing), MP_ROM_PTR(&rp2pio_statemachine_writing_obj) },
787+
{ MP_ROM_QSTR(MP_QSTR_pending), MP_ROM_PTR(&rp2pio_statemachine_pending_obj) },
733788

734789
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&rp2pio_statemachine_frequency_obj) },
735790
{ MP_ROM_QSTR(MP_QSTR_rxstall), MP_ROM_PTR(&rp2pio_statemachine_rxstall_obj) },

ports/raspberrypi/bindings/rp2pio/StateMachine.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ void common_hal_rp2pio_statemachine_run(rp2pio_statemachine_obj_t *self, const u
6565

6666
// Writes out the given data.
6767
bool common_hal_rp2pio_statemachine_write(rp2pio_statemachine_obj_t *self, const uint8_t *data, size_t len, uint8_t stride_in_bytes);
68-
bool common_hal_rp2pio_statemachine_start_continuous_write(rp2pio_statemachine_obj_t *self, mp_obj_t buf_obj, const uint8_t *data, size_t len, uint8_t stride_in_bytes);
69-
bool common_hal_rp2pio_statemachine_end_continuous_write(rp2pio_statemachine_obj_t *self);
68+
bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t *self, const sm_buf_info *once_obj, const sm_buf_info *loop_obj, uint8_t stride_in_bytes);
69+
bool common_hal_rp2pio_statemachine_stop_background_write(rp2pio_statemachine_obj_t *self);
70+
mp_int_t common_hal_rp2pio_statemachine_get_pending(rp2pio_statemachine_obj_t *self);
71+
bool common_hal_rp2pio_statemachine_get_writing(rp2pio_statemachine_obj_t *self);
7072
bool common_hal_rp2pio_statemachine_readinto(rp2pio_statemachine_obj_t *self, uint8_t *data, size_t len, uint8_t stride_in_bytes);
7173
bool common_hal_rp2pio_statemachine_write_readinto(rp2pio_statemachine_obj_t *self,
7274
const uint8_t *data_out, size_t out_len, uint8_t out_stride_in_bytes,

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <string.h>
28+
2729
#include "bindings/rp2pio/StateMachine.h"
2830

2931
#include "common-hal/microcontroller/__init__.h"
@@ -86,7 +88,7 @@ STATIC void rp2pio_statemachine_clear_dma(int pio_index, int sm) {
8688
if (!dma_hw->inte0) {
8789
irq_set_mask_enabled(1 << DMA_IRQ_0, false);
8890
}
89-
MP_STATE_PORT(continuous_pio)[channel] = NULL;
91+
MP_STATE_PORT(background_pio)[channel] = NULL;
9092
dma_channel_abort(channel);
9193
dma_channel_unclaim(channel);
9294
}
@@ -608,7 +610,7 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel
608610

609611
void rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self, bool leave_pins) {
610612
common_hal_rp2pio_statemachine_stop(self);
611-
(void)common_hal_rp2pio_statemachine_end_continuous_write(self);
613+
(void)common_hal_rp2pio_statemachine_stop_background_write(self);
612614

613615
uint8_t sm = self->state_machine;
614616
uint8_t pio_index = pio_get_index(self->pio);
@@ -877,32 +879,43 @@ uint8_t rp2pio_statemachine_program_offset(rp2pio_statemachine_obj_t *self) {
877879
return _current_program_offset[pio_index][sm];
878880
}
879881

880-
bool common_hal_rp2pio_statemachine_start_continuous_write(rp2pio_statemachine_obj_t *self, mp_obj_t buf_obj, const uint8_t *data, size_t len, uint8_t stride_in_bytes) {
882+
bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t *self, const sm_buf_info *once, const sm_buf_info *loop, uint8_t stride_in_bytes) {
881883
uint8_t pio_index = pio_get_index(self->pio);
882884
uint8_t sm = self->state_machine;
883885

884-
if (SM_DMA_ALLOCATED(pio_index, sm) && stride_in_bytes == self->continuous_stride_in_bytes) {
885-
while (self->pending_set_data) {
886+
int pending_buffers = (once->info.buf != NULL) + (loop->info.buf != NULL);
887+
if (!once->info.buf) {
888+
once = loop;
889+
}
890+
891+
892+
if (SM_DMA_ALLOCATED(pio_index, sm)) {
893+
if (stride_in_bytes != self->background_stride_in_bytes) {
894+
mp_raise_ValueError(translate("Mismatched data size"));
895+
}
896+
897+
while (self->pending_buffers) {
886898
RUN_BACKGROUND_TASKS;
887899
if (self->user_interruptible && mp_hal_is_interrupted()) {
888-
(void)common_hal_rp2pio_statemachine_end_continuous_write(self);
889900
return false;
890901
}
891902
}
892903

893904
common_hal_mcu_disable_interrupts();
894-
self->next_buffer = data;
895-
self->next_size = len / stride_in_bytes;
896-
self->pending_set_data = true;
905+
self->once = *once;
906+
self->loop = *loop;
907+
self->pending_buffers = pending_buffers;
908+
909+
if (self->dma_completed) {
910+
rp2pio_statemachine_dma_complete(self, SM_DMA_GET_CHANNEL(pio_index, sm));
911+
self->dma_completed = false;
912+
}
913+
897914
common_hal_mcu_enable_interrupts();
898915

899-
// need to keep a reference alive to the buffer, lest the GC collect it while its lone remaining pointer is in the DMA peripheral register
900-
self->buf_objs[++self->buf_obj_idx % 2] = buf_obj;
901916
return true;
902917
}
903918

904-
common_hal_rp2pio_statemachine_end_continuous_write(self);
905-
906919
int channel = dma_claim_unused_channel(false);
907920
if (channel == -1) {
908921
return false;
@@ -916,13 +929,12 @@ bool common_hal_rp2pio_statemachine_start_continuous_write(rp2pio_statemachine_o
916929

917930
dma_channel_config c;
918931

919-
self->pending_set_data = false;
920-
self->continuous_stride_in_bytes = stride_in_bytes;
921-
self->buf_objs[0] = buf_obj;
922-
self->buf_objs[1] = NULL;
923-
924-
self->next_buffer = data;
925-
self->next_size = len / stride_in_bytes;
932+
self->current = *once;
933+
self->once = *loop;
934+
self->loop = *loop;
935+
self->pending_buffers = pending_buffers;
936+
self->dma_completed = false;
937+
self->background_stride_in_bytes = stride_in_bytes;
926938

927939
c = dma_channel_get_default_config(channel);
928940
channel_config_set_transfer_data_size(&c, _stride_to_dma_size(stride_in_bytes));
@@ -931,12 +943,12 @@ bool common_hal_rp2pio_statemachine_start_continuous_write(rp2pio_statemachine_o
931943
channel_config_set_write_increment(&c, false);
932944
dma_channel_configure(channel, &c,
933945
tx_destination,
934-
data,
935-
len / stride_in_bytes,
946+
once->info.buf,
947+
once->info.len / stride_in_bytes,
936948
false);
937949

938950
common_hal_mcu_disable_interrupts();
939-
MP_STATE_PORT(continuous_pio)[channel] = self;
951+
MP_STATE_PORT(background_pio)[channel] = self;
940952
dma_hw->inte0 |= 1u << channel;
941953
irq_set_mask_enabled(1 << DMA_IRQ_0, true);
942954
dma_start_channel_mask(1u << channel);
@@ -946,15 +958,36 @@ bool common_hal_rp2pio_statemachine_start_continuous_write(rp2pio_statemachine_o
946958
}
947959

948960
void rp2pio_statemachine_dma_complete(rp2pio_statemachine_obj_t *self, int channel) {
949-
dma_channel_set_read_addr(channel, self->next_buffer, false);
950-
dma_channel_set_trans_count(channel, self->next_size, true);
961+
self->current = self->once;
962+
self->once = self->loop;
951963

952-
self->pending_set_data = false;
964+
if (self->current.info.buf) {
965+
if (self->pending_buffers > 0) {
966+
self->pending_buffers--;
967+
}
968+
dma_channel_set_read_addr(channel, self->current.info.buf, false);
969+
dma_channel_set_trans_count(channel, self->current.info.len / self->background_stride_in_bytes, true);
970+
} else {
971+
self->dma_completed = true;
972+
self->pending_buffers = 0; // should be a no-op
973+
}
953974
}
954975

955-
bool common_hal_rp2pio_statemachine_end_continuous_write(rp2pio_statemachine_obj_t *self) {
976+
bool common_hal_rp2pio_statemachine_stop_background_write(rp2pio_statemachine_obj_t *self) {
956977
uint8_t pio_index = pio_get_index(self->pio);
957978
uint8_t sm = self->state_machine;
958979
rp2pio_statemachine_clear_dma(pio_index, sm);
980+
memset(&self->current, 0, sizeof(self->current));
981+
memset(&self->once, 0, sizeof(self->once));
982+
memset(&self->loop, 0, sizeof(self->loop));
983+
self->pending_buffers = 0;
959984
return true;
960985
}
986+
987+
bool common_hal_rp2pio_statemachine_get_writing(rp2pio_statemachine_obj_t *self) {
988+
return !self->dma_completed;
989+
}
990+
991+
int common_hal_rp2pio_statemachine_get_pending(rp2pio_statemachine_obj_t *self) {
992+
return self->pending_buffers;
993+
}

0 commit comments

Comments
 (0)