From c23eb168277d727b7b279d337dd934c9af1b78b3 Mon Sep 17 00:00:00 2001 From: dizcza Date: Tue, 6 Feb 2024 23:26:36 +0200 Subject: [PATCH] esp-idf millis fixes --- src/SensorLib.h | 4 ++-- src/SensorQMI8658.hpp | 2 +- src/platform/esp_arduino.cpp | 24 ++++++++---------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/SensorLib.h b/src/SensorLib.h index bf34f89..1e552ac 100644 --- a/src/SensorLib.h +++ b/src/SensorLib.h @@ -142,8 +142,8 @@ typedef struct __SensorLibPins { #define LOG(fmt, ...) LOG_PORT.printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__) #define LOG_BIN(x) LOG_PORT.println(x,BIN); #else -#define LOG(fmt, ...) -#define LOG_BIN(x) +#define LOG(fmt, ...) printf("[%s] " fmt "\n", __func__, ##__VA_ARGS__) +#define LOG_BIN(x) printf("[%s] 0x%X\n", __func__, x) #endif #ifndef lowByte diff --git a/src/SensorQMI8658.hpp b/src/SensorQMI8658.hpp index 4ef90d9..b04414f 100644 --- a/src/SensorQMI8658.hpp +++ b/src/SensorQMI8658.hpp @@ -210,7 +210,7 @@ class SensorQMI8658 : bool reset(bool waitResult = true, uint32_t timeout = 500) { - int val; + int val = 0; // initialize with some value to avoid compilation errors writeRegister(QMI8658_REG_RESET, QMI8658_REG_RESET_DEFAULT); // Maximum 15ms for the Reset process to be finished if (waitResult) { diff --git a/src/platform/esp_arduino.cpp b/src/platform/esp_arduino.cpp index 9e4d6b6..169265a 100644 --- a/src/platform/esp_arduino.cpp +++ b/src/platform/esp_arduino.cpp @@ -11,6 +11,8 @@ #include "driver/gpio.h" #include "esp_timer.h" #include "freertos/FreeRTOS.h" +#include + void pinMode(uint32_t gpio, uint8_t mode) { @@ -43,32 +45,22 @@ int digitalRead(uint32_t gpio) void delay(uint32_t ms) { - vTaskDelay(ms / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(ms)); + ets_delay_us((ms % portTICK_PERIOD_MS) * 1000UL); } uint32_t millis() { - return esp_timer_get_time(); + return (uint32_t) (esp_timer_get_time() / 1000LL); } uint32_t micros() { - return (esp_timer_get_time() / 1000ULL); + return (uint32_t) esp_timer_get_time(); } void delayMicroseconds(uint32_t us) { - uint64_t m = (uint64_t)esp_timer_get_time(); - if (us) { - uint64_t e = (m + us); - if (m > e) { - while ((uint64_t)esp_timer_get_time() > e) { - asm volatile ("nop"); - } - } - while ((uint64_t)esp_timer_get_time() < e) { - asm volatile ("nop"); - } - } + ets_delay_us(us); } -#endif \ No newline at end of file +#endif