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.
This commit is contained in:
parent
a075e0b7d8
commit
0461640983
|
@ -608,6 +608,9 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) {
|
|||
} else {
|
||||
bufinfo.typecode |= 0x20; // make lowercase to support upper and lower
|
||||
}
|
||||
if (bufinfo.len == 0) { // edge case: buffer of zero length supplied
|
||||
return args[1];
|
||||
}
|
||||
}
|
||||
if (n_args > 2) {
|
||||
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) {
|
|||
if (dest == NULL) {
|
||||
return mp_obj_new_int_from_uint(value);
|
||||
}
|
||||
if (dest >= dest_top) {
|
||||
return args[1];
|
||||
}
|
||||
if (bufinfo.typecode == 'b') {
|
||||
*(uint8_t *)dest = value;
|
||||
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) {
|
|||
} else {
|
||||
mp_raise_ValueError("unsupported buffer type");
|
||||
}
|
||||
if (dest >= dest_top) {
|
||||
return args[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rp2_state_machine_get_obj, 1, 3, rp2_state_machine_get);
|
||||
|
|
Loading…
Reference in New Issue