esp32: Pump the event loop while waiting for rx-chr or delay_ms.
@@ -48,6 +48,7 @@ int mp_hal_stdin_rx_chr(void) {
if (c != -1) {
return c;
}
+ MICROPY_EVENT_POLL_HOOK
vTaskDelay(1);
}
}
@@ -92,12 +93,21 @@ uint32_t mp_hal_ticks_us(void) {
void mp_hal_delay_ms(uint32_t ms) {
struct timeval tv_start;
- gettimeofday(&tv_start, NULL);
- vTaskDelay(ms / portTICK_PERIOD_MS);
struct timeval tv_end;
+ uint64_t dt;
+ gettimeofday(&tv_start, NULL);
+ for (;;) {
gettimeofday(&tv_end, NULL);
- uint64_t dt = (tv_end.tv_sec - tv_start.tv_sec) * 1000 + (tv_end.tv_usec - tv_start.tv_usec) / 1000;
+ dt = (tv_end.tv_sec - tv_start.tv_sec) * 1000 + (tv_end.tv_usec - tv_start.tv_usec) / 1000;
+ if (dt + portTICK_PERIOD_MS >= ms) {
+ // doing a vTaskDelay would take us beyound requested delay time
+ break;
+ }
+ MICROPY_EVENT_POLL_HOOK
+ vTaskDelay(1);
+ }
if (dt < ms) {
+ // do the remaining delay accurately
ets_delay_us((ms - dt) * 1000);
}
}
