diff options
| author | robert-hh <robert@hammelrath.com> | 2023-06-17 16:07:58 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-09-02 17:09:51 +1000 |
| commit | 9f1576f2ade989d10c9504450f69779d48f9674c (patch) | |
| tree | 020ed6d647a969564b45a107decdb6d4c2d4899a | |
| parent | 6aa404ca53e3ebd1f234a8d62259a1e660a4132c (diff) | |
rp2/machine_timer: Fix printing of timer period.
Showing the period alway as microsecond quantities, since tick_hz is
assumed as 1_000_000 if the period is given by freq=xxx. If the period is
larger than 0xffffffff, the value is divided by 1000 and "000" is appended
in the display. That works for periods up to about 50 days.
Signed-off-by: robert-hh <robert@hammelrath.com>
| -rw-r--r-- | ports/rp2/machine_timer.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ports/rp2/machine_timer.c b/ports/rp2/machine_timer.c index e4fbb03af..f0df541e6 100644 --- a/ports/rp2/machine_timer.c +++ b/ports/rp2/machine_timer.c @@ -57,7 +57,12 @@ STATIC int64_t alarm_callback(alarm_id_t id, void *user_data) { STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { machine_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); qstr mode = self->mode == TIMER_MODE_ONE_SHOT ? MP_QSTR_ONE_SHOT : MP_QSTR_PERIODIC; - mp_printf(print, "Timer(mode=%q, period=%u, tick_hz=1000000)", mode, self->delta_us); + mp_printf(print, "Timer(mode=%q, tick_hz=1000000, period=", mode); + if (self->delta_us <= 0xffffffff) { + mp_printf(print, "%u)", (uint32_t)self->delta_us); + } else { + mp_printf(print, "%u000)", (uint32_t)(self->delta_us / 1000)); + } } STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
