M5Utility 0.2.0 git rev:301a6b5
Loading...
Searching...
No Matches
platform_detect.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
19#ifndef M5_UTILITY_PLATFORM_DETECT_HPP
20#define M5_UTILITY_PLATFORM_DETECT_HPP
21
22// Fail fast with a single clear diagnostic on toolchains that ship no C++
23// standard library at all (e.g. avr-gcc for AVR cores); otherwise the first
24// standard header include produces a cascade of unrelated-looking errors.
25// This probes existence only — a header that exists but is unusable is a
26// different problem (see M5UTILITY_HAS_USABLE_CHRONO below).
27#if defined(__has_include)
28#if !__has_include(<type_traits>) || !__has_include(<vector>) || !__has_include(<functional>)
29#error "M5Utility requires the C++ standard library, which this toolchain (e.g. avr-gcc for AVR cores) does not provide"
30#endif
31#endif
32
33#define M5UTILITY_TIME_SOURCE_ESP 1
34#define M5UTILITY_TIME_SOURCE_ARDUINO 2
35#define M5UTILITY_TIME_SOURCE_CHRONO 3
36
42#if !defined(M5UTILITY_TIME_SOURCE)
43#if defined(ESP_PLATFORM)
44// Defined by the ESP-IDF build system and by every Arduino-ESP32 core, for all
45// chips — no per-target CONFIG_IDF_TARGET_* list to maintain.
46#define M5UTILITY_TIME_SOURCE M5UTILITY_TIME_SOURCE_ESP
47#elif defined(ARDUINO)
48// Any other Arduino core: millis()/micros()/delay() are guaranteed by the Arduino API
49// contract on every core (RP2040, SAMD, ...), while <thread> generally is not
50// (bare-metal, no RTOS by default).
51#define M5UTILITY_TIME_SOURCE M5UTILITY_TIME_SOURCE_ARDUINO
52#else
53// Hosted build (native tests etc.)
54#define M5UTILITY_TIME_SOURCE M5UTILITY_TIME_SOURCE_CHRONO
55#endif
56#endif
57
58#if (M5UTILITY_TIME_SOURCE < M5UTILITY_TIME_SOURCE_ESP) || (M5UTILITY_TIME_SOURCE > M5UTILITY_TIME_SOURCE_CHRONO)
59#error "M5UTILITY_TIME_SOURCE must be one of M5UTILITY_TIME_SOURCE_{ESP,ARDUINO,CHRONO}"
60#endif
61
81#if !defined(M5UTILITY_HAS_USABLE_CHRONO)
82#if defined(ARDUINO) && !defined(ESP_PLATFORM)
83#define M5UTILITY_HAS_USABLE_CHRONO 0
84#else
85#define M5UTILITY_HAS_USABLE_CHRONO 1
86#endif
87#endif
88
89#endif // M5_UTILITY_PLATFORM_DETECT_HPP