Check that neopixel write is actually given a DigitalInOut.

This commit is contained in:
Scott Shawcroft 2017-02-22 20:10:10 +01:00
parent fc718d9437
commit 4c05086661
2 changed files with 5 additions and 1 deletions

View File

@ -74,7 +74,7 @@ const mp_obj_type_t mcu_pin_type = {
void assert_pin(mp_obj_t obj, bool none_ok) { 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)) { 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")); nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", mcu_pin_type.name));
} }
} }

View File

@ -30,6 +30,7 @@
#include "common-hal/nativeio/types.h" #include "common-hal/nativeio/types.h"
#include "shared-bindings/nativeio/DigitalInOut.h"
#include "shared-bindings/neopixel_write/__init__.h" #include "shared-bindings/neopixel_write/__init__.h"
//| :mod:`neopixel_write` --- Low-level neopixel implementation //| :mod:`neopixel_write` --- Low-level neopixel implementation
@ -50,6 +51,9 @@
//| :param bytearray buf: The bytes to clock out. No assumption is made about color order //| :param bytearray buf: The bytes to clock out. No assumption is made about color order
//| //|
STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) { STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) {
if (!MP_OBJ_IS_TYPE(digitalinout_obj, &nativeio_digitalinout_type)) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Expected a %q", nativeio_digitalinout_type.name));
}
// Convert parameters into expected types. // Convert parameters into expected types.
const nativeio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj); const nativeio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj);
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;