@geastack/targets 0.1.77

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.
Files changed (348) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +83 -0
  3. package/package.json +50 -0
  4. package/targets/cmake/geatsc-generated-archive-build.mjs +614 -0
  5. package/targets/cmake/geatsc_generated_archive.cmake +116 -0
  6. package/targets/cmake/geatsc_generated_archive_build.cmake +50 -0
  7. package/targets/esp32/app_project.cmake +33 -0
  8. package/targets/esp32/apps/app_manager.cpp +188 -0
  9. package/targets/esp32/apps/app_manager.h +10 -0
  10. package/targets/esp32/chip_bindings/README.md +58 -0
  11. package/targets/esp32/chip_bindings/audio/es8311.cpp +556 -0
  12. package/targets/esp32/chip_bindings/displays/co5300.cpp +510 -0
  13. package/targets/esp32/chip_bindings/displays/co5300.h +47 -0
  14. package/targets/esp32/chip_bindings/displays/co5300_async_stream.inc +79 -0
  15. package/targets/esp32/chip_bindings/displays/qspi_panel.h +65 -0
  16. package/targets/esp32/chip_bindings/displays/sh8601.cpp +583 -0
  17. package/targets/esp32/chip_bindings/displays/sh8601.h +36 -0
  18. package/targets/esp32/chip_bindings/gps/lc76g.cpp +296 -0
  19. package/targets/esp32/chip_bindings/gps/lc76g.h +7 -0
  20. package/targets/esp32/chip_bindings/imu/bmi270.cpp +299 -0
  21. package/targets/esp32/chip_bindings/imu/bmi270_config.inl +439 -0
  22. package/targets/esp32/chip_bindings/imu/qmi8658.cpp +213 -0
  23. package/targets/esp32/chip_bindings/power/axp2101.cpp +185 -0
  24. package/targets/esp32/chip_bindings/touch/cst9217.cpp +229 -0
  25. package/targets/esp32/chip_bindings/touch/cst9217_controller.h +78 -0
  26. package/targets/esp32/chip_bindings/touch/ft3168.cpp +340 -0
  27. package/targets/esp32/chip_bindings/touch/ft3168_controller.h +103 -0
  28. package/targets/esp32/chip_bindings/touch/ft6336.cpp +310 -0
  29. package/targets/esp32/chip_bindings/touch/ft6336_controller.h +90 -0
  30. package/targets/esp32/components/gea_framework/CMakeLists.txt +62 -0
  31. package/targets/esp32/connectivity/ble_hid.cpp +2916 -0
  32. package/targets/esp32/connectivity/ble_hid.h +8 -0
  33. package/targets/esp32/connectivity/diagnostics_transport.cpp +523 -0
  34. package/targets/esp32/connectivity/diagnostics_transport_offline.cpp +108 -0
  35. package/targets/esp32/connectivity/wifi.cpp +615 -0
  36. package/targets/esp32/connectivity/wifi_debug_offline.cpp +37 -0
  37. package/targets/esp32/connectivity/wifi_task_stack.h +119 -0
  38. package/targets/esp32/display.cpp +6010 -0
  39. package/targets/esp32/display_headless.cpp +468 -0
  40. package/targets/esp32/gea/platform_random.h +11 -0
  41. package/targets/esp32/gea_framework.cmake +382 -0
  42. package/targets/esp32/gpio.cpp +229 -0
  43. package/targets/esp32/host_sources.cmake +35 -0
  44. package/targets/esp32/imu_absent.cpp +36 -0
  45. package/targets/esp32/ldfragments/gea_ui_state_external.lf +35 -0
  46. package/targets/esp32/memory_config.h +64 -0
  47. package/targets/esp32/power_absent.cpp +22 -0
  48. package/targets/esp32/sdk-patches/0001-esp_ptr_dma_capable-accept-PSRAM.patch +70 -0
  49. package/targets/esp32/sdk-patches/0002-gdma-access_ext_mem-spi_master.patch +59 -0
  50. package/targets/esp32/sdk-patches/README.md +127 -0
  51. package/targets/esp32/services/app_runner.cpp +248 -0
  52. package/targets/esp32/services/app_state.cpp +56 -0
  53. package/targets/esp32/services/audio_runtime_stub.cpp +86 -0
  54. package/targets/esp32/services/battery_service.cpp +31 -0
  55. package/targets/esp32/services/device_control.cpp +1896 -0
  56. package/targets/esp32/services/device_control.h +31 -0
  57. package/targets/esp32/services/frame_scheduler.cpp +1571 -0
  58. package/targets/esp32/services/heap.cpp +129 -0
  59. package/targets/esp32/services/memory.cpp +103 -0
  60. package/targets/esp32/services/ota.cpp +840 -0
  61. package/targets/esp32/services/ota_image.cpp +162 -0
  62. package/targets/esp32/services/ota_image.h +16 -0
  63. package/targets/esp32/services/storage_service.cpp +159 -0
  64. package/targets/esp32/touch_absent.cpp +44 -0
  65. package/targets/esp32-m5stack-m5paper/CMakeLists.txt +10 -0
  66. package/targets/esp32-m5stack-m5paper/README.md +55 -0
  67. package/targets/esp32-m5stack-m5paper/dependencies.lock +76 -0
  68. package/targets/esp32-m5stack-m5paper/main/CMakeLists.txt +46 -0
  69. package/targets/esp32-m5stack-m5paper/main/Kconfig.projbuild +10 -0
  70. package/targets/esp32-m5stack-m5paper/main/app_main.cpp +114 -0
  71. package/targets/esp32-m5stack-m5paper/main/audio_stub.cpp +27 -0
  72. package/targets/esp32-m5stack-m5paper/main/buttons.cpp +111 -0
  73. package/targets/esp32-m5stack-m5paper/main/display.cpp +1074 -0
  74. package/targets/esp32-m5stack-m5paper/main/i2c.cpp +36 -0
  75. package/targets/esp32-m5stack-m5paper/main/idf_component.yml +7 -0
  76. package/targets/esp32-m5stack-m5paper/main/imu_stub.cpp +20 -0
  77. package/targets/esp32-m5stack-m5paper/main/include/board.h +100 -0
  78. package/targets/esp32-m5stack-m5paper/main/include/buttons.h +8 -0
  79. package/targets/esp32-m5stack-m5paper/main/launcher_button.cpp +82 -0
  80. package/targets/esp32-m5stack-m5paper/main/m5paper_psram.lf +20 -0
  81. package/targets/esp32-m5stack-m5paper/main/power.cpp +73 -0
  82. package/targets/esp32-m5stack-m5paper/main/sdcard_mount.cpp +82 -0
  83. package/targets/esp32-m5stack-m5paper/main/touch.cpp +279 -0
  84. package/targets/esp32-m5stack-m5paper/partitions.csv +9 -0
  85. package/targets/esp32-m5stack-m5paper/sdkconfig.defaults +84 -0
  86. package/targets/esp32-p4-m5stack-tab5/CMakeLists.txt +10 -0
  87. package/targets/esp32-p4-m5stack-tab5/dependencies.lock +276 -0
  88. package/targets/esp32-p4-m5stack-tab5/main/CMakeLists.txt +586 -0
  89. package/targets/esp32-p4-m5stack-tab5/main/Kconfig.projbuild +12 -0
  90. package/targets/esp32-p4-m5stack-tab5/main/app_main.cpp +177 -0
  91. package/targets/esp32-p4-m5stack-tab5/main/camera.cpp +2025 -0
  92. package/targets/esp32-p4-m5stack-tab5/main/display.cpp +4033 -0
  93. package/targets/esp32-p4-m5stack-tab5/main/fatfs_ffconf.h +383 -0
  94. package/targets/esp32-p4-m5stack-tab5/main/i2c.cpp +39 -0
  95. package/targets/esp32-p4-m5stack-tab5/main/idf_component.yml +21 -0
  96. package/targets/esp32-p4-m5stack-tab5/main/include/board.h +130 -0
  97. package/targets/esp32-p4-m5stack-tab5/main/include/tab5_drivers.h +68 -0
  98. package/targets/esp32-p4-m5stack-tab5/main/include/wifi_config.h.example +5 -0
  99. package/targets/esp32-p4-m5stack-tab5/main/launcher_button.cpp +188 -0
  100. package/targets/esp32-p4-m5stack-tab5/main/power.cpp +22 -0
  101. package/targets/esp32-p4-m5stack-tab5/main/sdcard_mount.cpp +125 -0
  102. package/targets/esp32-p4-m5stack-tab5/main/tab5_audio.cpp +345 -0
  103. package/targets/esp32-p4-m5stack-tab5/main/tab5_drivers.cpp +871 -0
  104. package/targets/esp32-p4-m5stack-tab5/main/tab5_imu.cpp +246 -0
  105. package/targets/esp32-p4-m5stack-tab5/main/touch.cpp +206 -0
  106. package/targets/esp32-p4-m5stack-tab5/partitions.csv +12 -0
  107. package/targets/esp32-p4-m5stack-tab5/sdkconfig.defaults +128 -0
  108. package/targets/esp32-p4-waveshare-touch-lcd-3.5/CMakeLists.txt +19 -0
  109. package/targets/esp32-p4-waveshare-touch-lcd-3.5/component-patches/0001-esp_video-csi-raw-passthrough-p4-rev-lt-v3.patch +28 -0
  110. package/targets/esp32-p4-waveshare-touch-lcd-3.5/component-patches/README.md +45 -0
  111. package/targets/esp32-p4-waveshare-touch-lcd-3.5/component-patches/apply.sh +37 -0
  112. package/targets/esp32-p4-waveshare-touch-lcd-3.5/dependencies.lock +196 -0
  113. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/CMakeLists.txt +562 -0
  114. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/Kconfig.projbuild +12 -0
  115. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/app_main.cpp +166 -0
  116. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/camera.cpp +2105 -0
  117. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/display.cpp +1730 -0
  118. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/fatfs_ffconf.h +383 -0
  119. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/i2c.cpp +39 -0
  120. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/idf_component.yml +11 -0
  121. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/include/board.h +87 -0
  122. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/include/panel_native.h +59 -0
  123. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/include/wifi_config.h.example +5 -0
  124. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/launcher_button.cpp +191 -0
  125. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/power.cpp +15 -0
  126. package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/touch.cpp +306 -0
  127. package/targets/esp32-p4-waveshare-touch-lcd-3.5/partitions.csv +13 -0
  128. package/targets/esp32-p4-waveshare-touch-lcd-3.5/patches/README.md +22 -0
  129. package/targets/esp32-p4-waveshare-touch-lcd-3.5/patches/espressif__esp_video-csi-bypass.patch +28 -0
  130. package/targets/esp32-p4-waveshare-touch-lcd-3.5/sdkconfig.defaults +109 -0
  131. package/targets/esp32-p4-waveshare-touch-lcd-3.5/tools/README-camera-capture.md +84 -0
  132. package/targets/esp32-p4-waveshare-touch-lcd-3.5/tools/capture-camera.py +369 -0
  133. package/targets/esp32-p4-waveshare-touch-lcd-7/CMakeLists.txt +10 -0
  134. package/targets/esp32-p4-waveshare-touch-lcd-7/dependencies.lock +258 -0
  135. package/targets/esp32-p4-waveshare-touch-lcd-7/main/CMakeLists.txt +577 -0
  136. package/targets/esp32-p4-waveshare-touch-lcd-7/main/Kconfig.projbuild +12 -0
  137. package/targets/esp32-p4-waveshare-touch-lcd-7/main/app_main.cpp +177 -0
  138. package/targets/esp32-p4-waveshare-touch-lcd-7/main/camera.cpp +1935 -0
  139. package/targets/esp32-p4-waveshare-touch-lcd-7/main/display.cpp +2832 -0
  140. package/targets/esp32-p4-waveshare-touch-lcd-7/main/fatfs_ffconf.h +383 -0
  141. package/targets/esp32-p4-waveshare-touch-lcd-7/main/i2c.cpp +39 -0
  142. package/targets/esp32-p4-waveshare-touch-lcd-7/main/idf_component.yml +23 -0
  143. package/targets/esp32-p4-waveshare-touch-lcd-7/main/include/board.h +68 -0
  144. package/targets/esp32-p4-waveshare-touch-lcd-7/main/include/wifi_config.h.example +5 -0
  145. package/targets/esp32-p4-waveshare-touch-lcd-7/main/launcher_button.cpp +191 -0
  146. package/targets/esp32-p4-waveshare-touch-lcd-7/main/power.cpp +15 -0
  147. package/targets/esp32-p4-waveshare-touch-lcd-7/main/sdcard_mount.cpp +125 -0
  148. package/targets/esp32-p4-waveshare-touch-lcd-7/main/touch.cpp +332 -0
  149. package/targets/esp32-p4-waveshare-touch-lcd-7/partitions.csv +12 -0
  150. package/targets/esp32-p4-waveshare-touch-lcd-7/sdkconfig.defaults +122 -0
  151. package/targets/esp32-p4-waveshare-touch-lcd-7/tools/README-camera-capture.md +84 -0
  152. package/targets/esp32-p4-waveshare-touch-lcd-7/tools/capture-camera.py +369 -0
  153. package/targets/esp32-s3-devkit-n16r8.json +31 -0
  154. package/targets/esp32-s3-elecrow-rotary-2.1/CMakeLists.txt +10 -0
  155. package/targets/esp32-s3-elecrow-rotary-2.1/dependencies.lock +40 -0
  156. package/targets/esp32-s3-elecrow-rotary-2.1/main/CMakeLists.txt +549 -0
  157. package/targets/esp32-s3-elecrow-rotary-2.1/main/Kconfig.projbuild +12 -0
  158. package/targets/esp32-s3-elecrow-rotary-2.1/main/app_main.cpp +187 -0
  159. package/targets/esp32-s3-elecrow-rotary-2.1/main/display_rgb.cpp +1338 -0
  160. package/targets/esp32-s3-elecrow-rotary-2.1/main/i2c.cpp +39 -0
  161. package/targets/esp32-s3-elecrow-rotary-2.1/main/idf_component.yml +5 -0
  162. package/targets/esp32-s3-elecrow-rotary-2.1/main/include/board.h +142 -0
  163. package/targets/esp32-s3-elecrow-rotary-2.1/main/include/pcf8574.h +16 -0
  164. package/targets/esp32-s3-elecrow-rotary-2.1/main/include/rotary_encoder.h +7 -0
  165. package/targets/esp32-s3-elecrow-rotary-2.1/main/launcher_button.cpp +191 -0
  166. package/targets/esp32-s3-elecrow-rotary-2.1/main/pcf8574.cpp +86 -0
  167. package/targets/esp32-s3-elecrow-rotary-2.1/main/platform_stubs.cpp +47 -0
  168. package/targets/esp32-s3-elecrow-rotary-2.1/main/rotary_encoder.cpp +135 -0
  169. package/targets/esp32-s3-elecrow-rotary-2.1/main/touch.cpp +250 -0
  170. package/targets/esp32-s3-elecrow-rotary-2.1/partitions.csv +8 -0
  171. package/targets/esp32-s3-elecrow-rotary-2.1/sdkconfig.defaults +116 -0
  172. package/targets/esp32-s3-epaper-1.54/CMakeLists.txt +10 -0
  173. package/targets/esp32-s3-epaper-1.54/dependencies.lock +76 -0
  174. package/targets/esp32-s3-epaper-1.54/main/CMakeLists.txt +691 -0
  175. package/targets/esp32-s3-epaper-1.54/main/Kconfig.projbuild +12 -0
  176. package/targets/esp32-s3-epaper-1.54/main/app_main.cpp +181 -0
  177. package/targets/esp32-s3-epaper-1.54/main/buttons.cpp +144 -0
  178. package/targets/esp32-s3-epaper-1.54/main/display.cpp +1281 -0
  179. package/targets/esp32-s3-epaper-1.54/main/fatfs_ffconf.h +377 -0
  180. package/targets/esp32-s3-epaper-1.54/main/i2c.cpp +39 -0
  181. package/targets/esp32-s3-epaper-1.54/main/idf_component.yml +7 -0
  182. package/targets/esp32-s3-epaper-1.54/main/imu_stub.cpp +21 -0
  183. package/targets/esp32-s3-epaper-1.54/main/include/board.h +119 -0
  184. package/targets/esp32-s3-epaper-1.54/main/include/buttons.h +9 -0
  185. package/targets/esp32-s3-epaper-1.54/main/include/wifi_config.h.example +5 -0
  186. package/targets/esp32-s3-epaper-1.54/main/launcher_button.cpp +191 -0
  187. package/targets/esp32-s3-epaper-1.54/main/power.cpp +15 -0
  188. package/targets/esp32-s3-epaper-1.54/main/sdcard_mount.cpp +89 -0
  189. package/targets/esp32-s3-epaper-1.54/main/touch.cpp +299 -0
  190. package/targets/esp32-s3-epaper-1.54/partitions.csv +8 -0
  191. package/targets/esp32-s3-epaper-1.54/sdkconfig.defaults +217 -0
  192. package/targets/esp32-s3-lilygo-t-display-s3-long/CMakeLists.txt +10 -0
  193. package/targets/esp32-s3-lilygo-t-display-s3-long/README.md +29 -0
  194. package/targets/esp32-s3-lilygo-t-display-s3-long/dependencies.lock +116 -0
  195. package/targets/esp32-s3-lilygo-t-display-s3-long/main/CMakeLists.txt +90 -0
  196. package/targets/esp32-s3-lilygo-t-display-s3-long/main/idf_component.yml +7 -0
  197. package/targets/esp32-s3-lilygo-t-display-s3-long/main/include/board.h +61 -0
  198. package/targets/esp32-s3-lilygo-t-display-s3-long/main/touch.cpp +299 -0
  199. package/targets/esp32-s3-lilygo-t-display-s3-long/partitions.csv +7 -0
  200. package/targets/esp32-s3-lilygo-t-display-s3-long/sdkconfig.defaults +50 -0
  201. package/targets/esp32-s3-lilygo-t5-epaper-4.7/CMakeLists.txt +12 -0
  202. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/CMakeLists.txt +17 -0
  203. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/ed047tc1.c +269 -0
  204. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/ed047tc1.h +142 -0
  205. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/epd_driver.c +1114 -0
  206. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/epd_driver.h +410 -0
  207. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/gea_epd.c +989 -0
  208. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/i2s_data_bus.c +489 -0
  209. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/i2s_data_bus.h +104 -0
  210. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/rmt_pulse.c +136 -0
  211. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/rmt_pulse.h +78 -0
  212. package/targets/esp32-s3-lilygo-t5-epaper-4.7/components/epd_driver/utilities.h +49 -0
  213. package/targets/esp32-s3-lilygo-t5-epaper-4.7/dependencies.lock +35 -0
  214. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/CMakeLists.txt +30 -0
  215. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/Kconfig.projbuild +10 -0
  216. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/app_main.cpp +95 -0
  217. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/audio_stub.cpp +27 -0
  218. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/buttons.cpp +40 -0
  219. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/display.cpp +627 -0
  220. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/i2c.cpp +36 -0
  221. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/idf_component.yml +4 -0
  222. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/imu_stub.cpp +20 -0
  223. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/include/board.h +85 -0
  224. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/include/buttons.h +8 -0
  225. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/launcher_button.cpp +82 -0
  226. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/power.cpp +36 -0
  227. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/sdcard_mount.cpp +90 -0
  228. package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/touch.cpp +293 -0
  229. package/targets/esp32-s3-lilygo-t5-epaper-4.7/partitions.csv +9 -0
  230. package/targets/esp32-s3-lilygo-t5-epaper-4.7/sdkconfig.defaults +217 -0
  231. package/targets/esp32-s3-m5stack-papers3/CMakeLists.txt +13 -0
  232. package/targets/esp32-s3-m5stack-papers3/components/papers3_epd/CMakeLists.txt +5 -0
  233. package/targets/esp32-s3-m5stack-papers3/components/papers3_epd/include/papers3_epd.h +74 -0
  234. package/targets/esp32-s3-m5stack-papers3/components/papers3_epd/papers3_epd.c +671 -0
  235. package/targets/esp32-s3-m5stack-papers3/dependencies.lock +76 -0
  236. package/targets/esp32-s3-m5stack-papers3/main/CMakeLists.txt +64 -0
  237. package/targets/esp32-s3-m5stack-papers3/main/Kconfig.projbuild +10 -0
  238. package/targets/esp32-s3-m5stack-papers3/main/app_main.cpp +96 -0
  239. package/targets/esp32-s3-m5stack-papers3/main/audio_stub.cpp +27 -0
  240. package/targets/esp32-s3-m5stack-papers3/main/buttons.cpp +49 -0
  241. package/targets/esp32-s3-m5stack-papers3/main/display.cpp +706 -0
  242. package/targets/esp32-s3-m5stack-papers3/main/i2c.cpp +36 -0
  243. package/targets/esp32-s3-m5stack-papers3/main/idf_component.yml +14 -0
  244. package/targets/esp32-s3-m5stack-papers3/main/imu.cpp +351 -0
  245. package/targets/esp32-s3-m5stack-papers3/main/include/board.h +101 -0
  246. package/targets/esp32-s3-m5stack-papers3/main/include/buttons.h +8 -0
  247. package/targets/esp32-s3-m5stack-papers3/main/launcher_button.cpp +96 -0
  248. package/targets/esp32-s3-m5stack-papers3/main/power.cpp +102 -0
  249. package/targets/esp32-s3-m5stack-papers3/main/sdcard_mount.cpp +88 -0
  250. package/targets/esp32-s3-m5stack-papers3/main/touch.cpp +287 -0
  251. package/targets/esp32-s3-m5stack-papers3/partitions.csv +9 -0
  252. package/targets/esp32-s3-m5stack-papers3/sdkconfig.defaults +232 -0
  253. package/targets/esp32-s3-m5stack-sticks3/CMakeLists.txt +10 -0
  254. package/targets/esp32-s3-m5stack-sticks3/dependencies.lock +51 -0
  255. package/targets/esp32-s3-m5stack-sticks3/main/CMakeLists.txt +51 -0
  256. package/targets/esp32-s3-m5stack-sticks3/main/Kconfig.projbuild +12 -0
  257. package/targets/esp32-s3-m5stack-sticks3/main/app_main.cpp +130 -0
  258. package/targets/esp32-s3-m5stack-sticks3/main/buttons.cpp +101 -0
  259. package/targets/esp32-s3-m5stack-sticks3/main/display.cpp +1391 -0
  260. package/targets/esp32-s3-m5stack-sticks3/main/i2c.cpp +39 -0
  261. package/targets/esp32-s3-m5stack-sticks3/main/idf_component.yml +8 -0
  262. package/targets/esp32-s3-m5stack-sticks3/main/imu_stub.cpp +9 -0
  263. package/targets/esp32-s3-m5stack-sticks3/main/include/board.h +89 -0
  264. package/targets/esp32-s3-m5stack-sticks3/main/include/buttons.h +9 -0
  265. package/targets/esp32-s3-m5stack-sticks3/main/launcher_button.cpp +191 -0
  266. package/targets/esp32-s3-m5stack-sticks3/main/power.cpp +15 -0
  267. package/targets/esp32-s3-m5stack-sticks3/main/sdcard_mount.cpp +8 -0
  268. package/targets/esp32-s3-m5stack-sticks3/main/touch.cpp +65 -0
  269. package/targets/esp32-s3-m5stack-sticks3/partitions.csv +8 -0
  270. package/targets/esp32-s3-m5stack-sticks3/sdkconfig.defaults +130 -0
  271. package/targets/esp32-s3-touch-amoled-1.75/CMakeLists.txt +10 -0
  272. package/targets/esp32-s3-touch-amoled-1.75/dependencies.lock +130 -0
  273. package/targets/esp32-s3-touch-amoled-1.75/main/CMakeLists.txt +589 -0
  274. package/targets/esp32-s3-touch-amoled-1.75/main/Kconfig.projbuild +12 -0
  275. package/targets/esp32-s3-touch-amoled-1.75/main/app_main.cpp +153 -0
  276. package/targets/esp32-s3-touch-amoled-1.75/main/i2c.cpp +39 -0
  277. package/targets/esp32-s3-touch-amoled-1.75/main/idf_component.yml +9 -0
  278. package/targets/esp32-s3-touch-amoled-1.75/main/include/board.h +110 -0
  279. package/targets/esp32-s3-touch-amoled-1.75/main/include/wifi_config.h.example +5 -0
  280. package/targets/esp32-s3-touch-amoled-1.75/main/launcher_button.cpp +191 -0
  281. package/targets/esp32-s3-touch-amoled-1.75/main/touch.cpp +45 -0
  282. package/targets/esp32-s3-touch-amoled-1.75/partitions.csv +8 -0
  283. package/targets/esp32-s3-touch-amoled-1.75/sdkconfig.defaults +179 -0
  284. package/targets/esp32-s3-touch-amoled-1.8/CMakeLists.txt +10 -0
  285. package/targets/esp32-s3-touch-amoled-1.8/dependencies.lock +105 -0
  286. package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +768 -0
  287. package/targets/esp32-s3-touch-amoled-1.8/main/Kconfig.projbuild +12 -0
  288. package/targets/esp32-s3-touch-amoled-1.8/main/app_main.cpp +172 -0
  289. package/targets/esp32-s3-touch-amoled-1.8/main/i2c.cpp +39 -0
  290. package/targets/esp32-s3-touch-amoled-1.8/main/idf_component.yml +8 -0
  291. package/targets/esp32-s3-touch-amoled-1.8/main/include/board.h +83 -0
  292. package/targets/esp32-s3-touch-amoled-1.8/main/include/wifi_config.h.example +5 -0
  293. package/targets/esp32-s3-touch-amoled-1.8/main/launcher_button.cpp +191 -0
  294. package/targets/esp32-s3-touch-amoled-1.8/main/touch.cpp +41 -0
  295. package/targets/esp32-s3-touch-amoled-1.8/partitions.csv +8 -0
  296. package/targets/esp32-s3-touch-amoled-1.8/sdkconfig.defaults +179 -0
  297. package/targets/esp32-s3-touch-amoled-2.06/CMakeLists.txt +10 -0
  298. package/targets/esp32-s3-touch-amoled-2.06/dependencies.lock +64 -0
  299. package/targets/esp32-s3-touch-amoled-2.06/main/CMakeLists.txt +1121 -0
  300. package/targets/esp32-s3-touch-amoled-2.06/main/Kconfig.projbuild +12 -0
  301. package/targets/esp32-s3-touch-amoled-2.06/main/app_main.cpp +333 -0
  302. package/targets/esp32-s3-touch-amoled-2.06/main/i2c.cpp +39 -0
  303. package/targets/esp32-s3-touch-amoled-2.06/main/idf_component.yml +27 -0
  304. package/targets/esp32-s3-touch-amoled-2.06/main/include/board.h +114 -0
  305. package/targets/esp32-s3-touch-amoled-2.06/main/include/wifi_config.h.example +5 -0
  306. package/targets/esp32-s3-touch-amoled-2.06/main/launcher_button.cpp +199 -0
  307. package/targets/esp32-s3-touch-amoled-2.06/main/sdcard_mount.cpp +105 -0
  308. package/targets/esp32-s3-touch-amoled-2.06/main/touch.cpp +49 -0
  309. package/targets/esp32-s3-touch-amoled-2.06/partitions.csv +14 -0
  310. package/targets/esp32-s3-touch-amoled-2.06/sdkconfig.defaults +273 -0
  311. package/targets/esp32-s3-touch-amoled-2.41/CMakeLists.txt +10 -0
  312. package/targets/esp32-s3-touch-amoled-2.41/main/CMakeLists.txt +71 -0
  313. package/targets/esp32-s3-touch-amoled-2.41/main/Kconfig.projbuild +12 -0
  314. package/targets/esp32-s3-touch-amoled-2.41/main/idf_component.yml +27 -0
  315. package/targets/esp32-s3-touch-amoled-2.41/main/include/board.h +108 -0
  316. package/targets/esp32-s3-touch-amoled-2.41/main/include/wifi_config.h.example +5 -0
  317. package/targets/esp32-s3-touch-amoled-2.41/main/panel_reset.cpp +82 -0
  318. package/targets/esp32-s3-touch-amoled-2.41/main/touch.cpp +49 -0
  319. package/targets/esp32-s3-touch-amoled-2.41/partitions.csv +8 -0
  320. package/targets/esp32-s3-touch-amoled-2.41/sdkconfig.defaults +273 -0
  321. package/targets/rp2350-tufty-2350/CMakeLists.txt +348 -0
  322. package/targets/rp2350-tufty-2350/README.md +53 -0
  323. package/targets/rp2350-tufty-2350/boards/pimoroni_tufty2350.h +87 -0
  324. package/targets/rp2350-tufty-2350/main/bringup.cpp +187 -0
  325. package/targets/rp2350-tufty-2350/main/include/board.h +124 -0
  326. package/targets/rp2350-tufty-2350/main/rp2350_panel.cpp +428 -0
  327. package/targets/rp2350-tufty-2350/main/rp2350_panel.h +46 -0
  328. package/targets/rp2350-tufty-2350/main/st7789_parallel.pio +7 -0
  329. package/targets/rp2350-waveshare-touch-amoled-2.41/CMakeLists.txt +345 -0
  330. package/targets/rp2350-waveshare-touch-amoled-2.41/README.md +153 -0
  331. package/targets/rp2350-waveshare-touch-amoled-2.41/boards/waveshare_rp2350_touch_amoled_2_41.h +59 -0
  332. package/targets/rp2350-waveshare-touch-amoled-2.41/main/app.cpp +984 -0
  333. package/targets/rp2350-waveshare-touch-amoled-2.41/main/bringup.cpp +222 -0
  334. package/targets/rp2350-waveshare-touch-amoled-2.41/main/include/board.h +138 -0
  335. package/targets/rp2350-waveshare-touch-amoled-2.41/main/rp2350_gea_platform.cpp +2553 -0
  336. package/targets/rp2350-waveshare-touch-amoled-2.41/main/rp2350_gea_platform.h +18 -0
  337. package/targets/rp2350-waveshare-touch-amoled-2.41/main/rp2350_host_fetch_stub.cpp +64 -0
  338. package/targets/rp2350-waveshare-touch-amoled-2.41/main/rp2350_panel.cpp +677 -0
  339. package/targets/rp2350-waveshare-touch-amoled-2.41/main/rp2350_panel.h +48 -0
  340. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/rp_pico_alloc.c +354 -0
  341. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/rp_pico_alloc.h +56 -0
  342. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/tlsf/tlsf.c +1284 -0
  343. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/tlsf/tlsf.h +95 -0
  344. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/tlsf/tlsf_block_functions.h +123 -0
  345. package/targets/rp2350-waveshare-touch-amoled-2.41/main/vendor/waveshare_psram/tlsf/tlsf_common.h +127 -0
  346. package/targets/rp2350-waveshare-touch-amoled-2.41/tools/rp2350-scroll-bench.py +162 -0
  347. package/targets/rp2350-waveshare-touch-amoled-2.41/tools/rp2350-scroll-parity.py +198 -0
  348. package/targets.json +154 -0
@@ -0,0 +1,1896 @@
1
+ #include "services/device_control.h"
2
+
3
+ #include "apps.h"
4
+ #include "canvas.h"
5
+ #include "display.h"
6
+ #include "events.h"
7
+ #include "i2c.h"
8
+ #include "input.h"
9
+ #include "pixel.h"
10
+ #include "touch.h" // Touchscreen::injectEvent for GEADEV DRAG/SWIPE
11
+ #include "wifi.h" // network::wifi() for GEADEV PING ip=/mac=
12
+ #include "services/app_state.h"
13
+ #include "services/storage_service.h"
14
+ #include "ui/internal.h"
15
+ #include "ui/canvas_element.h"
16
+ #include "ui/tree_internal.h"
17
+ #include "ui/virtual_keyboard.h"
18
+
19
+ #include "driver/i2c_master.h"
20
+ #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
21
+ #include "driver/usb_serial_jtag.h"
22
+ #include "driver/usb_serial_jtag_vfs.h"
23
+ #endif
24
+ #include "esp_heap_caps.h"
25
+ #include "platform/file_cache.h" // gea::platform::storage::ensureMounted for GEADEV PUSH
26
+ #include "esp_log.h"
27
+ #include "esp_err.h"
28
+ #include "esp_mmu_map.h"
29
+ #include "esp_partition.h"
30
+ #include "freertos/FreeRTOS.h"
31
+ #include "freertos/idf_additions.h"
32
+ #include "freertos/semphr.h"
33
+ #include "freertos/task.h"
34
+
35
+ #include <dirent.h>
36
+ #include <cstdarg>
37
+ #include <cerrno>
38
+ #include <cctype>
39
+ #include <cstdint>
40
+ #include <cstdio>
41
+ #include <cstdlib>
42
+ #include <cstring>
43
+ #include <string>
44
+ #include <sys/stat.h> // ::mkdir for GEADEV PUSH parent dirs
45
+ #include <sys/time.h>
46
+ #include "esp_system.h" // esp_restart() for GEADEV REBOOT
47
+ #include "audio.h" // gea::platform::audio::AudioSystem for GEADEV PLAYFILE
48
+ #include "power.h" // Power::batteryPercent() for STATE battery
49
+ #include "host/notify.h" // gea::host::postNotification() for GEADEV NOTIFY
50
+ #include "host/backends.h" // WifiBackend for GEADEV WIFI
51
+ #include "host/storage.h" // gea::host::Storage for GEADEV STORAGE SET
52
+
53
+ namespace gea::platform::esp32::services {
54
+
55
+ namespace {
56
+
57
+ // The GEADEV command console is a development facility, and its task stack is
58
+ // 8 KiB of internal SRAM -- which on an S3 is the same memory an app's DMA
59
+ // buffers and real-time arenas come from. An app whose own budget lives there
60
+ // can set GEA_EMBEDDED_DEVICE_CONTROL=0 in gea.defines to leave the task
61
+ // unstarted. captureScreenshotRgb565() below is unaffected either way: the
62
+ // Wi-Fi OTA server's /screenshot endpoint calls it without a console.
63
+ #ifndef GEA_EMBEDDED_DEVICE_CONTROL
64
+ #define GEA_EMBEDDED_DEVICE_CONTROL 1
65
+ #endif
66
+
67
+ constexpr const char *kTag = "gea_device_ctl";
68
+ constexpr int kTaskStackBytes = 8192;
69
+ constexpr int kTaskPriority = 4;
70
+ constexpr int kUsbJtagTaskStackBytes = 8192;
71
+
72
+ enum class CommandSource {
73
+ Stdio,
74
+ UsbSerialJtag,
75
+ };
76
+
77
+ SemaphoreHandle_t gCommandMutex = nullptr;
78
+
79
+ std::uint32_t crc32Stream(std::uint32_t crc, const std::uint8_t *data, std::size_t n);
80
+ extern "C" bool geaDisplaySnapshotPrefersPresented() __attribute__((weak));
81
+
82
+ // Mirrors the engine's default (core/packages/engine/ui/tree_render.cpp): a target
83
+ // that does not fuse the replay into the flush keeps a persistent framebuffer.
84
+ #ifndef GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH
85
+ #define GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH 0
86
+ #endif
87
+
88
+ char *skipSpace(char *p)
89
+ {
90
+ while (p && *p && std::isspace(static_cast<unsigned char>(*p))) p++;
91
+ return p;
92
+ }
93
+
94
+ char *nextToken(char *&p)
95
+ {
96
+ p = skipSpace(p);
97
+ if (!p || !*p) return nullptr;
98
+ char *token = p;
99
+ while (*p && !std::isspace(static_cast<unsigned char>(*p))) p++;
100
+ if (*p) *p++ = '\0';
101
+ return token;
102
+ }
103
+
104
+ bool parseInt(char *token, int *out)
105
+ {
106
+ if (!token || !out) return false;
107
+ char *end = nullptr;
108
+ const long value = std::strtol(token, &end, 10);
109
+ if (!end || *end != '\0') return false;
110
+ if (value < -32768 || value > 32767) return false;
111
+ *out = static_cast<int>(value);
112
+ return true;
113
+ }
114
+
115
+ bool tokenEquals(const char *a, const char *b)
116
+ {
117
+ if (!a || !b) return false;
118
+ while (*a && *b) {
119
+ const int ca = std::toupper(static_cast<unsigned char>(*a++));
120
+ const int cb = std::toupper(static_cast<unsigned char>(*b++));
121
+ if (ca != cb) return false;
122
+ }
123
+ return *a == '\0' && *b == '\0';
124
+ }
125
+
126
+ bool storageKeyIsSensitive(const char *key)
127
+ {
128
+ if (!key) return true;
129
+ std::string lower;
130
+ for (const char *p = key; *p; ++p)
131
+ lower.push_back(static_cast<char>(std::tolower(static_cast<unsigned char>(*p))));
132
+ return lower.find("key") != std::string::npos ||
133
+ lower.find("token") != std::string::npos ||
134
+ lower.find("secret") != std::string::npos ||
135
+ lower.find("password") != std::string::npos;
136
+ }
137
+
138
+ class Base64Writer {
139
+ public:
140
+ void writeByte(std::uint8_t byte)
141
+ {
142
+ pending_[pendingLength_++] = byte;
143
+ if (pendingLength_ == 3) {
144
+ writeQuantum(pending_, 3);
145
+ pendingLength_ = 0;
146
+ }
147
+ }
148
+
149
+ void finish()
150
+ {
151
+ if (pendingLength_ > 0) {
152
+ writeQuantum(pending_, pendingLength_);
153
+ pendingLength_ = 0;
154
+ }
155
+ flushLine();
156
+ }
157
+
158
+ private:
159
+ void writeQuantum(const std::uint8_t *bytes, int length)
160
+ {
161
+ const std::uint32_t a = length > 0 ? bytes[0] : 0;
162
+ const std::uint32_t b = length > 1 ? bytes[1] : 0;
163
+ const std::uint32_t c = length > 2 ? bytes[2] : 0;
164
+ const std::uint32_t value = (a << 16) | (b << 8) | c;
165
+
166
+ append(kAlphabet[(value >> 18) & 0x3f]);
167
+ append(kAlphabet[(value >> 12) & 0x3f]);
168
+ append(length > 1 ? kAlphabet[(value >> 6) & 0x3f] : '=');
169
+ append(length > 2 ? kAlphabet[value & 0x3f] : '=');
170
+ }
171
+
172
+ void append(char ch)
173
+ {
174
+ line_[lineLength_++] = ch;
175
+ if (lineLength_ >= kLineLength) flushLine();
176
+ }
177
+
178
+ void flushLine()
179
+ {
180
+ if (lineLength_ <= 0) return;
181
+ std::printf("GEADEV:DATA ");
182
+ std::fwrite(line_, 1, static_cast<std::size_t>(lineLength_), stdout);
183
+ std::printf("\n");
184
+ lineLength_ = 0;
185
+ }
186
+
187
+ static constexpr int kLineLength = 76;
188
+ static constexpr char kAlphabet[] =
189
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
190
+
191
+ std::uint8_t pending_[3]{};
192
+ int pendingLength_ = 0;
193
+ char line_[kLineLength]{};
194
+ int lineLength_ = 0;
195
+ };
196
+
197
+ void writeU16(Base64Writer &writer, std::uint16_t value)
198
+ {
199
+ writer.writeByte(static_cast<std::uint8_t>(value & 0xff));
200
+ writer.writeByte(static_cast<std::uint8_t>((value >> 8) & 0xff));
201
+ }
202
+
203
+ void writeRun(Base64Writer &writer, std::uint16_t count, std::uint16_t rgb565)
204
+ {
205
+ writeU16(writer, count);
206
+ writeU16(writer, rgb565);
207
+ }
208
+
209
+ bool captureSnapshotRgb565(std::uint16_t *snapshot, int pixelCapacity, int *width, int *height,
210
+ char *appIdBuffer, std::size_t appIdBufferSize)
211
+ {
212
+ using gea::platform::display::Display;
213
+
214
+ gea::framework::services::AppState::lock();
215
+ bool copied = false;
216
+ bool copiedRetained = false;
217
+ // A screenshot must show what the panel is actually showing. The retained
218
+ // re-replay below rebuilds the frame from the display list, so it reports what
219
+ // the engine MEANT to draw -- it cannot witness a defect in the rasterizer, the
220
+ // flush, or the panel byte order, and it silently skips whatever the live frame
221
+ // took from a cache (the static backdrop blit, the bg gradient cache). That made
222
+ // it a false witness while chasing corrupted pixels on css-3d-cube: the capture
223
+ // came back clean every time while the panel was visibly wrong.
224
+ //
225
+ // When the framebuffer is persistent (the replay is NOT fused into the flush) it
226
+ // holds the real, just-presented frame, so copy that instead. Only the fused path
227
+ // leaves the framebuffer frozen at frame 0 -- that is the case the re-replay was
228
+ // written for, and it keeps it.
229
+ const bool framebufferIsLive = GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH == 0;
230
+ if (framebufferIsLive ||
231
+ (geaDisplaySnapshotPrefersPresented && geaDisplaySnapshotPrefersPresented())) {
232
+ copied = Display::copySnapshotRgb565(snapshot, pixelCapacity, width, height, true);
233
+ }
234
+
235
+ // Retained apps render through the fused flush, which writes the DMA staging buffer
236
+ // and leaves the PSRAM framebuffer frozen at frame 0 — so copySnapshotRgb565 would
237
+ // return a stale boot frame. Re-replay the live display list into the snapshot first;
238
+ // fall back to the framebuffer/present copy for canvas apps (renderRetained returns
239
+ // false when there's no retained command list).
240
+ if (!copied) {
241
+ copied = gea::embedded::ui::renderRetainedSnapshotRgb565(
242
+ snapshot, gea::platform::display::kWidth, gea::platform::display::kHeight);
243
+ copiedRetained = copied;
244
+ }
245
+ if (copiedRetained)
246
+ {
247
+ *width = gea::platform::display::kWidth;
248
+ *height = gea::platform::display::kHeight;
249
+ }
250
+ else if (!copied)
251
+ {
252
+ copied = Display::copySnapshotRgb565(snapshot, pixelCapacity, width, height, true);
253
+ }
254
+ const char *appId = gea::framework::apps::AppManager::currentId();
255
+ if (appIdBuffer && appIdBufferSize > 0)
256
+ std::snprintf(appIdBuffer, appIdBufferSize, "%s", appId ? appId : "");
257
+ gea::framework::services::AppState::unlock();
258
+
259
+ return copied && *width > 0 && *height > 0;
260
+ }
261
+
262
+ #if GEA_PIXEL_STORAGE_PACKED
263
+ // Same shape as captureSnapshotRgb565, but for a board whose native storage is
264
+ // sub-byte packed (GRAY4/GRAY2): copies the packed pixel stream under the
265
+ // AppState lock (cheap -- it's the board's real, small framebuffer, not an
266
+ // RGB565 expansion of it) and releases the lock before any encoding happens.
267
+ // There is no fused-replay/retained-snapshot variant here: that optimization
268
+ // (GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH) targets fast panels with a DMA
269
+ // staging buffer, never the e-paper GRAY4/GRAY2 boards this path serves.
270
+ bool captureSnapshotPacked(std::uint8_t *snapshot, int byteCapacity, int *width, int *height,
271
+ char *appIdBuffer, std::size_t appIdBufferSize)
272
+ {
273
+ using gea::platform::display::Display;
274
+
275
+ gea::framework::services::AppState::lock();
276
+ const bool copied = Display::copySnapshotPacked(snapshot, byteCapacity, width, height, true);
277
+ const char *appId = gea::framework::apps::AppManager::currentId();
278
+ if (appIdBuffer && appIdBufferSize > 0)
279
+ std::snprintf(appIdBuffer, appIdBufferSize, "%s", appId ? appId : "");
280
+ gea::framework::services::AppState::unlock();
281
+
282
+ return copied && *width > 0 && *height > 0;
283
+ }
284
+ #endif // GEA_PIXEL_STORAGE_PACKED
285
+
286
+ void writeScreenshot()
287
+ {
288
+ int width = 0;
289
+ int height = 0;
290
+ char appIdBuffer[96];
291
+
292
+ #if GEA_PIXEL_STORAGE_PACKED
293
+ // A packed (GRAY4/GRAY2) board's real framebuffer is a quarter/eighth the
294
+ // size an RGB565 expansion of the same pixels would need -- allocate that
295
+ // (what the device can actually spare) and expand to RGB565 per pixel while
296
+ // RLE-encoding below, instead of asking heap_caps_malloc for a buffer sized
297
+ // for a pixel format this board doesn't have.
298
+ const int pixelCountInt = gea::platform::display::kWidth * gea::platform::display::kHeight;
299
+ const std::size_t pixelCount = static_cast<std::size_t>(pixelCountInt);
300
+ const std::size_t byteCount =
301
+ static_cast<std::size_t>(gea::framework::graphics::pixel::packed::rowBytes(pixelCountInt));
302
+ auto *snapshot = static_cast<std::uint8_t *>(
303
+ heap_caps_malloc(byteCount, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
304
+ bool heapCapsAllocated = snapshot != nullptr;
305
+ if (!snapshot) snapshot = static_cast<std::uint8_t *>(std::malloc(byteCount));
306
+ if (!snapshot) {
307
+ std::printf("GEADEV:ERR SCREENSHOT no-memory bytes=%u\n", static_cast<unsigned>(byteCount));
308
+ std::fflush(stdout);
309
+ return;
310
+ }
311
+
312
+ const bool copied = captureSnapshotPacked(snapshot, static_cast<int>(byteCount), &width, &height,
313
+ appIdBuffer, sizeof(appIdBuffer));
314
+ if (!copied) {
315
+ if (heapCapsAllocated) heap_caps_free(snapshot);
316
+ else std::free(snapshot);
317
+ std::printf("GEADEV:ERR SCREENSHOT display-unavailable\n");
318
+ std::fflush(stdout);
319
+ return;
320
+ }
321
+
322
+ flockfile(stdout);
323
+ std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n",
324
+ width,
325
+ height,
326
+ appIdBuffer);
327
+
328
+ Base64Writer writer;
329
+ if (pixelCount > 0) {
330
+ using gea::framework::graphics::pixel::packed;
331
+ using gea::framework::graphics::pixel::fromNative;
332
+ std::uint16_t runValue = fromNative(packed::get(snapshot, 0));
333
+ std::uint16_t runCount = 1;
334
+ for (std::size_t i = 1; i < pixelCount; i++) {
335
+ const std::uint16_t value = fromNative(packed::get(snapshot, static_cast<int>(i)));
336
+ if (value == runValue && runCount < 65535) {
337
+ runCount++;
338
+ continue;
339
+ }
340
+ writeRun(writer, runCount, runValue);
341
+ runValue = value;
342
+ runCount = 1;
343
+ }
344
+ writeRun(writer, runCount, runValue);
345
+ }
346
+ writer.finish();
347
+ std::printf("GEADEV:SCREENSHOT END\n");
348
+ std::fflush(stdout);
349
+ funlockfile(stdout);
350
+
351
+ if (heapCapsAllocated) heap_caps_free(snapshot);
352
+ else std::free(snapshot);
353
+ #else
354
+ const int pixelCountInt = gea::platform::display::kWidth * gea::platform::display::kHeight;
355
+ const std::size_t pixelCount = static_cast<std::size_t>(pixelCountInt);
356
+ auto *snapshot = static_cast<std::uint16_t *>(
357
+ heap_caps_malloc(pixelCount * sizeof(std::uint16_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
358
+ bool heapCapsAllocated = snapshot != nullptr;
359
+ if (!snapshot) snapshot = static_cast<std::uint16_t *>(std::malloc(pixelCount * sizeof(std::uint16_t)));
360
+ if (!snapshot) {
361
+ std::printf("GEADEV:ERR SCREENSHOT no-memory bytes=%u\n",
362
+ static_cast<unsigned>(pixelCount * sizeof(std::uint16_t)));
363
+ std::fflush(stdout);
364
+ return;
365
+ }
366
+
367
+ const bool copied = captureSnapshotRgb565(snapshot, pixelCountInt, &width, &height,
368
+ appIdBuffer, sizeof(appIdBuffer));
369
+ if (!copied) {
370
+ if (heapCapsAllocated) heap_caps_free(snapshot);
371
+ else std::free(snapshot);
372
+ std::printf("GEADEV:ERR SCREENSHOT display-unavailable\n");
373
+ std::fflush(stdout);
374
+ return;
375
+ }
376
+
377
+ flockfile(stdout);
378
+ std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n",
379
+ width,
380
+ height,
381
+ appIdBuffer);
382
+
383
+ Base64Writer writer;
384
+ if (pixelCount > 0) {
385
+ std::uint16_t runValue = snapshot[0];
386
+ std::uint16_t runCount = 1;
387
+ for (std::size_t i = 1; i < pixelCount; i++) {
388
+ const std::uint16_t value = snapshot[i];
389
+ if (value == runValue && runCount < 65535) {
390
+ runCount++;
391
+ continue;
392
+ }
393
+ writeRun(writer, runCount, runValue);
394
+ runValue = value;
395
+ runCount = 1;
396
+ }
397
+ writeRun(writer, runCount, runValue);
398
+ }
399
+ writer.finish();
400
+ std::printf("GEADEV:SCREENSHOT END\n");
401
+ std::fflush(stdout);
402
+ funlockfile(stdout);
403
+
404
+ if (heapCapsAllocated) heap_caps_free(snapshot);
405
+ else std::free(snapshot);
406
+ #endif // GEA_PIXEL_STORAGE_PACKED
407
+ }
408
+
409
+ #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
410
+ class ScopedLogSilence {
411
+ public:
412
+ ScopedLogSilence()
413
+ : previous_(esp_log_level_get(nullptr))
414
+ {
415
+ esp_log_level_set("*", ESP_LOG_NONE);
416
+ }
417
+
418
+ ~ScopedLogSilence()
419
+ {
420
+ esp_log_level_set("*", previous_);
421
+ }
422
+
423
+ private:
424
+ esp_log_level_t previous_;
425
+ };
426
+
427
+ bool usbWriteAll(const void *data, std::size_t size)
428
+ {
429
+ const auto *bytes = static_cast<const std::uint8_t *>(data);
430
+ std::size_t offset = 0;
431
+ int emptyWrites = 0;
432
+ while (offset < size) {
433
+ const std::size_t remaining = size - offset;
434
+ const std::size_t chunk = remaining > 512 ? 512 : remaining;
435
+ const int wrote = usb_serial_jtag_write_bytes(bytes + offset, chunk, pdMS_TO_TICKS(1000));
436
+ if (wrote <= 0) {
437
+ if (++emptyWrites > 5) return false;
438
+ vTaskDelay(pdMS_TO_TICKS(2));
439
+ continue;
440
+ }
441
+ emptyWrites = 0;
442
+ offset += static_cast<std::size_t>(wrote);
443
+ }
444
+ return true;
445
+ }
446
+
447
+ bool usbPrintf(const char *format, ...)
448
+ {
449
+ char line[192];
450
+ va_list args;
451
+ va_start(args, format);
452
+ const int n = std::vsnprintf(line, sizeof(line), format, args);
453
+ va_end(args);
454
+ if (n <= 0) return true;
455
+ const std::size_t len = static_cast<std::size_t>(n);
456
+ if (len < sizeof(line)) return usbWriteAll(line, len);
457
+
458
+ char *heapLine = static_cast<char *>(std::malloc(len + 1));
459
+ if (!heapLine) return false;
460
+ va_start(args, format);
461
+ std::vsnprintf(heapLine, len + 1, format, args);
462
+ va_end(args);
463
+ const bool ok = usbWriteAll(heapLine, len);
464
+ std::free(heapLine);
465
+ return ok;
466
+ }
467
+
468
+ #if GEA_PIXEL_STORAGE_PACKED
469
+ void writeScreenshotUsbRaw()
470
+ {
471
+ int width = 0;
472
+ int height = 0;
473
+ const int pixelCountInt = gea::platform::display::kWidth * gea::platform::display::kHeight;
474
+ const std::size_t byteCount =
475
+ static_cast<std::size_t>(gea::framework::graphics::pixel::packed::rowBytes(pixelCountInt));
476
+ auto *snapshot = static_cast<std::uint8_t *>(
477
+ heap_caps_malloc(byteCount, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
478
+ bool heapCapsAllocated = snapshot != nullptr;
479
+ if (!snapshot) snapshot = static_cast<std::uint8_t *>(std::malloc(byteCount));
480
+ if (!snapshot) {
481
+ usbPrintf("GEADEV:ERR SCREENSHOTBIN no-memory bytes=%u\n", static_cast<unsigned>(byteCount));
482
+ return;
483
+ }
484
+
485
+ char appIdBuffer[96];
486
+ const bool copied = captureSnapshotPacked(snapshot, static_cast<int>(byteCount), &width, &height,
487
+ appIdBuffer, sizeof(appIdBuffer));
488
+ if (!copied) {
489
+ if (heapCapsAllocated) heap_caps_free(snapshot);
490
+ else std::free(snapshot);
491
+ usbPrintf("GEADEV:ERR SCREENSHOTBIN display-unavailable\n");
492
+ return;
493
+ }
494
+
495
+ // Wire format stays rgb565-raw-v1 (host decoder is unchanged): expand packed
496
+ // pixels to RGB565 ONE ROW AT A TIME while streaming to USB, instead of
497
+ // holding a second full-frame RGB565 buffer the device does not have room
498
+ // for. The packed snapshot above was copied under the AppState lock; the
499
+ // expand-and-send loop below runs entirely outside it, same as the RGB565
500
+ // path.
501
+ const std::size_t bytes = static_cast<std::size_t>(width) * static_cast<std::size_t>(height) * sizeof(std::uint16_t);
502
+ const std::size_t rowBytes = static_cast<std::size_t>(width) * sizeof(std::uint16_t);
503
+ auto *rowRgb = static_cast<std::uint16_t *>(heap_caps_malloc(rowBytes, MALLOC_CAP_8BIT));
504
+ bool rowHeapCapsAllocated = rowRgb != nullptr;
505
+ if (!rowRgb) rowRgb = static_cast<std::uint16_t *>(std::malloc(rowBytes));
506
+ if (!rowRgb) {
507
+ if (heapCapsAllocated) heap_caps_free(snapshot);
508
+ else std::free(snapshot);
509
+ usbPrintf("GEADEV:ERR SCREENSHOTBIN no-memory bytes=%u\n", static_cast<unsigned>(rowBytes));
510
+ return;
511
+ }
512
+
513
+ ScopedLogSilence silence;
514
+ flockfile(stdout);
515
+ std::fflush(stdout);
516
+ usb_serial_jtag_wait_tx_done(pdMS_TO_TICKS(500));
517
+ const bool headerOk = usbPrintf(
518
+ "GEADEV:SCREENSHOTBIN BEGIN width=%d height=%d encoding=rgb565-raw-v1 bytes=%u app=%s\n",
519
+ width, height, static_cast<unsigned>(bytes), appIdBuffer);
520
+
521
+ using gea::framework::graphics::pixel::packed;
522
+ using gea::framework::graphics::pixel::fromNative;
523
+ std::uint32_t crc = 0xFFFFFFFFu;
524
+ bool bodyOk = headerOk;
525
+ for (int row = 0; row < height && bodyOk; ++row) {
526
+ for (int x = 0; x < width; ++x)
527
+ rowRgb[x] = fromNative(packed::get(snapshot, row * width + x));
528
+ crc = crc32Stream(crc, reinterpret_cast<const std::uint8_t *>(rowRgb), rowBytes);
529
+ bodyOk = usbWriteAll(rowRgb, rowBytes);
530
+ }
531
+ crc ^= 0xFFFFFFFFu;
532
+ const bool footerOk = bodyOk && usbPrintf("GEADEV:SCREENSHOTBIN END bytes=%u crc=0x%08x\n",
533
+ static_cast<unsigned>(bytes), static_cast<unsigned>(crc));
534
+ (void)footerOk;
535
+ usb_serial_jtag_wait_tx_done(pdMS_TO_TICKS(5000));
536
+ funlockfile(stdout);
537
+
538
+ if (rowHeapCapsAllocated) heap_caps_free(rowRgb);
539
+ else std::free(rowRgb);
540
+ if (heapCapsAllocated) heap_caps_free(snapshot);
541
+ else std::free(snapshot);
542
+ }
543
+ #else
544
+ void writeScreenshotUsbRaw()
545
+ {
546
+ int width = 0;
547
+ int height = 0;
548
+ const int pixelCountInt = gea::platform::display::kWidth * gea::platform::display::kHeight;
549
+ const std::size_t pixelCount = static_cast<std::size_t>(pixelCountInt);
550
+ auto *snapshot = static_cast<std::uint16_t *>(
551
+ heap_caps_malloc(pixelCount * sizeof(std::uint16_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
552
+ bool heapCapsAllocated = snapshot != nullptr;
553
+ if (!snapshot) snapshot = static_cast<std::uint16_t *>(std::malloc(pixelCount * sizeof(std::uint16_t)));
554
+ if (!snapshot) {
555
+ usbPrintf("GEADEV:ERR SCREENSHOTBIN no-memory bytes=%u\n",
556
+ static_cast<unsigned>(pixelCount * sizeof(std::uint16_t)));
557
+ return;
558
+ }
559
+
560
+ char appIdBuffer[96];
561
+ const bool copied = captureSnapshotRgb565(snapshot, pixelCountInt, &width, &height,
562
+ appIdBuffer, sizeof(appIdBuffer));
563
+ if (!copied) {
564
+ if (heapCapsAllocated) heap_caps_free(snapshot);
565
+ else std::free(snapshot);
566
+ usbPrintf("GEADEV:ERR SCREENSHOTBIN display-unavailable\n");
567
+ return;
568
+ }
569
+
570
+ const std::size_t bytes = static_cast<std::size_t>(width) * static_cast<std::size_t>(height) * sizeof(std::uint16_t);
571
+ const std::uint32_t crc = crc32Stream(0xFFFFFFFFu, reinterpret_cast<const std::uint8_t *>(snapshot), bytes) ^ 0xFFFFFFFFu;
572
+ ScopedLogSilence silence;
573
+ flockfile(stdout);
574
+ std::fflush(stdout);
575
+ usb_serial_jtag_wait_tx_done(pdMS_TO_TICKS(500));
576
+ const bool headerOk = usbPrintf(
577
+ "GEADEV:SCREENSHOTBIN BEGIN width=%d height=%d encoding=rgb565-raw-v1 bytes=%u app=%s\n",
578
+ width, height, static_cast<unsigned>(bytes), appIdBuffer);
579
+ const bool bodyOk = headerOk && usbWriteAll(snapshot, bytes);
580
+ const bool footerOk = bodyOk && usbPrintf("GEADEV:SCREENSHOTBIN END bytes=%u crc=0x%08x\n",
581
+ static_cast<unsigned>(bytes), static_cast<unsigned>(crc));
582
+ (void)footerOk;
583
+ usb_serial_jtag_wait_tx_done(pdMS_TO_TICKS(5000));
584
+ funlockfile(stdout);
585
+
586
+ if (heapCapsAllocated) heap_caps_free(snapshot);
587
+ else std::free(snapshot);
588
+ }
589
+ #endif // GEA_PIXEL_STORAGE_PACKED
590
+ #endif
591
+
592
+ // Set the system wall clock from the host (no WiFi/SNTP needed). The watch face
593
+ // reads it via Date(); the host sends its own clock so the watch shows real time.
594
+ void handleSetTime(char *&cursor)
595
+ {
596
+ char *tok = nextToken(cursor);
597
+ if (!tok || tok[0] == '\0') {
598
+ std::printf("GEADEV:ERR SETTIME usage=GEADEV_SETTIME_epoch_seconds\n");
599
+ return;
600
+ }
601
+ const long long epoch = std::strtoll(tok, nullptr, 10);
602
+ struct timeval tv;
603
+ tv.tv_sec = static_cast<time_t>(epoch);
604
+ tv.tv_usec = 0;
605
+ if (settimeofday(&tv, nullptr) == 0) {
606
+ struct timeval back;
607
+ gettimeofday(&back, nullptr);
608
+ std::printf("GEADEV:OK SETTIME epoch=%lld readback=%lld\n", epoch, static_cast<long long>(back.tv_sec));
609
+ } else {
610
+ std::printf("GEADEV:ERR SETTIME settimeofday-failed\n");
611
+ }
612
+ }
613
+
614
+ // Get or set the display backlight brightness (0-100%) from the host. No arg
615
+ // reports the current value; with an arg, clamps to 0-100, sets it via the
616
+ // Display service, and reads it back. Gives the Mac companion a brightness
617
+ // control over USB (the same Display::setBrightness the settings panel uses).
618
+ void handleBrightness(char *&cursor)
619
+ {
620
+ using gea::platform::display::Display;
621
+ char *tok = nextToken(cursor);
622
+ if (!tok || tok[0] == '\0') {
623
+ std::printf("GEADEV:OK BRIGHTNESS value=%d\n", Display::brightness());
624
+ return;
625
+ }
626
+ int pct = 0;
627
+ if (!parseInt(tok, &pct)) {
628
+ std::printf("GEADEV:ERR BRIGHTNESS usage=GEADEV_BRIGHTNESS_[0-100]\n");
629
+ return;
630
+ }
631
+ if (pct < 0) pct = 0;
632
+ if (pct > 100) pct = 100;
633
+ Display::setBrightness(pct);
634
+ std::printf("GEADEV:OK BRIGHTNESS value=%d readback=%d\n", pct, Display::brightness());
635
+ }
636
+
637
+ // GEADEV HBM / VSYNC [on|off] -- the panel toggles that sit beside
638
+ // brightness. Every display knob has to answer on BOTH transports: an app
639
+ // with no network binding builds firmware with WiFi disabled, so the HTTP
640
+ // endpoints in ota.cpp are unreachable and USB is the only way in.
641
+ // Accepts on/off, 1/0, true/false, yes/no. `off` and `on` share no first
642
+ // letter with each other's negation, so the first character decides except
643
+ // for the o-pair, which needs the second.
644
+ bool parseOnOff(const char *token, bool *out)
645
+ {
646
+ if (!token || token[0] == '\0') return false;
647
+ const char first = static_cast<char>(std::tolower(static_cast<unsigned char>(token[0])));
648
+ const char second = static_cast<char>(std::tolower(static_cast<unsigned char>(token[1])));
649
+ if (first == 'o') {
650
+ if (second == 'n') {
651
+ *out = true;
652
+ return true;
653
+ }
654
+ if (second == 'f') {
655
+ *out = false;
656
+ return true;
657
+ }
658
+ return false;
659
+ }
660
+ if (first == '1' || first == 't' || first == 'y') {
661
+ *out = true;
662
+ return true;
663
+ }
664
+ if (first == '0' || first == 'f' || first == 'n') {
665
+ *out = false;
666
+ return true;
667
+ }
668
+ return false;
669
+ }
670
+
671
+ void handleHbm(char *&cursor)
672
+ {
673
+ using gea::platform::display::Display;
674
+ char *tok = nextToken(cursor);
675
+ if (!tok || tok[0] == '\0') {
676
+ std::printf("GEADEV:OK HBM value=%d\n", Display::highBrightnessMode() ? 1 : 0);
677
+ return;
678
+ }
679
+ bool on = false;
680
+ if (!parseOnOff(tok, &on)) {
681
+ std::printf("GEADEV:ERR HBM usage=GEADEV_HBM_[on|off]\n");
682
+ return;
683
+ }
684
+ // A panel without a high-brightness ceiling reports supported=0 rather
685
+ // than erroring: the caller asked a question the board can answer.
686
+ const bool ok = Display::setHighBrightnessMode(on);
687
+ std::printf("GEADEV:OK HBM value=%d supported=%d\n", Display::highBrightnessMode() ? 1 : 0, ok ? 1 : 0);
688
+ }
689
+
690
+ void handleVsync(char *&cursor)
691
+ {
692
+ using gea::platform::display::Display;
693
+ char *tok = nextToken(cursor);
694
+ if (!tok || tok[0] == '\0') {
695
+ std::printf("GEADEV:OK VSYNC value=%d\n", Display::vsyncEnabled() ? 1 : 0);
696
+ return;
697
+ }
698
+ bool on = false;
699
+ if (!parseOnOff(tok, &on)) {
700
+ std::printf("GEADEV:ERR VSYNC usage=GEADEV_VSYNC_[on|off]\n");
701
+ return;
702
+ }
703
+ Display::setVSync(on);
704
+ std::printf("GEADEV:OK VSYNC value=%d\n", Display::vsyncEnabled() ? 1 : 0);
705
+ }
706
+
707
+ void handleI2cScan()
708
+ {
709
+ auto bus = gea::platform::i2c::Bus::primary();
710
+ if (!bus.available()) {
711
+ std::printf("GEADEV:ERR I2CSCAN bus-unavailable\n");
712
+ return;
713
+ }
714
+
715
+ auto nativeBus = static_cast<i2c_master_bus_handle_t>(bus.nativeHandle());
716
+ int count = 0;
717
+ std::printf("GEADEV:I2CSCAN BEGIN\n");
718
+ for (std::uint16_t address = 0x08; address <= 0x77; address++) {
719
+ const esp_err_t err = i2c_master_probe(nativeBus, address, 50);
720
+ if (err == ESP_OK) {
721
+ std::printf("GEADEV:I2CSCAN ADDR 0x%02x\n", static_cast<unsigned>(address));
722
+ count++;
723
+ }
724
+ }
725
+ std::printf("GEADEV:I2CSCAN END count=%d\n", count);
726
+ }
727
+
728
+ void handleNode(char *&cursor)
729
+ {
730
+ const char *className = nextToken(cursor);
731
+ if (!className || className[0] == '\0') {
732
+ std::printf("GEADEV:ERR NODE usage=GEADEV_NODE_class\n");
733
+ return;
734
+ }
735
+
736
+ gea::framework::services::AppState::lock();
737
+ auto &tree = gea::embedded::ui::Tree::instance();
738
+ const int nodeCount = tree.nodeCount();
739
+ int printed = 0;
740
+ for (int nodeId = 0; nodeId < nodeCount; nodeId++) {
741
+ if (!tree.hasClass(nodeId, className)) continue;
742
+ const auto &node = tree.node(nodeId);
743
+ int16_t xs[4] = {};
744
+ int16_t ys[4] = {};
745
+ gea::embedded::ui::ViewRenderer::transformedRectCorners(node,
746
+ false,
747
+ node.layout.x,
748
+ node.layout.y,
749
+ node.layout.width,
750
+ node.layout.height,
751
+ xs,
752
+ ys);
753
+ std::printf(
754
+ "GEADEV:NODE class=%s id=%d parent=%d type=%d display=%d style=%dx%d min=%dx%d max=%dx%d pos=%d,%d,%d,%d transform=%d,%d,%d,%d,%d layout=%d,%d,%d,%d corners=%d,%d;%d,%d;%d,%d;%d,%d ovf=%d,%d,%d scroll=%d,%d,%d,%d\n",
755
+ className,
756
+ nodeId,
757
+ node.parent,
758
+ static_cast<int>(node.type),
759
+ node.style.display,
760
+ node.style.width,
761
+ node.style.height,
762
+ node.style.min_width,
763
+ node.style.min_height,
764
+ node.style.max_width,
765
+ node.style.max_height,
766
+ node.style.pos_offsets[3],
767
+ node.style.pos_offsets[0],
768
+ node.style.pos_offsets[1],
769
+ node.style.pos_offsets[2],
770
+ gea::embedded::ui::rstyle(node.style).transform_translate_x,
771
+ gea::embedded::ui::rstyle(node.style).transform_translate_y,
772
+ gea::embedded::ui::rstyle(node.style).transform_translate_x_percent,
773
+ gea::embedded::ui::rstyle(node.style).transform_translate_y_percent,
774
+ gea::embedded::ui::rstyle(node.style).transform_rotate,
775
+ node.layout.x,
776
+ node.layout.y,
777
+ node.layout.width,
778
+ node.layout.height,
779
+ xs[0],
780
+ ys[0],
781
+ xs[1],
782
+ ys[1],
783
+ xs[2],
784
+ ys[2],
785
+ xs[3],
786
+ ys[3],
787
+ static_cast<int>(node.style.overflow),
788
+ static_cast<int>(node.style.overflow_x),
789
+ static_cast<int>(node.style.overflow_y),
790
+ static_cast<int>(node.layout.scroll_x),
791
+ static_cast<int>(node.layout.scroll_y),
792
+ static_cast<int>(node.layout.scroll_content_width),
793
+ static_cast<int>(node.layout.scroll_content_height));
794
+ printed++;
795
+ }
796
+ gea::framework::services::AppState::unlock();
797
+ if (printed == 0) std::printf("GEADEV:NODE class=%s none=1 nodes=%d\n", className, nodeCount);
798
+ }
799
+
800
+ void handleHitTest(char *&cursor)
801
+ {
802
+ int x = 0;
803
+ int y = 0;
804
+ if (!parseInt(nextToken(cursor), &x) || !parseInt(nextToken(cursor), &y)) {
805
+ std::printf("GEADEV:ERR HITTEST usage=GEADEV_HITTEST_x_y\n");
806
+ return;
807
+ }
808
+
809
+ gea::framework::services::AppState::lock();
810
+ auto &tree = gea::embedded::ui::Tree::instance();
811
+ const int nodeId = tree.hitTestNode(x, y);
812
+ const int pressTarget = tree.hitTest(x, y);
813
+ if (nodeId < 0 || nodeId >= tree.nodeCount()) {
814
+ gea::framework::services::AppState::unlock();
815
+ std::printf("GEADEV:HITTEST x=%d y=%d node=-1 press=-1\n", x, y);
816
+ return;
817
+ }
818
+ const auto &node = tree.node(nodeId);
819
+ const std::string classes = tree.className(nodeId);
820
+ const int pressId = tree.pressId(nodeId);
821
+ std::printf(
822
+ "GEADEV:HITTEST x=%d y=%d node=%d parent=%d type=%d display=%d class=\"%s\" press=%d press_id=%d transform=%d,%d,%d,%d,%d layout=%d,%d,%d,%d\n",
823
+ x,
824
+ y,
825
+ nodeId,
826
+ node.parent,
827
+ static_cast<int>(node.type),
828
+ node.style.display,
829
+ classes.c_str(),
830
+ pressTarget,
831
+ pressId,
832
+ gea::embedded::ui::rstyle(node.style).transform_translate_x,
833
+ gea::embedded::ui::rstyle(node.style).transform_translate_y,
834
+ gea::embedded::ui::rstyle(node.style).transform_translate_x_percent,
835
+ gea::embedded::ui::rstyle(node.style).transform_translate_y_percent,
836
+ gea::embedded::ui::rstyle(node.style).transform_rotate,
837
+ node.layout.x,
838
+ node.layout.y,
839
+ node.layout.width,
840
+ node.layout.height);
841
+ gea::framework::services::AppState::unlock();
842
+ }
843
+
844
+ void handleTap(char *&cursor)
845
+ {
846
+ int x = 0;
847
+ int y = 0;
848
+ int holdMs = 80;
849
+ if (!parseInt(nextToken(cursor), &x) || !parseInt(nextToken(cursor), &y)) {
850
+ std::printf("GEADEV:ERR TAP usage=GEADEV_TAP_x_y_[hold_ms]\n");
851
+ return;
852
+ }
853
+ char *holdToken = nextToken(cursor);
854
+ if (holdToken && !parseInt(holdToken, &holdMs)) {
855
+ std::printf("GEADEV:ERR TAP invalid-hold-ms\n");
856
+ return;
857
+ }
858
+ if (holdMs < 0) holdMs = 0;
859
+ if (holdMs > 2000) holdMs = 2000;
860
+
861
+ gea::framework::events::TouchRuntime::queueTouchEvent(gea::framework::events::TouchPhase::Down, true, x, y);
862
+ vTaskDelay(pdMS_TO_TICKS(holdMs));
863
+ gea::framework::events::TouchRuntime::queueTouchEvent(gea::framework::events::TouchPhase::Up, false, x, y);
864
+ std::printf("GEADEV:OK TAP x=%d y=%d hold_ms=%d\n", x, y, holdMs);
865
+ }
866
+
867
+ void handleDrag(char *&cursor)
868
+ {
869
+ int x1 = 0;
870
+ int y1 = 0;
871
+ int x2 = 0;
872
+ int y2 = 0;
873
+ int steps = 6;
874
+ int delayMs = 24;
875
+ if (!parseInt(nextToken(cursor), &x1) || !parseInt(nextToken(cursor), &y1) ||
876
+ !parseInt(nextToken(cursor), &x2) || !parseInt(nextToken(cursor), &y2)) {
877
+ std::printf("GEADEV:ERR DRAG usage=GEADEV_DRAG_x1_y1_x2_y2_[steps]_[delay_ms]\n");
878
+ return;
879
+ }
880
+ char *stepsToken = nextToken(cursor);
881
+ if (stepsToken && !parseInt(stepsToken, &steps)) {
882
+ std::printf("GEADEV:ERR DRAG invalid-steps\n");
883
+ return;
884
+ }
885
+ char *delayToken = nextToken(cursor);
886
+ if (delayToken && !parseInt(delayToken, &delayMs)) {
887
+ std::printf("GEADEV:ERR DRAG invalid-delay-ms\n");
888
+ return;
889
+ }
890
+ if (steps < 1) steps = 1;
891
+ if (steps > 64) steps = 64;
892
+ if (delayMs < 0) delayMs = 0;
893
+ if (delayMs > 250) delayMs = 250;
894
+
895
+ // Drive the drag through Touchscreen::injectEvent (not queueTouchEvent): the
896
+ // Move phase must update the controller's latestMove_ cache, or the
897
+ // TouchRuntime's consumeLatestMove overwrites these coords with the last real
898
+ // hardware sample and the synthetic drag never scrolls a momentum container.
899
+ using gea::platform::touch::Touchscreen;
900
+ using gea::platform::touch::Phase;
901
+ Touchscreen::injectEvent(Phase::Down, true, x1, y1);
902
+ for (int i = 1; i <= steps; ++i) {
903
+ if (delayMs > 0) vTaskDelay(pdMS_TO_TICKS(delayMs));
904
+ const int x = x1 + ((x2 - x1) * i) / steps;
905
+ const int y = y1 + ((y2 - y1) * i) / steps;
906
+ Touchscreen::injectEvent(Phase::Move, true, x, y);
907
+ }
908
+ if (delayMs > 0) vTaskDelay(pdMS_TO_TICKS(delayMs));
909
+ Touchscreen::injectEvent(Phase::Up, false, x2, y2);
910
+ std::printf("GEADEV:OK DRAG x1=%d y1=%d x2=%d y2=%d steps=%d delay_ms=%d\n",
911
+ x1, y1, x2, y2, steps, delayMs);
912
+ }
913
+
914
+ void handleRotary(char *&cursor)
915
+ {
916
+ int delta = 0;
917
+ int repeat = 1;
918
+ int delayMs = 0;
919
+ if (!parseInt(nextToken(cursor), &delta)) {
920
+ std::printf("GEADEV:ERR ROTARY usage=GEADEV_ROTARY_delta_[repeat]_[delay_ms]\n");
921
+ return;
922
+ }
923
+ char *repeatToken = nextToken(cursor);
924
+ if (repeatToken && !parseInt(repeatToken, &repeat)) {
925
+ std::printf("GEADEV:ERR ROTARY invalid-repeat\n");
926
+ return;
927
+ }
928
+ char *delayToken = nextToken(cursor);
929
+ if (delayToken && !parseInt(delayToken, &delayMs)) {
930
+ std::printf("GEADEV:ERR ROTARY invalid-delay-ms\n");
931
+ return;
932
+ }
933
+ if (repeat < 1) repeat = 1;
934
+ if (repeat > 200) repeat = 200;
935
+ if (delayMs < 0) delayMs = 0;
936
+ if (delayMs > 2000) delayMs = 2000;
937
+
938
+ for (int i = 0; i < repeat; ++i) {
939
+ gea::framework::input::queueRotaryDelta(delta);
940
+ if (delayMs > 0 && i + 1 < repeat) vTaskDelay(pdMS_TO_TICKS(delayMs));
941
+ }
942
+ std::printf("GEADEV:OK ROTARY delta=%d repeat=%d delay_ms=%d\n", delta, repeat, delayMs);
943
+ }
944
+
945
+ // Inject a key press (web keyCode) through the same queue hardware buttons
946
+ // use, so button-driven boards (e-paper BOOT/PWR = ArrowUp/ArrowDown) are
947
+ // exercisable over serial.
948
+ void handleKey(char *&cursor)
949
+ {
950
+ int keyCode = 0;
951
+ if (!parseInt(nextToken(cursor), &keyCode) || keyCode == 0) {
952
+ std::printf("GEADEV:ERR KEY usage=GEADEV_KEY_keycode\n");
953
+ return;
954
+ }
955
+ gea::framework::input::queueKeyDown(keyCode);
956
+ std::printf("GEADEV:OK KEY keycode=%d\n", keyCode);
957
+ }
958
+
959
+ // Inspect or seed app-facing localStorage from the host. GET is base64 encoded
960
+ // so tab/newline-rich values survive the line protocol, and secret-like key
961
+ // names are denied to avoid echoing credentials into terminal logs.
962
+ void handleStorage(char *&cursor)
963
+ {
964
+ char *action = nextToken(cursor);
965
+ if (!action) {
966
+ std::printf("GEADEV:ERR STORAGE usage=GEADEV_STORAGE_SET_key_value|GEADEV_STORAGE_GET_key\n");
967
+ return;
968
+ }
969
+
970
+ char *key = nextToken(cursor);
971
+ if (!key || key[0] == '\0') {
972
+ std::printf("GEADEV:ERR STORAGE usage=GEADEV_STORAGE_SET_key_value|GEADEV_STORAGE_GET_key\n");
973
+ return;
974
+ }
975
+
976
+ if (tokenEquals(action, "GET")) {
977
+ if (storageKeyIsSensitive(key)) {
978
+ std::printf("GEADEV:STORAGE GET ERR key=%s denied=sensitive\n", key);
979
+ return;
980
+ }
981
+ const std::string value = gea::host::Storage.getItem(std::string(key));
982
+ flockfile(stdout);
983
+ std::printf("GEADEV:STORAGE GET BEGIN key=%s bytes=%d encoding=base64\n",
984
+ key, static_cast<int>(value.size()));
985
+ Base64Writer writer;
986
+ for (unsigned char ch : value)
987
+ writer.writeByte(ch);
988
+ writer.finish();
989
+ std::printf("GEADEV:STORAGE GET END key=%s bytes=%d\n", key, static_cast<int>(value.size()));
990
+ std::fflush(stdout);
991
+ funlockfile(stdout);
992
+ return;
993
+ }
994
+
995
+ if (!tokenEquals(action, "SET")) {
996
+ std::printf("GEADEV:ERR STORAGE usage=GEADEV_STORAGE_SET_key_value|GEADEV_STORAGE_GET_key\n");
997
+ return;
998
+ }
999
+
1000
+ char *value = skipSpace(cursor);
1001
+ if (!value || value[0] == '\0') {
1002
+ std::printf("GEADEV:ERR STORAGE usage=GEADEV_STORAGE_SET_key_value\n");
1003
+ return;
1004
+ }
1005
+
1006
+ gea::host::Storage.setItem(std::string(key), std::string(value));
1007
+ std::printf("GEADEV:OK STORAGE key=%s bytes=%d\n", key, static_cast<int>(std::strlen(value)));
1008
+ }
1009
+
1010
+ // Simulate a swipe: touch down at (x,y1), move, up at (x,y2). Lets the host
1011
+ // exercise gestures like the top-edge swipe-down that opens settings.
1012
+ void handleSwipe(char *&cursor)
1013
+ {
1014
+ int x = 0;
1015
+ int y1 = 0;
1016
+ int y2 = 0;
1017
+ if (!parseInt(nextToken(cursor), &x) || !parseInt(nextToken(cursor), &y1) || !parseInt(nextToken(cursor), &y2)) {
1018
+ std::printf("GEADEV:ERR SWIPE usage=GEADEV_SWIPE_x_y1_y2\n");
1019
+ return;
1020
+ }
1021
+ // Same injectEvent path as handleDrag so the Move updates latestMove_ and the
1022
+ // swipe actually drives scroll/gesture handlers (see handleDrag note).
1023
+ using gea::platform::touch::Touchscreen;
1024
+ using gea::platform::touch::Phase;
1025
+ Touchscreen::injectEvent(Phase::Down, true, x, y1);
1026
+ vTaskDelay(pdMS_TO_TICKS(40));
1027
+ Touchscreen::injectEvent(Phase::Move, true, x, (y1 + y2) / 2);
1028
+ vTaskDelay(pdMS_TO_TICKS(40));
1029
+ Touchscreen::injectEvent(Phase::Up, false, x, y2);
1030
+ std::printf("GEADEV:OK SWIPE x=%d y1=%d y2=%d\n", x, y1, y2);
1031
+ }
1032
+
1033
+ // geaos Phase 2 spike probe: map the spare ota_1 flash region onto the
1034
+ // instruction bus at runtime and report the vaddr the MMU assigns + the free
1035
+ // executable vaddr space. Settles whether a dynamically-loaded app can be
1036
+ // fixed-base linked (link vaddr must equal the vaddr esp_mmu_map hands back).
1037
+ // Uses ota_1 so it never touches the protected partitions.csv.
1038
+ void handleMmuProbe()
1039
+ {
1040
+ const esp_partition_t *slot =
1041
+ esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, nullptr);
1042
+ if (!slot) {
1043
+ std::printf("GEADEV:ERR MMUPROBE no-ota_1\n");
1044
+ return;
1045
+ }
1046
+ const mmu_mem_caps_t caps = static_cast<mmu_mem_caps_t>(MMU_MEM_CAP_EXEC | MMU_MEM_CAP_READ);
1047
+ size_t maxBlock = 0;
1048
+ esp_mmu_map_get_max_consecutive_free_block_size(caps, MMU_TARGET_FLASH0, &maxBlock);
1049
+ void *vaddr = nullptr;
1050
+ const esp_err_t err =
1051
+ esp_mmu_map(static_cast<esp_paddr_t>(slot->address), 0x10000, MMU_TARGET_FLASH0, caps, 0, &vaddr);
1052
+ std::printf("GEADEV:MMUPROBE ota1_paddr=0x%08x map=%s vaddr=%p max_free_exec=%u\n",
1053
+ static_cast<unsigned>(slot->address), esp_err_to_name(err), vaddr,
1054
+ static_cast<unsigned>(maxBlock));
1055
+ if (err == ESP_OK && vaddr) {
1056
+ const uint32_t first = *static_cast<volatile uint32_t *>(vaddr);
1057
+ std::printf("GEADEV:MMUPROBE first_word=0x%08x (instruction-bus read ok)\n",
1058
+ static_cast<unsigned>(first));
1059
+ esp_mmu_unmap(vaddr);
1060
+ }
1061
+ // Data-bus (READ-only) mapping: where app .rodata must live so byte reads
1062
+ // work (the EXEC/instruction-bus mapping above faults on byte data access).
1063
+ void *dvaddr = nullptr;
1064
+ const esp_err_t derr = esp_mmu_map(static_cast<esp_paddr_t>(slot->address), 0x10000,
1065
+ MMU_TARGET_FLASH0, MMU_MEM_CAP_READ, 0, &dvaddr);
1066
+ std::printf("GEADEV:MMUPROBE read_only_map=%s dbus_vaddr=%p\n", esp_err_to_name(derr), dvaddr);
1067
+ if (derr == ESP_OK && dvaddr) {
1068
+ const uint8_t b0 = *static_cast<volatile uint8_t *>(dvaddr);
1069
+ std::printf("GEADEV:MMUPROBE dbus_byte0=0x%02x (data-bus byte read ok)\n", static_cast<unsigned>(b0));
1070
+ esp_mmu_unmap(dvaddr);
1071
+ }
1072
+ }
1073
+
1074
+ // Firmware callback the loaded app invokes (passed as a pointer — no symbol
1075
+ // resolution, isolates the execute/callback mechanism).
1076
+ void loadtest_log(const char *msg) { std::printf("GEADEV:LOADTEST app-says: %s\n", msg ? msg : ""); }
1077
+
1078
+ // geaos Phase 2 execute-proof: map the app blob in ota_1 onto the instruction
1079
+ // bus, read its 16-byte header (magic/abi/entry-offset), and CALL the entry
1080
+ // (XIP from flash) passing loadtest_log. Proves map -> jump -> execute ->
1081
+ // callback -> return across the loader boundary. Blob built at
1082
+ // lib/gea-embedded/geaos/spike/ and flashed to ota_1 (0x1010000).
1083
+ void handleLoadTest()
1084
+ {
1085
+ const esp_partition_t *slot =
1086
+ esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, nullptr);
1087
+ if (!slot) {
1088
+ std::printf("GEADEV:ERR LOADTEST no-ota_1\n");
1089
+ return;
1090
+ }
1091
+ // Two views of the one blob: code on the instruction bus (EXEC), data on the
1092
+ // data bus (READ). PADDR_SHARED lets the same flash paddr map to both vaddrs.
1093
+ void *codeVaddr = nullptr;
1094
+ void *dataVaddr = nullptr;
1095
+ // Code page (blob offset 0) -> instruction bus; rodata page (offset 0x10000)
1096
+ // -> data bus. Different paddrs, so each maps once (no PADDR_SHARED).
1097
+ const esp_err_t ce = esp_mmu_map(static_cast<esp_paddr_t>(slot->address), 0x10000, MMU_TARGET_FLASH0,
1098
+ static_cast<mmu_mem_caps_t>(MMU_MEM_CAP_EXEC | MMU_MEM_CAP_READ), 0,
1099
+ &codeVaddr);
1100
+ const esp_err_t de = esp_mmu_map(static_cast<esp_paddr_t>(slot->address) + 0x10000, 0x10000,
1101
+ MMU_TARGET_FLASH0, MMU_MEM_CAP_READ, 0, &dataVaddr);
1102
+ std::printf("GEADEV:LOADTEST code=%p(%s) data=%p(%s)\n", codeVaddr, esp_err_to_name(ce), dataVaddr,
1103
+ esp_err_to_name(de));
1104
+ if (ce != ESP_OK || de != ESP_OK || !codeVaddr || !dataVaddr) {
1105
+ if (codeVaddr) esp_mmu_unmap(codeVaddr);
1106
+ if (dataVaddr) esp_mmu_unmap(dataVaddr);
1107
+ return;
1108
+ }
1109
+ // The app is fixed-base linked to these exact vaddrs (code 0x43060000,
1110
+ // data 0x3d060000); only jump if the runtime mapping matched the link.
1111
+ if (reinterpret_cast<uintptr_t>(codeVaddr) != 0x43060000u ||
1112
+ reinterpret_cast<uintptr_t>(dataVaddr) != 0x3d070000u) {
1113
+ std::printf("GEADEV:LOADTEST vaddr-mismatch (want code=0x43060000 data=0x3d070000); not jumping\n");
1114
+ esp_mmu_unmap(codeVaddr);
1115
+ esp_mmu_unmap(dataVaddr);
1116
+ return;
1117
+ }
1118
+ const uint32_t *hdr = static_cast<const uint32_t *>(codeVaddr); // header in code page (32-bit reads ok on IBUS)
1119
+ std::printf("GEADEV:LOADTEST magic=0x%08x abi=%u entry_off=0x%x\n", static_cast<unsigned>(hdr[0]),
1120
+ static_cast<unsigned>(hdr[1]), static_cast<unsigned>(hdr[2]));
1121
+ if (hdr[0] != 0x47454131u) {
1122
+ std::printf("GEADEV:LOADTEST bad-magic; not jumping\n");
1123
+ esp_mmu_unmap(codeVaddr);
1124
+ esp_mmu_unmap(dataVaddr);
1125
+ return;
1126
+ }
1127
+ using AppEntry = int (*)(void (*)(const char *));
1128
+ const AppEntry entry = reinterpret_cast<AppEntry>(reinterpret_cast<uintptr_t>(codeVaddr) + hdr[2]);
1129
+ std::printf("GEADEV:LOADTEST calling entry @%p ...\n", reinterpret_cast<void *>(entry));
1130
+ const int ret = entry(&loadtest_log);
1131
+ std::printf("GEADEV:LOADTEST entry returned %d (expected 42)\n", ret);
1132
+ esp_mmu_unmap(codeVaddr);
1133
+ esp_mmu_unmap(dataVaddr);
1134
+ }
1135
+
1136
+ // ── GEADEV PUSH: stream a file from the host to the device's microSD ─────────
1137
+ // Raw-binary file upload over the same serial command channel (on the P4 this
1138
+ // IS the USB-Serial-JTAG CDC endpoint, so this is the "CDC bulk" path — no
1139
+ // hex/base64, one byte per byte). The host sends:
1140
+ // GEADEV PUSH <dest-path> <size> [crc32]\n
1141
+ // then exactly <size> raw bytes. The device opens the file, replies
1142
+ // "GEADEV:PUSH READY", drains <size> bytes straight off stdin into the file,
1143
+ // verifies CRC32 (zlib/binascii-compatible), and replies "GEADEV:PUSH OK" or
1144
+ // "GEADEV:PUSH ERR ...". Loads a region's .pmtiles onto /sdcard without
1145
+ // removing the card.
1146
+
1147
+ // Streaming CRC32 (poly 0xEDB88320). `crc` runs un-inverted: init 0xFFFFFFFF,
1148
+ // invert the final result to match zlib/binascii.crc32.
1149
+ std::uint32_t crc32Stream(std::uint32_t crc, const std::uint8_t *data, std::size_t n)
1150
+ {
1151
+ for (std::size_t i = 0; i < n; i++) {
1152
+ crc ^= data[i];
1153
+ for (int b = 0; b < 8; b++) crc = (crc & 1) ? ((crc >> 1) ^ 0xEDB88320u) : (crc >> 1);
1154
+ }
1155
+ return crc;
1156
+ }
1157
+
1158
+ int base64Value(char ch)
1159
+ {
1160
+ if (ch >= 'A' && ch <= 'Z') return ch - 'A';
1161
+ if (ch >= 'a' && ch <= 'z') return ch - 'a' + 26;
1162
+ if (ch >= '0' && ch <= '9') return ch - '0' + 52;
1163
+ if (ch == '+') return 62;
1164
+ if (ch == '/') return 63;
1165
+ return -1;
1166
+ }
1167
+
1168
+ bool decodeBase64Char(char ch, std::uint8_t *out, long size, long &got,
1169
+ int *quartet, int &quartetLen, int &padding)
1170
+ {
1171
+ if (ch == '\r' || ch == '\n' || ch == ' ' || ch == '\t') return true;
1172
+ if (ch == '=') {
1173
+ quartet[quartetLen++] = 0;
1174
+ padding++;
1175
+ } else {
1176
+ const int value = base64Value(ch);
1177
+ if (value < 0 || padding > 0) return false;
1178
+ quartet[quartetLen++] = value;
1179
+ }
1180
+ if (quartetLen < 4) return true;
1181
+
1182
+ const std::uint32_t triple =
1183
+ (static_cast<std::uint32_t>(quartet[0]) << 18) |
1184
+ (static_cast<std::uint32_t>(quartet[1]) << 12) |
1185
+ (static_cast<std::uint32_t>(quartet[2]) << 6) |
1186
+ static_cast<std::uint32_t>(quartet[3]);
1187
+ const int bytes = padding == 0 ? 3 : (padding == 1 ? 2 : 1);
1188
+ for (int i = 0; i < bytes; ++i) {
1189
+ if (got >= size) return false;
1190
+ out[got++] = static_cast<std::uint8_t>((triple >> (16 - i * 8)) & 0xff);
1191
+ }
1192
+ quartetLen = 0;
1193
+ padding = 0;
1194
+ return true;
1195
+ }
1196
+
1197
+ // mkdir -p of the parent directories in `path` (FAT/VFS); existing dirs are fine.
1198
+ void makeParentDirs(const char *path)
1199
+ {
1200
+ char buf[160];
1201
+ std::snprintf(buf, sizeof(buf), "%s", path);
1202
+ for (char *p = buf + 1; *p; p++) {
1203
+ if (*p == '/') {
1204
+ *p = '\0';
1205
+ ::mkdir(buf, 0777);
1206
+ *p = '/';
1207
+ }
1208
+ }
1209
+ }
1210
+
1211
+ void handlePush(char *args)
1212
+ {
1213
+ char *pathTok = nextToken(args);
1214
+ char *sizeTok = nextToken(args);
1215
+ char *crcTok = nextToken(args);
1216
+ if (!pathTok || !sizeTok) {
1217
+ std::printf("GEADEV:PUSH ERR usage=GEADEV_PUSH_path_size_[crc32]\n");
1218
+ return;
1219
+ }
1220
+ char *end = nullptr;
1221
+ const long size = std::strtol(sizeTok, &end, 10);
1222
+ if (!end || *end != '\0' || size < 0) {
1223
+ std::printf("GEADEV:PUSH ERR bad-size\n");
1224
+ return;
1225
+ }
1226
+ std::uint32_t expectCrc = 0;
1227
+ const bool haveCrc = crcTok != nullptr;
1228
+ if (haveCrc) expectCrc = static_cast<std::uint32_t>(std::strtoul(crcTok, nullptr, 0));
1229
+
1230
+ char path[160];
1231
+ std::snprintf(path, sizeof(path), "%s", pathTok);
1232
+ // Mount the microSD (the tile cache does this via writeCacheFile; a raw
1233
+ // fopen alone won't trigger it).
1234
+ if (!gea::platform::storage::ensureMounted()) {
1235
+ std::printf("GEADEV:PUSH ERR no-storage path=%s\n", path);
1236
+ return;
1237
+ }
1238
+ makeParentDirs(path);
1239
+ std::FILE *f = std::fopen(path, "wb");
1240
+ if (!f) {
1241
+ std::printf("GEADEV:PUSH ERR open-failed path=%s errno=%d\n", path, errno);
1242
+ return;
1243
+ }
1244
+ // Read the whole file CONTINUOUSLY into a PSRAM buffer (no per-chunk ACK
1245
+ // round-trips — those stalled — and no SD writes mid-read, so the read never
1246
+ // pauses). The flow-control-less console RX buffer can't overflow because the
1247
+ // HOST throttles its send rate below our drain rate. SD is written once at
1248
+ // the end. (Buffer fits PSRAM for region-sized archives.)
1249
+ std::printf("GEADEV:PUSH READY path=%s bytes=%ld\n", path, size);
1250
+ std::fflush(stdout);
1251
+
1252
+ std::uint8_t *mem = size > 0 ? static_cast<std::uint8_t *>(heap_caps_malloc(static_cast<std::size_t>(size), MALLOC_CAP_SPIRAM)) : nullptr;
1253
+ if (size > 0 && !mem) {
1254
+ std::fclose(f);
1255
+ std::printf("GEADEV:PUSH ERR no-memory bytes=%ld\n", size);
1256
+ return;
1257
+ }
1258
+ long got = 0;
1259
+ int stalls = 0;
1260
+ bool ioError = false;
1261
+ while (got < size) {
1262
+ const std::size_t n = std::fread(mem + got, 1, static_cast<std::size_t>(size - got), stdin);
1263
+ if (n == 0) {
1264
+ if (++stalls > 20000) { // ~40s of silence → abort
1265
+ ioError = true;
1266
+ break;
1267
+ }
1268
+ vTaskDelay(pdMS_TO_TICKS(2));
1269
+ continue;
1270
+ }
1271
+ stalls = 0;
1272
+ got += static_cast<long>(n);
1273
+ }
1274
+ std::uint32_t finalCrc = 0;
1275
+ if (!ioError) {
1276
+ const std::size_t wrote = std::fwrite(mem, 1, static_cast<std::size_t>(size), f);
1277
+ if (wrote != static_cast<std::size_t>(size)) ioError = true;
1278
+ else finalCrc = crc32Stream(0xFFFFFFFFu, mem, static_cast<std::size_t>(size)) ^ 0xFFFFFFFFu;
1279
+ }
1280
+ std::fclose(f);
1281
+ if (mem) heap_caps_free(mem);
1282
+ if (ioError) {
1283
+ std::printf("GEADEV:PUSH ERR transfer-failed path=%s got=%ld\n", path, got);
1284
+ return;
1285
+ }
1286
+ if (haveCrc && finalCrc != expectCrc) {
1287
+ std::printf("GEADEV:PUSH ERR crc-mismatch path=%s got=0x%08x want=0x%08x\n",
1288
+ path, static_cast<unsigned>(finalCrc), static_cast<unsigned>(expectCrc));
1289
+ return;
1290
+ }
1291
+ std::printf("GEADEV:PUSH OK path=%s bytes=%ld crc=0x%08x\n", path, size, static_cast<unsigned>(finalCrc));
1292
+ }
1293
+
1294
+ void handlePushBase64(char *args)
1295
+ {
1296
+ char *pathTok = nextToken(args);
1297
+ char *sizeTok = nextToken(args);
1298
+ char *crcTok = nextToken(args);
1299
+ if (!pathTok || !sizeTok) {
1300
+ std::printf("GEADEV:PUSH64 ERR usage=GEADEV_PUSH64_path_size_[crc32]\n");
1301
+ return;
1302
+ }
1303
+ char *end = nullptr;
1304
+ const long size = std::strtol(sizeTok, &end, 10);
1305
+ if (!end || *end != '\0' || size < 0) {
1306
+ std::printf("GEADEV:PUSH64 ERR bad-size\n");
1307
+ return;
1308
+ }
1309
+ std::uint32_t expectCrc = 0;
1310
+ const bool haveCrc = crcTok != nullptr;
1311
+ if (haveCrc) expectCrc = static_cast<std::uint32_t>(std::strtoul(crcTok, nullptr, 0));
1312
+
1313
+ char path[160];
1314
+ std::snprintf(path, sizeof(path), "%s", pathTok);
1315
+ if (!gea::platform::storage::ensureMounted()) {
1316
+ std::printf("GEADEV:PUSH64 ERR no-storage path=%s\n", path);
1317
+ return;
1318
+ }
1319
+ makeParentDirs(path);
1320
+ std::FILE *f = std::fopen(path, "wb");
1321
+ if (!f) {
1322
+ std::printf("GEADEV:PUSH64 ERR open-failed path=%s errno=%d\n", path, errno);
1323
+ return;
1324
+ }
1325
+
1326
+ std::uint8_t *mem = size > 0 ? static_cast<std::uint8_t *>(heap_caps_malloc(static_cast<std::size_t>(size), MALLOC_CAP_SPIRAM)) : nullptr;
1327
+ if (size > 0 && !mem) {
1328
+ std::fclose(f);
1329
+ std::printf("GEADEV:PUSH64 ERR no-memory bytes=%ld\n", size);
1330
+ return;
1331
+ }
1332
+
1333
+ std::printf("GEADEV:PUSH64 READY path=%s bytes=%ld\n", path, size);
1334
+ std::fflush(stdout);
1335
+
1336
+ long got = 0;
1337
+ bool ioError = false;
1338
+ int quartet[4] = {0, 0, 0, 0};
1339
+ int quartetLen = 0;
1340
+ int padding = 0;
1341
+ char line[600];
1342
+ while (got < size) {
1343
+ while (!std::fgets(line, sizeof(line), stdin)) {
1344
+ if (std::ferror(stdin)) std::clearerr(stdin);
1345
+ vTaskDelay(pdMS_TO_TICKS(2));
1346
+ }
1347
+ for (char *p = line; *p; ++p) {
1348
+ if (!decodeBase64Char(*p, mem, size, got, quartet, quartetLen, padding)) {
1349
+ ioError = true;
1350
+ break;
1351
+ }
1352
+ }
1353
+ if (ioError) break;
1354
+ }
1355
+
1356
+ std::uint32_t finalCrc = 0;
1357
+ if (!ioError && got == size) {
1358
+ std::uint32_t crc = 0xFFFFFFFFu;
1359
+ long writtenTotal = 0;
1360
+ while (writtenTotal < size) {
1361
+ const std::size_t remaining = static_cast<std::size_t>(size - writtenTotal);
1362
+ const std::size_t chunk = remaining > 4096 ? 4096 : remaining;
1363
+ const std::size_t wrote = std::fwrite(mem + writtenTotal, 1, chunk, f);
1364
+ if (wrote != chunk) {
1365
+ ioError = true;
1366
+ break;
1367
+ }
1368
+ crc = crc32Stream(crc, mem + writtenTotal, chunk);
1369
+ writtenTotal += static_cast<long>(chunk);
1370
+ }
1371
+ finalCrc = crc ^ 0xFFFFFFFFu;
1372
+ } else {
1373
+ ioError = true;
1374
+ }
1375
+ std::fclose(f);
1376
+ if (mem) heap_caps_free(mem);
1377
+ if (ioError) {
1378
+ std::printf("GEADEV:PUSH64 ERR transfer-failed path=%s got=%ld errno=%d\n", path, got, errno);
1379
+ return;
1380
+ }
1381
+ if (haveCrc && finalCrc != expectCrc) {
1382
+ std::printf("GEADEV:PUSH64 ERR crc-mismatch path=%s got=0x%08x want=0x%08x\n",
1383
+ path, static_cast<unsigned>(finalCrc), static_cast<unsigned>(expectCrc));
1384
+ return;
1385
+ }
1386
+ std::printf("GEADEV:PUSH64 OK path=%s bytes=%ld crc=0x%08x\n", path, size, static_cast<unsigned>(finalCrc));
1387
+ }
1388
+
1389
+ void handleListFiles(char *args)
1390
+ {
1391
+ const char *pathTok = nextToken(args);
1392
+ const char *path = pathTok && pathTok[0] ? pathTok : "/sdcard";
1393
+ if (!gea::platform::storage::ensureMounted()) {
1394
+ std::printf("GEADEV:LS ERR no-storage path=%s\n", path);
1395
+ return;
1396
+ }
1397
+ DIR *dir = opendir(path);
1398
+ if (!dir) {
1399
+ std::printf("GEADEV:LS ERR open-failed path=%s\n", path);
1400
+ return;
1401
+ }
1402
+ std::printf("GEADEV:LS BEGIN path=%s\n", path);
1403
+ while (true) {
1404
+ struct dirent *entry = readdir(dir);
1405
+ if (!entry) break;
1406
+ if (std::strcmp(entry->d_name, ".") == 0 || std::strcmp(entry->d_name, "..") == 0) continue;
1407
+ std::string fullPath = std::string(path) + "/" + entry->d_name;
1408
+ struct stat st {};
1409
+ const long size = stat(fullPath.c_str(), &st) == 0 ? static_cast<long>(st.st_size) : -1;
1410
+ const char *type = size >= 0 && S_ISDIR(st.st_mode) ? "dir" : "file";
1411
+ std::printf("GEADEV:LS ENTRY name=%s type=%s size=%ld\n", entry->d_name, type, size);
1412
+ }
1413
+ closedir(dir);
1414
+ std::printf("GEADEV:LS END path=%s\n", path);
1415
+ }
1416
+
1417
+ void handleRemoveFile(char *args)
1418
+ {
1419
+ const char *path = nextToken(args);
1420
+ if (!path || path[0] == '\0') {
1421
+ std::printf("GEADEV:RM ERR usage=GEADEV_RM_path\n");
1422
+ return;
1423
+ }
1424
+ if (!gea::platform::storage::ensureMounted()) {
1425
+ std::printf("GEADEV:RM ERR no-storage path=%s\n", path);
1426
+ return;
1427
+ }
1428
+ const int rc = std::remove(path);
1429
+ if (rc != 0) {
1430
+ std::printf("GEADEV:RM ERR remove-failed path=%s errno=%d\n", path, errno);
1431
+ return;
1432
+ }
1433
+ std::printf("GEADEV:RM OK path=%s\n", path);
1434
+ }
1435
+
1436
+ void handlePull(char *args)
1437
+ {
1438
+ const char *path = nextToken(args);
1439
+ if (!path || path[0] == '\0') {
1440
+ std::printf("GEADEV:PULL ERR usage=GEADEV_PULL_path\n");
1441
+ return;
1442
+ }
1443
+ if (!gea::platform::storage::ensureMounted()) {
1444
+ std::printf("GEADEV:PULL ERR no-storage path=%s\n", path);
1445
+ return;
1446
+ }
1447
+ std::FILE *f = std::fopen(path, "rb");
1448
+ if (!f) {
1449
+ std::printf("GEADEV:PULL ERR open-failed path=%s\n", path);
1450
+ return;
1451
+ }
1452
+ std::fseek(f, 0, SEEK_END);
1453
+ const long size = std::ftell(f);
1454
+ std::fseek(f, 0, SEEK_SET);
1455
+ flockfile(stdout);
1456
+ std::printf("GEADEV:PULL BEGIN path=%s bytes=%ld encoding=base64\n", path, size);
1457
+ Base64Writer writer;
1458
+ std::uint32_t crc = 0xFFFFFFFFu;
1459
+ std::uint8_t buffer[384];
1460
+ long total = 0;
1461
+ while (true) {
1462
+ const std::size_t got = std::fread(buffer, 1, sizeof(buffer), f);
1463
+ if (got == 0) break;
1464
+ crc = crc32Stream(crc, buffer, got);
1465
+ for (std::size_t i = 0; i < got; i++) writer.writeByte(buffer[i]);
1466
+ total += static_cast<long>(got);
1467
+ }
1468
+ writer.finish();
1469
+ std::fclose(f);
1470
+ const std::uint32_t finalCrc = crc ^ 0xFFFFFFFFu;
1471
+ std::printf("GEADEV:PULL END path=%s bytes=%ld crc=0x%08x\n", path, total, static_cast<unsigned>(finalCrc));
1472
+ std::fflush(stdout);
1473
+ funlockfile(stdout);
1474
+ }
1475
+
1476
+ void handlePlayFile(char *args)
1477
+ {
1478
+ const char *path = nextToken(args);
1479
+ if (!path || path[0] == '\0') {
1480
+ std::printf("GEADEV:PLAYFILE ERR usage=GEADEV_PLAYFILE_path\n");
1481
+ return;
1482
+ }
1483
+ const bool ok = gea::platform::audio::AudioSystem::playFile(std::string(path));
1484
+ std::printf("GEADEV:PLAYFILE %s path=%s\n", ok ? "OK" : "ERR", path);
1485
+ }
1486
+
1487
+ // Optional per-target GEADEV command extension. The weak default (defined at the
1488
+ // end of this file, outside the namespace) returns false; a target that wants
1489
+ // extra commands — e.g. the ESP32-P4 camera capture (CAMSTILL / CAMCLIP) in
1490
+ // targets/esp32-p4-waveshare-touch-lcd-7/main/camera.cpp — provides a strong
1491
+ // override. Receives the command token plus the remaining argument cursor.
1492
+ extern "C" bool geaHandleExtraDevCommand(const char *command, char *args);
1493
+
1494
+ void handleCommand(char *line, CommandSource source)
1495
+ {
1496
+ char *cursor = line;
1497
+ char *prefix = nextToken(cursor);
1498
+ if (!prefix || !tokenEquals(prefix, "GEADEV")) return;
1499
+
1500
+ char *command = nextToken(cursor);
1501
+ if (!command) {
1502
+ std::printf("GEADEV:ERR missing-command\n");
1503
+ return;
1504
+ }
1505
+
1506
+ if (tokenEquals(command, "PING")) {
1507
+ // `gea boards discover` identifies a plugged-in unit from this one
1508
+ // line: the app it runs, the address it holds (0.0.0.0 without WiFi)
1509
+ // and the station MAC, which is also the USB serial an ESP32 board
1510
+ // enumerates with -- so the reply confirms which alias the port is.
1511
+ const char *appId = gea::framework::apps::AppManager::currentId();
1512
+ const std::string ip = gea::framework::network::wifi().ip();
1513
+ const std::string mac = gea::framework::network::wifi().mac();
1514
+ std::printf("GEADEV:PONG app=%s ip=%s mac=%s\n", appId ? appId : "", ip.c_str(), mac.c_str());
1515
+ } else if (tokenEquals(command, "APP")) {
1516
+ const char *appId = gea::framework::apps::AppManager::currentId();
1517
+ std::printf("GEADEV:APP id=%s\n", appId ? appId : "");
1518
+ } else if (tokenEquals(command, "MEM")) {
1519
+ const unsigned intFree = static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1520
+ const unsigned intTotal = static_cast<unsigned>(heap_caps_get_total_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1521
+ const unsigned intLargest = static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1522
+ const unsigned intMinFree = static_cast<unsigned>(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
1523
+ const unsigned psramFree = static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1524
+ const unsigned psramTotal = static_cast<unsigned>(heap_caps_get_total_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1525
+ const unsigned psramLargest = static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1526
+ const char *appId = gea::framework::apps::AppManager::currentId();
1527
+ std::printf(
1528
+ "GEADEV:MEM app=%s internal_used=%u internal_free=%u internal_total=%u internal_largest=%u internal_min_free=%u psram_used=%u psram_free=%u psram_total=%u psram_largest=%u\n",
1529
+ appId ? appId : "",
1530
+ intTotal - intFree, intFree, intTotal, intLargest, intMinFree,
1531
+ psramTotal - psramFree, psramFree, psramTotal, psramLargest);
1532
+ } else if (tokenEquals(command, "CANVASSTATS")) {
1533
+ int tBegin = 0, tEnd = 0, tFillRect = 0, tDrawImage = 0, tNullPx = 0, tPresentOk = 0;
1534
+ gea::embedded::ui::canvasTotalsRead(&tBegin, &tEnd, &tFillRect, &tDrawImage, &tNullPx, &tPresentOk);
1535
+ std::printf("GEADEV:CANVASSTATS begin=%d end=%d fillRect=%d drawImage=%d nullPixels=%d presentOk=%d\n",
1536
+ tBegin, tEnd, tFillRect, tDrawImage, tNullPx, tPresentOk);
1537
+ } else if (tokenEquals(command, "LANDFRAME")) {
1538
+ using gea::platform::display::Display;
1539
+ int total = 0, align = 0, raster = 0, text = 0, flip = 0;
1540
+ Display::landFrameDebug(&total, &align, &raster, &text, &flip);
1541
+ std::printf("GEADEV:LANDFRAME totalUs=%d alignUs=%d rasterUs=%d textUs=%d flipUs=%d\n", total, align, raster, text, flip);
1542
+ } else if (tokenEquals(command, "KBINFO")) {
1543
+ auto &tree = gea::embedded::ui::Tree::instance();
1544
+ const int kb = gea::embedded::ui::VirtualKeyboard::instance().debugRootNode();
1545
+ const int active = tree.activeInputId();
1546
+ if (kb >= 0 && kb < tree.nodeCount()) {
1547
+ const auto &node = tree.node(kb);
1548
+ std::printf("GEADEV:KBINFO kb=%d active=%d parent=%d display=%d layout=%d,%d %dx%d styleTop=%d styleW=%d styleH=%d\n",
1549
+ kb, active, node.parent, node.style.display, node.layout.x, node.layout.y,
1550
+ node.layout.width, node.layout.height, node.style.pos_offsets[0], node.style.width, node.style.height);
1551
+ } else {
1552
+ std::printf("GEADEV:KBINFO kb=%d active=%d\n", kb, active);
1553
+ }
1554
+ } else if (tokenEquals(command, "LANDPAN")) {
1555
+ using gea::platform::display::Display;
1556
+ int detect = 0, kick = 0, strips = 0, wait = 0, interior = 0;
1557
+ Display::landPanDebug(&detect, &kick, &strips, &wait, &interior);
1558
+ std::printf("GEADEV:LANDPAN detectUs=%d kickUs=%d stripUs=%d waitUs=%d interiorUs=%d\n", detect, kick, strips, wait, interior);
1559
+ } else if (tokenEquals(command, "FLUSHSTATS")) {
1560
+ using gea::platform::display::Display;
1561
+ const auto stats = Display::flushPerfStatsRead();
1562
+ int dbReason = 0, dbExtra = 0, dbCount = 0;
1563
+ gea::embedded::ui::Tree::instance().displayBackedFailDebug(&dbReason, &dbExtra, &dbCount);
1564
+ int ppCalls = 0, ppDirect = 0, ppGeneral = 0, ppRejected = 0, tsKind = 0, tsType = 0, tsCount = 0;
1565
+ Display::presentPathDebug(&ppCalls, &ppDirect, &ppGeneral, &ppRejected, &tsKind, &tsType, &tsCount);
1566
+ int slotMode = -1, slotRebinds = 0;
1567
+ gea::embedded::ui::Tree::instance().canvasSlotDebug(0, &slotMode, &slotRebinds);
1568
+ std::printf("GEADEV:FLUSHSTATS calls=%d chunks=%d pixels=%d totalUs=%lld rasterUs=%lld copyUs=%lld txUs=%lld slotWaitUs=%lld completeWaitUs=%lld dbReason=%d dbExtra=%d dbCount=%d ppCalls=%d ppDirect=%d ppGeneral=%d ppRejected=%d tsKind=%d tsType=%d tsCount=%d slotMode=%d rebinds=%d\n",
1569
+ stats.callCount, stats.chunkCount, stats.pixelCount,
1570
+ static_cast<long long>(stats.totalUs), static_cast<long long>(stats.rasterUs),
1571
+ static_cast<long long>(stats.copyUs), static_cast<long long>(stats.txUs),
1572
+ static_cast<long long>(stats.slotWaitUs), static_cast<long long>(stats.completeWaitUs),
1573
+ dbReason, dbExtra, dbCount, ppCalls, ppDirect, ppGeneral, ppRejected, tsKind, tsType, tsCount, slotMode, slotRebinds);
1574
+ } else if (tokenEquals(command, "STATE")) {
1575
+ using gea::platform::display::Display;
1576
+
1577
+ gea::framework::services::AppState::lock();
1578
+ const char *appId = gea::framework::apps::AppManager::currentId();
1579
+ char appIdBuffer[96];
1580
+ std::snprintf(appIdBuffer, sizeof(appIdBuffer), "%s", appId ? appId : "");
1581
+ auto &tree = gea::embedded::ui::Tree::instance();
1582
+ const int nodes = tree.nodeCount();
1583
+ const int root = tree.mountedRoot();
1584
+ const int width = tree.mountedWidth();
1585
+ const int height = tree.mountedHeight();
1586
+ const int refresh = tree.refreshRequired() ? 1 : 0;
1587
+ // Reachability census: `nodes` is the slot high-water mark, so a climbing
1588
+ // count alone cannot say whether the surplus is still hanging in the tree
1589
+ // (a rebuild that appends without removing) or detached-but-unfreed (a
1590
+ // remove that never ran). Walking from the mounted root separates them.
1591
+ int reachable = 0;
1592
+ int rootless = 0;
1593
+ {
1594
+ const auto *nodeArray = tree.nodes();
1595
+ int stack[256];
1596
+ int top = 0;
1597
+ if (root >= 0 && root < nodes) stack[top++] = root;
1598
+ int guard = 0;
1599
+ while (top > 0 && guard++ < nodes * 4) {
1600
+ const int id = stack[--top];
1601
+ reachable++;
1602
+ for (int c = nodeArray[id].first_child; c >= 0 && c < nodes; c = nodeArray[c].next_sibling) {
1603
+ if (top < 256) stack[top++] = c;
1604
+ }
1605
+ }
1606
+ for (int i = 0; i < nodes; i++)
1607
+ if (i != root && nodeArray[i].parent < 0) rootless++;
1608
+ }
1609
+ const int drawNonBlack = Display::countNonBlackPixels(false);
1610
+ const int presentedNonBlack = Display::countNonBlackPixels(true);
1611
+ gea::framework::services::AppState::unlock();
1612
+ const int battery = gea::platform::power::Power::batteryPercent();
1613
+ std::printf("GEADEV:STATE app=%s nodes=%d reachable=%d rootless=%d root=%d width=%d height=%d refresh=%d draw_nonblack=%d presented_nonblack=%d battery=%d\n",
1614
+ appIdBuffer,
1615
+ nodes,
1616
+ reachable,
1617
+ rootless,
1618
+ root,
1619
+ width,
1620
+ height,
1621
+ refresh,
1622
+ drawNonBlack,
1623
+ presentedNonBlack,
1624
+ battery);
1625
+ } else if (tokenEquals(command, "TAP")) {
1626
+ handleTap(cursor);
1627
+ } else if (tokenEquals(command, "DRAG")) {
1628
+ handleDrag(cursor);
1629
+ } else if (tokenEquals(command, "ROTARY")) {
1630
+ handleRotary(cursor);
1631
+ } else if (tokenEquals(command, "KEY")) {
1632
+ handleKey(cursor);
1633
+ } else if (tokenEquals(command, "STORAGE")) {
1634
+ handleStorage(cursor);
1635
+ } else if (tokenEquals(command, "SWIPE")) {
1636
+ handleSwipe(cursor);
1637
+ } else if (tokenEquals(command, "BRIGHTNESS")) {
1638
+ handleBrightness(cursor);
1639
+ } else if (tokenEquals(command, "HBM")) {
1640
+ handleHbm(cursor);
1641
+ } else if (tokenEquals(command, "VSYNC")) {
1642
+ handleVsync(cursor);
1643
+ } else if (tokenEquals(command, "I2CSCAN")) {
1644
+ handleI2cScan();
1645
+ } else if (tokenEquals(command, "NODE")) {
1646
+ handleNode(cursor);
1647
+ } else if (tokenEquals(command, "HITTEST")) {
1648
+ handleHitTest(cursor);
1649
+ } else if (tokenEquals(command, "REBOOT")) {
1650
+ // Soft-reboot the device. Lets the Mac companion apply a face change
1651
+ // (SETDEFAULT writes NVS; the new default only takes effect on boot).
1652
+ std::printf("GEADEV:OK REBOOT\n");
1653
+ std::fflush(stdout);
1654
+ vTaskDelay(pdMS_TO_TICKS(120)); // let the serial response flush before reset
1655
+ esp_restart();
1656
+ } else if (tokenEquals(command, "NOTIFY")) {
1657
+ // The rest of the line is the notification text; push it to the Notify
1658
+ // channel that watch faces read to show a transient banner.
1659
+ while (*cursor == ' ') cursor++;
1660
+ gea::host::postNotification(std::string(cursor));
1661
+ std::printf("GEADEV:OK NOTIFY len=%d\n", static_cast<int>(std::strlen(cursor)));
1662
+ } else if (tokenEquals(command, "PUSH")) {
1663
+ if (source == CommandSource::Stdio) handlePush(cursor);
1664
+ else std::printf("GEADEV:PUSH ERR unsupported-on-usb-direct\n");
1665
+ } else if (tokenEquals(command, "PUSH64")) {
1666
+ if (source == CommandSource::Stdio) handlePushBase64(cursor);
1667
+ else std::printf("GEADEV:PUSH64 ERR unsupported-on-usb-direct\n");
1668
+ } else if (tokenEquals(command, "LS")) {
1669
+ handleListFiles(cursor);
1670
+ } else if (tokenEquals(command, "RM")) {
1671
+ handleRemoveFile(cursor);
1672
+ } else if (tokenEquals(command, "PULL")) {
1673
+ handlePull(cursor);
1674
+ } else if (tokenEquals(command, "PLAYFILE")) {
1675
+ handlePlayFile(cursor);
1676
+ } else if (tokenEquals(command, "BACK")) {
1677
+ const bool ok = gea::framework::apps::AppManager::returnRunningAppToLauncher("device control");
1678
+ std::printf("GEADEV:OK BACK returned=%d\n", ok ? 1 : 0);
1679
+ } else if (tokenEquals(command, "WIFI")) {
1680
+ // Dev/test: WiFi is opt-in (off at boot); bring it up or down on demand.
1681
+ const char *arg = nextToken(cursor);
1682
+ const bool on = !arg || tokenEquals(arg, "ON") || tokenEquals(arg, "1");
1683
+ gea::framework::network::WifiBackend::setEnabled(on);
1684
+ std::printf("GEADEV:OK WIFI %s connected=%d\n", on ? "on" : "off",
1685
+ gea::framework::network::WifiBackend::connected() ? 1 : 0);
1686
+ } else if (tokenEquals(command, "SETDEFAULT")) {
1687
+ // Set the boot default app (NVS 'default_app'), read by Runtime::run at
1688
+ // boot. Lets the Mac companion choose which app the watch boots into.
1689
+ const char *appId = nextToken(cursor);
1690
+ if (!appId || appId[0] == '\0')
1691
+ std::printf("GEADEV:ERR SETDEFAULT usage=GEADEV_SETDEFAULT_appid\n");
1692
+ else if (gea::framework::services::StorageService::setString("default_app", appId))
1693
+ std::printf("GEADEV:OK SETDEFAULT default_app=%s\n", appId);
1694
+ else
1695
+ std::printf("GEADEV:ERR SETDEFAULT nvs-write-failed\n");
1696
+ } else if (tokenEquals(command, "SETTIME")) {
1697
+ handleSetTime(cursor);
1698
+ } else if (tokenEquals(command, "SCREENSHOT")) {
1699
+ writeScreenshot();
1700
+ #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
1701
+ } else if (tokenEquals(command, "SCREENSHOTBIN")) {
1702
+ if (source == CommandSource::UsbSerialJtag) writeScreenshotUsbRaw();
1703
+ else std::printf("GEADEV:ERR SCREENSHOTBIN usb-serial-jtag-only\n");
1704
+ #endif
1705
+ } else if (tokenEquals(command, "MMUPROBE")) {
1706
+ handleMmuProbe();
1707
+ } else if (tokenEquals(command, "LOADTEST")) {
1708
+ handleLoadTest();
1709
+ } else if (geaHandleExtraDevCommand(command, cursor)) {
1710
+ // Handled by a target-specific extension (e.g. ESP32-P4 camera capture).
1711
+ } else {
1712
+ std::printf("GEADEV:ERR unknown-command command=%s\n", command);
1713
+ }
1714
+ std::fflush(stdout);
1715
+ }
1716
+
1717
+ void dispatchLineTooLong()
1718
+ {
1719
+ if (gCommandMutex) xSemaphoreTake(gCommandMutex, portMAX_DELAY);
1720
+ std::printf("GEADEV:ERR line-too-long max=%d\n", 511);
1721
+ std::fflush(stdout);
1722
+ if (gCommandMutex) xSemaphoreGive(gCommandMutex);
1723
+ }
1724
+
1725
+ void dispatchCommand(char *line, CommandSource source)
1726
+ {
1727
+ if (gCommandMutex) xSemaphoreTake(gCommandMutex, portMAX_DELAY);
1728
+ handleCommand(line, source);
1729
+ if (gCommandMutex) xSemaphoreGive(gCommandMutex);
1730
+ }
1731
+
1732
+ class CommandLineAccumulator {
1733
+ public:
1734
+ explicit CommandLineAccumulator(CommandSource source) : source_(source) {}
1735
+
1736
+ void feed(const char *data, std::size_t length)
1737
+ {
1738
+ for (std::size_t i = 0; i < length; ++i) feed(data[i]);
1739
+ }
1740
+
1741
+ private:
1742
+ void feed(char ch)
1743
+ {
1744
+ if (ch == '\n' || ch == '\r') {
1745
+ if (overflow_) {
1746
+ dispatchLineTooLong();
1747
+ } else if (length_ > 0) {
1748
+ buffer_[length_] = '\0';
1749
+ dispatchCommand(buffer_, source_);
1750
+ }
1751
+ length_ = 0;
1752
+ overflow_ = false;
1753
+ return;
1754
+ }
1755
+ if (length_ + 1 >= sizeof(buffer_)) {
1756
+ overflow_ = true;
1757
+ } else if (!overflow_) {
1758
+ buffer_[length_++] = ch;
1759
+ }
1760
+ }
1761
+
1762
+ CommandSource source_;
1763
+ char buffer_[512]{};
1764
+ std::size_t length_ = 0;
1765
+ bool overflow_ = false;
1766
+ };
1767
+
1768
+ #if !CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
1769
+ class DeviceControlTask {
1770
+ public:
1771
+ static void run(void *)
1772
+ {
1773
+ std::setvbuf(stdin, nullptr, _IONBF, 0);
1774
+ std::setvbuf(stdout, nullptr, _IONBF, 0);
1775
+ ESP_LOGI(kTag, "Device control ready: send 'GEADEV PING', 'GEADEV TAP x y', 'GEADEV BACK', or 'GEADEV SCREENSHOT'");
1776
+
1777
+ char readBuffer[160];
1778
+ CommandLineAccumulator parser(CommandSource::Stdio);
1779
+ while (true) {
1780
+ if (!std::fgets(readBuffer, sizeof(readBuffer), stdin)) {
1781
+ vTaskDelay(pdMS_TO_TICKS(50));
1782
+ continue;
1783
+ }
1784
+ parser.feed(readBuffer, std::strlen(readBuffer));
1785
+ }
1786
+ }
1787
+ };
1788
+ #endif
1789
+
1790
+ #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
1791
+ class UsbSerialJtagControlTask {
1792
+ public:
1793
+ static void run(void *)
1794
+ {
1795
+ usb_serial_jtag_driver_config_t config = {
1796
+ .tx_buffer_size = 4096,
1797
+ .rx_buffer_size = 1024,
1798
+ };
1799
+ if (!usb_serial_jtag_is_driver_installed()) {
1800
+ const esp_err_t err = usb_serial_jtag_driver_install(&config);
1801
+ if (err != ESP_OK) {
1802
+ ESP_LOGE(kTag, "Failed to install USB Serial/JTAG driver: %s", esp_err_to_name(err));
1803
+ vTaskDelete(nullptr);
1804
+ return;
1805
+ }
1806
+ }
1807
+ usb_serial_jtag_vfs_use_driver();
1808
+ ESP_LOGI(kTag, "USB Serial/JTAG device control ready: send 'GEADEV PING' or 'GEADEV SCREENSHOTBIN'");
1809
+
1810
+ CommandLineAccumulator parser(CommandSource::UsbSerialJtag);
1811
+ char readBuffer[128];
1812
+ while (true) {
1813
+ const int n = usb_serial_jtag_read_bytes(readBuffer, sizeof(readBuffer), pdMS_TO_TICKS(50));
1814
+ if (n > 0) parser.feed(readBuffer, static_cast<std::size_t>(n));
1815
+ }
1816
+ }
1817
+ };
1818
+ #endif
1819
+
1820
+ bool gStarted = false;
1821
+
1822
+ } // namespace
1823
+
1824
+ // Public capture entry point. The anonymous-namespace helper above stays the
1825
+ // single implementation; this only lifts it out for the WiFi screenshot path.
1826
+ bool captureScreenshotRgb565(std::uint16_t *snapshot, int pixelCapacity, int *width, int *height,
1827
+ char *appIdBuffer, std::size_t appIdBufferSize)
1828
+ {
1829
+ return captureSnapshotRgb565(snapshot, pixelCapacity, width, height, appIdBuffer, appIdBufferSize);
1830
+ }
1831
+
1832
+ #if GEA_PIXEL_STORAGE_PACKED
1833
+ bool captureScreenshotPacked(std::uint8_t *snapshot, int byteCapacity, int *width, int *height,
1834
+ char *appIdBuffer, std::size_t appIdBufferSize)
1835
+ {
1836
+ return captureSnapshotPacked(snapshot, byteCapacity, width, height, appIdBuffer, appIdBufferSize);
1837
+ }
1838
+ #endif
1839
+
1840
+ void startDeviceControlTask()
1841
+ {
1842
+ #if !GEA_EMBEDDED_DEVICE_CONTROL
1843
+ ESP_LOGI(kTag, "device control disabled by the app (GEA_EMBEDDED_DEVICE_CONTROL=0)");
1844
+ #else
1845
+ if (gStarted) return;
1846
+ gStarted = true;
1847
+ if (!gCommandMutex) {
1848
+ gCommandMutex = xSemaphoreCreateMutex();
1849
+ if (!gCommandMutex) {
1850
+ gStarted = false;
1851
+ ESP_LOGE(kTag, "Failed to create device control mutex");
1852
+ return;
1853
+ }
1854
+ }
1855
+ #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
1856
+ TaskHandle_t usbTask = nullptr;
1857
+ const BaseType_t usbCreated = xTaskCreateWithCaps(&UsbSerialJtagControlTask::run,
1858
+ "gea_devctl_usb",
1859
+ kUsbJtagTaskStackBytes,
1860
+ nullptr,
1861
+ kTaskPriority,
1862
+ &usbTask,
1863
+ MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
1864
+ if (usbCreated != pdPASS) {
1865
+ gStarted = false;
1866
+ ESP_LOGE(kTag, "Failed to start USB Serial/JTAG device control task");
1867
+ }
1868
+ #else
1869
+ TaskHandle_t task = nullptr;
1870
+ const BaseType_t created = xTaskCreateWithCaps(&DeviceControlTask::run,
1871
+ "gea_devctl",
1872
+ kTaskStackBytes,
1873
+ nullptr,
1874
+ kTaskPriority,
1875
+ &task,
1876
+ MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
1877
+ if (created != pdPASS) {
1878
+ gStarted = false;
1879
+ ESP_LOGE(kTag, "Failed to start device control task");
1880
+ }
1881
+ #endif
1882
+ #endif // GEA_EMBEDDED_DEVICE_CONTROL
1883
+ }
1884
+
1885
+ } // namespace gea::platform::esp32::services
1886
+
1887
+ // Weak no-op default for the per-target GEADEV command extension. Targets that
1888
+ // add commands (e.g. ESP32-P4 camera capture) override this with a strong symbol;
1889
+ // the linker then picks the override. Defined at global scope to match the
1890
+ // `extern "C"` declaration used at the call site.
1891
+ extern "C" __attribute__((weak)) bool geaHandleExtraDevCommand(const char *command, char *args)
1892
+ {
1893
+ (void)command;
1894
+ (void)args;
1895
+ return false;
1896
+ }