M5Utility 0.2.0 git rev:301a6b5
Loading...
Searching...
No Matches
platform_detect.hpp File Reference

Build-environment detection shared by the sources that need a time source or <chrono> More...

Go to the source code of this file.

Macros

#define M5UTILITY_TIME_SOURCE_ESP   1
 esp_timer + FreeRTOS (ESP-IDF and Arduino-ESP32)
 
#define M5UTILITY_TIME_SOURCE_ARDUINO   2
 Arduino API millis()/micros()/delay()
 
#define M5UTILITY_TIME_SOURCE_CHRONO   3
 hosted C++ <chrono> + <thread>
 
#define M5UTILITY_TIME_SOURCE   M5UTILITY_TIME_SOURCE_CHRONO
 Which API backs m5::utility::millis()/micros()/delay()/delayMicroseconds() and the no-<chrono> log timestamp. Predefine to one of the values above to override the auto-detection.
 
#define M5UTILITY_HAS_USABLE_CHRONO   1
 Whether the logging path may use <chrono> (elapsed_time_t and the log timestamp clock in log/library_log.*, the only consumers). Predefine (0/1) to override.
 

Detailed Description

Build-environment detection shared by the sources that need a time source or <chrono>

Detection policy, kept in one place so supporting a new environment takes one change here (or a build-flag override) instead of edits scattered across sources:

  • Header existence is probed with __has_include (e.g. <sdkconfig.h> in library_log.hpp).
  • Language / standard-library features are probed with feature-test macros (__cplusplus etc.).
  • Environment traits (bare-metal vs hosted, which time API is authoritative) cannot be probed; they are derived from ecosystem-guaranteed macros (ESP_PLATFORM, ARDUINO). For an environment the auto-detection does not know, integrators can predefine M5UTILITY_TIME_SOURCE and/or M5UTILITY_HAS_USABLE_CHRONO to override it.

Macro Definition Documentation

◆ M5UTILITY_HAS_USABLE_CHRONO

#define M5UTILITY_HAS_USABLE_CHRONO   1

Whether the logging path may use <chrono> (elapsed_time_t and the log timestamp clock in log/library_log.*, the only consumers). Predefine (0/1) to override.

Scope note: this flag alone does not make the whole library <chrono>-free — with M5UTILITY_TIME_SOURCE_CHRONO the time source itself still requires <chrono>/<thread> (compatibility_feature.cpp). An environment whose <chrono> is unusable needs a non-chrono M5UTILITY_TIME_SOURCE as well; the auto-detection already pairs the two (non-ESP Arduino cores get TIME_SOURCE_ARDUINO + HAS_USABLE_CHRONO=0).

Why not __has_include(<chrono>): on some non-ESP32 Arduino cores the header exists but Arduino.h's abs()/round() function-like macros corrupt <chrono>'s own internal use of those names (empirically confirmed on the officially-registered PlatformIO atmelsam / raspberrypi(mbed) platforms, GCC 9.x libstdc++).