diff --git a/MicroPython_BUILD/components/micropython/esp32/machine_timer.c b/MicroPython_BUILD/components/micropython/esp32/machine_timer.c index 82f56d5..ccde87e 100644 --- a/MicroPython_BUILD/components/micropython/esp32/machine_timer.c +++ b/MicroPython_BUILD/components/micropython/esp32/machine_timer.c @@ -73,8 +73,8 @@ typedef struct _machine_timer_obj_t { const mp_obj_type_t machine_timer_type; -static machine_timer_obj_t *timers_used[4] = {NULL}; -static machine_timer_obj_t *ext_timers[TIMER_EXT_NUM] = {NULL}; +static machine_timer_obj_t * timers_used[4] = {NULL}; +static machine_timer_obj_t * ext_timers[TIMER_EXT_NUM] = {NULL}; //---------------------------------------------- @@ -128,6 +128,17 @@ STATIC void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr if (self->debug_pin >= 0) { mp_printf(print, "\n Debug output on gpio %d, ", self->debug_pin); } + if (self->type == TIMER_TYPE_EXTBASE) { + machine_timer_obj_t *extmr; + mp_printf(print, " Handled extended timers:\n"); + for (int i=0; i < TIMER_EXT_NUM; i++) { + extmr = ext_timers[i]; + if (extmr) { + mp_printf(print, " %2d: Period: %d ms, %s", i+4, extmr->period, (extmr->state == TIMER_RUNNING) ? "Running" : "Paused"); + } + } + } + } //----------------------------------------------------------------------------------------------------------------- @@ -224,14 +235,21 @@ STATIC void machine_ext_timer_isr(void *self_in) self->event_num++; // test extended timers for (int i=0; i < TIMER_EXT_NUM; i++) { - if (ext_timers[i] != NULL) { - extmr = ext_timers[i]; + extmr = ext_timers[i]; + if (extmr) { + // Extended timer exists if (extmr->state == TIMER_RUNNING) { + // Timer is running, increment extended timer's counter extmr->counter++; if ((extmr->counter % extmr->period) == 0) { + // Extended timer's period elapsed, increment events number extmr->event_num++; if (extmr->counter == extmr->alarm) { - if ((extmr->callback) && (mp_sched_schedule(extmr->callback, extmr))) extmr->cb_num++; + // Schedule the callback execution + if ((extmr->callback) && (mp_sched_schedule(extmr->callback, extmr))) { + extmr->cb_num++; + self->cb_num++; + } if (extmr->repeat) extmr->counter = 0x00000000ULL; } } @@ -243,8 +261,12 @@ STATIC void machine_ext_timer_isr(void *self_in) //--------------------------------------------------------- STATIC void machine_timer_enable(machine_timer_obj_t *self) { - if (self->id >= 4) return; - timer_config_t config; + if (self->id >= 4) { + ext_timers[(self->id-4)] = self; + return; + } + + timer_config_t config; config.counter_dir = TIMER_COUNT_UP; config.intr_type = TIMER_INTR_LEVEL; config.counter_en = TIMER_PAUSE; @@ -281,6 +303,7 @@ STATIC void machine_timer_enable(machine_timer_obj_t *self) } check_esp_err(timer_start((self->id >> 1) & 1, self->id & 1)); } + timers_used[self->id] = self; } //--------------------------------------------------------------------------------------------------------------------------------- @@ -340,6 +363,7 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n } // enable and start the timer machine_timer_enable(self); + if (self->type != TIMER_TYPE_CHRONO) self->state = TIMER_RUNNING; else self->state = TIMER_PAUSED; } @@ -357,6 +381,8 @@ STATIC mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, mp_uint_t n self->counter = 0x00000000ULL; self->alarm = self->period; self->state = TIMER_RUNNING; + + machine_timer_enable(self); } return mp_const_none; @@ -400,7 +426,7 @@ STATIC mp_obj_t machine_timer_value(mp_obj_t self_in) if (self->type == TIMER_TYPE_EXTBASE) result = self->event_num; // value in ms else { timer_get_counter_value((self->id >> 1) & 1, self->id & 1, &result); - if (self->type != TIMER_TYPE_CHRONO) result *= (self->period / 2); // value in ms + if (self->type != TIMER_TYPE_CHRONO) result *= (self->period / 2); // value in us } } else { @@ -646,7 +672,6 @@ STATIC const mp_map_elem_t machine_timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_resume), (mp_obj_t)&machine_timer_resume_obj }, { MP_ROM_QSTR(MP_QSTR_timernum), (mp_obj_t)&machine_timer_id_obj }, { MP_ROM_QSTR(MP_QSTR_period), (mp_obj_t)&machine_timer_period_obj }, - { MP_ROM_QSTR(MP_QSTR_period), (mp_obj_t)&machine_timer_period_obj }, { MP_ROM_QSTR(MP_QSTR_callback), (mp_obj_t)&machine_timer_callback_obj }, { MP_ROM_QSTR(MP_QSTR_isrunning), (mp_obj_t)&machine_timer_isrunning_obj }, diff --git a/MicroPython_BUILD/components/micropython/esp32/mpversion.h b/MicroPython_BUILD/components/micropython/esp32/mpversion.h index bfc9f38..738fe43 100644 --- a/MicroPython_BUILD/components/micropython/esp32/mpversion.h +++ b/MicroPython_BUILD/components/micropython/esp32/mpversion.h @@ -1,8 +1,8 @@ // MicroPython version info -#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.6" +#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.7" #define MICROPY_GIT_HASH "g2ddee729" -#define MICROPY_BUILD_DATE "2017-01-17" +#define MICROPY_BUILD_DATE "2017-01-18" #define MICROPY_VERSION_MAJOR (3) #define MICROPY_VERSION_MINOR (1) -#define MICROPY_VERSION_MICRO (6) -#define MICROPY_VERSION_STRING "3.1.6" +#define MICROPY_VERSION_MICRO (7) +#define MICROPY_VERSION_STRING "3.1.7" diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip index e9abf11..0d08726 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip differ diff --git a/MicroPython_BUILD/firmware/esp32/MicroPython.bin b/MicroPython_BUILD/firmware/esp32/MicroPython.bin index 4ddfe35..b6a0c2a 100644 Binary files a/MicroPython_BUILD/firmware/esp32/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin index 6e7da56..32bf737 100644 Binary files a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin index f3c0b97..2cabc9e 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin index 9648866..12322a6 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin index e7c2acb..0fc9a33 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin index 20440e1..e5436ec 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin index 5ca6685..ff69386 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin index 3d3dad0..eb5153c 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin index 8802bae..fd37909 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin index 89fd629..9327d2e 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin differ