TinyGPU
Loading...
Searching...
No Matches
Emulation.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file Emulation.h
4 * @brief Drop-in replacement for `#include <Arduino.h>` (plus `<SPI.h>`/
5 * `<Wire.h>` where needed) for every file under TinyGPU/Drivers and
6 * TinyGPU/Input - include this instead of those directly.
7 *
8 * Resolves to one of three things, depending on what's available:
9 *
10 * - A real Arduino core is on the include path (Arduino IDE/
11 * arduino-cli, an ESP-IDF build with the arduino-esp32 component
12 * present, or the desktop Arduino-Emulator used by this project's
13 * own examples): transparent passthrough to the real
14 * `<Arduino.h>`/`<SPI.h>`/`<Wire.h>` - nothing of this project's own
15 * is defined.
16 * - No real Arduino core, but ESP_PLATFORM is defined (a plain
17 * ESP-IDF component build via `idf_component_register`, without
18 * arduino-esp32): TinyGPU/Abstractions/EmulationIDF.h - an ESP-IDF-
19 * native emulation of delay()/millis(), pinMode()/digitalWrite()/
20 * digitalRead(), and SPIClass/TwoWire (+ the global SPI/Wire
21 * instances).
22 * - Neither (a plain desktop C++/CMake build that links TinyGPU
23 * directly, without the Arduino-Emulator this project's own examples
24 * fetch): TinyGPU/Abstractions/EmulationDesktop.h - just delay()/
25 * millis(), enough to compile and drive
26 * TinyGPU/Input/GestureDetector.h. See that header for why GPIO/SPI/
27 * I2C aren't stubbed out there.
28 *
29 * Neither fallback is a general Arduino-core replacement - each only
30 * covers the calls this library's own Drivers/Input headers make
31 * (verified by grepping them), not the full Arduino API. A sketch built
32 * against either fallback that calls other Arduino functions will still
33 * need its own additions, or the real Arduino core after all.
34 *
35 * Both fallbacks define their symbols inside `namespace tinygpu` (not
36 * globally) - safe to do since every call site (all of TinyGPU/Drivers
37 * and TinyGPU/Input) lives inside that same namespace, so unqualified
38 * lookup finds them there. Only the real-Arduino-core branch leaves
39 * things where that core put them (global/`arduino::`), since that's not
40 * this project's code to move.
41 */
42
43#if __has_include(<Arduino.h>)
44
45// Real Arduino core available - use it as-is. <SPI.h>/<Wire.h> are
46// separate headers even on real Arduino cores, so pull those in too when
47// present (harmless/absent-safe via __has_include - most Drivers/Input
48// files only need Arduino.h itself).
49#include <Arduino.h>
50#if __has_include(<SPI.h>)
51#include <SPI.h>
52#endif
53#if __has_include(<Wire.h>)
54#include <Wire.h>
55#endif
56
57#elif defined(ESP_PLATFORM)
58
59#include "TinyGPU/Abstractions/EmulationIDF.h"
60
61#else
62
63#include "TinyGPU/Abstractions/EmulationDesktop.h"
64
65#endif