diff options
| author | Damien George | 2017-01-31 12:36:04 +1100 |
|---|---|---|
| committer | Damien George | 2017-01-31 12:36:04 +1100 |
| commit | e24e03b41591bdfac832d60f77b1ad63e5c0c2c6 (patch) | |
| tree | c86caa7a8c7f6b1c3bb43f374c15335be4f86e3d | |
| parent | b039d93d7e0d43bb45e0c36a28f02d580acbf5ea (diff) | |
stmhal/pin: Add C-level pin ioctl method.
| -rw-r--r-- | stmhal/pin.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/stmhal/pin.c b/stmhal/pin.c index 9c4eb8ba1..29370e6a2 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -31,6 +31,7 @@ #include "py/nlr.h" #include "py/runtime.h" #include "py/mphal.h" +#include "extmod/virtpin.h" #include "pin.h" /// \moduleref pyb @@ -542,12 +543,33 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table); +STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { + (void)errcode; + pin_obj_t *self = self_in; + + switch (request) { + case MP_PIN_READ: { + return mp_hal_pin_read(self); + } + case MP_PIN_WRITE: { + mp_hal_pin_write(self, arg); + return 0; + } + } + return -1; +} + +STATIC const mp_pin_p_t pin_pin_p = { + .ioctl = pin_ioctl, +}; + const mp_obj_type_t pin_type = { { &mp_type_type }, .name = MP_QSTR_Pin, .print = pin_print, .make_new = pin_make_new, .call = pin_call, + .protocol = &pin_pin_p, .locals_dict = (mp_obj_t)&pin_locals_dict, }; |
