diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2016-11-29 15:49:50 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2016-11-29 15:50:01 -0800 |
| commit | 4933fa1c27f987be558a33b1736089b04e880a03 (patch) | |
| tree | 973345cef69c216a897c6ba670ab238ea0e2c2f3 /shared-bindings/microcontroller/Pin.c | |
| parent | 72455e441fb70a6a3f01b20ecb760f6f3f6f84ec (diff) | |
shared-bindings: Ensure pin objects are actually pins.
Fixes #12
Diffstat (limited to 'shared-bindings/microcontroller/Pin.c')
| -rw-r--r-- | shared-bindings/microcontroller/Pin.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 733fa29ec..c691a9a17 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -26,6 +26,9 @@ #include "shared-bindings/microcontroller/Pin.h" +#include "py/nlr.h" +#include "py/obj.h" + //| .. currentmodule:: microcontroller //| //| :class:`Pin` --- Pin reference @@ -44,3 +47,9 @@ const mp_obj_type_t mcu_pin_type = { { &mp_type_type }, .name = MP_QSTR_Pin, }; + +void assert_pin(mp_obj_t obj, bool none_ok) { + if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Expected a Pin")); + } +} |
