diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index e086dff9d57d3..f907b94d14a88 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -506,7 +506,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_write_obj, 2, rp2pio_statemachine //| Then the ``once`` and/or ``loop`` buffers are queued. and the function returns. //| The ``once`` buffer (if specified) will be written just once. //| Finally, the ``loop`` and/or ``loop2`` buffer (if specified) will continue being looped indefinitely. If both ``loop`` and ``loop2`` are specified, they will alternate. -//| +//| //| Writes to the FIFO will match the input buffer's element size. For example, bytearray elements //| will perform 8 bit writes to the PIO FIFO. The RP2040's memory bus will duplicate the value into //| the other byte positions. So, pulling more data in the PIO assembly will read the duplicated values. @@ -1181,6 +1181,8 @@ static const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_last_read), MP_ROM_PTR(&rp2pio_statemachine_last_read_obj) }, { MP_ROM_QSTR(MP_QSTR_last_write), MP_ROM_PTR(&rp2pio_statemachine_last_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_write_audio), MP_ROM_PTR(&rp2pio_statemachine_write_audio_obj) }, + { MP_ROM_QSTR(MP_QSTR_read_audio), MP_ROM_PTR(&rp2pio_statemachine_read_audio_obj) }, }; static MP_DEFINE_CONST_DICT(rp2pio_statemachine_locals_dict, rp2pio_statemachine_locals_dict_table); diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.h b/ports/raspberrypi/bindings/rp2pio/StateMachine.h index 3d265b19a5245..5a15abc804535 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.h +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.h @@ -75,6 +75,12 @@ bool common_hal_rp2pio_statemachine_write_readinto(rp2pio_statemachine_obj_t *se uint32_t common_hal_rp2pio_statemachine_get_frequency(rp2pio_statemachine_obj_t *self); void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *self, uint32_t frequency); +mp_obj_t common_hal_rp2pio_statemachine_get_write_audio(rp2pio_statemachine_obj_t *self); +void common_hal_rp2pio_statemachine_set_write_audio(rp2pio_statemachine_obj_t *self, mp_obj_t write_audio); + +mp_obj_t common_hal_rp2pio_statemachine_get_read_audio(rp2pio_statemachine_obj_t *self); +void common_hal_rp2pio_statemachine_set_read_audio(rp2pio_statemachine_obj_t *self, mp_obj_t read_audio); + bool common_hal_rp2pio_statemachine_get_rxstall(rp2pio_statemachine_obj_t *self); void common_hal_rp2pio_statemachine_clear_rxfifo(rp2pio_statemachine_obj_t *self); diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 87f573d98a693..9c9a10a903d17 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -449,6 +449,9 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, sm_config_set_fifo_join(&c, join); + self->read_audio = mp_const_none; + self->write_audio = mp_const_none; + // TODO: these arguments // int mov_status_type, int mov_status_n, // int set_count, int out_count @@ -754,6 +757,22 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel pio_sm_clkdiv_restart(self->pio, self->state_machine); } +mp_obj_t common_hal_rp2pio_statemachine_get_write_audio(rp2pio_statemachine_obj_t *self) { + return self->write_audio; +} + +void common_hal_rp2pio_statemachine_set_write_audio(rp2pio_statemachine_obj_t *self, mp_obj_t write_audio) { + self->write_audio = write_audio; +} + +mp_obj_t common_hal_rp2pio_statemachine_get_read_audio(rp2pio_statemachine_obj_t *self) { + return self->read_audio; +} + +void common_hal_rp2pio_statemachine_set_read_audio(rp2pio_statemachine_obj_t *self, mp_obj_t read_audio) { + self->read_audio = read_audio; +} + void rp2pio_statemachine_reset_ok(PIO pio, int sm) { uint8_t pio_index = pio_get_index(pio); _never_reset[pio_index][sm] = false; diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h index 7fa2f3d6c7522..fb69125aa63b1 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h @@ -60,6 +60,8 @@ typedef struct { sm_buf_info once_write_buf_info, loop_write_buf_info, loop2_write_buf_info; sm_buf_info current_write_buf, next_write_buf_1, next_write_buf_2, next_write_buf_3; + mp_obj_t write_audio, read_audio; + bool switched_write_buffers, switched_read_buffers; int background_stride_in_bytes;