@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,2832 @@
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 "pixel.h"
8
+
9
+ #include <algorithm>
10
+ #include <atomic>
11
+ #include <cstddef>
12
+ #include <cstdint>
13
+ #include <cstring>
14
+ #include <new>
15
+ #include <utility>
16
+
17
+ #include "driver/ledc.h"
18
+ #include "driver/ppa.h"
19
+ #include "esp_cache.h"
20
+ #include "esp_err.h"
21
+ #include "esp_heap_caps.h"
22
+ #include "esp_lcd_ili9881c.h"
23
+ #include "esp_lcd_mipi_dsi.h"
24
+ #include "esp_lcd_panel_io.h"
25
+ #include "esp_async_memcpy.h"
26
+ #include "esp_lcd_panel_ops.h"
27
+ #include "esp_ldo_regulator.h"
28
+ #include "esp_log.h"
29
+ #include "esp_timer.h"
30
+ #include "freertos/FreeRTOS.h"
31
+ #include "freertos/semphr.h"
32
+ #include "freertos/task.h"
33
+
34
+ namespace platform_display = gea::platform::display;
35
+ namespace orientation_detail = gea::framework::display::detail;
36
+ namespace pixel = gea::framework::graphics::pixel;
37
+ namespace present = gea::framework::display_present;
38
+
39
+ namespace gea::platform::esp32_p4_waveshare::display {
40
+
41
+ namespace {
42
+
43
+ constexpr const char *kTag = "waveshare_p4_display";
44
+ constexpr int kNativeWidth = platform_display::kNativeWidth;
45
+ constexpr int kNativeHeight = platform_display::kNativeHeight;
46
+ constexpr int kMaxLogicalWidth = kNativeHeight > kNativeWidth ? kNativeHeight : kNativeWidth;
47
+ constexpr int kMaxLogicalHeight = kNativeHeight;
48
+ constexpr int kMaxPixels = kNativeWidth * kNativeHeight;
49
+ constexpr int kFlushRowsDefault = 64;
50
+ constexpr int kDsiLaneCount = 2;
51
+ constexpr float kDsiLaneBitrateMbps = 1000.0f;
52
+ constexpr float kDpiClockMhz = 80.0f;
53
+ constexpr pixel::Format kFramebufferPixelFormat = pixel::Format::Rgb565;
54
+ constexpr pixel::Format kDsiOutputPixelFormat = pixel::Format::Rgb565;
55
+ constexpr int kPanelBitsPerPixel = pixel::bitsPerPixel(kDsiOutputPixelFormat);
56
+ // Two DPI scanout framebuffers: a full-screen producer (the camera) can write the
57
+ // non-scanned (back) buffer and flip it in at vblank — tear-free — instead of writing
58
+ // the live buffer mid-scan. The UI / windowed modes keep using whichever buffer is
59
+ // currently scanned (single-buffer), so only a full-screen direct producer pays for
60
+ // the second buffer's PSRAM.
61
+ constexpr int kDpiFrameBufferCount = 2;
62
+ constexpr int kDsiPhyLdoChannel = 3;
63
+ constexpr int kDsiPhyLdoVoltageMv = 2500;
64
+ constexpr ledc_channel_t kBacklightLedcChannel = LEDC_CHANNEL_1;
65
+ constexpr ledc_timer_t kBacklightLedcTimer = LEDC_TIMER_1;
66
+ constexpr int kBacklightLedcMaxDuty = 1023;
67
+ constexpr int kMaxPresentRects = 16;
68
+ constexpr int kOwnedFrameBufferPixels = kMaxPixels;
69
+
70
+ struct PanelCoord {
71
+ int x = 0;
72
+ int y = 0;
73
+ };
74
+
75
+ struct PanelInitCommand {
76
+ int cmd = 0;
77
+ std::uint8_t data[3] = {};
78
+ std::size_t dataBytes = 0;
79
+ unsigned int delayMs = 0;
80
+ };
81
+
82
+ constexpr lcd_color_format_t lcdColorFormat(pixel::Format format)
83
+ {
84
+ switch (format) {
85
+ case pixel::Format::Rgb565:
86
+ return LCD_COLOR_FMT_RGB565;
87
+ case pixel::Format::Rgb888:
88
+ return LCD_COLOR_FMT_RGB888;
89
+ case pixel::Format::Rgba8888:
90
+ break;
91
+ }
92
+ return LCD_COLOR_FMT_RGB565;
93
+ }
94
+
95
+ static constexpr PanelInitCommand kWaveshareIli9881cInitCommands[] = {
96
+ {0xFF, {0x98, 0x81, 0x03}, 3, 0},
97
+ {0x01, {0x00}, 1, 0},
98
+ {0x02, {0x00}, 1, 0},
99
+ {0x03, {0x73}, 1, 0},
100
+ {0x04, {0x00}, 1, 0},
101
+ {0x05, {0x00}, 1, 0},
102
+ {0x06, {0x0A}, 1, 0},
103
+ {0x07, {0x00}, 1, 0},
104
+ {0x08, {0x00}, 1, 0},
105
+ {0x09, {0x61}, 1, 0},
106
+ {0x0A, {0x00}, 1, 0},
107
+ {0x0B, {0x00}, 1, 0},
108
+ {0x0C, {0x01}, 1, 0},
109
+ {0x0D, {0x00}, 1, 0},
110
+ {0x0E, {0x00}, 1, 0},
111
+ {0x0F, {0x61}, 1, 0},
112
+ {0x10, {0x61}, 1, 0},
113
+ {0x11, {0x00}, 1, 0},
114
+ {0x12, {0x00}, 1, 0},
115
+ {0x13, {0x00}, 1, 0},
116
+ {0x14, {0x00}, 1, 0},
117
+ {0x15, {0x00}, 1, 0},
118
+ {0x16, {0x00}, 1, 0},
119
+ {0x17, {0x00}, 1, 0},
120
+ {0x18, {0x00}, 1, 0},
121
+ {0x19, {0x00}, 1, 0},
122
+ {0x1A, {0x00}, 1, 0},
123
+ {0x1B, {0x00}, 1, 0},
124
+ {0x1C, {0x00}, 1, 0},
125
+ {0x1D, {0x00}, 1, 0},
126
+ {0x1E, {0x40}, 1, 0},
127
+ {0x1F, {0x80}, 1, 0},
128
+ {0x20, {0x06}, 1, 0},
129
+ {0x21, {0x01}, 1, 0},
130
+ {0x22, {0x00}, 1, 0},
131
+ {0x23, {0x00}, 1, 0},
132
+ {0x24, {0x00}, 1, 0},
133
+ {0x25, {0x00}, 1, 0},
134
+ {0x26, {0x00}, 1, 0},
135
+ {0x27, {0x00}, 1, 0},
136
+ {0x28, {0x33}, 1, 0},
137
+ {0x29, {0x03}, 1, 0},
138
+ {0x2A, {0x00}, 1, 0},
139
+ {0x2B, {0x00}, 1, 0},
140
+ {0x2C, {0x00}, 1, 0},
141
+ {0x2D, {0x00}, 1, 0},
142
+ {0x2E, {0x00}, 1, 0},
143
+ {0x2F, {0x00}, 1, 0},
144
+ {0x30, {0x00}, 1, 0},
145
+ {0x31, {0x00}, 1, 0},
146
+ {0x32, {0x00}, 1, 0},
147
+ {0x33, {0x00}, 1, 0},
148
+ {0x34, {0x04}, 1, 0},
149
+ {0x35, {0x00}, 1, 0},
150
+ {0x36, {0x00}, 1, 0},
151
+ {0x37, {0x00}, 1, 0},
152
+ {0x38, {0x3C}, 1, 0},
153
+ {0x39, {0x00}, 1, 0},
154
+ {0x3A, {0x00}, 1, 0},
155
+ {0x3B, {0x00}, 1, 0},
156
+ {0x3C, {0x00}, 1, 0},
157
+ {0x3D, {0x00}, 1, 0},
158
+ {0x3E, {0x00}, 1, 0},
159
+ {0x3F, {0x00}, 1, 0},
160
+ {0x40, {0x00}, 1, 0},
161
+ {0x41, {0x00}, 1, 0},
162
+ {0x42, {0x00}, 1, 0},
163
+ {0x43, {0x00}, 1, 0},
164
+ {0x44, {0x00}, 1, 0},
165
+ {0x50, {0x10}, 1, 0},
166
+ {0x51, {0x32}, 1, 0},
167
+ {0x52, {0x54}, 1, 0},
168
+ {0x53, {0x76}, 1, 0},
169
+ {0x54, {0x98}, 1, 0},
170
+ {0x55, {0xBA}, 1, 0},
171
+ {0x56, {0x10}, 1, 0},
172
+ {0x57, {0x32}, 1, 0},
173
+ {0x58, {0x54}, 1, 0},
174
+ {0x59, {0x76}, 1, 0},
175
+ {0x5A, {0x98}, 1, 0},
176
+ {0x5B, {0xBA}, 1, 0},
177
+ {0x5C, {0xDC}, 1, 0},
178
+ {0x5D, {0xFE}, 1, 0},
179
+ {0x5E, {0x00}, 1, 0},
180
+ {0x5F, {0x0E}, 1, 0},
181
+ {0x60, {0x0F}, 1, 0},
182
+ {0x61, {0x0C}, 1, 0},
183
+ {0x62, {0x0D}, 1, 0},
184
+ {0x63, {0x06}, 1, 0},
185
+ {0x64, {0x07}, 1, 0},
186
+ {0x65, {0x02}, 1, 0},
187
+ {0x66, {0x02}, 1, 0},
188
+ {0x67, {0x02}, 1, 0},
189
+ {0x68, {0x02}, 1, 0},
190
+ {0x69, {0x01}, 1, 0},
191
+ {0x6A, {0x00}, 1, 0},
192
+ {0x6B, {0x02}, 1, 0},
193
+ {0x6C, {0x15}, 1, 0},
194
+ {0x6D, {0x14}, 1, 0},
195
+ {0x6E, {0x02}, 1, 0},
196
+ {0x6F, {0x02}, 1, 0},
197
+ {0x70, {0x02}, 1, 0},
198
+ {0x71, {0x02}, 1, 0},
199
+ {0x72, {0x02}, 1, 0},
200
+ {0x73, {0x02}, 1, 0},
201
+ {0x74, {0x02}, 1, 0},
202
+ {0x75, {0x0E}, 1, 0},
203
+ {0x76, {0x0F}, 1, 0},
204
+ {0x77, {0x0C}, 1, 0},
205
+ {0x78, {0x0D}, 1, 0},
206
+ {0x79, {0x06}, 1, 0},
207
+ {0x7A, {0x07}, 1, 0},
208
+ {0x7B, {0x02}, 1, 0},
209
+ {0x7C, {0x02}, 1, 0},
210
+ {0x7D, {0x02}, 1, 0},
211
+ {0x7E, {0x02}, 1, 0},
212
+ {0x7F, {0x01}, 1, 0},
213
+ {0x80, {0x00}, 1, 0},
214
+ {0x81, {0x02}, 1, 0},
215
+ {0x82, {0x14}, 1, 0},
216
+ {0x83, {0x15}, 1, 0},
217
+ {0x84, {0x02}, 1, 0},
218
+ {0x85, {0x02}, 1, 0},
219
+ {0x86, {0x02}, 1, 0},
220
+ {0x87, {0x02}, 1, 0},
221
+ {0x88, {0x02}, 1, 0},
222
+ {0x89, {0x02}, 1, 0},
223
+ {0x8A, {0x02}, 1, 0},
224
+ {0xFF, {0x98, 0x81, 0x04}, 3, 0},
225
+ {0x38, {0x01}, 1, 0},
226
+ {0x39, {0x00}, 1, 0},
227
+ {0x6C, {0x15}, 1, 0},
228
+ {0x6E, {0x2A}, 1, 0},
229
+ {0x6F, {0x33}, 1, 0},
230
+ {0x3A, {0x94}, 1, 0},
231
+ {0x8D, {0x14}, 1, 0},
232
+ {0x87, {0xBA}, 1, 0},
233
+ {0x26, {0x76}, 1, 0},
234
+ {0xB2, {0xD1}, 1, 0},
235
+ {0xB5, {0x06}, 1, 0},
236
+ {0x3B, {0x98}, 1, 0},
237
+ {0xFF, {0x98, 0x81, 0x01}, 3, 0},
238
+ {0x22, {0x0A}, 1, 0},
239
+ {0x31, {0x00}, 1, 0},
240
+ {0x53, {0x71}, 1, 0},
241
+ {0x55, {0x8F}, 1, 0},
242
+ {0x40, {0x33}, 1, 0},
243
+ {0x50, {0x96}, 1, 0},
244
+ {0x51, {0x96}, 1, 0},
245
+ {0x60, {0x23}, 1, 0},
246
+ {0xA0, {0x08}, 1, 0},
247
+ {0xA1, {0x1D}, 1, 0},
248
+ {0xA2, {0x2A}, 1, 0},
249
+ {0xA3, {0x10}, 1, 0},
250
+ {0xA4, {0x15}, 1, 0},
251
+ {0xA5, {0x28}, 1, 0},
252
+ {0xA6, {0x1C}, 1, 0},
253
+ {0xA7, {0x1D}, 1, 0},
254
+ {0xA8, {0x7E}, 1, 0},
255
+ {0xA9, {0x1D}, 1, 0},
256
+ {0xAA, {0x29}, 1, 0},
257
+ {0xAB, {0x6B}, 1, 0},
258
+ {0xAC, {0x1A}, 1, 0},
259
+ {0xAD, {0x18}, 1, 0},
260
+ {0xAE, {0x4B}, 1, 0},
261
+ {0xAF, {0x20}, 1, 0},
262
+ {0xB0, {0x27}, 1, 0},
263
+ {0xB1, {0x50}, 1, 0},
264
+ {0xB2, {0x64}, 1, 0},
265
+ {0xB3, {0x39}, 1, 0},
266
+ {0xC0, {0x08}, 1, 0},
267
+ {0xC1, {0x1D}, 1, 0},
268
+ {0xC2, {0x2A}, 1, 0},
269
+ {0xC3, {0x10}, 1, 0},
270
+ {0xC4, {0x15}, 1, 0},
271
+ {0xC5, {0x28}, 1, 0},
272
+ {0xC6, {0x1C}, 1, 0},
273
+ {0xC7, {0x1D}, 1, 0},
274
+ {0xC8, {0x7E}, 1, 0},
275
+ {0xC9, {0x1D}, 1, 0},
276
+ {0xCA, {0x29}, 1, 0},
277
+ {0xCB, {0x6B}, 1, 0},
278
+ {0xCC, {0x1A}, 1, 0},
279
+ {0xCD, {0x18}, 1, 0},
280
+ {0xCE, {0x4B}, 1, 0},
281
+ {0xCF, {0x20}, 1, 0},
282
+ {0xD0, {0x27}, 1, 0},
283
+ {0xD1, {0x50}, 1, 0},
284
+ {0xD2, {0x64}, 1, 0},
285
+ {0xD3, {0x39}, 1, 0},
286
+ {0xFF, {0x98, 0x81, 0x00}, 3, 0},
287
+ {0x3A, {0x77}, 1, 0},
288
+ {0x36, {0x00}, 1, 0},
289
+ {0x35, {0x00}, 1, 0},
290
+ {0x35, {0x00}, 1, 0},
291
+ {0x11, {0x00}, 0, 150},
292
+ {0x29, {0x00}, 0, 20},
293
+ };
294
+
295
+ constexpr std::size_t kWaveshareIli9881cInitCommandCount =
296
+ sizeof(kWaveshareIli9881cInitCommands) / sizeof(kWaveshareIli9881cInitCommands[0]);
297
+
298
+ const ili9881c_lcd_init_cmd_t *waveshareIli9881cInitCommands(std::uint16_t *count)
299
+ {
300
+ static ili9881c_lcd_init_cmd_t commands[kWaveshareIli9881cInitCommandCount]{};
301
+ static bool initialized = false;
302
+ if (!initialized) {
303
+ for (std::size_t i = 0; i < kWaveshareIli9881cInitCommandCount; ++i) {
304
+ const auto &src = kWaveshareIli9881cInitCommands[i];
305
+ commands[i].cmd = src.cmd;
306
+ commands[i].data = src.dataBytes > 0 ? src.data : nullptr;
307
+ commands[i].data_bytes = src.dataBytes;
308
+ commands[i].delay_ms = src.delayMs;
309
+ }
310
+ initialized = true;
311
+ }
312
+ if (count) *count = static_cast<std::uint16_t>(kWaveshareIli9881cInitCommandCount);
313
+ return commands;
314
+ }
315
+
316
+ esp_lcd_video_timing_t videoTiming()
317
+ {
318
+ esp_lcd_video_timing_t timing{};
319
+ timing.h_size = kNativeWidth;
320
+ timing.v_size = kNativeHeight;
321
+ timing.hsync_pulse_width = 50;
322
+ timing.hsync_back_porch = 239;
323
+ timing.hsync_front_porch = 33;
324
+ timing.vsync_pulse_width = 30;
325
+ timing.vsync_back_porch = 20;
326
+ timing.vsync_front_porch = 2;
327
+ return timing;
328
+ }
329
+
330
+ PanelCoord panelForSourcePixel(int sourceX, int sourceY)
331
+ {
332
+ using gea::framework::display::DisplayOrientation;
333
+ switch (orientation_detail::DisplayOrientationState::orientation()) {
334
+ case DisplayOrientation::PortraitSecondary:
335
+ return {kNativeWidth - 1 - sourceX, kNativeHeight - 1 - sourceY};
336
+ case DisplayOrientation::LandscapePrimary:
337
+ return {sourceY, kNativeHeight - 1 - sourceX};
338
+ case DisplayOrientation::LandscapeSecondary:
339
+ return {kNativeWidth - 1 - sourceY, sourceX};
340
+ case DisplayOrientation::PortraitPrimary:
341
+ default:
342
+ return {sourceX, sourceY};
343
+ }
344
+ }
345
+
346
+ present::Rect clampLogicalRect(present::Rect rect, int width, int height)
347
+ {
348
+ if (width <= 0 || height <= 0) return {};
349
+ rect = present::clampAndAlign(rect, width, height);
350
+ if (!present::valid(rect)) return {};
351
+ return rect;
352
+ }
353
+
354
+ present::Rect physicalBoundsForLogicalRect(const present::Rect &logical)
355
+ {
356
+ if (!present::valid(logical)) return {};
357
+ const PanelCoord corners[] = {
358
+ panelForSourcePixel(logical.x0, logical.y0),
359
+ panelForSourcePixel(logical.x1, logical.y0),
360
+ panelForSourcePixel(logical.x0, logical.y1),
361
+ panelForSourcePixel(logical.x1, logical.y1),
362
+ };
363
+ present::Rect out{corners[0].x, corners[0].y, corners[0].x, corners[0].y};
364
+ for (const PanelCoord &corner : corners) {
365
+ if (corner.x < out.x0) out.x0 = corner.x;
366
+ if (corner.y < out.y0) out.y0 = corner.y;
367
+ if (corner.x > out.x1) out.x1 = corner.x;
368
+ if (corner.y > out.y1) out.y1 = corner.y;
369
+ }
370
+ return present::clampAndAlign(out, kNativeWidth, kNativeHeight);
371
+ }
372
+
373
+ } // namespace
374
+
375
+ class DisplayBackend {
376
+ public:
377
+ static DisplayBackend &instance()
378
+ {
379
+ static DisplayBackend backend;
380
+ return backend;
381
+ }
382
+
383
+ bool init()
384
+ {
385
+ if (initialized_) return true;
386
+ mutex_ = xSemaphoreCreateMutex();
387
+ if (!mutex_) {
388
+ ESP_LOGE(kTag, "failed to allocate display mutex");
389
+ return false;
390
+ }
391
+
392
+ // 128-byte aligned so the PPA can target it as an output picture (the
393
+ // camera's direct-present scales straight into this framebuffer). PPA
394
+ // output to PSRAM requires the buffer base + size aligned to the cache
395
+ // line; round the size up to match.
396
+ {
397
+ const std::size_t fbBytes =
398
+ (static_cast<std::size_t>(kOwnedFrameBufferPixels) * sizeof(std::uint16_t) + 127) & ~static_cast<std::size_t>(127);
399
+ ownedFrameBuffer_ = static_cast<std::uint16_t *>(
400
+ heap_caps_aligned_alloc(128, fbBytes, MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA | MALLOC_CAP_8BIT));
401
+ if (ownedFrameBuffer_) std::memset(ownedFrameBuffer_, 0, fbBytes);
402
+ }
403
+ if (!ownedFrameBuffer_) {
404
+ ESP_LOGE(kTag, "display owned framebuffer alloc failed");
405
+ return false;
406
+ }
407
+
408
+ if (!initPanel()) {
409
+ ESP_LOGE(kTag, "panel init failed");
410
+ return false;
411
+ }
412
+ bindCanvas();
413
+ if (frameBuffer_) {
414
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
415
+ }
416
+ initialized_ = true;
417
+ ESP_LOGI(kTag, "display ready native=%dx%d logical=%dx%d", kNativeWidth, kNativeHeight, logicalWidth(), logicalHeight());
418
+ return true;
419
+ }
420
+
421
+ bool start() { return init(); }
422
+
423
+ gea::framework::graphics::Canvas *canvas()
424
+ {
425
+ if (!frameBuffer_) init();
426
+ return &replayCanvas();
427
+ }
428
+
429
+ // Public accessor: is canvas() the panel scanout buffer (no logical->panel
430
+ // rotation)? Used by the camera direct-present to skip the rotate-flush.
431
+ bool framebufferIsPanelDirect() const { return usingPanelFrameBufferDirectly(); }
432
+
433
+ // The portrait scanout buffer the camera can PPA straight into for its preview
434
+ // rect. Valid whenever the panel framebuffer is the un-rotated portrait scanout
435
+ // (logical coords == panel coords), independent of where the UI composes — so it
436
+ // stays available even though the UI now composes off-screen into ownedFrameBuffer_.
437
+ bool panelScanoutSurface(std::uint16_t **outBuffer, int *outW, int *outH) const
438
+ {
439
+ using gea::framework::display::DisplayOrientation;
440
+ if (!panelFrameBuffer_ ||
441
+ orientation_detail::DisplayOrientationState::orientation() != DisplayOrientation::PortraitPrimary ||
442
+ logicalStride_ != kNativeWidth) {
443
+ return false;
444
+ }
445
+ if (outBuffer) *outBuffer = panelFrameBuffer_;
446
+ if (outW) *outW = kNativeWidth;
447
+ if (outH) *outH = kNativeHeight;
448
+ return true;
449
+ }
450
+
451
+ // One-pass camera→panel target (see Display::panelDirectTarget). The panel scanout
452
+ // buffer always exists, so this works in ANY orientation: the camera composes its own
453
+ // sensor rotation with the orientation's rotation steps and scales+rotates straight
454
+ // into the panel, eliminating the off-screen landscape canvas + second rotate flush.
455
+ bool panelDirectTarget(int logicalX, int logicalY, int logicalW, int logicalH,
456
+ std::uint16_t **outBuf, int *outBufW, int *outBufH,
457
+ int *outPanelX, int *outPanelY, int *outPanelW, int *outPanelH,
458
+ int *outRotSteps, int *outFlip) const
459
+ {
460
+ if (!panelFrameBuffer_) return false;
461
+ present::Rect logical{logicalX, logicalY, logicalX + logicalW - 1, logicalY + logicalH - 1};
462
+ logical = clampLogicalRect(logical, logicalWidth(), logicalHeight());
463
+ if (!present::valid(logical)) return false;
464
+ const present::Rect panel = physicalBoundsForLogicalRect(logical);
465
+ if (!present::valid(panel)) return false;
466
+ const int panelW = panel.x1 - panel.x0 + 1;
467
+ const int panelH = panel.y1 - panel.y0 + 1;
468
+ // Tear-free double-buffer path: only when the producer covers the WHOLE panel
469
+ // (e.g. a full-screen camera) and a second framebuffer exists. Then it writes the
470
+ // non-scanned (back) buffer and flips it in at vblank — nothing it overwrites is
471
+ // being scanned. A sub-rect producer (windowed) can't double-buffer without also
472
+ // carrying the surrounding UI into the back buffer, so it writes the live buffer.
473
+ const bool coversPanel = panel.x0 == 0 && panel.y0 == 0 && panelW == kNativeWidth && panelH == kNativeHeight;
474
+ const bool canFlip = coversPanel && panelFrameBuffers_[1] != nullptr;
475
+ if (outBuf) *outBuf = canFlip ? panelFrameBuffers_[1 - scannedFbIndex_] : panelFrameBuffer_;
476
+ if (outFlip) *outFlip = canFlip ? 1 : 0;
477
+ if (outBufW) *outBufW = kNativeWidth;
478
+ if (outBufH) *outBufH = kNativeHeight;
479
+ if (outPanelX) *outPanelX = panel.x0;
480
+ if (outPanelY) *outPanelY = panel.y0;
481
+ if (outPanelW) *outPanelW = panelW;
482
+ if (outPanelH) *outPanelH = panelH;
483
+ if (outRotSteps) {
484
+ switch (ppaRotationForCurrentOrientation()) {
485
+ case PPA_SRM_ROTATION_ANGLE_90: *outRotSteps = 1; break;
486
+ case PPA_SRM_ROTATION_ANGLE_180: *outRotSteps = 2; break;
487
+ case PPA_SRM_ROTATION_ANGLE_270: *outRotSteps = 3; break;
488
+ default: *outRotSteps = 0; break;
489
+ }
490
+ }
491
+ return true;
492
+ }
493
+
494
+ // Flip the just-written back buffer in at the next vblank (tear-free). The producer
495
+ // PPA-wrote panelFrameBuffers_[1 - scannedFbIndex_] (returned by panelDirectTarget with
496
+ // outFlip=1); draw_bitmap with a pointer inside an internal fb does no copy, it cache-
497
+ // syncs the rows and swaps cur_fb_index, which the DSI DMA picks up at the frame restart.
498
+ void flipPanelToBack()
499
+ {
500
+ if (!panel_ || panelFrameBuffers_[1] == nullptr) return;
501
+ const int back = 1 - scannedFbIndex_;
502
+ esp_lcd_panel_draw_bitmap(panel_, 0, 0, kNativeWidth, kNativeHeight, panelFrameBuffers_[back]);
503
+ scannedFbIndex_ = back;
504
+ panelFrameBuffer_ = panelFrameBuffers_[back]; // UI writes follow the scanned buffer
505
+ }
506
+
507
+ gea::framework::graphics::Canvas *drawingCanvas()
508
+ {
509
+ if (!frameBuffer_) init();
510
+ return &replayCanvas();
511
+ }
512
+
513
+ void applyOrientation()
514
+ {
515
+ take();
516
+ bindCanvasLocked();
517
+ if (!frameBuffer_) {
518
+ give();
519
+ return;
520
+ }
521
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
522
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
523
+ previousPresentValid_ = false;
524
+ needsFullPhysicalFlush_ = true;
525
+ frameBufferCoherent_ = true;
526
+ give();
527
+ ESP_LOGI(kTag, "orientation=%s logical=%dx%d",
528
+ orientation_detail::DisplayOrientationState::orientationString().c_str(),
529
+ logicalWidth(), logicalHeight());
530
+ }
531
+
532
+ void clear()
533
+ {
534
+ clearNoFlush();
535
+ flush();
536
+ }
537
+
538
+ void clearNoFlush()
539
+ {
540
+ if (!frameBuffer_) init();
541
+ take();
542
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
543
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
544
+ previousPresentValid_ = false;
545
+ needsFullPhysicalFlush_ = true;
546
+ frameBufferCoherent_ = true;
547
+ give();
548
+ }
549
+
550
+ // Restore the draw canvas binding to the framebuffer. The engine calls
551
+ // Display::rebindCanvasToFramebuffer() after the fused rasterized-flush path
552
+ // rebinds the canvas onto a chunk buffer; this board has no rasterized flush,
553
+ // so it is idempotent here — but the symbol must exist and rebinding is the
554
+ // correct, safe restore.
555
+ void rebindCanvasToFramebuffer()
556
+ {
557
+ take();
558
+ bindCanvasLocked();
559
+ give();
560
+ }
561
+
562
+ void flush()
563
+ {
564
+ if (!init()) return;
565
+ // While the panel-direct tile path owns the screen (full-frame flips of
566
+ // the scanout back buffer), the composed logical canvas is STALE — a
567
+ // flush here would paint it over the fresh tiles, alternating
568
+ // fresh/stale frames (white flicker while panning). The transition out
569
+ // of panel-direct re-arms a full flush explicitly.
570
+ if (panelDirectActive_) return;
571
+ pathExternalFlush_++;
572
+ const bool fullPhysicalFlush = needsFullPhysicalFlush_;
573
+ if (!fullPhysicalFlush && !canvas_.dirty(nullptr, nullptr, nullptr, nullptr)) return;
574
+ const std::int64_t started = esp_timer_get_time();
575
+ gea::framework::graphics::CanvasDirtyRect dirtyRects[gea::framework::graphics::Canvas::kMaxDirtyRects];
576
+ int dirtyCount = 0;
577
+ if (fullPhysicalFlush) {
578
+ dirtyRects[0] = {0, 0, logicalWidth() - 1, logicalHeight() - 1};
579
+ dirtyCount = 1;
580
+ ESP_LOGI(kTag, "first physical flush covers full logical frame %dx%d", logicalWidth(), logicalHeight());
581
+ } else {
582
+ dirtyCount = canvas_.dirtyRects(dirtyRects, gea::framework::graphics::Canvas::kMaxDirtyRects);
583
+ }
584
+ if (!fullPhysicalFlush && dirtyCount <= 0) {
585
+ int x0 = 0;
586
+ int y0 = 0;
587
+ int x1 = -1;
588
+ int y1 = -1;
589
+ if (canvas_.dirty(&x0, &y0, &x1, &y1)) {
590
+ dirtyRects[0] = {x0, y0, x1, y1};
591
+ dirtyCount = 1;
592
+ }
593
+ }
594
+ bool ok = true;
595
+ flushStats_.callCount++;
596
+ for (int i = 0; i < dirtyCount; ++i) {
597
+ const auto &rect = dirtyRects[i];
598
+ if (!flushNativeLogicalRect({rect.x0, rect.y0, rect.x1, rect.y1})) {
599
+ ok = false;
600
+ break;
601
+ }
602
+ }
603
+ flushStats_.totalUs += esp_timer_get_time() - started;
604
+ if (ok) {
605
+ canvas_.resetDirty();
606
+ if (fullPhysicalFlush) needsFullPhysicalFlush_ = false;
607
+ }
608
+ }
609
+
610
+ void flushRects(const platform_display::DisplayFlushRect *rects, int count)
611
+ {
612
+ if (!rects || count <= 0) return;
613
+ if (!init()) return;
614
+ if (needsFullPhysicalFlush_) {
615
+ const std::int64_t started = esp_timer_get_time();
616
+ flushStats_.callCount++;
617
+ ESP_LOGI(kTag, "first physical flush covers full logical frame %dx%d", logicalWidth(), logicalHeight());
618
+ const bool ok = flushNativeLogicalRect({0, 0, logicalWidth() - 1, logicalHeight() - 1});
619
+ flushStats_.totalUs += esp_timer_get_time() - started;
620
+ if (ok) {
621
+ canvas_.resetDirty();
622
+ needsFullPhysicalFlush_ = false;
623
+ }
624
+ return;
625
+ }
626
+ const std::int64_t started = esp_timer_get_time();
627
+ bool ok = true;
628
+ flushStats_.callCount++;
629
+ for (int i = 0; i < count; ++i) {
630
+ const auto &rect = rects[i];
631
+ if (!flushNativeLogicalRect({rect.x0, rect.y0, rect.x1, rect.y1})) {
632
+ ok = false;
633
+ break;
634
+ }
635
+ }
636
+ flushStats_.totalUs += esp_timer_get_time() - started;
637
+ if (ok) canvas_.resetDirty();
638
+ }
639
+
640
+ bool streamRect(int x, int y, int w, int h, platform_display::DisplayStreamRasterFn raster, void *user)
641
+ {
642
+ if (!raster || w <= 0 || h <= 0) return false;
643
+ if (!init()) return false;
644
+ const int x0 = std::max(0, x);
645
+ const int y0 = std::max(0, y);
646
+ const int x1 = std::min(logicalWidth() - 1, x + w - 1);
647
+ const int y1 = std::min(logicalHeight() - 1, y + h - 1);
648
+ if (x0 > x1 || y0 > y1) return true;
649
+
650
+ const int width = x1 - x0 + 1;
651
+ const int maxRows = std::max(1, kFlushRowsDefault);
652
+ for (int row = y0; row <= y1; row += maxRows) {
653
+ int rows = maxRows;
654
+ if (row + rows > y1 + 1) rows = y1 - row + 1;
655
+ if (x0 == 0 && width == logicalStride_) {
656
+ raster(frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_, width, rows, x0, row, user);
657
+ } else {
658
+ for (int copyRow = 0; copyRow < rows; ++copyRow) {
659
+ raster(frameBuffer_ + static_cast<std::size_t>(row + copyRow) * logicalStride_ + x0,
660
+ width,
661
+ 1,
662
+ x0,
663
+ row + copyRow,
664
+ user);
665
+ }
666
+ }
667
+ }
668
+ canvas_.markDirty(x0, y0, x1, y1);
669
+ frameBufferCoherent_ = true;
670
+ flush();
671
+ return true;
672
+ }
673
+
674
+ bool presentCommands(const platform_display::DisplayPresentCommand *commands, int commandCount)
675
+ {
676
+ if (!commands || commandCount <= 0 || !init()) return false;
677
+ presentCalls_++;
678
+ if (presentCalls_ <= 3 || (presentCalls_ & 31) == 1) {
679
+ ESP_LOGI(kTag, "present paths: total=%d direct=%d general=%d externalFlush=%d rejected=%d",
680
+ presentCalls_, pathDirect_, pathGeneral_, pathExternalFlush_, pathRejected_);
681
+ }
682
+ present::Frame current;
683
+ if (!present::extractFrame(commands, commandCount, current)) {
684
+ pathRejected_++;
685
+ return false;
686
+ }
687
+ if (!present::frameHasOpaqueBase(current, logicalWidth(), logicalHeight())) {
688
+ pathRejected_++;
689
+ return false;
690
+ }
691
+ if (!isFastClearFillCirclesFrame(current) && !frameBufferCoherent_) {
692
+ previousPresentValid_ = false;
693
+ needsFullPhysicalFlush_ = true;
694
+ }
695
+ const bool tileShape = framePpaTileEligible(current);
696
+ if (!tileShape && (scrollOriginX_ != 0 || scrollOriginY_ != 0)) {
697
+ // A non-tile frame can't run on the wrapped surface: linearize by
698
+ // forcing a full rebuild at origin (0,0).
699
+ scrollOriginX_ = 0;
700
+ scrollOriginY_ = 0;
701
+ panelSyncedForTorus_ = false;
702
+ previousPresentValid_ = false;
703
+ needsFullPhysicalFlush_ = true;
704
+ }
705
+ // PANEL-DIRECT TILE PATH: raster the whole tile frame straight into the
706
+ // NON-SCANNED panel buffer and flip it in at vblank. The default present
707
+ // composes into ownedFrameBuffer_ then PPA-copies owned->panel — and that
708
+ // 0-degree full-screen PPA copy measures a constant ~43ms (the PPA moves
709
+ // ~86MB/s against the DSI-scanned PSRAM), capping every present at ~20fps
710
+ // no matter how little was rastered. Direct raster (~15ms with the
711
+ // memcpy/nearest blits) + draw_bitmap's internal row sync (~11ms) + a
712
+ // tear-free flip ≈ 26ms — pan, pinch, and load all land at ~38fps.
713
+ {
714
+ static bool gateLogged = false;
715
+ if (!gateLogged) {
716
+ gateLogged = true;
717
+ ESP_LOGI(kTag, "panel-direct gate: tile=%d fb1=%d orient=%d lw=%d lh=%d nw=%d nh=%d",
718
+ tileShape ? 1 : 0, panelFrameBuffers_[1] != nullptr ? 1 : 0,
719
+ static_cast<int>(orientation_detail::DisplayOrientationState::orientation()),
720
+ logicalWidth(), logicalHeight(), kNativeWidth, kNativeHeight);
721
+ }
722
+ }
723
+ if (tileShape && panelFrameBuffers_[1] != nullptr &&
724
+ orientation_detail::DisplayOrientationState::orientation() ==
725
+ gea::framework::display::DisplayOrientation::PortraitPrimary &&
726
+ logicalWidth() == kNativeWidth && logicalHeight() == kNativeHeight) {
727
+ scrollOriginX_ = 0;
728
+ scrollOriginY_ = 0;
729
+ panelSyncedForTorus_ = false;
730
+ const std::int64_t started = esp_timer_get_time();
731
+ flushStats_.callCount++;
732
+ // Scan alignment: the previous flip latches at the next frame restart.
733
+ // If it was recent, wait for one refresh boundary before writing the
734
+ // buffer it released — otherwise the base fill paints the LIVE frame
735
+ // (white flashes while panning).
736
+ if (refreshDoneSem_ && lastFlipUs_ != 0 && esp_timer_get_time() - lastFlipUs_ < 20000) {
737
+ xSemaphoreTake(refreshDoneSem_, pdMS_TO_TICKS(40));
738
+ }
739
+ std::uint16_t *back = panelFrameBuffers_[1 - scannedFbIndex_];
740
+ const int height = logicalHeight();
741
+ const int width = logicalWidth();
742
+ const int maxRows = std::max(1, kFlushRowsDefault);
743
+ for (int row = 0; row < height; row += maxRows) {
744
+ int rows = maxRows;
745
+ if (row + rows > height) rows = height - row;
746
+ // Occlusion: when the band is fully covered by opaque tile blits,
747
+ // skip the base fill (command 0) — at ~100MB/s PSRAM bandwidth the
748
+ // fill's 1.8MB of throwaway writes per frame cost ~12ms alone.
749
+ std::size_t firstCommand = 0;
750
+ {
751
+ // Interval-union over x of commands spanning ALL of this band.
752
+ int covered = 0;
753
+ int spans[16][2];
754
+ int spanCount = 0;
755
+ for (std::size_t i = 1; i < current.commands.size() && spanCount < 16; ++i) {
756
+ const present::Command &c = current.commands[i];
757
+ const present::Rect b = present::commandBounds(c, width, height);
758
+ if (!present::valid(b) || b.y0 > row || b.y1 < row + rows - 1) continue;
759
+ spans[spanCount][0] = std::max(0, b.x0);
760
+ spans[spanCount][1] = std::min(width - 1, b.x1);
761
+ spanCount++;
762
+ }
763
+ // Sort the few spans by start (insertion sort) and union them.
764
+ for (int a = 1; a < spanCount; ++a) {
765
+ for (int b2 = a; b2 > 0 && spans[b2][0] < spans[b2 - 1][0]; --b2) {
766
+ std::swap(spans[b2][0], spans[b2 - 1][0]);
767
+ std::swap(spans[b2][1], spans[b2 - 1][1]);
768
+ }
769
+ }
770
+ int reach = 0;
771
+ for (int a = 0; a < spanCount; ++a) {
772
+ if (spans[a][0] > reach) break;
773
+ if (spans[a][1] + 1 > reach) reach = spans[a][1] + 1;
774
+ }
775
+ covered = reach >= width ? 1 : 0;
776
+ if (covered) firstCommand = 1;
777
+ }
778
+ std::uint16_t *target = back + static_cast<std::size_t>(row) * kNativeWidth;
779
+ const std::int64_t rasterStartUs = esp_timer_get_time();
780
+ gea::framework::graphics::Canvas bandCanvas;
781
+ bandCanvas.bindPixels(target, kNativeWidth, rows, kNativeWidth);
782
+ for (std::size_t i = firstCommand; i < current.commands.size(); ++i) {
783
+ const present::Command &cmd = current.commands[i];
784
+ // Band pre-skip: without it every command rasters against every
785
+ // 64-row chunk — ~25 sidebar text commands x 20 chunks walked
786
+ // glyph loops 500x per frame (+110ms measured).
787
+ if (cmd.type != gea::platform::display::DisplayPresentCommandType::Clear) {
788
+ const present::Rect bounds = present::commandBounds(cmd, width, height);
789
+ if (!present::valid(bounds) || bounds.y1 < row || bounds.y0 > row + rows - 1) continue;
790
+ }
791
+ present::rasterCommandRows(bandCanvas, target, 0, kNativeWidth, row, rows, height, cmd);
792
+ }
793
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
794
+ }
795
+ take();
796
+ const std::int64_t flipStartUs = esp_timer_get_time();
797
+ // Drain a stale refresh grant so the post-flip wait (next frame's
798
+ // pre-raster) observes a boundary that happened AFTER this flip.
799
+ if (refreshDoneSem_) xSemaphoreTake(refreshDoneSem_, 0);
800
+ flipPanelToBack();
801
+ lastFlipUs_ = esp_timer_get_time();
802
+ flushStats_.copyUs += lastFlipUs_ - flipStartUs;
803
+ give();
804
+ flushStats_.totalUs += esp_timer_get_time() - started;
805
+ flushStats_.chunkCount++;
806
+ flushStats_.pixelCount += logicalWidth() * height;
807
+ static int directHits = 0;
808
+ directHits++;
809
+ pathDirect_++;
810
+ if ((directHits & 15) == 1) {
811
+ ESP_LOGI(kTag, "panel-direct tile frame #%d total=%lldus", directHits,
812
+ static_cast<long long>(esp_timer_get_time() - started));
813
+ }
814
+ // Mark the mode: the composed (owned) framebuffer is now STALE. The
815
+ // canvas flush is suppressed while active; the transition out
816
+ // re-arms a full composed repaint.
817
+ panelDirectActive_ = true;
818
+ previousPresentValid_ = false;
819
+ frameBufferCoherent_ = false;
820
+ canvas_.resetDirty();
821
+ return true;
822
+ }
823
+ // LANDSCAPE PANEL-NATIVE PRESENT: the panel is portrait-native and the
824
+ // PPA's 90-degree rotation costs ~150ms/frame (measured) — no pipelining
825
+ // can hide that. Instead, tiles are PRE-ROTATED once at decode (worker
826
+ // core), every command's geometry is transformed into panel space, and
827
+ // the frame rasters DIRECTLY into the portrait back scanout buffer like
828
+ // the portrait panel-direct path. Sidebar text draws via the rotated
829
+ // glyph blitter in a full-buffer pass.
830
+ {
831
+ using gea::framework::display::DisplayOrientation;
832
+ const DisplayOrientation orient = orientation_detail::DisplayOrientationState::orientation();
833
+ const bool landscape = orient == DisplayOrientation::LandscapePrimary;
834
+ {
835
+ static bool landGateLogged = false;
836
+ if (!landGateLogged && landscape) {
837
+ landGateLogged = true;
838
+ ESP_LOGI(kTag, "landscape gate: tile=%d fb1=%d lw=%d lh=%d nW=%d nH=%d",
839
+ tileShape ? 1 : 0, panelFrameBuffers_[1] != nullptr ? 1 : 0, logicalWidth(), logicalHeight(),
840
+ kNativeWidth, kNativeHeight);
841
+ }
842
+ }
843
+ if (tileShape && landscape && panelFrameBuffers_[1] != nullptr &&
844
+ logicalWidth() == kNativeHeight && logicalHeight() == kNativeWidth) {
845
+ scrollOriginX_ = 0;
846
+ scrollOriginY_ = 0;
847
+ panelSyncedForTorus_ = false;
848
+ const std::int64_t started = esp_timer_get_time();
849
+ flushStats_.callCount++;
850
+ // Transform geometry to panel space IN PLACE (landscape-primary:
851
+ // panel = {srcY, kNativeHeight - 1 - srcX}); FillText keeps its
852
+ // landscape anchor for the rotated text pass.
853
+ using Type = gea::platform::display::DisplayPresentCommandType;
854
+ for (present::Command &cmd : current.commands) {
855
+ if (cmd.type == Type::Clear || cmd.type == Type::FillText) continue;
856
+ const int lx = cmd.x;
857
+ const int ly = cmd.y;
858
+ const int lw2 = cmd.w;
859
+ const int lh2 = cmd.h;
860
+ cmd.x = ly;
861
+ cmd.y = kNativeHeight - lx - lw2;
862
+ cmd.w = lh2;
863
+ cmd.h = lw2;
864
+ if (cmd.type == Type::DrawImage || cmd.type == Type::DrawImageScaled) {
865
+ const int sw = cmd.srcWidth;
866
+ cmd.srcWidth = cmd.srcHeight;
867
+ cmd.srcHeight = sw;
868
+ }
869
+ }
870
+ // Scan alignment (same as the portrait path).
871
+ {
872
+ const std::int64_t alignStart = esp_timer_get_time();
873
+ if (refreshDoneSem_ && lastFlipUs_ != 0 && esp_timer_get_time() - lastFlipUs_ < 20000) {
874
+ xSemaphoreTake(refreshDoneSem_, pdMS_TO_TICKS(40));
875
+ }
876
+ landAlignUs_ = static_cast<int>(esp_timer_get_time() - alignStart);
877
+ }
878
+ std::uint16_t *back = panelFrameBuffers_[1 - scannedFbIndex_];
879
+ std::uint16_t *front = panelFrameBuffers_[scannedFbIndex_];
880
+ const int height = kNativeHeight;
881
+ const int width = kNativeWidth;
882
+ // PAN FAST PATH: when every image command moved by ONE common
883
+ // translation since the previous frame, copy the overlap from the
884
+ // front buffer (frame N-1) and raster only the exposed strips and
885
+ // the moved small rects (pins/labels). A full-screen re-raster is
886
+ // ~40ms; the copy is ~15ms for the map region.
887
+ // DISABLED pending debugging: v1 had a copy-direction defect that
888
+ // wiped tiles and pathological dirty-raster cost (212-378ms). The
889
+ // full raster below is correct at ~76ms.
890
+ constexpr bool kPanFastPathEnabled = true;
891
+ bool panMode = false;
892
+ int pdx = 0, pdy = 0;
893
+ present::Rect dirtyRects[64];
894
+ int dirtyCount = 0;
895
+ const std::int64_t panDetectStart = esp_timer_get_time();
896
+ const int backIndex = 1 - scannedFbIndex_;
897
+ const std::uint32_t railHash = railContentHash(current, kNativeWidth, kNativeHeight);
898
+ if (kPanFastPathEnabled && !landPrevValid_[backIndex]) {
899
+ panBailReason_ = 1;
900
+ panBailCounts_[1]++;
901
+ }
902
+ if (kPanFastPathEnabled && landPrevValid_[backIndex]) {
903
+ bool haveDelta = false;
904
+ bool consistent = true;
905
+ int imgPairs = 0;
906
+ for (const present::Command &cmd : current.commands) {
907
+ if (cmd.type != Type::DrawImage && cmd.type != Type::DrawImageScaled) continue;
908
+ for (int j = 0; j < landPrevCount_[backIndex]; ++j) {
909
+ const LandPrevCmd &prev = landPrev_[backIndex][j];
910
+ if (prev.pixels != cmd.pixels || prev.type != static_cast<std::int16_t>(cmd.type)) continue;
911
+ // Same image at a different scale (fallback ancestors swap
912
+ // span levels while tiles stream): not a translation pair —
913
+ // the dirty phase repaints it — but no reason to bail.
914
+ if (prev.w != cmd.w || prev.h != cmd.h) break;
915
+ const int dx = cmd.x - prev.x;
916
+ const int dy = cmd.y - prev.y;
917
+ if (!haveDelta) { pdx = dx; pdy = dy; haveDelta = true; }
918
+ else if (dx != pdx || dy != pdy) consistent = false;
919
+ imgPairs++;
920
+ break;
921
+ }
922
+ if (!consistent) break;
923
+ }
924
+ panMode = haveDelta && consistent && imgPairs >= 4 &&
925
+ railHash == landPrevRailHash_[backIndex] &&
926
+ pdx > -440 && pdx < 440 && pdy > -440 && pdy < 440;
927
+ if (!panMode) {
928
+ int reason = 2;
929
+ if (!haveDelta) reason = 2;
930
+ else if (!consistent) reason = 3;
931
+ else if (imgPairs < 4) reason = 4;
932
+ else reason = 5;
933
+ panBailReason_ = reason;
934
+ panBailCounts_[reason]++;
935
+ }
936
+ if (panMode) {
937
+ // Small-rect dirties: previous + current fills/text in the map
938
+ // region (pins, labels) so movers repaint and ghosts clear.
939
+ auto addDirty = [&](present::Rect r) {
940
+ // Each fresh tile is ~1.3ms of honest raster; only bail to a
941
+ // full re-raster when the dirty set rivals the whole screen.
942
+ if (dirtyCount >= 60) { panMode = false; panBailReason_ = 6; panBailCounts_[6]++; return; }
943
+ if (!present::valid(r)) return;
944
+ dirtyRects[dirtyCount++] = r;
945
+ };
946
+ for (int j = 0; j < landPrevCount_[backIndex] && panMode; ++j) {
947
+ const LandPrevCmd &prev = landPrev_[backIndex][j];
948
+ if (prev.pixels) continue;
949
+ addDirty(present::Rect{prev.x, prev.y, prev.x + prev.w - 1, prev.y + prev.h - 1});
950
+ }
951
+ for (std::size_t ci = 0; ci < current.commands.size(); ++ci) {
952
+ const present::Command &cmd = current.commands[ci];
953
+ if (!panMode) break;
954
+ if (ci == 0) continue; // base fill participates in strip rasters only
955
+ if (cmd.type == Type::Clear) continue;
956
+ if (cmd.type == Type::DrawImage || cmd.type == Type::DrawImageScaled) {
957
+ // A draw is clean only when its previous instance moved by
958
+ // exactly the pan delta at the same scale; everything else
959
+ // (fresh tile, rescaled ancestor) repaints, including the
960
+ // previous footprint so stale pixels clear.
961
+ bool clean = false;
962
+ for (int j = 0; j < landPrevCount_[backIndex]; ++j) {
963
+ const LandPrevCmd &prev = landPrev_[backIndex][j];
964
+ if (prev.pixels != cmd.pixels) continue;
965
+ if (prev.w == cmd.w && prev.h == cmd.h &&
966
+ cmd.x - prev.x == pdx && cmd.y - prev.y == pdy) {
967
+ clean = true;
968
+ } else {
969
+ addDirty(present::Rect{prev.x, prev.y, prev.x + prev.w - 1, prev.y + prev.h - 1});
970
+ }
971
+ break;
972
+ }
973
+ if (!clean) addDirty(present::commandBounds(cmd, width, height));
974
+ continue;
975
+ }
976
+ if (cmd.type == Type::FillText) {
977
+ // Rail text only; rail rows aren't copied or touched in
978
+ // pan mode, so nothing to do.
979
+ continue;
980
+ }
981
+ const present::Rect b = present::commandBounds(cmd, width, height);
982
+ // Rail-region fills (panel rows >= kRailPanelRow) stay put.
983
+ if (b.y0 >= kRailPanelRow) continue;
984
+ addDirty(b);
985
+ }
986
+ }
987
+ }
988
+ panDetectUs_ = static_cast<int>(esp_timer_get_time() - panDetectStart);
989
+ if (panMode) {
990
+ // NO COPY: the back buffer already holds this buffer's previous
991
+ // frame (N-2); the strips below cover the N-2 -> N exposure.
992
+ panKickUs_ = 0;
993
+ // Exposed strips (disjoint from the copied block) raster while
994
+ // the DMA streams; interior rects wait for completion below.
995
+ present::Rect stripRects[4];
996
+ int stripCount = 0;
997
+ if (pdy > 0) stripRects[stripCount++] = present::Rect{0, 0, width - 1, pdy - 1};
998
+ if (pdy < 0) stripRects[stripCount++] = present::Rect{0, kRailPanelRow + pdy, width - 1, kRailPanelRow - 1};
999
+ if (pdx > 0) stripRects[stripCount++] = present::Rect{0, 0, pdx - 1, kRailPanelRow - 1};
1000
+ if (pdx < 0) stripRects[stripCount++] = present::Rect{width + pdx, 0, width - 1, kRailPanelRow - 1};
1001
+ const std::int64_t rasterStartUs = esp_timer_get_time();
1002
+ for (int sIdx = 0; sIdx < stripCount; ++sIdx) {
1003
+ present::Rect rect = stripRects[sIdx];
1004
+ if (rect.y0 < 0) rect.y0 = 0;
1005
+ if (rect.x0 < 0) rect.x0 = 0;
1006
+ if (rect.y1 >= kRailPanelRow) rect.y1 = kRailPanelRow - 1;
1007
+ if (rect.x1 >= width) rect.x1 = width - 1;
1008
+ if (!present::valid(rect)) continue;
1009
+ const int rows = rect.y1 - rect.y0 + 1;
1010
+ std::uint16_t *target = back + static_cast<std::size_t>(rect.y0) * width;
1011
+ gea::framework::graphics::Canvas bandCanvas;
1012
+ bandCanvas.bindPixels(target, width, rows, width);
1013
+ bandCanvas.pushClip(rect.x0, 0, rect.x1 - rect.x0 + 1, rows);
1014
+ for (std::size_t i = 0; i < current.commands.size(); ++i) {
1015
+ const present::Command &cmd = current.commands[i];
1016
+ if (cmd.type == Type::FillText) continue;
1017
+ if (cmd.type != Type::Clear) {
1018
+ const present::Rect bounds = present::commandBounds(cmd, width, height);
1019
+ if (!present::valid(bounds) || bounds.y1 < rect.y0 || bounds.y0 > rect.y1 ||
1020
+ bounds.x1 < rect.x0 || bounds.x0 > rect.x1) continue;
1021
+ }
1022
+ present::rasterCommandRows(bandCanvas, target, 0, width, rect.y0, rows, height, cmd);
1023
+ }
1024
+ bandCanvas.resetClip();
1025
+ }
1026
+ panStripUs_ = static_cast<int>(esp_timer_get_time() - rasterStartUs);
1027
+ panWaitUs_ = 0;
1028
+ const std::int64_t panInteriorStart = esp_timer_get_time();
1029
+ // Interior dirty rects (pins, fresh tiles) over the copied area.
1030
+ for (int d = 0; d < dirtyCount; ++d) {
1031
+ present::Rect rect = dirtyRects[d];
1032
+ if (rect.y0 < 0) rect.y0 = 0;
1033
+ if (rect.x0 < 0) rect.x0 = 0;
1034
+ if (rect.y1 >= kRailPanelRow) rect.y1 = kRailPanelRow - 1;
1035
+ if (rect.x1 >= width) rect.x1 = width - 1;
1036
+ if (!present::valid(rect)) continue;
1037
+ const int rows = rect.y1 - rect.y0 + 1;
1038
+ std::uint16_t *target = back + static_cast<std::size_t>(rect.y0) * width;
1039
+ gea::framework::graphics::Canvas bandCanvas;
1040
+ bandCanvas.bindPixels(target, width, rows, width);
1041
+ bandCanvas.pushClip(rect.x0, 0, rect.x1 - rect.x0 + 1, rows);
1042
+ for (std::size_t i = 0; i < current.commands.size(); ++i) {
1043
+ const present::Command &cmd = current.commands[i];
1044
+ if (cmd.type == Type::FillText) continue;
1045
+ if (cmd.type != Type::Clear) {
1046
+ const present::Rect bounds = present::commandBounds(cmd, width, height);
1047
+ if (!present::valid(bounds) || bounds.y1 < rect.y0 || bounds.y0 > rect.y1 ||
1048
+ bounds.x1 < rect.x0 || bounds.x0 > rect.x1) continue;
1049
+ }
1050
+ present::rasterCommandRows(bandCanvas, target, 0, width, rect.y0, rows, height, cmd);
1051
+ }
1052
+ bandCanvas.resetClip();
1053
+ }
1054
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
1055
+ panInteriorUs_ = static_cast<int>(esp_timer_get_time() - panInteriorStart);
1056
+ }
1057
+ // Snapshot this frame's commands into THIS buffer's slot for the
1058
+ // next time it becomes the back buffer (two frames from now).
1059
+ landPrevCount_[backIndex] = 0;
1060
+ landPrevValid_[backIndex] = false;
1061
+ bool snapshotOverflow = false;
1062
+ for (std::size_t ci = 0; ci < current.commands.size(); ++ci) {
1063
+ const present::Command &cmd = current.commands[ci];
1064
+ if (landPrevCount_[backIndex] >= kLandPrevMax) { snapshotOverflow = true; break; }
1065
+ if (ci == 0) continue; // base fill: never a dirty source
1066
+ if (cmd.type == Type::Clear || cmd.type == Type::FillText) continue;
1067
+ const bool isImage = cmd.type == Type::DrawImage || cmd.type == Type::DrawImageScaled;
1068
+ const present::Rect b = present::commandBounds(cmd, width, height);
1069
+ if (!isImage && present::valid(b) && b.y0 >= kRailPanelRow) continue; // static rail fills
1070
+ LandPrevCmd &slot = landPrev_[backIndex][landPrevCount_[backIndex]];
1071
+ slot.pixels = isImage ? cmd.pixels : nullptr;
1072
+ slot.type = static_cast<std::int16_t>(cmd.type);
1073
+ slot.x = cmd.x;
1074
+ slot.y = cmd.y;
1075
+ slot.w = cmd.w;
1076
+ slot.h = cmd.h;
1077
+ landPrevCount_[backIndex]++;
1078
+ }
1079
+ if (!snapshotOverflow && landPrevCount_[backIndex] > 0) landPrevValid_[backIndex] = true;
1080
+ landPrevRailHash_[backIndex] = railHash;
1081
+ const int maxRows = std::max(1, kFlushRowsDefault);
1082
+ if (!panMode)
1083
+ for (int row = 0; row < height; row += maxRows) {
1084
+ int rows = maxRows;
1085
+ if (row + rows > height) rows = height - row;
1086
+ // Occlusion: skip the base fill when opaque blits cover the band.
1087
+ std::size_t firstCommand = 0;
1088
+ {
1089
+ int spans[16][2];
1090
+ int spanCount = 0;
1091
+ for (std::size_t i = 1; i < current.commands.size() && spanCount < 16; ++i) {
1092
+ const present::Command &c = current.commands[i];
1093
+ if (c.type == Type::FillText) continue;
1094
+ const present::Rect b = present::commandBounds(c, width, height);
1095
+ if (!present::valid(b) || b.y0 > row || b.y1 < row + rows - 1) continue;
1096
+ spans[spanCount][0] = std::max(0, b.x0);
1097
+ spans[spanCount][1] = std::min(width - 1, b.x1);
1098
+ spanCount++;
1099
+ }
1100
+ for (int a = 1; a < spanCount; ++a) {
1101
+ for (int b2 = a; b2 > 0 && spans[b2][0] < spans[b2 - 1][0]; --b2) {
1102
+ std::swap(spans[b2][0], spans[b2 - 1][0]);
1103
+ std::swap(spans[b2][1], spans[b2 - 1][1]);
1104
+ }
1105
+ }
1106
+ int reach = 0;
1107
+ for (int a = 0; a < spanCount; ++a) {
1108
+ if (spans[a][0] > reach) break;
1109
+ if (spans[a][1] + 1 > reach) reach = spans[a][1] + 1;
1110
+ }
1111
+ if (reach >= width) firstCommand = 1;
1112
+ }
1113
+ std::uint16_t *target = back + static_cast<std::size_t>(row) * kNativeWidth;
1114
+ const std::int64_t rasterStartUs = esp_timer_get_time();
1115
+ gea::framework::graphics::Canvas bandCanvas;
1116
+ bandCanvas.bindPixels(target, kNativeWidth, rows, kNativeWidth);
1117
+ for (std::size_t i = firstCommand; i < current.commands.size(); ++i) {
1118
+ const present::Command &cmd = current.commands[i];
1119
+ if (cmd.type == Type::FillText) continue; // rotated full-buffer pass below
1120
+ if (cmd.type != Type::Clear) {
1121
+ const present::Rect bounds = present::commandBounds(cmd, width, height);
1122
+ if (!present::valid(bounds) || bounds.y1 < row || bounds.y0 > row + rows - 1) continue;
1123
+ }
1124
+ present::rasterCommandRows(bandCanvas, target, 0, kNativeWidth, row, rows, height, cmd);
1125
+ }
1126
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
1127
+ }
1128
+ landRasterUs_ = static_cast<int>(esp_timer_get_time() - started) - landAlignUs_;
1129
+ landPanMode_ = panMode ? 1 : 0;
1130
+ if (panMode) landPanFrames_++; else landFullFrames_++;
1131
+ // Sidebar text: rotated glyph blits over the full back buffer
1132
+ // (landscape anchors; the blitter does the panel transform per pixel).
1133
+ if (!panMode) {
1134
+ const std::int64_t textStartUs = esp_timer_get_time();
1135
+ gea::framework::graphics::Canvas fullCanvas;
1136
+ fullCanvas.bindPixels(back, kNativeWidth, kNativeHeight, kNativeWidth);
1137
+ for (const present::Command &cmd : current.commands) {
1138
+ if (cmd.type != Type::FillText || cmd.fontFamilyId < 0) continue;
1139
+ fullCanvas.drawTextFontFamilyRotated90(cmd.text.c_str(), cmd.x, cmd.y, cmd.color,
1140
+ cmd.fontFamilyId, cmd.fontSizePx);
1141
+ }
1142
+ flushStats_.rasterUs += esp_timer_get_time() - textStartUs;
1143
+ landTextUs_ = static_cast<int>(esp_timer_get_time() - textStartUs);
1144
+ }
1145
+ take();
1146
+ const std::int64_t flipStartUs = esp_timer_get_time();
1147
+ if (refreshDoneSem_) xSemaphoreTake(refreshDoneSem_, 0);
1148
+ flipPanelToBack();
1149
+ lastFlipUs_ = esp_timer_get_time();
1150
+ flushStats_.copyUs += lastFlipUs_ - flipStartUs;
1151
+ landFlipUs_ = static_cast<int>(lastFlipUs_ - flipStartUs);
1152
+ give();
1153
+ landTotalUs_ = static_cast<int>(esp_timer_get_time() - started);
1154
+ flushStats_.totalUs += esp_timer_get_time() - started;
1155
+ flushStats_.chunkCount++;
1156
+ flushStats_.pixelCount += width * height;
1157
+ static int landHits = 0;
1158
+ landHits++;
1159
+ pathDirect_++;
1160
+ if ((landHits & 15) == 1) {
1161
+ ESP_LOGI(kTag, "landscape panel-native frame #%d total=%lldus", landHits,
1162
+ static_cast<long long>(esp_timer_get_time() - started));
1163
+ }
1164
+ panelDirectActive_ = true;
1165
+ previousPresentValid_ = false;
1166
+ frameBufferCoherent_ = false;
1167
+ canvas_.resetDirty();
1168
+ return true;
1169
+ }
1170
+ }
1171
+ if (panelDirectActive_) {
1172
+ // A frame that ISN'T panel-direct is taking over: the scanout holds
1173
+ // tile content the composed path knows nothing about. Force a full
1174
+ // composed repaint + flush.
1175
+ panelDirectActive_ = false;
1176
+ previousPresentValid_ = false;
1177
+ needsFullPhysicalFlush_ = true;
1178
+ landPrevValid_[0] = false;
1179
+ landPrevValid_[1] = false;
1180
+ }
1181
+ {
1182
+ using gea::framework::display::DisplayOrientation;
1183
+ using Type = gea::platform::display::DisplayPresentCommandType;
1184
+ const bool rotatedMode = !(orientation_detail::DisplayOrientationState::orientation() == DisplayOrientation::PortraitPrimary &&
1185
+ usingPanelFrameBufferDirectly());
1186
+ int shiftDx = 0;
1187
+ int shiftDy = 0;
1188
+ const int absLimitX = logicalWidth() / 2;
1189
+ const int absLimitY = logicalHeight() / 2;
1190
+ const bool panPreconditions = tileShape && rotatedMode && previousPresentValid_ && !needsFullPhysicalFlush_ && frameBufferCoherent_;
1191
+ const bool panShiftFound = panPreconditions && detectUniformShift(previousPresentFrame_, current, &shiftDx, &shiftDy);
1192
+ if (panPreconditions && !panShiftFound) {
1193
+ static int panMisses = 0;
1194
+ panMisses++;
1195
+ if ((panMisses & 31) == 1) ESP_LOGI(kTag, "torus MISS #%d (no uniform shift; cmds=%d)", panMisses, static_cast<int>(current.commands.size()));
1196
+ }
1197
+ if (panShiftFound &&
1198
+ (shiftDx < 0 ? -shiftDx : shiftDx) < absLimitX && (shiftDy < 0 ? -shiftDy : shiftDy) < absLimitY) {
1199
+ // PAN FAST PATH: the frame is the previous one uniformly shifted.
1200
+ // Move the torus origin, raster ONLY the exposed strips and any
1201
+ // commands without a shifted twin, then rebuild the panel with
1202
+ // 1-4 big PPA rotate ops. ~30-80k rastered pixels instead of 921k.
1203
+ static int panHits = 0;
1204
+ panHits++;
1205
+ const std::int64_t rasterUs0 = flushStats_.rasterUs;
1206
+ const std::int64_t copyUs0 = flushStats_.copyUs;
1207
+ const std::int64_t txUs0 = flushStats_.txUs;
1208
+ const std::int64_t started = esp_timer_get_time();
1209
+ flushStats_.callCount++;
1210
+ scrollOriginX_ = wrapCoord(scrollOriginX_ - shiftDx, logicalWidth());
1211
+ scrollOriginY_ = wrapCoord(scrollOriginY_ - shiftDy, logicalHeight());
1212
+ present::Rect rects[kMaxPresentRects];
1213
+ int rectCount = 0;
1214
+ if (shiftDx > 0)
1215
+ present::addRect(rects, &rectCount, kMaxPresentRects, {0, 0, shiftDx - 1, logicalHeight() - 1}, logicalWidth(), logicalHeight());
1216
+ else if (shiftDx < 0)
1217
+ present::addRect(rects, &rectCount, kMaxPresentRects, {logicalWidth() + shiftDx, 0, logicalWidth() - 1, logicalHeight() - 1},
1218
+ logicalWidth(), logicalHeight());
1219
+ if (shiftDy > 0)
1220
+ present::addRect(rects, &rectCount, kMaxPresentRects, {0, 0, logicalWidth() - 1, shiftDy - 1}, logicalWidth(), logicalHeight());
1221
+ else if (shiftDy < 0)
1222
+ present::addRect(rects, &rectCount, kMaxPresentRects, {0, logicalHeight() + shiftDy, logicalWidth() - 1, logicalHeight() - 1},
1223
+ logicalWidth(), logicalHeight());
1224
+ for (std::size_t i = 1; i < current.commands.size(); ++i) {
1225
+ const present::Command &c = current.commands[i];
1226
+ bool matchedCmd = false;
1227
+ for (std::size_t j = 1; j < previousPresentFrame_.commands.size() && !matchedCmd; ++j) {
1228
+ const present::Command &p = previousPresentFrame_.commands[j];
1229
+ matchedCmd = p.type == c.type && p.pixels == c.pixels && p.srcWidth == c.srcWidth &&
1230
+ p.srcHeight == c.srcHeight &&
1231
+ (c.type != Type::DrawImageScaled || (p.w == c.w && p.h == c.h)) &&
1232
+ p.x + shiftDx == c.x && p.y + shiftDy == c.y;
1233
+ }
1234
+ if (!matchedCmd)
1235
+ present::addCommandBounds(c, rects, &rectCount, kMaxPresentRects, logicalWidth(), logicalHeight());
1236
+ }
1237
+ bool ok = true;
1238
+ for (int i = 0; i < rectCount && ok; ++i) {
1239
+ present::Rect region = clampLogicalRect(rects[i], logicalWidth(), logicalHeight());
1240
+ if (!present::valid(region)) continue;
1241
+ rasterPresentRegion(current, region);
1242
+ TorusPart parts[4];
1243
+ const int partCount = splitLogicalRectToTorus(region, parts);
1244
+ const std::int64_t syncStartUs = esp_timer_get_time();
1245
+ for (int p = 0; p < partCount && ok; ++p) ok = syncTorusPartToMemory(parts[p]);
1246
+ flushStats_.copyUs += esp_timer_get_time() - syncStartUs;
1247
+ }
1248
+ if (ok && !panelSyncedForTorus_) {
1249
+ ok = syncPanelFrameBufferRectToMemory({0, 0, kNativeWidth - 1, kNativeHeight - 1});
1250
+ panelSyncedForTorus_ = true;
1251
+ }
1252
+ if (ok) ok = flushFullPanelFromTorus();
1253
+ flushStats_.totalUs += esp_timer_get_time() - started;
1254
+ if ((panHits & 15) == 1) {
1255
+ ESP_LOGI(kTag, "torus pan #%d dx=%d dy=%d rects=%d total=%lldus raster=%lldus sync=%lldus ppa=%lldus",
1256
+ panHits, shiftDx, shiftDy, rectCount,
1257
+ static_cast<long long>(esp_timer_get_time() - started),
1258
+ static_cast<long long>(flushStats_.rasterUs - rasterUs0),
1259
+ static_cast<long long>(flushStats_.copyUs - copyUs0),
1260
+ static_cast<long long>(flushStats_.txUs - txUs0));
1261
+ }
1262
+ if (ok) {
1263
+ previousPresentFrame_ = std::move(current);
1264
+ previousPresentValid_ = true;
1265
+ frameBufferCoherent_ = true;
1266
+ canvas_.resetDirty();
1267
+ } else {
1268
+ scrollOriginX_ = 0;
1269
+ scrollOriginY_ = 0;
1270
+ panelSyncedForTorus_ = false;
1271
+ previousPresentValid_ = false;
1272
+ needsFullPhysicalFlush_ = true;
1273
+ }
1274
+ return ok;
1275
+ }
1276
+ }
1277
+ if (isFastClearFillCirclesFrame(current) && incrementalCirclePathBeneficial(current)) {
1278
+ const bool ok = presentClearFillCirclesFrame(current);
1279
+ if (ok) {
1280
+ previousPresentFrame_ = std::move(current);
1281
+ previousPresentValid_ = true;
1282
+ needsFullPhysicalFlush_ = false;
1283
+ canvas_.resetDirty();
1284
+ }
1285
+ return ok;
1286
+ }
1287
+ present::Rect regions[kMaxPresentRects];
1288
+ int regionCount = 0;
1289
+ if (previousPresentValid_) {
1290
+ regionCount = present::dirtyRects(&previousPresentFrame_,
1291
+ current,
1292
+ regions,
1293
+ kMaxPresentRects,
1294
+ logicalWidth(),
1295
+ logicalHeight());
1296
+ } else {
1297
+ regions[0] = {0, 0, logicalWidth() - 1, logicalHeight() - 1};
1298
+ regionCount = 1;
1299
+ }
1300
+ if (regionCount <= 0) {
1301
+ previousPresentFrame_ = std::move(current);
1302
+ previousPresentValid_ = true;
1303
+ return true;
1304
+ }
1305
+
1306
+ const std::int64_t started = esp_timer_get_time();
1307
+ bool ok = true;
1308
+ pathGeneral_++;
1309
+ flushStats_.callCount++;
1310
+ // MEASURED LOSS, kept dark: per-tile PPA blits cost MORE than the CPU
1311
+ // raster (flush 53-89ms -> 84-182ms on the maps tile grid) because the
1312
+ // IDF PPA driver cache-syncs the full 1.8MB output framebuffer around
1313
+ // EVERY transaction — ~30 small ops pay ~30 full-buffer msyncs. The PPA
1314
+ // only wins as one big op per region (like the rotate flush). Re-try if
1315
+ // the driver ever grows a no-sync/explicit-sync mode.
1316
+ constexpr bool kUsePpaTileBlits = false;
1317
+ const bool ppaTiles = kUsePpaTileBlits && framePpaTileEligible(current);
1318
+ for (int i = 0; i < regionCount; ++i) {
1319
+ present::Rect region = clampLogicalRect(regions[i], logicalWidth(), logicalHeight());
1320
+ if (!present::valid(region)) continue;
1321
+ bool rastered = false;
1322
+ if (ppaTiles) {
1323
+ const std::int64_t ppaStartUs = esp_timer_get_time();
1324
+ rastered = ppaRasterTileRegion(current, region);
1325
+ flushStats_.rasterUs += esp_timer_get_time() - ppaStartUs;
1326
+ }
1327
+ if (!rastered) rasterPresentRegion(current, region);
1328
+ ok = flushNativeLogicalRect(region);
1329
+ if (!ok) {
1330
+ ok = false;
1331
+ break;
1332
+ }
1333
+ }
1334
+ flushStats_.totalUs += esp_timer_get_time() - started;
1335
+ if (ok) {
1336
+ previousPresentFrame_ = std::move(current);
1337
+ previousPresentValid_ = true;
1338
+ needsFullPhysicalFlush_ = false;
1339
+ frameBufferCoherent_ = true;
1340
+ canvas_.resetDirty();
1341
+ }
1342
+ return ok;
1343
+ }
1344
+
1345
+ // A frame whose base layer is [Clear, FillCircles]. Commands AFTER the circle
1346
+ // batch (FPS text, a HUD rect, ...) are overlays drawn on top — they ride the
1347
+ // incremental path via a per-frame overlay re-raster, so they no longer
1348
+ // disqualify it. (Previously this required EXACTLY two commands, which dropped
1349
+ // any circle frame carrying an FPS counter onto the slow full-screen path.)
1350
+ static bool isFastClearFillCirclesFrame(const present::Frame &frame)
1351
+ {
1352
+ using Type = gea::platform::display::DisplayPresentCommandType;
1353
+ if (frame.commands.size() < 2) return false;
1354
+ const present::Command &clear = frame.commands[0];
1355
+ const present::Command &circles = frame.commands[1];
1356
+ if (clear.type != Type::Clear || circles.type != Type::FillCirclesRgb565) return false;
1357
+ if (circles.alpha != 255 || circles.radius <= 0 || circles.circlesCount < 0) return false;
1358
+ return circles.hasCircleEntries();
1359
+ }
1360
+
1361
+ // The incremental circle path erases + redraws every ball (2x scattered writes
1362
+ // over the whole framebuffer — cache-thrashing) to save the cache writeback on
1363
+ // the untouched area. That trade only pays when the touched area is small; for a
1364
+ // dense/full-screen ball field the general chunked rasterizer is faster (measured
1365
+ // 21.6 vs 18.2fps for 1000 balls). So gate the incremental path on the would-be
1366
+ // dirty area, mirroring the amoled's geometric band-collapse decision.
1367
+ bool incrementalCirclePathBeneficial(const present::Frame &current) const
1368
+ {
1369
+ if (!previousPresentValid_ || needsFullPhysicalFlush_) return false;
1370
+ if (!isFastClearFillCirclesFrame(previousPresentFrame_)) return false;
1371
+ if (previousPresentFrame_.commands[0].color != current.commands[0].color) return false;
1372
+ present::Rect dirty = present::unite(circleBatchBounds(previousPresentFrame_.commands[1]),
1373
+ circleBatchBounds(current.commands[1]));
1374
+ for (std::size_t i = 2; i < current.commands.size(); ++i)
1375
+ dirty = present::unite(dirty, present::commandBounds(current.commands[i], logicalWidth(), logicalHeight()));
1376
+ for (std::size_t i = 2; i < previousPresentFrame_.commands.size(); ++i)
1377
+ dirty = present::unite(dirty, present::commandBounds(previousPresentFrame_.commands[i], logicalWidth(), logicalHeight()));
1378
+ dirty = clampLogicalRect(dirty, logicalWidth(), logicalHeight());
1379
+ if (!present::valid(dirty)) return true; // nothing moved — trivially cheap
1380
+ const long long dirtyArea = static_cast<long long>(dirty.x1 - dirty.x0 + 1) * (dirty.y1 - dirty.y0 + 1);
1381
+ const long long screenArea = static_cast<long long>(logicalWidth()) * logicalHeight();
1382
+ return dirtyArea * 3 < screenArea; // only when < ~1/3 of the screen is touched
1383
+ }
1384
+
1385
+ bool presentClearFillCirclesFrame(const present::Frame &current)
1386
+ {
1387
+ const present::Command &clear = current.commands[0];
1388
+ const present::Command &circles = current.commands[1];
1389
+ const bool canIncremental =
1390
+ previousPresentValid_ &&
1391
+ isFastClearFillCirclesFrame(previousPresentFrame_) &&
1392
+ previousPresentFrame_.commands[0].color == clear.color;
1393
+
1394
+ // Overlays = every command past the circle batch (e.g. the FPS text). They
1395
+ // sit on top of the balls and don't move with them, so their box — current
1396
+ // AND previous (to erase the stale overlay) — is repainted independently and
1397
+ // re-composited from scratch. Empty when the frame is pure [Clear, FillCircles].
1398
+ present::Rect overlayDirty{};
1399
+ for (std::size_t i = 2; i < current.commands.size(); ++i)
1400
+ overlayDirty = present::unite(overlayDirty, present::commandBounds(current.commands[i], logicalWidth(), logicalHeight()));
1401
+ if (canIncremental)
1402
+ for (std::size_t i = 2; i < previousPresentFrame_.commands.size(); ++i)
1403
+ overlayDirty = present::unite(overlayDirty, present::commandBounds(previousPresentFrame_.commands[i], logicalWidth(), logicalHeight()));
1404
+ overlayDirty = clampLogicalRect(overlayDirty, logicalWidth(), logicalHeight());
1405
+
1406
+ present::Rect dirty = present::fullScreen(logicalWidth(), logicalHeight());
1407
+ if (canIncremental && !needsFullPhysicalFlush_) {
1408
+ dirty = present::unite(circleBatchBounds(previousPresentFrame_.commands[1]), circleBatchBounds(circles));
1409
+ if (present::valid(overlayDirty)) dirty = present::unite(dirty, overlayDirty);
1410
+ dirty = clampLogicalRect(dirty, logicalWidth(), logicalHeight());
1411
+ if (!present::valid(dirty)) return true;
1412
+ }
1413
+
1414
+ const std::int64_t started = esp_timer_get_time();
1415
+ flushStats_.callCount++;
1416
+ const std::int64_t rasterStartUs = esp_timer_get_time();
1417
+ if (canIncremental && !needsFullPhysicalFlush_) {
1418
+ drawCircleBatchRaw(previousPresentFrame_.commands[1], clear.color, true);
1419
+ } else {
1420
+ clearFrameBufferRows(0, logicalHeight() - 1, clear.color);
1421
+ }
1422
+ drawCircleBatchRaw(circles, 0, false);
1423
+ // Composite overlays: re-raster their box from the full frame (clear + the
1424
+ // balls behind them + the overlay itself), so the old overlay is erased and
1425
+ // the new one lands on top of whatever balls sit behind it.
1426
+ if (present::valid(overlayDirty)) rasterPresentRegion(current, overlayDirty);
1427
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
1428
+
1429
+ const bool ok = flushNativeLogicalRect(dirty);
1430
+ flushStats_.totalUs += esp_timer_get_time() - started;
1431
+ if (ok) frameBufferCoherent_ = true;
1432
+ return ok;
1433
+ }
1434
+
1435
+ present::Rect circleBatchBounds(const present::Command &command) const
1436
+ {
1437
+ present::Rect bounds{};
1438
+ const auto *circles = command.circleEntries();
1439
+ if (!circles || command.circlesCount <= 0) return bounds;
1440
+ for (int i = 0; i < command.circlesCount; ++i) {
1441
+ bounds = present::unite(bounds,
1442
+ present::circleBounds(static_cast<int>(circles[i].x),
1443
+ static_cast<int>(circles[i].y),
1444
+ command.radius));
1445
+ }
1446
+ return bounds;
1447
+ }
1448
+
1449
+ void clearFrameBufferRows(int y0, int y1, std::uint16_t color)
1450
+ {
1451
+ if (!frameBuffer_) return;
1452
+ y0 = std::max(0, y0);
1453
+ y1 = std::min(logicalHeight() - 1, y1);
1454
+ if (y0 > y1) return;
1455
+ const int width = logicalWidth();
1456
+ const int rows = y1 - y0 + 1;
1457
+ std::uint16_t *dst = frameBuffer_ + static_cast<std::size_t>(y0) * logicalStride_;
1458
+ if (logicalStride_ == width) {
1459
+ const std::size_t pixels = static_cast<std::size_t>(width) * rows;
1460
+ if (color == 0) std::memset(dst, 0, pixels * sizeof(std::uint16_t));
1461
+ else std::fill_n(dst, pixels, color);
1462
+ return;
1463
+ }
1464
+ for (int y = y0; y <= y1; ++y) {
1465
+ std::uint16_t *row = frameBuffer_ + static_cast<std::size_t>(y) * logicalStride_;
1466
+ if (color == 0) std::memset(row, 0, static_cast<std::size_t>(width) * sizeof(std::uint16_t));
1467
+ else std::fill_n(row, width, color);
1468
+ }
1469
+ }
1470
+
1471
+ void drawCircleBatchRaw(const present::Command &command, std::uint16_t overrideColor, bool useOverrideColor)
1472
+ {
1473
+ if (!frameBuffer_ || command.radius <= 0 || command.circlesCount <= 0) return;
1474
+ const auto *circles = command.circleEntries();
1475
+ if (!circles) return;
1476
+ const int width = logicalWidth();
1477
+ const int height = logicalHeight();
1478
+ const int r = command.radius;
1479
+ for (int i = 0; i < command.circlesCount; ++i) {
1480
+ const int cx = static_cast<int>(circles[i].x);
1481
+ const int cy = static_cast<int>(circles[i].y);
1482
+ const std::uint16_t color = useOverrideColor ? overrideColor : circles[i].color;
1483
+ int dy0 = -r;
1484
+ int dy1 = r;
1485
+ if (cy + dy0 < 0) dy0 = -cy;
1486
+ if (cy + dy1 >= height) dy1 = height - 1 - cy;
1487
+ if (dy0 > dy1) continue;
1488
+ for (int dy = dy0; dy <= dy1; ++dy) {
1489
+ const int spanIndex = dy + command.spans.origin;
1490
+ const int halfWidth =
1491
+ spanIndex >= 0 && spanIndex < static_cast<int>(command.spans.halfWidths.size())
1492
+ ? command.spans.halfWidths[static_cast<std::size_t>(spanIndex)]
1493
+ : present::integerSqrt(r * r - dy * dy);
1494
+ int x0 = cx - halfWidth;
1495
+ int x1 = cx + halfWidth;
1496
+ if (x0 < 0) x0 = 0;
1497
+ if (x1 >= width) x1 = width - 1;
1498
+ if (x0 > x1) continue;
1499
+ std::uint16_t *dst = frameBuffer_ + static_cast<std::size_t>(cy + dy) * logicalStride_ + x0;
1500
+ const int count = x1 - x0 + 1;
1501
+ if (color == 0) std::memset(dst, 0, static_cast<std::size_t>(count) * sizeof(std::uint16_t));
1502
+ else std::fill_n(dst, count, color);
1503
+ }
1504
+ }
1505
+ }
1506
+
1507
+ void setFlushConfig(int chunkRows, int queueDepth)
1508
+ {
1509
+ if (chunkRows > 0) flushRows_ = std::min(chunkRows, kFlushRowsDefault);
1510
+ if (queueDepth > 0) flushDepth_ = queueDepth;
1511
+ }
1512
+
1513
+ int flushChunkRows() const { return flushRows_; }
1514
+ int flushQueueDepth() const { return flushDepth_; }
1515
+ int flushBufferBytes() const { return 0; }
1516
+
1517
+ bool copySnapshotRgb565(std::uint16_t *dst, int pixelCapacity, int *width, int *height)
1518
+ {
1519
+ const int lw = logicalWidth();
1520
+ const int lh = logicalHeight();
1521
+ if (!dst || pixelCapacity < lw * lh) return false;
1522
+ if (width) *width = lw;
1523
+ if (height) *height = lh;
1524
+ // Panel-direct modes raster straight into the scanout buffers and leave
1525
+ // the composed framebuffer stale — snapshot what the GLASS shows by
1526
+ // reading the scanned panel buffer through the inverse orientation map.
1527
+ if (panelDirectActive_ && panelFrameBuffers_[scannedFbIndex_]) {
1528
+ const std::uint16_t *panel = panelFrameBuffers_[scannedFbIndex_];
1529
+ for (int ly = 0; ly < lh; ++ly) {
1530
+ std::uint16_t *out = dst + static_cast<std::size_t>(ly) * lw;
1531
+ for (int lx = 0; lx < lw; ++lx) {
1532
+ const PanelCoord pc = panelForSourcePixel(lx, ly);
1533
+ out[lx] = panel[static_cast<std::size_t>(pc.y) * kNativeWidth + pc.x];
1534
+ }
1535
+ }
1536
+ return true;
1537
+ }
1538
+ for (int row = 0; row < lh; ++row) {
1539
+ std::memcpy(dst + static_cast<std::size_t>(row) * lw,
1540
+ frameBuffer_ + static_cast<std::size_t>(row) * logicalStride_,
1541
+ static_cast<std::size_t>(lw) * sizeof(std::uint16_t));
1542
+ }
1543
+ return true;
1544
+ }
1545
+
1546
+ int countNonBlackPixels() const
1547
+ {
1548
+ if (!frameBuffer_) return 0;
1549
+ int count = 0;
1550
+ for (int y = 0; y < logicalHeight(); ++y) {
1551
+ const std::uint16_t *row = frameBuffer_ + static_cast<std::size_t>(y) * logicalStride_;
1552
+ for (int x = 0; x < logicalWidth(); ++x) {
1553
+ if (pixel::toRgb565(row[x]) != 0) ++count;
1554
+ }
1555
+ }
1556
+ return count;
1557
+ }
1558
+
1559
+ void setBrightness(int brightness)
1560
+ {
1561
+ if (brightness < 0) brightness = 0;
1562
+ if (brightness > 100) brightness = 100;
1563
+ brightness_ = brightness;
1564
+ if (brightnessInitialized_) updateBacklightDuty();
1565
+ }
1566
+
1567
+ int brightness() const { return brightness_; }
1568
+
1569
+ platform_display::DisplayFlushPerfStats flushStats() const { return flushStats_; }
1570
+ void presentPathDebug(int *calls, int *direct, int *general, int *rejected, int *tsKind, int *tsType, int *tsCount) const
1571
+ {
1572
+ *calls = presentCalls_;
1573
+ *direct = pathDirect_;
1574
+ *general = pathGeneral_;
1575
+ *rejected = pathRejected_;
1576
+ *tsKind = gTileShapeFailKind;
1577
+ *tsType = gTileShapeFailType;
1578
+ *tsCount = gTileShapeFailCount;
1579
+ }
1580
+ void landPanDebug(int *detect, int *kick, int *strips, int *wait, int *interior) const
1581
+ {
1582
+ *detect = panBailCounts_[1] + panBailCounts_[2] * 1000 + panBailCounts_[3] * 1000000;
1583
+ *kick = panBailCounts_[4] + panBailCounts_[5] * 1000 + panBailCounts_[6] * 1000000;
1584
+ *strips = panStripUs_;
1585
+ *wait = panBailReason_;
1586
+ *interior = panInteriorUs_ & 0xffffff;
1587
+ }
1588
+ void landFrameDebug(int *total, int *align, int *raster, int *text, int *flip) const
1589
+ {
1590
+ *total = landTotalUs_;
1591
+ *align = landAlignUs_;
1592
+ *raster = landRasterUs_;
1593
+ *text = landTextUs_;
1594
+ *flip = (landFlipUs_ & 0xffff) | (landPanMode_ << 16) | ((landPanFrames_ & 0xff) << 17) | ((landFullFrames_ & 0x7f) << 25);
1595
+ }
1596
+ void flushStatsReset() { flushStats_ = {}; }
1597
+
1598
+ const char *flushStageName() const { return "idle"; }
1599
+ int flushStageChunk() const { return 0; }
1600
+ platform_display::DisplayFlushStageDetail flushStageDetail() const { return {}; }
1601
+ std::uint16_t *backgroundCache(int *capPx) { return fullScreenScratch(backgroundCache_, backgroundCacheAttempted_, capPx, "background"); }
1602
+ std::uint16_t *backdropCache(int *capPx) { return fullScreenScratch(backdropCache_, backdropCacheAttempted_, capPx, "backdrop"); }
1603
+ void setRenderCore(int core)
1604
+ {
1605
+ renderCoreId_ = core;
1606
+ if (frameBuffer_) workerCanvas_.bindPixels(frameBuffer_, logicalWidth(), logicalHeight(), logicalStride_);
1607
+ }
1608
+
1609
+ void absorbWorkerDirty()
1610
+ {
1611
+ int x0 = 0;
1612
+ int y0 = 0;
1613
+ int x1 = -1;
1614
+ int y1 = -1;
1615
+ if (workerCanvas_.dirty(&x0, &y0, &x1, &y1)) canvas_.markDirty(x0, y0, x1, y1);
1616
+ workerCanvas_.resetDirty();
1617
+ }
1618
+
1619
+ private:
1620
+ DisplayBackend() = default;
1621
+
1622
+ int logicalWidth() const { return orientation_detail::DisplayOrientationState::width(); }
1623
+ int logicalHeight() const { return orientation_detail::DisplayOrientationState::height(); }
1624
+ bool onWorkerCore() const { return renderCoreId_ >= 0 && xPortGetCoreID() != renderCoreId_; }
1625
+ gea::framework::graphics::Canvas &replayCanvas() { return onWorkerCore() ? workerCanvas_ : canvas_; }
1626
+
1627
+ std::uint16_t *fullScreenScratch(std::uint16_t *&buffer, bool &attempted, int *capPx, const char *label)
1628
+ {
1629
+ if (!attempted) {
1630
+ attempted = true;
1631
+ buffer = static_cast<std::uint16_t *>(
1632
+ heap_caps_malloc(static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t),
1633
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1634
+ if (buffer) {
1635
+ ESP_LOGI(kTag, "allocated %s cache %.1f KiB", label, (kMaxPixels * sizeof(std::uint16_t)) / 1024.0);
1636
+ } else {
1637
+ ESP_LOGW(kTag, "failed to allocate %s cache (%zu bytes)",
1638
+ label,
1639
+ static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
1640
+ }
1641
+ }
1642
+ if (capPx) *capPx = buffer ? kMaxPixels : 0;
1643
+ return buffer;
1644
+ }
1645
+
1646
+ void bindCanvas()
1647
+ {
1648
+ take();
1649
+ bindCanvasLocked();
1650
+ give();
1651
+ }
1652
+
1653
+ void bindCanvasLocked()
1654
+ {
1655
+ const int width = logicalWidth();
1656
+ const int height = logicalHeight();
1657
+ const int stride = width;
1658
+ std::uint16_t *targetFrameBuffer = preferredFrameBuffer();
1659
+ if (!targetFrameBuffer) return;
1660
+ if (frameBuffer_ != targetFrameBuffer) frameBuffer_ = targetFrameBuffer;
1661
+ if (canvas_.pixels() == frameBuffer_ && canvas_.width() == width && canvas_.height() == height && logicalStride_ == stride) return;
1662
+ logicalStride_ = stride;
1663
+ canvas_.bindPixels(frameBuffer_, width, height, logicalStride_);
1664
+ workerCanvas_.bindPixels(frameBuffer_, width, height, logicalStride_);
1665
+ }
1666
+
1667
+ std::uint16_t *preferredFrameBuffer() const
1668
+ {
1669
+ // Always compose into the off-screen owned buffer (never directly into the
1670
+ // scanned-out panel framebuffer). The flush then PPA-blits the dirty region
1671
+ // owned->panel: the runtime's multi-ms rasterization no longer touches the
1672
+ // live scanout buffer, so the only write the DSI can catch mid-scan is the
1673
+ // fast hardware PPA copy — shrinking the tear window from the whole frame's
1674
+ // raster down to a sub-ms blit. (Portrait is a 0deg PPA copy.)
1675
+ return ownedFrameBuffer_;
1676
+ }
1677
+
1678
+ bool usingPanelFrameBufferDirectly() const
1679
+ {
1680
+ using gea::framework::display::DisplayOrientation;
1681
+ return frameBuffer_ && panelFrameBuffer_ && frameBuffer_ == panelFrameBuffer_ &&
1682
+ logicalStride_ == kNativeWidth &&
1683
+ orientation_detail::DisplayOrientationState::orientation() == DisplayOrientation::PortraitPrimary;
1684
+ }
1685
+
1686
+ bool syncFrameBufferRectToMemory(present::Rect logicalRect)
1687
+ {
1688
+ return syncBufferRectToMemory(frameBuffer_, logicalStride_, logicalWidth(), logicalHeight(), logicalRect, "DPI framebuffer");
1689
+ }
1690
+
1691
+ bool syncBufferRectToMemory(std::uint16_t *buffer,
1692
+ int stridePixels,
1693
+ int widthPixels,
1694
+ int heightPixels,
1695
+ present::Rect rect,
1696
+ const char *label)
1697
+ {
1698
+ if (!buffer) return false;
1699
+ rect = present::clampAndAlign(rect, widthPixels, heightPixels);
1700
+ if (!present::valid(rect)) return true;
1701
+ const int width = rect.x1 - rect.x0 + 1;
1702
+ if (width <= 0) return true;
1703
+ const std::size_t bytes = static_cast<std::size_t>(width) * sizeof(std::uint16_t);
1704
+ constexpr int kFlags = ESP_CACHE_MSYNC_FLAG_DIR_C2M |
1705
+ ESP_CACHE_MSYNC_FLAG_TYPE_DATA |
1706
+ ESP_CACHE_MSYNC_FLAG_UNALIGNED;
1707
+ for (int y = rect.y0; y <= rect.y1; ++y) {
1708
+ void *row = buffer + static_cast<std::size_t>(y) * stridePixels + rect.x0;
1709
+ const esp_err_t err = esp_cache_msync(row, bytes, kFlags);
1710
+ if (err == ESP_OK) continue;
1711
+ if (!cacheSyncWarned_) {
1712
+ cacheSyncWarned_ = true;
1713
+ ESP_LOGE(kTag, "%s cache writeback failed: %s", label, esp_err_to_name(err));
1714
+ }
1715
+ return false;
1716
+ }
1717
+ return true;
1718
+ }
1719
+
1720
+ bool syncPanelFrameBufferRectToMemory(present::Rect panelRect)
1721
+ {
1722
+ return syncBufferRectToMemory(panelFrameBuffer_, kNativeWidth, kNativeWidth, kNativeHeight, panelRect, "DPI panel framebuffer");
1723
+ }
1724
+
1725
+ bool initPpaSrm()
1726
+ {
1727
+ if (ppaSrmClient_) return true;
1728
+ ppa_client_config_t config{};
1729
+ config.oper_type = PPA_OPERATION_SRM;
1730
+ config.max_pending_trans_num = 1;
1731
+ config.data_burst_length = PPA_DATA_BURST_LENGTH_128;
1732
+ const esp_err_t err = ppa_register_client(&config, &ppaSrmClient_);
1733
+ if (err != ESP_OK) {
1734
+ if (!ppaWarned_) {
1735
+ ppaWarned_ = true;
1736
+ ESP_LOGE(kTag, "PPA SRM client registration failed: %s", esp_err_to_name(err));
1737
+ }
1738
+ return false;
1739
+ }
1740
+ ESP_LOGI(kTag, "PPA SRM rotation ready");
1741
+ return true;
1742
+ }
1743
+
1744
+ ppa_srm_rotation_angle_t ppaRotationForCurrentOrientation() const
1745
+ {
1746
+ using gea::framework::display::DisplayOrientation;
1747
+ switch (orientation_detail::DisplayOrientationState::orientation()) {
1748
+ case DisplayOrientation::PortraitSecondary:
1749
+ return PPA_SRM_ROTATION_ANGLE_180;
1750
+ case DisplayOrientation::LandscapePrimary:
1751
+ return PPA_SRM_ROTATION_ANGLE_90;
1752
+ case DisplayOrientation::LandscapeSecondary:
1753
+ return PPA_SRM_ROTATION_ANGLE_270;
1754
+ case DisplayOrientation::PortraitPrimary:
1755
+ default:
1756
+ return PPA_SRM_ROTATION_ANGLE_0;
1757
+ }
1758
+ }
1759
+
1760
+ bool rotateLogicalRectToPanelWithPpa(present::Rect logicalRect, present::Rect panelRect)
1761
+ {
1762
+ if (!frameBuffer_ || !panelFrameBuffer_) return false;
1763
+ logicalRect = clampLogicalRect(logicalRect, logicalWidth(), logicalHeight());
1764
+ panelRect = present::clampAndAlign(panelRect, kNativeWidth, kNativeHeight);
1765
+ if (!present::valid(logicalRect) || !present::valid(panelRect)) return true;
1766
+ if (!initPpaSrm()) return false;
1767
+
1768
+ const int logicalRectWidth = logicalRect.x1 - logicalRect.x0 + 1;
1769
+ const int logicalRectHeight = logicalRect.y1 - logicalRect.y0 + 1;
1770
+ const std::int64_t syncStartUs = esp_timer_get_time();
1771
+ if (!syncFrameBufferRectToMemory(logicalRect) || !syncPanelFrameBufferRectToMemory(panelRect)) {
1772
+ flushStats_.copyUs += esp_timer_get_time() - syncStartUs;
1773
+ return false;
1774
+ }
1775
+ flushStats_.copyUs += esp_timer_get_time() - syncStartUs;
1776
+
1777
+ ppa_srm_oper_config_t config{};
1778
+ config.in.buffer = frameBuffer_;
1779
+ config.in.pic_w = static_cast<std::uint32_t>(logicalWidth());
1780
+ config.in.pic_h = static_cast<std::uint32_t>(logicalHeight());
1781
+ config.in.block_w = static_cast<std::uint32_t>(logicalRectWidth);
1782
+ config.in.block_h = static_cast<std::uint32_t>(logicalRectHeight);
1783
+ config.in.block_offset_x = static_cast<std::uint32_t>(logicalRect.x0);
1784
+ config.in.block_offset_y = static_cast<std::uint32_t>(logicalRect.y0);
1785
+ config.in.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
1786
+ config.out.buffer = panelFrameBuffer_;
1787
+ config.out.buffer_size = static_cast<std::uint32_t>(kMaxPixels * sizeof(std::uint16_t));
1788
+ config.out.pic_w = kNativeWidth;
1789
+ config.out.pic_h = kNativeHeight;
1790
+ config.out.block_offset_x = static_cast<std::uint32_t>(panelRect.x0);
1791
+ config.out.block_offset_y = static_cast<std::uint32_t>(panelRect.y0);
1792
+ config.out.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
1793
+ config.rotation_angle = ppaRotationForCurrentOrientation();
1794
+ config.scale_x = 1.0f;
1795
+ config.scale_y = 1.0f;
1796
+ config.mode = PPA_TRANS_MODE_BLOCKING;
1797
+
1798
+ const std::int64_t ppaStartUs = esp_timer_get_time();
1799
+ const esp_err_t err = ppa_do_scale_rotate_mirror(ppaSrmClient_, &config);
1800
+ flushStats_.txUs += esp_timer_get_time() - ppaStartUs;
1801
+ if (err != ESP_OK) {
1802
+ if (!ppaWarned_) {
1803
+ ppaWarned_ = true;
1804
+ ESP_LOGE(kTag, "PPA SRM present failed: %s", esp_err_to_name(err));
1805
+ }
1806
+ return false;
1807
+ }
1808
+ return true;
1809
+ }
1810
+
1811
+ bool enableDsiPhyPower()
1812
+ {
1813
+ if (dsiPhyPower_) return true;
1814
+ esp_ldo_channel_config_t ldoConfig{};
1815
+ ldoConfig.chan_id = kDsiPhyLdoChannel;
1816
+ ldoConfig.voltage_mv = kDsiPhyLdoVoltageMv;
1817
+ const esp_err_t err = esp_ldo_acquire_channel(&ldoConfig, &dsiPhyPower_);
1818
+ if (err != ESP_OK) {
1819
+ ESP_LOGE(kTag, "DSI PHY LDO enable failed: %s", esp_err_to_name(err));
1820
+ return false;
1821
+ }
1822
+ ESP_LOGI(kTag, "DSI PHY powered on LDO%d %dmV", kDsiPhyLdoChannel, kDsiPhyLdoVoltageMv);
1823
+ return true;
1824
+ }
1825
+
1826
+ bool initBacklight()
1827
+ {
1828
+ if (brightnessInitialized_) return true;
1829
+
1830
+ ledc_timer_config_t timerConfig{};
1831
+ timerConfig.speed_mode = LEDC_LOW_SPEED_MODE;
1832
+ timerConfig.duty_resolution = LEDC_TIMER_10_BIT;
1833
+ timerConfig.timer_num = kBacklightLedcTimer;
1834
+ timerConfig.freq_hz = 5000;
1835
+ timerConfig.clk_cfg = LEDC_AUTO_CLK;
1836
+ esp_err_t err = ledc_timer_config(&timerConfig);
1837
+ if (err != ESP_OK) {
1838
+ ESP_LOGE(kTag, "backlight LEDC timer init failed: %s", esp_err_to_name(err));
1839
+ return false;
1840
+ }
1841
+
1842
+ ledc_channel_config_t channelConfig{};
1843
+ channelConfig.gpio_num = gea::platform::board::display.backlight;
1844
+ channelConfig.speed_mode = LEDC_LOW_SPEED_MODE;
1845
+ channelConfig.channel = kBacklightLedcChannel;
1846
+ channelConfig.timer_sel = kBacklightLedcTimer;
1847
+ channelConfig.duty = 0;
1848
+ channelConfig.hpoint = 0;
1849
+ err = ledc_channel_config(&channelConfig);
1850
+ if (err != ESP_OK) {
1851
+ ESP_LOGE(kTag, "backlight LEDC channel init failed: %s", esp_err_to_name(err));
1852
+ return false;
1853
+ }
1854
+
1855
+ brightnessInitialized_ = true;
1856
+ updateBacklightDuty();
1857
+ return true;
1858
+ }
1859
+
1860
+ void updateBacklightDuty()
1861
+ {
1862
+ const std::uint32_t duty = static_cast<std::uint32_t>((kBacklightLedcMaxDuty * brightness_) / 100);
1863
+ const esp_err_t setErr = ledc_set_duty(LEDC_LOW_SPEED_MODE, kBacklightLedcChannel, duty);
1864
+ const esp_err_t updateErr = ledc_update_duty(LEDC_LOW_SPEED_MODE, kBacklightLedcChannel);
1865
+ if (setErr != ESP_OK || updateErr != ESP_OK) {
1866
+ ESP_LOGE(kTag, "backlight duty update failed: set=%s update=%s",
1867
+ esp_err_to_name(setErr),
1868
+ esp_err_to_name(updateErr));
1869
+ }
1870
+ }
1871
+
1872
+ bool initPanel()
1873
+ {
1874
+ if (panel_) return true;
1875
+ if (!initBacklight() || !enableDsiPhyPower()) return false;
1876
+
1877
+ esp_lcd_dsi_bus_config_t busConfig{};
1878
+ busConfig.bus_id = 0;
1879
+ busConfig.num_data_lanes = kDsiLaneCount;
1880
+ busConfig.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT;
1881
+ busConfig.lane_bit_rate_mbps = kDsiLaneBitrateMbps;
1882
+ esp_err_t err = esp_lcd_new_dsi_bus(&busConfig, &mipiDsiBus_);
1883
+ if (err != ESP_OK) {
1884
+ ESP_LOGE(kTag, "DSI bus init failed: %s", esp_err_to_name(err));
1885
+ return false;
1886
+ }
1887
+
1888
+ esp_lcd_dbi_io_config_t dbiConfig{};
1889
+ dbiConfig.virtual_channel = 0;
1890
+ dbiConfig.lcd_cmd_bits = 8;
1891
+ dbiConfig.lcd_param_bits = 8;
1892
+ err = esp_lcd_new_panel_io_dbi(mipiDsiBus_, &dbiConfig, &io_);
1893
+ if (err != ESP_OK) {
1894
+ ESP_LOGE(kTag, "DSI DBI IO init failed: %s", esp_err_to_name(err));
1895
+ return false;
1896
+ }
1897
+
1898
+ esp_lcd_dpi_panel_config_t dpiConfig{};
1899
+ dpiConfig.virtual_channel = 0;
1900
+ dpiConfig.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT;
1901
+ dpiConfig.dpi_clock_freq_mhz = kDpiClockMhz;
1902
+ dpiConfig.in_color_format = lcdColorFormat(kFramebufferPixelFormat);
1903
+ dpiConfig.out_color_format = lcdColorFormat(kDsiOutputPixelFormat);
1904
+ dpiConfig.num_fbs = kDpiFrameBufferCount;
1905
+ dpiConfig.video_timing = videoTiming();
1906
+
1907
+ std::uint16_t panelInitCommandCount = 0;
1908
+ const ili9881c_lcd_init_cmd_t *panelInitCommands = waveshareIli9881cInitCommands(&panelInitCommandCount);
1909
+
1910
+ ili9881c_vendor_config_t vendorConfig{};
1911
+ vendorConfig.init_cmds = panelInitCommands;
1912
+ vendorConfig.init_cmds_size = panelInitCommandCount;
1913
+ vendorConfig.mipi_config.dsi_bus = mipiDsiBus_;
1914
+ vendorConfig.mipi_config.dpi_config = &dpiConfig;
1915
+ vendorConfig.mipi_config.lane_num = kDsiLaneCount;
1916
+
1917
+ esp_lcd_panel_dev_config_t panelConfig{};
1918
+ panelConfig.reset_gpio_num = gea::platform::board::display.reset;
1919
+ panelConfig.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
1920
+ panelConfig.bits_per_pixel = kPanelBitsPerPixel;
1921
+ panelConfig.vendor_config = &vendorConfig;
1922
+
1923
+ err = esp_lcd_new_panel_ili9881c(io_, &panelConfig, &panel_);
1924
+ if (err != ESP_OK) {
1925
+ ESP_LOGE(kTag, "ILI9881C panel create failed: %s", esp_err_to_name(err));
1926
+ return false;
1927
+ }
1928
+ err = esp_lcd_panel_reset(panel_);
1929
+ if (err != ESP_OK) {
1930
+ ESP_LOGE(kTag, "panel reset failed: %s", esp_err_to_name(err));
1931
+ return false;
1932
+ }
1933
+ err = esp_lcd_panel_init(panel_);
1934
+ if (err != ESP_OK) {
1935
+ ESP_LOGE(kTag, "panel init failed: %s", esp_err_to_name(err));
1936
+ return false;
1937
+ }
1938
+ void *fb0 = nullptr;
1939
+ void *fb1 = nullptr;
1940
+ err = esp_lcd_dpi_panel_get_frame_buffer(panel_, kDpiFrameBufferCount, &fb0, &fb1);
1941
+ if (err == ESP_OK && fb0) {
1942
+ panelFrameBuffers_[0] = static_cast<std::uint16_t *>(fb0);
1943
+ panelFrameBuffers_[1] = static_cast<std::uint16_t *>(fb1); // null when num_fbs == 1
1944
+ scannedFbIndex_ = 0; // the driver scans fb0 first
1945
+ panelFrameBuffer_ = panelFrameBuffers_[0];
1946
+ ESP_LOGI(kTag, "using DPI panel framebuffers fb0=%p fb1=%p", panelFrameBuffers_[0], panelFrameBuffers_[1]);
1947
+ } else {
1948
+ ESP_LOGE(kTag, "DPI panel framebuffer unavailable: %s", esp_err_to_name(err));
1949
+ return false;
1950
+ }
1951
+ // Refresh-boundary signal for scan-aligned double-buffer flips: a
1952
+ // draw_bitmap buffer swap only latches at the next frame restart, so a
1953
+ // producer must not write the just-released buffer until one refresh
1954
+ // completes (else its base fill lands on the still-scanned frame —
1955
+ // visible as white flashes while panning).
1956
+ refreshDoneSem_ = xSemaphoreCreateBinary();
1957
+ if (refreshDoneSem_) {
1958
+ esp_lcd_dpi_panel_event_callbacks_t cbs{};
1959
+ cbs.on_refresh_done = [](esp_lcd_panel_handle_t, esp_lcd_dpi_panel_event_data_t *, void *ctx) -> bool {
1960
+ BaseType_t woken = pdFALSE;
1961
+ xSemaphoreGiveFromISR(static_cast<SemaphoreHandle_t>(ctx), &woken);
1962
+ return woken == pdTRUE;
1963
+ };
1964
+ if (esp_lcd_dpi_panel_register_event_callbacks(panel_, &cbs, refreshDoneSem_) != ESP_OK) {
1965
+ ESP_LOGW(kTag, "refresh-done callback unavailable; panel-direct flips stay unaligned");
1966
+ vSemaphoreDelete(refreshDoneSem_);
1967
+ refreshDoneSem_ = nullptr;
1968
+ }
1969
+ }
1970
+ err = esp_lcd_panel_disp_on_off(panel_, true);
1971
+ if (err != ESP_OK) {
1972
+ ESP_LOGE(kTag, "panel on failed: %s", esp_err_to_name(err));
1973
+ return false;
1974
+ }
1975
+
1976
+ // One-shot GDMA bandwidth probe: can the AXI DMA move a full frame
1977
+ // between PSRAM buffers materially faster than the PPA's measured
1978
+ // ~86MB/s or the CPU's ~120MB/s? Decides whether map pans should be a
1979
+ // DMA content-shift + strip raster. The buffers get fully overwritten
1980
+ // by the first present, so the copy is harmless.
1981
+ if (panelFrameBuffers_[1] && ownedFrameBuffer_) {
1982
+ async_memcpy_config_t mcpConfig{};
1983
+ mcpConfig.backlog = 4;
1984
+ mcpConfig.dma_burst_size = 64;
1985
+ async_memcpy_handle_t mcp = nullptr;
1986
+ if (esp_async_memcpy_install_gdma_axi(&mcpConfig, &mcp) == ESP_OK) {
1987
+ SemaphoreHandle_t done = xSemaphoreCreateBinary();
1988
+ auto benchCb = [](async_memcpy_handle_t, async_memcpy_event_t *, void *ctx) -> bool {
1989
+ BaseType_t woken = pdFALSE;
1990
+ xSemaphoreGiveFromISR(static_cast<SemaphoreHandle_t>(ctx), &woken);
1991
+ return woken == pdTRUE;
1992
+ };
1993
+ const std::size_t benchBytes = static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t);
1994
+ const std::int64_t benchStart = esp_timer_get_time();
1995
+ if (done &&
1996
+ esp_async_memcpy(mcp, panelFrameBuffers_[1], ownedFrameBuffer_, benchBytes, benchCb, done) == ESP_OK &&
1997
+ xSemaphoreTake(done, pdMS_TO_TICKS(500)) == pdTRUE) {
1998
+ const std::int64_t benchUs = esp_timer_get_time() - benchStart;
1999
+ ESP_LOGI(kTag, "GDMA bench: %u bytes in %lld us = %.1f MB/s", static_cast<unsigned>(benchBytes),
2000
+ static_cast<long long>(benchUs), benchUs > 0 ? benchBytes / static_cast<double>(benchUs) : 0.0);
2001
+ } else {
2002
+ ESP_LOGW(kTag, "GDMA bench failed");
2003
+ }
2004
+ if (done) vSemaphoreDelete(done);
2005
+ // Keep the channel: the landscape pan fast path uses it to
2006
+ // shift-copy the map region (~15.5ms DMA, overlapped with the
2007
+ // CPU strip raster) instead of a ~22ms CPU memcpy.
2008
+ mcp_ = mcp;
2009
+ mcpDone_ = xSemaphoreCreateBinary();
2010
+ } else {
2011
+ ESP_LOGW(kTag, "GDMA AXI async-memcpy unavailable");
2012
+ }
2013
+ }
2014
+ ESP_LOGI(kTag,
2015
+ "ILI9881C DSI panel ready lanes=%d bitrate=%.0fMbps clock=%.0fMHz fb=%s out=%s panel_bpp=%d dpi_fbs=%d init_cmds=%u",
2016
+ kDsiLaneCount,
2017
+ kDsiLaneBitrateMbps,
2018
+ kDpiClockMhz,
2019
+ pixel::name(kFramebufferPixelFormat),
2020
+ pixel::name(kDsiOutputPixelFormat),
2021
+ kPanelBitsPerPixel,
2022
+ kDpiFrameBufferCount,
2023
+ static_cast<unsigned>(panelInitCommandCount));
2024
+ return true;
2025
+ }
2026
+
2027
+ bool flushNativeLogicalRect(present::Rect logicalRect)
2028
+ {
2029
+ logicalRect = clampLogicalRect(logicalRect, logicalWidth(), logicalHeight());
2030
+ if (!present::valid(logicalRect)) return true;
2031
+ const present::Rect panelRect = physicalBoundsForLogicalRect(logicalRect);
2032
+ if (!present::valid(panelRect)) return true;
2033
+ using gea::framework::display::DisplayOrientation;
2034
+ const bool directRows =
2035
+ orientation_detail::DisplayOrientationState::orientation() == DisplayOrientation::PortraitPrimary;
2036
+
2037
+ take();
2038
+ bindCanvasLocked();
2039
+ if (!panel_) {
2040
+ give();
2041
+ return false;
2042
+ }
2043
+ bool ok = true;
2044
+ const int panelWidth = panelRect.x1 - panelRect.x0 + 1;
2045
+ const int panelHeight = panelRect.y1 - panelRect.y0 + 1;
2046
+ if (directRows && usingPanelFrameBufferDirectly()) {
2047
+ const std::int64_t syncStartUs = esp_timer_get_time();
2048
+ // NOTE: this full-frame cache writeback (~40ms for 720x1280) is the dominant
2049
+ // per-frame cost. Splitting it across both cores was measured to be a net loss
2050
+ // (21.6->19.4fps, flush 40->44ms): it is PSRAM-write-bandwidth-bound, so two
2051
+ // cores just contend for the same bus while adding handshake latency. The 40ms
2052
+ // is a hard bandwidth floor for a full-screen redraw on this DSI panel.
2053
+ ok = syncFrameBufferRectToMemory(logicalRect);
2054
+ flushStats_.copyUs += esp_timer_get_time() - syncStartUs;
2055
+ flushStats_.chunkCount++;
2056
+ flushStats_.pixelCount += panelWidth * panelHeight;
2057
+ give();
2058
+ return ok;
2059
+ }
2060
+
2061
+ if (frameBuffer_ != ownedFrameBuffer_) {
2062
+ ESP_LOGE(kTag, "rotated flush requires the owned framebuffer");
2063
+ give();
2064
+ return false;
2065
+ }
2066
+ if (scrollOriginX_ != 0 || scrollOriginY_ != 0) {
2067
+ // Torus mode: the logical rect's pixels live at wrapped framebuffer
2068
+ // locations — sync + rotate each part separately.
2069
+ TorusPart parts[4];
2070
+ const int count = splitLogicalRectToTorus(logicalRect, parts);
2071
+ ok = true;
2072
+ for (int i = 0; i < count && ok; ++i) {
2073
+ const TorusPart &part = parts[i];
2074
+ const std::int64_t syncStartUs = esp_timer_get_time();
2075
+ ok = syncTorusPartToMemory(part);
2076
+ flushStats_.copyUs += esp_timer_get_time() - syncStartUs;
2077
+ if (!ok) break;
2078
+ const int w = part.torus.x1 - part.torus.x0 + 1;
2079
+ const int h = part.torus.y1 - part.torus.y0 + 1;
2080
+ const present::Rect partLogical{part.logicalX, part.logicalY, part.logicalX + w - 1, part.logicalY + h - 1};
2081
+ ok = rotateTorusPartToPanelWithPpa(part, physicalBoundsForLogicalRect(partLogical));
2082
+ }
2083
+ if (ok) {
2084
+ flushStats_.chunkCount++;
2085
+ flushStats_.pixelCount += panelWidth * panelHeight;
2086
+ }
2087
+ give();
2088
+ return ok;
2089
+ }
2090
+ ok = rotateLogicalRectToPanelWithPpa(logicalRect, panelRect);
2091
+ if (ok) {
2092
+ flushStats_.chunkCount++;
2093
+ flushStats_.pixelCount += panelWidth * panelHeight;
2094
+ }
2095
+ give();
2096
+ return ok;
2097
+ }
2098
+
2099
+ // ---- Scroll-origin (torus) panning -------------------------------------
2100
+ // A pan repaints the whole screen even though 80-90% of the pixels are the
2101
+ // SAME content at a shifted address — and a full-screen repaint is bus-
2102
+ // bound (~9MB of PSRAM traffic ≈ 60-90ms). Instead, when a frame is the
2103
+ // previous frame uniformly shifted by (dx,dy), move the framebuffer's READ
2104
+ // ORIGIN (treating it as a wrapping scroll surface) and raster only the
2105
+ // newly exposed strips. The PPA rotate pass — which runs anyway — assembles
2106
+ // the wrapped quadrants into the panel buffer. Pan frames drop from ~921k
2107
+ // rastered pixels to the strip area (~30-80k).
2108
+
2109
+ static int wrapCoord(int v, int size)
2110
+ {
2111
+ int m = v % size;
2112
+ return m < 0 ? m + size : m;
2113
+ }
2114
+
2115
+ // A logical-space rect mapped onto the torus: `torus` is where the pixels
2116
+ // live in the framebuffer; logicalX/logicalY are the content coordinates of
2117
+ // its top-left corner.
2118
+ struct TorusPart {
2119
+ present::Rect torus;
2120
+ int logicalX;
2121
+ int logicalY;
2122
+ };
2123
+
2124
+ int splitLogicalRectToTorus(const present::Rect &logical, TorusPart out[4]) const
2125
+ {
2126
+ const int w = logicalWidth();
2127
+ const int h = logicalHeight();
2128
+ const int rectW = logical.x1 - logical.x0 + 1;
2129
+ const int rectH = logical.y1 - logical.y0 + 1;
2130
+ if (rectW <= 0 || rectH <= 0) return 0;
2131
+ const int startX = wrapCoord(logical.x0 + scrollOriginX_, w);
2132
+ const int startY = wrapCoord(logical.y0 + scrollOriginY_, h);
2133
+ const int xw0 = std::min(rectW, w - startX);
2134
+ const int yh0 = std::min(rectH, h - startY);
2135
+ struct Seg {
2136
+ int torusStart;
2137
+ int logicalStart;
2138
+ int size;
2139
+ };
2140
+ const Seg xs[2] = {{startX, logical.x0, xw0}, {0, logical.x0 + xw0, rectW - xw0}};
2141
+ const Seg ys[2] = {{startY, logical.y0, yh0}, {0, logical.y0 + yh0, rectH - yh0}};
2142
+ int count = 0;
2143
+ for (const Seg &sy : ys) {
2144
+ if (sy.size <= 0) continue;
2145
+ for (const Seg &sx : xs) {
2146
+ if (sx.size <= 0) continue;
2147
+ out[count].torus = {sx.torusStart, sy.torusStart, sx.torusStart + sx.size - 1, sy.torusStart + sy.size - 1};
2148
+ out[count].logicalX = sx.logicalStart;
2149
+ out[count].logicalY = sy.logicalStart;
2150
+ count++;
2151
+ }
2152
+ }
2153
+ return count;
2154
+ }
2155
+
2156
+ // Write back one torus part's framebuffer rows to PSRAM (so the PPA's DMA
2157
+ // reads see them).
2158
+ bool syncTorusPartToMemory(const TorusPart &part)
2159
+ {
2160
+ return syncBufferRectToMemory(frameBuffer_, logicalStride_, logicalStride_, logicalHeight(), part.torus,
2161
+ "torus framebuffer part");
2162
+ }
2163
+
2164
+ // True when `current` equals `previous` with every image command shifted by
2165
+ // one uniform integer (dx,dy) (matched by pixel pointer + draw size) and an
2166
+ // identical opaque base. Unmatched commands (edge tiles entering the view)
2167
+ // are fine — the caller rasters their bounds. At least 2/3 must match so a
2168
+ // zoom (where sizes change) never false-positives.
2169
+ static bool detectUniformShift(const present::Frame &previous, const present::Frame &current, int *dx, int *dy)
2170
+ {
2171
+ using Type = gea::platform::display::DisplayPresentCommandType;
2172
+ if (previous.commands.size() < 2 || current.commands.size() < 2) return false;
2173
+ if (!present::commandsEqual(previous.commands[0], current.commands[0])) return false;
2174
+ bool have = false;
2175
+ int sx = 0;
2176
+ int sy = 0;
2177
+ int matched = 0;
2178
+ int images = 0;
2179
+ for (std::size_t i = 1; i < current.commands.size(); ++i) {
2180
+ const present::Command &c = current.commands[i];
2181
+ if (c.type != Type::DrawImage && c.type != Type::DrawImageScaled) return false;
2182
+ images++;
2183
+ for (std::size_t j = 1; j < previous.commands.size(); ++j) {
2184
+ const present::Command &p = previous.commands[j];
2185
+ if (p.type != c.type || p.pixels != c.pixels) continue;
2186
+ if (p.srcWidth != c.srcWidth || p.srcHeight != c.srcHeight) continue;
2187
+ if (c.type == Type::DrawImageScaled && (p.w != c.w || p.h != c.h)) continue;
2188
+ const int candX = c.x - p.x;
2189
+ const int candY = c.y - p.y;
2190
+ if (!have) {
2191
+ have = true;
2192
+ sx = candX;
2193
+ sy = candY;
2194
+ } else if (candX != sx || candY != sy) {
2195
+ return false;
2196
+ }
2197
+ matched++;
2198
+ break;
2199
+ }
2200
+ }
2201
+ if (!have || (sx == 0 && sy == 0)) return false;
2202
+ if (matched * 3 < images * 2) return false;
2203
+ *dx = sx;
2204
+ *dy = sy;
2205
+ return true;
2206
+ }
2207
+
2208
+ // Rotate the full torus surface into the panel buffer: one PPA op per
2209
+ // wrapped quadrant (1, 2, or 4 big ops — efficient, unlike per-tile ops).
2210
+ // Sources must already be written back (strips are synced at raster time;
2211
+ // everything else was synced when it was last rastered).
2212
+ bool flushFullPanelFromTorus()
2213
+ {
2214
+ const present::Rect full{0, 0, logicalWidth() - 1, logicalHeight() - 1};
2215
+ TorusPart parts[4];
2216
+ const int count = splitLogicalRectToTorus(full, parts);
2217
+ take();
2218
+ bindCanvasLocked();
2219
+ if (!panel_ || frameBuffer_ != ownedFrameBuffer_) {
2220
+ give();
2221
+ return false;
2222
+ }
2223
+ bool ok = true;
2224
+ for (int i = 0; i < count && ok; ++i) {
2225
+ const TorusPart &part = parts[i];
2226
+ const int w = part.torus.x1 - part.torus.x0 + 1;
2227
+ const int h = part.torus.y1 - part.torus.y0 + 1;
2228
+ const present::Rect logicalRect{part.logicalX, part.logicalY, part.logicalX + w - 1, part.logicalY + h - 1};
2229
+ const present::Rect panelRect = physicalBoundsForLogicalRect(logicalRect);
2230
+ if (!present::valid(panelRect)) continue;
2231
+ ok = rotateTorusPartToPanelWithPpa(part, panelRect);
2232
+ }
2233
+ if (ok) {
2234
+ flushStats_.chunkCount++;
2235
+ flushStats_.pixelCount += logicalWidth() * logicalHeight();
2236
+ }
2237
+ give();
2238
+ return ok;
2239
+ }
2240
+
2241
+ // Like rotateLogicalRectToPanelWithPpa, but the source block sits at the
2242
+ // part's TORUS coordinates while the panel destination comes from its
2243
+ // LOGICAL rect. No source cache sync here — the caller guarantees it.
2244
+ bool rotateTorusPartToPanelWithPpa(const TorusPart &part, present::Rect panelRect)
2245
+ {
2246
+ if (!frameBuffer_ || !panelFrameBuffer_) return false;
2247
+ panelRect = present::clampAndAlign(panelRect, kNativeWidth, kNativeHeight);
2248
+ if (!present::valid(panelRect)) return true;
2249
+ if (!initPpaSrm()) return false;
2250
+
2251
+ ppa_srm_oper_config_t config{};
2252
+ config.in.buffer = frameBuffer_;
2253
+ config.in.pic_w = static_cast<std::uint32_t>(logicalWidth());
2254
+ config.in.pic_h = static_cast<std::uint32_t>(logicalHeight());
2255
+ config.in.block_w = static_cast<std::uint32_t>(part.torus.x1 - part.torus.x0 + 1);
2256
+ config.in.block_h = static_cast<std::uint32_t>(part.torus.y1 - part.torus.y0 + 1);
2257
+ config.in.block_offset_x = static_cast<std::uint32_t>(part.torus.x0);
2258
+ config.in.block_offset_y = static_cast<std::uint32_t>(part.torus.y0);
2259
+ config.in.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
2260
+ config.out.buffer = panelFrameBuffer_;
2261
+ config.out.buffer_size = static_cast<std::uint32_t>(kMaxPixels * sizeof(std::uint16_t));
2262
+ config.out.pic_w = kNativeWidth;
2263
+ config.out.pic_h = kNativeHeight;
2264
+ config.out.block_offset_x = static_cast<std::uint32_t>(panelRect.x0);
2265
+ config.out.block_offset_y = static_cast<std::uint32_t>(panelRect.y0);
2266
+ config.out.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
2267
+ config.rotation_angle = ppaRotationForCurrentOrientation();
2268
+ config.scale_x = 1.0f;
2269
+ config.scale_y = 1.0f;
2270
+ config.mode = PPA_TRANS_MODE_BLOCKING;
2271
+
2272
+ const std::int64_t ppaStartUs = esp_timer_get_time();
2273
+ const esp_err_t err = ppa_do_scale_rotate_mirror(ppaSrmClient_, &config);
2274
+ flushStats_.txUs += esp_timer_get_time() - ppaStartUs;
2275
+ return err == ESP_OK;
2276
+ }
2277
+
2278
+ // True when the frame is an opaque base followed by raster-safe commands —
2279
+ // originally OPAQUE IMAGE BLITS only (the tile grid), now also opaque
2280
+ // fills and text (the in-canvas sidebar): the panel-direct path does a
2281
+ // FULL re-raster in painter's order every frame, so any command the chunk
2282
+ // rasterizer supports is z-order-safe. Images must be opaque + aligned.
2283
+ static inline int gTileShapeFailKind = 0;
2284
+ static inline int gTileShapeFailType = 0;
2285
+ static inline int gTileShapeFailCount = 0;
2286
+
2287
+ // Landscape pan fast path: previous frame's panel-space commands, used to
2288
+ // detect a pure translation and to dirty the moved small rects (pins).
2289
+ struct LandPrevCmd {
2290
+ const std::uint16_t *pixels;
2291
+ std::int16_t type;
2292
+ int x, y, w, h;
2293
+ };
2294
+ // Panel row where the (static) sidebar begins in landscape: the rail
2295
+ // occupies landscape x < 220 -> panel rows >= kNativeHeight - 220.
2296
+ static constexpr int kRailPanelRow = kNativeHeight - 220;
2297
+ static constexpr int kLandPrevMax = 192;
2298
+ // Last landscape frame's phase timings (never reset; GEADEV diagnostics).
2299
+ int landTotalUs_ = 0;
2300
+ int landAlignUs_ = 0;
2301
+ int landRasterUs_ = 0;
2302
+ int landTextUs_ = 0;
2303
+ int landFlipUs_ = 0;
2304
+ int landPanMode_ = 0;
2305
+ int landPanFrames_ = 0;
2306
+ int landFullFrames_ = 0;
2307
+ async_memcpy_handle_t mcp_ = nullptr;
2308
+ SemaphoreHandle_t mcpDone_ = nullptr;
2309
+ // Pan-path phase timings (us) for GEADEV LANDPAN.
2310
+ int panDetectUs_ = 0;
2311
+ int panKickUs_ = 0;
2312
+ int panStripUs_ = 0;
2313
+ int panWaitUs_ = 0;
2314
+ int panInteriorUs_ = 0;
2315
+ int panDmaErr_ = -1;
2316
+ // Why the last non-pan landscape frame bailed: 1=no snapshot, 2=no delta,
2317
+ // 3=inconsistent deltas, 4=too few pairs, 5=delta too large, 6=dirty overflow.
2318
+ int panBailReason_ = 0;
2319
+ int panBailCounts_[7] = {0, 0, 0, 0, 0, 0, 0};
2320
+ // One snapshot per scanout buffer: the pan path rasters against the
2321
+ // content ALREADY in the back buffer (frame N-2 for that buffer), so the
2322
+ // delta must be measured against that frame's command set.
2323
+ LandPrevCmd landPrev_[2][kLandPrevMax];
2324
+ int landPrevCount_[2] = {0, 0};
2325
+ bool landPrevValid_[2] = {false, false};
2326
+ // Hash of the rail-region commands (fills below kRailPanelRow + all text):
2327
+ // the pan path skips rail rows entirely, so ANY rail change must force a
2328
+ // full raster or sidebar state changes (search keyboard, zoom label)
2329
+ // never reach the glass.
2330
+ std::uint32_t landPrevRailHash_[2] = {0, 0};
2331
+
2332
+ static std::uint32_t railContentHash(const present::Frame &frame, int width, int height)
2333
+ {
2334
+ using Type = gea::platform::display::DisplayPresentCommandType;
2335
+ std::uint32_t h = 2166136261u;
2336
+ auto mix = [&h](std::uint32_t v) {
2337
+ h ^= v;
2338
+ h *= 16777619u;
2339
+ };
2340
+ for (const present::Command &cmd : frame.commands) {
2341
+ if (cmd.type == Type::FillText) {
2342
+ mix(static_cast<std::uint32_t>(cmd.x * 31 + cmd.y));
2343
+ mix(cmd.color);
2344
+ for (char c : cmd.text) mix(static_cast<std::uint32_t>(c));
2345
+ continue;
2346
+ }
2347
+ if (cmd.type != Type::FillRectRgb565) continue;
2348
+ const present::Rect b = present::commandBounds(cmd, width, height);
2349
+ if (!present::valid(b) || b.y0 < height - 220) continue;
2350
+ mix(static_cast<std::uint32_t>(cmd.x * 31 + cmd.y));
2351
+ mix(static_cast<std::uint32_t>(cmd.w * 31 + cmd.h));
2352
+ mix(cmd.color);
2353
+ }
2354
+ return h;
2355
+ }
2356
+
2357
+ static bool framePpaTileEligible(const present::Frame &frame)
2358
+ {
2359
+ using Type = gea::platform::display::DisplayPresentCommandType;
2360
+ auto fail = [&](int kind, int type) {
2361
+ gTileShapeFailKind = kind;
2362
+ gTileShapeFailType = type;
2363
+ gTileShapeFailCount++;
2364
+ return false;
2365
+ };
2366
+ if (frame.commands.size() < 2) return fail(1, static_cast<int>(frame.commands.size()));
2367
+ for (std::size_t i = 1; i < frame.commands.size(); ++i) {
2368
+ const present::Command &cmd = frame.commands[i];
2369
+ if (cmd.type == Type::FillRectRgb565 || cmd.type == Type::FillText) {
2370
+ if (cmd.alpha != 255) return fail(2, static_cast<int>(cmd.type));
2371
+ continue;
2372
+ }
2373
+ if (cmd.type != Type::DrawImage && cmd.type != Type::DrawImageScaled) return fail(3, static_cast<int>(cmd.type));
2374
+ if (cmd.alphaPixels || cmd.alpha != 255 || !cmd.pixels) return fail(4, static_cast<int>(cmd.type));
2375
+ if (cmd.srcWidth <= 0 || cmd.srcHeight <= 0) return fail(5, static_cast<int>(cmd.type));
2376
+ if ((reinterpret_cast<std::uintptr_t>(cmd.pixels) & 63) != 0) return fail(6, static_cast<int>(cmd.type));
2377
+ }
2378
+ return true;
2379
+ }
2380
+
2381
+ // Raster an eligible tile frame for one region with the PPA doing the pixel
2382
+ // hauling: the CPU only fills the opaque base; every tile is a hardware DMA
2383
+ // blit (with scaling) straight into the logical framebuffer. The CPU raster
2384
+ // costs ~70-100ms for a full 720x1280 composite (PSRAM bandwidth through
2385
+ // the cache); the PPA does the same haul in ~15ms with the CPU free.
2386
+ // Returns false (caller falls back to the CPU raster) when a SCALED blit
2387
+ // only partially intersects the region — PPA block offsets can't express
2388
+ // that clip exactly — or when a PPA op is rejected.
2389
+ bool ppaRasterTileRegion(const present::Frame &frame, const present::Rect &region)
2390
+ {
2391
+ if (!frameBuffer_ || !initPpaSrm()) return false;
2392
+ using Type = gea::platform::display::DisplayPresentCommandType;
2393
+ for (std::size_t i = 1; i < frame.commands.size(); ++i) {
2394
+ const present::Command &cmd = frame.commands[i];
2395
+ if (cmd.type != Type::DrawImageScaled) continue;
2396
+ if (cmd.w == cmd.srcWidth && cmd.h == cmd.srcHeight) continue;
2397
+ const present::Rect dst = present::rectFromBox(cmd.x, cmd.y, cmd.w, cmd.h);
2398
+ const bool outside = dst.x1 < region.x0 || dst.x0 > region.x1 || dst.y1 < region.y0 || dst.y0 > region.y1;
2399
+ const bool inside = dst.x0 >= region.x0 && dst.y0 >= region.y0 && dst.x1 <= region.x1 && dst.y1 <= region.y1;
2400
+ if (!outside && !inside) return false;
2401
+ const float sx = static_cast<float>(cmd.w) / cmd.srcWidth;
2402
+ const float sy = static_cast<float>(cmd.h) / cmd.srcHeight;
2403
+ // PPA SRM scale range is [1/16, 256); stay comfortably inside.
2404
+ if (sx < 0.07f || sy < 0.07f || sx >= 250.0f || sy >= 250.0f) return false;
2405
+ }
2406
+
2407
+ // 1. CPU: opaque base fill across the region (Clear or full-screen fill).
2408
+ const std::uint16_t fillColor = frame.commands.front().color;
2409
+ const int rowWidth = region.x1 - region.x0 + 1;
2410
+ for (int y = region.y0; y <= region.y1; ++y) {
2411
+ std::uint16_t *row = frameBuffer_ + static_cast<std::size_t>(y) * logicalStride_ + region.x0;
2412
+ std::fill_n(row, rowWidth, fillColor);
2413
+ }
2414
+ // 2. Write the fill back to PSRAM so the PPA's writes compose on top.
2415
+ if (!syncFrameBufferRectToMemory(region)) return false;
2416
+
2417
+ // 3. The blits, in painter's order (ancestor fallbacks before exact tiles).
2418
+ for (std::size_t i = 1; i < frame.commands.size(); ++i) {
2419
+ const present::Command &cmd = frame.commands[i];
2420
+ const int dstW = cmd.type == Type::DrawImageScaled ? cmd.w : cmd.srcWidth;
2421
+ const int dstH = cmd.type == Type::DrawImageScaled ? cmd.h : cmd.srcHeight;
2422
+ const bool scaled = dstW != cmd.srcWidth || dstH != cmd.srcHeight;
2423
+ const present::Rect dst = present::rectFromBox(cmd.x, cmd.y, dstW, dstH);
2424
+ const present::Rect inter{std::max(dst.x0, region.x0), std::max(dst.y0, region.y0),
2425
+ std::min(dst.x1, region.x1), std::min(dst.y1, region.y1)};
2426
+ if (!present::valid(inter)) continue;
2427
+
2428
+ ppa_srm_oper_config_t config{};
2429
+ config.in.buffer = const_cast<void *>(static_cast<const void *>(cmd.pixels));
2430
+ config.in.pic_w = static_cast<std::uint32_t>(cmd.srcWidth);
2431
+ config.in.pic_h = static_cast<std::uint32_t>(cmd.srcHeight);
2432
+ if (scaled) {
2433
+ config.in.block_w = static_cast<std::uint32_t>(cmd.srcWidth);
2434
+ config.in.block_h = static_cast<std::uint32_t>(cmd.srcHeight);
2435
+ config.out.block_offset_x = static_cast<std::uint32_t>(dst.x0);
2436
+ config.out.block_offset_y = static_cast<std::uint32_t>(dst.y0);
2437
+ config.scale_x = static_cast<float>(dstW) / cmd.srcWidth;
2438
+ config.scale_y = static_cast<float>(dstH) / cmd.srcHeight;
2439
+ } else {
2440
+ config.in.block_w = static_cast<std::uint32_t>(inter.x1 - inter.x0 + 1);
2441
+ config.in.block_h = static_cast<std::uint32_t>(inter.y1 - inter.y0 + 1);
2442
+ config.in.block_offset_x = static_cast<std::uint32_t>(inter.x0 - dst.x0);
2443
+ config.in.block_offset_y = static_cast<std::uint32_t>(inter.y0 - dst.y0);
2444
+ config.out.block_offset_x = static_cast<std::uint32_t>(inter.x0);
2445
+ config.out.block_offset_y = static_cast<std::uint32_t>(inter.y0);
2446
+ config.scale_x = 1.0f;
2447
+ config.scale_y = 1.0f;
2448
+ }
2449
+ config.in.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
2450
+ config.out.buffer = frameBuffer_;
2451
+ config.out.buffer_size = static_cast<std::uint32_t>(kMaxPixels * sizeof(std::uint16_t));
2452
+ config.out.pic_w = static_cast<std::uint32_t>(logicalStride_);
2453
+ config.out.pic_h = static_cast<std::uint32_t>(logicalHeight());
2454
+ config.out.srm_cm = PPA_SRM_COLOR_MODE_RGB565;
2455
+ config.rotation_angle = PPA_SRM_ROTATION_ANGLE_0;
2456
+ config.mode = PPA_TRANS_MODE_BLOCKING;
2457
+ if (ppa_do_scale_rotate_mirror(ppaSrmClient_, &config) != ESP_OK) return false;
2458
+ }
2459
+
2460
+ // 4. Drop the CPU's now-stale cached copy of the PPA-written rows.
2461
+ // Writeback-then-invalidate over a cache-line-aligned span so neighbor
2462
+ // lines never lose dirty data (M2C demands aligned ranges).
2463
+ {
2464
+ std::uint8_t *start = reinterpret_cast<std::uint8_t *>(frameBuffer_ + static_cast<std::size_t>(region.y0) * logicalStride_);
2465
+ const std::size_t len = static_cast<std::size_t>(region.y1 - region.y0 + 1) * logicalStride_ * sizeof(std::uint16_t);
2466
+ const std::uintptr_t spanStart = reinterpret_cast<std::uintptr_t>(start) & ~static_cast<std::uintptr_t>(127);
2467
+ const std::uintptr_t spanEnd = (reinterpret_cast<std::uintptr_t>(start) + len + 127) & ~static_cast<std::uintptr_t>(127);
2468
+ esp_cache_msync(reinterpret_cast<void *>(spanStart), spanEnd - spanStart,
2469
+ ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_TYPE_DATA);
2470
+ esp_cache_msync(reinterpret_cast<void *>(spanStart), spanEnd - spanStart,
2471
+ ESP_CACHE_MSYNC_FLAG_DIR_M2C | ESP_CACHE_MSYNC_FLAG_TYPE_DATA);
2472
+ }
2473
+ return true;
2474
+ }
2475
+
2476
+ void rasterPresentRegion(const present::Frame &frame, const present::Rect &region)
2477
+ {
2478
+ if (!present::valid(region)) return;
2479
+ // Torus-aware: raster the LOGICAL region into its (possibly wrapped)
2480
+ // framebuffer location(s). With origin (0,0) this is exactly one part at
2481
+ // the identity position — the historical behavior.
2482
+ TorusPart parts[4];
2483
+ const int count = splitLogicalRectToTorus(region, parts);
2484
+ const int height = logicalHeight();
2485
+ const int maxRows = std::max(1, kFlushRowsDefault);
2486
+ for (int p = 0; p < count; ++p) {
2487
+ const TorusPart &part = parts[p];
2488
+ const int width = part.torus.x1 - part.torus.x0 + 1;
2489
+ const int partRows = part.torus.y1 - part.torus.y0 + 1;
2490
+ for (int r = 0; r < partRows; r += maxRows) {
2491
+ int rows = maxRows;
2492
+ if (r + rows > partRows) rows = partRows - r;
2493
+ std::uint16_t *rasterTarget =
2494
+ frameBuffer_ + static_cast<std::size_t>(part.torus.y0 + r) * logicalStride_ + part.torus.x0;
2495
+ const std::int64_t rasterStartUs = esp_timer_get_time();
2496
+ present::rasterFrameRowsStrided(rasterTarget,
2497
+ logicalStride_,
2498
+ part.logicalX,
2499
+ width,
2500
+ part.logicalY + r,
2501
+ rows,
2502
+ height,
2503
+ frame);
2504
+ flushStats_.rasterUs += esp_timer_get_time() - rasterStartUs;
2505
+ }
2506
+ }
2507
+ }
2508
+
2509
+ void take()
2510
+ {
2511
+ if (mutex_) xSemaphoreTake(mutex_, portMAX_DELAY);
2512
+ }
2513
+
2514
+ void give()
2515
+ {
2516
+ if (mutex_) xSemaphoreGive(mutex_);
2517
+ }
2518
+
2519
+ SemaphoreHandle_t mutex_ = nullptr;
2520
+ esp_lcd_panel_handle_t panel_ = nullptr;
2521
+ esp_lcd_panel_io_handle_t io_ = nullptr;
2522
+ esp_lcd_dsi_bus_handle_t mipiDsiBus_ = nullptr;
2523
+ esp_ldo_channel_handle_t dsiPhyPower_ = nullptr;
2524
+ ppa_client_handle_t ppaSrmClient_ = nullptr;
2525
+ std::uint16_t *frameBuffer_ = nullptr;
2526
+ std::uint16_t *ownedFrameBuffer_ = nullptr;
2527
+ std::uint16_t *panelFrameBuffer_ = nullptr; // the buffer the DSI is currently scanning
2528
+ std::uint16_t *panelFrameBuffers_[2] = {nullptr, nullptr}; // both DPI scanout buffers (num_fbs)
2529
+ int scannedFbIndex_ = 0; // which of panelFrameBuffers_ the DSI scans now (driver default 0)
2530
+ std::uint16_t *backgroundCache_ = nullptr;
2531
+ std::uint16_t *backdropCache_ = nullptr;
2532
+ // Scroll origin of the logical framebuffer when it acts as a wrapping
2533
+ // (torus) scroll surface for tile-grid pans; (0,0) = plain linear layout.
2534
+ int scrollOriginX_ = 0;
2535
+ int scrollOriginY_ = 0;
2536
+ // Refresh-boundary semaphore (given at 60Hz by the DPI on_refresh_done ISR)
2537
+ // + the moment of the last double-buffer flip, for scan-aligned writes.
2538
+ SemaphoreHandle_t refreshDoneSem_ = nullptr;
2539
+ std::int64_t lastFlipUs_ = 0;
2540
+ // Landscape pipelined present: the CPU rasters frame N+1 into a compose
2541
+ // ping-pong while the PPA rotates frame N into the panel back buffer —
2542
+ // throughput becomes the rotate alone (~43ms) instead of raster+rotate.
2543
+ std::uint16_t *composeBuffers_[2] = {nullptr, nullptr};
2544
+ int composeIndex_ = 0;
2545
+ SemaphoreHandle_t ppaDoneSem_ = nullptr;
2546
+ bool ppaInFlight_ = false;
2547
+ bool ppaCallbackRegistered_ = false;
2548
+ // The panel buffer is only ever DMA-written in torus mode; one defensive
2549
+ // writeback when entering the mode, then skipped.
2550
+ bool panelSyncedForTorus_ = false;
2551
+ // Panel-direct tile mode: full-frame flips own the scanout; the composed
2552
+ // logical canvas is stale, so its flush is suppressed until transition out.
2553
+ bool panelDirectActive_ = false;
2554
+ // Present-path diagnostics.
2555
+ int presentCalls_ = 0;
2556
+ int pathDirect_ = 0;
2557
+ int pathGeneral_ = 0;
2558
+ int pathExternalFlush_ = 0;
2559
+ int pathRejected_ = 0;
2560
+ gea::framework::graphics::Canvas canvas_;
2561
+ gea::framework::graphics::Canvas workerCanvas_;
2562
+ int logicalStride_ = kMaxLogicalWidth;
2563
+ int renderCoreId_ = -1;
2564
+ int flushRows_ = kFlushRowsDefault;
2565
+ int flushDepth_ = 1;
2566
+ int brightness_ = 100;
2567
+ bool brightnessInitialized_ = false;
2568
+ bool initialized_ = false;
2569
+ bool frameBufferCoherent_ = true;
2570
+ bool cacheSyncWarned_ = false;
2571
+ bool ppaWarned_ = false;
2572
+ bool backgroundCacheAttempted_ = false;
2573
+ bool backdropCacheAttempted_ = false;
2574
+ platform_display::DisplayFlushPerfStats flushStats_{};
2575
+ present::Frame previousPresentFrame_{};
2576
+ bool previousPresentValid_ = false;
2577
+ bool needsFullPhysicalFlush_ = true;
2578
+ };
2579
+
2580
+ } // namespace gea::platform::esp32_p4_waveshare::display
2581
+
2582
+ extern "C" std::uint16_t *gea_bg_cache(int *cap_px)
2583
+ {
2584
+ return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().backgroundCache(cap_px);
2585
+ }
2586
+
2587
+ extern "C" std::uint16_t *gea_backdrop_cache(int *cap_px)
2588
+ {
2589
+ return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().backdropCache(cap_px);
2590
+ }
2591
+
2592
+ namespace {
2593
+
2594
+ struct P4RenderWorker {
2595
+ TaskHandle_t task = nullptr;
2596
+ void (*volatile fn)(void *, int, int) = nullptr;
2597
+ void *volatile ctx = nullptr;
2598
+ volatile int y0 = 0;
2599
+ volatile int y1 = 0;
2600
+ std::atomic<std::uint32_t> jobSeq{0};
2601
+ std::atomic<bool> done{true};
2602
+ bool attempted = false;
2603
+ };
2604
+
2605
+ P4RenderWorker gRenderWorker;
2606
+ volatile std::int64_t gRenderWorkerSubmitUs = 0;
2607
+ std::int64_t gRenderWorkerStartLatencyUs = 0;
2608
+ std::int64_t gRenderWorkerBandUs = 0;
2609
+ std::int64_t gRenderWorkerWaitUs = 0;
2610
+ int gRenderWorkerJobs = 0;
2611
+ constexpr std::uint32_t kRenderWorkerStackBytes = 12288;
2612
+
2613
+ void renderWorkerTask(void *)
2614
+ {
2615
+ // MUST start at 0 (jobSeq's initial value), NOT jobSeq.load(): submit() creates
2616
+ // this task and increments jobSeq immediately after, so loading here usually
2617
+ // reads 1 and swallows job 1 (the caller times out and the first parallel band
2618
+ // is silently dropped). Same race fixed on the elecrow in d22bfc5f9.
2619
+ std::uint32_t seen = 0;
2620
+ std::int64_t idleSince = esp_timer_get_time();
2621
+ for (;;) {
2622
+ while (gRenderWorker.jobSeq.load(std::memory_order_acquire) == seen) {
2623
+ if (esp_timer_get_time() - idleSince > 4000) {
2624
+ ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100));
2625
+ idleSince = esp_timer_get_time();
2626
+ }
2627
+ }
2628
+ seen = gRenderWorker.jobSeq.load(std::memory_order_acquire);
2629
+ const std::int64_t started = esp_timer_get_time();
2630
+ gRenderWorkerStartLatencyUs += started - gRenderWorkerSubmitUs;
2631
+ void (*fn)(void *, int, int) = gRenderWorker.fn;
2632
+ if (fn) fn(gRenderWorker.ctx, gRenderWorker.y0, gRenderWorker.y1);
2633
+ gRenderWorkerBandUs += esp_timer_get_time() - started;
2634
+ gRenderWorker.done.store(true, std::memory_order_release);
2635
+ idleSince = esp_timer_get_time();
2636
+ }
2637
+ }
2638
+
2639
+ } // namespace
2640
+
2641
+ extern "C" bool gea_render_parallel_submit(void (*fn)(void *, int, int), void *ctx, int y0, int y1)
2642
+ {
2643
+ if (!gRenderWorker.attempted) {
2644
+ gRenderWorker.attempted = true;
2645
+ const BaseType_t renderCore = xPortGetCoreID();
2646
+ const BaseType_t workerCore = (renderCore == 0) ? 1 : 0;
2647
+ const UBaseType_t priority = uxTaskPriorityGet(nullptr);
2648
+ const BaseType_t created = xTaskCreatePinnedToCore(renderWorkerTask,
2649
+ "gea_rwrk",
2650
+ kRenderWorkerStackBytes,
2651
+ nullptr,
2652
+ priority,
2653
+ &gRenderWorker.task,
2654
+ workerCore);
2655
+ std::printf("[render-worker] task=%p create=%d renderCore=%d workerCore=%d prio=%u stack=%u\n",
2656
+ static_cast<void *>(gRenderWorker.task),
2657
+ static_cast<int>(created),
2658
+ static_cast<int>(renderCore),
2659
+ static_cast<int>(workerCore),
2660
+ static_cast<unsigned>(priority),
2661
+ static_cast<unsigned>(kRenderWorkerStackBytes));
2662
+ if (created != pdPASS || !gRenderWorker.task) {
2663
+ multi_heap_info_t info{};
2664
+ heap_caps_get_info(&info, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
2665
+ std::printf("[render-worker] create failed: create=%d stack=%u internal_free=%u internal_largest=%u internal_min=%u free_blocks=%u alloc_blocks=%u total_blocks=%u\n",
2666
+ static_cast<int>(created),
2667
+ static_cast<unsigned>(kRenderWorkerStackBytes),
2668
+ static_cast<unsigned>(info.total_free_bytes),
2669
+ static_cast<unsigned>(info.largest_free_block),
2670
+ static_cast<unsigned>(info.minimum_free_bytes),
2671
+ static_cast<unsigned>(info.free_blocks),
2672
+ static_cast<unsigned>(info.allocated_blocks),
2673
+ static_cast<unsigned>(info.total_blocks));
2674
+ }
2675
+ }
2676
+ if (!gRenderWorker.task) return false;
2677
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().setRenderCore(static_cast<int>(xPortGetCoreID()));
2678
+ gRenderWorker.fn = fn;
2679
+ gRenderWorker.ctx = ctx;
2680
+ gRenderWorker.y0 = y0;
2681
+ gRenderWorker.y1 = y1;
2682
+ gRenderWorker.done.store(false, std::memory_order_release);
2683
+ gRenderWorkerSubmitUs = esp_timer_get_time();
2684
+ gRenderWorker.jobSeq.fetch_add(1, std::memory_order_release);
2685
+ xTaskNotifyGive(gRenderWorker.task);
2686
+ return true;
2687
+ }
2688
+
2689
+ extern "C" void gea_render_parallel_wait()
2690
+ {
2691
+ if (!gRenderWorker.task) return;
2692
+ const std::int64_t waitStarted = esp_timer_get_time();
2693
+ const std::int64_t deadline = waitStarted + 100000;
2694
+ while (!gRenderWorker.done.load(std::memory_order_acquire)) {
2695
+ if (esp_timer_get_time() > deadline) {
2696
+ std::printf("[render-worker] WAIT TIMEOUT\n");
2697
+ break;
2698
+ }
2699
+ }
2700
+ gRenderWorkerWaitUs += esp_timer_get_time() - waitStarted;
2701
+ if (++gRenderWorkerJobs >= 300) {
2702
+ std::printf("[worker] startLat=%dus band=%dus wait=%dus (avg/300)\n",
2703
+ static_cast<int>(gRenderWorkerStartLatencyUs / 300),
2704
+ static_cast<int>(gRenderWorkerBandUs / 300),
2705
+ static_cast<int>(gRenderWorkerWaitUs / 300));
2706
+ gRenderWorkerStartLatencyUs = 0;
2707
+ gRenderWorkerBandUs = 0;
2708
+ gRenderWorkerWaitUs = 0;
2709
+ gRenderWorkerJobs = 0;
2710
+ }
2711
+ }
2712
+
2713
+ extern "C" void gea_render_parallel_merge_dirty()
2714
+ {
2715
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().absorbWorkerDirty();
2716
+ }
2717
+
2718
+ extern "C" int gea_current_render_core()
2719
+ {
2720
+ return static_cast<int>(xPortGetCoreID());
2721
+ }
2722
+
2723
+ namespace gea::platform::display {
2724
+
2725
+ namespace {
2726
+
2727
+ gea::framework::graphics::Canvas *drawingCanvas()
2728
+ {
2729
+ return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().drawingCanvas();
2730
+ }
2731
+
2732
+ } // namespace
2733
+
2734
+ bool Display::init() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().init(); }
2735
+ bool Display::start() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().start(); }
2736
+ gea::framework::graphics::Canvas *Display::canvas() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().canvas(); }
2737
+ bool Display::framebufferIsPanelDirect() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().framebufferIsPanelDirect(); }
2738
+ bool Display::panelScanoutSurface(uint16_t **outBuffer, int *outW, int *outH) { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().panelScanoutSurface(outBuffer, outW, outH); }
2739
+ bool Display::panelDirectTarget(int logicalX, int logicalY, int logicalW, int logicalH,
2740
+ uint16_t **outBuf, int *outBufW, int *outBufH,
2741
+ int *outPanelX, int *outPanelY, int *outPanelW, int *outPanelH,
2742
+ int *outRotSteps, int *outFlip) {
2743
+ return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().panelDirectTarget(
2744
+ logicalX, logicalY, logicalW, logicalH, outBuf, outBufW, outBufH, outPanelX, outPanelY, outPanelW, outPanelH, outRotSteps, outFlip);
2745
+ }
2746
+ void Display::flipPanelToBack() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flipPanelToBack(); }
2747
+ void Display::clear() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().clear(); }
2748
+ void Display::clearNoFlush() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().clearNoFlush(); }
2749
+ void Display::print(const char *) {}
2750
+ void Display::flush() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flush(); }
2751
+ void Display::rebindCanvasToFramebuffer() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().rebindCanvasToFramebuffer(); }
2752
+ void Display::flushRects(const DisplayFlushRect *rects, int count, bool) { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushRects(rects, count); }
2753
+ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user) { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().streamRect(x, y, w, h, raster, user); }
2754
+ bool Display::present(const DisplayPresentCommand *commands, int command_count) { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().presentCommands(commands, command_count); }
2755
+ void Display::presentPathDebug(int *calls, int *direct, int *general, int *rejected, int *tileShapeFailKind, int *tileShapeFailType, int *tileShapeFailCount)
2756
+ {
2757
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().presentPathDebug(
2758
+ calls, direct, general, rejected, tileShapeFailKind, tileShapeFailType, tileShapeFailCount);
2759
+ }
2760
+ void Display::landFrameDebug(int *total, int *align, int *raster, int *text, int *flip)
2761
+ {
2762
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().landFrameDebug(total, align, raster, text, flip);
2763
+ }
2764
+ void Display::landPanDebug(int *detect, int *kick, int *strips, int *wait, int *interior)
2765
+ {
2766
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().landPanDebug(detect, kick, strips, wait, interior);
2767
+ }
2768
+ void Display::setFlushConfig(int chunk_rows, int queue_depth) { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().setFlushConfig(chunk_rows, queue_depth); }
2769
+ void Display::reserveInternal(std::size_t) {}
2770
+ bool Display::setHighBrightnessMode(bool) { return false; }
2771
+ bool Display::highBrightnessMode() { return false; }
2772
+ void Display::applyPendingInternalReserve() {}
2773
+ int Display::flushChunkRows() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushChunkRows(); }
2774
+ int Display::flushQueueDepth() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushQueueDepth(); }
2775
+ int Display::flushBufferBytes() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushBufferBytes(); }
2776
+ void Display::pushClip(int x, int y, int w, int h) { if (auto *c = drawingCanvas()) c->pushClip(x, y, w, h); }
2777
+ void Display::popClip() { if (auto *c = drawingCanvas()) c->popClip(); }
2778
+ void Display::resetClip() { if (auto *c = drawingCanvas()) c->resetClip(); }
2779
+ void Display::setAlpha(std::uint8_t alpha) { if (auto *c = drawingCanvas()) c->setGlobalAlpha(alpha); }
2780
+ std::uint8_t Display::alpha() { return drawingCanvas() ? drawingCanvas()->globalAlpha() : 255; }
2781
+ int Display::brightness() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().brightness(); }
2782
+ void Display::setBrightness(int brightness_percent) { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().setBrightness(brightness_percent); }
2783
+ // Tearing sync (TE/VBlank): not implemented on this target.
2784
+ void Display::setVSync(bool) {}
2785
+ void Display::invalidate() {}
2786
+ bool Display::vsyncEnabled() { return false; }
2787
+ void Display::vsyncWaitForFrame() {}
2788
+ void Display::clip(int *x0, int *y0, int *x1, int *y1)
2789
+ {
2790
+ if (auto *c = drawingCanvas()) c->currentClip(x0, y0, x1, y1);
2791
+ }
2792
+ 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); }
2793
+ 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); }
2794
+ void Display::resetScrollRegion() {}
2795
+ 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); }
2796
+ void Display::fillCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillCircle(cx, cy, r, color); }
2797
+ void Display::strokeCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->strokeCircle(cx, cy, r, color); }
2798
+ 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); }
2799
+ 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); }
2800
+ 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); }
2801
+ 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); }
2802
+ 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); }
2803
+ 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); }
2804
+ void Display::setPixel(int x, int y, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, 1, 1, color); }
2805
+ 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); }
2806
+ 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); }
2807
+ 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); }
2808
+ 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); }
2809
+ 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); }
2810
+ void Display::setWorldOverlay(const std::uint16_t *, int, int, int, int) {}
2811
+ void Display::setWorldScroll(int) {}
2812
+ void Display::flushStatsRead(std::int64_t *total_us, int *call_count, int *pixel_count)
2813
+ {
2814
+ const auto stats = gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStats();
2815
+ if (total_us) *total_us = stats.totalUs;
2816
+ if (call_count) *call_count = stats.callCount;
2817
+ if (pixel_count) *pixel_count = stats.pixelCount;
2818
+ }
2819
+ DisplayFlushPerfStats Display::flushPerfStatsRead() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStats(); }
2820
+ void Display::flushStatsReset() { gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStatsReset(); }
2821
+ const char *Display::flushStageName() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStageName(); }
2822
+ int Display::flushStageChunk() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStageChunk(); }
2823
+ DisplayFlushStageDetail Display::flushStageDetail() { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().flushStageDetail(); }
2824
+ bool Display::copySnapshotRgb565(std::uint16_t *dst, int pixel_capacity, int *width, int *height, bool) { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().copySnapshotRgb565(dst, pixel_capacity, width, height); }
2825
+ int Display::countNonBlackPixels(bool) { return gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().countNonBlackPixels(); }
2826
+
2827
+ void applyOrientation(gea::framework::display::DisplayOrientation)
2828
+ {
2829
+ gea::platform::esp32_p4_waveshare::display::DisplayBackend::instance().applyOrientation();
2830
+ }
2831
+
2832
+ } // namespace gea::platform::display