Skip to content

Commit 2507c83

Browse files
committed
esp8266/machine_pin: Add "hard" parameter to pin.irq, soft by default.
1 parent 31ea158 commit 2507c83

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

esp8266/machine_pin.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ STATIC uint8_t pin_mode[16 + 1];
8787
// forward declaration
8888
STATIC const pin_irq_obj_t pin_irq_obj[16];
8989

90+
// whether the irq is hard or soft
91+
STATIC bool pin_irq_is_hard[16];
92+
9093
void pin_init0(void) {
9194
ETS_GPIO_INTR_DISABLE();
9295
ETS_GPIO_INTR_ATTACH(pin_intr_handler_iram, NULL);
9396
// disable all interrupts
9497
memset(&MP_STATE_PORT(pin_irq_handler)[0], 0, 16 * sizeof(mp_obj_t));
98+
memset(pin_irq_is_hard, 0, sizeof(pin_irq_obj));
9599
for (int p = 0; p < 16; ++p) {
96100
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << p);
97101
SET_TRIGGER(p, 0);
@@ -107,7 +111,11 @@ void pin_intr_handler(uint32_t status) {
107111
if (status & 1) {
108112
mp_obj_t handler = MP_STATE_PORT(pin_irq_handler)[p];
109113
if (handler != MP_OBJ_NULL) {
110-
mp_call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
114+
if (pin_irq_is_hard[p]) {
115+
mp_call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
116+
} else {
117+
mp_sched_schedule(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
118+
}
111119
}
112120
}
113121
}
@@ -346,10 +354,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_high_obj, pyb_pin_high);
346354

347355
// pin.irq(*, trigger, handler=None)
348356
STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
349-
enum { ARG_trigger, ARG_handler };
357+
enum { ARG_trigger, ARG_handler, ARG_hard };
350358
static const mp_arg_t allowed_args[] = {
351359
{ MP_QSTR_trigger, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
352360
{ MP_QSTR_handler, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
361+
{ MP_QSTR_hard, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
353362
};
354363
pyb_pin_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
355364
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -367,6 +376,7 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
367376
}
368377
ETS_GPIO_INTR_DISABLE();
369378
MP_STATE_PORT(pin_irq_handler)[self->phys_port] = handler;
379+
pin_irq_is_hard[self->phys_port] = args[ARG_hard].u_bool;
370380
SET_TRIGGER(self->phys_port, args[ARG_trigger].u_int);
371381
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << self->phys_port);
372382
ETS_GPIO_INTR_ENABLE();

0 commit comments

Comments
 (0)