Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raspberrypi: support PIO on high pins #9901

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ msgstr ""
#: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c
#: shared-bindings/bitmapfilter/__init__.c shared-bindings/canio/CAN.c
#: shared-bindings/digitalio/Pull.c shared-bindings/supervisor/__init__.c
#: shared-module/synthio/Synthesizer.c
#: shared-module/synthio/Biquad.c shared-module/synthio/Synthesizer.c
msgid "%q must be of type %q or %q, not %q"
msgstr ""

Expand Down Expand Up @@ -795,6 +795,10 @@ msgstr ""
msgid "Cannot subclass slice"
msgstr ""

#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Cannot use GPIO0..15 together with GPIO32..47"
msgstr ""

#: ports/nordic/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge, only level"
msgstr ""
Expand Down Expand Up @@ -3383,10 +3387,6 @@ msgstr ""
msgid "label redefined"
msgstr ""

#: shared-bindings/audiomixer/MixerVoice.c
msgid "level must be between 0 and 1"
msgstr ""

#: py/objarray.c
msgid "lhs and rhs should be compatible"
msgstr ""
Expand Down
14 changes: 7 additions & 7 deletions ports/raspberrypi/bindings/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ static mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n

{ MP_QSTR_first_in_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_in_pin_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
{ MP_QSTR_pull_in_pin_up, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_pull_in_pin_down, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_pull_in_pin_up, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_ROM_INT(0)} },
{ MP_QSTR_pull_in_pin_down, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_ROM_INT(0) } },

{ MP_QSTR_first_set_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_set_pin_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
Expand Down Expand Up @@ -334,14 +334,14 @@ static mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
args[ARG_frequency].u_int,
init_bufinfo.buf, init_bufinfo.len / 2,
may_exec_bufinfo.buf, may_exec_bufinfo.len / 2,
first_out_pin, out_pin_count, args[ARG_initial_out_pin_state].u_int, args[ARG_initial_out_pin_direction].u_int,
first_in_pin, in_pin_count, args[ARG_pull_in_pin_up].u_int, args[ARG_pull_in_pin_down].u_int,
first_set_pin, set_pin_count, args[ARG_initial_set_pin_state].u_int, args[ARG_initial_set_pin_direction].u_int,
first_out_pin, out_pin_count, PIO_PINMASK32_FROM_VALUE(args[ARG_initial_out_pin_state].u_int), PIO_PINMASK32_FROM_VALUE(args[ARG_initial_out_pin_direction].u_int),
first_in_pin, in_pin_count, PIO_PINMASK32_FROM_VALUE(args[ARG_pull_in_pin_up].u_int), PIO_PINMASK32_FROM_VALUE(args[ARG_pull_in_pin_down].u_int),
first_set_pin, set_pin_count, PIO_PINMASK32_FROM_VALUE(args[ARG_initial_set_pin_state].u_int), PIO_PINMASK32_FROM_VALUE(args[ARG_initial_set_pin_direction].u_int),
first_sideset_pin, sideset_pin_count, args[ARG_sideset_pindirs].u_bool,
args[ARG_initial_sideset_pin_state].u_int, args[ARG_initial_sideset_pin_direction].u_int,
PIO_PINMASK32_FROM_VALUE(args[ARG_initial_sideset_pin_state].u_int), PIO_PINMASK32_FROM_VALUE(args[ARG_initial_sideset_pin_direction].u_int),
args[ARG_sideset_enable].u_bool,
jmp_pin, jmp_pin_pull,
0,
PIO_PINMASK_FROM_VALUE(0), // wait_gpio_mask
args[ARG_exclusive_pin_use].u_bool,
args[ARG_auto_pull].u_bool, pull_threshold, args[ARG_out_shift_right].u_bool,
args[ARG_wait_for_txstall].u_bool,
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/bindings/rp2pio/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
size_t frequency,
const uint16_t *init, size_t init_len,
const uint16_t *may_exec, size_t may_exec_len,
const mcu_pin_obj_t *first_out_pin, uint8_t out_pin_count, uint32_t initial_out_pin_state, uint32_t initial_out_pin_direction,
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_out_pin, uint8_t out_pin_count, pio_pinmask32_t initial_out_pin_state, pio_pinmask32_t initial_out_pin_direction,
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, pio_pinmask32_t in_pull_pin_up, pio_pinmask32_t in_pull_pin_down,
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count, pio_pinmask32_t initial_set_pin_state, pio_pinmask32_t initial_set_pin_direction,
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count, bool sideset_pindirs,
uint32_t initial_sideset_pin_state, uint32_t initial_sideset_pin_direction,
pio_pinmask32_t initial_sideset_pin_state, pio_pinmask32_t initial_sideset_pin_direction,
bool sideset_enable,
const mcu_pin_obj_t *jmp_pin, digitalio_pull_t jmp_pin_pull,
uint32_t wait_gpio_mask,
pio_pinmask_t wait_gpio_mask,
bool exclusive_pin_use,
bool auto_pull, uint8_t pull_threshold, bool out_shift_right,
bool wait_for_txstall,
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/common-hal/audiobusio/I2SOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
44100 * 32 * 6, // Clock at 44.1 khz to warm the DAC up.
NULL, 0, // init
NULL, 0, // may_exec
data, 1, 0, 0xffffffff, // out pin
data, 1, PIO_PINMASK32_NONE, PIO_PINMASK32_ALL, // out pin
NULL, 0, // in pins
0, 0, // in pulls
NULL, 0, 0, 0x1f, // set pins
sideset_pin, 2, false, 0, 0x1f, // sideset pins
PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // in pulls
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // set pins
sideset_pin, 2, false, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // sideset pins
false, // No sideset enable
NULL, PULL_NONE, // jump pin
0, // wait gpio pins
PIO_PINMASK_NONE, // wait gpio pins
true, // exclusive pin use
false, 32, false, // shift out left to start with MSB
false, // Wait for txstall
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/common-hal/audiobusio/PDMIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
sample_rate * 32 * 2, // Frequency based on sample rate
NULL, 0,
NULL, 0, // may_exec
NULL, 1, 0, 0xffffffff, // out pin
NULL, 1, PIO_PINMASK32_NONE, PIO_PINMASK32_ALL, // out pin
data_pin, 1, // in pins
0, 0, // in pulls
NULL, 0, 0, 0x1f, // set pins
clock_pin, 1, false, 0, 0x1f, // sideset pins
PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // in pulls
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // set pins
clock_pin, 1, false, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // sideset pins
false, // No sideset enable
NULL, PULL_NONE, // jump pin
0, // wait gpio pins
PIO_PINMASK_NONE, // wait gpio pins
true, // exclusive pin use
false, 32, false, // out settings
false, // Wait for txstall
Expand Down
7 changes: 4 additions & 3 deletions ports/raspberrypi/common-hal/floppyio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ int common_hal_floppyio_flux_readinto(void *buf, size_t len, digitalio_digitalin

memset(buf, 0, len);

uint32_t pins_we_use = 1 << data->pin->number;

pio_pinmask_t pins_we_use = PIO_PINMASK_FROM_PIN(data->pin->number);

rp2pio_statemachine_obj_t state_machine;
bool ok = rp2pio_statemachine_construct(&state_machine,
Expand All @@ -86,10 +87,10 @@ int common_hal_floppyio_flux_readinto(void *buf, size_t len, digitalio_digitalin
NULL, 0, // init program
NULL, 0, // out
index->pin, 1, // in
1, 0, // in pull up/down
PIO_PINMASK_FROM_PIN(index->pin->number), PIO_PINMASK_FROM_VALUE(0), // pull up/down
NULL, 0, // set
NULL, 0, false, // sideset
0, 0, // initial pin state
PIO_PINMASK_FROM_VALUE(0), PIO_PINMASK_FROM_VALUE(0), // initial pin state
data->pin, // jump pin
pins_we_use, false, true,
true, 32, false, // TX setting we don't use
Expand Down
13 changes: 7 additions & 6 deletions ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
common_hal_mcu_processor_get_frequency(), // full speed (4 instructions per loop -> max pclk 30MHz @ 120MHz)
0, 0, // init
NULL, 0, // may_exec
NULL, 0, 0, 0, // out pins
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // out pins
pin_from_number(data_pins[0]), data_count, // in pins
0, 0, // in pulls
NULL, 0, 0, 0, // set pins
PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // in pulls
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // set pins
#if DEBUG_STATE_MACHINE
&pin_GPIO26, 3, 7, 7, // sideset pins
&pin_GPIO26, 3, PIO_PINMASK32_FROM_VALUE(7), PIO_PINMASK32_FROM_VALUE(7), // sideset pins
#else
NULL, 0, false, 0, 0, // sideset pins
NULL, 0, false, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // sideset pins
#endif
false, // No sideset enable
NULL, PULL_NONE, // jump pin
(1 << vertical_sync->number) | (1 << horizontal_reference->number) | (1 << data_clock->number), // wait gpio pins
PIO_PINMASK_OR3(PIO_PINMASK_FROM_PIN(vertical_sync->number), PIO_PINMASK_FROM_PIN(horizontal_reference->number), PIO_PINMASK_FROM_PIN(data_clock->number)),
// wait gpio pins
true, // exclusive pin use
false, 32, false, // out settings
false, // wait for txstall
Expand Down
6 changes: 3 additions & 3 deletions ports/raspberrypi/common-hal/neopixel_write/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,

// TODO: Cache the state machine after we create it once. We'll need a way to
// change the pins then though.
uint32_t pins_we_use = 1 << digitalinout->pin->number;
pio_pinmask_t pins_we_use = PIO_PINMASK_FROM_PIN(digitalinout->pin->number);
bool ok = rp2pio_statemachine_construct(&state_machine,
neopixel_program, MP_ARRAY_SIZE(neopixel_program),
12800000, // 12.8MHz, to get appropriate sub-bit times in PIO program.
NULL, 0, // init program
NULL, 1, // out
NULL, 1, // in
0, 0, // in pulls
PIO_PINMASK_NONE, PIO_PINMASK_NONE, // gpio pulls
NULL, 1, // set
digitalinout->pin, 1, false, // sideset
0, pins_we_use, // initial pin state
PIO_PINMASK_NONE, 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
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/common-hal/paralleldisplaybus/ParallelBus.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ void common_hal_paralleldisplaybus_parallelbus_construct(paralleldisplaybus_para
frequency * 2, // frequency multiplied by 2 as 2 PIO instructions
NULL, 0, // init
NULL, 0, // may_exec
data0, 8, 0, 255, // first out pin, # out pins
NULL, 0, 0, 0, // first in pin, # in pins
NULL, 0, 0, 0, // first set pin
write, 1, false, 0, 1, // first sideset pin
data0, 8, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(255), // first out pin, # out pins
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first in pin, # in pins
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first set pin
write, 1, false, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(1), // first sideset pin
false, // No sideset enable
NULL, PULL_NONE, // jump pin
0, // wait gpio pins
PIO_PINMASK_NONE, // wait gpio pins
true, // exclusive pin usage
true, 8, true, // TX, auto pull every 8 bits. shift left to output msb first
false, // wait for TX stall
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
1000000, // frequency
NULL, 0, // init, init_len
NULL, 0, // may_exec
NULL, 0, 0, 0, // first out pin, # out pins, initial_out_pin_state
pin, 1, 0, 0, // first in pin, # in pins
NULL, 0, 0, 0, // first set pin
NULL, 0, false, 0, 0, // first sideset pin
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first out pin, # out pins, initial_out_pin_state
pin, 1, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first in pin, # in pins
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first set pin
NULL, 0, false, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // first sideset pin
false, // No sideset enable
NULL, PULL_NONE, // jump pin, jmp_pull
0, // wait gpio pins
PIO_PINMASK_NONE, // wait gpio pins
true, // exclusive pin usage
false, 8, false, // TX, setting we don't use
false, // wait for TX stall
Expand Down
10 changes: 5 additions & 5 deletions ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
1000000,
encoder_init, MP_ARRAY_SIZE(encoder_init), // init
NULL, 0, // may_exec
NULL, 0, 0, 0, // out pin
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_NONE, // out pin
pins[0], 2, // in pins
3, 0, // in pulls
NULL, 0, 0, 0x1f, // set pins
NULL, 0, false, 0, 0x1f, // sideset pins
PIO_PINMASK32_FROM_VALUE(3), PIO_PINMASK32_NONE, // in pulls
NULL, 0, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // set pins
NULL, 0, false, PIO_PINMASK32_NONE, PIO_PINMASK32_FROM_VALUE(0x1f), // sideset pins
false, // No sideset enable
NULL, PULL_NONE, // jump pin
0, // wait gpio pins
PIO_PINMASK_NONE, // wait gpio pins
true, // exclusive pin use
false, 32, false, // out settings
false, // Wait for txstall
Expand Down
Loading