8000 esp8266/machine_pin: Implement pin ioctl protocol. · micropython/micropython@18b6835 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18b6835

Browse files
author
Paul Sokolovsky
committed
esp8266/machine_pin: Implement pin ioctl protocol.
For polymorphic interfacing on C level.
1 parent 0ddeedf commit 18b6835

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

esp8266/machine_pin.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/runtime.h"
3838
#include "py/gc.h"
3939
#include "py/mphal.h"
40+
#include "extmod/virtpin.h"
4041
#include "modmachine.h"
4142

4243
#define GET_TRIGGER(phys_port) \
@@ -374,6 +375,23 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
374375
}
375376
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_pin_irq_obj, 1, pyb_pin_irq);
376377

378+
STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode);
379+
STATIC mp_uint_t pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
380+
(void)errcode;
381+
pyb_pin_obj_t *self = self_in;
382+
383+
switch (request) {
384+
case MP_PIN_READ: {
385+
return pin_get(self->phys_port);
386+
}
387+
case MP_PIN_WRITE: {
388+
pin_set(self->phys_port, arg);
389+
return 0;
390+
}
391+
}
392+
return -1;
393+
}
394+
377395
STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
378396
// instance methods
379397
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pyb_pin_init_obj },
@@ -396,12 +414,17 @@ STATIC const mp_map_elem_t pyb_pin_locals_dict_table[] = {
396414

397415
STATIC MP_DEFINE_CONST_DICT(pyb_pin_locals_dict, pyb_pin_locals_dict_table);
398416

417+
STATIC const mp_pin_p_t pin_pin_p = {
418+
.ioctl = pin_ioctl,
419+
};
420+
399421
const mp_obj_type_t pyb_pin_type = {
400422
{ &mp_type_type },
401423
.name = MP_QSTR_Pin,
402424
.print = pyb_pin_print,
403425
.make_new = pyb_pin_make_new,
404426
.call = pyb_pin_call,
427+
.protocol = &pin_pin_p,
405428
.locals_dict = (mp_obj_t)&pyb_pin_locals_dict,
406429
};
407430

0 commit comments

Comments
 (0)
0