@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,1281 @@
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
+
15
+ #include "driver/gpio.h"
16
+ #include "driver/spi_master.h"
17
+ #include "esp_err.h"
18
+ #include "esp_heap_caps.h"
19
+ #include "esp_log.h"
20
+ #include "esp_timer.h"
21
+ #include "freertos/FreeRTOS.h"
22
+ #include "freertos/semphr.h"
23
+ #include "freertos/task.h"
24
+
25
+ namespace platform_display = gea::platform::display;
26
+ namespace orientation_detail = gea::framework::display::detail;
27
+ namespace pixel = gea::framework::graphics::pixel;
28
+ namespace present = gea::framework::display_present;
29
+
30
+ namespace gea::platform::esp32_s3_epaper::display {
31
+
32
+ namespace {
33
+
34
+ constexpr const char *kTag = "epaper_display";
35
+ constexpr int kNativeWidth = platform_display::kNativeWidth; // 200
36
+ constexpr int kNativeHeight = platform_display::kNativeHeight; // 200
37
+ constexpr int kMaxPixels = kNativeWidth * kNativeHeight;
38
+ // 1-bit packed panel frame: 200/8 = 25 bytes per row.
39
+ constexpr int kPackedStride = kNativeWidth / 8;
40
+ constexpr int kPackedBytes = kPackedStride * kNativeHeight;
41
+ // SSD1681 datasheet caps the write clock at 20 MHz; the full packed frame is
42
+ // 5000 bytes, so the RAM write itself is ~2 ms — refresh time is dominated by
43
+ // the waveform (~0.4 s partial, ~1.5 s full), not the SPI.
44
+ constexpr int kSpiClockHz = 20 * 1000 * 1000;
45
+ // Ghosting control: run a full (flashing) refresh after this many partial
46
+ // updates — but only when updates are sparse (a flash mid-animation would
47
+ // freeze it for ~1.5 s). During a fast streak the full refresh is deferred to
48
+ // the first idle moment, with a hard cap so trails can never run away.
49
+ // Defaults; apps can retune all of these (and supply their own waveform LUTs)
50
+ // at runtime via Display.setEpaperRefreshConfig().
51
+ constexpr int kFullRefreshEveryPartials = 30;
52
+ constexpr int kFullRefreshHardCapPartials = 240;
53
+ // Updates arriving within this window of the previous refresh are a "streak"
54
+ // (animation / held button): switch to the fast partial waveform.
55
+ constexpr std::int64_t kFastStreakWindowUs = 1000 * 1000;
56
+ constexpr int kLutBytes = 159;
57
+
58
+ // Waveshare 1.54" V2 (SSD1681) waveform LUTs, from the vendor BSP
59
+ // (docs/scratch/ref-esp32-s3-epaper-154). 153 LUT bytes + gate/source voltage
60
+ // and dummy-line trailer consumed by EPD_SetLut.
61
+ const uint8_t kLutFull[159] = {
62
+ 0x80, 0x48, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
63
+ 0x40, 0x48, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
64
+ 0x80, 0x48, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
65
+ 0x40, 0x48, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
66
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
67
+ 0xA, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
68
+ 0x8, 0x1, 0x0, 0x8, 0x1, 0x0, 0x2,
69
+ 0xA, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
70
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
71
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
72
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
73
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
74
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
75
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
76
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
77
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
78
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
79
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0,
80
+ 0x22, 0x17, 0x41, 0x0, 0x32, 0x20,
81
+ };
82
+
83
+ const uint8_t kLutPartial[159] = {
84
+ 0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
85
+ 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
86
+ 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
87
+ 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
88
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
89
+ 0xF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
90
+ 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
91
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
92
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
93
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
94
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
95
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
96
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
97
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
98
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
99
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
100
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
101
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0,
102
+ 0x02, 0x17, 0x41, 0xB0, 0x32, 0x28,
103
+ };
104
+
105
+ // Fast partial waveform: the vendor partial LUT with the drive phase cut to 4
106
+ // frames and the frame-rate nibbles raised 0x2 -> 0x7. Measured on-device:
107
+ // ~265 ms/refresh vs the vendor partial's ~360 ms (~30% faster). This panel's
108
+ // controller stepping has a ~240 ms floor in the mode-2 update sequence that
109
+ // LUT timing fields don't reach (TP counts only cost ~5 ms/frame at FR 0x7;
110
+ // FR 0xF is no faster than 0x7) — so this is near the floor, not a tuning
111
+ // timidity. Lighter blacks/ghost trails are the trade; used only during
112
+ // update streaks, and the periodic full refresh wipes the residue.
113
+ const uint8_t kLutPartialFast[159] = {
114
+ 0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
115
+ 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
116
+ 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
117
+ 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
118
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
119
+ 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
120
+ 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0,
121
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
122
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
123
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
124
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
125
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
126
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
127
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
128
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
129
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
130
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
131
+ 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x0, 0x0, 0x0,
132
+ 0x02, 0x17, 0x41, 0xB0, 0x32, 0x28,
133
+ };
134
+
135
+ constexpr int kLut4GrayBytes = 153;
136
+
137
+ // 4-level grayscale waveform LUT for the SSD1681 (GDEY0154D67 panel class),
138
+ // from ZinggJM/GxEPD2_4G (src/gdey/GxEPD2_154_GDEY0154D67.cpp, lut_4G). 153
139
+ // bytes written verbatim via 0x32; unlike the B/W LUT, gray mode does NOT
140
+ // program the gate/source-voltage trailer (0x3F/0x03/0x04/0x2C) — it relies on
141
+ // the controller OTP defaults, matching the reference library. The 4 RAM-plane
142
+ // bit combinations select VS groups L0..L3 (white / light / dark / black); the
143
+ // per-pixel encoding lives in packFrameGray below.
144
+ const uint8_t kLut4Gray[kLut4GrayBytes] = {
145
+ 0x40, 0x48, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L0 white
146
+ 0x08, 0x48, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L1 light grey
147
+ 0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L2 dark grey
148
+ 0x20, 0x48, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L3 black
149
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L4 vcom
150
+ 0x0A, 0x19, 0x00, 0x03, 0x08, 0x00, 0x00, // TP0
151
+ 0x14, 0x01, 0x00, 0x14, 0x01, 0x00, 0x03, // TP1
152
+ 0x0A, 0x03, 0x00, 0x08, 0x19, 0x00, 0x00, // TP2
153
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // TP3
154
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP4
155
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP5
156
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP6
157
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP7
158
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP8
159
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP9
160
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP10
161
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP11
162
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00,
163
+ };
164
+
165
+ // 4x4 ordered-dither thresholds (Bayer), pre-scaled to 8-bit luma. The counter
166
+ // UI is dark-themed: a plain 50% threshold would collapse the navy background
167
+ // and the gray button fills into the same solid black. Dithering keeps the
168
+ // mid-gray fills visually distinct on the 1-bit panel.
169
+ constexpr uint8_t kBayer4x4[4][4] = {
170
+ {8, 136, 40, 168},
171
+ {200, 72, 232, 104},
172
+ {56, 184, 24, 152},
173
+ {248, 120, 216, 88},
174
+ };
175
+
176
+ // Whether to ordered-dither into the 1-bit panel. Dithering only earns its keep
177
+ // for continuous-tone content (gray fills, gradients, grayscale imagery). For a
178
+ // pure black/white UI like voice-notes it does the opposite: the framebuffer's
179
+ // only non-B/W pixels are the anti-aliased edges of glyphs (and AA'd shapes),
180
+ // so dithering scatters every letter's rim into speckle. With dithering off we
181
+ // hard-threshold at 50% luma, snapping those AA edges to crisp black/white.
182
+ // Flip this to true on a build whose app renders real gray fills/images.
183
+ constexpr bool kDitherToPanel = false;
184
+ constexpr uint8_t kMonoThreshold = 128;
185
+
186
+ inline uint8_t lumaFromRgb565(std::uint16_t c)
187
+ {
188
+ const int r = ((c >> 11) & 0x1f);
189
+ const int g = ((c >> 5) & 0x3f);
190
+ const int b = (c & 0x1f);
191
+ const int r8 = (r << 3) | (r >> 2);
192
+ const int g8 = (g << 2) | (g >> 4);
193
+ const int b8 = (b << 3) | (b >> 2);
194
+ return static_cast<uint8_t>((r8 * 77 + g8 * 150 + b8 * 29) >> 8);
195
+ }
196
+
197
+ // 4-level grayscale: classify 8-bit luma into one of four levels. Level 3 is
198
+ // white (brightest), level 0 is black. The two intermediate levels map to the
199
+ // SSD1681's two single-plane waveform groups.
200
+ inline uint8_t grayLevelFromLuma(uint8_t luma)
201
+ {
202
+ // Compressed/perceptual quantization. 4 levels is the SSD1681 ceiling, so
203
+ // linear quarter thresholds (64/128/192) snap thin anti-aliased glyph edges
204
+ // — whose pixels cluster near-black/near-white — straight to pure B/W, and
205
+ // small text reads 1-bit. Narrowing the pure-black/white bands and widening
206
+ // the two grey bands (≈ perceptual midpoints of evenly-spaced reflectances)
207
+ // pulls those edge pixels into dark/light grey, softening text. Pure ink
208
+ // (luma 0) stays black and pure paper (255) stays white. No dithering — it
209
+ // would speckle thin text.
210
+ if (luma >= 208) return 3; // white
211
+ if (luma >= 128) return 2; // light grey
212
+ if (luma >= 48) return 1; // dark grey
213
+ return 0; // black
214
+ }
215
+
216
+ // The bit a level contributes to each RAM plane, as actually transmitted to the
217
+ // controller. Replicates GxEPD2_4G's writeImage_4G (after its ~out_byte
218
+ // inversion): white -> {0,0}, black -> {1,1}, light grey -> {plane24=1,
219
+ // plane26=0}, dark grey -> {plane24=0, plane26=1}. The (plane26,plane24) RAM
220
+ // pair selects VS group L0..L3 in kLut4Gray.
221
+ inline bool grayPlane24Bit(uint8_t level) { return level == 2 || level == 0; }
222
+ inline bool grayPlane26Bit(uint8_t level) { return level == 1 || level == 0; }
223
+
224
+ present::Rect clampLogicalRect(present::Rect rect, int width, int height)
225
+ {
226
+ if (width <= 0 || height <= 0) return {};
227
+ rect = present::clampAndAlign(rect, width, height);
228
+ if (!present::valid(rect)) return {};
229
+ return rect;
230
+ }
231
+
232
+ } // namespace
233
+
234
+ class DisplayBackend {
235
+ public:
236
+ static DisplayBackend &instance()
237
+ {
238
+ static DisplayBackend backend;
239
+ return backend;
240
+ }
241
+
242
+ bool init()
243
+ {
244
+ if (initialized_) return true;
245
+ mutex_ = xSemaphoreCreateMutex();
246
+ packMutex_ = xSemaphoreCreateMutex();
247
+ if (!mutex_ || !packMutex_) {
248
+ ESP_LOGE(kTag, "failed to allocate display mutexes");
249
+ return false;
250
+ }
251
+
252
+ frameBuffer_ = static_cast<std::uint16_t *>(
253
+ heap_caps_malloc(static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t),
254
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
255
+ if (!frameBuffer_) {
256
+ ESP_LOGE(kTag, "framebuffer alloc failed");
257
+ return false;
258
+ }
259
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
260
+
261
+ // Two packed 1-bit frames: the frame task packs into pending_, the
262
+ // refresh worker copies into tx_ and transmits. Only tx_ is DMA'd (it is
263
+ // the SPI source), so it stays internal DMA-capable RAM. pending_ is
264
+ // CPU-only (packed by packFrame, then memcpy'd into tx_), so it lives in
265
+ // PSRAM — that reclaims ~5 KB of scarce internal DMA RAM, which with WiFi
266
+ // up is what lets the SD card allocate its read DMA buffer (otherwise
267
+ // sdmmc allocate_dma_buf NO_MEMs and the WAV can't be read to upload).
268
+ pendingPack_ = static_cast<uint8_t *>(
269
+ heap_caps_malloc(kPackedBytes, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
270
+ txPack_ = static_cast<uint8_t *>(
271
+ heap_caps_malloc(kPackedBytes, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
272
+ // Second RAM plane (0x26) is used ONLY in 4-level grayscale mode. It is now
273
+ // allocated LAZILY on the first setGrayscale(true) instead of up front, so
274
+ // B/W apps (the default — e.g. voice-notes) don't pin ~10 KB of DMA-capable
275
+ // internal RAM. On this RAM-tight board that reclaimed 10 KB is what lets
276
+ // esp_wifi_init succeed: WiFi needs a contiguous DMA-internal pool, and the
277
+ // 1-bit e-paper panel has no large display staging for reserveInternal to
278
+ // reclaim the way the AMOLED boards do.
279
+ if (!pendingPack_ || !txPack_) {
280
+ ESP_LOGE(kTag, "packed frame alloc failed");
281
+ return false;
282
+ }
283
+ std::memset(pendingPack_, 0xff, kPackedBytes);
284
+ std::memset(txPack_, 0xff, kPackedBytes);
285
+
286
+ if (!initPanel()) {
287
+ ESP_LOGE(kTag, "panel init failed");
288
+ return false;
289
+ }
290
+ bindCanvas();
291
+
292
+ // Refresh worker off the frame task: a partial refresh holds BUSY for
293
+ // ~0.4 s (full ~1.5 s) and must never stall input/event processing.
294
+ // Updates landing while a refresh is in flight coalesce into pending_.
295
+ if (xTaskCreatePinnedToCore(refreshTaskEntry, "epd_refresh", 4096, this, 5, &refreshTask_, 1) != pdPASS) {
296
+ ESP_LOGE(kTag, "failed to start refresh task");
297
+ return false;
298
+ }
299
+
300
+ initialized_ = true;
301
+ ESP_LOGI(kTag, "e-paper display ready %dx%d (packed %d bytes)", kNativeWidth, kNativeHeight, kPackedBytes);
302
+ return true;
303
+ }
304
+
305
+ bool start() { return init(); }
306
+
307
+ gea::framework::graphics::Canvas *canvas()
308
+ {
309
+ if (!frameBuffer_) init();
310
+ return &canvas_;
311
+ }
312
+
313
+ bool framebufferIsPanelDirect() const { return false; }
314
+
315
+ void applyOrientation()
316
+ {
317
+ // Square panel: every orientation is 200x200; just repaint fully.
318
+ take();
319
+ bindCanvasLocked();
320
+ if (frameBuffer_) {
321
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
322
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
323
+ previousPresentValid_ = false;
324
+ needsFullPhysicalFlush_ = true;
325
+ }
326
+ give();
327
+ }
328
+
329
+ void clear()
330
+ {
331
+ clearNoFlush();
332
+ flush();
333
+ }
334
+
335
+ void clearNoFlush()
336
+ {
337
+ if (!frameBuffer_) init();
338
+ take();
339
+ std::memset(frameBuffer_, 0, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
340
+ canvas_.markDirty(0, 0, logicalWidth() - 1, logicalHeight() - 1);
341
+ previousPresentValid_ = false;
342
+ needsFullPhysicalFlush_ = true;
343
+ give();
344
+ }
345
+
346
+ // The panel always receives the full packed 200x200 frame (5000 bytes —
347
+ // cheaper to pack wholesale than to window), so flush granularity only
348
+ // decides WHETHER to refresh, never what subset to send.
349
+ void flush()
350
+ {
351
+ if (!init()) return;
352
+ if (!needsFullPhysicalFlush_ && !canvas_.dirty(nullptr, nullptr, nullptr, nullptr)) return;
353
+ const std::int64_t started = esp_timer_get_time();
354
+ if (needsFullPhysicalFlush_) forceFullRefresh_.store(true, std::memory_order_release);
355
+ requestRefresh();
356
+ canvas_.resetDirty();
357
+ needsFullPhysicalFlush_ = false;
358
+ flushStats_.callCount++;
359
+ flushStats_.totalUs += esp_timer_get_time() - started;
360
+ }
361
+
362
+ void flushRects(const platform_display::DisplayFlushRect *rects, int count)
363
+ {
364
+ if (!rects || count <= 0) return;
365
+ if (!init()) return;
366
+ const std::int64_t started = esp_timer_get_time();
367
+ if (needsFullPhysicalFlush_) forceFullRefresh_.store(true, std::memory_order_release);
368
+ requestRefresh();
369
+ canvas_.resetDirty();
370
+ needsFullPhysicalFlush_ = false;
371
+ flushStats_.callCount++;
372
+ flushStats_.totalUs += esp_timer_get_time() - started;
373
+ }
374
+
375
+ bool streamRect(int x, int y, int w, int h, platform_display::DisplayStreamRasterFn raster, void *user)
376
+ {
377
+ if (!raster || w <= 0 || h <= 0) return false;
378
+ if (!init()) return false;
379
+ const int x0 = std::max(0, x);
380
+ const int y0 = std::max(0, y);
381
+ const int x1 = std::min(logicalWidth() - 1, x + w - 1);
382
+ const int y1 = std::min(logicalHeight() - 1, y + h - 1);
383
+ if (x0 > x1 || y0 > y1) return true;
384
+ const int width = x1 - x0 + 1;
385
+ for (int row = y0; row <= y1; ++row) {
386
+ raster(frameBuffer_ + static_cast<std::size_t>(row) * kNativeWidth + x0, width, 1, x0, row, user);
387
+ }
388
+ canvas_.markDirty(x0, y0, x1, y1);
389
+ flush();
390
+ return true;
391
+ }
392
+
393
+ bool presentCommands(const platform_display::DisplayPresentCommand *commands, int commandCount)
394
+ {
395
+ if (!commands || commandCount <= 0 || !init()) return false;
396
+ present::Frame current;
397
+ if (!present::extractFrame(commands, commandCount, current)) return false;
398
+ if (!present::frameHasOpaqueBase(current, logicalWidth(), logicalHeight())) return false;
399
+ // The panel gets the whole packed frame anyway, so raster the whole
400
+ // frame — diffing against the previous present buys nothing here.
401
+ const present::Rect full = present::fullScreen(logicalWidth(), logicalHeight());
402
+ const std::int64_t started = esp_timer_get_time();
403
+ rasterPresentRegion(current, full);
404
+ if (needsFullPhysicalFlush_) forceFullRefresh_.store(true, std::memory_order_release);
405
+ requestRefresh();
406
+ flushStats_.callCount++;
407
+ flushStats_.totalUs += esp_timer_get_time() - started;
408
+ previousPresentFrame_ = std::move(current);
409
+ previousPresentValid_ = true;
410
+ needsFullPhysicalFlush_ = false;
411
+ canvas_.resetDirty();
412
+ return true;
413
+ }
414
+
415
+ void setFlushConfig(int, int) {}
416
+ int flushChunkRows() const { return kNativeHeight; }
417
+ int flushQueueDepth() const { return 1; }
418
+ int flushBufferBytes() const { return kPackedBytes; }
419
+
420
+ bool copySnapshotRgb565(std::uint16_t *dst, int pixelCapacity, int *width, int *height)
421
+ {
422
+ if (!dst || pixelCapacity < kMaxPixels || !frameBuffer_) return false;
423
+ if (width) *width = logicalWidth();
424
+ if (height) *height = logicalHeight();
425
+ std::memcpy(dst, frameBuffer_, static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t));
426
+ return true;
427
+ }
428
+
429
+ int countNonBlackPixels() const
430
+ {
431
+ if (!frameBuffer_) return 0;
432
+ int count = 0;
433
+ for (int i = 0; i < kMaxPixels; ++i) {
434
+ if (pixel::toRgb565(frameBuffer_[i]) != 0) ++count;
435
+ }
436
+ return count;
437
+ }
438
+
439
+ // No backlight on an e-paper panel.
440
+ void setBrightness(int) {}
441
+ int brightness() const { return 100; }
442
+
443
+ platform_display::DisplayFlushPerfStats flushStats() const { return flushStats_; }
444
+ void flushStatsReset() { flushStats_ = {}; }
445
+ const char *flushStageName() const { return refreshInFlight_.load(std::memory_order_acquire) ? "epd-refresh" : "idle"; }
446
+ int flushStageChunk() const { return 0; }
447
+ platform_display::DisplayFlushStageDetail flushStageDetail() const { return {}; }
448
+
449
+ std::uint16_t *backgroundCache(int *capPx) { return fullScreenScratch(backgroundCache_, backgroundCacheAttempted_, capPx, "background"); }
450
+ std::uint16_t *backdropCache(int *capPx) { return fullScreenScratch(backdropCache_, backdropCacheAttempted_, capPx, "backdrop"); }
451
+
452
+ private:
453
+ DisplayBackend() = default;
454
+
455
+ int logicalWidth() const { return orientation_detail::DisplayOrientationState::width(); }
456
+ int logicalHeight() const { return orientation_detail::DisplayOrientationState::height(); }
457
+
458
+ std::uint16_t *fullScreenScratch(std::uint16_t *&buffer, bool &attempted, int *capPx, const char *label)
459
+ {
460
+ if (!attempted) {
461
+ attempted = true;
462
+ buffer = static_cast<std::uint16_t *>(
463
+ heap_caps_malloc(static_cast<std::size_t>(kMaxPixels) * sizeof(std::uint16_t),
464
+ MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
465
+ if (!buffer) ESP_LOGW(kTag, "failed to allocate %s cache", label);
466
+ }
467
+ if (capPx) *capPx = buffer ? kMaxPixels : 0;
468
+ return buffer;
469
+ }
470
+
471
+ void bindCanvas()
472
+ {
473
+ take();
474
+ bindCanvasLocked();
475
+ give();
476
+ }
477
+
478
+ void bindCanvasLocked()
479
+ {
480
+ if (!frameBuffer_) return;
481
+ if (canvas_.pixels() == frameBuffer_ && canvas_.width() == kNativeWidth && canvas_.height() == kNativeHeight) return;
482
+ canvas_.bindPixels(frameBuffer_, kNativeWidth, kNativeHeight, kNativeWidth);
483
+ }
484
+
485
+ void rasterPresentRegion(const present::Frame &frame, const present::Rect &region)
486
+ {
487
+ if (!present::valid(region)) return;
488
+ const int width = region.x1 - region.x0 + 1;
489
+ std::uint16_t *target = frameBuffer_ + static_cast<std::size_t>(region.y0) * kNativeWidth + region.x0;
490
+ present::rasterFrameRowsStrided(target,
491
+ kNativeWidth,
492
+ region.x0,
493
+ width,
494
+ region.y0,
495
+ region.y1 - region.y0 + 1,
496
+ logicalHeight(),
497
+ frame);
498
+ }
499
+
500
+ // --- RGB565 -> 1-bit packing -------------------------------------------
501
+
502
+ // Pack the live framebuffer into pending_ and kick the worker. Runs on the
503
+ // frame task; ~40k pixels of integer math, well under a millisecond.
504
+ void requestRefresh()
505
+ {
506
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
507
+ if (grayscaleEnabled_) {
508
+ packFrameGray(pendingPack_, pendingPack26_);
509
+ } else {
510
+ packFrame(pendingPack_);
511
+ }
512
+ pendingSeq_.fetch_add(1, std::memory_order_release);
513
+ xSemaphoreGive(packMutex_);
514
+ if (refreshTask_) xTaskNotifyGive(refreshTask_);
515
+ }
516
+
517
+ void packFrame(uint8_t *dst)
518
+ {
519
+ for (int y = 0; y < kNativeHeight; ++y) {
520
+ const std::uint16_t *src = frameBuffer_ + static_cast<std::size_t>(y) * kNativeWidth;
521
+ uint8_t *row = dst + static_cast<std::size_t>(y) * kPackedStride;
522
+ for (int xb = 0; xb < kPackedStride; ++xb) {
523
+ uint8_t bits = 0;
524
+ const int x0 = xb << 3;
525
+ for (int bit = 0; bit < 8; ++bit) {
526
+ const uint8_t luma = lumaFromRgb565(src[x0 + bit]);
527
+ const uint8_t threshold = kDitherToPanel ? kBayer4x4[y & 3][(x0 + bit) & 3] : kMonoThreshold;
528
+ if (luma >= threshold) bits |= static_cast<uint8_t>(0x80 >> bit);
529
+ }
530
+ row[xb] = bits;
531
+ }
532
+ }
533
+ }
534
+
535
+ // Pack the framebuffer into the two SSD1681 RAM planes for 4-level
536
+ // grayscale. Each pixel's luma picks one of four levels; the level's bit in
537
+ // each plane is laid down MSB-first, matching the gray waveform LUT's group
538
+ // selection. Records the per-level histogram for the next refresh log.
539
+ void packFrameGray(uint8_t *dst24, uint8_t *dst26)
540
+ {
541
+ std::uint32_t counts[4] = {0, 0, 0, 0};
542
+ for (int y = 0; y < kNativeHeight; ++y) {
543
+ const std::uint16_t *src = frameBuffer_ + static_cast<std::size_t>(y) * kNativeWidth;
544
+ uint8_t *row24 = dst24 + static_cast<std::size_t>(y) * kPackedStride;
545
+ uint8_t *row26 = dst26 + static_cast<std::size_t>(y) * kPackedStride;
546
+ for (int xb = 0; xb < kPackedStride; ++xb) {
547
+ uint8_t b24 = 0;
548
+ uint8_t b26 = 0;
549
+ const int x0 = xb << 3;
550
+ for (int bit = 0; bit < 8; ++bit) {
551
+ const uint8_t level = grayLevelFromLuma(lumaFromRgb565(src[x0 + bit]));
552
+ counts[level]++;
553
+ const uint8_t mask = static_cast<uint8_t>(0x80 >> bit);
554
+ if (grayPlane24Bit(level)) b24 |= mask;
555
+ if (grayPlane26Bit(level)) b26 |= mask;
556
+ }
557
+ row24[xb] = b24;
558
+ row26[xb] = b26;
559
+ }
560
+ }
561
+ for (int i = 0; i < 4; ++i) lastGrayLevelCounts_[i] = counts[i];
562
+ }
563
+
564
+ // --- SSD1681 panel transport (vendor BSP command sequences) -------------
565
+
566
+ void setCs(int level) { gpio_set_level(gea::platform::board::display.cs, level); }
567
+ void setDc(int level) { gpio_set_level(gea::platform::board::display.dc, level); }
568
+ void setRst(int level) { gpio_set_level(gea::platform::board::display.reset, level); }
569
+
570
+ void waitBusy()
571
+ {
572
+ // BUSY high = controller refreshing. Full refresh holds it ~1.5 s.
573
+ const std::int64_t deadline = esp_timer_get_time() + 5000000;
574
+ while (gpio_get_level(gea::platform::board::display.busy) == 1) {
575
+ if (esp_timer_get_time() > deadline) {
576
+ ESP_LOGE(kTag, "BUSY stuck high >5s");
577
+ return;
578
+ }
579
+ vTaskDelay(pdMS_TO_TICKS(5));
580
+ }
581
+ }
582
+
583
+ void spiSendByte(uint8_t data)
584
+ {
585
+ spi_transaction_t t = {};
586
+ t.length = 8;
587
+ t.tx_buffer = &data;
588
+ ESP_ERROR_CHECK_WITHOUT_ABORT(spi_device_polling_transmit(spi_, &t));
589
+ }
590
+
591
+ void sendCommand(uint8_t command)
592
+ {
593
+ setDc(0);
594
+ setCs(0);
595
+ spiSendByte(command);
596
+ setCs(1);
597
+ }
598
+
599
+ void sendData(uint8_t data)
600
+ {
601
+ setDc(1);
602
+ setCs(0);
603
+ spiSendByte(data);
604
+ setCs(1);
605
+ }
606
+
607
+ void sendDataBytes(const uint8_t *data, int len)
608
+ {
609
+ setDc(1);
610
+ setCs(0);
611
+ spi_transaction_t t = {};
612
+ t.length = static_cast<std::size_t>(len) * 8;
613
+ t.tx_buffer = data;
614
+ ESP_ERROR_CHECK_WITHOUT_ABORT(spi_device_polling_transmit(spi_, &t));
615
+ setCs(1);
616
+ }
617
+
618
+ void setWindow(uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd)
619
+ {
620
+ sendCommand(0x44);
621
+ sendData((xStart >> 3) & 0xFF);
622
+ sendData((xEnd >> 3) & 0xFF);
623
+ sendCommand(0x45);
624
+ sendData(yStart & 0xFF);
625
+ sendData((yStart >> 8) & 0xFF);
626
+ sendData(yEnd & 0xFF);
627
+ sendData((yEnd >> 8) & 0xFF);
628
+ }
629
+
630
+ void setCursor(uint16_t x, uint16_t y)
631
+ {
632
+ sendCommand(0x4E);
633
+ sendData(x & 0xFF);
634
+ sendCommand(0x4F);
635
+ sendData(y & 0xFF);
636
+ sendData((y >> 8) & 0xFF);
637
+ }
638
+
639
+ void setLut(const uint8_t *lut)
640
+ {
641
+ sendCommand(0x32);
642
+ sendDataBytes(lut, 153);
643
+ waitBusy();
644
+ sendCommand(0x3f);
645
+ sendData(lut[153]);
646
+ sendCommand(0x03);
647
+ sendData(lut[154]);
648
+ sendCommand(0x04);
649
+ sendData(lut[155]);
650
+ sendData(lut[156]);
651
+ sendData(lut[157]);
652
+ sendCommand(0x2c);
653
+ sendData(lut[158]);
654
+ }
655
+
656
+ void hardwareReset()
657
+ {
658
+ setRst(1);
659
+ vTaskDelay(pdMS_TO_TICKS(50));
660
+ setRst(0);
661
+ vTaskDelay(pdMS_TO_TICKS(20));
662
+ setRst(1);
663
+ vTaskDelay(pdMS_TO_TICKS(50));
664
+ }
665
+
666
+ // Full-waveform init (vendor EPD_Init): SWRESET, driver output 0xC7=199
667
+ // gates, data entry Y-decrement/X-increment with the cursor at the top, so
668
+ // linearly streamed RAM bytes land top row first.
669
+ void panelInitFull()
670
+ {
671
+ hardwareReset();
672
+ waitBusy();
673
+ sendCommand(0x12); // SWRESET
674
+ waitBusy();
675
+ sendCommand(0x01); // driver output control
676
+ sendData(0xC7);
677
+ sendData(0x00);
678
+ sendData(0x01);
679
+ sendCommand(0x11); // data entry mode: X inc, Y dec
680
+ sendData(0x01);
681
+ setWindow(0, kNativeWidth - 1, kNativeHeight - 1, 0);
682
+ sendCommand(0x3C); // border waveform
683
+ sendData(0x01);
684
+ sendCommand(0x18); // internal temperature sensor
685
+ sendData(0x80);
686
+ sendCommand(0x22); // load temperature + waveform
687
+ sendData(0xB1);
688
+ sendCommand(0x20);
689
+ setCursor(0, kNativeHeight - 1);
690
+ waitBusy();
691
+ setLut(kLutFull);
692
+ }
693
+
694
+ // Vendor partial-LUT activation: the LUT write only lands after the
695
+ // display-option block + the 0x22=0xC0/0x20 analog re-enable — a bare
696
+ // 0x32 write mid-flight leaves the previously latched waveform running.
697
+ void activatePartialLut(const uint8_t *lut)
698
+ {
699
+ setLut(lut);
700
+ sendCommand(0x37);
701
+ const uint8_t otp[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00};
702
+ for (int i = 0; i < 10; ++i) sendData(otp[i]);
703
+ sendCommand(0x3C); // border waveform
704
+ sendData(0x80);
705
+ sendCommand(0x22);
706
+ sendData(0xc0);
707
+ sendCommand(0x20);
708
+ waitBusy();
709
+ }
710
+
711
+ void panelInitPartial()
712
+ {
713
+ hardwareReset();
714
+ waitBusy();
715
+ activatePartialLut(kLutPartial);
716
+ }
717
+
718
+ void turnOnDisplayFull()
719
+ {
720
+ sendCommand(0x22);
721
+ sendData(0xc7);
722
+ sendCommand(0x20);
723
+ waitBusy();
724
+ }
725
+
726
+ void turnOnDisplayPartial()
727
+ {
728
+ sendCommand(0x22);
729
+ sendData(0xcf);
730
+ sendCommand(0x20);
731
+ waitBusy();
732
+ }
733
+
734
+ void writeRam(uint8_t reg, const uint8_t *packed)
735
+ {
736
+ setCursor(0, kNativeHeight - 1);
737
+ sendCommand(reg);
738
+ sendDataBytes(packed, kPackedBytes);
739
+ }
740
+
741
+ // --- 4-level grayscale transport (GxEPD2_4G GDEY0154D67 sequences) -------
742
+
743
+ // Gray mode scans top-to-bottom (X inc, Y inc) with the cursor at the
744
+ // origin, so packFrameGray's natural top-row-first layout lands correctly.
745
+ void setGrayRamArea()
746
+ {
747
+ sendCommand(0x11); // data entry mode: X inc, Y inc
748
+ sendData(0x03);
749
+ sendCommand(0x44);
750
+ sendData(0x00);
751
+ sendData((kNativeWidth - 1) >> 3);
752
+ sendCommand(0x45);
753
+ sendData(0x00);
754
+ sendData(0x00);
755
+ sendData((kNativeHeight - 1) & 0xFF);
756
+ sendData(((kNativeHeight - 1) >> 8) & 0xFF);
757
+ sendCommand(0x4E);
758
+ sendData(0x00);
759
+ sendCommand(0x4F);
760
+ sendData(0x00);
761
+ sendData(0x00);
762
+ }
763
+
764
+ // Gray init: load the 4-level waveform via 0x32 (153 bytes, no voltage
765
+ // trailer — gray mode uses OTP defaults). Border waveform 0x00 per the
766
+ // reference library.
767
+ void panelInitGray()
768
+ {
769
+ hardwareReset();
770
+ waitBusy();
771
+ sendCommand(0x12); // SWRESET
772
+ waitBusy();
773
+ sendCommand(0x01); // driver output control
774
+ sendData(0xC7);
775
+ sendData(0x00);
776
+ sendData(0x00);
777
+ sendCommand(0x3C); // border waveform
778
+ sendData(0x00);
779
+ sendCommand(0x18); // internal temperature sensor
780
+ sendData(0x80);
781
+ setGrayRamArea();
782
+ sendCommand(0x32);
783
+ sendDataBytes(kLut4Gray, kLut4GrayBytes);
784
+ }
785
+
786
+ // Write a full RAM plane in gray mode. Resets the address counter to the
787
+ // origin first so each plane starts at the top-left regardless of the
788
+ // previous plane's write.
789
+ void writeGrayPlane(uint8_t reg, const uint8_t *packed)
790
+ {
791
+ setGrayRamArea();
792
+ sendCommand(reg);
793
+ sendDataBytes(packed, kPackedBytes);
794
+ }
795
+
796
+ void turnOnDisplayGray()
797
+ {
798
+ sendCommand(0x22);
799
+ sendData(0xc7);
800
+ sendCommand(0x20);
801
+ waitBusy();
802
+ }
803
+
804
+ bool initPanel()
805
+ {
806
+ // Power rail first: EPD power is ACTIVE LOW (vendor board_power_bsp).
807
+ {
808
+ gpio_config_t railConf = {};
809
+ railConf.intr_type = GPIO_INTR_DISABLE;
810
+ railConf.mode = GPIO_MODE_OUTPUT;
811
+ railConf.pin_bit_mask = 1ULL << gea::platform::board::power.epdPower;
812
+ railConf.pull_down_en = GPIO_PULLDOWN_DISABLE;
813
+ railConf.pull_up_en = GPIO_PULLUP_ENABLE;
814
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&railConf));
815
+ gpio_set_level(gea::platform::board::power.epdPower, 0);
816
+ vTaskDelay(pdMS_TO_TICKS(10));
817
+ }
818
+
819
+ // Control GPIOs: RST/DC/CS outputs, BUSY input.
820
+ {
821
+ gpio_config_t outConf = {};
822
+ outConf.intr_type = GPIO_INTR_DISABLE;
823
+ outConf.mode = GPIO_MODE_OUTPUT;
824
+ outConf.pin_bit_mask = (1ULL << gea::platform::board::display.reset) |
825
+ (1ULL << gea::platform::board::display.dc) |
826
+ (1ULL << gea::platform::board::display.cs);
827
+ outConf.pull_down_en = GPIO_PULLDOWN_DISABLE;
828
+ outConf.pull_up_en = GPIO_PULLUP_ENABLE;
829
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&outConf));
830
+
831
+ gpio_config_t inConf = outConf;
832
+ inConf.mode = GPIO_MODE_INPUT;
833
+ inConf.pin_bit_mask = 1ULL << gea::platform::board::display.busy;
834
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&inConf));
835
+ setRst(1);
836
+ setCs(1);
837
+ }
838
+
839
+ spi_bus_config_t busConfig = {};
840
+ busConfig.mosi_io_num = gea::platform::board::display.mosi;
841
+ busConfig.miso_io_num = -1;
842
+ busConfig.sclk_io_num = gea::platform::board::display.sclk;
843
+ busConfig.quadwp_io_num = -1;
844
+ busConfig.quadhd_io_num = -1;
845
+ busConfig.max_transfer_sz = kPackedBytes;
846
+ esp_err_t err = spi_bus_initialize(gea::platform::board::display.spiHost, &busConfig, SPI_DMA_CH_AUTO);
847
+ if (err != ESP_OK) {
848
+ ESP_LOGE(kTag, "SPI bus init failed: %s", esp_err_to_name(err));
849
+ return false;
850
+ }
851
+
852
+ spi_device_interface_config_t devConfig = {};
853
+ devConfig.spics_io_num = -1; // CS driven manually around cmd/data phases
854
+ devConfig.clock_speed_hz = kSpiClockHz;
855
+ devConfig.mode = 0;
856
+ devConfig.queue_size = 7;
857
+ err = spi_bus_add_device(gea::platform::board::display.spiHost, &devConfig, &spi_);
858
+ if (err != ESP_OK) {
859
+ ESP_LOGE(kTag, "SPI device add failed: %s", esp_err_to_name(err));
860
+ return false;
861
+ }
862
+
863
+ // Vendor bring-up: full init, white base image into BOTH RAM planes
864
+ // (0x24 current + 0x26 previous — the partial waveform diffs against
865
+ // the previous plane), one full refresh, then switch to the partial LUT.
866
+ panelInitFull();
867
+ std::memset(txPack_, 0xff, kPackedBytes);
868
+ writeRam(0x24, txPack_);
869
+ writeRam(0x26, txPack_);
870
+ turnOnDisplayFull();
871
+ panelInitPartial();
872
+ partialsSinceFull_ = 0;
873
+ ESP_LOGI(kTag, "SSD1681 panel ready cs=%d dc=%d rst=%d busy=%d clk=%dMHz",
874
+ static_cast<int>(gea::platform::board::display.cs),
875
+ static_cast<int>(gea::platform::board::display.dc),
876
+ static_cast<int>(gea::platform::board::display.reset),
877
+ static_cast<int>(gea::platform::board::display.busy),
878
+ kSpiClockHz / 1000000);
879
+ return true;
880
+ }
881
+
882
+ // --- refresh worker ------------------------------------------------------
883
+
884
+ static void refreshTaskEntry(void *arg) { static_cast<DisplayBackend *>(arg)->refreshLoop(); }
885
+
886
+ void refreshLoop()
887
+ {
888
+ for (;;) {
889
+ ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
890
+ for (;;) {
891
+ bool have = false;
892
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
893
+ const uint32_t seq = pendingSeq_.load(std::memory_order_acquire);
894
+ if (seq != transmittedSeq_) {
895
+ std::memcpy(txPack_, pendingPack_, kPackedBytes);
896
+ if (grayscaleEnabled_) std::memcpy(txPack26_, pendingPack26_, kPackedBytes);
897
+ txGrayscale_ = grayscaleEnabled_;
898
+ transmittedSeq_ = seq;
899
+ have = true;
900
+ }
901
+ xSemaphoreGive(packMutex_);
902
+ if (!have) break;
903
+ refreshInFlight_.store(true, std::memory_order_release);
904
+ transmitFrame();
905
+ refreshInFlight_.store(false, std::memory_order_release);
906
+ }
907
+ }
908
+ }
909
+
910
+ enum class PartialLut : uint8_t { Standard, Fast, Invalid };
911
+ enum class PanelMode : uint8_t { BlackWhite, Gray };
912
+
913
+ // Return from gray mode to the B/W full+partial waveform pipeline. Gray
914
+ // mode latched the gray LUT and a different RAM scan layout, so just reset
915
+ // the B/W state and force a full refresh — the dueFull branch re-runs the
916
+ // complete B/W init (panelInitFull re-establishes window/data-entry).
917
+ void reinitBlackWhite()
918
+ {
919
+ panelMode_ = PanelMode::BlackWhite;
920
+ partialsSinceFull_ = 0;
921
+ loadedPartialLut_ = PartialLut::Invalid;
922
+ forceFullRefresh_.store(true, std::memory_order_release);
923
+ }
924
+
925
+ public:
926
+ // Runtime refresh policy (Display.setEpaperRefreshConfig). Values < 0 keep
927
+ // the current setting. LUT pointers: null = unchanged, len 0 = restore the
928
+ // vendor waveform, len 159 = custom waveform (other lengths rejected).
929
+ void setRefreshConfig(int fullEvery, int hardCap, int fastWindowMs,
930
+ const uint8_t *partialLut, int partialLutLen,
931
+ const uint8_t *fastLut, int fastLutLen)
932
+ {
933
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
934
+ if (fullEvery >= 0) fullRefreshEveryPartials_ = fullEvery;
935
+ if (hardCap >= 0) fullRefreshHardCapPartials_ = hardCap;
936
+ if (fastWindowMs >= 0) fastStreakWindowUs_ = static_cast<std::int64_t>(fastWindowMs) * 1000;
937
+ bool lutsChanged = false;
938
+ lutsChanged |= applyCustomLut(partialLut, partialLutLen, customPartialLut_, hasCustomPartialLut_, "partialLut");
939
+ lutsChanged |= applyCustomLut(fastLut, fastLutLen, customFastLut_, hasCustomFastLut_, "fastLut");
940
+ // Force the worker to re-activate whatever waveform applies next.
941
+ if (lutsChanged) loadedPartialLut_ = PartialLut::Invalid;
942
+ xSemaphoreGive(packMutex_);
943
+ ESP_LOGI(kTag,
944
+ "refresh config: fullEvery=%d hardCap=%d fastWindowMs=%lld customPartial=%d customFast=%d",
945
+ fullRefreshEveryPartials_, fullRefreshHardCapPartials_,
946
+ static_cast<long long>(fastStreakWindowUs_ / 1000),
947
+ hasCustomPartialLut_ ? 1 : 0, hasCustomFastLut_ ? 1 : 0);
948
+ }
949
+
950
+ // Force a full (anti-ghost) refresh of the current frame.
951
+ void requestFullRefresh()
952
+ {
953
+ if (!init()) return;
954
+ forceFullRefresh_.store(true, std::memory_order_release);
955
+ requestRefresh();
956
+ }
957
+
958
+ // Toggle 4-level grayscale rendering. Gray mode renders the framebuffer's
959
+ // luma into 4 reflectance levels via the SSD1681's two RAM planes + gray
960
+ // waveform LUT; every update is a full ~1 s refresh (no partial path). B/W
961
+ // mode (the default) keeps the fast partial waveform. The mode switch and a
962
+ // re-pack of the current frame happen on the next refresh.
963
+ void setGrayscale(bool enabled)
964
+ {
965
+ if (enabled && (!pendingPack26_ || !txPack26_)) {
966
+ // Lazily allocate the 0x26 grayscale plane (DMA-capable internal) on the
967
+ // first enable; B/W apps never pay this ~10 KB (see init()). Bail to B/W
968
+ // if the DMA-internal pool can't spare it.
969
+ if (!pendingPack26_)
970
+ pendingPack26_ = static_cast<uint8_t *>(
971
+ heap_caps_malloc(kPackedBytes, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
972
+ if (!txPack26_)
973
+ txPack26_ = static_cast<uint8_t *>(
974
+ heap_caps_malloc(kPackedBytes, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
975
+ if (!pendingPack26_ || !txPack26_) {
976
+ ESP_LOGE(kTag, "grayscale plane alloc failed; staying in B/W");
977
+ return;
978
+ }
979
+ std::memset(pendingPack26_, 0x00, kPackedBytes);
980
+ std::memset(txPack26_, 0x00, kPackedBytes);
981
+ }
982
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
983
+ const bool changed = grayscaleEnabled_ != enabled;
984
+ grayscaleEnabled_ = enabled;
985
+ xSemaphoreGive(packMutex_);
986
+ ESP_LOGI(kTag, "grayscale %s", enabled ? "on" : "off");
987
+ if (changed && initialized_) {
988
+ forceFullRefresh_.store(true, std::memory_order_release);
989
+ requestRefresh();
990
+ }
991
+ }
992
+
993
+ private:
994
+ static bool applyCustomLut(const uint8_t *lut, int len, uint8_t *store, bool &hasCustom, const char *name)
995
+ {
996
+ if (!lut && len < 0) return false; // absent — unchanged
997
+ if (len == 0) { // explicit reset to vendor waveform
998
+ if (!hasCustom) return false;
999
+ hasCustom = false;
1000
+ return true;
1001
+ }
1002
+ if (len != kLutBytes || !lut) {
1003
+ ESP_LOGE(kTag, "%s must be exactly %d bytes (got %d) — ignored", name, kLutBytes, len);
1004
+ return false;
1005
+ }
1006
+ std::memcpy(store, lut, kLutBytes);
1007
+ hasCustom = true;
1008
+ return true;
1009
+ }
1010
+
1011
+ const uint8_t *partialLutBytes() const { return hasCustomPartialLut_ ? customPartialLut_ : kLutPartial; }
1012
+ const uint8_t *fastLutBytes() const { return hasCustomFastLut_ ? customFastLut_ : kLutPartialFast; }
1013
+
1014
+ // 4-level grayscale refresh: full-waveform every time (no partial path in
1015
+ // gray mode), ~1 s. Loads the gray LUT on first entry / after leaving B/W,
1016
+ // writes both RAM planes, then a single full update drives the 4 levels.
1017
+ void transmitGrayFrame(std::int64_t started)
1018
+ {
1019
+ forceFullRefresh_.exchange(false, std::memory_order_acq_rel);
1020
+ if (panelMode_ != PanelMode::Gray) {
1021
+ panelInitGray();
1022
+ panelMode_ = PanelMode::Gray;
1023
+ loadedPartialLut_ = PartialLut::Invalid;
1024
+ }
1025
+ writeGrayPlane(0x26, txPack26_);
1026
+ writeGrayPlane(0x24, txPack_);
1027
+ turnOnDisplayGray();
1028
+ partialsSinceFull_ = 0;
1029
+ lastTransmitEndUs_ = esp_timer_get_time();
1030
+ const std::int64_t tookUs = lastTransmitEndUs_ - started;
1031
+ flushStats_.txUs += tookUs;
1032
+ flushStats_.chunkCount++;
1033
+ flushStats_.pixelCount += kMaxPixels;
1034
+ ESP_LOGI(kTag, "gray refresh %d ms levels[blk=%u dark=%u light=%u wht=%u]",
1035
+ static_cast<int>(tookUs / 1000),
1036
+ static_cast<unsigned>(lastGrayLevelCounts_[0]),
1037
+ static_cast<unsigned>(lastGrayLevelCounts_[1]),
1038
+ static_cast<unsigned>(lastGrayLevelCounts_[2]),
1039
+ static_cast<unsigned>(lastGrayLevelCounts_[3]));
1040
+ }
1041
+
1042
+ void transmitFrame()
1043
+ {
1044
+ const std::int64_t started = esp_timer_get_time();
1045
+ // Snapshot the (frame-task-writable) policy under the pack mutex.
1046
+ xSemaphoreTake(packMutex_, portMAX_DELAY);
1047
+ const int fullEvery = fullRefreshEveryPartials_;
1048
+ const int hardCap = fullRefreshHardCapPartials_;
1049
+ const std::int64_t fastWindowUs = fastStreakWindowUs_;
1050
+ const bool grayscale = txGrayscale_;
1051
+ xSemaphoreGive(packMutex_);
1052
+
1053
+ if (grayscale) {
1054
+ transmitGrayFrame(started);
1055
+ return;
1056
+ }
1057
+ // Leaving gray mode: re-establish the B/W full+partial waveform path.
1058
+ if (panelMode_ != PanelMode::BlackWhite) {
1059
+ reinitBlackWhite();
1060
+ }
1061
+
1062
+ const bool fastStreak = fastWindowUs > 0 && started - lastTransmitEndUs_ < fastWindowUs;
1063
+ const bool dueFull = forceFullRefresh_.exchange(false, std::memory_order_acq_rel) ||
1064
+ partialsSinceFull_ >= hardCap ||
1065
+ (!fastStreak && partialsSinceFull_ >= fullEvery);
1066
+ if (dueFull) {
1067
+ // Anti-ghosting flash: full-waveform refresh of the current frame,
1068
+ // re-seed both RAM planes, then back to the partial LUT.
1069
+ panelInitFull();
1070
+ writeRam(0x24, txPack_);
1071
+ turnOnDisplayFull();
1072
+ writeRam(0x24, txPack_);
1073
+ writeRam(0x26, txPack_);
1074
+ turnOnDisplayFull();
1075
+ hardwareReset();
1076
+ waitBusy();
1077
+ activatePartialLut(partialLutBytes());
1078
+ loadedPartialLut_ = PartialLut::Standard;
1079
+ partialsSinceFull_ = 0;
1080
+ } else {
1081
+ const PartialLut want = fastStreak ? PartialLut::Fast : PartialLut::Standard;
1082
+ if (want != loadedPartialLut_) {
1083
+ activatePartialLut(want == PartialLut::Fast ? fastLutBytes() : partialLutBytes());
1084
+ loadedPartialLut_ = want;
1085
+ }
1086
+ writeRam(0x24, txPack_);
1087
+ turnOnDisplayPartial();
1088
+ partialsSinceFull_++;
1089
+ }
1090
+ lastTransmitEndUs_ = esp_timer_get_time();
1091
+ const std::int64_t tookUs = lastTransmitEndUs_ - started;
1092
+ flushStats_.txUs += tookUs;
1093
+ flushStats_.chunkCount++;
1094
+ flushStats_.pixelCount += kMaxPixels;
1095
+ refreshLogAccumUs_ += tookUs;
1096
+ if (++refreshLogCount_ >= 16) {
1097
+ ESP_LOGI(kTag, "16 refreshes avg %d ms (lut=%s)",
1098
+ static_cast<int>(refreshLogAccumUs_ / 16000),
1099
+ loadedPartialLut_ == PartialLut::Fast ? "fast" : "standard");
1100
+ refreshLogAccumUs_ = 0;
1101
+ refreshLogCount_ = 0;
1102
+ }
1103
+ }
1104
+
1105
+ void take()
1106
+ {
1107
+ if (mutex_) xSemaphoreTake(mutex_, portMAX_DELAY);
1108
+ }
1109
+
1110
+ void give()
1111
+ {
1112
+ if (mutex_) xSemaphoreGive(mutex_);
1113
+ }
1114
+
1115
+ SemaphoreHandle_t mutex_ = nullptr;
1116
+ SemaphoreHandle_t packMutex_ = nullptr;
1117
+ spi_device_handle_t spi_ = nullptr;
1118
+ std::uint16_t *frameBuffer_ = nullptr;
1119
+ uint8_t *pendingPack_ = nullptr;
1120
+ uint8_t *txPack_ = nullptr;
1121
+ uint8_t *pendingPack26_ = nullptr;
1122
+ uint8_t *txPack26_ = nullptr;
1123
+ std::uint16_t *backgroundCache_ = nullptr;
1124
+ std::uint16_t *backdropCache_ = nullptr;
1125
+ TaskHandle_t refreshTask_ = nullptr;
1126
+ gea::framework::graphics::Canvas canvas_;
1127
+ std::atomic<uint32_t> pendingSeq_{0};
1128
+ uint32_t transmittedSeq_ = 0;
1129
+ std::atomic<bool> refreshInFlight_{false};
1130
+ int partialsSinceFull_ = 0;
1131
+ PartialLut loadedPartialLut_ = PartialLut::Standard;
1132
+ PanelMode panelMode_ = PanelMode::BlackWhite;
1133
+ bool grayscaleEnabled_ = false; // guarded by packMutex_
1134
+ bool txGrayscale_ = false; // mode the snapshotted tx planes were packed in
1135
+ std::uint32_t lastGrayLevelCounts_[4] = {0, 0, 0, 0};
1136
+ std::int64_t lastTransmitEndUs_ = 0;
1137
+ std::int64_t refreshLogAccumUs_ = 0;
1138
+ int refreshLogCount_ = 0;
1139
+ // Runtime refresh policy (Display.setEpaperRefreshConfig); guarded by packMutex_.
1140
+ int fullRefreshEveryPartials_ = kFullRefreshEveryPartials;
1141
+ int fullRefreshHardCapPartials_ = kFullRefreshHardCapPartials;
1142
+ std::int64_t fastStreakWindowUs_ = kFastStreakWindowUs;
1143
+ uint8_t customPartialLut_[kLutBytes]{};
1144
+ uint8_t customFastLut_[kLutBytes]{};
1145
+ bool hasCustomPartialLut_ = false;
1146
+ bool hasCustomFastLut_ = false;
1147
+ std::atomic<bool> forceFullRefresh_{false};
1148
+ bool backgroundCacheAttempted_ = false;
1149
+ bool backdropCacheAttempted_ = false;
1150
+ bool initialized_ = false;
1151
+ bool needsFullPhysicalFlush_ = true;
1152
+ platform_display::DisplayFlushPerfStats flushStats_{};
1153
+ present::Frame previousPresentFrame_{};
1154
+ bool previousPresentValid_ = false;
1155
+ };
1156
+
1157
+ } // namespace gea::platform::esp32_s3_epaper::display
1158
+
1159
+ // Strong definitions for the weak hooks in lib/gea-embedded/host/display.cpp:
1160
+ // the JS-facing Display.setEpaperRefreshConfig / Display.epaperFullRefresh.
1161
+ extern "C" void gea_epaper_set_refresh_config(
1162
+ int full_refresh_every_partials,
1163
+ int full_refresh_hard_cap_partials,
1164
+ int fast_streak_window_ms,
1165
+ const std::uint8_t *partial_lut, int partial_lut_len,
1166
+ const std::uint8_t *fast_lut, int fast_lut_len)
1167
+ {
1168
+ gea::platform::esp32_s3_epaper::display::DisplayBackend::instance().setRefreshConfig(
1169
+ full_refresh_every_partials, full_refresh_hard_cap_partials, fast_streak_window_ms,
1170
+ partial_lut, partial_lut_len, fast_lut, fast_lut_len);
1171
+ }
1172
+
1173
+ extern "C" void gea_epaper_full_refresh(void)
1174
+ {
1175
+ gea::platform::esp32_s3_epaper::display::DisplayBackend::instance().requestFullRefresh();
1176
+ }
1177
+
1178
+ extern "C" void gea_epaper_set_grayscale(int enabled)
1179
+ {
1180
+ gea::platform::esp32_s3_epaper::display::DisplayBackend::instance().setGrayscale(enabled != 0);
1181
+ }
1182
+
1183
+ extern "C" std::uint16_t *gea_bg_cache(int *cap_px)
1184
+ {
1185
+ return gea::platform::esp32_s3_epaper::display::DisplayBackend::instance().backgroundCache(cap_px);
1186
+ }
1187
+
1188
+ extern "C" std::uint16_t *gea_backdrop_cache(int *cap_px)
1189
+ {
1190
+ return gea::platform::esp32_s3_epaper::display::DisplayBackend::instance().backdropCache(cap_px);
1191
+ }
1192
+
1193
+ namespace gea::platform::display {
1194
+
1195
+ namespace {
1196
+
1197
+ using Backend = gea::platform::esp32_s3_epaper::display::DisplayBackend;
1198
+
1199
+ gea::framework::graphics::Canvas *drawingCanvas()
1200
+ {
1201
+ return Backend::instance().canvas();
1202
+ }
1203
+
1204
+ } // namespace
1205
+
1206
+ bool Display::init() { return Backend::instance().init(); }
1207
+ bool Display::start() { return Backend::instance().start(); }
1208
+ gea::framework::graphics::Canvas *Display::canvas() { return Backend::instance().canvas(); }
1209
+ bool Display::framebufferIsPanelDirect() { return Backend::instance().framebufferIsPanelDirect(); }
1210
+ void Display::clear() { Backend::instance().clear(); }
1211
+ void Display::clearNoFlush() { Backend::instance().clearNoFlush(); }
1212
+ void Display::print(const char *) {}
1213
+ void Display::flush() { Backend::instance().flush(); }
1214
+ void Display::flushRects(const DisplayFlushRect *rects, int count, bool) { Backend::instance().flushRects(rects, count); }
1215
+ 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); }
1216
+ bool Display::present(const DisplayPresentCommand *commands, int command_count) { return Backend::instance().presentCommands(commands, command_count); }
1217
+ void Display::setFlushConfig(int chunk_rows, int queue_depth) { Backend::instance().setFlushConfig(chunk_rows, queue_depth); }
1218
+ void Display::reserveInternal(std::size_t) {}
1219
+ bool Display::setHighBrightnessMode(bool) { return false; }
1220
+ bool Display::highBrightnessMode() { return false; }
1221
+ void Display::applyPendingInternalReserve() {}
1222
+ int Display::flushChunkRows() { return Backend::instance().flushChunkRows(); }
1223
+ int Display::flushQueueDepth() { return Backend::instance().flushQueueDepth(); }
1224
+ int Display::flushBufferBytes() { return Backend::instance().flushBufferBytes(); }
1225
+ void Display::pushClip(int x, int y, int w, int h) { if (auto *c = drawingCanvas()) c->pushClip(x, y, w, h); }
1226
+ void Display::popClip() { if (auto *c = drawingCanvas()) c->popClip(); }
1227
+ void Display::resetClip() { if (auto *c = drawingCanvas()) c->resetClip(); }
1228
+ void Display::setAlpha(std::uint8_t alpha) { if (auto *c = drawingCanvas()) c->setGlobalAlpha(alpha); }
1229
+ std::uint8_t Display::alpha() { return drawingCanvas() ? drawingCanvas()->globalAlpha() : 255; }
1230
+ int Display::brightness() { return Backend::instance().brightness(); }
1231
+ void Display::setBrightness(int brightness_percent) { Backend::instance().setBrightness(brightness_percent); }
1232
+ // Tearing sync (TE/VBlank): not implemented on this target.
1233
+ void Display::setVSync(bool) {}
1234
+ void Display::invalidate() {}
1235
+ bool Display::vsyncEnabled() { return false; }
1236
+ void Display::vsyncWaitForFrame() {}
1237
+ void Display::clip(int *x0, int *y0, int *x1, int *y1)
1238
+ {
1239
+ if (auto *c = drawingCanvas()) c->currentClip(x0, y0, x1, y1);
1240
+ }
1241
+ 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); }
1242
+ 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); }
1243
+ void Display::resetScrollRegion() {}
1244
+ 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); }
1245
+ void Display::fillCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillCircle(cx, cy, r, color); }
1246
+ void Display::strokeCircle(int cx, int cy, int r, std::uint16_t color) { if (auto *c = drawingCanvas()) c->strokeCircle(cx, cy, r, color); }
1247
+ 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); }
1248
+ 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); }
1249
+ 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); }
1250
+ 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); }
1251
+ 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); }
1252
+ 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); }
1253
+ void Display::setPixel(int x, int y, std::uint16_t color) { if (auto *c = drawingCanvas()) c->fillRect(x, y, 1, 1, color); }
1254
+ 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); }
1255
+ 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); }
1256
+ 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); }
1257
+ 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); }
1258
+ 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); }
1259
+ void Display::setWorldOverlay(const std::uint16_t *, int, int, int, int) {}
1260
+ void Display::setWorldScroll(int) {}
1261
+ void Display::flushStatsRead(std::int64_t *total_us, int *call_count, int *pixel_count)
1262
+ {
1263
+ const auto stats = Backend::instance().flushStats();
1264
+ if (total_us) *total_us = stats.totalUs;
1265
+ if (call_count) *call_count = stats.callCount;
1266
+ if (pixel_count) *pixel_count = stats.pixelCount;
1267
+ }
1268
+ DisplayFlushPerfStats Display::flushPerfStatsRead() { return Backend::instance().flushStats(); }
1269
+ void Display::flushStatsReset() { Backend::instance().flushStatsReset(); }
1270
+ const char *Display::flushStageName() { return Backend::instance().flushStageName(); }
1271
+ int Display::flushStageChunk() { return Backend::instance().flushStageChunk(); }
1272
+ DisplayFlushStageDetail Display::flushStageDetail() { return Backend::instance().flushStageDetail(); }
1273
+ bool Display::copySnapshotRgb565(std::uint16_t *dst, int pixel_capacity, int *width, int *height, bool) { return Backend::instance().copySnapshotRgb565(dst, pixel_capacity, width, height); }
1274
+ int Display::countNonBlackPixels(bool) { return Backend::instance().countNonBlackPixels(); }
1275
+
1276
+ void applyOrientation(gea::framework::display::DisplayOrientation)
1277
+ {
1278
+ Backend::instance().applyOrientation();
1279
+ }
1280
+
1281
+ } // namespace gea::platform::display