summaryrefslogtreecommitdiff
path: root/shared-bindings/microcontroller/Pin.c
diff options
context:
space:
mode:
authorAnson He <ansonhe1997@gmail.com>2020-07-28 17:03:10 +0800
committerGitHub <noreply@github.com>2020-07-28 17:03:10 +0800
commitc010cc2c414a98caa1aa510497666bf017c792ab (patch)
treedac841881017719bae0654a64cbc52f35cf6977a /shared-bindings/microcontroller/Pin.c
parent36ef3476de945071da9c1274e5b4d8bcdcc13d13 (diff)
parentdebbf1028adee2309ed991c90517c50d5eb13bfb (diff)
Merge pull request #1 from adafruit/main
Merged main to fork
Diffstat (limited to 'shared-bindings/microcontroller/Pin.c')
-rw-r--r--shared-bindings/microcontroller/Pin.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c
index 765e602e5..1294b78f0 100644
--- a/shared-bindings/microcontroller/Pin.c
+++ b/shared-bindings/microcontroller/Pin.c
@@ -36,10 +36,10 @@
//| class Pin:
//| """Identifies an IO pin on the microcontroller."""
//|
-//| def __init__(self, ):
+//| def __init__(self) -> None:
//| """Identifies an IO pin on the microcontroller. They are fixed by the
//| hardware so they cannot be constructed on demand. Instead, use
-//| `board` or `microcontroller.pin` to reference the desired pin."""
+//| :mod:`board` or :mod:`microcontroller.pin` to reference the desired pin."""
//| ...
//|
@@ -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) {