diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-07-13 15:53:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-13 15:53:44 -0700 |
| commit | d712d1281c6f7bde36629767ce429cc646ed0a29 (patch) | |
| tree | 6cb982ba12020332f2d9cbed3eb515ccdf8f510e /shared-bindings/microcontroller/Pin.c | |
| parent | c8752ff93eb62f115e9129f7b2d20d8ed5a8ed88 (diff) | |
| parent | 3fcd999130fcd87ccbabb65dbe6a6a6cadc08d90 (diff) | |
Merge branch 'main' into master
Diffstat (limited to 'shared-bindings/microcontroller/Pin.c')
| -rw-r--r-- | shared-bindings/microcontroller/Pin.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 765e602e5..d5b971ae5 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<len; i++) { + pins_out[i] = validate_obj_is_free_pin(mp_obj_subscr(seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL)); + } +} + // Validate that the obj is a free pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly. mcu_pin_obj_t *validate_obj_is_free_pin_or_none(mp_obj_t obj) { if (obj == mp_const_none) { |
