Skip to content

Commit 594c422

Browse files
robert-hhdpgeorge
authored andcommitted
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 <[email protected]>
1 parent 46c3df0 commit 594c422

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ports/esp32/machine_timer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct _machine_timer_obj_t {
5454
mp_uint_t index;
5555

5656
mp_uint_t repeat;
57-
// ESP32 timers are 64-bit
57+
// ESP32 timers are 64 or 54-bit
5858
uint64_t period;
5959

6060
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
8484
machine_timer_obj_t *self = self_in;
8585
qstr mode = self->repeat ? MP_QSTR_PERIODIC : MP_QSTR_ONE_SHOT;
8686
uint64_t period = self->period / (TIMER_SCALE / 1000); // convert to ms
87+
#if CONFIG_IDF_TARGET_ESP32C3
88+
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", self->group, mode, period);
89+
#else
8790
mp_printf(print, "Timer(%u, mode=%q, period=%lu)", (self->group << 1) | self->index, mode, period);
91+
#endif
8892
}
8993

9094
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) {
9195
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
96+
#if CONFIG_IDF_TARGET_ESP32C3
97+
mp_uint_t group = mp_obj_get_int(args[0]) & 1;
98+
mp_uint_t index = 0;
99+
#else
92100
mp_uint_t group = (mp_obj_get_int(args[0]) >> 1) & 1;
93101
mp_uint_t index = mp_obj_get_int(args[0]) & 1;
102+
#endif
94103

95104
machine_timer_obj_t *self = NULL;
96105

0 commit comments

Comments
 (0)