Skip to content

Commit d0f927c

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 d0f927c

File tree

10 files changed

+169
-177
lines changed

10 files changed

+169
-177
lines changed

locale/circuitpython.pot

Lines changed: 28 additions & 74 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

@@ -2765,10 +2755,6 @@ msgstr ""
27652755
msgid "cannot create instance"
27662756
msgstr ""
27672757

2768-
#: extmod/ulab/code/ndarray.c
2769-
msgid "cannot delete array elements"
2770-
msgstr ""
2771-
27722758
#: py/runtime.c
27732759
msgid "cannot import name %q"
27742760
msgstr ""
@@ -3226,14 +3212,6 @@ msgstr ""
32263212
msgid "inline assembler must be a function"
32273213
msgstr ""
32283214

3229-
#: extmod/ulab/code/numpy/vector.c
3230-
msgid "input and output dimensions differ"
3231-
msgstr ""
3232-
3233-
#: extmod/ulab/code/numpy/vector.c
3234-
msgid "input and output shapes differ"
3235-
msgstr ""
3236-
32373215
#: extmod/ulab/code/numpy/create.c
32383216
msgid "input argument must be an integer, a tuple, or a list"
32393217
msgstr ""
@@ -3562,10 +3540,6 @@ msgstr ""
35623540
msgid "native yield"
35633541
msgstr ""
35643542

3565-
#: extmod/ulab/code/ndarray.c
3566-
msgid "ndarray length overflows"
3567-
msgstr ""
3568-
35693543
#: py/runtime.c
35703544
#, c-format
35713545
msgid "need more than %d values to unpack"
@@ -3664,10 +3638,6 @@ msgstr ""
36643638
msgid "not implemented for complex dtype"
36653639
msgstr ""
36663640

3667-
#: extmod/ulab/code/numpy/bitwise.c
3668-
msgid "not supported for input types"
3669-
msgstr ""
3670-
36713641
#: extmod/ulab/code/numpy/create.c
36723642
msgid "number of points must be at least 2"
36733643
msgstr ""
@@ -3778,8 +3748,8 @@ msgstr ""
37783748
msgid "opcode"
37793749
msgstr ""
37803750

3781-
#: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/bitwise.c
3782-
#: extmod/ulab/code/numpy/compare.c extmod/ulab/code/numpy/vector.c
3751+
#: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare.c
3752+
#: extmod/ulab/code/numpy/vector.c
37833753
msgid "operands could not be broadcast together"
37843754
msgstr ""
37853755

@@ -3816,26 +3786,10 @@ msgstr ""
38163786
msgid "out array is too small"
38173787
msgstr ""
38183788

3819-
#: extmod/ulab/code/numpy/vector.c
3820-
msgid "out keyword is not supported for complex dtype"
3821-
msgstr ""
3822-
3823-
#: extmod/ulab/code/numpy/vector.c
3824-
msgid "out keyword is not supported for function"
3825-
msgstr ""
3826-
38273789
#: extmod/ulab/code/utils/utils.c
38283790
msgid "out must be a float dense array"
38293791
msgstr ""
38303792

3831-
#: extmod/ulab/code/numpy/vector.c
3832-
msgid "out must be an ndarray"
3833-
msgstr ""
3834-
3835-
#: extmod/ulab/code/numpy/vector.c
3836-
msgid "out must be of float dtype"
3837-
msgstr ""
3838-
38393793
#: shared-bindings/bitmaptools/__init__.c
38403794
msgid "out of range of target"
38413795
msgstr ""
@@ -4021,7 +3975,7 @@ msgstr ""
40213975
msgid "sosfilt requires iterable arguments"
40223976
msgstr ""
40233977

4024-
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
3978+
#: shared-bindings/bitmaptools/__init__.c
40253979
msgid "source palette too large"
40263980
msgstr ""
40273981

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
//| jmp_pin_pull: Optional[digitalio.Pull] = None,
8585
//| exclusive_pin_use: bool = True,
8686
//| auto_pull: bool = False,
87+
//| auto_pull: bool = False,
8788
//| pull_threshold: int = 32,
8889
//| out_shift_right: bool = True,
8990
//| wait_for_txstall: bool = True,
@@ -100,6 +101,10 @@
100101
//| :param int frequency: the target clock frequency of the state machine. Actual may be less. Use 0 for system clock speed.
101102
//| :param ReadableBuffer init: a program to run once at start up. This is run after program
102103
//| is started so instructions may be intermingled
104+
//| :param ReadableBuffer may_exec: Instructions that may be executed via `StateMachine.exec` calls.
105+
//| Some elements of the `StateMachine`'s configuration are inferred from the instructions used;
106+
//| for instance, if there is no ``in`` or ``push`` instruction, then the `StateMachine` is configured without a receive FIFO.
107+
//| In this case, passing a ``may_exec`` program containing an ``in`` instruction such as ``in x``, a receive FIFO will be configured.
103108
//| :param ~microcontroller.Pin first_out_pin: the first pin to use with the OUT instruction
104109
//| :param int out_pin_count: the count of consecutive pins to use with OUT starting at first_out_pin
105110
//| :param int initial_out_pin_state: the initial output value for out pins starting at first_out_pin
@@ -152,7 +157,7 @@
152157
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) {
153158
rp2pio_statemachine_obj_t *self = m_new_obj(rp2pio_statemachine_obj_t);
154159
self->base.type = &rp2pio_statemachine_type;
155-
enum { ARG_program, ARG_frequency, ARG_init,
160+
enum { ARG_program, ARG_frequency, ARG_init, ARG_may_exec,
156161
ARG_first_out_pin, ARG_out_pin_count, ARG_initial_out_pin_state, ARG_initial_out_pin_direction,
157162
ARG_first_in_pin, ARG_in_pin_count,
158163
ARG_pull_in_pin_up, ARG_pull_in_pin_down,
@@ -171,6 +176,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
171176
{ MP_QSTR_program, MP_ARG_REQUIRED | MP_ARG_OBJ },
172177
{ MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_INT },
173178
{ MP_QSTR_init, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
179+
{ MP_QSTR_may_exec, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
174180

175181
{ MP_QSTR_first_out_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
176182
{ MP_QSTR_out_pin_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} },
@@ -220,6 +226,10 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
220226
init_bufinfo.len = 0;
221227
mp_get_buffer(args[ARG_init].u_obj, &init_bufinfo, MP_BUFFER_READ);
222228

229+
mp_buffer_info_t may_exec_bufinfo;
230+
may_exec_bufinfo.len = 0;
231+
mp_get_buffer(args[ARG_may_exec].u_obj, &may_exec_bufinfo, MP_BUFFER_READ);
232+
223233
// We don't validate pin in use here because we may be ok sharing them within a PIO.
224234
const mcu_pin_obj_t *first_out_pin =
225235
validate_obj_is_pin_or_none(args[ARG_first_out_pin].u_obj, MP_QSTR_first_out_pin);
@@ -264,6 +274,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
264274
bufinfo.buf, bufinfo.len / 2,
265275
args[ARG_frequency].u_int,
266276
init_bufinfo.buf, init_bufinfo.len / 2,
277+
may_exec_bufinfo.buf, bufinfo.len / 2,
267278
first_out_pin, out_pin_count, args[ARG_initial_out_pin_state].u_int, args[ARG_initial_out_pin_direction].u_int,
268279
first_in_pin, in_pin_count, args[ARG_pull_in_pin_up].u_int, args[ARG_pull_in_pin_down].u_int,
269280
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)