esp8266/machine_pin: Make pin.irq arguments positional.
All arguments to pin.irq are converted from keyword-only to positional, and can still be specified by keyword so it's a backwards compatible change. The default value for the "trigger" arg is changed from 0 (no trigger) to rising+falling edge.
This commit is contained in:
parent
2507c83b0e
commit
9ee4641850
|
@ -352,13 +352,13 @@ STATIC mp_obj_t pyb_pin_high(mp_obj_t self_in) {
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_high_obj, pyb_pin_high);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_pin_high_obj, pyb_pin_high);
|
||||||
|
|
||||||
// pin.irq(*, trigger, handler=None)
|
// pin.irq(handler=None, trigger=IRQ_FALLING|IRQ_RISING, hard=False)
|
||||||
STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum { ARG_trigger, ARG_handler, ARG_hard };
|
enum { ARG_handler, ARG_trigger, ARG_hard };
|
||||||
static const mp_arg_t allowed_args[] = {
|
static const mp_arg_t allowed_args[] = {
|
||||||
{ MP_QSTR_trigger, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
{ MP_QSTR_handler, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||||
{ MP_QSTR_handler, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
{ MP_QSTR_trigger, MP_ARG_INT, {.u_int = GPIO_PIN_INTR_POSEDGE | GPIO_PIN_INTR_NEGEDGE} },
|
||||||
{ MP_QSTR_hard, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
{ MP_QSTR_hard, MP_ARG_BOOL, {.u_bool = false} },
|
||||||
};
|
};
|
||||||
pyb_pin_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
pyb_pin_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
|
@ -368,16 +368,18 @@ STATIC mp_obj_t pyb_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "pin does not have IRQ capabilities"));
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "pin does not have IRQ capabilities"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[ARG_trigger].u_int != 0) {
|
if (n_args > 1) {
|
||||||
// configure irq
|
// configure irq
|
||||||
mp_obj_t handler = args[ARG_handler].u_obj;
|
mp_obj_t handler = args[ARG_handler].u_obj;
|
||||||
|
uint32_t trigger = args[ARG_trigger].u_int;
|
||||||
if (handler == mp_const_none) {
|
if (handler == mp_const_none) {
|
||||||
handler = MP_OBJ_NULL;
|
handler = MP_OBJ_NULL;
|
||||||
|
trigger = 0;
|
||||||
}
|
}
|
||||||
ETS_GPIO_INTR_DISABLE();
|
ETS_GPIO_INTR_DISABLE();
|
||||||
MP_STATE_PORT(pin_irq_handler)[self->phys_port] = handler;
|
MP_STATE_PORT(pin_irq_handler)[self->phys_port] = handler;
|
||||||
pin_irq_is_hard[self->phys_port] = args[ARG_hard].u_bool;
|
pin_irq_is_hard[self->phys_port] = args[ARG_hard].u_bool;
|
||||||
SET_TRIGGER(self->phys_port, args[ARG_trigger].u_int);
|
SET_TRIGGER(self->phys_port, trigger);
|
||||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << self->phys_port);
|
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << self->phys_port);
|
||||||
ETS_GPIO_INTR_ENABLE();
|
ETS_GPIO_INTR_ENABLE();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue