8000 stmhal: Update ExtInt to allow keyword arguments in constructor. · errordeveloper/micropython@0a6e9f5 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 0a6e9f5

Browse files
committed
stmhal: Update ExtInt to allow keyword arguments in constructor.
1 parent 57e4158 commit 0a6e9f5

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

stmhal/extint.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// print("line =", line)
2929
//
3030
// # 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)
3232
//
3333
// Now every time a falling edge is seen on the X1 pin, the callback will be
3434
// called. Caution: mechanical pushbuttons have "bounce" and pushing or
@@ -46,11 +46,11 @@
4646
//
4747
// extint = pyb.ExtInt(pin, mode, pull, callback)
4848
//
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.
5252
//
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
5454
// something to do with sleep mode and the WFE instruction.
5555
//
5656
// 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) {
241241

242242
// line_obj = pyb.ExtInt(pin, mode, trigger, callback)
243243

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+
244252
STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
245253
// type_in == extint_obj_type
246254

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);
248260

249261
extint_obj_t *self = m_new_obj(extint_obj_t);
250262
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);
256264

257265
return self;
258266
}

stmhal/qstrdefsport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Q(send)
8888

8989
// for ExtInt class
9090
Q(ExtInt)
91+
Q(pin)
92+
Q(mode)
93+
Q(trigger)
94+
Q(callback)
9195
Q(line)
9296
Q(enable)
9397
Q(disable)

stmhal/spi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ STATIC const mp_arg_parse_t pyb_spi_init_accepted_args[] = {
160160
{ MP_QSTR_ti, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_BOOL, {.u_bool = false} },
161161
{ MP_QSTR_crcpoly, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_OBJ, {.u_obj = mp_const_none} },
162162
};
163-
164163
#define PYB_SPI_INIT_NUM_ARGS (sizeof(pyb_spi_init_accepted_args) / sizeof(pyb_spi_init_accepted_args[0]))
165164

166165
STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {

0 commit comments

Comments
 (0)
0