37
37
#include "py/runtime.h"
38
38
#include "py/gc.h"
39
39
#include "py/mphal.h"
40
+ #include "extmod/virtpin.h"
40
41
#include "modmachine.h"
41
42
42
43
#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
374
375
}
375
376
STATIC MP_DEFINE_CONST_FUN_OBJ_KW (pyb_pin_irq_obj , 1 , pyb_pin_irq );
376
377
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
+
377
395
STATIC const mp_map_elem_t pyb_pin_locals_dict_table [] = {
378
396
// instance methods
379
397
{ 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[] = {
396
414
397
415
STATIC MP_DEFINE_CONST_DICT (pyb_pin_locals_dict , pyb_pin_locals_dict_table );
398
416
417
+ STATIC const mp_pin_p_t pin_pin_p = {
418
+ .ioctl = pin_ioctl ,
419
+ };
420
+
399
421
const mp_obj_type_t pyb_pin_type = {
400
422
{ & mp_type_type },
401
423
.name = MP_QSTR_Pin ,
402
424
.print = pyb_pin_print ,
403
425
.make_new = pyb_pin_make_new ,
404
426
.call = pyb_pin_call ,
427
+ .protocol = & pin_pin_p ,
405
428
.locals_dict = (mp_obj_t )& pyb_pin_locals_dict ,
406
429
};
407
430
0 commit comments