|
28 | 28 | // print("line =", line)
|
29 | 29 | //
|
30 | 30 | // # Note: ExtInt will automatically configure the gpio line as an input.
|
31 |
| -// extint = pyb.ExtInt(pin, pyb.ExtInt.MODE_IRQ_FALLING, pyb.GPIO.PULL_UP, callback) |
| 31 | +// extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.GPIO.PULL_UP, callback) |
32 | 32 | //
|
33 | 33 | // Now every time a falling edge is seen on the X1 pin, the callback will be
|
34 | 34 | // called. Caution: mechanical pushbuttons have "bounce" and pushing or
|
|
46 | 46 | //
|
47 | 47 | // extint = pyb.ExtInt(pin, mode, pull, callback)
|
48 | 48 | //
|
49 |
| -// Valid modes are pyb.ExtInt.MODE_IRQ_RISING, pyb.ExtInt.MODE_IRQ_FALLING, |
50 |
| -// pyb.ExtInt.MODE_IRQ_RISING_FALLING, pyb.ExtInt.MODE_EVT_RISING, |
51 |
| -// pyb.ExtInt.MODE_EVT_FALLING, and pyb.ExtInt.MODE_EVT_RISING_FALLING. |
| 49 | +// Valid modes are pyb.ExtInt.IRQ_RISING, pyb.ExtInt.IRQ_FALLING, |
| 50 | +// pyb.ExtInt.IRQ_RISING_FALLING, pyb.ExtInt.EVT_RISING, |
| 51 | +// pyb.ExtInt.EVT_FALLING, and pyb.ExtInt.EVT_RISING_FALLING. |
52 | 52 | //
|
53 |
| -// Only the MODE_IRQ_xxx modes have been tested. The MODE_EVT_xxx modes have |
| 53 | +// Only the IRQ_xxx modes have been tested. The EVT_xxx modes have |
54 | 54 | // something to do with sleep mode and the WFE instruction.
|
55 | 55 | //
|
56 | 56 | // Valid pull values are pyb.GPIO.PULL_UP, pyb.GPIO.PULL_DOWN, pyb.GPIO.PULL_NONE.
|
@@ -241,18 +241,26 @@ STATIC mp_obj_t extint_regs(void) {
|
241 | 241 |
|
242 | 242 | // line_obj = pyb.ExtInt(pin, mode, trigger, callback)
|
243 | 243 |
|
| 244 | +STATIC const mp_arg_parse_t pyb_extint_make_new_accepted_args[] = { |
| 245 | + { MP_QSTR_pin, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, |
| 246 | + { MP_QSTR_mode, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, |
| 247 | + { MP_QSTR_trigger, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, |
| 248 | + { MP_QSTR_callback, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} }, |
| 249 | +}; |
| 250 | +#define PYB_EXTINT_MAKE_NEW_NUM_ARGS (sizeof(pyb_extint_make_new_accepted_args) / sizeof(pyb_extint_make_new_accepted_args[0])) |
| 251 | + |
244 | 252 | STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
245 | 253 | // type_in == extint_obj_type
|
246 | 254 |
|
247 |
| - mp_arg_check_num(n_args, n_kw, 4, 4, false); |
| 255 | + // parse args |
| 256 | + mp_map_t kw_args; |
| 257 | + mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); |
| 258 | + mp_arg_parse_val_t vals[PYB_EXTINT_MAKE_NEW_NUM_ARGS]; |
| 259 | + mp_arg_parse_all(n_args, args, &kw_args, PYB_EXTINT_MAKE_NEW_NUM_ARGS, pyb_extint_make_new_accepted_args, vals); |
248 | 260 |
|
249 | 261 | extint_obj_t *self = m_new_obj(extint_obj_t);
|
250 | 262 | self->base.type = type_in;
|
251 |
| - mp_obj_t line_obj = args[0]; |
252 |
| - mp_obj_t mode_obj = args[1]; |
253 |
| - mp_obj_t trigger_obj = args[2]; |
254 |
| - mp_obj_t callback_obj = args[3]; |
255 |
| - self->line = extint_register(line_obj, mode_obj, trigger_obj, callback_obj, false, NULL); |
| 263 | + self->line = extint_register(vals[0].u_obj, vals[1].u_obj, vals[2].u_obj, vals[3].u_obj, false, NULL); |
256 | 264 |
|
257 | 265 | return self;
|
258 | 266 | }
|
|
0 commit comments