diff options
| author | Damien George <damien@micropython.org> | 2025-07-06 22:00:27 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-07-08 11:15:11 +1000 |
| commit | bf432a3e0f542321b15fcc775f62f072ba56f29d (patch) | |
| tree | 7f12abc72f30eb47b2520db1e04167dead7cd861 | |
| parent | 0fd65c44cf23b22a582a86409ca8408077dd0a94 (diff) | |
zephyr/machine_timer: Make machine.Timer id argument optional.
With a default of -1, for soft timer. This matches other ports, and the
`extmod/machine_timer.c` implementation.
This change allows the `tests/extmod/machine_soft_timer.py` test to pass.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/zephyr/machine_timer.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ports/zephyr/machine_timer.c b/ports/zephyr/machine_timer.c index 8ab2f6291..1bb743c2e 100644 --- a/ports/zephyr/machine_timer.c +++ b/ports/zephyr/machine_timer.c @@ -77,9 +77,14 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr } static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); - - if (mp_obj_get_int(args[0]) != -1) { + // Get timer id (only soft timer (-1) supported at the moment) + mp_int_t id = -1; + if (n_args > 0) { + id = mp_obj_get_int(args[0]); + --n_args; + ++args; + } + if (id != -1) { mp_raise_ValueError(MP_ERROR_TEXT("only virtual timers are supported")); } @@ -90,10 +95,10 @@ static mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, self->next = MP_STATE_PORT(machine_timer_obj_head); MP_STATE_PORT(machine_timer_obj_head) = self; - if (n_args > 1 || n_kw > 0) { + if (n_args > 0 || n_kw > 0) { mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); - machine_timer_init_helper(self, n_args - 1, args + 1, &kw_args); + machine_timer_init_helper(self, n_args, args, &kw_args); } return self; } |
