8000 mimxrt/machine_pin: Implement ioctl for Pin. · micropython/micropython@a1dc727 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1dc727

Browse files
alphaFreddpgeorge
authored andcommitted
mimxrt/machine_pin: Implement ioctl for Pin.
To make machine.Signal work correctly (among other things). The solution is taken over from the rp2 port. Signed-off-by: Philipp Ebensberger
1 parent c70930f commit a1dc727

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ports/mimxrt/machine_pin.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/runtime.h"
3333
#include "py/mphal.h"
3434
#include "shared/runtime/mpirq.h"
35+
#include "extmod/virtpin.h"
3536
#include "pin.h"
3637

3738
// Local functions
@@ -425,12 +426,34 @@ STATIC const mp_rom_map_elem_t machine_pin_locals_dict_table[] = {
425426
};
426427
STATIC MP_DEFINE_CONST_DICT(machine_pin_locals_dict, machine_pin_locals_dict_table);
427428

429+
430+
STATIC mp_uint_t machine_pin_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
431+
(void)errcode;
432+
machine_pin_obj_t *self = self_in;
433+
434+
switch (request) {
435+
case MP_PIN_READ: {
436+
return mp_hal_pin_read(self);
437+
}
438+
case MP_PIN_WRITE: {
439+
mp_hal_pin_write(self, arg);
440+
return 0;
441+
}
442+
}
443+
return -1;
444+
}
445+
446+
STATIC const mp_pin_p_t machine_pin_obj_protocol = {
447+
.ioctl = machine_pin_ioctl,
448+
};
449+
428450
const mp_obj_type_t machine_pin_type = {
429451
{&mp_type_type},
430452
.name = MP_QSTR_Pin,
431453
.print = machine_pin_obj_print,
432454
.call = machine_pin_obj_call,
433455
.make_new = mp_pin_make_new,
456+
.protocol = &machine_pin_obj_protocol,
434457
.locals_dict = (mp_obj_dict_t *)&machine_pin_locals_dict,
435458
};
436459

0 commit comments

Comments
 (0)
0