@geastack/targets 0.1.110 → 0.1.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ #include "gea_embedded_app_config.h"
2
+
3
+ #include "apps/app_manager.h"
4
+ #ifndef GEA_EMBEDDED_BLE_DISABLED
5
+ #include "connectivity/ble_hid.h"
6
+ #endif
7
+ #include "display.h"
8
+ #include "host/display_orientation.h"
9
+
10
+ // Forward-declare here instead of through a header — there's already a
11
+ // `wifi.h` in `lib/gea-embedded/include/` defining WifiAdapter/WifiDriver,
12
+ // and adding a second `wifi.h` under `targets/esp32/connectivity/` shadows
13
+ // it in the include search path, breaking the WifiStation TU which needs
14
+ // the base class.
15
+ namespace gea::targets::esp32::wifi {
16
+ void registerDriver();
17
+ }
18
+
19
+ // Registers the platform camera backend (host/camera.cpp) with the runtime's
20
+ // board-independent <camera> preview seam. Forward-declared here for the same
21
+ // reason as wifi::registerDriver() above.
22
+ namespace gea::framework::camera {
23
+ void registerCameraSurface();
24
+ }
25
+
26
+ // Wires the microSD card as the persistent file-cache backend (sdcard_mount.cpp).
27
+ // Forward-declared for the same reason as the registrations above.
28
+ namespace gea::platform::storage {
29
+ void installSdCardFileCache();
30
+ }
31
+ #include "memory_config.h"
32
+ #include "runtime.h"
33
+ #include "services/device_control.h"
34
+
35
+ #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
36
+ #include "esp_heap_caps.h"
37
+ #endif
38
+ #include "esp_log.h"
39
+ #include "sdkconfig.h"
40
+ #include "freertos/FreeRTOS.h"
41
+ #include "freertos/task.h"
42
+
43
+ namespace {
44
+
45
+ constexpr const char *kTag = "gea_embedded";
46
+
47
+ void runRuntime();
48
+
49
+ #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
50
+ void logHeapProbe(const char *stage)
51
+ {
52
+ ESP_LOGI(kTag,
53
+ "heap probe [%s] internal_free=%u internal_largest=%u internal_min=%u psram_free=%u",
54
+ stage ? stage : "?",
55
+ static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
56
+ static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
57
+ static_cast<unsigned>(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
58
+ static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)));
59
+ }
60
+ #endif
61
+
62
+ constexpr int kAppMainTaskStack = CONFIG_ESP_MAIN_TASK_STACK_SIZE;
63
+ // An app whose own realtime tasks must outrank the render loop (audio DSP, a USB
64
+ // isochronous host) sets gea.defines.GEA_EMBEDDED_RUNTIME_TASK_PRIORITY to place
65
+ // this below them; the default is what this board needs on its own.
66
+ #ifndef GEA_EMBEDDED_RUNTIME_TASK_PRIORITY
67
+ #define GEA_EMBEDDED_RUNTIME_TASK_PRIORITY 5
68
+ #endif
69
+ constexpr UBaseType_t kRuntimeTaskPriority = GEA_EMBEDDED_RUNTIME_TASK_PRIORITY;
70
+
71
+ #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
72
+ void logCurrentTaskStack(const char *stage, int stackBytes)
73
+ {
74
+ TaskHandle_t currentTask = xTaskGetCurrentTaskHandle();
75
+ ESP_LOGI(kTag,
76
+ "stack probe [%s] task=%s core=%d stack_arg=%d hwm=%u",
77
+ stage ? stage : "?",
78
+ currentTask ? pcTaskGetName(currentTask) : "?",
79
+ static_cast<int>(xPortGetCoreID()),
80
+ stackBytes,
81
+ static_cast<unsigned>(uxTaskGetStackHighWaterMark(currentTask)));
82
+ }
83
+ #endif
84
+
85
+ void runRuntime()
86
+ {
87
+ gea::framework::RuntimeOptions options{};
88
+ options.width = gea::framework::display::detail::DisplayOrientationState::width();
89
+ options.height = gea::framework::display::detail::DisplayOrientationState::height();
90
+ gea::framework::Runtime::run(options);
91
+ }
92
+
93
+ } // namespace
94
+
95
+ extern "C" void app_main(void)
96
+ {
97
+ // Force the targets/esp32/apps/app_manager.cpp TU to be linked in. That
98
+ // TU's only side effect is a file-scope `PlatformRegistration` whose
99
+ // constructor calls AppManager::setPlatform(...). With -Wl,--gc-sections
100
+ // and the main component built as a static archive, nothing else
101
+ // references launcherPlatform(), so the linker drops the entire object
102
+ // file — the static ctor never runs, AppManager::platform_ stays null,
103
+ // and AppManager::startLauncherButtonTask() / returnRunningAppToLauncher
104
+ // / ... all become silent no-ops. Result: the BOOT button task is never
105
+ // created and no `launcher_button` log lines are ever emitted.
106
+ (void)gea::platform::esp32::apps::launcherPlatform();
107
+
108
+ // Same static-archive trap as `launcherPlatform()` above. Three different
109
+ // `wifi.cpp` files all archive as `wifi.cpp.obj` in `libmain.a`; symbol-
110
+ // driven archive linking pulls in `lib/gea-embedded/wifi.cpp` (WifiAdapter
111
+ // + NullWifiDriver) and `lib/gea-embedded/host/wifi.cpp` (WifiBackend
112
+ // shim) because external code references them, but the ESP32 driver's
113
+ // only side effect was an anonymous-namespace static-init global with no
114
+ // external references — so the obj was dropped, leaving NullWifiDriver
115
+ // (whose enabled()/setEnabled() are silent no-ops) as the active driver.
116
+ // `wifi().init()` returned false in <1ms at boot ("WiFi failed; OTA not
117
+ // available") and the Settings panel WiFi toggle did nothing.
118
+ //
119
+ // Note: wifi.cpp itself wraps `wifi_init_config_t.osi_funcs` to bump the
120
+ // closed-source wifi blob's hardcoded 3584-byte task stack to 8192,
121
+ // avoiding a stack overflow during WPA2 auth on this firmware.
122
+ //
123
+ // GEA_EMBEDDED_WIFI_DISABLED skips driver registration entirely, leaving the
124
+ // no-op NullWifiDriver active (no esp_wifi_init/start, no WiFi DMA/ISR bus
125
+ // traffic). Used to isolate whether WiFi PSRAM/cache-bus contention is what
126
+ // starves the direct-PSRAM SPI flush FIFO.
127
+ #ifndef GEA_EMBEDDED_WIFI_DISABLED
128
+ gea::targets::esp32::wifi::registerDriver();
129
+ #endif
130
+
131
+ // Wire the microSD card as the persistent file-cache backend (used by the
132
+ // runtime image host's loadFile/writeFile — e.g. the maps OSM tile cache).
133
+ // This call also forces sdcard_mount.cpp into the link.
134
+ gea::platform::storage::installSdCardFileCache();
135
+
136
+ // Wire the platform camera backend to the runtime preview seam so a
137
+ // <camera> element / the Camera facade can stream. No hardware is touched
138
+ // until the camera is actually opened.
139
+ gea::framework::camera::registerCameraSurface();
140
+
141
+ // Same static-archive trap as `launcherPlatform()` and `wifi::registerDriver()`
142
+ // above. Reference the HID driver explicitly so its TU is pulled in and
143
+ // `HidServer` replaces the board-independent `NullBleDriver`. Originally
144
+ // gated on `GEA_EMBEDDED_APP_USES_BLE`, but `geatsc analyze` only detects
145
+ // BLE usage when the import literal is `from 'gea-embedded'` — the
146
+ // internal `runtime-surface` re-export chain that `gea-embedded`'s
147
+ // Settings panel uses (`import { BLE, ... } from '../../runtime-surface'`)
148
+ // gets a false negative, the macro never lands, the driver never
149
+ // registers, and the BLUETOOTH toggle is a silent no-op (NullBleDriver's
150
+ // `setEnabled` ignores its argument; `enabled()` always returns false).
151
+ // We can't just define the macro unconditionally either — it also gates
152
+ // `gea_init`'s SPIRAM-vs-DRAM placement in `app_runner.cpp`, and forcing
153
+ // DRAM there fails (64 KB stack > 32 KB largest contiguous block at
154
+ // init time). So: register the driver here unconditionally, leave the
155
+ // macro narrow.
156
+ #ifndef GEA_EMBEDDED_BLE_DISABLED
157
+ gea::targets::esp32::ble::registerHidDriver();
158
+ #endif
159
+
160
+ vTaskPrioritySet(nullptr, kRuntimeTaskPriority);
161
+ #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
162
+ logCurrentTaskStack("main_task:before_runtime", kAppMainTaskStack);
163
+ #endif
164
+ #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
165
+ logHeapProbe("app_main:before_device_control_task");
166
+ #endif
167
+ gea::platform::esp32::services::startDeviceControlTask();
168
+ #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
169
+ logHeapProbe("app_main:before_runtime");
170
+ #endif
171
+ runRuntime();
172
+
173
+ ESP_LOGE(kTag, "Runtime returned unexpectedly; parking main task");
174
+ while (true) {
175
+ vTaskDelay(pdMS_TO_TICKS(1000));
176
+ }
177
+ }