@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,840 @@
1
+ #include "services/ota.h"
2
+
3
+ #include "services/ota_image.h"
4
+
5
+ #include "display.h" // display geometry for /screenshot, elastic RAM for staging
6
+ #include "services/device_control.h"
7
+
8
+ #include <cstring>
9
+ #include <cstdlib>
10
+ #include <cstdint>
11
+ #include <strings.h>
12
+ #include <atomic>
13
+
14
+ #include "esp_app_format.h"
15
+ #include "esp_flash.h"
16
+ #include "esp_private/esp_clk.h"
17
+ #include "esp_memory_utils.h"
18
+ #include "esp_http_server.h"
19
+ #include "esp_log.h"
20
+ #include "esp_ota_ops.h"
21
+ #include "esp_partition.h"
22
+ #include "esp_system.h"
23
+ #include "esp_timer.h"
24
+ #include "esp_heap_caps.h"
25
+ #include "freertos/FreeRTOS.h"
26
+ #include "freertos/task.h"
27
+ #include "freertos/timers.h"
28
+
29
+ namespace gea::framework::services {
30
+
31
+ namespace {
32
+
33
+ constexpr const char *kTag = "gea_esp32_ota";
34
+ constexpr int kServerPort = 8080;
35
+ // The handler streams through a 1 KiB stack buffer. A 3 KiB server task corrupted
36
+ // its FreeRTOS frame as esp_ota_begin entered the flash path on real hardware,
37
+ // resetting the connection after the client's first 128 KiB socket window. Four
38
+ // KiB is the smallest allocation that leaves room for that call chain beside
39
+ // the USB device-control task and both radio stacks.
40
+ //
41
+ // 8 KiB, not 4, since /screenshot landed here: capturing a frame replays the
42
+ // retained UI tree (renderRetainedSnapshotRgb565), whose stack cost scales with
43
+ // tree depth. The serial device-control task sizes itself at 8 KiB for exactly
44
+ // that call, and this task now makes the same one. The extra 4 KiB of internal
45
+ // DRAM is affordable only because the IPC task stacks gave back ~24 KiB.
46
+ constexpr int kServerStackSize = 8192;
47
+
48
+ // ESP-IDF only arms flash auto-suspend for an explicit allow-list of JEDEC ids
49
+ // (spi_flash_chip_gd.c / _winbond.c / _generic.c). Enabling the feature on a
50
+ // part that is NOT on that list is FATAL at boot: esp_flash_suspend_cmd_init
51
+ // returns ESP_ERR_NOT_SUPPORTED and esp_flash_init_default_chip propagates it.
52
+ // Report the id so the config can be decided from the hardware, not a guess.
53
+ constexpr std::uint32_t kSuspendQualifiedIds[] = {
54
+ 0xC84016, 0xC84017, 0xC84018, 0xC84319, // GigaDevice (spi_flash_chip_gd.c)
55
+ };
56
+
57
+ bool flashSuspendQualified(std::uint32_t chipId)
58
+ {
59
+ for (const std::uint32_t id : kSuspendQualifiedIds)
60
+ if (id == chipId) return true;
61
+ return false;
62
+ }
63
+
64
+ // The image session and the reboot timer moved to ota_image.cpp: staging an
65
+ // image is transport-agnostic and a BLE-only build has to link it without this
66
+ // HTTP server. The start diagnostics moved with them so ble_hid.cpp can report
67
+ // them in a build where no server exists; this file is their only writer.
68
+ using gea::targets::esp32::ota_debug::httpStartError;
69
+ using gea::targets::esp32::ota_debug::httpStarted;
70
+
71
+ class OtaHttpServer {
72
+ public:
73
+ static OtaHttpServer &instance()
74
+ {
75
+ static OtaHttpServer server;
76
+ return server;
77
+ }
78
+
79
+ bool start()
80
+ {
81
+ if (server_) return true;
82
+
83
+ httpd_config_t config = HTTPD_DEFAULT_CONFIG();
84
+ config.server_port = kServerPort;
85
+ config.stack_size = kServerStackSize;
86
+ // IDF's default cap is 8 and this server already registers 8 routes;
87
+ // httpd_register_uri_handler fails silently past the cap, so every
88
+ // route added later would 404 with nothing in the log to say why.
89
+ config.max_uri_handlers = 16;
90
+
91
+ const esp_err_t startError = httpd_start(&server_, &config);
92
+ httpStartError.store(static_cast<int>(startError), std::memory_order_relaxed);
93
+ if (startError != ESP_OK) {
94
+ ESP_LOGE(kTag, "Failed to start OTA HTTP server: %s", esp_err_to_name(startError));
95
+ server_ = nullptr;
96
+ return false;
97
+ }
98
+ httpStarted.store(true, std::memory_order_relaxed);
99
+
100
+ registerHandlers();
101
+ ESP_LOGI(kTag, "OTA server listening on port %d", config.server_port);
102
+ return true;
103
+ }
104
+
105
+ private:
106
+ OtaHttpServer() = default;
107
+
108
+ static bool queryBool(const char *query, const char *key, bool fallback)
109
+ {
110
+ char value[12];
111
+ if (!query || httpd_query_key_value(query, key, value, sizeof(value)) != ESP_OK) return fallback;
112
+ return std::strcmp(value, "1") == 0
113
+ || strcasecmp(value, "true") == 0
114
+ || strcasecmp(value, "yes") == 0
115
+ || strcasecmp(value, "on") == 0;
116
+ }
117
+
118
+ static const esp_partition_t *findSlot(const char *slot)
119
+ {
120
+ if (!slot || slot[0] == '\0') return nullptr;
121
+ return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, slot);
122
+ }
123
+
124
+ static esp_err_t postHandler(httpd_req_t *req)
125
+ {
126
+ return instance().handlePost(req);
127
+ }
128
+
129
+ static esp_err_t statusHandler(httpd_req_t *req)
130
+ {
131
+ return instance().handleStatus(req);
132
+ }
133
+
134
+ static esp_err_t eraseHandler(httpd_req_t *req)
135
+ {
136
+ return instance().handleErase(req);
137
+ }
138
+
139
+ esp_err_t handlePost(httpd_req_t *req)
140
+ {
141
+ char query[128] = {};
142
+ char slot[17] = {};
143
+ const bool hasQuery = httpd_req_get_url_query_str(req, query, sizeof(query)) == ESP_OK;
144
+ const bool hasSlot = hasQuery && httpd_query_key_value(query, "slot", slot, sizeof(slot)) == ESP_OK;
145
+ const bool setBoot = queryBool(hasQuery ? query : nullptr, "boot", !hasSlot);
146
+ const bool rebootAfter = queryBool(hasQuery ? query : nullptr, "reboot", !hasSlot);
147
+
148
+ const esp_partition_t *updatePartition = hasSlot ? findSlot(slot) : esp_ota_get_next_update_partition(nullptr);
149
+ if (!updatePartition) {
150
+ httpd_resp_send_err(req, hasSlot ? HTTPD_404_NOT_FOUND : HTTPD_500_INTERNAL_SERVER_ERROR, hasSlot ? "OTA slot not found" : "No OTA partition found");
151
+ return ESP_FAIL;
152
+ }
153
+
154
+ if (req->content_len > updatePartition->size) {
155
+ httpd_resp_send_err(req, HTTPD_413_CONTENT_TOO_LARGE, "Image does not fit OTA slot");
156
+ return ESP_FAIL;
157
+ }
158
+
159
+ const esp_partition_t *running = esp_ota_get_running_partition();
160
+ if (running && running->address == updatePartition->address) {
161
+ httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Cannot write the running partition over OTA");
162
+ return ESP_FAIL;
163
+ }
164
+
165
+ ESP_LOGI(kTag, "OTA update started for %s (%d bytes)", updatePartition->label, req->content_len);
166
+
167
+ // Erase the whole destination range ONCE, up front, instead of letting
168
+ // esp_ota_write erase lazily under OTA_WITH_SEQUENTIAL_WRITES. Two things
169
+ // were wrong with the lazy mode. It erases a 4 KiB SECTOR at a time (~45 ms
170
+ // each on this part) — 938 of them for a 3.8 MB image, ~42 s of pure erase,
171
+ // where esp_partition_erase_range over the same range issues 64 KiB BLOCK
172
+ // erases (~3x less time per byte). And every one of those erases happened
173
+ // INSIDE the receive loop with the flash cache disabled, so the socket was
174
+ // not drained and lwIP's small receive window emptied and refilled around
175
+ // each stall. Passing the real content length moves the erase out of the
176
+ // transfer entirely; the client simply blocks on a full window while it runs.
177
+ const std::size_t eraseLength = req->content_len > 0
178
+ ? static_cast<std::size_t>(req->content_len)
179
+ : static_cast<std::size_t>(OTA_WITH_SEQUENTIAL_WRITES);
180
+ const int64_t eraseStartUs = esp_timer_get_time();
181
+ esp_ota_handle_t otaHandle;
182
+ esp_err_t err = esp_ota_begin(updatePartition, eraseLength, &otaHandle);
183
+ const int64_t eraseUs = esp_timer_get_time() - eraseStartUs;
184
+ if (err != ESP_OK) {
185
+ ESP_LOGE(kTag, "esp_ota_begin failed: %s", esp_err_to_name(err));
186
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "OTA begin failed");
187
+ return ESP_FAIL;
188
+ }
189
+ ESP_LOGI(kTag, "OTA erase: %d bytes in %lld ms", req->content_len, eraseUs / 1000);
190
+
191
+ const int64_t transferStartUs = esp_timer_get_time();
192
+ const int total = receiveImage(req, otaHandle);
193
+ if (total < 0) return ESP_FAIL;
194
+ const int64_t transferUs = esp_timer_get_time() - transferStartUs;
195
+
196
+ err = esp_ota_end(otaHandle);
197
+ if (err != ESP_OK) {
198
+ ESP_LOGE(kTag, "esp_ota_end failed: %s", esp_err_to_name(err));
199
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "OTA validation failed");
200
+ return ESP_FAIL;
201
+ }
202
+
203
+ if (setBoot) {
204
+ err = esp_ota_set_boot_partition(updatePartition);
205
+ if (err != ESP_OK) {
206
+ ESP_LOGE(kTag, "esp_ota_set_boot_partition failed: %s", esp_err_to_name(err));
207
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Set boot partition failed");
208
+ return ESP_FAIL;
209
+ }
210
+ }
211
+
212
+ // Report the phases separately: erase, socket receive, and flash write are
213
+ // three different bottlenecks and a single aggregate rate hides which one
214
+ // is binding.
215
+ const int64_t totalUs = eraseUs + transferUs;
216
+ ESP_LOGI(kTag,
217
+ "OTA complete for %s! %d bytes in %lld ms (%lu B/s) "
218
+ "[erase %lld ms, recv %lld ms, flash %lld ms, payload %lu B/s]",
219
+ updatePartition->label,
220
+ total,
221
+ totalUs / 1000,
222
+ static_cast<unsigned long>(totalUs > 0 ? (static_cast<int64_t>(total) * 1000000 / totalUs) : 0),
223
+ eraseUs / 1000,
224
+ recvUs_ / 1000,
225
+ writeUs_ / 1000,
226
+ static_cast<unsigned long>(transferUs > 0 ? (static_cast<int64_t>(total) * 1000000 / transferUs) : 0));
227
+ httpd_resp_sendstr(req, rebootAfter ? "OTA OK, rebooting...\n" : "OTA OK, staged.\n");
228
+
229
+ if (rebootAfter) {
230
+ vTaskDelay(pdMS_TO_TICKS(500));
231
+ esp_restart();
232
+ }
233
+
234
+ return ESP_OK;
235
+ }
236
+
237
+ // Staging for the receive loop. It MUST live in internal DRAM: the main flash
238
+ // is hosted on SPI1, for which spi_flash_hal_supports_direct_write() is false,
239
+ // so esp_flash_write only takes its direct path when esp_ptr_in_dram(buffer)
240
+ // holds. A PSRAM staging buffer would instead be copied into flash through a
241
+ // 32-byte stack bounce buffer, one bus acquisition and cache-disable window per
242
+ // 32 bytes. PSRAM is plentiful on this board and completely unusable here.
243
+ //
244
+ // Receiving and writing run in sequence on purpose. A double-buffered writer
245
+ // task was built and measured, and it bought nothing (30.6 s against 28.9 s for
246
+ // this loop on the same image): esp_ota_write disables the flash cache, which
247
+ // stops every flash-resident instruction on both cores — including lwIP and the
248
+ // WiFi driver — so the socket cannot be drained while a write is in flight no
249
+ // matter which task owns it. Overlap here needs the receive path in IRAM, not
250
+ // another task.
251
+ // The OTA staging buffer competes for DMA-capable internal DRAM with the
252
+ // display's elastic flush staging -- and, since the diagnostics server landed,
253
+ // with its socket too. What matters is not the buffer's SIZE but its REGION:
254
+ // with no DMA-capable block free, the request falls back to RTC fast memory,
255
+ // which is not DRAM, and esp_flash_write then copies the whole image through a
256
+ // 32-byte bounce buffer. Measured on this board: flash phase 8.0 s from DRAM
257
+ // vs 20.6 s from RTC fast, for the same 3.9 MB image. (Chunk size itself is
258
+ // nearly free -- 4 KiB and 32 KiB writes clock the same 495-507 KB/s.)
259
+ //
260
+ // Borrow the RAM from the display for the duration of the transfer, exactly
261
+ // as the WiFi bring-up does. The screen is static during an OTA, so a smaller
262
+ // flush pipeline costs nothing visible, and the reservation is released on
263
+ // every exit path.
264
+ struct DisplayRamLoan {
265
+ explicit DisplayRamLoan(std::size_t bytes)
266
+ {
267
+ if (bytes == 0) return;
268
+ gea::platform::display::Display::reserveInternal(bytes);
269
+ // The resize is applied by the frame task, not here on the HTTP task,
270
+ // so give it a few frames to land before we try to allocate.
271
+ vTaskDelay(pdMS_TO_TICKS(100));
272
+ active_ = true;
273
+ }
274
+ ~DisplayRamLoan()
275
+ {
276
+ if (active_) gea::platform::display::Display::reserveInternal(0);
277
+ }
278
+ DisplayRamLoan(const DisplayRamLoan &) = delete;
279
+ DisplayRamLoan &operator=(const DisplayRamLoan &) = delete;
280
+
281
+ private:
282
+ bool active_ = false;
283
+ };
284
+
285
+ struct ReceiveStaging {
286
+ std::uint8_t *data = nullptr;
287
+ std::size_t size = 0;
288
+
289
+ // MALLOC_CAP_DMA, not a bare MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT.
290
+ // "Internal and 8-bit accessible" also matches RTC FAST memory, which the
291
+ // heap hands out once DRAM runs short -- and RTC fast is not DRAM, so
292
+ // esp_flash_write refuses its direct path and copies the whole image
293
+ // through a 32-byte stack bounce buffer. Measured on this board: 517 KB/s
294
+ // from DRAM vs 212 KB/s from RTC fast, i.e. the flash phase of a 3.9 MB
295
+ // OTA went 7.6 s -> 20 s with no code change, purely because the buffer
296
+ // landed in the wrong internal heap. A SMALLER DRAM buffer beats a larger
297
+ // RTC one: the same measurement showed 4 KiB and 32 KiB writes running at
298
+ // identical speed, so chunk size is nearly free while the source region is
299
+ // worth 2.4x.
300
+ explicit ReceiveStaging(std::size_t preferred)
301
+ {
302
+ for (std::size_t candidate = preferred; candidate >= 1024; candidate /= 2) {
303
+ data = static_cast<std::uint8_t *>(
304
+ heap_caps_malloc(candidate, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA));
305
+ if (data) {
306
+ size = candidate;
307
+ return;
308
+ }
309
+ }
310
+ }
311
+ ~ReceiveStaging() { heap_caps_free(data); }
312
+ ReceiveStaging(const ReceiveStaging &) = delete;
313
+ ReceiveStaging &operator=(const ReceiveStaging &) = delete;
314
+ };
315
+
316
+ int receiveImage(httpd_req_t *req, esp_ota_handle_t otaHandle)
317
+ {
318
+ char stackBuffer[1024];
319
+ const DisplayRamLoan ramLoan(16 * 1024);
320
+ ReceiveStaging staging(8192);
321
+ char *const buffer = staging.data ? reinterpret_cast<char *>(staging.data) : stackBuffer;
322
+ const std::size_t bufferSize = staging.data ? staging.size : sizeof(stackBuffer);
323
+ // A staging buffer that shrank -- or worse, landed outside DRAM -- because
324
+ // another subsystem took the DMA-capable heap first shows up as a slower
325
+ // OTA, not as an allocation failure. Report the size actually obtained
326
+ // alongside the DMA heap it came from, so the two are comparable after the
327
+ // fact without another build.
328
+ ESP_LOGI(kTag, "OTA staging buffer: %u bytes (internal-dma free=%u largest=%u)",
329
+ static_cast<unsigned>(bufferSize),
330
+ static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)),
331
+ static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)));
332
+
333
+ int received = 0;
334
+ int total = 0;
335
+ int loggedAt = 0;
336
+ recvUs_ = 0;
337
+ writeUs_ = 0;
338
+
339
+ while (total < req->content_len) {
340
+ const std::size_t remaining = static_cast<std::size_t>(req->content_len - total);
341
+ const int64_t recvStartUs = esp_timer_get_time();
342
+ received = httpd_req_recv(req, buffer, remaining < bufferSize ? remaining : bufferSize);
343
+ recvUs_ += esp_timer_get_time() - recvStartUs;
344
+ if (received == HTTPD_SOCK_ERR_TIMEOUT) {
345
+ // A busy radio can temporarily drain lwIP's receive queue while the
346
+ // peer is still connected. ESP-IDF documents this as retryable; the
347
+ // old handler aborted an otherwise healthy upload on the first stall.
348
+ continue;
349
+ }
350
+ if (received <= 0) break;
351
+ const int64_t writeStartUs = esp_timer_get_time();
352
+ const esp_err_t err = esp_ota_write(otaHandle, buffer, received);
353
+ writeUs_ += esp_timer_get_time() - writeStartUs;
354
+ if (err != ESP_OK) {
355
+ ESP_LOGE(kTag, "esp_ota_write failed: %s", esp_err_to_name(err));
356
+ esp_ota_abort(otaHandle);
357
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "OTA write failed");
358
+ return -1;
359
+ }
360
+ total += received;
361
+ if (total - loggedAt >= (512 * 1024)) {
362
+ loggedAt = total;
363
+ ESP_LOGI(kTag, "OTA progress: %d of %d bytes", total, req->content_len);
364
+ }
365
+ }
366
+
367
+ if (total != req->content_len) {
368
+ ESP_LOGE(kTag, "OTA receive error after %d of %d bytes", total, req->content_len);
369
+ esp_ota_abort(otaHandle);
370
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Receive failed");
371
+ return -1;
372
+ }
373
+
374
+ return total;
375
+ }
376
+
377
+ int64_t recvUs_ = 0;
378
+ int64_t writeUs_ = 0;
379
+
380
+ esp_err_t handleStatus(httpd_req_t *req)
381
+ {
382
+ httpd_resp_set_type(req, "application/json");
383
+
384
+ const esp_partition_t *running = esp_ota_get_running_partition();
385
+ esp_app_desc_t desc;
386
+ char chunk[256];
387
+
388
+ httpd_resp_sendstr_chunk(req, "{\"running\":");
389
+ if (running) {
390
+ const char *version = "";
391
+ if (esp_ota_get_partition_description(running, &desc) == ESP_OK) version = desc.version;
392
+ snprintf(chunk, sizeof(chunk), "{\"label\":\"%s\",\"offset\":%lu,\"size\":%lu,\"version\":\"%s\"}",
393
+ running->label, (unsigned long)running->address, (unsigned long)running->size, version);
394
+ httpd_resp_sendstr_chunk(req, chunk);
395
+ } else {
396
+ httpd_resp_sendstr_chunk(req, "null");
397
+ }
398
+
399
+ httpd_resp_sendstr_chunk(req, ",\"partitions\":[");
400
+ bool first = true;
401
+ esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, nullptr);
402
+ while (it) {
403
+ const esp_partition_t *partition = esp_partition_get(it);
404
+ if (partition) {
405
+ const char *version = "";
406
+ if (esp_ota_get_partition_description(partition, &desc) == ESP_OK) version = desc.version;
407
+ snprintf(chunk, sizeof(chunk), "%s{\"label\":\"%s\",\"offset\":%lu,\"size\":%lu,\"version\":\"%s\"}",
408
+ first ? "" : ",", partition->label, (unsigned long)partition->address, (unsigned long)partition->size, version);
409
+ httpd_resp_sendstr_chunk(req, chunk);
410
+ first = false;
411
+ }
412
+ it = esp_partition_next(it);
413
+ }
414
+ if (it) esp_partition_iterator_release(it);
415
+ httpd_resp_sendstr_chunk(req, "]");
416
+
417
+ // Flash identity. Decides whether CONFIG_SPI_FLASH_AUTO_SUSPEND can be
418
+ // turned on for this board at all -- see kSuspendQualifiedIds above.
419
+ std::uint32_t chipId = 0;
420
+ if (esp_flash_read_id(nullptr, &chipId) == ESP_OK) {
421
+ snprintf(chunk, sizeof(chunk),
422
+ ",\"flash\":{\"id\":\"0x%06lx\",\"suspendQualified\":%s}",
423
+ (unsigned long)chipId, flashSuspendQualified(chipId) ? "true" : "false");
424
+ httpd_resp_sendstr_chunk(req, chunk);
425
+ }
426
+
427
+ // Clock and internal-heap state. Both are inputs to flash throughput: the
428
+ // SPI flash clock is derived from the CPU/APB clock, and a bench or OTA
429
+ // staging buffer that cannot find contiguous internal DRAM silently falls
430
+ // back to a smaller chunk. Reporting them turns "the flash got slower"
431
+ // from a guess into a comparison.
432
+ snprintf(chunk, sizeof(chunk),
433
+ ",\"clocks\":{\"cpuMhz\":%d},\"heap\":{\"internalFree\":%u,\"internalLargest\":%u,\"dmaLargest\":%u}",
434
+ esp_clk_cpu_freq() / 1000000,
435
+ static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
436
+ static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)),
437
+ static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)));
438
+ httpd_resp_sendstr_chunk(req, chunk);
439
+ httpd_resp_sendstr_chunk(req, "}");
440
+ httpd_resp_sendstr_chunk(req, nullptr);
441
+ return ESP_OK;
442
+ }
443
+
444
+ esp_err_t handleErase(httpd_req_t *req)
445
+ {
446
+ char query[64] = {};
447
+ char slot[17] = {};
448
+ if (httpd_req_get_url_query_str(req, query, sizeof(query)) != ESP_OK
449
+ || httpd_query_key_value(query, "slot", slot, sizeof(slot)) != ESP_OK) {
450
+ httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Missing slot");
451
+ return ESP_FAIL;
452
+ }
453
+
454
+ const esp_partition_t *partition = findSlot(slot);
455
+ if (!partition) {
456
+ httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "OTA slot not found");
457
+ return ESP_FAIL;
458
+ }
459
+
460
+ const esp_partition_t *running = esp_ota_get_running_partition();
461
+ if (running && running->address == partition->address) {
462
+ httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Cannot erase the running partition");
463
+ return ESP_FAIL;
464
+ }
465
+
466
+ ESP_LOGI(kTag, "Erasing OTA slot %s (%lu bytes)", partition->label, (unsigned long)partition->size);
467
+ const esp_err_t err = esp_partition_erase_range(partition, 0, partition->size);
468
+ if (err != ESP_OK) {
469
+ ESP_LOGE(kTag, "Failed to erase %s: %s", partition->label, esp_err_to_name(err));
470
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Erase failed");
471
+ return ESP_FAIL;
472
+ }
473
+
474
+ httpd_resp_sendstr(req, "OTA slot erased.\n");
475
+ return ESP_OK;
476
+ }
477
+
478
+ // Raw flash erase/program throughput on the INACTIVE OTA slot, with no radio
479
+ // and no TCP in the path. This exists to answer one question with a
480
+ // measurement instead of arithmetic: is the OTA "flash" phase sitting on the
481
+ // SPI NOR floor, or on per-call overhead in esp_ota_write? It reports two
482
+ // program rates -- one at the 8 KiB chunk the OTA receive loop uses, one at
483
+ // 64 KiB. If they agree, the part itself is the limit.
484
+ esp_err_t handleFlashBench(httpd_req_t *req)
485
+ {
486
+ const esp_partition_t *partition = esp_ota_get_next_update_partition(nullptr);
487
+ if (!partition) {
488
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "No spare OTA partition");
489
+ return ESP_FAIL;
490
+ }
491
+ const esp_partition_t *running = esp_ota_get_running_partition();
492
+ if (running && running->address == partition->address) {
493
+ httpd_resp_send_err(req, HTTPD_403_FORBIDDEN, "Refusing to benchmark the running partition");
494
+ return ESP_FAIL;
495
+ }
496
+
497
+ char query[64] = {};
498
+ char bytesValue[16] = {};
499
+ std::size_t length = 1024 * 1024;
500
+ if (httpd_req_get_url_query_str(req, query, sizeof(query)) == ESP_OK
501
+ && httpd_query_key_value(query, "bytes", bytesValue, sizeof(bytesValue)) == ESP_OK) {
502
+ const long requested = strtol(bytesValue, nullptr, 10);
503
+ if (requested > 0) length = static_cast<std::size_t>(requested);
504
+ }
505
+ length &= ~static_cast<std::size_t>(0xFFF); // whole 4 KiB sectors
506
+ if (length == 0 || length > partition->size) length = partition->size;
507
+
508
+ // Internal DRAM is scarce with both radios up, so take the largest
509
+ // staging buffer that fits and report which size was used. MALLOC_CAP_DMA
510
+ // for the same reason ReceiveStaging uses it: an RTC-fast buffer measures
511
+ // the bounce path, not the flash. The address is reported so a slow result
512
+ // can be attributed to the region rather than guessed at.
513
+ // Borrow the display's elastic staging exactly as the real transfer does,
514
+ // so the bench measures the conditions an OTA actually runs under rather
515
+ // than the idle ones. Without it there is no 4 KiB DMA-capable block free
516
+ // on this board at all and the bench simply fails.
517
+ const DisplayRamLoan ramLoan(16 * 1024);
518
+ std::size_t benchBuffer = 0;
519
+ std::uint8_t *buffer = nullptr;
520
+ for (std::size_t candidate = 32768; candidate >= 1024; candidate /= 2) {
521
+ buffer = static_cast<std::uint8_t *>(
522
+ heap_caps_malloc(candidate, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA));
523
+ if (buffer) { benchBuffer = candidate; break; }
524
+ }
525
+ if (!buffer) {
526
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "No internal DRAM for the bench buffer");
527
+ return ESP_FAIL;
528
+ }
529
+ std::memset(buffer, 0xA5, benchBuffer);
530
+
531
+ const int64_t eraseStartUs = esp_timer_get_time();
532
+ esp_err_t err = esp_partition_erase_range(partition, 0, length);
533
+ const int64_t eraseUs = esp_timer_get_time() - eraseStartUs;
534
+
535
+ int64_t write8Us = 0;
536
+ int64_t write64Us = 0;
537
+ const std::size_t half = (length / 2) & ~static_cast<std::size_t>(0xFFF);
538
+ if (err == ESP_OK) {
539
+ const int64_t start = esp_timer_get_time();
540
+ const std::size_t smallChunk = benchBuffer < 4096 ? benchBuffer : 4096;
541
+ for (std::size_t offset = 0; offset < half && err == ESP_OK; offset += smallChunk)
542
+ err = esp_partition_write(partition, offset, buffer, smallChunk);
543
+ write8Us = esp_timer_get_time() - start;
544
+ }
545
+ if (err == ESP_OK) {
546
+ const int64_t start = esp_timer_get_time();
547
+ for (std::size_t offset = half; offset < length && err == ESP_OK; offset += benchBuffer)
548
+ err = esp_partition_write(partition, offset, buffer, benchBuffer);
549
+ write64Us = esp_timer_get_time() - start;
550
+ }
551
+ // Record where the buffer lived before releasing it: "internal" is not one
552
+ // region, and only a DRAM source gets esp_flash_write's direct path.
553
+ const std::uintptr_t bufferAddress = reinterpret_cast<std::uintptr_t>(buffer);
554
+ const bool bufferInDram = esp_ptr_in_dram(buffer);
555
+ heap_caps_free(buffer);
556
+
557
+ if (err != ESP_OK) {
558
+ ESP_LOGE(kTag, "flash bench failed: %s", esp_err_to_name(err));
559
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Flash bench failed");
560
+ return ESP_FAIL;
561
+ }
562
+
563
+ // The slot now holds 0xA5, not an image. Say so: the caller must reflash
564
+ // it before that slot can be booted.
565
+ ESP_LOGW(kTag, "flash bench overwrote %s -- reflash before booting it", partition->label);
566
+
567
+ const auto rate = [](std::size_t bytes, int64_t us) -> unsigned long {
568
+ return us > 0 ? static_cast<unsigned long>((static_cast<int64_t>(bytes) * 1000000) / us / 1024) : 0;
569
+ };
570
+ char body[512];
571
+ snprintf(body, sizeof(body),
572
+ "{\"slot\":\"%s\",\"bytes\":%lu,"
573
+ "\"eraseMs\":%lld,\"eraseKBs\":%lu,"
574
+ "\"chunkBytes\":%lu,\"chunkAddr\":\"0x%08lx\",\"chunkInDram\":%s,"
575
+ "\"program4kMs\":%lld,\"program4kKBs\":%lu,"
576
+ "\"programBigMs\":%lld,\"programBigKBs\":%lu,"
577
+ "\"combinedKBs\":%lu}\n",
578
+ partition->label, (unsigned long)length,
579
+ eraseUs / 1000, rate(length, eraseUs),
580
+ (unsigned long)benchBuffer, (unsigned long)bufferAddress, bufferInDram ? "true" : "false",
581
+ write8Us / 1000, rate(half, write8Us),
582
+ write64Us / 1000, rate(length - half, write64Us),
583
+ rate(length, eraseUs + write8Us + write64Us));
584
+ httpd_resp_set_type(req, "application/json");
585
+ httpd_resp_sendstr(req, body);
586
+ return ESP_OK;
587
+ }
588
+
589
+ static esp_err_t flashBenchHandler(httpd_req_t *req)
590
+ {
591
+ return instance().handleFlashBench(req);
592
+ }
593
+
594
+ // Capture the live frame and return it as raw RGB565, the same
595
+ // "rgb565-raw-v1" payload the serial SCREENSHOTBIN command emits, so the host
596
+ // decoder is shared. Screenshots used to require the USB cable; the panel is
597
+ // 410x502x2 = ~402 KiB, which is ~26 s over BLE but well under a second here.
598
+ #if GEA_PIXEL_STORAGE_PACKED
599
+ // A packed (GRAY4/GRAY2) board's real framebuffer is a quarter/eighth the
600
+ // size an RGB565 expansion of the same pixels would need. Capture that (what
601
+ // the device can actually spare -- see the SCREENSHOTBIN fix this mirrors in
602
+ // device_control.cpp) and expand to RGB565 one row at a time while chunking
603
+ // to the socket. The wire payload stays rgb565-raw-v1 (shared with
604
+ // SCREENSHOTBIN), so the host decoder needs no changes.
605
+ esp_err_t handleScreenshot(httpd_req_t *req)
606
+ {
607
+ const int pixelCount = gea::platform::display::kWidth * gea::platform::display::kHeight;
608
+ const std::size_t byteCount = static_cast<std::size_t>(
609
+ gea::framework::graphics::pixel::packed::rowBytes(pixelCount));
610
+ auto *snapshot = static_cast<std::uint8_t *>(
611
+ heap_caps_malloc(byteCount, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
612
+ if (!snapshot) {
613
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "No PSRAM for the snapshot");
614
+ return ESP_FAIL;
615
+ }
616
+
617
+ int width = 0;
618
+ int height = 0;
619
+ char appId[96] = {};
620
+ const bool captured = gea::platform::esp32::services::captureScreenshotPacked(
621
+ snapshot, static_cast<int>(byteCount), &width, &height, appId, sizeof(appId));
622
+ if (!captured) {
623
+ heap_caps_free(snapshot);
624
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Display unavailable");
625
+ return ESP_FAIL;
626
+ }
627
+
628
+ char widthHeader[16];
629
+ char heightHeader[16];
630
+ httpd_resp_set_type(req, "application/octet-stream");
631
+ snprintf(widthHeader, sizeof(widthHeader), "%d", width);
632
+ httpd_resp_set_hdr(req, "X-Gea-Width", widthHeader);
633
+ snprintf(heightHeader, sizeof(heightHeader), "%d", height);
634
+ httpd_resp_set_hdr(req, "X-Gea-Height", heightHeader);
635
+ httpd_resp_set_hdr(req, "X-Gea-Encoding", "rgb565-raw-v1");
636
+ httpd_resp_set_hdr(req, "X-Gea-App", appId);
637
+
638
+ using gea::framework::graphics::pixel::packed;
639
+ using gea::framework::graphics::pixel::fromNative;
640
+ auto *rowRgb = static_cast<std::uint16_t *>(
641
+ heap_caps_malloc(static_cast<std::size_t>(width) * sizeof(std::uint16_t), MALLOC_CAP_8BIT));
642
+ if (!rowRgb) {
643
+ heap_caps_free(snapshot);
644
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "No memory for the row buffer");
645
+ return ESP_FAIL;
646
+ }
647
+ esp_err_t err = ESP_OK;
648
+ for (int row = 0; row < height && err == ESP_OK; ++row) {
649
+ for (int x = 0; x < width; ++x)
650
+ rowRgb[x] = fromNative(packed::get(snapshot, row * width + x));
651
+ err = httpd_resp_send_chunk(req, reinterpret_cast<const char *>(rowRgb),
652
+ static_cast<std::size_t>(width) * sizeof(std::uint16_t));
653
+ }
654
+ if (err == ESP_OK) err = httpd_resp_send_chunk(req, nullptr, 0);
655
+ heap_caps_free(rowRgb);
656
+ heap_caps_free(snapshot);
657
+ return err;
658
+ }
659
+ #else
660
+ esp_err_t handleScreenshot(httpd_req_t *req)
661
+ {
662
+ const int pixelCount = gea::platform::display::kWidth * gea::platform::display::kHeight;
663
+ auto *snapshot = static_cast<std::uint16_t *>(
664
+ heap_caps_malloc(static_cast<std::size_t>(pixelCount) * sizeof(std::uint16_t),
665
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
666
+ if (!snapshot) {
667
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "No PSRAM for the snapshot");
668
+ return ESP_FAIL;
669
+ }
670
+
671
+ int width = 0;
672
+ int height = 0;
673
+ char appId[96] = {};
674
+ const bool captured = gea::platform::esp32::services::captureScreenshotRgb565(
675
+ snapshot, pixelCount, &width, &height, appId, sizeof(appId));
676
+ if (!captured) {
677
+ heap_caps_free(snapshot);
678
+ httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Display unavailable");
679
+ return ESP_FAIL;
680
+ }
681
+
682
+ // httpd_resp_set_hdr stores the POINTER, not a copy, and the value must
683
+ // stay alive until the response is sent -- so every header needs its own
684
+ // buffer. Sharing one made both dimensions report the last value written.
685
+ char widthHeader[16];
686
+ char heightHeader[16];
687
+ httpd_resp_set_type(req, "application/octet-stream");
688
+ snprintf(widthHeader, sizeof(widthHeader), "%d", width);
689
+ httpd_resp_set_hdr(req, "X-Gea-Width", widthHeader);
690
+ snprintf(heightHeader, sizeof(heightHeader), "%d", height);
691
+ httpd_resp_set_hdr(req, "X-Gea-Height", heightHeader);
692
+ httpd_resp_set_hdr(req, "X-Gea-Encoding", "rgb565-raw-v1");
693
+ httpd_resp_set_hdr(req, "X-Gea-App", appId);
694
+
695
+ // Send in bounded chunks: one 402 KiB write would pin the whole frame in
696
+ // the socket path at once.
697
+ const auto *bytes = reinterpret_cast<const char *>(snapshot);
698
+ const std::size_t total = static_cast<std::size_t>(width) * static_cast<std::size_t>(height)
699
+ * sizeof(std::uint16_t);
700
+ esp_err_t err = ESP_OK;
701
+ for (std::size_t sent = 0; sent < total && err == ESP_OK; sent += 8192) {
702
+ const std::size_t span = (total - sent) < 8192 ? (total - sent) : 8192;
703
+ err = httpd_resp_send_chunk(req, bytes + sent, span);
704
+ }
705
+ if (err == ESP_OK) err = httpd_resp_send_chunk(req, nullptr, 0);
706
+ heap_caps_free(snapshot);
707
+ return err;
708
+ }
709
+ #endif // GEA_PIXEL_STORAGE_PACKED
710
+
711
+ static esp_err_t screenshotHandler(httpd_req_t *req)
712
+ {
713
+ return instance().handleScreenshot(req);
714
+ }
715
+
716
+ // POST /display/hbm?on=1|0 -- toggle the panel's high-brightness mode over
717
+ // WiFi. Lives on this server because it is the one HTTP surface a cable-free
718
+ // board has; it is device control, not OTA.
719
+ esp_err_t handleDisplayHbm(httpd_req_t *req)
720
+ {
721
+ char query[32] = {};
722
+ char onValue[8] = {};
723
+ bool on = true;
724
+ if (httpd_req_get_url_query_str(req, query, sizeof(query)) == ESP_OK
725
+ && httpd_query_key_value(query, "on", onValue, sizeof(onValue)) == ESP_OK) {
726
+ on = !(onValue[0] == '0' || onValue[0] == 'f' || onValue[0] == 'n');
727
+ }
728
+ const bool ok = gea::platform::display::Display::setHighBrightnessMode(on);
729
+ char body[96];
730
+ snprintf(body, sizeof(body), "{\"ok\":%s,\"hbm\":%s}\n", ok ? "true" : "false",
731
+ gea::platform::display::Display::highBrightnessMode() ? "true" : "false");
732
+ httpd_resp_set_type(req, "application/json");
733
+ if (!ok) httpd_resp_set_status(req, "501 Not Implemented");
734
+ httpd_resp_sendstr(req, body);
735
+ return ESP_OK;
736
+ }
737
+ static esp_err_t displayHbmHandler(httpd_req_t *req) { return instance().handleDisplayHbm(req); }
738
+
739
+ // POST /display/brightness?value=0-100 and /display/vsync?on=1|0 -- the
740
+ // remaining display knobs, so every one of them answers on WiFi as well as
741
+ // over USB (GEADEV BRIGHTNESS/HBM/VSYNC). Without a value each reports.
742
+ esp_err_t handleDisplayBrightness(httpd_req_t *req)
743
+ {
744
+ using gea::platform::display::Display;
745
+ char query[32] = {};
746
+ char value[8] = {};
747
+ if (httpd_req_get_url_query_str(req, query, sizeof(query)) == ESP_OK
748
+ && httpd_query_key_value(query, "value", value, sizeof(value)) == ESP_OK) {
749
+ int percent = atoi(value);
750
+ if (percent < 0) percent = 0;
751
+ if (percent > 100) percent = 100;
752
+ Display::setBrightness(percent);
753
+ }
754
+ char body[64];
755
+ snprintf(body, sizeof(body), "{\"ok\":true,\"brightness\":%d}\n", Display::brightness());
756
+ httpd_resp_set_type(req, "application/json");
757
+ httpd_resp_sendstr(req, body);
758
+ return ESP_OK;
759
+ }
760
+ static esp_err_t displayBrightnessHandler(httpd_req_t *req) { return instance().handleDisplayBrightness(req); }
761
+
762
+ esp_err_t handleDisplayVsync(httpd_req_t *req)
763
+ {
764
+ using gea::platform::display::Display;
765
+ char query[32] = {};
766
+ char onValue[8] = {};
767
+ if (httpd_req_get_url_query_str(req, query, sizeof(query)) == ESP_OK
768
+ && httpd_query_key_value(query, "on", onValue, sizeof(onValue)) == ESP_OK) {
769
+ Display::setVSync(!(onValue[0] == '0' || onValue[0] == 'f' || onValue[0] == 'n'));
770
+ }
771
+ char body[64];
772
+ snprintf(body, sizeof(body), "{\"ok\":true,\"vsync\":%s}\n", Display::vsyncEnabled() ? "true" : "false");
773
+ httpd_resp_set_type(req, "application/json");
774
+ httpd_resp_sendstr(req, body);
775
+ return ESP_OK;
776
+ }
777
+ static esp_err_t displayVsyncHandler(httpd_req_t *req) { return instance().handleDisplayVsync(req); }
778
+
779
+ void registerHandlers()
780
+ {
781
+ httpd_uri_t otaUri = {};
782
+ otaUri.uri = "/ota";
783
+ otaUri.method = HTTP_POST;
784
+ otaUri.handler = &OtaHttpServer::postHandler;
785
+ httpd_register_uri_handler(server_, &otaUri);
786
+
787
+ httpd_uri_t statusUri = {};
788
+ statusUri.uri = "/ota/status";
789
+ statusUri.method = HTTP_GET;
790
+ statusUri.handler = &OtaHttpServer::statusHandler;
791
+ httpd_register_uri_handler(server_, &statusUri);
792
+
793
+ httpd_uri_t screenshotUri = {};
794
+ screenshotUri.uri = "/screenshot";
795
+ screenshotUri.method = HTTP_GET;
796
+ screenshotUri.handler = &OtaHttpServer::screenshotHandler;
797
+ httpd_register_uri_handler(server_, &screenshotUri);
798
+
799
+ httpd_uri_t hbmUri = {};
800
+ hbmUri.uri = "/display/hbm";
801
+ hbmUri.method = HTTP_POST;
802
+ hbmUri.handler = &OtaHttpServer::displayHbmHandler;
803
+ httpd_register_uri_handler(server_, &hbmUri);
804
+
805
+ httpd_uri_t brightnessUri = {};
806
+ brightnessUri.uri = "/display/brightness";
807
+ brightnessUri.method = HTTP_POST;
808
+ brightnessUri.handler = &OtaHttpServer::displayBrightnessHandler;
809
+ httpd_register_uri_handler(server_, &brightnessUri);
810
+
811
+ httpd_uri_t vsyncUri = {};
812
+ vsyncUri.uri = "/display/vsync";
813
+ vsyncUri.method = HTTP_POST;
814
+ vsyncUri.handler = &OtaHttpServer::displayVsyncHandler;
815
+ httpd_register_uri_handler(server_, &vsyncUri);
816
+
817
+ httpd_uri_t benchUri = {};
818
+ benchUri.uri = "/ota/flashbench";
819
+ benchUri.method = HTTP_POST;
820
+ benchUri.handler = &OtaHttpServer::flashBenchHandler;
821
+ httpd_register_uri_handler(server_, &benchUri);
822
+
823
+ httpd_uri_t eraseUri = {};
824
+ eraseUri.uri = "/ota/erase";
825
+ eraseUri.method = HTTP_POST;
826
+ eraseUri.handler = &OtaHttpServer::eraseHandler;
827
+ httpd_register_uri_handler(server_, &eraseUri);
828
+ }
829
+
830
+ httpd_handle_t server_ = nullptr;
831
+ };
832
+
833
+ } // namespace
834
+
835
+ bool OtaServer::start()
836
+ {
837
+ return OtaHttpServer::instance().start();
838
+ }
839
+
840
+ } // namespace gea::framework::services