summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2024-04-03 19:01:39 +0200
committerDamien George <damien@micropython.org>2024-07-23 14:55:35 +1000
commit594c4229b7aaa7b62ef2b24f47feeb7071714a0d (patch)
tree03e02e012c7f0e9c10ad53ed20da6ac0314eb6df
parent46c3df0229c81d5a6274e57315558404273b2fae (diff)
downloadmicropython-594c4229b7aaa7b62ef2b24f47feeb7071714a0d.tar.gz
micropython-594c4229b7aaa7b62ef2b24f47feeb7071714a0d.zip
esp32/machine_timer: 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>
-rw-r--r--ports/esp32/machine_timer.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ports/esp32/machine_timer.c b/ports/esp32/machine_timer.c
index 5e249e46e6..011f87ba9e 100644
--- a/ports/esp32/machine_timer.c
+++ b/ports/esp32/machine_timer.c
@@ -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;