TinyGPU
Loading...
Searching...
No Matches
EmulationDesktop.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file EmulationDesktop.h
4 * @brief Minimal delay()/millis() for a plain desktop C++ build - no
5 * Arduino core, no ESP-IDF.
6 *
7 * This is the desktop branch of TinyGPU/Emulation.h's fallback - include
8 * that instead of this file directly; it decides whether a real Arduino
9 * core is available, and routes here only when it isn't and
10 * ESP_PLATFORM is also undefined (a plain desktop C++/CMake build that
11 * links TinyGPU directly, without the Arduino-Emulator this project's
12 * own examples fetch - see the top-level CMakeLists.txt).
13 *
14 * millis() is what TinyGPU/Input/GestureDetector.h calls internally to
15 * time gesture durations (tap/long-press/swipe/drag), so a desktop
16 * consumer of GestureDetector.h needs this fallback to even compile;
17 * delay() is provided alongside it for that same consumer's own event
18 * loop to pace itself with, the same way every example's loop() does.
19 *
20 * Only delay()/millis() are provided here - unlike EmulationIDF.h's
21 * ESP-IDF fallback, there's no generic desktop equivalent of a GPIO pin
22 * or an SPI/I2C bus to emulate, so pinMode()/digitalWrite()/SPIClass/
23 * TwoWire are intentionally not stubbed out: a file that actually needs
24 * one of those (DisplayDriverSPI.h, TouchDriverArduino.h, ...) has no
25 * meaningful desktop implementation to fall back to and should fail to
26 * compile here rather than silently pretend hardware I/O succeeded.
27 */
28
29#include <chrono>
30#include <thread>
31
32// Namespaced (not global) like the rest of this library - safe to do
33// since every call site (all of TinyGPU/Drivers and TinyGPU/Input) lives
34// inside `namespace tinygpu` itself, so unqualified lookup finds these
35// the same way it would find them in the global namespace on the
36// real-Arduino-core branch of TinyGPU/Emulation.h.
37namespace tinygpu {
38
39/// Milliseconds since the epoch, from a monotonic (steady) clock - not
40/// "time since boot" the way Arduino's millis() is, but that distinction
41/// never matters here: GestureDetector.h only ever subtracts two millis()
42/// calls to get an elapsed duration, never reads the absolute value.
43inline unsigned long millis() {
44 using namespace std::chrono;
45 return static_cast<unsigned long>(
46 duration_cast<milliseconds>(steady_clock::now().time_since_epoch())
47 .count());
48}
49
50/// Blocks the calling thread for `ms` milliseconds, matching Arduino's
51/// delay().
52inline void delay(unsigned long ms) {
53 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
54}
55
56} // namespace tinygpu
Definition: DSIBusESP32.h:19
void delay(unsigned long ms)
Definition: EmulationDesktop.h:52
unsigned long millis()
Definition: EmulationDesktop.h:43