From bf57f3606a437a3a41aa0943ecf7b7b427010092 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 1 Feb 2022 10:19:17 -0600 Subject: [PATCH] rp2pio: Add pull up/down support for the "jmp pin" This is needed so that the floppy flux reader can enable the pull up on the index pin while using it as a pio jmp pin. Also fixes a doc bug where the `jmp_pin` was omitted in one spot in the docs. --- ports/raspberrypi/bindings/rp2pio/StateMachine.c | 9 +++++++-- ports/raspberrypi/bindings/rp2pio/StateMachine.h | 3 ++- ports/raspberrypi/common-hal/audiobusio/I2SOut.c | 2 +- ports/raspberrypi/common-hal/audiobusio/PDMIn.c | 2 +- .../common-hal/imagecapture/ParallelImageCapture.c | 2 +- .../common-hal/paralleldisplay/ParallelBus.c | 2 +- .../common-hal/rotaryio/IncrementalEncoder.c | 2 +- ports/raspberrypi/common-hal/rp2pio/StateMachine.c | 13 ++++++++++++- 8 files changed, 26 insertions(+), 9 deletions(-) diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index 3dcc6e927b..90af6ebce0 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -79,6 +79,8 @@ //| initial_sideset_pin_state: int = 0, //| initial_sideset_pin_direction: int = 0x1f, //| sideset_enable: bool = False, +//| jmp_pin: Optional[microcontroller.Pin] = None, +//| jmp_pin_pull: Optional[digitalio.Pull] = None, //| exclusive_pin_use: bool = True, //| auto_pull: bool = False, //| pull_threshold: int = 32, @@ -113,6 +115,7 @@ //| :param int initial_sideset_pin_direction: the initial output direction for sideset pins starting at first_sideset_pin //| :param bool sideset_enable: True when the top sideset bit is to enable. This should be used with the ".side_set # opt" directive //| :param ~microcontroller.Pin jmp_pin: the pin which determines the branch taken by JMP PIN instructions +//| :param ~digitalio.Pull jmp_pin_pull: The pull value for the jmp pin, default is no pull. //| :param bool exclusive_pin_use: When True, do not share any pins with other state machines. Pins are never shared with other peripherals //| :param bool auto_pull: When True, automatically load data from the tx FIFO into the //| output shift register (OSR) when an OUT instruction shifts more than pull_threshold bits @@ -150,7 +153,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n ARG_first_set_pin, ARG_set_pin_count, ARG_initial_set_pin_state, ARG_initial_set_pin_direction, ARG_first_sideset_pin, ARG_sideset_pin_count, ARG_initial_sideset_pin_state, ARG_initial_sideset_pin_direction, ARG_sideset_enable, - ARG_jmp_pin, + ARG_jmp_pin, ARG_jmp_pin_pull, ARG_exclusive_pin_use, ARG_auto_pull, ARG_pull_threshold, ARG_out_shift_right, ARG_wait_for_txstall, @@ -184,6 +187,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n { MP_QSTR_sideset_enable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, { MP_QSTR_jmp_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_jmp_pin_pull, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_exclusive_pin_use, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, { MP_QSTR_auto_pull, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, @@ -230,6 +234,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n } const mcu_pin_obj_t *jmp_pin = validate_obj_is_pin_or_none(args[ARG_jmp_pin].u_obj); + digitalio_pull_t jmp_pin_pull = validate_pull(args[ARG_jmp_pin_pull].u_rom_obj, MP_QSTR_jmp_pull); mp_int_t pull_threshold = args[ARG_pull_threshold].u_int; mp_int_t push_threshold = args[ARG_push_threshold].u_int; @@ -263,7 +268,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n first_set_pin, args[ARG_set_pin_count].u_int, args[ARG_initial_set_pin_state].u_int, args[ARG_initial_set_pin_direction].u_int, first_sideset_pin, args[ARG_sideset_pin_count].u_int, args[ARG_initial_sideset_pin_state].u_int, args[ARG_initial_sideset_pin_direction].u_int, args[ARG_sideset_enable].u_bool, - jmp_pin, + jmp_pin, jmp_pin_pull, 0, args[ARG_exclusive_pin_use].u_bool, args[ARG_auto_pull].u_bool, pull_threshold, args[ARG_out_shift_right].u_bool, diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.h b/ports/raspberrypi/bindings/rp2pio/StateMachine.h index 3f3b8cf7d8..e2770cd46d 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.h +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.h @@ -29,6 +29,7 @@ #include "py/obj.h" +#include "shared-bindings/digitalio/Pull.h" #include "common-hal/microcontroller/Pin.h" #include "common-hal/rp2pio/StateMachine.h" @@ -45,7 +46,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count, uint32_t initial_set_pin_state, uint32_t initial_set_pin_direction, const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count, uint32_t initial_sideset_pin_state, uint32_t initial_sideset_pin_direction, bool sideset_enable, - const mcu_pin_obj_t *jmp_pin, + const mcu_pin_obj_t *jmp_pin, digitalio_pull_t jmp_pin_pull, uint32_t wait_gpio_mask, bool exclusive_pin_use, bool auto_pull, uint8_t pull_threshold, bool out_shift_right, diff --git a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c index 4296014e50..d5699742e4 100644 --- a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c +++ b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c @@ -127,7 +127,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self, 0, 0, // in pulls NULL, 0, 0, 0x1f, // set pins bit_clock, 2, 0, 0x1f, // sideset pins - NULL, // jump pin + NULL, PULL_NONE, // jump pin 0, // wait gpio pins true, // exclusive pin use false, 32, false, // shift out left to start with MSB diff --git a/ports/raspberrypi/common-hal/audiobusio/PDMIn.c b/ports/raspberrypi/common-hal/audiobusio/PDMIn.c index 859e82eb11..4579dedcf5 100644 --- a/ports/raspberrypi/common-hal/audiobusio/PDMIn.c +++ b/ports/raspberrypi/common-hal/audiobusio/PDMIn.c @@ -71,7 +71,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self, 0, 0, // in pulls NULL, 0, 0, 0x1f, // set pins clock_pin, 1, 0, 0x1f, // sideset pins - NULL, // jump pin + NULL, PULL_NONE, // jump pin 0, // wait gpio pins true, // exclusive pin use false, 32, false, // out settings diff --git a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c index 45a3766897..8890e3f526 100644 --- a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c @@ -112,7 +112,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle NULL, 0, 0, 0, // sideset pins #endif false, // No sideset enable - NULL, // jump pin + NULL, PULL_NONE, // jump pin (1 << vertical_sync->number) | (1 << horizontal_reference->number) | (1 << data_clock->number), // wait gpio pins true, // exclusive pin use false, 32, false, // out settings diff --git a/ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c b/ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c index 2e0ae4def2..12f8d79a74 100644 --- a/ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c +++ b/ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c @@ -100,7 +100,7 @@ void common_hal_paralleldisplay_parallelbus_construct(paralleldisplay_parallelbu NULL, 0, 0, 0, // first set pin write, 1, 0, 1, // first sideset pin false, // No sideset enable - NULL, // jump pin + NULL, PULL_NONE, // jump pin 0, // wait gpio pins true, // exclusive pin usage true, 8, true, // TX, auto pull every 8 bits. shift left to output msb first diff --git a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c index 1f15b010f7..faf63c2812 100644 --- a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c @@ -86,7 +86,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode NULL, 0, 0, 0x1f, // set pins NULL, 0, 0, 0x1f, // sideset pins false, // No sideset enable - NULL, // jump pin + NULL, PULL_NONE, // jump pin 0, // wait gpio pins true, // exclusive pin use false, 32, false, // out settings diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index ac5a41652a..5de35e51c0 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -27,6 +27,7 @@ #include "bindings/rp2pio/StateMachine.h" #include "common-hal/microcontroller/__init__.h" +#include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" @@ -342,7 +343,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count, uint32_t initial_set_pin_state, uint32_t initial_set_pin_direction, const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count, uint32_t initial_sideset_pin_state, uint32_t initial_sideset_pin_direction, bool sideset_enable, - const mcu_pin_obj_t *jmp_pin, + const mcu_pin_obj_t *jmp_pin, digitalio_pull_t jmp_pull, uint32_t wait_gpio_mask, bool exclusive_pin_use, bool auto_pull, uint8_t pull_threshold, bool out_shift_right, @@ -489,6 +490,16 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, // Deal with pull up/downs uint32_t pull_up = mask_and_rotate(first_in_pin, in_pin_count, pull_pin_up); uint32_t pull_down = mask_and_rotate(first_in_pin, in_pin_count, pull_pin_down); + + if (jmp_pin) { + uint32_t jmp_mask = mask_and_rotate(jmp_pin, 1, 0x1f); + if (jmp_pull == PULL_UP) { + pull_up |= jmp_mask; + } + if (jmp_pull == PULL_DOWN) { + pull_up |= jmp_mask; + } + } if (initial_pin_direction & (pull_up | pull_down)) { mp_raise_ValueError(translate("pull masks conflict with direction masks")); }