Skip to content

Commit 5780d9a

Browse files
committed
rp2: Add StateMachine.may_exec
and also sanity-check the init instructions, thanks to the newly factored-out checker. Closes: #8221
1 parent a27a5aa commit 5780d9a

File tree

10 files changed

+167
-139
lines changed

10 files changed

+167
-139
lines changed

locale/circuitpython.pot

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,22 @@ msgstr ""
251251
msgid "%q=%q"
252252
msgstr ""
253253

254+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
255+
msgid "%q[%u] shifts in more bits than pin count"
256+
msgstr ""
257+
258+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
259+
msgid "%q[%u] shifts out more bits than pin count"
260+
msgstr ""
261+
262+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
263+
msgid "%q[%u] uses extra pin"
264+
msgstr ""
265+
266+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
267+
msgid "%q[%u] waits on input outside of count"
268+
msgstr ""
269+
254270
#: ports/espressif/common-hal/espidf/__init__.c
255271
#, c-format
256272
msgid "%s error 0x%x"
@@ -1161,26 +1177,6 @@ msgstr ""
11611177
msgid "Input/output error"
11621178
msgstr ""
11631179

1164-
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1165-
#, c-format
1166-
msgid "Instruction %d shifts in more bits than pin count"
1167-
msgstr ""
1168-
1169-
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1170-
#, c-format
1171-
msgid "Instruction %d shifts out more bits than pin count"
1172-
msgstr ""
1173-
1174-
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1175-
#, c-format
1176-
msgid "Instruction %d uses extra pin"
1177-
msgstr ""
1178-
1179-
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1180-
#, c-format
1181-
msgid "Instruction %d waits on input outside of count"
1182-
msgstr ""
1183-
11841180
#: ports/nrf/common-hal/_bleio/__init__.c
11851181
msgid "Insufficient authentication"
11861182
msgstr ""
@@ -1352,38 +1348,31 @@ msgid "Mismatched swap flag"
13521348
msgstr ""
13531349

13541350
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1355-
#, c-format
1356-
msgid "Missing first_in_pin. Instruction %d reads pin(s)"
1351+
msgid "Missing first_in_pin. %q[%u] reads pin(s)"
13571352
msgstr ""
13581353

13591354
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1360-
#, c-format
1361-
msgid "Missing first_in_pin. Instruction %d shifts in from pin(s)"
1355+
msgid "Missing first_in_pin. %q[%u] shifts in from pin(s)"
13621356
msgstr ""
13631357

13641358
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1365-
#, c-format
1366-
msgid "Missing first_in_pin. Instruction %d waits based on pin"
1359+
msgid "Missing first_in_pin. %q[%u] waits based on pin"
13671360
msgstr ""
13681361

13691362
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1370-
#, c-format
1371-
msgid "Missing first_out_pin. Instruction %d shifts out to pin(s)"
1363+
msgid "Missing first_out_pin. %q[%u] shifts out to pin(s)"
13721364
msgstr ""
13731365

13741366
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1375-
#, c-format
1376-
msgid "Missing first_out_pin. Instruction %d writes pin(s)"
1367+
msgid "Missing first_out_pin. %q[%u] writes pin(s)"
13771368
msgstr ""
13781369

13791370
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1380-
#, c-format
1381-
msgid "Missing first_set_pin. Instruction %d sets pin(s)"
1371+
msgid "Missing first_set_pin. %q[%u] sets pin(s)"
13821372
msgstr ""
13831373

13841374
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1385-
#, c-format
1386-
msgid "Missing jmp_pin. Instruction %d jumps on pin"
1375+
msgid "Missing jmp_pin. %q[%u] jumps on pin"
13871376
msgstr ""
13881377

13891378
#: shared-bindings/busio/UART.c shared-bindings/displayio/Group.c
@@ -1825,7 +1814,8 @@ msgstr ""
18251814

18261815
#: shared-bindings/_bleio/__init__.c
18271816
#: shared-bindings/memorymonitor/AllocationSize.c
1828-
#: shared-bindings/pulseio/PulseIn.c shared-module/displayio/Bitmap.c
1817+
#: shared-bindings/pulseio/PulseIn.c shared-module/bitmaptools/__init__.c
1818+
#: shared-module/displayio/Bitmap.c
18291819
msgid "Read-only"
18301820
msgstr ""
18311821

@@ -4021,7 +4011,7 @@ msgstr ""
40214011
msgid "sosfilt requires iterable arguments"
40224012
msgstr ""
40234013

4024-
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
4014+
#: shared-bindings/bitmaptools/__init__.c
40254015
msgid "source palette too large"
40264016
msgstr ""
40274017

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
//| :param int frequency: the target clock frequency of the state machine. Actual may be less. Use 0 for system clock speed.
101101
//| :param ReadableBuffer init: a program to run once at start up. This is run after program
102102
//| is started so instructions may be intermingled
103+
//| :param ReadableBuffer may_exec: Instructions that may be executed via `StateMachine.exec` calls.
104+
//| Some elements of the `StateMachine`'s configuration are inferred from the instructions used;
105+
//| for instance, if there is no ``in`` or ``push`` instruction, then the `StateMachine` is configured without a receive FIFO.
106+
//| In this case, passing a ``may_exec`` program containing an ``in`` instruction such as ``in x``, a receive FIFO will be configured.
103107
//| :param ~microcontroller.Pin first_out_pin: the first pin to use with the OUT instruction
104108
//| :param int out_pin_count: the count of consecutive pins to use with OUT starting at first_out_pin
105109
//| :param int initial_out_pin_state: the initial output value for out pins starting at first_out_pin
@@ -152,7 +156,7 @@
152156
STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
153157
rp2pio_statemachine_obj_t *self = m_new_obj(rp2pio_statemachine_obj_t);
154158
self->base.type = &rp2pio_statemachine_type;
155-
enum { ARG_program, ARG_frequency, ARG_init,
159+
enum { ARG_program, ARG_frequency, ARG_init, ARG_may_exec,
156160
ARG_first_out_pin, ARG_out_pin_count, ARG_initial_out_pin_state, ARG_initial_out_pin_direction,
157161
ARG_first_in_pin, ARG_in_pin_count,
158162
ARG_pull_in_pin_up, ARG_pull_in_pin_down,
@@ -171,6 +175,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
171175
{ MP_QSTR_program, MP_ARG_REQUIRED | MP_ARG_OBJ },
172176
{ MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_INT },
173177
{ MP_QSTR_init, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
178+
{ MP_QSTR_may_exec, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
174179

175180
{ MP_QSTR_first_out_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
176181
{ MP_QSTR_out_pin_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
@@ -220,6 +225,10 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
220225
init_bufinfo.len = 0;
221226
mp_get_buffer(args[ARG_init].u_obj, &init_bufinfo, MP_BUFFER_READ);
222227

228+
mp_buffer_info_t may_exec_bufinfo;
229+
may_exec_bufinfo.len = 0;
230+
mp_get_buffer(args[ARG_may_exec].u_obj, &may_exec_bufinfo, MP_BUFFER_READ);
231+
223232
// We don't validate pin in use here because we may be ok sharing them within a PIO.
224233
const mcu_pin_obj_t *first_out_pin =
225234
validate_obj_is_pin_or_none(args[ARG_first_out_pin].u_obj, MP_QSTR_first_out_pin);
@@ -264,6 +273,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
264273
bufinfo.buf, bufinfo.len / 2,
265274
args[ARG_frequency].u_int,
266275
init_bufinfo.buf, init_bufinfo.len / 2,
276+
may_exec_bufinfo.buf, bufinfo.len / 2,
267277
first_out_pin, out_pin_count, args[ARG_initial_out_pin_state].u_int, args[ARG_initial_out_pin_direction].u_int,
268278
first_in_pin, in_pin_count, args[ARG_pull_in_pin_up].u_int, args[ARG_pull_in_pin_down].u_int,
269279
first_set_pin, set_pin_count, args[ARG_initial_set_pin_state].u_int, args[ARG_initial_set_pin_direction].u_int,

ports/raspberrypi/bindings/rp2pio/StateMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
4141
const uint16_t *program, size_t program_len,
4242
size_t frequency,
4343
const uint16_t *init, size_t init_len,
44+
const uint16_t *may_exec, size_t may_exec_len,
4445
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,
4546
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, uint32_t pull_pin_up, uint32_t pull_pin_down,
4647
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,

ports/raspberrypi/common-hal/audiobusio/I2SOut.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
121121
&self->state_machine,
122122
program, program_len,
123123
44100 * 32 * 6, // Clock at 44.1 khz to warm the DAC up.
124-
NULL, 0,
124+
NULL, 0, // init
125+
NULL, 0, // may_exec
125126
data, 1, 0, 0xffffffff, // out pin
126127
NULL, 0, // in pins
127128
0, 0, // in pulls

ports/raspberrypi/common-hal/audiobusio/PDMIn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
6666
pdmin, MP_ARRAY_SIZE(pdmin),
6767
sample_rate * 32 * 2, // Frequency based on sample rate
6868
NULL, 0,
69+
NULL, 0, // may_exec
6970
NULL, 1, 0, 0xffffffff, // out pin
7071
data_pin, 1, // in pins
7172
0, 0, // in pulls

ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
102102
imagecapture_code, MP_ARRAY_SIZE(imagecapture_code),
103103
common_hal_mcu_processor_get_frequency(), // full speed (4 instructions per loop -> max pclk 30MHz @ 120MHz)
104104
0, 0, // init
105+
NULL, 0, // may_exec
105106
NULL, 0, 0, 0, // out pins
106107
pin_from_number(data_pins[0]), data_count, // in pins
107108
0, 0, // in pulls

ports/raspberrypi/common-hal/paralleldisplay/ParallelBus.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void common_hal_paralleldisplay_parallelbus_construct(paralleldisplay_parallelbu
9898
parallel_program, MP_ARRAY_SIZE(parallel_program),
9999
frequency * 2, // frequency multiplied by 2 as 2 PIO instructions
100100
NULL, 0, // init
101+
NULL, 0, // may_exec
101102
data0, 8, 0, 255, // first out pin, # out pins
102103
NULL, 0, 0, 0, // first in pin, # in pins
103104
NULL, 0, 0, 0, // first set pin

ports/raspberrypi/common-hal/pulseio/PulseIn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
6161
pulsein_program, MP_ARRAY_SIZE(pulsein_program),
6262
1000000, // frequency
6363
NULL, 0, // init, init_len
64+
NULL, 0, // may_exec
6465
NULL, 0, 0, 0, // first out pin, # out pins, initial_out_pin_state
6566
pin, 1, 0, 0, // first in pin, # in pins
6667
NULL, 0, 0, 0, // first set pin

ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
8181
encoder, MP_ARRAY_SIZE(encoder),
8282
1000000,
8383
encoder_init, MP_ARRAY_SIZE(encoder_init), // init
84+
NULL, 0, // may_exec
8485
NULL, 0, 0, 0, // out pin
8586
pins[0], 2, // in pins
8687
3, 0, // in pulls

0 commit comments

Comments
 (0)