esp32/machine_timer: Fix timer.value() for an uninitialized timer.
Raises a value error in that case, which happens after a timer was created but not initialized, or after calling `timer.deinit()`. Fixes issue #17033. Signed-off-by: robert-hh <robert@hammelrath.com>
This commit is contained in:
parent
d7371124d2
commit
1d4bf8ac40
1 changed files with 3 additions and 0 deletions
|
|
@ -246,6 +246,9 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(machine_timer_init_obj, 1, machine_timer_init)
|
|||
|
||||
static mp_obj_t machine_timer_value(mp_obj_t self_in) {
|
||||
machine_timer_obj_t *self = self_in;
|
||||
if (self->handle == NULL) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("timer not set"));
|
||||
}
|
||||
uint64_t result = timer_ll_get_counter_value(self->hal_context.dev, self->index);
|
||||
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)(result / (TIMER_SCALE / 1000))); // value in ms
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue