Skip to content

Commit

Permalink
set up pio audio parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
timchinowsky committed Nov 20, 2024
1 parent b1381a0 commit 82d1898
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ports/raspberrypi/bindings/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions ports/raspberrypi/bindings/rp2pio/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 82d1898

Please sign in to comment.