Added support for specifying the JMP pin (RP2 PIO)

This commit is contained in:
Nathan Young 2021-07-22 18:39:04 +02:00
parent 10645bf538
commit 8221a12cf6
11 changed files with 23 additions and 6 deletions

View File

@ -109,6 +109,7 @@
//| :param int sideset_pin_count: the count of consecutive pins to use with a side set starting at first_sideset_pin
//| :param int initial_sideset_pin_state: the initial output value for sideset pins starting at first_sideset_pin
//| :param int initial_sideset_pin_direction: the initial output direction for sideset pins starting at first_sideset_pin
//| :param ~microcontroller.Pin jmp_pin: the pin which determines the branch taken by JMP PIN instructions
//| :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
@ -138,6 +139,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
ARG_pull_in_pin_up, ARG_pull_in_pin_down,
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_jmp_pin,
ARG_exclusive_pin_use,
ARG_auto_pull, ARG_pull_threshold, ARG_out_shift_right,
ARG_wait_for_txstall,
@ -167,6 +169,8 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
{ MP_QSTR_initial_sideset_pin_state, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_initial_sideset_pin_direction, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x1f} },
{ MP_QSTR_jmp_pin, 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} },
{ MP_QSTR_pull_threshold, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 32} },
@ -210,6 +214,8 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
mp_raise_ValueError(translate("Side set pin count must be between 1 and 5"));
}
const mcu_pin_obj_t *jmp_pin = validate_obj_is_pin_or_none(args[ARG_jmp_pin].u_obj);
mp_int_t pull_threshold = args[ARG_pull_threshold].u_int;
mp_int_t push_threshold = args[ARG_push_threshold].u_int;
if (pull_threshold < 1 || pull_threshold > 32) {
@ -241,6 +247,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
first_in_pin, args[ARG_in_pin_count].u_int, args[ARG_pull_in_pin_up].u_int, args[ARG_pull_in_pin_down].u_int,
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,
jmp_pin,
0,
args[ARG_exclusive_pin_use].u_bool,
args[ARG_auto_pull].u_bool, pull_threshold, args[ARG_out_shift_right].u_bool,

View File

@ -44,6 +44,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, uint32_t pull_pin_up, uint32_t pull_pin_down,
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,
const mcu_pin_obj_t *jmp_pin,
uint32_t wait_gpio_mask,
bool exclusive_pin_use,
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,

View File

@ -126,6 +126,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
0, // wait gpio pins
true, // exclusive pin use
false, 32, false, // shift out left to start with MSB

View File

@ -71,6 +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
0, // wait gpio pins
true, // exclusive pin use
false, 32, false, // out settings

View File

@ -99,6 +99,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t *sel
NULL, 0, 0, 0, // first in pin, # in pins
NULL, 0, 0, 0, // first set pin
write, 1, 0, 1, // first sideset pin
NULL, // 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

View File

@ -111,6 +111,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
#else
NULL, 0, 0, 0, // sideset pins
#endif
NULL, // 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

View File

@ -71,6 +71,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
NULL, 1, // set
digitalinout->pin, 1, // sideset
0, pins_we_use, // initial pin state
NULL, // jump pin
pins_we_use, true, false,
true, 8, false, // TX, auto pull every 8 bits. shift left to output msb first
true, // Wait for txstall. If we don't, then we'll deinit too quickly.

View File

@ -67,6 +67,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
NULL, 0,
NULL, 0,
1, 0,
NULL, // jump pin
1 << self->pin, false, true,
false, 8, false, // TX, unused
false,

View File

@ -84,6 +84,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
3, 0, // in pulls
NULL, 0, 0, 0x1f, // set pins
NULL, 0, 0, 0x1f, // sideset pins
NULL, // jump pin
0, // wait gpio pins
true, // exclusive pin use
false, 32, false, // out settings

View File

@ -158,6 +158,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count,
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count,
uint32_t initial_pin_state, uint32_t initial_pin_direction,
const mcu_pin_obj_t *jmp_pin,
uint32_t pins_we_use, bool tx_fifo, bool rx_fifo,
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
bool wait_for_txstall,
@ -278,6 +279,9 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
sm_config_set_sideset(&c, sideset_pin_count, false /* optional */, false /* pin direction */);
sm_config_set_sideset_pins(&c, first_sideset_pin->number);
}
if (jmp_pin != NULL) {
sm_config_set_jmp_pin(&c, jmp_pin->number);
}
sm_config_set_wrap(&c, program_offset, program_offset + program_len - 1);
sm_config_set_in_shift(&c, in_shift_right, auto_push, push_threshold);
sm_config_set_out_shift(&c, out_shift_right, auto_pull, pull_threshold);
@ -329,6 +333,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
uint32_t pull_pin_up, uint32_t pull_pin_down,
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,
const mcu_pin_obj_t *jmp_pin,
uint32_t wait_gpio_mask,
bool exclusive_pin_use,
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
@ -341,6 +346,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
pins_we_use |= _check_pins_free(first_in_pin, in_pin_count, exclusive_pin_use);
pins_we_use |= _check_pins_free(first_set_pin, set_pin_count, exclusive_pin_use);
pins_we_use |= _check_pins_free(first_sideset_pin, sideset_pin_count, exclusive_pin_use);
pins_we_use |= _check_pins_free(jmp_pin, 1, exclusive_pin_use);
// Look through the program to see what we reference and make sure it was provided.
bool tx_fifo = false;
@ -361,12 +367,6 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
out_loaded = true;
}
}
if (instruction == pio_instr_bits_jmp) {
uint16_t condition = (full_instruction & 0x00e0) >> 5;
if (condition == 0x6) { // GPIO
mp_raise_NotImplementedError_varg(translate("Instruction %d jumps on pin"), i);
}
}
if (instruction == pio_instr_bits_wait) {
uint16_t wait_source = (full_instruction & 0x0060) >> 5;
uint16_t wait_index = full_instruction & 0x001f;
@ -486,6 +486,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
first_set_pin, set_pin_count,
first_sideset_pin, sideset_pin_count,
initial_pin_state, initial_pin_direction,
jmp_pin,
pins_we_use, tx_fifo, rx_fifo,
auto_pull, pull_threshold, out_shift_right,
wait_for_txstall,

View File

@ -68,6 +68,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count,
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count,
uint32_t initial_pin_state, uint32_t initial_pin_direction,
const mcu_pin_obj_t *jmp_pin,
uint32_t pins_we_use, bool tx_fifo, bool rx_fifo,
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
bool wait_for_txstall,