From 159728b550c70f239e03c267a23f3950de635d3a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 27 May 2020 09:09:39 -0500 Subject: [PATCH] shared-bindings: Factor out validate_list_is_free_pins This will ultimately be used by SDIO, where a variable length list of data lines is called for. --- locale/circuitpython.pot | 2 +- shared-bindings/microcontroller/Pin.c | 12 ++++++++++++ shared-bindings/microcontroller/Pin.h | 1 + shared-bindings/rgbmatrix/RGBMatrix.c | 11 ++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 55147dc03e..9a5a788b08 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -338,7 +338,7 @@ msgstr "" msgid "Array values should be single bytes." msgstr "" -#: shared-bindings/rgbmatrix/RGBMatrix.c +#: shared-bindings/microcontroller/Pin.c msgid "At most %d %q may be specified (not %d)" msgstr "" diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 765e602e5f..d5b971ae5e 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -101,6 +101,18 @@ mcu_pin_obj_t *validate_obj_is_free_pin(mp_obj_t obj) { return pin; } +// Validate every element in the list to be a free pin. +void validate_list_is_free_pins(qstr what, mcu_pin_obj_t **pins_out, mp_int_t max_pins, mp_obj_t seq, uint8_t *count_out) { + mp_int_t len = MP_OBJ_SMALL_INT_VALUE(mp_obj_len(seq)); + if (len > max_pins) { + mp_raise_ValueError_varg(translate("At most %d %q may be specified (not %d)"), max_pins, what, len); + } + *count_out = len; + for (mp_int_t i=0; i max_pins) { - mp_raise_ValueError_varg(translate("At most %d %q may be specified (not %d)"), max_pins, what, len); - } - *count_out = len; - for (mp_int_t i=0; i