@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,1391 @@
1
+ #include "display.h"
2
+
3
+ #include "board.h"
4
+ #include "canvas.h"
5
+ #include "display_present.h"
6
+ #include "host/display_orientation.h"
7
+ #include "i2c.h"
8
+ #include "pixel.h"
9
+
10
+ #include <algorithm>
11
+ #include <atomic>
12
+ #include <cstddef>
13
+ #include <cstdint>
14
+ #include <cstdio>
15
+ #include <cstring>
16
+
17
+ #include "driver/gpio.h"
18
+ #include "driver/i2c_master.h"
19
+ #include "driver/ledc.h"
20
+ #include "driver/spi_master.h"
21
+ #include "esp_attr.h"
22
+ #include "esp_err.h"
23
+ #include "esp_heap_caps.h"
24
+ #include "esp_lcd_panel_io.h"
25
+ #include "esp_lcd_panel_ops.h"
26
+ #include "esp_lcd_panel_vendor.h"
27
+ #include "esp_log.h"
28
+ #include "esp_timer.h"
29
+ #include "freertos/FreeRTOS.h"
30
+ #include "freertos/semphr.h"
31
+ #include "freertos/task.h"
32
+
33
+ namespace platform_display = gea::platform::display;
34
+ namespace orientation_detail = gea::framework::display::detail;
35
+ namespace pixel = gea::framework::graphics::pixel;
36
+ namespace present = gea::framework::display_present;
37
+
38
+ namespace gea::platform::esp32_s3_sticks3::display {
39
+
40
+ namespace {
41
+
42
+ constexpr const char *kTag = "sticks3_display";
43
+ constexpr int kNativeWidth = platform_display::kNativeWidth; // 135
44
+ constexpr int kNativeHeight = platform_display::kNativeHeight; // 240
45
+ constexpr int kMaxLogicalWidth = kNativeHeight > kNativeWidth ? kNativeHeight : kNativeWidth;
46
+ constexpr int kMaxPixels = kNativeWidth * kNativeHeight;
47
+ constexpr int kFlushRowsDefault = 64;
48
+ // ST7789V2 SPI panel (M5Stack StickS3): 135x240 on a 240x320 GRAM, SPI mode 0,
49
+ // 8-bit command/parameter, color-inverted, RGB element order. 80 MHz pixel
50
+ // clock — over the ST7789V2's spec'd ~62 MHz write cycle, but overclocking
51
+ // ST7789 glass to 80 MHz is common (its ST7796 sibling runs 80 here) and
52
+ // this panel was verified visually clean at 80 MHz on-device. It does NOT
53
+ // raise fps over 40 MHz: bouncing-balls-jsx is rasterization-bound (~11 ms
54
+ // display-list replay/frame → ~71 fps), and the panel-push task already
55
+ // hides the SPI wire, so the clock isn't on the critical path. Kept at 80
56
+ // for latency headroom. (An earlier "80 MHz blanks the panel" reading was a
57
+ // false attribution — the glass was dark because the M5PM1 L3B rail was
58
+ // unpowered, not the clock.) Glass window sits at GRAM offset (52,40) in the
59
+ // panel's native portrait addressing; esp_lcd_panel_set_gap carries the
60
+ // offset so draw_bitmap coords stay 0-based. Framebuffer is panel-endian, so
61
+ // staging is a straight memcpy.
62
+ constexpr int kSpiPclkHz = 80 * 1000 * 1000;
63
+ constexpr int kPanelBitsPerPixel = 16;
64
+ constexpr int kSpiTransQueueDepth = 8;
65
+ // Four staging bands cover a whole 240-row frame (4 x 64-row chunks), so a
66
+ // full-screen flush queues every chunk and returns with the ~13 ms of wire
67
+ // time riding under the NEXT frame's rasterization instead of gating the
68
+ // frame loop (the panel-side cap is then the wire rate, ~76 Hz).
69
+ constexpr int kStagingDepth = 4;
70
+ constexpr int kGapPortraitPrimaryX = 52;
71
+ constexpr int kGapPortraitPrimaryY = 40;
72
+ // MADCTL MX+MY flips addressing across the 240x320 GRAM; the 135-column glass
73
+ // splits the 105 spare columns 52/53, so the mirrored gap is one column over.
74
+ constexpr int kGapPortraitSecondaryX = 53;
75
+ constexpr int kGapPortraitSecondaryY = 40;
76
+ // Flush rotation modes: landscape logical frames are rotated into the panel's
77
+ // portrait scan order at flush time instead of via MADCTL (which would make
78
+ // GRAM writes perpendicular to the gate scan and shear/tear on motion).
79
+ constexpr int kFlushRotationNone = 0;
80
+ constexpr int kFlushRotationLandscapePrimary = 1;
81
+ constexpr int kFlushRotationLandscapeSecondary = 2;
82
+ // Internal-RAM bounce band for CPU-composed flushes. Bands are at most
83
+ // kNativeWidth pixels wide in BOTH orientations: the portrait linear path
84
+ // pushes full-width (135 px) rows, and the landscape path rotates into
85
+ // panel-order bands whose width is the panel's 135-px scan line.
86
+ constexpr int kStagingBytes = kNativeWidth * kFlushRowsDefault * static_cast<int>(sizeof(std::uint16_t));
87
+ constexpr ledc_channel_t kBacklightLedcChannel = LEDC_CHANNEL_1;
88
+ constexpr ledc_timer_t kBacklightLedcTimer = LEDC_TIMER_1;
89
+ constexpr int kBacklightLedcMaxDuty = 1023;
90
+ constexpr int kMaxPresentRects = 16;
91
+ constexpr int kOwnedFrameBufferPixels = kMaxPixels;
92
+
93
+ present::Rect clampLogicalRect(present::Rect rect, int width, int height)
94
+ {
95
+ if (width <= 0 || height <= 0) return {};
96
+ rect = present::clampAndAlign(rect, width, height);
97
+ if (!present::valid(rect)) return {};
98
+ return rect;
99
+ }
100
+
101
+ int integerSqrt(int value)
102
+ {
103
+ if (value <= 0) return 0;
104
+ int result = 0;
105
+ int bit = 1 << 14;
106
+ while (bit > value) bit >>= 2;
107
+ while (bit != 0) {
108
+ if (value >= result + bit) {
109
+ value -= result + bit;
110
+ result = (result >> 1) + bit;
111
+ } else {
112
+ result >>= 1;
113
+ }
114
+ bit >>= 2;
115
+ }
116
+ return result;
117
+ }
118
+
119
+ } // namespace
120
+
121
+ class DisplayBackend {
122
+ public:
123
+ static DisplayBackend &instance()
124
+ {
125
+ static DisplayBackend backend;
126
+ return backend;
127
+ }
128
+
129
+ bool init()
130
+ {
131
+ if (initialized_) return true;
132
+ mutex_ = xSemaphoreCreateMutex();
133
+ if (!mutex_) {
134
+ ESP_LOGE(kTag, "failed to allocate display mutex");
135
+ return false;
136
+ }
137
+
138
+ {
139
+ const std::size_t fbBytes = static_cast<std::size_t>(kOwnedFrameBufferPixels) * sizeof(std::uint16_t);
140
+ ownedFrameBuffer_ = static_cast<std::uint16_t *>(
141
+ heap_caps_malloc(fbBytes, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
142
+ if (ownedFrameBuffer_) std::memset(ownedFrameBuffer_, 0, fbBytes);
143
+ }
144
+ if (!ownedFrameBuffer_) {
145
+ ESP_LOGE(kTag, "display owned framebuffer alloc failed");
146
+ return false;
147
+ }
148
+
149
+ if (!initPanel()) {
150
+ ESP_LOGE(kTag, "panel init failed");
151
+ return false;
152
+ }
153
+ bindCanvas();
154
+ if (frameBuffer_) {
155
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
156
+ }
157
+ initialized_ = true;
158
+ ESP_LOGI(kTag, "display ready native=%dx%d logical=%dx%d", kNativeWidth, kNativeHeight, logicalWidth(), logicalHeight());
159
+ return true;
160
+ }
161
+
162
+ bool start() { return init(); }
163
+
164
+ gea::framework::graphics::Canvas *canvas()
165
+ {
166
+ if (!frameBuffer_) init();
167
+ return &replayCanvas();
168
+ }
169
+
170
+ // A push panel never exposes its own scanout buffer.
171
+ bool framebufferIsPanelDirect() const { return false; }
172
+
173
+ gea::framework::graphics::Canvas *drawingCanvas()
174
+ {
175
+ if (!frameBuffer_) init();
176
+ return &replayCanvas();
177
+ }
178
+
179
+ void applyOrientation()
180
+ {
181
+ take();
182
+ // MADCTL/gap commands must not interleave with a band on the wire.
183
+ waitPanelPushIdle();
184
+ bindCanvasLocked();
185
+ applyPanelOrientation();
186
+ if (!frameBuffer_) {
187
+ give();
188
+ return;
189
+ }
190
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
191
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
192
+ previousPresentValid_ = false;
193
+ needsFullPhysicalFlush_ = true;
194
+ give();
195
+ ESP_LOGI(kTag, "orientation=%s logical=%dx%d",
196
+ orientation_detail::DisplayOrientationState::orientationString().c_str(),
197
+ logicalWidth(), logicalHeight());
198
+ }
199
+
200
+ void clear()
201
+ {
202
+ clearNoFlush();
203
+ flush();
204
+ }
205
+
206
+ void clearNoFlush()
207
+ {
208
+ if (!frameBuffer_) init();
209
+ take();
210
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
211
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
212
+ previousPresentValid_ = false;
213
+ needsFullPhysicalFlush_ = true;
214
+ give();
215
+ }
216
+
217
+ void flush()
218
+ {
219
+ if (!init()) return;
220
+ const bool fullPhysicalFlush = needsFullPhysicalFlush_;
221
+ if (!fullPhysicalFlush && !canvas_.dirty(nullptr, nullptr, nullptr, nullptr)) return;
222
+ const std::int64_t started = esp_timer_get_time();
223
+ gea::framework::graphics::CanvasDirtyRect dirtyRects[gea::framework::graphics::Canvas::kMaxDirtyRects];
224
+ int dirtyCount = 0;
225
+ if (fullPhysicalFlush) {
226
+ dirtyRects[0] = {0, 0, logicalWidth() - 1, logicalHeight() - 1};
227
+ dirtyCount = 1;
228
+ ESP_LOGI(kTag, "first physical flush covers full logical frame %dx%d", logicalWidth(), logicalHeight());
229
+ } else {
230
+ dirtyCount = canvas_.dirtyRects(dirtyRects, gea::framework::graphics::Canvas::kMaxDirtyRects);
231
+ }
232
+ if (!fullPhysicalFlush && dirtyCount <= 0) {
233
+ int x0 = 0;
234
+ int y0 = 0;
235
+ int x1 = -1;
236
+ int y1 = -1;
237
+ if (canvas_.dirty(&x0, &y0, &x1, &y1)) {
238
+ dirtyRects[0] = {x0, y0, x1, y1};
239
+ dirtyCount = 1;
240
+ }
241
+ }
242
+ bool ok = true;
243
+ flushStats_.callCount++;
244
+ for (int i = 0; i < dirtyCount; ++i) {
245
+ const auto &rect = dirtyRects[i];
246
+ if (!flushNativeLogicalRect({rect.x0, rect.y0, rect.x1, rect.y1})) {
247
+ ok = false;
248
+ break;
249
+ }
250
+ }
251
+ flushStats_.totalUs += esp_timer_get_time() - started;
252
+ if (ok) {
253
+ canvas_.resetDirty();
254
+ if (fullPhysicalFlush) needsFullPhysicalFlush_ = false;
255
+ }
256
+ }
257
+
258
+ void flushRects(const platform_display::DisplayFlushRect *rects, int count)
259
+ {
260
+ if (!rects || count <= 0) return;
261
+ if (!init()) return;
262
+ if (needsFullPhysicalFlush_) {
263
+ const std::int64_t started = esp_timer_get_time();
264
+ flushStats_.callCount++;
265
+ ESP_LOGI(kTag, "first physical flush covers full logical frame %dx%d", logicalWidth(), logicalHeight());
266
+ const bool ok = flushNativeLogicalRect({0, 0, logicalWidth() - 1, logicalHeight() - 1});
267
+ flushStats_.totalUs += esp_timer_get_time() - started;
268
+ if (ok) {
269
+ canvas_.resetDirty();
270
+ needsFullPhysicalFlush_ = false;
271
+ }
272
+ return;
273
+ }
274
+ const std::int64_t started = esp_timer_get_time();
275
+ bool ok = true;
276
+ flushStats_.callCount++;
277
+ for (int i = 0; i < count; ++i) {
278
+ const auto &rect = rects[i];
279
+ if (!flushNativeLogicalRect({rect.x0, rect.y0, rect.x1, rect.y1})) {
280
+ ok = false;
281
+ break;
282
+ }
283
+ }
284
+ flushStats_.totalUs += esp_timer_get_time() - started;
285
+ if (ok) canvas_.resetDirty();
286
+ }
287
+
288
+ bool streamRect(int x, int y, int w, int h, platform_display::DisplayStreamRasterFn raster, void *user)
289
+ {
290
+ if (!raster || w <= 0 || h <= 0) return false;
291
+ if (!init()) return false;
292
+ const int x0 = std::max(0, x);
293
+ const int y0 = std::max(0, y);
294
+ const int x1 = std::min(logicalWidth() - 1, x + w - 1);
295
+ const int y1 = std::min(logicalHeight() - 1, y + h - 1);
296
+ if (x0 > x1 || y0 > y1) return true;
297
+
298
+ const int width = x1 - x0 + 1;
299
+ const int maxRows = std::max(1, kFlushRowsDefault);
300
+ for (int row = y0; row <= y1; row += maxRows) {
301
+ int rows = maxRows;
302
+ if (row + rows > y1 + 1) rows = y1 - row + 1;
303
+ if (x0 == 0 && width == logicalStride_) {
304
+ raster(frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_, width, rows, x0, row, user);
305
+ } else {
306
+ for (int copyRow = 0; copyRow < rows; ++copyRow) {
307
+ raster(frameBuffer_ + static_cast<std::size_t>(row + copyRow) * logicalStride_ + x0,
308
+ width,
309
+ 1,
310
+ x0,
311
+ row + copyRow,
312
+ user);
313
+ }
314
+ }
315
+ }
316
+ canvas_.markDirty(x0, y0, x1, y1);
317
+ flush();
318
+ return true;
319
+ }
320
+
321
+ bool presentCommands(const platform_display::DisplayPresentCommand *commands, int commandCount)
322
+ {
323
+ if (!commands || commandCount <= 0 || !init()) return false;
324
+ present::Frame current;
325
+ if (!present::extractFrame(commands, commandCount, current)) return false;
326
+ if (!present::frameHasOpaqueBase(current, logicalWidth(), logicalHeight())) return false;
327
+ if (isFastClearFillCirclesFrame(current) && incrementalCirclePathBeneficial(current)) {
328
+ const bool ok = presentClearFillCirclesFrame(current);
329
+ if (ok) {
330
+ previousPresentFrame_ = std::move(current);
331
+ previousPresentValid_ = true;
332
+ needsFullPhysicalFlush_ = false;
333
+ canvas_.resetDirty();
334
+ }
335
+ return ok;
336
+ }
337
+ present::Rect regions[kMaxPresentRects];
338
+ int regionCount = 0;
339
+ if (previousPresentValid_) {
340
+ regionCount = present::dirtyRects(&previousPresentFrame_,
341
+ current,
342
+ regions,
343
+ kMaxPresentRects,
344
+ logicalWidth(),
345
+ logicalHeight());
346
+ } else {
347
+ regions[0] = {0, 0, logicalWidth() - 1, logicalHeight() - 1};
348
+ regionCount = 1;
349
+ }
350
+ if (regionCount <= 0) {
351
+ previousPresentFrame_ = std::move(current);
352
+ previousPresentValid_ = true;
353
+ return true;
354
+ }
355
+
356
+ const std::int64_t started = esp_timer_get_time();
357
+ bool ok = true;
358
+ flushStats_.callCount++;
359
+ for (int i = 0; i < regionCount; ++i) {
360
+ present::Rect region = clampLogicalRect(regions[i], logicalWidth(), logicalHeight());
361
+ if (!present::valid(region)) continue;
362
+ rasterPresentRegion(current, region);
363
+ ok = flushNativeLogicalRect(region);
364
+ if (!ok) break;
365
+ }
366
+ flushStats_.totalUs += esp_timer_get_time() - started;
367
+ if (ok) {
368
+ previousPresentFrame_ = std::move(current);
369
+ previousPresentValid_ = true;
370
+ needsFullPhysicalFlush_ = false;
371
+ canvas_.resetDirty();
372
+ }
373
+ return ok;
374
+ }
375
+
376
+ // A frame whose base layer is [Clear, FillCircles]. Commands AFTER the circle
377
+ // batch (FPS text, a HUD rect, ...) are overlays drawn on top — they ride the
378
+ // incremental path via a per-frame overlay re-raster.
379
+ static bool isFastClearFillCirclesFrame(const present::Frame &frame)
380
+ {
381
+ using Type = gea::platform::display::DisplayPresentCommandType;
382
+ if (frame.commands.size() < 2) return false;
383
+ const present::Command &clear = frame.commands[0];
384
+ const present::Command &circles = frame.commands[1];
385
+ if (clear.type != Type::Clear || circles.type != Type::FillCirclesRgb565) return false;
386
+ if (circles.alpha != 255 || circles.radius <= 0 || circles.circlesCount < 0) return false;
387
+ return circles.hasCircleEntries();
388
+ }
389
+
390
+ // The incremental circle path erases + redraws every ball to save the
391
+ // writeback of the untouched area; only worth it when the touched area is
392
+ // small relative to the screen.
393
+ bool incrementalCirclePathBeneficial(const present::Frame &current) const
394
+ {
395
+ if (!previousPresentValid_ || needsFullPhysicalFlush_) return false;
396
+ if (!isFastClearFillCirclesFrame(previousPresentFrame_)) return false;
397
+ if (previousPresentFrame_.commands[0].color != current.commands[0].color) return false;
398
+ present::Rect dirty = present::unite(circleBatchBounds(previousPresentFrame_.commands[1]),
399
+ circleBatchBounds(current.commands[1]));
400
+ for (std::size_t i = 2; i < current.commands.size(); ++i)
401
+ dirty = present::unite(dirty, present::commandBounds(current.commands[i], logicalWidth(), logicalHeight()));
402
+ for (std::size_t i = 2; i < previousPresentFrame_.commands.size(); ++i)
403
+ dirty = present::unite(dirty, present::commandBounds(previousPresentFrame_.commands[i], logicalWidth(), logicalHeight()));
404
+ dirty = clampLogicalRect(dirty, logicalWidth(), logicalHeight());
405
+ if (!present::valid(dirty)) return true; // nothing moved — trivially cheap
406
+ const long long dirtyArea = static_cast<long long>(dirty.x1 - dirty.x0 + 1) * (dirty.y1 - dirty.y0 + 1);
407
+ const long long screenArea = static_cast<long long>(logicalWidth()) * logicalHeight();
408
+ return dirtyArea * 3 < screenArea; // only when < ~1/3 of the screen is touched
409
+ }
410
+
411
+ bool presentClearFillCirclesFrame(const present::Frame &current)
412
+ {
413
+ const present::Command &clear = current.commands[0];
414
+ const present::Command &circles = current.commands[1];
415
+ const bool canIncremental =
416
+ previousPresentValid_ &&
417
+ isFastClearFillCirclesFrame(previousPresentFrame_) &&
418
+ previousPresentFrame_.commands[0].color == clear.color;
419
+
420
+ // Overlays = every command past the circle batch (e.g. the FPS text).
421
+ // Their box — current AND previous (to erase the stale overlay) — is
422
+ // repainted independently and re-composited from scratch.
423
+ present::Rect overlayDirty{};
424
+ for (std::size_t i = 2; i < current.commands.size(); ++i)
425
+ overlayDirty = present::unite(overlayDirty, present::commandBounds(current.commands[i], logicalWidth(), logicalHeight()));
426
+ if (canIncremental)
427
+ for (std::size_t i = 2; i < previousPresentFrame_.commands.size(); ++i)
428
+ overlayDirty = present::unite(overlayDirty, present::commandBounds(previousPresentFrame_.commands[i], logicalWidth(), logicalHeight()));
429
+ overlayDirty = clampLogicalRect(overlayDirty, logicalWidth(), logicalHeight());
430
+
431
+ present::Rect dirty = present::fullScreen(logicalWidth(), logicalHeight());
432
+ if (canIncremental && !needsFullPhysicalFlush_) {
433
+ dirty = present::unite(circleBatchBounds(previousPresentFrame_.commands[1]), circleBatchBounds(circles));
434
+ if (present::valid(overlayDirty)) dirty = present::unite(dirty, overlayDirty);
435
+ dirty = clampLogicalRect(dirty, logicalWidth(), logicalHeight());
436
+ if (!present::valid(dirty)) return true;
437
+ }
438
+
439
+ const std::int64_t started = esp_timer_get_time();
440
+ flushStats_.callCount++;
441
+ const std::int64_t rasterStartUs = esp_timer_get_time();
442
+ if (canIncremental && !needsFullPhysicalFlush_) {
443
+ drawCircleBatchRaw(previousPresentFrame_.commands[1], clear.color, true);
444
+ } else {
445
+ clearFrameBufferRows(0, logicalHeight() - 1, clear.color);
446
+ }
447
+ drawCircleBatchRaw(circles, 0, false);
448
+ // Composite overlays: re-raster their box from the full frame so the old
449
+ // overlay is erased and the new one lands on top of whatever balls sit
450
+ // behind it.
451
+ if (present::valid(overlayDirty)) rasterPresentRegion(current, overlayDirty);
452
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
453
+
454
+ const bool ok = flushNativeLogicalRect(dirty);
455
+ flushStats_.totalUs += esp_timer_get_time() - started;
456
+ return ok;
457
+ }
458
+
459
+ present::Rect circleBatchBounds(const present::Command &command) const
460
+ {
461
+ present::Rect bounds{};
462
+ const auto *circles = command.circleEntries();
463
+ if (!circles || command.circlesCount <= 0) return bounds;
464
+ for (int i = 0; i < command.circlesCount; ++i) {
465
+ bounds = present::unite(bounds,
466
+ present::circleBounds(static_cast<int>(circles[i].x),
467
+ static_cast<int>(circles[i].y),
468
+ command.radius));
469
+ }
470
+ return bounds;
471
+ }
472
+
473
+ void clearFrameBufferRows(int y0, int y1, std::uint16_t color)
474
+ {
475
+ if (!frameBuffer_) return;
476
+ y0 = std::max(0, y0);
477
+ y1 = std::min(logicalHeight() - 1, y1);
478
+ if (y0 > y1) return;
479
+ const int width = logicalWidth();
480
+ const int rows = y1 - y0 + 1;
481
+ std::uint16_t *dst = frameBuffer_ + static_cast<std::size_t>(y0) * logicalStride_;
482
+ if (logicalStride_ == width) {
483
+ const std::size_t pixels = static_cast<std::size_t>(width) * rows;
484
+ if (color == 0) std::memset(dst, 0, pixels * sizeof(std::uint16_t));
485
+ else std::fill_n(dst, pixels, color);
486
+ return;
487
+ }
488
+ for (int y = y0; y <= y1; ++y) {
489
+ std::uint16_t *row = frameBuffer_ + static_cast<std::size_t>(y) * logicalStride_;
490
+ if (color == 0) std::memset(row, 0, static_cast<std::size_t>(width) * sizeof(std::uint16_t));
491
+ else std::fill_n(row, width, color);
492
+ }
493
+ }
494
+
495
+ void drawCircleBatchRaw(const present::Command &command, std::uint16_t overrideColor, bool useOverrideColor)
496
+ {
497
+ if (!frameBuffer_ || command.radius <= 0 || command.circlesCount <= 0) return;
498
+ const auto *circles = command.circleEntries();
499
+ if (!circles) return;
500
+ const int width = logicalWidth();
501
+ const int height = logicalHeight();
502
+ const int r = command.radius;
503
+ for (int i = 0; i < command.circlesCount; ++i) {
504
+ const int cx = static_cast<int>(circles[i].x);
505
+ const int cy = static_cast<int>(circles[i].y);
506
+ const std::uint16_t color = useOverrideColor ? overrideColor : circles[i].color;
507
+ int dy0 = -r;
508
+ int dy1 = r;
509
+ if (cy + dy0 < 0) dy0 = -cy;
510
+ if (cy + dy1 >= height) dy1 = height - 1 - cy;
511
+ if (dy0 > dy1) continue;
512
+ for (int dy = dy0; dy <= dy1; ++dy) {
513
+ const int halfWidth = integerSqrt(r * r - dy * dy);
514
+ int x0 = cx - halfWidth;
515
+ int x1 = cx + halfWidth;
516
+ if (x0 < 0) x0 = 0;
517
+ if (x1 >= width) x1 = width - 1;
518
+ if (x0 > x1) continue;
519
+ std::uint16_t *dst = frameBuffer_ + static_cast<std::size_t>(cy + dy) * logicalStride_ + x0;
520
+ const int count = x1 - x0 + 1;
521
+ if (color == 0) std::memset(dst, 0, static_cast<std::size_t>(count) * sizeof(std::uint16_t));
522
+ else std::fill_n(dst, count, color);
523
+ }
524
+ }
525
+ }
526
+
527
+ void setFlushConfig(int chunkRows, int queueDepth)
528
+ {
529
+ if (chunkRows > 0) flushRows_ = std::min(chunkRows, kFlushRowsDefault);
530
+ if (queueDepth > 0) flushDepth_ = queueDepth;
531
+ }
532
+
533
+ int flushChunkRows() const { return flushRows_; }
534
+ int flushQueueDepth() const { return flushDepth_; }
535
+ int flushBufferBytes() const { return kStagingBytes * kStagingDepth; }
536
+
537
+ bool copySnapshotRgb565(std::uint16_t *dst, int pixelCapacity, int *width, int *height)
538
+ {
539
+ if (!dst || pixelCapacity < logicalWidth() * logicalHeight()) return false;
540
+ if (width) *width = logicalWidth();
541
+ if (height) *height = logicalHeight();
542
+ for (int row = 0; row < logicalHeight(); ++row) {
543
+ std::memcpy(dst + static_cast<std::size_t>(row) * logicalWidth(),
544
+ frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_,
545
+ static_cast<std::size_t>(logicalWidth()) * sizeof(std::uint16_t));
546
+ }
547
+ return true;
548
+ }
549
+
550
+ int countNonBlackPixels() const
551
+ {
552
+ if (!frameBuffer_) return 0;
553
+ int count = 0;
554
+ for (int y = 0; y < logicalHeight(); ++y) {
555
+ const std::uint16_t *row = frameBuffer_ + static_cast<std::size_t>(y) * logicalStride_;
556
+ for (int x = 0; x < logicalWidth(); ++x) {
557
+ if (pixel::toRgb565(row[x]) != 0) ++count;
558
+ }
559
+ }
560
+ return count;
561
+ }
562
+
563
+ void setBrightness(int brightness)
564
+ {
565
+ if (brightness < 0) brightness = 0;
566
+ if (brightness > 100) brightness = 100;
567
+ brightness_ = brightness;
568
+ if (brightnessInitialized_) updateBacklightDuty();
569
+ }
570
+
571
+ int brightness() const { return brightness_; }
572
+
573
+ platform_display::DisplayFlushPerfStats flushStats() const { return flushStats_; }
574
+ void flushStatsReset() { flushStats_ = {}; }
575
+
576
+ const char *flushStageName() const { return "idle"; }
577
+ int flushStageChunk() const { return 0; }
578
+ platform_display::DisplayFlushStageDetail flushStageDetail() const { return {}; }
579
+ std::uint16_t *backgroundCache(int *capPx) { return fullScreenScratch(backgroundCache_, backgroundCacheAttempted_, capPx, "background"); }
580
+ std::uint16_t *backdropCache(int *capPx) { return fullScreenScratch(backdropCache_, backdropCacheAttempted_, capPx, "backdrop"); }
581
+ void setRenderCore(int core)
582
+ {
583
+ renderCoreId_ = core;
584
+ if (frameBuffer_) workerCanvas_.bindPixels(frameBuffer_, logicalWidth(), logicalHeight(), logicalStride_);
585
+ }
586
+
587
+ // Restore the draw canvas to the framebuffer after a caller (e.g. the render
588
+ // layer's retained-snapshot path) temporarily bound it onto another buffer.
589
+ void rebindCanvasToFramebuffer()
590
+ {
591
+ take();
592
+ bindCanvasLocked();
593
+ give();
594
+ }
595
+
596
+ void absorbWorkerDirty()
597
+ {
598
+ int x0 = 0;
599
+ int y0 = 0;
600
+ int x1 = -1;
601
+ int y1 = -1;
602
+ if (workerCanvas_.dirty(&x0, &y0, &x1, &y1)) canvas_.markDirty(x0, y0, x1, y1);
603
+ workerCanvas_.resetDirty();
604
+ }
605
+
606
+ private:
607
+ DisplayBackend() = default;
608
+
609
+ int logicalWidth() const { return orientation_detail::DisplayOrientationState::width(); }
610
+ int logicalHeight() const { return orientation_detail::DisplayOrientationState::height(); }
611
+ bool onWorkerCore() const { return renderCoreId_ >= 0 && xPortGetCoreID() != renderCoreId_; }
612
+ gea::framework::graphics::Canvas &replayCanvas() { return onWorkerCore() ? workerCanvas_ : canvas_; }
613
+
614
+ std::uint16_t *fullScreenScratch(std::uint16_t *&buffer, bool &attempted, int *capPx, const char *label)
615
+ {
616
+ if (!attempted) {
617
+ attempted = true;
618
+ buffer = static_cast<std::uint16_t *>(
619
+ heap_caps_malloc(static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t),
620
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
621
+ if (buffer) {
622
+ ESP_LOGI(kTag, "allocated %s cache %.1f KiB", label, (kMaxPixels * sizeof(std::uint16_t)) / 1024.0);
623
+ } else {
624
+ ESP_LOGW(kTag, "failed to allocate %s cache (%zu bytes)",
625
+ label,
626
+ static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
627
+ }
628
+ }
629
+ if (capPx) *capPx = buffer ? kMaxPixels : 0;
630
+ return buffer;
631
+ }
632
+
633
+ void bindCanvas()
634
+ {
635
+ take();
636
+ bindCanvasLocked();
637
+ give();
638
+ }
639
+
640
+ void bindCanvasLocked()
641
+ {
642
+ const int width = logicalWidth();
643
+ const int height = logicalHeight();
644
+ const int stride = width;
645
+ if (!ownedFrameBuffer_) return;
646
+ if (frameBuffer_ != ownedFrameBuffer_) frameBuffer_ = ownedFrameBuffer_;
647
+ if (canvas_.pixels() == frameBuffer_ && canvas_.width() == width && canvas_.height() == height && logicalStride_ == stride) return;
648
+ logicalStride_ = stride;
649
+ canvas_.bindPixels(frameBuffer_, width, height, logicalStride_);
650
+ workerCanvas_.bindPixels(frameBuffer_, width, height, logicalStride_);
651
+ }
652
+
653
+ bool initBacklight()
654
+ {
655
+ if (brightnessInitialized_) return true;
656
+
657
+ ledc_timer_config_t timerConfig{};
658
+ timerConfig.speed_mode = LEDC_LOW_SPEED_MODE;
659
+ timerConfig.duty_resolution = LEDC_TIMER_10_BIT;
660
+ timerConfig.timer_num = kBacklightLedcTimer;
661
+ timerConfig.freq_hz = 5000;
662
+ timerConfig.clk_cfg = LEDC_AUTO_CLK;
663
+ esp_err_t err = ledc_timer_config(&timerConfig);
664
+ if (err != ESP_OK) {
665
+ ESP_LOGE(kTag, "backlight LEDC timer init failed: %s", esp_err_to_name(err));
666
+ return false;
667
+ }
668
+
669
+ ledc_channel_config_t channelConfig{};
670
+ channelConfig.gpio_num = gea::platform::board::display.backlight;
671
+ channelConfig.speed_mode = LEDC_LOW_SPEED_MODE;
672
+ channelConfig.channel = kBacklightLedcChannel;
673
+ channelConfig.timer_sel = kBacklightLedcTimer;
674
+ channelConfig.duty = 0;
675
+ channelConfig.hpoint = 0;
676
+ err = ledc_channel_config(&channelConfig);
677
+ if (err != ESP_OK) {
678
+ ESP_LOGE(kTag, "backlight LEDC channel init failed: %s", esp_err_to_name(err));
679
+ return false;
680
+ }
681
+
682
+ brightnessInitialized_ = true;
683
+ updateBacklightDuty();
684
+ return true;
685
+ }
686
+
687
+ void updateBacklightDuty()
688
+ {
689
+ const std::uint32_t duty = static_cast<std::uint32_t>((kBacklightLedcMaxDuty * brightness_) / 100);
690
+ const esp_err_t setErr = ledc_set_duty(LEDC_LOW_SPEED_MODE, kBacklightLedcChannel, duty);
691
+ const esp_err_t updateErr = ledc_update_duty(LEDC_LOW_SPEED_MODE, kBacklightLedcChannel);
692
+ if (setErr != ESP_OK || updateErr != ESP_OK) {
693
+ ESP_LOGE(kTag, "backlight duty update failed: set=%s update=%s",
694
+ esp_err_to_name(setErr),
695
+ esp_err_to_name(updateErr));
696
+ }
697
+ }
698
+
699
+ static bool IRAM_ATTR onColorTransDone(esp_lcd_panel_io_handle_t,
700
+ esp_lcd_panel_io_event_data_t *,
701
+ void *userCtx)
702
+ {
703
+ auto *self = static_cast<DisplayBackend *>(userCtx);
704
+ BaseType_t woken = pdFALSE;
705
+ if (self && self->flushDoneSem_) xSemaphoreGiveFromISR(self->flushDoneSem_, &woken);
706
+ return woken == pdTRUE;
707
+ }
708
+
709
+ // The ST7789's gate driver always scans the physical (portrait) lines —
710
+ // MADCTL only remaps GRAM *addressing*, not the refresh scan. Writing
711
+ // landscape full-width bands through a swapped MADCTL would advance
712
+ // PERPENDICULAR to the panel's scan and shear on motion, so landscape
713
+ // orientations keep the panel in PORTRAIT addressing and the flush path
714
+ // rotates each band into scan order instead (flushRotatedLogicalRect);
715
+ // only portrait orientations use MADCTL. The GRAM gap moves with the
716
+ // mirror (the 240x320 GRAM window shifts across the 135x240 glass).
717
+ void applyPanelOrientation()
718
+ {
719
+ if (!panel_) return;
720
+ using gea::framework::display::DisplayOrientation;
721
+ bool mirrorX = false;
722
+ bool mirrorY = false;
723
+ int gapX = kGapPortraitPrimaryX;
724
+ int gapY = kGapPortraitPrimaryY;
725
+ flushRotation_ = kFlushRotationNone;
726
+ switch (orientation_detail::DisplayOrientationState::orientation()) {
727
+ case DisplayOrientation::LandscapePrimary:
728
+ // Portrait addressing + rotate-on-flush:
729
+ // panel x = logical y, panel y = (panelH-1) - logical x.
730
+ flushRotation_ = kFlushRotationLandscapePrimary;
731
+ break;
732
+ case DisplayOrientation::LandscapeSecondary:
733
+ // panel x = (panelW-1) - logical y, panel y = logical x.
734
+ flushRotation_ = kFlushRotationLandscapeSecondary;
735
+ break;
736
+ case DisplayOrientation::PortraitSecondary:
737
+ mirrorX = true;
738
+ mirrorY = true;
739
+ gapX = kGapPortraitSecondaryX;
740
+ gapY = kGapPortraitSecondaryY;
741
+ break;
742
+ case DisplayOrientation::PortraitPrimary:
743
+ default:
744
+ break;
745
+ }
746
+ esp_lcd_panel_swap_xy(panel_, false);
747
+ esp_lcd_panel_mirror(panel_, mirrorX, mirrorY);
748
+ esp_lcd_panel_set_gap(panel_, gapX, gapY);
749
+ }
750
+
751
+ // Drive the M5PM1 PMIC's GPIO2 high — the "L3B" rail that powers the LCD
752
+ // panel + backlight on the StickS3. The exact register sequence is M5GFX's
753
+ // board_M5StickS3 bring-up ("PM1_G2 -- L3B Enable, LCD Power On"): make
754
+ // GPIO2 a push-pull output driven high, then disable the PMIC's I2C idle
755
+ // sleep so it keeps answering. On a cold boot this rail is OFF, so without
756
+ // it the panel and backlight are unpowered and the glass stays dark no
757
+ // matter what the SPI side does (ST7789 never ACKs, so flushes still
758
+ // "succeed"). M5PM1 @ 0x6E, 100 kHz.
759
+ bool powerOnLcdRail()
760
+ {
761
+ constexpr std::uint8_t kAddr = 0x6E;
762
+ constexpr std::uint8_t kGpio2 = 1 << 2;
763
+ auto bus = gea::platform::i2c::Bus::primary();
764
+ if (!bus.available()) {
765
+ ESP_LOGE(kTag, "I2C bus unavailable; cannot power LCD rail");
766
+ return false;
767
+ }
768
+ auto busHandle = static_cast<i2c_master_bus_handle_t>(bus.nativeHandle());
769
+ i2c_device_config_t devCfg = {};
770
+ devCfg.dev_addr_length = I2C_ADDR_BIT_LEN_7;
771
+ devCfg.device_address = kAddr;
772
+ devCfg.scl_speed_hz = 100000;
773
+ i2c_master_dev_handle_t dev = nullptr;
774
+ esp_err_t err = i2c_master_bus_add_device(busHandle, &devCfg, &dev);
775
+ if (err != ESP_OK || !dev) {
776
+ ESP_LOGE(kTag, "M5PM1 add_device failed: %s", esp_err_to_name(err));
777
+ return false;
778
+ }
779
+
780
+ constexpr int kTimeoutMs = 100;
781
+ auto write8 = [&](std::uint8_t reg, std::uint8_t val) {
782
+ const std::uint8_t buf[2] = {reg, val};
783
+ return i2c_master_transmit(dev, buf, sizeof(buf), kTimeoutMs) == ESP_OK;
784
+ };
785
+ auto read8 = [&](std::uint8_t reg, std::uint8_t &val) {
786
+ return i2c_master_transmit_receive(dev, &reg, 1, &val, 1, kTimeoutMs) == ESP_OK;
787
+ };
788
+ auto bitOff = [&](std::uint8_t reg, std::uint8_t mask) {
789
+ std::uint8_t v = 0;
790
+ return read8(reg, v) && write8(reg, static_cast<std::uint8_t>(v & ~mask));
791
+ };
792
+ auto bitOn = [&](std::uint8_t reg, std::uint8_t mask) {
793
+ std::uint8_t v = 0;
794
+ return read8(reg, v) && write8(reg, static_cast<std::uint8_t>(v | mask));
795
+ };
796
+
797
+ bool ok = true;
798
+ ok = bitOff(0x16, kGpio2) && ok; // gpio2 = gpio function (not alternate)
799
+ ok = bitOn(0x10, kGpio2) && ok; // gpio2 = output
800
+ ok = bitOff(0x13, kGpio2) && ok; // gpio2 = push-pull
801
+ ok = bitOn(0x11, kGpio2) && ok; // gpio2 = HIGH -> LCD/backlight rail on
802
+ ok = write8(0x09, 0x00) && ok; // disable PMIC I2C idle sleep
803
+ i2c_master_bus_rm_device(dev);
804
+ if (!ok) {
805
+ ESP_LOGE(kTag, "M5PM1 LCD-rail enable had I2C failures");
806
+ return false;
807
+ }
808
+ // Let the rail settle before resetting/initializing the panel (M5GFX
809
+ // waits 100 ms here too).
810
+ vTaskDelay(pdMS_TO_TICKS(100));
811
+ ESP_LOGI(kTag, "M5PM1 L3B rail enabled (LCD power on)");
812
+ return true;
813
+ }
814
+
815
+ bool initPanel()
816
+ {
817
+ if (panel_) return true;
818
+ // LCD + backlight power rail FIRST — the panel is unpowered until this
819
+ // runs, so backlight PWM and SPI writes are no-ops before it.
820
+ powerOnLcdRail();
821
+ if (!initBacklight()) return false;
822
+
823
+ // Rotating internal-RAM staging bands, allocated FIRST so the ring depth
824
+ // can adapt to how much DMA-capable internal RAM is actually free. Each
825
+ // flush copies a full-width band of the PSRAM framebuffer here, then DMAs
826
+ // it over SPI; with multiple bands the memcpy of the next band runs while
827
+ // the previous one is still on the wire. A connectivity-heavy app
828
+ // (WiFi+BLE+audio) reserves a large slice of internal RAM, leaving too
829
+ // little for the full 4-band ring — rather than kill the panel we degrade
830
+ // to as many bands as fit (min 1). Fewer bands just means less
831
+ // rasterize/DMA overlap (lower peak fps), not a dead display: the right
832
+ // trade for a diagnostics screen.
833
+ stagingDepth_ = 0;
834
+ for (int i = 0; i < kStagingDepth; ++i) {
835
+ stagingPixels_[i] = static_cast<std::uint16_t *>(
836
+ heap_caps_malloc(static_cast<std::size_t>(kStagingBytes), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
837
+ if (!stagingPixels_[i]) break;
838
+ stagingDepth_ = i + 1;
839
+ }
840
+ if (stagingDepth_ == 0) {
841
+ ESP_LOGE(kTag, "display staging band alloc (%d bytes) failed", kStagingBytes);
842
+ return false;
843
+ }
844
+ if (stagingDepth_ < kStagingDepth) {
845
+ ESP_LOGW(kTag, "display staging ring reduced to %d/%d bands (%d bytes each) under RAM pressure",
846
+ stagingDepth_, kStagingDepth, kStagingBytes);
847
+ }
848
+
849
+ // DMA-completion handshake for the push task (one transfer on the wire at
850
+ // a time), plus the staging ring's producer/consumer semaphores sized to
851
+ // the actual band count.
852
+ flushDoneSem_ = xSemaphoreCreateBinary();
853
+ slotFree_ = xSemaphoreCreateCounting(stagingDepth_, stagingDepth_);
854
+ slotReady_ = xSemaphoreCreateCounting(stagingDepth_, 0);
855
+ if (!flushDoneSem_ || !slotFree_ || !slotReady_) {
856
+ ESP_LOGE(kTag, "failed to allocate flush semaphores");
857
+ return false;
858
+ }
859
+
860
+ spi_bus_config_t busConfig = {};
861
+ busConfig.mosi_io_num = gea::platform::board::display.mosi;
862
+ busConfig.miso_io_num = GPIO_NUM_NC;
863
+ busConfig.sclk_io_num = gea::platform::board::display.sclk;
864
+ busConfig.quadwp_io_num = GPIO_NUM_NC;
865
+ busConfig.quadhd_io_num = GPIO_NUM_NC;
866
+ busConfig.max_transfer_sz = kStagingBytes;
867
+ esp_err_t err = spi_bus_initialize(gea::platform::board::display.spiHost, &busConfig, SPI_DMA_CH_AUTO);
868
+ if (err != ESP_OK) {
869
+ ESP_LOGE(kTag, "SPI bus init failed: %s", esp_err_to_name(err));
870
+ return false;
871
+ }
872
+
873
+ esp_lcd_panel_io_spi_config_t ioConfig = {};
874
+ ioConfig.cs_gpio_num = gea::platform::board::display.cs;
875
+ ioConfig.dc_gpio_num = gea::platform::board::display.dc;
876
+ ioConfig.spi_mode = 0;
877
+ ioConfig.pclk_hz = kSpiPclkHz;
878
+ ioConfig.trans_queue_depth = kSpiTransQueueDepth;
879
+ ioConfig.lcd_cmd_bits = 8;
880
+ ioConfig.lcd_param_bits = 8;
881
+ ioConfig.on_color_trans_done = &DisplayBackend::onColorTransDone;
882
+ ioConfig.user_ctx = this;
883
+ err = esp_lcd_new_panel_io_spi(
884
+ static_cast<esp_lcd_spi_bus_handle_t>(gea::platform::board::display.spiHost), &ioConfig, &io_);
885
+ if (err != ESP_OK) {
886
+ ESP_LOGE(kTag, "SPI panel IO init failed: %s", esp_err_to_name(err));
887
+ return false;
888
+ }
889
+
890
+ esp_lcd_panel_dev_config_t panelConfig = {};
891
+ panelConfig.reset_gpio_num = gea::platform::board::display.reset;
892
+ panelConfig.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
893
+ panelConfig.bits_per_pixel = kPanelBitsPerPixel;
894
+ err = esp_lcd_new_panel_st7789(io_, &panelConfig, &panel_);
895
+ if (err != ESP_OK) {
896
+ ESP_LOGE(kTag, "ST7789 panel create failed: %s", esp_err_to_name(err));
897
+ return false;
898
+ }
899
+ err = esp_lcd_panel_reset(panel_);
900
+ if (err != ESP_OK) {
901
+ ESP_LOGE(kTag, "panel reset failed: %s", esp_err_to_name(err));
902
+ return false;
903
+ }
904
+ err = esp_lcd_panel_init(panel_);
905
+ if (err != ESP_OK) {
906
+ ESP_LOGE(kTag, "panel init failed: %s", esp_err_to_name(err));
907
+ return false;
908
+ }
909
+ // The StickS3 glass runs color-inverted (M5GFX: invert = true).
910
+ esp_lcd_panel_invert_color(panel_, true);
911
+ applyPanelOrientation();
912
+ err = esp_lcd_panel_disp_on_off(panel_, true);
913
+ if (err != ESP_OK) {
914
+ ESP_LOGE(kTag, "panel on failed: %s", esp_err_to_name(err));
915
+ return false;
916
+ }
917
+ // Panel push worker on the core opposite the app frame task (core 0);
918
+ // created after panel init so bring-up commands never interleave with
919
+ // a queued band.
920
+ if (xTaskCreatePinnedToCore(&DisplayBackend::panelPushTaskEntry, "panel_push", 4096, this, 5, &pushTask_, 1) != pdPASS) {
921
+ ESP_LOGE(kTag, "failed to start panel push task");
922
+ return false;
923
+ }
924
+ ESP_LOGI(kTag,
925
+ "ST7789 SPI panel ready %dx%d host=%d pclk=%dMHz mode=0 cs=%d dc=%d rst=%d bl=%d gap=(%d,%d)",
926
+ kNativeWidth, kNativeHeight,
927
+ static_cast<int>(gea::platform::board::display.spiHost),
928
+ kSpiPclkHz / 1000000,
929
+ static_cast<int>(gea::platform::board::display.cs),
930
+ static_cast<int>(gea::platform::board::display.dc),
931
+ static_cast<int>(gea::platform::board::display.reset),
932
+ static_cast<int>(gea::platform::board::display.backlight),
933
+ kGapPortraitPrimaryX, kGapPortraitPrimaryY);
934
+ return true;
935
+ }
936
+
937
+ // Panel-push worker. esp_lcd serializes each draw_bitmap's CASET/RASET
938
+ // command writes against the previous chunk's queued color DMA (polling
939
+ // transactions drain the queue), so pushing from the frame loop eats the
940
+ // full wire time no matter how deep the transaction queue is. Instead the
941
+ // flush paths only memcpy bands into the staging ring and hand them to
942
+ // this task (same pattern as the P4 backend's async panel push); the wire
943
+ // waits happen here, on the other core, under the next frame's
944
+ // rasterization. Backpressure = the slotFree_ counting semaphore: when the
945
+ // renderer outruns the panel it blocks on a free band, capping the frame
946
+ // rate at the wire rate instead of adding to it.
947
+ static void panelPushTaskEntry(void *arg)
948
+ {
949
+ auto *self = static_cast<DisplayBackend *>(arg);
950
+ for (;;) {
951
+ xSemaphoreTake(self->slotReady_, portMAX_DELAY);
952
+ const int slot = self->pushConsumeIdx_;
953
+ self->pushConsumeIdx_ = (slot + 1) % self->stagingDepth_;
954
+ const PushSlot &job = self->pushSlots_[slot];
955
+ const std::int64_t txStartUs = esp_timer_get_time();
956
+ const esp_err_t err = esp_lcd_panel_draw_bitmap(
957
+ self->panel_, job.x0, job.y0, job.x1, job.y1, self->stagingPixels_[slot]);
958
+ if (err == ESP_OK) {
959
+ if (self->flushDoneSem_) xSemaphoreTake(self->flushDoneSem_, portMAX_DELAY);
960
+ } else {
961
+ ESP_LOGE(kTag, "push draw_bitmap failed: %s", esp_err_to_name(err));
962
+ }
963
+ self->flushStats_.txUs += esp_timer_get_time() - txStartUs;
964
+ xSemaphoreGive(self->slotFree_);
965
+ }
966
+ }
967
+
968
+ // Grab a free staging band (blocking on the panel when the renderer is
969
+ // ahead), fill it via `fill`, record the panel-coords rect, and queue it
970
+ // for the push task. draw_bitmap end coordinates are exclusive.
971
+ template <typename Fill>
972
+ void submitBand(int panelX0, int panelY0, int panelX1, int panelY1, int pixels, Fill fill)
973
+ {
974
+ xSemaphoreTake(slotFree_, portMAX_DELAY);
975
+ const std::int64_t copyStartUs = esp_timer_get_time();
976
+ fill(stagingPixels_[stagingSlot_]);
977
+ flushStats_.byteSwapUs += esp_timer_get_time() - copyStartUs;
978
+ pushSlots_[stagingSlot_] = PushSlot{panelX0, panelY0, panelX1, panelY1};
979
+ stagingSlot_ = (stagingSlot_ + 1) % stagingDepth_;
980
+ flushStats_.chunkCount++;
981
+ flushStats_.pixelCount += pixels;
982
+ xSemaphoreGive(slotReady_);
983
+ }
984
+
985
+ // Block until every queued band is on the glass. Needed before panel-level
986
+ // commands (MADCTL/gap changes): esp_lcd panel handles are not
987
+ // thread-safe against a concurrent draw_bitmap from the push task.
988
+ void waitPanelPushIdle()
989
+ {
990
+ if (!slotFree_) return;
991
+ while (uxSemaphoreGetCount(slotFree_) < static_cast<UBaseType_t>(stagingDepth_)) {
992
+ vTaskDelay(1);
993
+ }
994
+ }
995
+
996
+ bool flushNativeLogicalRect(present::Rect logicalRect)
997
+ {
998
+ logicalRect = clampLogicalRect(logicalRect, logicalWidth(), logicalHeight());
999
+ if (!present::valid(logicalRect)) return true;
1000
+ if (flushRotation_ != kFlushRotationNone) return flushRotatedLogicalRect(logicalRect);
1001
+
1002
+ take();
1003
+ bindCanvasLocked();
1004
+ if (!panel_ || !frameBuffer_ || !stagingPixels_[0]) {
1005
+ give();
1006
+ return false;
1007
+ }
1008
+
1009
+ // The logical frame maps 1:1 to the panel, so flush full-width bands:
1010
+ // that keeps each band's framebuffer rows contiguous and lets one packed
1011
+ // staging band feed the SPI DMA. The framebuffer is stored panel-endian
1012
+ // (GEA_EMBEDDED_PIXEL_PANEL_ENDIAN=1), so staging is a straight memcpy;
1013
+ // the push task pays the wire time.
1014
+ const int width = logicalWidth();
1015
+ const int y0 = std::max(0, logicalRect.y0);
1016
+ const int y1 = std::min(logicalHeight() - 1, logicalRect.y1);
1017
+ const int maxRows = std::max(1, std::min(flushRows_, kFlushRowsDefault));
1018
+
1019
+ for (int row = y0; row <= y1; row += maxRows) {
1020
+ int rows = maxRows;
1021
+ if (row + rows > y1 + 1) rows = y1 - row + 1;
1022
+ const std::size_t bandPixels = static_cast<std::size_t>(width) * rows;
1023
+ const std::uint16_t *src = frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_;
1024
+ submitBand(0, row, width, row + rows, static_cast<int>(bandPixels), [&](std::uint16_t *dst) {
1025
+ std::memcpy(dst, src, bandPixels * sizeof(std::uint16_t));
1026
+ });
1027
+ }
1028
+ give();
1029
+ return true;
1030
+ }
1031
+
1032
+ // Landscape flush onto the portrait-addressed panel: rotate each band into
1033
+ // the panel's scan order so the GRAM write front advances WITH the gate
1034
+ // scan. A logical rect {x0..x1, y0..y1} maps to the panel rect
1035
+ // {px: y0..y1, py: panelH-1-x1 .. panelH-1-x0} (LandscapePrimary) or
1036
+ // {px: panelW-1-y1 .. panelW-1-y0, py: x0..x1} (LandscapeSecondary).
1037
+ bool flushRotatedLogicalRect(const present::Rect &logicalRect)
1038
+ {
1039
+ take();
1040
+ bindCanvasLocked();
1041
+ if (!panel_ || !frameBuffer_ || !stagingPixels_[0]) {
1042
+ give();
1043
+ return false;
1044
+ }
1045
+
1046
+ const bool primary = flushRotation_ == kFlushRotationLandscapePrimary;
1047
+ const int panelH = kNativeHeight; // 240 physical scan lines
1048
+ const int panelW = kNativeWidth; // 135 pixels per scan line
1049
+ const int x0 = logicalRect.x0, x1 = logicalRect.x1;
1050
+ const int y0 = logicalRect.y0, y1 = logicalRect.y1;
1051
+
1052
+ const int px0 = primary ? y0 : panelW - 1 - y1;
1053
+ const int px1 = primary ? y1 : panelW - 1 - y0;
1054
+ const int py0 = primary ? panelH - 1 - x1 : x0;
1055
+ const int py1 = primary ? panelH - 1 - x0 : x1;
1056
+ const int bandW = px1 - px0 + 1;
1057
+ const int maxRows = std::max(1, std::min(flushRows_, kFlushRowsDefault));
1058
+
1059
+ for (int row = py0; row <= py1; row += maxRows) {
1060
+ int rows = maxRows;
1061
+ if (row + rows > py1 + 1) rows = py1 - row + 1;
1062
+ submitBand(px0, row, px1 + 1, row + rows, bandW * rows, [&](std::uint16_t *staging) {
1063
+ // Panel-endian framebuffer: the rotate is a plain strided copy.
1064
+ for (int ly = y0; ly <= y1; ++ly) {
1065
+ const std::uint16_t *srcRow = frameBuffer_ + static_cast<std::size_t>(ly) * logicalStride_;
1066
+ const int cx = primary ? ly - y0 : y1 - ly; // column inside the staging band
1067
+ std::uint16_t *dst = staging + cx;
1068
+ for (int r = row; r < row + rows; ++r) {
1069
+ const int lx = primary ? panelH - 1 - r : r;
1070
+ dst[static_cast<std::size_t>(r - row) * bandW] = srcRow[lx];
1071
+ }
1072
+ }
1073
+ });
1074
+ }
1075
+ give();
1076
+ return true;
1077
+ }
1078
+
1079
+ void rasterPresentRegion(const present::Frame &frame, const present::Rect &region)
1080
+ {
1081
+ if (!present::valid(region)) return;
1082
+ const int width = region.x1 - region.x0 + 1;
1083
+ const int height = logicalHeight();
1084
+ const int maxRows = std::max(1, kFlushRowsDefault);
1085
+ for (int row = region.y0; row <= region.y1; row += maxRows) {
1086
+ int rows = maxRows;
1087
+ if (row + rows > region.y1 + 1) rows = region.y1 - row + 1;
1088
+ std::uint16_t *rasterTarget = frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_ + region.x0;
1089
+ const std::int64_t rasterStartUs = esp_timer_get_time();
1090
+ present::rasterFrameRowsStrided(rasterTarget,
1091
+ logicalStride_,
1092
+ region.x0,
1093
+ width,
1094
+ row,
1095
+ rows,
1096
+ height,
1097
+ frame);
1098
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
1099
+ }
1100
+ }
1101
+
1102
+ void take()
1103
+ {
1104
+ if (mutex_) xSemaphoreTake(mutex_, portMAX_DELAY);
1105
+ }
1106
+
1107
+ void give()
1108
+ {
1109
+ if (mutex_) xSemaphoreGive(mutex_);
1110
+ }
1111
+
1112
+ SemaphoreHandle_t mutex_ = nullptr;
1113
+ esp_lcd_panel_handle_t panel_ = nullptr;
1114
+ esp_lcd_panel_io_handle_t io_ = nullptr;
1115
+ SemaphoreHandle_t flushDoneSem_ = nullptr;
1116
+ std::uint16_t *frameBuffer_ = nullptr;
1117
+ std::uint16_t *ownedFrameBuffer_ = nullptr;
1118
+ std::uint16_t *stagingPixels_[kStagingDepth] = {};
1119
+ std::uint16_t *backgroundCache_ = nullptr;
1120
+ std::uint16_t *backdropCache_ = nullptr;
1121
+ gea::framework::graphics::Canvas canvas_;
1122
+ gea::framework::graphics::Canvas workerCanvas_;
1123
+ int logicalStride_ = kMaxLogicalWidth;
1124
+ int renderCoreId_ = -1;
1125
+ int flushRows_ = kFlushRowsDefault;
1126
+ // Staging ring producer/consumer state (see panelPushTaskEntry/submitBand).
1127
+ struct PushSlot {
1128
+ int x0, y0, x1, y1; // panel coords; x1/y1 exclusive (draw_bitmap API)
1129
+ };
1130
+ PushSlot pushSlots_[kStagingDepth] = {};
1131
+ SemaphoreHandle_t slotFree_ = nullptr;
1132
+ SemaphoreHandle_t slotReady_ = nullptr;
1133
+ TaskHandle_t pushTask_ = nullptr;
1134
+ int stagingSlot_ = 0;
1135
+ int pushConsumeIdx_ = 0;
1136
+ // Number of staging bands actually allocated (<= kStagingDepth); set in
1137
+ // initPanel, which degrades the ring under internal-RAM pressure.
1138
+ int stagingDepth_ = kStagingDepth;
1139
+ // Landscape-on-portrait-panel flush rotation (see applyPanelOrientation).
1140
+ int flushRotation_ = kFlushRotationNone;
1141
+ int flushDepth_ = kStagingDepth;
1142
+ int brightness_ = 100;
1143
+ bool brightnessInitialized_ = false;
1144
+ bool initialized_ = false;
1145
+ bool backgroundCacheAttempted_ = false;
1146
+ bool backdropCacheAttempted_ = false;
1147
+ platform_display::DisplayFlushPerfStats flushStats_{};
1148
+ present::Frame previousPresentFrame_{};
1149
+ bool previousPresentValid_ = false;
1150
+ bool needsFullPhysicalFlush_ = true;
1151
+ };
1152
+
1153
+ } // namespace gea::platform::esp32_s3_sticks3::display
1154
+
1155
+ extern "C" std::uint16_t *gea_bg_cache(int *cap_px)
1156
+ {
1157
+ return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().backgroundCache(cap_px);
1158
+ }
1159
+
1160
+ extern "C" std::uint16_t *gea_backdrop_cache(int *cap_px)
1161
+ {
1162
+ return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().backdropCache(cap_px);
1163
+ }
1164
+
1165
+ namespace {
1166
+
1167
+ struct RenderWorker {
1168
+ TaskHandle_t task = nullptr;
1169
+ void (*volatile fn)(void *, int, int) = nullptr;
1170
+ void *volatile ctx = nullptr;
1171
+ volatile int y0 = 0;
1172
+ volatile int y1 = 0;
1173
+ std::atomic<std::uint32_t> jobSeq{0};
1174
+ std::atomic<bool> done{true};
1175
+ bool attempted = false;
1176
+ };
1177
+
1178
+ RenderWorker gRenderWorker;
1179
+ volatile std::int64_t gRenderWorkerSubmitUs = 0;
1180
+ std::int64_t gRenderWorkerStartLatencyUs = 0;
1181
+ std::int64_t gRenderWorkerBandUs = 0;
1182
+ std::int64_t gRenderWorkerWaitUs = 0;
1183
+ int gRenderWorkerJobs = 0;
1184
+ constexpr std::uint32_t kRenderWorkerStackBytes = 12288;
1185
+
1186
+ void renderWorkerTask(void *)
1187
+ {
1188
+ // MUST start at 0 (jobSeq's initial value), NOT jobSeq.load(): submit()
1189
+ // creates this task and increments jobSeq immediately after, so loading
1190
+ // here usually reads 1 and swallows job 1. Same race fixed on the elecrow
1191
+ // in d22bcf5f9.
1192
+ std::uint32_t seen = 0;
1193
+ std::int64_t idleSince = esp_timer_get_time();
1194
+ for (;;) {
1195
+ while (gRenderWorker.jobSeq.load(std::memory_order_acquire) == seen) {
1196
+ if (esp_timer_get_time() - idleSince > 4000) {
1197
+ ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100));
1198
+ idleSince = esp_timer_get_time();
1199
+ }
1200
+ }
1201
+ seen = gRenderWorker.jobSeq.load(std::memory_order_acquire);
1202
+ const std::int64_t started = esp_timer_get_time();
1203
+ gRenderWorkerStartLatencyUs += started - gRenderWorkerSubmitUs;
1204
+ void (*fn)(void *, int, int) = gRenderWorker.fn;
1205
+ if (fn) fn(gRenderWorker.ctx, gRenderWorker.y0, gRenderWorker.y1);
1206
+ gRenderWorkerBandUs += esp_timer_get_time() - started;
1207
+ gRenderWorker.done.store(true, std::memory_order_release);
1208
+ idleSince = esp_timer_get_time();
1209
+ }
1210
+ }
1211
+
1212
+ } // namespace
1213
+
1214
+ extern "C" bool gea_render_parallel_submit(void (*fn)(void *, int, int), void *ctx, int y0, int y1)
1215
+ {
1216
+ if (!gRenderWorker.attempted) {
1217
+ gRenderWorker.attempted = true;
1218
+ const BaseType_t renderCore = xPortGetCoreID();
1219
+ const BaseType_t workerCore = (renderCore == 0) ? 1 : 0;
1220
+ const UBaseType_t priority = uxTaskPriorityGet(nullptr);
1221
+ const BaseType_t created = xTaskCreatePinnedToCore(renderWorkerTask,
1222
+ "gea_rwrk",
1223
+ kRenderWorkerStackBytes,
1224
+ nullptr,
1225
+ priority,
1226
+ &gRenderWorker.task,
1227
+ workerCore);
1228
+ std::printf("[render-worker] task=%p create=%d renderCore=%d workerCore=%d prio=%u stack=%u\n",
1229
+ static_cast<void *>(gRenderWorker.task),
1230
+ static_cast<int>(created),
1231
+ static_cast<int>(renderCore),
1232
+ static_cast<int>(workerCore),
1233
+ static_cast<unsigned>(priority),
1234
+ static_cast<unsigned>(kRenderWorkerStackBytes));
1235
+ if (created != pdPASS || !gRenderWorker.task) {
1236
+ multi_heap_info_t info{};
1237
+ heap_caps_get_info(&info, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
1238
+ std::printf("[render-worker] create failed: create=%d stack=%u internal_free=%u internal_largest=%u\n",
1239
+ static_cast<int>(created),
1240
+ static_cast<unsigned>(kRenderWorkerStackBytes),
1241
+ static_cast<unsigned>(info.total_free_bytes),
1242
+ static_cast<unsigned>(info.largest_free_block));
1243
+ }
1244
+ }
1245
+ if (!gRenderWorker.task) return false;
1246
+ gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().setRenderCore(static_cast<int>(xPortGetCoreID()));
1247
+ gRenderWorker.fn = fn;
1248
+ gRenderWorker.ctx = ctx;
1249
+ gRenderWorker.y0 = y0;
1250
+ gRenderWorker.y1 = y1;
1251
+ gRenderWorker.done.store(false, std::memory_order_release);
1252
+ gRenderWorkerSubmitUs = esp_timer_get_time();
1253
+ gRenderWorker.jobSeq.fetch_add(1, std::memory_order_release);
1254
+ xTaskNotifyGive(gRenderWorker.task);
1255
+ return true;
1256
+ }
1257
+
1258
+ extern "C" void gea_render_parallel_wait()
1259
+ {
1260
+ if (!gRenderWorker.task) return;
1261
+ const std::int64_t waitStarted = esp_timer_get_time();
1262
+ const std::int64_t deadline = waitStarted + 100000;
1263
+ while (!gRenderWorker.done.load(std::memory_order_acquire)) {
1264
+ if (esp_timer_get_time() > deadline) {
1265
+ std::printf("[render-worker] WAIT TIMEOUT\n");
1266
+ break;
1267
+ }
1268
+ }
1269
+ gRenderWorkerWaitUs += esp_timer_get_time() - waitStarted;
1270
+ if (++gRenderWorkerJobs >= 300) {
1271
+ std::printf("[worker] startLat=%dus band=%dus wait=%dus (avg/300)\n",
1272
+ static_cast<int>(gRenderWorkerStartLatencyUs / 300),
1273
+ static_cast<int>(gRenderWorkerBandUs / 300),
1274
+ static_cast<int>(gRenderWorkerWaitUs / 300));
1275
+ gRenderWorkerStartLatencyUs = 0;
1276
+ gRenderWorkerBandUs = 0;
1277
+ gRenderWorkerWaitUs = 0;
1278
+ gRenderWorkerJobs = 0;
1279
+ }
1280
+ }
1281
+
1282
+ extern "C" void gea_render_parallel_merge_dirty()
1283
+ {
1284
+ gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().absorbWorkerDirty();
1285
+ }
1286
+
1287
+ extern "C" int gea_current_render_core()
1288
+ {
1289
+ return static_cast<int>(xPortGetCoreID());
1290
+ }
1291
+
1292
+ namespace gea::platform::display {
1293
+
1294
+ namespace {
1295
+
1296
+ gea::framework::graphics::Canvas *drawingCanvas()
1297
+ {
1298
+ return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().drawingCanvas();
1299
+ }
1300
+
1301
+ } // namespace
1302
+
1303
+ bool Display::init() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().init(); }
1304
+ bool Display::start() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().start(); }
1305
+ gea::framework::graphics::Canvas *Display::canvas() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().canvas(); }
1306
+ bool Display::framebufferIsPanelDirect() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().framebufferIsPanelDirect(); }
1307
+ void Display::clear() { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().clear(); }
1308
+ void Display::clearNoFlush() { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().clearNoFlush(); }
1309
+ void Display::print(const char *) {}
1310
+ void Display::flush() { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flush(); }
1311
+ void Display::flushRects(const DisplayFlushRect *rects, int count, bool) { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushRects(rects, count); }
1312
+ // Fused rasterized flush is not implemented on this backend: raster into the
1313
+ // framebuffer region band-by-band, then push those bands (functionally
1314
+ // equivalent, keeps the framebuffer coherent).
1315
+ void Display::flushRectsRasterized(const DisplayFlushRect *rects, int count, DisplayStreamRasterFn raster, void *user, bool)
1316
+ {
1317
+ if (!rects || count <= 0 || !raster) return;
1318
+ for (int i = 0; i < count; ++i) {
1319
+ const auto &r = rects[i];
1320
+ gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().streamRect(
1321
+ r.x0, r.y0, r.x1 - r.x0 + 1, r.y1 - r.y0 + 1, raster, user);
1322
+ }
1323
+ }
1324
+ void Display::rebindCanvasToFramebuffer() { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().rebindCanvasToFramebuffer(); }
1325
+ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user) { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().streamRect(x, y, w, h, raster, user); }
1326
+ bool Display::present(const DisplayPresentCommand *commands, int command_count) { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().presentCommands(commands, command_count); }
1327
+ void Display::setFlushConfig(int chunk_rows, int queue_depth) { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().setFlushConfig(chunk_rows, queue_depth); }
1328
+ void Display::reserveInternal(std::size_t) {}
1329
+ bool Display::setHighBrightnessMode(bool) { return false; }
1330
+ bool Display::highBrightnessMode() { return false; }
1331
+ void Display::applyPendingInternalReserve() {}
1332
+ int Display::flushChunkRows() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushChunkRows(); }
1333
+ int Display::flushQueueDepth() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushQueueDepth(); }
1334
+ int Display::flushBufferBytes() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushBufferBytes(); }
1335
+ void Display::pushClip(int x, int y, int w, int h) { if (auto *c = drawingCanvas()) c->pushClip(x, y, w, h); }
1336
+ void Display::popClip() { if (auto *c = drawingCanvas()) c->popClip(); }
1337
+ void Display::resetClip() { if (auto *c = drawingCanvas()) c->resetClip(); }
1338
+ void Display::setAlpha(std::uint8_t alpha) { if (auto *c = drawingCanvas()) c->setGlobalAlpha(alpha); }
1339
+ std::uint8_t Display::alpha() { return drawingCanvas() ? drawingCanvas()->globalAlpha() : 255; }
1340
+ int Display::brightness() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().brightness(); }
1341
+ void Display::setBrightness(int brightness_percent) { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().setBrightness(brightness_percent); }
1342
+ // Tearing sync (TE/VBlank): not implemented on this target.
1343
+ void Display::setVSync(bool) {}
1344
+ void Display::invalidate() {}
1345
+ bool Display::vsyncEnabled() { return false; }
1346
+ void Display::vsyncWaitForFrame() {}
1347
+ void Display::clip(int *x0, int *y0, int *x1, int *y1)
1348
+ {
1349
+ if (auto *c = drawingCanvas()) c->currentClip(x0, y0, x1, y1);
1350
+ }
1351
+ void Display::fillRect(int x, int y, int w, int h, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, w, h, color); }
1352
+ void Display::scrollRect(int x, int y, int w, int h, int dx, int dy) { if (auto *c = drawingCanvas()) c->scrollRect(x, y, w, h, dx, dy); }
1353
+ void Display::resetScrollRegion() {}
1354
+ void Display::strokeRect(int x, int y, int w, int h, std::uint16_t color) { if (auto *c = drawingCanvas()) c->strokeRect(x, y, w, h, color); }
1355
+ void Display::fillCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillCircle(cx, cy, r, color); }
1356
+ void Display::strokeCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->strokeCircle(cx, cy, r, color); }
1357
+ void Display::drawLine(int x0, int y0, int x1, int y1, std::uint16_t color) { if (auto *c = drawingCanvas()) c->drawLine(x0, y0, x1, y1, color); }
1358
+ void Display::drawArc(int cx, int cy, int r, int start_deg, int end_deg, std::uint16_t color) { if (auto *c = drawingCanvas()) c->drawArc(cx, cy, r, start_deg, end_deg, color); }
1359
+ void Display::fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillTriangle(x0, y0, x1, y1, x2, y2, color); }
1360
+ void Display::drawText(const char *text, int x, int y, std::uint16_t color, float scale) { if (auto *c = drawingCanvas()) c->drawText(text, x, y, color, scale); }
1361
+ void Display::drawTextFont(const char *text, int x, int y, std::uint16_t color, int font_id) { if (auto *c = drawingCanvas()) c->drawTextFont(text, x, y, color, font_id); }
1362
+ void Display::drawTextFontFamily(const char *text, int x, int y, std::uint16_t color, int family_id, int size_px) { if (auto *c = drawingCanvas()) c->drawTextFontFamily(text, x, y, color, family_id, size_px); }
1363
+ void Display::setPixel(int x, int y, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, 1, 1, color); }
1364
+ void Display::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillRoundedRect(x, y, w, h, tl, tr, br, bl, color); }
1365
+ void Display::fillRoundedRectBoxesRgb565(const std::int16_t *xs, const std::int16_t *ys, int count, int w, int h, int tl, int tr, int br, int bl, const std::uint16_t *colors) { if (auto *c = drawingCanvas()) c->fillRoundedRectBoxesRgb565(xs, ys, count, w, h, tl, tr, br, bl, colors); }
1366
+ void Display::strokeRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, int lw, std::uint16_t color) { if (auto *c = drawingCanvas()) c->strokeRoundedRect(x, y, w, h, tl, tr, br, bl, lw, color); }
1367
+ void Display::blitImage(const gea::framework::graphics::pixel::native_t *src, const std::uint8_t *alpha, int src_w, int src_h, int dx, int dy) { if (auto *c = drawingCanvas()) c->drawImage(src, alpha, src_w, src_h, dx, dy); }
1368
+ void Display::blitImageScaled(const gea::framework::graphics::pixel::native_t *src, const std::uint8_t *alpha, int src_w, int src_h, int dx, int dy, int dst_w, int dst_h) { if (auto *c = drawingCanvas()) c->drawImage(src, alpha, src_w, src_h, dx, dy, dst_w, dst_h); }
1369
+ void Display::setWorldOverlay(const std::uint16_t *, int, int, int, int) {}
1370
+ void Display::setWorldScroll(int) {}
1371
+ void Display::flushStatsRead(std::int64_t *total_us, int *call_count, int *pixel_count)
1372
+ {
1373
+ const auto stats = gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStats();
1374
+ if (total_us) *total_us = stats.totalUs;
1375
+ if (call_count) *call_count = stats.callCount;
1376
+ if (pixel_count) *pixel_count = stats.pixelCount;
1377
+ }
1378
+ DisplayFlushPerfStats Display::flushPerfStatsRead() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStats(); }
1379
+ void Display::flushStatsReset() { gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStatsReset(); }
1380
+ const char *Display::flushStageName() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStageName(); }
1381
+ int Display::flushStageChunk() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStageChunk(); }
1382
+ DisplayFlushStageDetail Display::flushStageDetail() { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().flushStageDetail(); }
1383
+ bool Display::copySnapshotRgb565(std::uint16_t *dst, int pixel_capacity, int *width, int *height, bool) { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().copySnapshotRgb565(dst, pixel_capacity, width, height); }
1384
+ int Display::countNonBlackPixels(bool) { return gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().countNonBlackPixels(); }
1385
+
1386
+ void applyOrientation(gea::framework::display::DisplayOrientation)
1387
+ {
1388
+ gea::platform::esp32_s3_sticks3::display::DisplayBackend::instance().applyOrientation();
1389
+ }
1390
+
1391
+ } // namespace gea::platform::display