@@ -37,17 +37,23 @@ typedef struct _pyb_wdt_obj_t {
3737
3838STATIC pyb_wdt_obj_t pyb_wdt = {{& pyb_wdt_type }};
3939
40- STATIC mp_obj_t pyb_wdt_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
41- // check arguments
42- mp_arg_check_num (n_args , n_kw , 2 , 2 , false);
43-
44- mp_int_t id = mp_obj_get_int (args [0 ]);
40+ STATIC mp_obj_t pyb_wdt_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * all_args ) {
41+ // parse arguments
42+ enum { ARG_id , ARG_timeout };
43+ static const mp_arg_t allowed_args [] = {
44+ { MP_QSTR_id , MP_ARG_INT , {.u_int = 0 } },
45+ { MP_QSTR_timeout , MP_ARG_INT , {.u_int = 5000 } },
46+ };
47+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
48+ mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
49+
50+ mp_int_t id = args [ARG_id ].u_int ;
4551 if (id != 0 ) {
4652 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ValueError , "WDT(%d) does not exist" , id ));
4753 }
4854
4955 // timeout is in milliseconds
50- mp_int_t timeout = mp_obj_get_int ( args [1 ]) ;
56+ mp_int_t timeout = args [ARG_timeout ]. u_int ;
5157
5258 // compute prescaler
5359 uint32_t prescaler ;
0 commit comments