esp32/machine_timer.c: Limit timer numbers for ESP32C3.

The ESP32C3 has only two timers in one group.
In the code this is reflected as two groups with one timer.

Signed-off-by: robert-hh <robert@hammelrath.com>
pull/14245/head
robert-hh 2024-04-03 19:01:39 +02:00
rodzic 5114f2c1ea
commit 75a9f35ab9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 32EC5F755D5A3A93
1 zmienionych plików z 10 dodań i 1 usunięć

Wyświetl plik

@ -54,7 +54,7 @@ typedef struct _machine_timer_obj_t {
mp_uint_t index;
mp_uint_t repeat;
// ESP32 timers are 64-bit
// ESP32 timers are 64 or 54-bit
uint64_t period;
mp_obj_t callback;
@ -84,13 +84,22 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
machine_timer_obj_t *self = self_in;
qstr mode = self->repeat ? MP_QSTR_PERIODIC : MP_QSTR_ONE_SHOT;
uint64_t period = self->period / (TIMER_SCALE / 1000); // convert to ms
#if CONFIG_IDF_TARGET_ESP32C3
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", self->group, mode, period);
#else
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", (self->group << 1) | self->index, mode, period);
#endif
}
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 CONFIG_IDF_TARGET_ESP32C3
mp_uint_t group = mp_obj_get_int(args[0]) & 1;
mp_uint_t index = 0;
#else
mp_uint_t group = (mp_obj_get_int(args[0]) >> 1) & 1;
mp_uint_t index = mp_obj_get_int(args[0]) & 1;
#endif
machine_timer_obj_t *self = NULL;