Skip to content

Commit 0461640

Browse files
robert-hhdpgeorge
authored andcommitted
rp2/rp2_pio: Fix sm.get(buf) to not wait after getting last item.
sm.get(buf) was waiting for one item more than the length of the supplied buffer. Even if this item was not stored, sm_get would block trying to get an item from the RX fifo. As part of the fix, the edge case for a zero length buffer was moved up to the section where the function arguments are handled. In case of a zero length buffer, sm.get() now returns immediately that buffer.
1 parent a075e0b commit 0461640

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ports/rp2/rp2_pio.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,9 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
608608
} else {
609609
bufinfo.typecode |= 0x20; // make lowercase to support upper and lower
610610
}
611+
if (bufinfo.len == 0) { // edge case: buffer of zero length supplied
612+
return args[1];
613+
}
611614
}
612615
if (n_args > 2) {
613616
shift = mp_obj_get_int(args[2]);
@@ -625,9 +628,6 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
625628
if (dest == NULL) {
626629
return mp_obj_new_int_from_uint(value);
627630
}
628-
if (dest >= dest_top) {
629-
return args[1];
630-
}
631631
if (bufinfo.typecode == 'b') {
632632
*(uint8_t *)dest = value;
633633
dest += sizeof(uint8_t);
@@ -640,6 +640,9 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
640640
} else {
641641
mp_raise_ValueError("unsupported buffer type");
642642
}
643+
if (dest >= dest_top) {
644+
return args[1];
645+
}
643646
}
644647
}
645648
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get);

0 commit comments

Comments
 (0)