@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,1074 @@
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 <array>
11
+ #include <atomic>
12
+ #include <cstddef>
13
+ #include <cstdint>
14
+ #include <cstring>
15
+ #include <utility>
16
+
17
+ #include "driver/gpio.h"
18
+ #include "driver/spi_master.h"
19
+ #include "esp_err.h"
20
+ #include "esp_heap_caps.h"
21
+ #include "esp_log.h"
22
+ #include "esp_timer.h"
23
+ #include "freertos/FreeRTOS.h"
24
+ #include "freertos/semphr.h"
25
+ #include "freertos/task.h"
26
+
27
+ namespace platform_display = gea::platform::display;
28
+ namespace orientation_detail = gea::framework::display::detail;
29
+ namespace pixel = gea::framework::graphics::pixel;
30
+ namespace present = gea::framework::display_present;
31
+
32
+ namespace gea::platform::m5paper::display {
33
+
34
+ namespace {
35
+
36
+ constexpr char kTag[] = "m5paper_display";
37
+ constexpr int kControllerWidth = 960;
38
+ constexpr int kControllerHeight = 540;
39
+ constexpr int kMaxPixels = kControllerWidth * kControllerHeight;
40
+ constexpr int kMaxPackedBytes = kMaxPixels / 2; // 4 bits per pixel
41
+ // M5GFX caps the M5Paper IT8951 write clock at 12 MHz. The older M5EPD
42
+ // library used 10 MHz, but 12 MHz is the controller-tested fast path.
43
+ // 12 MHz is this board's ceiling: 16 and 20 MHz were both tried for faster
44
+ // partial transfers (a 540x856 partial costs ~500 ms of pixel push) and the
45
+ // IT8951 failed init with a BUSY timeout at either speed — the M5Paper's SPI
46
+ // link, not the controller spec (24 MHz), is the limit. Don't raise this.
47
+ // 12 MHz is the reliable ceiling for this IT8951 wiring: 20 MHz hard-failed
48
+ // (BUSY timeout at init, controller never came up). The page-turn win comes
49
+ // from the interrupt-driven bulk transfer, not the clock.
50
+ constexpr int kSpiClockHz = 12 * 1000 * 1000;
51
+ constexpr int kDmaChunkBytes = 4096;
52
+ // One IT8951 waveform at a time is the reliable presentation unit. Multiple
53
+ // disjoint commands make a nominal UI frame take N complete panel cycles and
54
+ // allow the game to advance several states before the glass catches up. Keep
55
+ // a single union region containing every change since the in-flight frame.
56
+ constexpr int kMaxBatchRegions = 1;
57
+ constexpr int kDefaultFullRefreshEvery = 160;
58
+ constexpr int kDefaultFullRefreshHardCap = 600;
59
+ constexpr std::uint32_t kFallbackImageMemory = 0x001236e0;
60
+
61
+ constexpr std::uint16_t kCmdSystemRun = 0x0001;
62
+ constexpr std::uint16_t kCmdRegisterRead = 0x0010;
63
+ constexpr std::uint16_t kCmdRegisterWrite = 0x0011;
64
+ constexpr std::uint16_t kCmdLoadImageArea = 0x0021;
65
+ constexpr std::uint16_t kCmdLoadImageEnd = 0x0022;
66
+ constexpr std::uint16_t kCmdGetDeviceInfo = 0x0302;
67
+ constexpr std::uint16_t kCmdDisplayBufferArea = 0x0037;
68
+ constexpr std::uint16_t kCmdVcom = 0x0039;
69
+ constexpr std::uint16_t kRegisterPackedWrite = 0x0004;
70
+ constexpr std::uint16_t kRegisterImageAddress = 0x0208;
71
+ constexpr std::uint16_t kRegisterLutActive = 0x1224;
72
+
73
+ enum UpdateMode : std::uint16_t {
74
+ UpdateInit = 0,
75
+ UpdateDirect = 1,
76
+ UpdateGc16 = 2,
77
+ UpdateGl16 = 3,
78
+ UpdateDu4 = 6,
79
+ UpdateA2 = 7,
80
+ };
81
+
82
+ struct Region {
83
+ int x = 0;
84
+ int y = 0;
85
+ int w = 0;
86
+ int h = 0;
87
+ int rotation = 1;
88
+ bool full = false;
89
+ bool qualityGrayscale = false;
90
+ // Part of a rapid-update streak (scroll/animation): displayed with the fast
91
+ // 1-bit A2 waveform instead of GL16 — 16-level partials arriving faster than
92
+ // the ~450 ms grayscale waveform read as flicker. A quality re-display of
93
+ // the streak's union region runs once the streak goes quiet.
94
+ bool fastStreak = false;
95
+ int packedBytes = 0;
96
+ };
97
+
98
+ struct RefreshBatch {
99
+ std::array<Region, kMaxBatchRegions> regions = {};
100
+ int count = 0;
101
+ int pixelCount = 0;
102
+ bool full = false;
103
+ };
104
+
105
+ // GRAY4: the framebuffer already holds 16-level gray in the panel's own 4bpp
106
+ // packing, so there is NO flush-time pack/copy stage at all — the refresh task
107
+ // streams region rows straight from the live framebuffer into the SPI DMA
108
+ // chunk (A2 partials snap each nibble to the two endpoints on the way in).
109
+
110
+ int rotationFor(gea::framework::display::DisplayOrientation orientation)
111
+ {
112
+ using Orientation = gea::framework::display::DisplayOrientation;
113
+ switch (orientation) {
114
+ case Orientation::PortraitSecondary: return 3;
115
+ case Orientation::LandscapePrimary: return 0;
116
+ case Orientation::LandscapeSecondary: return 2;
117
+ case Orientation::PortraitPrimary:
118
+ default: return 1;
119
+ }
120
+ }
121
+
122
+ class DisplayBackend {
123
+ public:
124
+ static DisplayBackend &instance()
125
+ {
126
+ static DisplayBackend backend;
127
+ return backend;
128
+ }
129
+
130
+ bool init()
131
+ {
132
+ if (initialized_) return true;
133
+ mutex_ = xSemaphoreCreateMutex();
134
+ packMutex_ = xSemaphoreCreateMutex();
135
+ if (!mutex_ || !packMutex_) return false;
136
+
137
+ frameBuffer_ = static_cast<std::uint8_t *>(
138
+ heap_caps_calloc(kMaxPackedBytes, 1, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
139
+ dmaChunk_ = static_cast<std::uint8_t *>(
140
+ heap_caps_malloc(kDmaChunkBytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT));
141
+ dmaChunkB_ = static_cast<std::uint8_t *>(
142
+ heap_caps_malloc(kDmaChunkBytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT));
143
+ if (!frameBuffer_ || !dmaChunk_ || !dmaChunkB_) {
144
+ ESP_LOGE(kTag, "framebuffer/transfer allocation failed (PSRAM required)");
145
+ return false;
146
+ }
147
+
148
+ if (!initPanel()) return false;
149
+ bindCanvas();
150
+ if (xTaskCreatePinnedToCore(refreshTaskEntry, "m5paper_epd", 4096, this, 6, &refreshTask_, 1) != pdPASS) {
151
+ ESP_LOGE(kTag, "failed to start refresh task");
152
+ return false;
153
+ }
154
+ initialized_ = true;
155
+ ESP_LOGI(kTag, "M5Paper ready 540x960, 4/16 gray, partial update, packed=%d bytes", kMaxPackedBytes);
156
+ return true;
157
+ }
158
+
159
+ bool start() { return init(); }
160
+
161
+ gea::framework::graphics::Canvas *canvas()
162
+ {
163
+ if (!initialized_) init();
164
+ return &canvas_;
165
+ }
166
+
167
+ bool framebufferIsPanelDirect() const { return false; }
168
+
169
+ void applyOrientation(gea::framework::display::DisplayOrientation orientation)
170
+ {
171
+ if (!init()) return;
172
+ take();
173
+ rotation_ = rotationFor(orientation);
174
+ bindCanvasLocked();
175
+ std::memset(frameBuffer_, 0, kMaxPackedBytes);
176
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
177
+ needsFullPhysicalFlush_ = true;
178
+ give();
179
+ }
180
+
181
+ void clear()
182
+ {
183
+ clearNoFlush();
184
+ flush();
185
+ }
186
+
187
+ void clearNoFlush()
188
+ {
189
+ if (!init()) return;
190
+ take();
191
+ std::memset(frameBuffer_, 0, kMaxPackedBytes);
192
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
193
+ needsFullPhysicalFlush_ = true;
194
+ give();
195
+ }
196
+
197
+ void flush()
198
+ {
199
+ if (!init()) return;
200
+ int x0 = 0;
201
+ int y0 = 0;
202
+ int x1 = logicalWidth() - 1;
203
+ int y1 = logicalHeight() - 1;
204
+ if (!needsFullPhysicalFlush_ && !canvas_.dirty(&x0, &y0, &x1, &y1)) return;
205
+ requestRefresh(x0, y0, x1, y1, needsFullPhysicalFlush_);
206
+ canvas_.resetDirty();
207
+ needsFullPhysicalFlush_ = false;
208
+ }
209
+
210
+ void flushRects(const platform_display::DisplayFlushRect *rects, int count)
211
+ {
212
+ if (!rects || count <= 0 || !init()) return;
213
+ requestRefreshRects(rects, count, needsFullPhysicalFlush_);
214
+ canvas_.resetDirty();
215
+ needsFullPhysicalFlush_ = false;
216
+ }
217
+
218
+ bool streamRect(int x, int y, int w, int h, platform_display::DisplayStreamRasterFn raster, void *user)
219
+ {
220
+ if (!raster || w <= 0 || h <= 0 || !init()) return false;
221
+ const int x0 = std::max(0, x);
222
+ const int y0 = std::max(0, y);
223
+ const int x1 = std::min(logicalWidth() - 1, x + w - 1);
224
+ const int y1 = std::min(logicalHeight() - 1, y + h - 1);
225
+ if (x0 > x1 || y0 > y1) return true;
226
+ const int width = x1 - x0 + 1;
227
+ const int rowBytes = (logicalWidth() + 1) / 2;
228
+ // The raster callback fills an unpacked native-pixel (gray-value) row; pack
229
+ // it into the framebuffer's nibbles per row.
230
+ static pixel::native_t rowbuf[kControllerWidth];
231
+ for (int row = y0; row <= y1; ++row) {
232
+ raster(rowbuf, width, 1, x0, row, user);
233
+ pixel::packed::writeUnpacked(frameBuffer_ + static_cast<std::size_t>(row) * rowBytes, x0, rowbuf, width);
234
+ }
235
+ canvas_.markDirty(x0, y0, x1, y1);
236
+ flush();
237
+ return true;
238
+ }
239
+
240
+ bool presentCommands(const platform_display::DisplayPresentCommand *commands, int commandCount)
241
+ {
242
+ // The strided direct-present fast path assumes an unpacked native
243
+ // framebuffer; GRAY4 storage is nibble-packed, so decline and let the
244
+ // framework fall back to normal Canvas replay (which packs correctly).
245
+ (void)commands;
246
+ (void)commandCount;
247
+ return false;
248
+ }
249
+
250
+ void setFlushConfig(int, int) {}
251
+ int flushChunkRows() const { return logicalHeight(); }
252
+ int flushQueueDepth() const { return 1; }
253
+ int flushBufferBytes() const { return kMaxPackedBytes; }
254
+
255
+ bool copySnapshotRgb565(std::uint16_t *dst, int capacity, int *width, int *height)
256
+ {
257
+ if (!dst || capacity < kMaxPixels || !frameBuffer_) return false;
258
+ if (width) *width = logicalWidth();
259
+ if (height) *height = logicalHeight();
260
+ // Framebuffer is 4bpp packed; unpack each nibble to an RGB565 gray.
261
+ for (int i = 0; i < kMaxPixels; ++i)
262
+ dst[i] = pixel::gray4ToRgb565(pixel::packed::get(frameBuffer_, i));
263
+ return true;
264
+ }
265
+
266
+ // Packed (native GRAY4) snapshot -- frameBuffer_ IS already a flat packed
267
+ // pixel stream over the whole logical image (kMaxPackedBytes = kMaxPixels/2),
268
+ // so this is a straight copy: no per-pixel unpack/expand to RGB565, and a
269
+ // quarter the allocation copySnapshotRgb565 needs.
270
+ bool copySnapshotPacked(std::uint8_t *dst, int byteCapacity, int *width, int *height)
271
+ {
272
+ if (!dst || byteCapacity < kMaxPackedBytes || !frameBuffer_) return false;
273
+ if (width) *width = logicalWidth();
274
+ if (height) *height = logicalHeight();
275
+ std::memcpy(dst, frameBuffer_, static_cast<std::size_t>(kMaxPackedBytes));
276
+ return true;
277
+ }
278
+
279
+ int countNonBlackPixels() const
280
+ {
281
+ int count = 0;
282
+ for (int i = 0; frameBuffer_ && i < kMaxPixels; ++i)
283
+ if (pixel::packed::get(frameBuffer_, i) != 0) ++count;
284
+ return count;
285
+ }
286
+
287
+ void setBrightness(int) {}
288
+ int brightness() const { return 100; }
289
+ platform_display::DisplayFlushPerfStats flushStats() const { return stats_; }
290
+ void flushStatsReset() { stats_ = {}; }
291
+ const char *flushStageName() const { return refreshInFlight_.load() ? "it8951-refresh" : "idle"; }
292
+ int flushStageChunk() const { return 0; }
293
+ platform_display::DisplayFlushStageDetail flushStageDetail() const { return {}; }
294
+
295
+ std::uint16_t *backgroundCache(int *capacity) { return scratch(backgroundCache_, backgroundAttempted_, capacity); }
296
+ std::uint16_t *backdropCache(int *capacity) { return scratch(backdropCache_, backdropAttempted_, capacity); }
297
+
298
+ void setRefreshConfig(int fullEvery, int hardCap, int fastStreakWindowMs,
299
+ const std::uint8_t *, int, const std::uint8_t *, int)
300
+ {
301
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
302
+ if (fullEvery >= 0) fullRefreshEvery_ = fullEvery;
303
+ if (hardCap >= 0) fullRefreshHardCap_ = hardCap;
304
+ if (fastStreakWindowMs >= 0) fastStreakWindowUs_ = fastStreakWindowMs * 1000;
305
+ xSemaphoreGive(packMutex_);
306
+ ESP_LOGI(kTag, "refresh config fullEvery=%d hardCap=%d fastStreakMs=%d (IT8951 waveforms are controller-resident)",
307
+ fullRefreshEvery_, fullRefreshHardCap_, fastStreakWindowUs_ / 1000);
308
+ }
309
+
310
+ void requestFullRefresh()
311
+ {
312
+ if (!init()) return;
313
+ forceFullRefresh_.store(true);
314
+ requestRefresh(0, 0, logicalWidth() - 1, logicalHeight() - 1, true);
315
+ }
316
+
317
+ void setQualityGrayscale(bool enabled)
318
+ {
319
+ qualityGrayscale_.store(enabled);
320
+ forceFullRefresh_.store(true);
321
+ if (initialized_) requestRefresh(0, 0, logicalWidth() - 1, logicalHeight() - 1, true);
322
+ ESP_LOGI(kTag, "grayscale mode=%s", enabled ? "16-level quality" : "4-level fast");
323
+ }
324
+
325
+ void setFullOnCover(bool enabled) { fullOnCover_.store(enabled); }
326
+
327
+ void rebindCanvasToFramebuffer() { bindCanvas(); }
328
+
329
+ private:
330
+ DisplayBackend() = default;
331
+
332
+ int logicalWidth() const { return orientation_detail::DisplayOrientationState::width(); }
333
+ int logicalHeight() const { return orientation_detail::DisplayOrientationState::height(); }
334
+
335
+ void take() { if (mutex_) xSemaphoreTake(mutex_, portMAX_DELAY); }
336
+ void give() { if (mutex_) xSemaphoreGive(mutex_); }
337
+
338
+ void bindCanvas()
339
+ {
340
+ take();
341
+ bindCanvasLocked();
342
+ give();
343
+ }
344
+
345
+ void bindCanvasLocked()
346
+ {
347
+ canvas_.bindPixels(frameBuffer_, logicalWidth(), logicalHeight(), logicalWidth());
348
+ }
349
+
350
+ std::uint16_t *scratch(std::uint16_t *&buffer, bool &attempted, int *capacity)
351
+ {
352
+ if (!attempted) {
353
+ attempted = true;
354
+ buffer = static_cast<std::uint16_t *>(
355
+ heap_caps_malloc(kMaxPixels * sizeof(std::uint16_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
356
+ }
357
+ if (capacity) *capacity = buffer ? kMaxPixels : 0;
358
+ return buffer;
359
+ }
360
+
361
+ Region alignedRegion(int x0, int y0, int x1, int y1, bool full)
362
+ {
363
+ const int width = logicalWidth();
364
+ const int height = logicalHeight();
365
+ x0 = std::clamp(x0, 0, width - 1);
366
+ y0 = std::clamp(y0, 0, height - 1);
367
+ x1 = std::clamp(x1, 0, width - 1);
368
+ y1 = std::clamp(y1, 0, height - 1);
369
+ if (x1 < x0 || y1 < y0) return {};
370
+ // IT8951 4bpp loads require the controller X axis to be 4-pixel
371
+ // aligned. In portrait rotations logical Y maps to controller X, so
372
+ // align and expand both logical axes before packing. Aligning only X
373
+ // allowed small UI updates such as the FPS badge at y=927 to submit an
374
+ // unaligned physical-X area and eventually wedge panel updates.
375
+ x0 &= ~3;
376
+ x1 = std::min(width - 1, ((x1 + 4) & ~3) - 1);
377
+ y0 &= ~3;
378
+ y1 = std::min(height - 1, ((y1 + 4) & ~3) - 1);
379
+ Region region;
380
+ region.x = x0;
381
+ region.y = y0;
382
+ region.w = x1 - x0 + 1;
383
+ region.h = y1 - y0 + 1;
384
+ region.rotation = rotation_;
385
+ region.full = full;
386
+ region.qualityGrayscale = qualityGrayscale_.load();
387
+ region.packedBytes = region.w * region.h / 2;
388
+ return region;
389
+ }
390
+
391
+ bool waitForWaveform(const char *reason, std::int64_t &waitUs)
392
+ {
393
+ const std::int64_t started = esp_timer_get_time();
394
+ const bool ok = waitDisplay();
395
+ waitUs += esp_timer_get_time() - started;
396
+ if (!ok) {
397
+ ESP_LOGE(kTag, "IT8951 waveform wait failed reason=%s",
398
+ reason ? reason : "unknown");
399
+ return false;
400
+ }
401
+ return true;
402
+ }
403
+
404
+ bool addRegion(RefreshBatch &batch, const Region &region)
405
+ {
406
+ if (region.packedBytes <= 0) return true;
407
+ if (batch.count >= kMaxBatchRegions) return false;
408
+ batch.regions[batch.count++] = region;
409
+ return true;
410
+ }
411
+
412
+ void requestRefresh(int x0, int y0, int x1, int y1, bool requestedFull)
413
+ {
414
+ const platform_display::DisplayFlushRect rect = {x0, y0, x1, y1};
415
+ requestRefreshRects(&rect, 1, requestedFull);
416
+ }
417
+
418
+ void requestRefreshRects(const platform_display::DisplayFlushRect *rects, int count, bool requestedFull)
419
+ {
420
+ if (!rects || count <= 0) return;
421
+ const std::int64_t started = esp_timer_get_time();
422
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
423
+ const int partials = partialsSinceFull_.load();
424
+ const bool hasPending = pendingSeq_.load(std::memory_order_acquire) != transmittedSeq_;
425
+ bool coversScreen = false;
426
+ for (int i = 0; i < count && !coversScreen; ++i) {
427
+ coversScreen = rects[i].x0 <= 0 && rects[i].y0 <= 0 &&
428
+ rects[i].x1 >= logicalWidth() - 1 && rects[i].y1 >= logicalHeight() - 1;
429
+ }
430
+ // Rapid-succession requests (a scroll) are a streak: they ride the fast
431
+ // 1-bit waveform AND suppress the full-refresh promotions — a GC16 flash
432
+ // mid-scroll is exactly the visual we're avoiding; the post-streak GL16
433
+ // settle (and the next isolated refresh's cadence) recover quality.
434
+ const std::int64_t now = esp_timer_get_time();
435
+ const bool streak = fastStreakWindowUs_ > 0 && lastRequestUs_ > 0 &&
436
+ now - lastRequestUs_ <= fastStreakWindowUs_;
437
+ lastRequestUs_ = now;
438
+ bool full = requestedFull || (hasPending && pendingBatch_.full) || forceFullRefresh_.exchange(false) ||
439
+ (!streak && ((coversScreen && fullOnCover_.load()) ||
440
+ (fullRefreshEvery_ > 0 && partials >= fullRefreshEvery_) ||
441
+ (fullRefreshHardCap_ > 0 && partials >= fullRefreshHardCap_)));
442
+ RefreshBatch batch = {};
443
+ if (full) {
444
+ Region region = alignedRegion(0, 0, logicalWidth() - 1, logicalHeight() - 1, true);
445
+ addRegion(batch, region);
446
+ batch.full = true;
447
+ } else {
448
+ int unionX0 = logicalWidth();
449
+ int unionY0 = logicalHeight();
450
+ int unionX1 = -1;
451
+ int unionY1 = -1;
452
+ if (hasPending) {
453
+ for (int i = 0; i < pendingBatch_.count; ++i) {
454
+ const Region &region = pendingBatch_.regions[i];
455
+ unionX0 = std::min(unionX0, region.x);
456
+ unionY0 = std::min(unionY0, region.y);
457
+ unionX1 = std::max(unionX1, region.x + region.w - 1);
458
+ unionY1 = std::max(unionY1, region.y + region.h - 1);
459
+ }
460
+ }
461
+ for (int i = 0; i < count; ++i) {
462
+ Region region = alignedRegion(rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1, false);
463
+ if (region.packedBytes <= 0) continue;
464
+ unionX0 = std::min(unionX0, region.x);
465
+ unionY0 = std::min(unionY0, region.y);
466
+ unionX1 = std::max(unionX1, region.x + region.w - 1);
467
+ unionY1 = std::max(unionY1, region.y + region.h - 1);
468
+ }
469
+ if (unionX1 >= unionX0 && unionY1 >= unionY0) {
470
+ addRegion(batch, alignedRegion(unionX0, unionY0, unionX1, unionY1, false));
471
+ }
472
+ }
473
+ if (batch.count > 0) {
474
+ if (!batch.full && streak) {
475
+ for (int i = 0; i < batch.count; ++i) batch.regions[i].fastStreak = true;
476
+ }
477
+ batch.pixelCount = 0;
478
+ for (int i = 0; i < batch.count; ++i)
479
+ batch.pixelCount += batch.regions[i].w * batch.regions[i].h;
480
+ pendingBatch_ = batch;
481
+ pendingSeq_.fetch_add(1, std::memory_order_release);
482
+ }
483
+ xSemaphoreGive(packMutex_);
484
+ if (refreshTask_) xTaskNotifyGive(refreshTask_);
485
+
486
+ stats_.callCount++;
487
+ stats_.pixelCount += batch.pixelCount;
488
+ stats_.totalUs += esp_timer_get_time() - started;
489
+ }
490
+
491
+ bool waitReady(std::uint32_t timeoutMs = 3000)
492
+ {
493
+ const std::int64_t deadline = esp_timer_get_time() + static_cast<std::int64_t>(timeoutMs) * 1000;
494
+ while (gpio_get_level(gea::platform::board::display.busy) == 0) {
495
+ if (esp_timer_get_time() >= deadline) {
496
+ ESP_LOGE(kTag, "IT8951 BUSY timeout");
497
+ return false;
498
+ }
499
+ vTaskDelay(pdMS_TO_TICKS(1));
500
+ }
501
+ return true;
502
+ }
503
+
504
+ bool transfer(const void *tx, void *rx, int bytes)
505
+ {
506
+ spi_transaction_t transaction = {};
507
+ transaction.length = static_cast<std::size_t>(bytes) * 8;
508
+ transaction.tx_buffer = tx;
509
+ transaction.rx_buffer = rx;
510
+ return spi_device_polling_transmit(spi_, &transaction) == ESP_OK;
511
+ }
512
+
513
+ bool writeCommand(std::uint16_t command)
514
+ {
515
+ if (!waitReady()) return false;
516
+ const std::uint8_t prefix[2] = {0x60, 0x00};
517
+ const std::uint8_t word[2] = {static_cast<std::uint8_t>(command >> 8), static_cast<std::uint8_t>(command)};
518
+ gpio_set_level(gea::platform::board::display.cs, 0);
519
+ bool ok = transfer(prefix, nullptr, sizeof(prefix));
520
+ if (ok) ok = waitReady();
521
+ if (ok) ok = transfer(word, nullptr, sizeof(word));
522
+ gpio_set_level(gea::platform::board::display.cs, 1);
523
+ return ok;
524
+ }
525
+
526
+ bool writeWord(std::uint16_t value)
527
+ {
528
+ if (!waitReady()) return false;
529
+ const std::uint8_t prefix[2] = {0x00, 0x00};
530
+ const std::uint8_t word[2] = {static_cast<std::uint8_t>(value >> 8), static_cast<std::uint8_t>(value)};
531
+ gpio_set_level(gea::platform::board::display.cs, 0);
532
+ bool ok = transfer(prefix, nullptr, sizeof(prefix));
533
+ if (ok) ok = waitReady();
534
+ if (ok) ok = transfer(word, nullptr, sizeof(word));
535
+ gpio_set_level(gea::platform::board::display.cs, 1);
536
+ return ok;
537
+ }
538
+
539
+ bool writeArgs(std::uint16_t command, const std::uint16_t *args, int count)
540
+ {
541
+ if (!args || count < 0 || count > 20 || !writeCommand(command)) return false;
542
+ for (int i = 0; i < count; ++i)
543
+ if (!writeWord(args[i])) return false;
544
+ return true;
545
+ }
546
+
547
+ bool readWords(std::uint16_t *values, int count)
548
+ {
549
+ if (!values || count <= 0 || count > 20 || !waitReady()) return false;
550
+ const std::uint8_t prefix[2] = {0x10, 0x00};
551
+ const std::uint8_t dummy[2] = {};
552
+ std::uint8_t zeros[40] = {};
553
+ std::uint8_t received[40] = {};
554
+ gpio_set_level(gea::platform::board::display.cs, 0);
555
+ bool ok = transfer(prefix, nullptr, sizeof(prefix));
556
+ if (ok) ok = waitReady();
557
+ if (ok) ok = transfer(dummy, nullptr, sizeof(dummy));
558
+ if (ok) ok = waitReady();
559
+ if (ok) ok = transfer(zeros, received, count * 2);
560
+ gpio_set_level(gea::platform::board::display.cs, 1);
561
+ if (!ok) return false;
562
+ for (int i = 0; i < count; ++i)
563
+ values[i] = static_cast<std::uint16_t>((received[i * 2] << 8) | received[1 + i * 2]);
564
+ return true;
565
+ }
566
+
567
+ bool writeRegister(std::uint16_t address, std::uint16_t value)
568
+ {
569
+ return writeCommand(kCmdRegisterWrite) && writeWord(address) && writeWord(value);
570
+ }
571
+
572
+ bool setImageAddress()
573
+ {
574
+ return writeRegister(kRegisterImageAddress + 2, static_cast<std::uint16_t>(imageMemory_ >> 16)) &&
575
+ writeRegister(kRegisterImageAddress, static_cast<std::uint16_t>(imageMemory_));
576
+ }
577
+
578
+ bool waitDisplay()
579
+ {
580
+ const std::int64_t deadline = esp_timer_get_time() + 5000000;
581
+ for (;;) {
582
+ std::uint16_t active = 1;
583
+ if (!writeCommand(kCmdRegisterRead) || !writeWord(kRegisterLutActive) || !readWords(&active, 1)) return false;
584
+ if (active == 0) return true;
585
+ if (esp_timer_get_time() >= deadline) return false;
586
+ vTaskDelay(pdMS_TO_TICKS(2));
587
+ }
588
+ }
589
+
590
+ // Stream a region's pixel rows from the LIVE framebuffer into the controller.
591
+ // The framebuffer already holds the panel's 4bpp layout (region.x/w are 4-px
592
+ // aligned, so the row slice is byte-aligned) — rows are copied straight into
593
+ // the internal-RAM DMA chunk, no intermediate pack buffer. Full/GL16 loads
594
+ // keep all 16 levels; A2 partials need strict two-endpoint data, so those
595
+ // snap each nibble to 0/15 during the chunk fill.
596
+ bool writeRegionPixels(const Region &region)
597
+ {
598
+ if (!waitReady()) return false;
599
+ const std::uint8_t prefix[2] = {0x00, 0x00};
600
+ gpio_set_level(gea::platform::board::display.cs, 0);
601
+ bool ok = transfer(prefix, nullptr, sizeof(prefix));
602
+ const int rowBytes = (logicalWidth() + 1) / 2;
603
+ const int regionBytes = region.w / 2;
604
+ const bool quality = region.full || (region.qualityGrayscale && !region.fastStreak);
605
+ // Double-buffered, INTERRUPT-driven bulk transfer: while one chunk DMAs,
606
+ // this task fills the other and then BLOCKS in get_trans_result. A
607
+ // polling transmit here busy-spun this priority-6 task for the whole
608
+ // ~200 ms load and starved the frame task on the same core — the visible
609
+ // page-turn stall, not the wire time itself.
610
+ std::uint8_t *bufs[2] = {dmaChunk_, dmaChunkB_};
611
+ spi_transaction_t txn = {};
612
+ int cur = 0;
613
+ int fill = 0;
614
+ bool inFlight = false;
615
+ const auto awaitInFlight = [&]() {
616
+ if (!inFlight) return;
617
+ spi_transaction_t *done = nullptr;
618
+ if (spi_device_get_trans_result(spi_, &done, portMAX_DELAY) != ESP_OK) ok = false;
619
+ inFlight = false;
620
+ };
621
+ const auto queueChunk = [&](int bytes) {
622
+ awaitInFlight();
623
+ if (!ok || bytes <= 0) return;
624
+ txn = {};
625
+ txn.length = static_cast<std::size_t>(bytes) * 8;
626
+ txn.tx_buffer = bufs[cur];
627
+ if (spi_device_queue_trans(spi_, &txn, portMAX_DELAY) != ESP_OK) {
628
+ ok = false;
629
+ return;
630
+ }
631
+ inFlight = true;
632
+ cur ^= 1;
633
+ };
634
+ for (int row = 0; ok && row < region.h; ++row) {
635
+ const std::uint8_t *src = frameBuffer_ + static_cast<std::size_t>(region.y + row) * rowBytes + region.x / 2;
636
+ int copied = 0;
637
+ while (ok && copied < regionBytes) {
638
+ const int take = std::min(kDmaChunkBytes - fill, regionBytes - copied);
639
+ if (quality) {
640
+ std::memcpy(bufs[cur] + fill, src + copied, static_cast<std::size_t>(take));
641
+ } else {
642
+ for (int b = 0; b < take; ++b) {
643
+ const std::uint8_t byte = src[copied + b];
644
+ const std::uint8_t hi = (byte >> 4) < 8 ? 0 : 15;
645
+ const std::uint8_t lo = (byte & 0x0F) < 8 ? 0 : 15;
646
+ bufs[cur][fill + b] = static_cast<std::uint8_t>((hi << 4) | lo);
647
+ }
648
+ }
649
+ fill += take;
650
+ copied += take;
651
+ if (fill == kDmaChunkBytes) {
652
+ queueChunk(fill);
653
+ fill = 0;
654
+ }
655
+ }
656
+ }
657
+ if (ok && fill > 0) queueChunk(fill);
658
+ awaitInFlight();
659
+ gpio_set_level(gea::platform::board::display.cs, 1);
660
+ return ok;
661
+ }
662
+
663
+ bool loadRegion(const Region &region)
664
+ {
665
+ const std::uint16_t args[5] = {
666
+ static_cast<std::uint16_t>((1 << 8) | (2 << 4) | region.rotation),
667
+ static_cast<std::uint16_t>(region.x),
668
+ static_cast<std::uint16_t>(region.y),
669
+ static_cast<std::uint16_t>(region.w),
670
+ static_cast<std::uint16_t>(region.h),
671
+ };
672
+ return setImageAddress() && writeArgs(kCmdLoadImageArea, args, 5) &&
673
+ writeRegionPixels(region) && writeCommand(kCmdLoadImageEnd);
674
+ }
675
+
676
+ bool updateRegion(const Region &region, UpdateMode mode)
677
+ {
678
+ int x = region.x;
679
+ int y = region.y;
680
+ int w = region.w;
681
+ int h = region.h;
682
+ std::uint16_t args[7] = {};
683
+ switch (region.rotation) {
684
+ case 0: args[0] = x; args[1] = y; args[2] = w; args[3] = h; break;
685
+ case 1: args[0] = y; args[1] = kControllerHeight - w - x; args[2] = h; args[3] = w; break;
686
+ case 2: args[0] = kControllerWidth - w - x; args[1] = kControllerHeight - h - y; args[2] = w; args[3] = h; break;
687
+ case 3: args[0] = kControllerWidth - h - y; args[1] = x; args[2] = h; args[3] = w; break;
688
+ default: return false;
689
+ }
690
+ // IT8951 can freeze when a physical update's left and right edges are
691
+ // inside the same 4-pixel controller group. Logical X alignment is not
692
+ // sufficient in portrait mode because logical Y becomes physical X.
693
+ // Expand only the displayed area; adjacent image-memory pixels retain
694
+ // their previous contents.
695
+ int left = args[0];
696
+ int right = left + args[2] - 1;
697
+ if ((left & ~3) == (right & ~3)) {
698
+ if (right + 1 < kControllerWidth) {
699
+ right = std::min(kControllerWidth - 1, (right + 4) & ~3);
700
+ } else if (left > 0) {
701
+ --left;
702
+ }
703
+ args[0] = static_cast<std::uint16_t>(left);
704
+ args[2] = static_cast<std::uint16_t>(right - left + 1);
705
+ }
706
+ args[4] = mode;
707
+ args[5] = static_cast<std::uint16_t>(imageMemory_);
708
+ args[6] = static_cast<std::uint16_t>(imageMemory_ >> 16);
709
+ return writeArgs(kCmdDisplayBufferArea, args, 7);
710
+ }
711
+
712
+ bool initPanel()
713
+ {
714
+ // USB/DTR resets restart the ESP32 without removing power from the IT8951.
715
+ // Power-cycle the EPD rail so a controller left busy by the previous app
716
+ // always returns to its command-ready reset state.
717
+ gpio_set_level(gea::platform::board::power.epdPower, 0);
718
+ vTaskDelay(pdMS_TO_TICKS(100));
719
+ gpio_set_level(gea::platform::board::power.epdPower, 1);
720
+ vTaskDelay(pdMS_TO_TICKS(500));
721
+
722
+ gpio_config_t csConfig = {};
723
+ csConfig.pin_bit_mask = 1ULL << gea::platform::board::display.cs;
724
+ csConfig.mode = GPIO_MODE_OUTPUT;
725
+ csConfig.pull_up_en = GPIO_PULLUP_ENABLE;
726
+ csConfig.pull_down_en = GPIO_PULLDOWN_DISABLE;
727
+ csConfig.intr_type = GPIO_INTR_DISABLE;
728
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&csConfig));
729
+ gpio_set_level(gea::platform::board::display.cs, 1);
730
+
731
+ gpio_config_t busyConfig = {};
732
+ busyConfig.pin_bit_mask = 1ULL << gea::platform::board::display.busy;
733
+ busyConfig.mode = GPIO_MODE_INPUT;
734
+ busyConfig.pull_up_en = GPIO_PULLUP_ENABLE;
735
+ busyConfig.pull_down_en = GPIO_PULLDOWN_DISABLE;
736
+ busyConfig.intr_type = GPIO_INTR_DISABLE;
737
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&busyConfig));
738
+
739
+ spi_bus_config_t bus = {};
740
+ bus.mosi_io_num = gea::platform::board::display.mosi;
741
+ bus.miso_io_num = gea::platform::board::display.miso;
742
+ bus.sclk_io_num = gea::platform::board::display.sclk;
743
+ bus.quadwp_io_num = -1;
744
+ bus.quadhd_io_num = -1;
745
+ bus.max_transfer_sz = kDmaChunkBytes;
746
+ esp_err_t err = spi_bus_initialize(gea::platform::board::display.spiHost, &bus, SPI_DMA_CH_AUTO);
747
+ if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
748
+ ESP_LOGE(kTag, "SPI bus init failed: %s", esp_err_to_name(err));
749
+ return false;
750
+ }
751
+
752
+ spi_device_interface_config_t device = {};
753
+ device.clock_speed_hz = kSpiClockHz;
754
+ device.mode = 0;
755
+ device.spics_io_num = -1;
756
+ device.queue_size = 1;
757
+ err = spi_bus_add_device(gea::platform::board::display.spiHost, &device, &spi_);
758
+ if (err != ESP_OK) return false;
759
+
760
+ ESP_ERROR_CHECK_WITHOUT_ABORT(spi_device_acquire_bus(spi_, portMAX_DELAY));
761
+ std::uint16_t info[20] = {};
762
+ if (writeCommand(kCmdGetDeviceInfo)) {
763
+ vTaskDelay(pdMS_TO_TICKS(1));
764
+ if (readWords(info, 20)) {
765
+ const std::uint32_t reported = (static_cast<std::uint32_t>(info[3]) << 16) | info[2];
766
+ if (reported != 0 && reported != 0xffffffffu) imageMemory_ = reported;
767
+ }
768
+ }
769
+ const bool ok = writeCommand(kCmdSystemRun) &&
770
+ writeRegister(kRegisterPackedWrite, 1) && setImageAddress() &&
771
+ writeCommand(kCmdVcom) && writeWord(1) && writeWord(2300);
772
+ spi_device_release_bus(spi_);
773
+ if (!ok) return false;
774
+ ESP_LOGI(kTag, "IT8951 info=%ux%u image=0x%08lx CS=%d BUSY=%d SPI=%dMHz",
775
+ static_cast<unsigned>(info[0]), static_cast<unsigned>(info[1]),
776
+ static_cast<unsigned long>(imageMemory_), static_cast<int>(gea::platform::board::display.cs),
777
+ static_cast<int>(gea::platform::board::display.busy), kSpiClockHz / 1000000);
778
+ return true;
779
+ }
780
+
781
+ static void refreshTaskEntry(void *arg) { static_cast<DisplayBackend *>(arg)->refreshLoop(); }
782
+
783
+ void refreshLoop()
784
+ {
785
+ for (;;) {
786
+ const TickType_t waitTicks = (settlePending_ && fastStreakWindowUs_ > 0)
787
+ ? pdMS_TO_TICKS(fastStreakWindowUs_ / 1000 + 50)
788
+ : portMAX_DELAY;
789
+ if (ulTaskNotifyTake(pdTRUE, waitTicks) == 0) {
790
+ // Streak went quiet: one GL16 re-display of the union restores the
791
+ // 16-level rendering the 1-bit scroll waveform flattened.
792
+ if (settlePending_ && qualityGrayscale_.load() &&
793
+ pendingSeq_.load(std::memory_order_acquire) == transmittedSeq_) {
794
+ Region region = alignedRegion(settleX0_, settleY0_, settleX1_, settleY1_, false);
795
+ settlePending_ = false;
796
+ settleX1_ = -1;
797
+ if (region.packedBytes > 0) {
798
+ refreshInFlight_.store(true);
799
+ spi_device_acquire_bus(spi_, portMAX_DELAY);
800
+ bool ok = true;
801
+ std::int64_t waitUs = 0;
802
+ if (waveformPending_) {
803
+ ok = waitForWaveform("streak-settle", waitUs);
804
+ waveformPending_ = false;
805
+ }
806
+ if (ok) {
807
+ ok = loadRegion(region) && updateRegion(region, UpdateGl16);
808
+ if (ok) waveformPending_ = true;
809
+ }
810
+ spi_device_release_bus(spi_);
811
+ if (ok)
812
+ ESP_LOGI(kTag, "streak settle %dx%d@%d,%d", region.w, region.h, region.x, region.y);
813
+ refreshInFlight_.store(false);
814
+ }
815
+ }
816
+ continue;
817
+ }
818
+ for (;;) {
819
+ RefreshBatch batch;
820
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
821
+ const std::uint32_t seq = pendingSeq_.load(std::memory_order_acquire);
822
+ if (seq == transmittedSeq_) {
823
+ xSemaphoreGive(packMutex_);
824
+ break;
825
+ }
826
+ batch = pendingBatch_;
827
+ transmittedSeq_ = seq;
828
+ xSemaphoreGive(packMutex_);
829
+
830
+ refreshInFlight_.store(true);
831
+ const std::int64_t started = esp_timer_get_time();
832
+ spi_device_acquire_bus(spi_, portMAX_DELAY);
833
+ bool ok = batch.count == 1;
834
+ std::int64_t waveformWaitUs = 0;
835
+ const Region &region = batch.regions[0];
836
+ // A2 is the controller's fast, non-flashing waveform specifically for
837
+ // repeated black/white animation. DU is intended for isolated direct
838
+ // changes and accumulated a visible gray bias during continuous game
839
+ // updates on this panel. Full recovery stays on GC16, and GL16 remains
840
+ // available for explicitly requested grayscale content.
841
+ const UpdateMode mode = region.full ? UpdateGc16 :
842
+ ((region.qualityGrayscale && !region.fastStreak) ? UpdateGl16 : UpdateA2);
843
+ // Wait for the PREVIOUS update's waveform lazily, right before this
844
+ // load needs the controller idle — not after our own update. The
845
+ // waveform (~300 ms for a large A2 partial) then runs while the main
846
+ // task rasters the next frame instead of serializing behind the SPI
847
+ // transfer, which cuts a back-to-back scroll cycle by that much.
848
+ if (ok && waveformPending_) {
849
+ ok = waitForWaveform("previous", waveformWaitUs);
850
+ waveformPending_ = false;
851
+ }
852
+ if (ok) {
853
+ // Single-shot load+display: the whole region transitions as ONE
854
+ // waveform. A split top/bottom pipelined load was tried (top half
855
+ // inks ~100 ms sooner) and reverted — the two out-of-phase half
856
+ // waveforms read as tearing on a page turn.
857
+ ok = loadRegion(region) && updateRegion(region, mode);
858
+ if (ok) waveformPending_ = true;
859
+ }
860
+ spi_device_release_bus(spi_);
861
+ const std::int64_t elapsed = esp_timer_get_time() - started;
862
+ stats_.txUs += elapsed;
863
+ stats_.chunkCount++;
864
+ if (ok) {
865
+ if (batch.full) partialsSinceFull_.store(0);
866
+ else partialsSinceFull_.fetch_add(1);
867
+ if (region.fastStreak) {
868
+ if (!settlePending_ || settleX1_ < settleX0_) {
869
+ settleX0_ = region.x;
870
+ settleY0_ = region.y;
871
+ settleX1_ = region.x + region.w - 1;
872
+ settleY1_ = region.y + region.h - 1;
873
+ } else {
874
+ settleX0_ = std::min(settleX0_, region.x);
875
+ settleY0_ = std::min(settleY0_, region.y);
876
+ settleX1_ = std::max(settleX1_, region.x + region.w - 1);
877
+ settleY1_ = std::max(settleY1_, region.y + region.h - 1);
878
+ }
879
+ settlePending_ = true;
880
+ } else if (settlePending_ &&
881
+ (region.full ||
882
+ (region.x <= settleX0_ && region.y <= settleY0_ &&
883
+ region.x + region.w - 1 >= settleX1_ &&
884
+ region.y + region.h - 1 >= settleY1_))) {
885
+ // A quality refresh already covered the streak's union.
886
+ settlePending_ = false;
887
+ settleX1_ = -1;
888
+ }
889
+ }
890
+ if (!ok) ESP_LOGE(kTag, "IT8951 refresh failed");
891
+ else {
892
+ ESP_LOGI(kTag, "%s refresh %dx%d@%d,%d mode=%u tx=%lldms wait=%lldms",
893
+ region.full ? "full" : "partial", region.w, region.h, region.x, region.y,
894
+ static_cast<unsigned>(mode), static_cast<long long>(elapsed / 1000),
895
+ static_cast<long long>(waveformWaitUs / 1000));
896
+ }
897
+ refreshInFlight_.store(false);
898
+ }
899
+ }
900
+ }
901
+
902
+ SemaphoreHandle_t mutex_ = nullptr;
903
+ SemaphoreHandle_t packMutex_ = nullptr;
904
+ spi_device_handle_t spi_ = nullptr;
905
+ TaskHandle_t refreshTask_ = nullptr;
906
+ gea::framework::graphics::Canvas canvas_;
907
+ // GRAY4: the framebuffer IS the panel's native 4bpp packed format (2 px/byte),
908
+ // so the render output needs no per-frame repack — the flush copies (or DMAs)
909
+ // these bytes straight to the IT8951. Canvas writes packed nibbles here.
910
+ std::uint8_t *frameBuffer_ = nullptr;
911
+ std::uint8_t *dmaChunk_ = nullptr;
912
+ std::uint8_t *dmaChunkB_ = nullptr;
913
+ std::uint16_t *backgroundCache_ = nullptr;
914
+ std::uint16_t *backdropCache_ = nullptr;
915
+ std::uint32_t imageMemory_ = kFallbackImageMemory;
916
+ std::atomic<std::uint32_t> pendingSeq_{0};
917
+ std::uint32_t transmittedSeq_ = 0;
918
+ RefreshBatch pendingBatch_ = {};
919
+ std::atomic<bool> refreshInFlight_{false};
920
+ // Refresh-task-local: an update was issued whose waveform completion has not
921
+ // been waited on yet (waited lazily before the next load; see refreshLoop).
922
+ bool waveformPending_ = false;
923
+ // Fast-streak (1-bit scroll) state: window from setRefreshConfig, the last
924
+ // request timestamp (streak detection), and the union of streak-touched
925
+ // logical pixels awaiting the post-streak GL16 quality re-display.
926
+ int fastStreakWindowUs_ = 0;
927
+ std::int64_t lastRequestUs_ = 0;
928
+ bool settlePending_ = false;
929
+ int settleX0_ = 0;
930
+ int settleY0_ = 0;
931
+ int settleX1_ = -1;
932
+ int settleY1_ = -1;
933
+ std::atomic<bool> forceFullRefresh_{false};
934
+ std::atomic<bool> qualityGrayscale_{false};
935
+ // Promote full-screen-covering partials to a flashing GC16 full (default).
936
+ // A reading app whose every page turn covers the screen opts out via
937
+ // Display.setEpaperRefreshConfig({ fullOnCover: 0 }) and clears ghosting
938
+ // through the fullRefreshEvery cadence instead.
939
+ std::atomic<bool> fullOnCover_{true};
940
+ std::atomic<int> partialsSinceFull_{0};
941
+ int fullRefreshEvery_ = kDefaultFullRefreshEvery;
942
+ int fullRefreshHardCap_ = kDefaultFullRefreshHardCap;
943
+ int rotation_ = 1;
944
+ bool backgroundAttempted_ = false;
945
+ bool backdropAttempted_ = false;
946
+ bool initialized_ = false;
947
+ bool needsFullPhysicalFlush_ = true;
948
+ platform_display::DisplayFlushPerfStats stats_ = {};
949
+ };
950
+
951
+ } // namespace
952
+
953
+ } // namespace gea::platform::m5paper::display
954
+
955
+ extern "C" void gea_epaper_set_refresh_config(
956
+ int fullEvery, int hardCap, int fastWindowMs,
957
+ const std::uint8_t *partialLut, int partialLutLength,
958
+ const std::uint8_t *fastLut, int fastLutLength)
959
+ {
960
+ gea::platform::m5paper::display::DisplayBackend::instance().setRefreshConfig(
961
+ fullEvery, hardCap, fastWindowMs, partialLut, partialLutLength, fastLut, fastLutLength);
962
+ }
963
+
964
+ extern "C" void gea_epaper_full_refresh(void)
965
+ {
966
+ gea::platform::m5paper::display::DisplayBackend::instance().requestFullRefresh();
967
+ }
968
+
969
+ extern "C" void gea_epaper_set_grayscale(int enabled)
970
+ {
971
+ gea::platform::m5paper::display::DisplayBackend::instance().setQualityGrayscale(enabled != 0);
972
+ }
973
+
974
+ extern "C" void gea_epaper_set_full_on_cover(int enabled)
975
+ {
976
+ gea::platform::m5paper::display::DisplayBackend::instance().setFullOnCover(enabled != 0);
977
+ }
978
+
979
+ extern "C" std::uint16_t *gea_bg_cache(int *capacity)
980
+ {
981
+ return gea::platform::m5paper::display::DisplayBackend::instance().backgroundCache(capacity);
982
+ }
983
+
984
+ extern "C" std::uint16_t *gea_backdrop_cache(int *capacity)
985
+ {
986
+ return gea::platform::m5paper::display::DisplayBackend::instance().backdropCache(capacity);
987
+ }
988
+
989
+ namespace gea::platform::display {
990
+
991
+ namespace {
992
+
993
+ using Backend = gea::platform::m5paper::display::DisplayBackend;
994
+ gea::framework::graphics::Canvas *drawingCanvas() { return Backend::instance().canvas(); }
995
+
996
+ } // namespace
997
+
998
+ bool Display::init() { return Backend::instance().init(); }
999
+ bool Display::start() { return Backend::instance().start(); }
1000
+ gea::framework::graphics::Canvas *Display::canvas() { return Backend::instance().canvas(); }
1001
+ bool Display::framebufferIsPanelDirect() { return false; }
1002
+ void Display::clear() { Backend::instance().clear(); }
1003
+ void Display::clearNoFlush() { Backend::instance().clearNoFlush(); }
1004
+ void Display::print(const char *) {}
1005
+ void Display::flush() { Backend::instance().flush(); }
1006
+ void Display::flushRects(const DisplayFlushRect *rects, int count, bool) { Backend::instance().flushRects(rects, count); }
1007
+ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raster, void *user) { return Backend::instance().streamRect(x, y, w, h, raster, user); }
1008
+ bool Display::present(const DisplayPresentCommand *commands, int count) { return Backend::instance().presentCommands(commands, count); }
1009
+ void Display::rebindCanvasToFramebuffer() { Backend::instance().rebindCanvasToFramebuffer(); }
1010
+ void Display::setFlushConfig(int rows, int depth) { Backend::instance().setFlushConfig(rows, depth); }
1011
+ void Display::reserveInternal(std::size_t) {}
1012
+ bool Display::setHighBrightnessMode(bool) { return false; }
1013
+ bool Display::highBrightnessMode() { return false; }
1014
+ void Display::applyPendingInternalReserve() {}
1015
+ int Display::flushChunkRows() { return Backend::instance().flushChunkRows(); }
1016
+ int Display::flushQueueDepth() { return Backend::instance().flushQueueDepth(); }
1017
+ int Display::flushBufferBytes() { return Backend::instance().flushBufferBytes(); }
1018
+ void Display::pushClip(int x, int y, int w, int h) { if (auto *c = drawingCanvas()) c->pushClip(x, y, w, h); }
1019
+ void Display::popClip() { if (auto *c = drawingCanvas()) c->popClip(); }
1020
+ void Display::resetClip() { if (auto *c = drawingCanvas()) c->resetClip(); }
1021
+ void Display::setAlpha(std::uint8_t alpha) { if (auto *c = drawingCanvas()) c->setGlobalAlpha(alpha); }
1022
+ std::uint8_t Display::alpha() { return drawingCanvas() ? drawingCanvas()->globalAlpha() : 255; }
1023
+ int Display::brightness() { return Backend::instance().brightness(); }
1024
+ void Display::setBrightness(int value) { Backend::instance().setBrightness(value); }
1025
+ void Display::setVSync(bool) {}
1026
+ bool Display::vsyncEnabled() { return false; }
1027
+ void Display::vsyncWaitForFrame() {}
1028
+ void Display::invalidate() {}
1029
+ void Display::clip(int *x0, int *y0, int *x1, int *y1) { if (auto *c = drawingCanvas()) c->currentClip(x0, y0, x1, y1); }
1030
+ void Display::fillRect(int x, int y, int w, int h, pixel::native_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, w, h, color); }
1031
+ 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); }
1032
+ void Display::resetScrollRegion() {}
1033
+ void Display::strokeRect(int x, int y, int w, int h, pixel::native_t color) { if (auto *c = drawingCanvas()) c->strokeRect(x, y, w, h, color); }
1034
+ void Display::fillCircle(int x, int y, int r, pixel::native_t color) { if (auto *c = drawingCanvas()) c->fillCircle(x, y, r, color); }
1035
+ void Display::strokeCircle(int x, int y, int r, pixel::native_t color) { if (auto *c = drawingCanvas()) c->strokeCircle(x, y, r, color); }
1036
+ void Display::drawLine(int x0, int y0, int x1, int y1, pixel::native_t color) { if (auto *c = drawingCanvas()) c->drawLine(x0, y0, x1, y1, color); }
1037
+ void Display::drawArc(int x, int y, int r, int start, int end, pixel::native_t color) { if (auto *c = drawingCanvas()) c->drawArc(x, y, r, start, end, color); }
1038
+ void Display::fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, pixel::native_t color) { if (auto *c = drawingCanvas()) c->fillTriangle(x0, y0, x1, y1, x2, y2, color); }
1039
+ void Display::drawText(const char *text, int x, int y, pixel::native_t color, float scale) { if (auto *c = drawingCanvas()) c->drawText(text, x, y, color, scale); }
1040
+ void Display::drawTextFont(const char *text, int x, int y, pixel::native_t color, int font) { if (auto *c = drawingCanvas()) c->drawTextFont(text, x, y, color, font); }
1041
+ void Display::drawTextFontFamily(const char *text, int x, int y, pixel::native_t color, int family, int size) { if (auto *c = drawingCanvas()) c->drawTextFontFamily(text, x, y, color, family, size); }
1042
+ void Display::setPixel(int x, int y, pixel::native_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, 1, 1, color); }
1043
+ void Display::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, pixel::native_t color) { if (auto *c = drawingCanvas()) c->fillRoundedRect(x, y, w, h, tl, tr, br, bl, color); }
1044
+ 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 pixel::native_t *colors) { if (auto *c = drawingCanvas()) c->fillRoundedRectBoxesRgb565(xs, ys, count, w, h, tl, tr, br, bl, colors); }
1045
+ void Display::strokeRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, int lw, pixel::native_t color) { if (auto *c = drawingCanvas()) c->strokeRoundedRect(x, y, w, h, tl, tr, br, bl, lw, color); }
1046
+ void Display::blitImage(const pixel::native_t *src, const std::uint8_t *alpha, int sw, int sh, int x, int y) { if (auto *c = drawingCanvas()) c->drawImage(src, alpha, sw, sh, x, y); }
1047
+ void Display::blitImageScaled(const pixel::native_t *src, const std::uint8_t *alpha, int sw, int sh, int x, int y, int w, int h) { if (auto *c = drawingCanvas()) c->drawImage(src, alpha, sw, sh, x, y, w, h); }
1048
+ void Display::setWorldOverlay(const std::uint16_t *, int, int, int, int) {}
1049
+ void Display::setWorldScroll(int) {}
1050
+ void Display::flushStatsRead(std::int64_t *us, int *calls, int *pixels)
1051
+ {
1052
+ const auto stats = Backend::instance().flushStats();
1053
+ if (us) *us = stats.totalUs;
1054
+ if (calls) *calls = stats.callCount;
1055
+ if (pixels) *pixels = stats.pixelCount;
1056
+ }
1057
+ DisplayFlushPerfStats Display::flushPerfStatsRead() { return Backend::instance().flushStats(); }
1058
+ void Display::flushStatsReset() { Backend::instance().flushStatsReset(); }
1059
+ const char *Display::flushStageName() { return Backend::instance().flushStageName(); }
1060
+ int Display::flushStageChunk() { return 0; }
1061
+ DisplayFlushStageDetail Display::flushStageDetail() { return {}; }
1062
+ bool Display::copySnapshotRgb565(std::uint16_t *dst, int capacity, int *w, int *h, bool) { return Backend::instance().copySnapshotRgb565(dst, capacity, w, h); }
1063
+ bool Display::copySnapshotPacked(std::uint8_t *dst, int byteCapacity, int *w, int *h, bool) { return Backend::instance().copySnapshotPacked(dst, byteCapacity, w, h); }
1064
+ int Display::countNonBlackPixels(bool) { return Backend::instance().countNonBlackPixels(); }
1065
+
1066
+ // The canvas draws directly into the packed 4bpp framebuffer, so the presented
1067
+ // copy IS the live frame; the retained-snapshot re-replay reads the packed
1068
+ // storage as unpacked and lies.
1069
+ extern "C" bool geaDisplaySnapshotPrefersPresented() { return true; }
1070
+
1071
+ void applyOrientation(gea::framework::display::DisplayOrientation orientation) { Backend::instance().applyOrientation(orientation); }
1072
+ bool autoRotateAllowed() { return false; }
1073
+
1074
+ } // namespace gea::platform::display