Skip to content

Commit

Permalink
esp-idf millis fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcza committed Feb 6, 2024
1 parent b50ac6f commit c23eb16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/SensorLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/SensorQMI8658.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 8 additions & 16 deletions src/platform/esp_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "driver/gpio.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include <rom/ets_sys.h>


void pinMode(uint32_t gpio, uint8_t mode)
{
Expand Down Expand Up @@ -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
#endif

0 comments on commit c23eb16

Please sign in to comment.