8000 rp2/rp2_pio: Add JMP PIN support for PIO. · micropython/micropython@7a9027f · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a9027f

Browse files
tjvrdpgeorge
authored andcommitted
rp2/rp2_pio: Add JMP PIN support for PIO.
PIO state machines can make a conditional jump on the state of a pin: the `JMP PIN` command. This requires the pin to be configured with `sm_config_set_jmp_pin`, but until now we didn't have a way of doing that in MicroPython. This commit adds a new `jmp_pin=None` argument to `StateMachine`. If it is not `None` then we try to interpret it as a Pin, and pass its value to `sm_config_set_jmp_pin`. Signed-off-by: Tim Radvan <tim@tjvr.org>
1 parent 9b277d9 commit 7a9027f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ports/rp2/rp2_pio.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,14 @@ STATIC void rp2_state_machine_print(const mp_print_t *print, mp_obj_t self_in, m
422422
}
423423

424424
// StateMachine.init(prog, freq=-1, *,
425-
// in_base=None, out_base=None, set_base=None, sideset_base=None,
426-
// in_shiftdir=None, out_shiftdir=None, push_thresh=None, pull_thresh=None,
425+
// in_base=None, out_base=None, set_base=None, jmp_pin=None,
426+
// sideset_base=None, in_shiftdir=None, out_shiftdir=None,
427+
// push_thresh=None, pull_thresh=None,
427428
// )
428429
STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
429430
enum {
430431
ARG_prog, ARG_freq,
431-
ARG_in_base, ARG_out_base, ARG_set_base, ARG_sideset_base,
432+
ARG_in_base, ARG_out_base, ARG_set_base, ARG_jmp_pin, ARG_sideset_base,
432433
ARG_in_shiftdir, ARG_out_shiftdir, ARG_push_thresh, ARG_pull_thresh
433434
};
434435
static const mp_arg_t allowed_args[] = {
@@ -437,6 +438,7 @@ STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *sel
437438
{ MP_QSTR_in_base, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
438439
{ MP_QSTR_out_base, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
439440
{ MP_QSTR_set_base, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
441+
{ MP_QSTR_jmp_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
440442
{ MP_QSTR_sideset_base, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
441443
{ MP_QSTR_in_shiftdir, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
442444
{ MP_QSTR_out_shiftdir, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
@@ -501,6 +503,11 @@ STATIC mp_obj_t rp2_state_machine_init_helper(const rp2_state_machine_obj_t *sel
501503
sm_config_set_set_pins(&config, set_config.base, set_config.count);
502504
}
503505

506+
// Configure jmp pin, if needed.
507+
if (args[ARG_jmp_pin].u_obj != mp_const_none) {
508+
sm_config_set_jmp_pin(&config, mp_hal_get_pin_obj(args[ARG_jmp_pin].u_obj));
509+
}
510+
504511
// Configure sideset pin, if needed.
505512
asm_pio_config_t sideset_config = ASM_PIO_CONFIG_DEFAULT;
506513
asm_pio_get_pins("sideset", prog[PROG_SIDESET_PINS], args[ARG_sideset_base].u_obj, &sideset_config);

0 commit comments

Comments
 (0)
0