@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,989 @@
1
+ // Our own ED047TC1 driver for the LilyGo T5 4.7" E-Paper S3 (PCA9555 + TPS65185
2
+ // revision — the epdiy `lilygo_board_s3` variant).
3
+ //
4
+ // Implements the epd_driver.h subset the gea display backend uses. The panel is
5
+ // driven through the ESP32-S3 LCD peripheral in i80 mode via esp_lcd (our own
6
+ // DMA scan — the layer that will become the 60fps per-pixel engine).
7
+ //
8
+ // Pins + power from epdiy's src/board/lilygo_board_s3.c (data D0-D7 =
9
+ // {5,6,7,15,16,17,18,8}, edge clock CKH=4; direct-GPIO control CKV(gate)=48,
10
+ // STH(source start / i80 CS)=41, LEH(latch)=42, STV(gate start)=45; power/control
11
+ // over I2C SDA=39/SCL=40 via a PCA9555 @0x20 + TPS65185 @0x68).
12
+ //
13
+ // The frame scan (gate-start dance + per-row latch/clock/DMA order) mirrors
14
+ // Wenting Zhang's "Modos Smooth Graphics" (gitlab.com/zephray/paperboy msg.c,
15
+ // MIT) — the proven manual-GPIO sequence for this exact ED047TC1 panel — with
16
+ // OE/MODE driven over the PCA9555 (which the M5PaperS3 handles differently).
17
+ //
18
+ // STAGE 0: 1-bit black-on-white over EPD_IMAGE_FIELDS fields after a clear.
19
+
20
+ #include "epd_driver.h"
21
+
22
+ #include <string.h>
23
+
24
+ #include "driver/gpio.h"
25
+ #include "driver/i2c_master.h"
26
+ #include "esp_lcd_panel_io.h"
27
+ #include "esp_lcd_panel_ops.h"
28
+ #include "esp_heap_caps.h"
29
+ #include "esp_log.h"
30
+ #include "esp_rom_sys.h"
31
+ #include "esp_timer.h"
32
+ #include "freertos/FreeRTOS.h"
33
+ #include "freertos/task.h"
34
+
35
+ static const char *TAG = "gea_epd";
36
+
37
+ // ---- Pins (epdiy lilygo_board_s3) -------------------------------------------
38
+ #define PIN_D0 5
39
+ #define PIN_D1 6
40
+ #define PIN_D2 7
41
+ #define PIN_D3 15
42
+ #define PIN_D4 16
43
+ #define PIN_D5 17
44
+ #define PIN_D6 18
45
+ #define PIN_D7 8
46
+ #define PIN_CKH 4 // edge / pixel clock (i80 WR)
47
+ #define PIN_STH 41 // source start pulse (i80 CS)
48
+ #define PIN_CKV 48 // gate clock (direct GPIO)
49
+ #define PIN_LEH 42 // source latch (direct GPIO)
50
+ #define PIN_STV 45 // gate start (direct GPIO)
51
+ #define PIN_DC 9 // unused dummy DC for the i80 bus
52
+ #define PIN_CFG_SDA 39
53
+ #define PIN_CFG_SCL 40
54
+
55
+ // ---- PCA9555 (@0x20) --------------------------------------------------------
56
+ #define PCA_ADDR 0x20
57
+ #define PCA_REG_INPUT0 0
58
+ #define PCA_REG_OUTPUT0 2
59
+ #define PCA_REG_CONFIG0 6
60
+ #define PCA_OE 0x01
61
+ #define PCA_MODE 0x02
62
+ #define PCA_PWRUP 0x08
63
+ #define PCA_VCOM 0x10
64
+ #define PCA_WAKEUP 0x20
65
+ #define PCA_PWRGOOD 0x40
66
+ #define PCA_INT 0x80
67
+
68
+ // ---- TPS65185 (@0x68) -------------------------------------------------------
69
+ #define TPS_ADDR 0x68
70
+ #define TPS_REG_ENABLE 0x01
71
+ #define TPS_REG_VCOM1 0x03
72
+ #define TPS_REG_VCOM2 0x04
73
+ #define TPS_REG_UPSEQ0 0x09
74
+ #define TPS_REG_UPSEQ1 0x0A
75
+ #define TPS_REG_PG 0x0F
76
+ // Factory-calibrated for THIS panel: the T5 E-Paper S3 PRO factory firmware
77
+ // reads eps_vcom=1560 from NVS (seen on serial 2026-07-18). Wrong VCOM shows
78
+ // up as washed-out contrast and ghosting.
79
+ #define TPS_VCOM_MV 1560
80
+
81
+ #define EPD_LINE_BYTES (EPD_WIDTH / 4) // 2 bits/pixel, 4 px/byte -> 240
82
+ #define EPD_LINE_PAD 16
83
+ #define EPD_XCK_HZ 12000000
84
+ #define EPD_IMAGE_FIELDS 12
85
+
86
+ // Source-command polarity: standard ED047TC1, same as PaperBoy's M5PaperS3
87
+ // (push_lut_b uses 0x1, push_lut_w uses 0x2): 0x1 darkens (toward black),
88
+ // 0x2 lightens (toward white). The earlier bring-up note claiming this board
89
+ // was swapped came from an ambiguous 1-bit scene — with the swap the e-reader
90
+ // rendered as a washed-out negative (clear ended black, text lightened, page
91
+ // darkened).
92
+ #define DRV_HOLD 0x0
93
+ #define DRV_DARK 0x1
94
+ #define DRV_LIGHT 0x2
95
+
96
+ static i2c_master_bus_handle_t s_i2c;
97
+ static i2c_master_dev_handle_t s_pca;
98
+ static i2c_master_dev_handle_t s_tps;
99
+ static uint8_t s_pca_power; // sticky PWRUP|VCOM|WAKEUP bits held during operation
100
+ static esp_lcd_i80_bus_handle_t s_i80_bus;
101
+ static esp_lcd_panel_io_handle_t s_panel_io;
102
+ static volatile bool s_dma_done = true;
103
+ static uint8_t *s_dma[2]; // ping-pong DMA line buffers
104
+ static int s_cur;
105
+ static bool s_inited = false;
106
+
107
+ // Extra per-row gate-on time in µs. The bare scan only energizes each row for
108
+ // the ~21µs the next row's DMA takes — enough for the fast per-pixel engine's
109
+ // many-fields regime, but a WEAK push per field. Quality draws and panel
110
+ // repair extend the row-select window (epdiy's strong pushes do the same via
111
+ // its ckv_high_time), multiplying the charge transferred per field.
112
+ static int s_row_hold_us = 0;
113
+
114
+ void gea_epd_set_row_hold_us(int hold_us)
115
+ {
116
+ s_row_hold_us = hold_us < 0 ? 0 : hold_us;
117
+ }
118
+
119
+ // ---- PANEL SAFETY LAYER ------------------------------------------------------
120
+ // The first panel was destroyed by sustained saturation DC: a renderer that
121
+ // re-drove at-target pixels every frame for hours, plus an inverted-polarity
122
+ // session, plus marathon repair loops. This layer makes those failure modes
123
+ // STRUCTURALLY impossible rather than avoidable. Everything below funnels
124
+ // through the one scan chokepoint (frame_start/send_row), so no field
125
+ // function — present or future — can bypass it.
126
+ //
127
+ // 1. Per-pixel signed DC ledger (1 byte/px, PSRAM): every DARK/LIGHT command
128
+ // a pixel receives moves its ledger by a hold-scaled quantum; at the
129
+ // bound the command is rewritten to NOP in the DMA row. Balanced content
130
+ // hovers near zero forever; sustained one-way drive self-limits after
131
+ // roughly two transitions' worth of charge.
132
+ // 2. Duty limiter: a cap on scans per minute, and a forced rails-off rest
133
+ // after sustained continuous activity — a runaway build stops itself.
134
+ // 3. VCOM interlock: no scan drives the panel until the panel's OWN
135
+ // calibration has been provided via gea_epd_set_vcom_mv(). Never reuse
136
+ // another panel's value.
137
+ // 4. Experimental gating: repair/recovery/diagnostic waveforms refuse to run
138
+ // unless explicitly enabled, and hard-stop at a 30-minute wall clock.
139
+ #define LEDGER_BOUND 96 // hold-scaled quanta ≈ ~2 transitions one-way
140
+ #define LEDGER_QUANTUM_US 50 // 1 quantum per started 50µs of row drive
141
+ #define MAX_SCANS_PER_MINUTE 900
142
+ #define FORCED_REST_AFTER_US (120LL * 1000 * 1000)
143
+ #define FORCED_REST_MS 5000
144
+ #define EXPERIMENTAL_CAP_US (30LL * 60 * 1000 * 1000)
145
+
146
+ static int8_t *s_ledger; // [EPD_HEIGHT][EPD_WIDTH], PSRAM
147
+ static bool s_scan_suppressed; // set per frame_start; send_row NOPs the data
148
+ static int s_scan_row;
149
+ static bool s_vcom_set = false;
150
+ static unsigned s_vcom_mv;
151
+ static bool s_experimental = false;
152
+ static int64_t s_experimental_started_us;
153
+ static uint32_t s_scans_total, s_scans_this_minute, s_px_clamped;
154
+ static int64_t s_minute_epoch_us, s_activity_start_us, s_last_scan_us, s_last_telemetry_us, s_last_refuse_log_us;
155
+
156
+ static void epd_poweron_internal(void);
157
+
158
+ // Decide whether the scan that is about to start may DRIVE the panel. Runs
159
+ // the duty limiter, the forced-rest scheduler, and telemetry. A refused scan
160
+ // still clocks through mechanically but carries all-NOP data (zero drive).
161
+ static bool field_scan_permitted(void)
162
+ {
163
+ const int64_t now = esp_timer_get_time();
164
+ if (now - s_last_telemetry_us > 60LL * 1000 * 1000) {
165
+ s_last_telemetry_us = now;
166
+ ESP_LOGI(TAG, "safety: scans=%lu clamped_px=%lu rate=%lu/min",
167
+ (unsigned long)s_scans_total, (unsigned long)s_px_clamped, (unsigned long)s_scans_this_minute);
168
+ }
169
+ if (!s_vcom_set || !s_ledger) {
170
+ if (now - s_last_refuse_log_us > 5LL * 1000 * 1000) {
171
+ s_last_refuse_log_us = now;
172
+ ESP_LOGE(TAG, "safety: drive locked (%s) — all scans emitted as NOP",
173
+ !s_vcom_set ? "panel VCOM not set" : "ledger allocation failed");
174
+ }
175
+ return false;
176
+ }
177
+ if (now - s_minute_epoch_us > 60LL * 1000 * 1000) {
178
+ s_minute_epoch_us = now;
179
+ s_scans_this_minute = 0;
180
+ }
181
+ if (++s_scans_this_minute > MAX_SCANS_PER_MINUTE) {
182
+ if (now - s_last_refuse_log_us > 5LL * 1000 * 1000) {
183
+ s_last_refuse_log_us = now;
184
+ ESP_LOGW(TAG, "safety: duty limit (%d scans/min) — dropping drive until the window resets", MAX_SCANS_PER_MINUTE);
185
+ }
186
+ return false;
187
+ }
188
+ // Idle gaps reset the continuous-activity clock; sustained activity earns
189
+ // a mandatory rails-off zero-bias rest.
190
+ if (now - s_last_scan_us > 2LL * 1000 * 1000) s_activity_start_us = now;
191
+ s_last_scan_us = now;
192
+ if (now - s_activity_start_us > FORCED_REST_AFTER_US) {
193
+ ESP_LOGW(TAG, "safety: %llds continuous drive — forced %dms rails-off rest",
194
+ (long long)((now - s_activity_start_us) / 1000000), FORCED_REST_MS);
195
+ epd_poweroff();
196
+ vTaskDelay(pdMS_TO_TICKS(FORCED_REST_MS));
197
+ epd_poweron_internal();
198
+ s_activity_start_us = esp_timer_get_time();
199
+ s_last_scan_us = s_activity_start_us;
200
+ }
201
+ s_scans_total++;
202
+ return true;
203
+ }
204
+
205
+ static bool experimental_ok(const char *who)
206
+ {
207
+ if (!s_experimental) {
208
+ ESP_LOGE(TAG, "%s refused: experimental waveforms not enabled (call gea_epd_enable_experimental)", who);
209
+ return false;
210
+ }
211
+ if (esp_timer_get_time() - s_experimental_started_us > EXPERIMENTAL_CAP_US) {
212
+ ESP_LOGE(TAG, "%s stopped: 30-minute experimental wall-clock cap reached", who);
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
+
218
+ void gea_epd_set_vcom_mv(unsigned mv)
219
+ {
220
+ if (mv < 100 || mv > 5000) {
221
+ ESP_LOGE(TAG, "rejected VCOM %umV (sane range 100..5000)", mv);
222
+ return;
223
+ }
224
+ s_vcom_mv = mv;
225
+ s_vcom_set = true;
226
+ ESP_LOGI(TAG, "panel VCOM set to %umV", mv);
227
+ }
228
+
229
+ void gea_epd_enable_experimental(void)
230
+ {
231
+ s_experimental = true;
232
+ s_experimental_started_us = esp_timer_get_time();
233
+ ESP_LOGW(TAG, "experimental waveforms ENABLED (30-minute wall-clock cap)");
234
+ }
235
+
236
+ // ---- I2C helpers ------------------------------------------------------------
237
+
238
+ static esp_err_t reg_write(i2c_master_dev_handle_t dev, uint8_t reg, uint8_t val)
239
+ {
240
+ uint8_t buf[2] = { reg, val };
241
+ return i2c_master_transmit(dev, buf, 2, 1000);
242
+ }
243
+
244
+ static uint8_t reg_read(i2c_master_dev_handle_t dev, uint8_t reg)
245
+ {
246
+ uint8_t val = 0;
247
+ i2c_master_transmit_receive(dev, &reg, 1, &val, 1, 1000);
248
+ return val;
249
+ }
250
+
251
+ static inline void pca_set_config(uint8_t v) { reg_write(s_pca, PCA_REG_CONFIG0 + 1, v); }
252
+ static inline void pca_set_output(uint8_t v) { reg_write(s_pca, PCA_REG_OUTPUT0 + 1, v); }
253
+ static inline uint8_t pca_read_input(void) { return reg_read(s_pca, PCA_REG_INPUT0 + 1); }
254
+
255
+ // Set OE / MODE while keeping the sticky power bits. Slow (I2C); only called at
256
+ // frame boundaries, never per row.
257
+ static void pca_ctrl(bool oe, bool mode)
258
+ {
259
+ pca_set_output((uint8_t)((oe ? PCA_OE : 0) | (mode ? PCA_MODE : 0) | s_pca_power));
260
+ }
261
+
262
+ static inline void tps_set_vcom(unsigned mV)
263
+ {
264
+ unsigned val = mV / 10;
265
+ reg_write(s_tps, TPS_REG_VCOM2, (uint8_t)((val & 0x100) >> 8));
266
+ reg_write(s_tps, TPS_REG_VCOM1, (uint8_t)(val & 0xFF));
267
+ }
268
+
269
+ // ---- DMA row scan (PaperBoy sequence) ---------------------------------------
270
+
271
+ static bool IRAM_ATTR dma_done_cb(esp_lcd_panel_io_handle_t io,
272
+ esp_lcd_panel_io_event_data_t *ed, void *ctx)
273
+ {
274
+ (void)io; (void)ed; (void)ctx;
275
+ s_dma_done = true;
276
+ return false;
277
+ }
278
+
279
+ // Wait for the previous line's DMA, advance one gate line (CKV) latching the
280
+ // previously-shifted source data (LEH), then start shifting THIS row's data.
281
+ // Pipelined: the data given here is latched+driven on the NEXT call.
282
+ static void send_row(uint8_t *row)
283
+ {
284
+ // SAFETY chokepoint: every drive command in every scan passes through
285
+ // here. A suppressed scan (duty/interlock refusal) is stripped to NOP;
286
+ // otherwise the per-pixel DC ledger is charged and out-of-budget pixels
287
+ // are individually rewritten to NOP before the data reaches the panel.
288
+ if (s_scan_suppressed) {
289
+ memset(row, 0, EPD_LINE_BYTES);
290
+ } else if (s_ledger && s_scan_row < EPD_HEIGHT) {
291
+ const int inc = 1 + s_row_hold_us / LEDGER_QUANTUM_US;
292
+ int8_t *lrow = s_ledger + (size_t)s_scan_row * EPD_WIDTH;
293
+ for (int xb = 0; xb < EPD_LINE_BYTES; xb++) {
294
+ uint8_t b = row[xb];
295
+ if (!b) continue;
296
+ for (int p = 0; p < 4; p++) {
297
+ const uint8_t cmd = (uint8_t)((b >> (p * 2)) & 3u);
298
+ if (cmd != DRV_DARK && cmd != DRV_LIGHT) continue;
299
+ int8_t *l = &lrow[xb * 4 + p];
300
+ const int next = (cmd == DRV_DARK) ? (int)*l + inc : (int)*l - inc;
301
+ if (next > LEDGER_BOUND || next < -LEDGER_BOUND) {
302
+ b &= (uint8_t)~(3u << (p * 2));
303
+ s_px_clamped++;
304
+ } else {
305
+ *l = (int8_t)next;
306
+ }
307
+ }
308
+ row[xb] = b;
309
+ }
310
+ }
311
+ s_scan_row++;
312
+ while (!s_dma_done) {}
313
+ gpio_set_level(PIN_CKV, 0);
314
+ gpio_set_level(PIN_LEH, 1);
315
+ gpio_set_level(PIN_LEH, 0);
316
+ gpio_set_level(PIN_CKV, 1);
317
+ // Extend the gate-on window: the just-latched source data keeps driving
318
+ // the selected row for the entire CKV-high period.
319
+ if (s_row_hold_us) esp_rom_delay_us((uint32_t)s_row_hold_us);
320
+ s_dma_done = false;
321
+ esp_lcd_panel_io_tx_color(s_panel_io, -1, row, EPD_LINE_BYTES + EPD_LINE_PAD);
322
+ }
323
+
324
+ // Reset the gate driver to the first line (PaperBoy gate-start dance;
325
+ // STV = gate start, CKV = gate clock).
326
+ static void frame_start(void)
327
+ {
328
+ s_scan_row = 0;
329
+ s_scan_suppressed = !field_scan_permitted();
330
+ gpio_set_level(PIN_CKV, 1);
331
+ esp_rom_delay_us(7);
332
+ gpio_set_level(PIN_STV, 0);
333
+ esp_rom_delay_us(10);
334
+ gpio_set_level(PIN_CKV, 0);
335
+ gpio_set_level(PIN_CKV, 1);
336
+ esp_rom_delay_us(8);
337
+ gpio_set_level(PIN_STV, 1);
338
+ esp_rom_delay_us(10);
339
+ gpio_set_level(PIN_CKV, 0);
340
+ for (int i = 0; i < 2; i++) {
341
+ gpio_set_level(PIN_CKV, 1);
342
+ gpio_set_level(PIN_CKV, 0);
343
+ }
344
+ }
345
+
346
+ // One field: reset the gate, stream every row, then one trailing dummy line so
347
+ // the last real row gets latched+driven (pipeline flush).
348
+ // 4x4 ordered (Bayer) dither: a per-pixel threshold so 16-level grayscale
349
+ // renders as black/white patterns on this 1-bit-per-field drive. Pure black
350
+ // (g=0) is always dark, pure white (g=15) always light, mids dither.
351
+ static const uint8_t kBayer[4][4] = {
352
+ { 0, 8, 2, 10},
353
+ {12, 4, 14, 6},
354
+ { 3, 11, 1, 9},
355
+ {15, 7, 13, 5},
356
+ };
357
+
358
+ // One field driving each pixel toward its dithered target — or, with the
359
+ // commands swapped, toward the INVERSE of the target (the negative-image
360
+ // phase of a classic flashing full refresh).
361
+ static void field_from_rows_cmds(const uint8_t *fb, uint8_t drv_dark, uint8_t drv_light)
362
+ {
363
+ frame_start();
364
+ const int in_stride = EPD_WIDTH / 2; // 4bpp source rows
365
+ for (int y = 0; y < EPD_HEIGHT; y++) {
366
+ uint8_t *out = s_dma[s_cur];
367
+ const uint8_t *in = fb + (size_t)y * in_stride;
368
+ const uint8_t *bm = kBayer[y & 3];
369
+ for (int xb = 0; xb < EPD_LINE_BYTES; xb++) {
370
+ const uint8_t b0 = in[xb * 2 + 0];
371
+ const uint8_t b1 = in[xb * 2 + 1];
372
+ // The 4 pixels of this output byte are at x = xb*4 + {0,1,2,3}.
373
+ const uint8_t p0 = b0 & 0x0F, p1 = (b0 >> 4) & 0x0F;
374
+ const uint8_t p2 = b1 & 0x0F, p3 = (b1 >> 4) & 0x0F;
375
+ // Drive EVERY pixel toward its (dithered) target each field so a
376
+ // moving scene erases its previous frame instead of ghosting.
377
+ // Threshold rule: dark iff (p <= bayer && p != 15). With 16 gray
378
+ // levels against a 16-cell matrix one endpoint must saturate by
379
+ // construction — pin BOTH: pure black (p=0, <= every cell) is
380
+ // always driven dark and pure white (p=15) always light. A plain
381
+ // `p < bm` left 1/16 of pure-black pixels driven LIGHT every
382
+ // field (the bayer-0 cell), visibly graying solid text.
383
+ uint8_t v = 0;
384
+ v |= (uint8_t)(((p0 <= bm[0] && p0 != 15) ? drv_dark : drv_light) << 0);
385
+ v |= (uint8_t)(((p1 <= bm[1] && p1 != 15) ? drv_dark : drv_light) << 2);
386
+ v |= (uint8_t)(((p2 <= bm[2] && p2 != 15) ? drv_dark : drv_light) << 4);
387
+ v |= (uint8_t)(((p3 <= bm[3] && p3 != 15) ? drv_dark : drv_light) << 6);
388
+ out[xb] = v;
389
+ }
390
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
391
+ send_row(out);
392
+ s_cur ^= 1;
393
+ }
394
+ // Trailing dummy line flushes the last real row through the pipeline.
395
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
396
+ send_row(s_dma[s_cur]);
397
+ s_cur ^= 1;
398
+ while (!s_dma_done) {}
399
+ }
400
+
401
+ static void field_from_rows(const uint8_t *fb)
402
+ {
403
+ field_from_rows_cmds(fb, DRV_DARK, DRV_LIGHT);
404
+ }
405
+
406
+ static void field_uniform(uint8_t cmd);
407
+ static void field_uniform_masked(uint8_t cmd, int parity);
408
+ static void field_uniform_swept16(uint8_t cmd);
409
+ static void field_uniform_swept_range(uint8_t cmd, int byte_lo, int byte_hi);
410
+
411
+ // The "shake": rapid whole-panel black/white alternation, one field per
412
+ // direction — the activation phase of commercial e-paper waveforms (the
413
+ // familiar full-refresh flicker). Alternation, not sustained push, is what
414
+ // loosens stuck particles and clears latent charge.
415
+ static void shake(int alternations, int hold_us)
416
+ {
417
+ const int saved_hold = s_row_hold_us;
418
+ s_row_hold_us = hold_us;
419
+ for (int i = 0; i < alternations; i++) {
420
+ field_uniform_swept16(DRV_DARK);
421
+ field_uniform_swept16(DRV_LIGHT);
422
+ }
423
+ s_row_hold_us = saved_hold;
424
+ }
425
+
426
+ // Drive the whole panel toward one 2-bit command for `fields` fields.
427
+ static void field_uniform(uint8_t cmd)
428
+ {
429
+ const uint8_t byte = (uint8_t)((cmd << 6) | (cmd << 4) | (cmd << 2) | cmd);
430
+ frame_start();
431
+ for (int y = 0; y < EPD_HEIGHT; y++) {
432
+ uint8_t *out = s_dma[s_cur];
433
+ memset(out, byte, EPD_LINE_BYTES);
434
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
435
+ send_row(out);
436
+ s_cur ^= 1;
437
+ }
438
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
439
+ send_row(s_dma[s_cur]);
440
+ s_cur ^= 1;
441
+ while (!s_dma_done) {}
442
+ }
443
+
444
+ // One field driving HALF the pixels (x parity == `parity`) toward `cmd`, the
445
+ // other half NOP. A raw solid field makes all 960 source outputs in a row
446
+ // drive the SAME polarity at once — worst-case current on one supply rail —
447
+ // and the far end of the source chain (portrait bottom) sees sagged rails and
448
+ // never reaches full drive. Ground truth on THIS panel (2026-07-20): solid
449
+ // fills leave a bottom halo that checkerboard patterns never show, because a
450
+ // checker splits the row's load between the two rails. Driving solids as two
451
+ // complementary half-masked passes delivers the same charge to every pixel at
452
+ // checker-level per-row load.
453
+ static void field_uniform_masked(uint8_t cmd, int parity)
454
+ {
455
+ const uint8_t byte = parity
456
+ ? (uint8_t)((cmd << 6) | (DRV_HOLD << 4) | (cmd << 2) | DRV_HOLD)
457
+ : (uint8_t)((DRV_HOLD << 6) | (cmd << 4) | (DRV_HOLD << 2) | cmd);
458
+ frame_start();
459
+ for (int y = 0; y < EPD_HEIGHT; y++) {
460
+ uint8_t *out = s_dma[s_cur];
461
+ memset(out, byte, EPD_LINE_BYTES);
462
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
463
+ send_row(out);
464
+ s_cur ^= 1;
465
+ }
466
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
467
+ send_row(s_dma[s_cur]);
468
+ s_cur ^= 1;
469
+ while (!s_dma_done) {}
470
+ }
471
+
472
+ // GROUND TRUTH on this panel (user, 2026-07-20): checker fields (both
473
+ // polarities per row, net VCOM return current ~0) drive the WHOLE panel
474
+ // including the halo region; single-polarity fields — full solids AND
475
+ // half-masked solids (net 480 of 960 outputs one way) — leave the halo
476
+ // region undriven. The common electrode sags under net return current and
477
+ // the far region loses its effective drive voltage. So a solid may only be
478
+ // built from passes whose net current is a small fraction of a row: drive
479
+ // pixels with (x % 16 == group) — 60 of 960 outputs (~6%) — and sweep all
480
+ // 16 groups for full coverage. ~16x the scan time of a raw solid; solids
481
+ // are clears/flashes, not the animation path, so that's fine.
482
+ static void field_uniform_swept16(uint8_t cmd)
483
+ {
484
+ for (int group = 0; group < 16; group++) {
485
+ // 4-byte tile covering 16 pixels; exactly one driven per tile.
486
+ uint8_t tile[4] = { 0, 0, 0, 0 };
487
+ tile[group >> 2] = (uint8_t)(cmd << ((group & 3) * 2));
488
+ frame_start();
489
+ for (int y = 0; y < EPD_HEIGHT; y++) {
490
+ uint8_t *out = s_dma[s_cur];
491
+ for (int xb = 0; xb < EPD_LINE_BYTES; xb++) out[xb] = tile[xb & 3];
492
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
493
+ send_row(out);
494
+ s_cur ^= 1;
495
+ }
496
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
497
+ send_row(s_dma[s_cur]);
498
+ s_cur ^= 1;
499
+ while (!s_dma_done) {}
500
+ }
501
+ }
502
+
503
+ // ---- Public epd_driver.h API ------------------------------------------------
504
+
505
+ void epd_init(void)
506
+ {
507
+ if (s_inited) return;
508
+
509
+ gpio_config_t io = {
510
+ .mode = GPIO_MODE_OUTPUT,
511
+ .pull_up_en = GPIO_PULLUP_DISABLE,
512
+ .pull_down_en = GPIO_PULLDOWN_DISABLE,
513
+ .intr_type = GPIO_INTR_DISABLE,
514
+ .pin_bit_mask = (1ULL << PIN_CKV) | (1ULL << PIN_LEH) | (1ULL << PIN_STV),
515
+ };
516
+ ESP_ERROR_CHECK_WITHOUT_ABORT(gpio_config(&io));
517
+ gpio_set_level(PIN_CKV, 0);
518
+ gpio_set_level(PIN_LEH, 0);
519
+ gpio_set_level(PIN_STV, 1);
520
+
521
+ i2c_master_bus_config_t bus = {
522
+ .i2c_port = -1,
523
+ .sda_io_num = PIN_CFG_SDA,
524
+ .scl_io_num = PIN_CFG_SCL,
525
+ .clk_source = I2C_CLK_SRC_DEFAULT,
526
+ .glitch_ignore_cnt = 7,
527
+ };
528
+ ESP_ERROR_CHECK(i2c_new_master_bus(&bus, &s_i2c));
529
+ i2c_device_config_t pcacfg = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = PCA_ADDR, .scl_speed_hz = 100000 };
530
+ ESP_ERROR_CHECK(i2c_master_bus_add_device(s_i2c, &pcacfg, &s_pca));
531
+ i2c_device_config_t tpscfg = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = TPS_ADDR, .scl_speed_hz = 100000 };
532
+ ESP_ERROR_CHECK(i2c_master_bus_add_device(s_i2c, &tpscfg, &s_tps));
533
+ pca_set_config((uint8_t)(PCA_PWRGOOD | PCA_INT)); // those two are inputs
534
+ s_pca_power = 0;
535
+ pca_set_output(0);
536
+
537
+ esp_lcd_i80_bus_config_t i80 = {
538
+ .dc_gpio_num = PIN_DC,
539
+ .wr_gpio_num = PIN_CKH,
540
+ .clk_src = LCD_CLK_SRC_PLL160M,
541
+ .data_gpio_nums = { PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6, PIN_D7 },
542
+ .bus_width = 8,
543
+ .max_transfer_bytes = EPD_LINE_BYTES + EPD_LINE_PAD + 16,
544
+ .dma_burst_size = 32,
545
+ };
546
+ ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&i80, &s_i80_bus));
547
+ esp_lcd_panel_io_i80_config_t iocfg = {
548
+ .cs_gpio_num = PIN_STH,
549
+ .pclk_hz = EPD_XCK_HZ,
550
+ .trans_queue_depth = 4,
551
+ .on_color_trans_done = dma_done_cb,
552
+ .lcd_cmd_bits = 8,
553
+ .lcd_param_bits = 8,
554
+ .dc_levels = { .dc_idle_level = 0, .dc_cmd_level = 0, .dc_dummy_level = 0, .dc_data_level = 1 },
555
+ };
556
+ ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(s_i80_bus, &iocfg, &s_panel_io));
557
+
558
+ for (int i = 0; i < 2; i++)
559
+ s_dma[i] = heap_caps_aligned_alloc(16, EPD_LINE_BYTES + EPD_LINE_PAD + 16, MALLOC_CAP_DMA);
560
+ s_cur = 0;
561
+ s_dma_done = true;
562
+ // Per-pixel DC ledger (PSRAM). If this fails, field_scan_permitted locks
563
+ // all drive rather than running unprotected.
564
+ s_ledger = heap_caps_calloc((size_t)EPD_WIDTH * EPD_HEIGHT, 1, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
565
+ if (!s_ledger) ESP_LOGE(TAG, "safety: DC-ledger allocation FAILED — panel drive locked");
566
+ s_inited = true;
567
+ ESP_LOGI(TAG, "ED047TC1 i80/PCA9555/TPS65185 driver up: %dx%d pclk=%dMHz D0-7={%d,%d,%d,%d,%d,%d,%d,%d} CKH=%d CKV=%d STH=%d LEH=%d STV=%d I2C=%d/%d",
568
+ EPD_WIDTH, EPD_HEIGHT, EPD_XCK_HZ / 1000000,
569
+ PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6, PIN_D7,
570
+ PIN_CKH, PIN_CKV, PIN_STH, PIN_LEH, PIN_STV, PIN_CFG_SDA, PIN_CFG_SCL);
571
+ }
572
+
573
+ static void epd_poweron_internal(void)
574
+ {
575
+ if (!s_inited) return;
576
+ s_pca_power = PCA_WAKEUP; pca_ctrl(true, false);
577
+ vTaskDelay(1);
578
+ // Rail power-up sequencing (epdiy tps65185.c values): UPSEQ0=0xE1 orders
579
+ // the strobes, UPSEQ1=0xAA sets the inter-rail delays. We previously left
580
+ // the chip's defaults; program the proven config before PWRUP triggers the
581
+ // sequenced bring-up.
582
+ reg_write(s_tps, TPS_REG_UPSEQ0, 0xE1);
583
+ reg_write(s_tps, TPS_REG_UPSEQ1, 0xAA);
584
+ s_pca_power = PCA_WAKEUP | PCA_PWRUP; pca_ctrl(true, false);
585
+ s_pca_power = PCA_WAKEUP | PCA_PWRUP | PCA_VCOM; pca_ctrl(true, false);
586
+ vTaskDelay(1);
587
+
588
+ int tries = 0;
589
+ while (!(pca_read_input() & PCA_PWRGOOD)) {
590
+ if (++tries >= 200) { ESP_LOGE(TAG, "PWRGOOD timeout"); break; }
591
+ vTaskDelay(1);
592
+ }
593
+ reg_write(s_tps, TPS_REG_ENABLE, 0x3F);
594
+ // VCOM interlock: only ever program the panel's OWN calibration (set via
595
+ // gea_epd_set_vcom_mv). Unset -> chip default stays, and every scan is
596
+ // NOP-suppressed by field_scan_permitted anyway.
597
+ if (s_vcom_set) tps_set_vcom(s_vcom_mv);
598
+ gpio_set_level(PIN_STH, 1);
599
+
600
+ tries = 0;
601
+ while ((reg_read(s_tps, TPS_REG_PG) & 0xFA) != 0xFA) {
602
+ if (++tries >= 500) { ESP_LOGE(TAG, "TPS power-good failed PG=0x%02x", reg_read(s_tps, TPS_REG_PG)); break; }
603
+ vTaskDelay(1);
604
+ }
605
+ // Enable source outputs + drive mode for the whole draw session.
606
+ pca_ctrl(true, true);
607
+ }
608
+
609
+ void epd_poweron(void)
610
+ {
611
+ epd_poweron_internal();
612
+ }
613
+
614
+ void epd_poweroff(void)
615
+ {
616
+ if (!s_inited) return;
617
+ s_pca_power = PCA_WAKEUP;
618
+ pca_ctrl(false, false);
619
+ vTaskDelay(1);
620
+ s_pca_power = 0;
621
+ pca_ctrl(false, false);
622
+ }
623
+
624
+ void epd_poweroff_all(void) { epd_poweroff(); }
625
+
626
+ void epd_clear(void)
627
+ {
628
+ if (!s_inited) return;
629
+ const int saved_hold = s_row_hold_us;
630
+ // A clear must erase HISTORY, not merely push toward a color. Pixels
631
+ // carrying residual charge from a high-contrast pattern land off-target
632
+ // under a one-way push and the pattern shows through the solid. Full-range
633
+ // alternation first — every pass flips EVERY pixel — bleeds the asymmetric
634
+ // residue; then the sustained white push finishes on clean film (the
635
+ // classic flashing clear of commercial readers).
636
+ s_row_hold_us = 60;
637
+ for (int pass = 0; pass < 3; pass++) {
638
+ for (int i = 0; i < 3; i++) field_uniform_swept16(DRV_DARK);
639
+ for (int i = 0; i < 3; i++) field_uniform_swept16(DRV_LIGHT);
640
+ }
641
+ s_row_hold_us = 40;
642
+ for (int i = 0; i < 4; i++) field_uniform_swept16(DRV_DARK);
643
+ for (int i = 0; i < 6; i++) field_uniform_swept16(DRV_LIGHT);
644
+ s_row_hold_us = saved_hold;
645
+ }
646
+
647
+ // One field of a block-checkerboard at a given block size (pixels; use
648
+ // multiples of 4 so blocks land on byte boundaries). Visible to the eye,
649
+ // unlike a per-pixel checker which reads as uniform gray at this dpi, and
650
+ // coherent enough to exercise lateral charge differences across capsule
651
+ // clusters. Varying the block size between passes moves the lattice edges
652
+ // so no boundary line sits on the same pixels all session.
653
+ static void field_checker(int block_px, bool invert)
654
+ {
655
+ const uint8_t dark_fill = (uint8_t)((DRV_DARK << 6) | (DRV_DARK << 4) | (DRV_DARK << 2) | DRV_DARK);
656
+ const uint8_t light_fill = (uint8_t)((DRV_LIGHT << 6) | (DRV_LIGHT << 4) | (DRV_LIGHT << 2) | DRV_LIGHT);
657
+ if (block_px < 4) block_px = 4;
658
+ frame_start();
659
+ for (int y = 0; y < EPD_HEIGHT; y++) {
660
+ uint8_t *out = s_dma[s_cur];
661
+ const int yblk = y / block_px;
662
+ for (int xb = 0; xb < EPD_LINE_BYTES; xb++) {
663
+ const int parity = ((((xb * 4) / block_px) + yblk) & 1) ^ (invert ? 1 : 0);
664
+ out[xb] = parity ? dark_fill : light_fill;
665
+ }
666
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
667
+ send_row(out);
668
+ s_cur ^= 1;
669
+ }
670
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
671
+ send_row(s_dma[s_cur]);
672
+ s_cur ^= 1;
673
+ while (!s_dma_done) {}
674
+ }
675
+
676
+ // Deep panel recovery: multipass full-quality refresh cycles to dissipate
677
+ // accumulated residual charge (the aftermath of DC-imbalanced driving — the
678
+ // inverted-polarity phase kept pushing the page area one way). Each cycle is
679
+ // four saturating phases: all-black, all-white, checkerboard, inverse
680
+ // checkerboard — the pattern phases exercise LATERAL charge differences that
681
+ // uniform flashing can't reach (same recipe as vendor screen-repair tools).
682
+ // Every phase drives both pixel classes equally, so each cycle is zero-mean.
683
+ // Caller must have powered the panel on.
684
+ // Strong-drive repair: every field runs with an extended row-select window
685
+ // (REPAIR_ROW_HOLD_US) so each pass transfers ~4x the charge of a bare scan,
686
+ // and each phase is followed by a settle pause — e-ink particles keep moving
687
+ // on the ~100ms timescale after the field ends, and drive+settle cycling
688
+ // shakes trapped charge loose better than continuous drive.
689
+ #define REPAIR_ROW_HOLD_US 120
690
+ #define REPAIR_SETTLE_MS 100
691
+
692
+ void gea_epd_repair(int cycles, int fields_per_phase)
693
+ {
694
+ if (!s_inited || !experimental_ok("gea_epd_repair")) return;
695
+ const int saved_hold = s_row_hold_us;
696
+ s_row_hold_us = REPAIR_ROW_HOLD_US;
697
+ static const int kCheckerScales[3] = { 16, 32, 48 };
698
+ for (int c = 0; c < cycles; c++) {
699
+ // One checker scale per cycle (rotating across cycles so the lattice
700
+ // walks), and the checker is IMMEDIATELY followed by its exact inverse
701
+ // at the SAME scale: that pair flips every pixel and is zero-mean, so
702
+ // the pattern phase leaves no per-pixel-class history behind. Entering
703
+ // a solid straight from a pattern flips only HALF the pixels — the
704
+ // half that saturates in place keeps its offset and the pattern shows
705
+ // through the solid (seen on glass 2026-07-20) — so solids are only
706
+ // entered after a shake equalizes both classes' recent history.
707
+ const bool inv = (c & 1) != 0;
708
+ const int scale = kCheckerScales[c % 3];
709
+ shake(4, 20);
710
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_DARK);
711
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
712
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
713
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
714
+ for (int i = 0; i < fields_per_phase; i++) field_checker(scale, inv);
715
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
716
+ for (int i = 0; i < fields_per_phase; i++) field_checker(scale, !inv);
717
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
718
+ shake(4, 20);
719
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
720
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
721
+ if ((c % 25) == 24) ESP_LOGI(TAG, "repair cycle %d/%d", c + 1, cycles);
722
+ }
723
+ // Rest white.
724
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
725
+ s_row_hold_us = saved_hold;
726
+ }
727
+
728
+ // Solids-only deghosting wash for a PATTERN imprint (e.g. a checkerboard that
729
+ // shows through solid fills). Strong full-range black/white alternation with
730
+ // settle pauses: every transition flips EVERY pixel, so each cycle is exactly
731
+ // zero-mean per pixel and the imprint bleeds out — and unlike the checker-based
732
+ // repair there are no pattern phases that could re-imprint anything. Warming
733
+ // the panel WHILE this runs speeds recovery (particle mobility rises with
734
+ // temperature); heat without drive moves nothing.
735
+ void gea_epd_wash(int cycles, int fields_per_phase)
736
+ {
737
+ if (!s_inited || !experimental_ok("gea_epd_wash")) return;
738
+ const int saved_hold = s_row_hold_us;
739
+ for (int c = 0; c < cycles; c++) {
740
+ shake(6, 20); // rapid activation flicker
741
+ s_row_hold_us = REPAIR_ROW_HOLD_US;
742
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_DARK);
743
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
744
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
745
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
746
+ s_row_hold_us = saved_hold;
747
+ if ((c % 25) == 24) ESP_LOGI(TAG, "wash cycle %d/%d", c + 1, cycles);
748
+ }
749
+ // Rest white.
750
+ s_row_hold_us = REPAIR_ROW_HOLD_US;
751
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
752
+ s_row_hold_us = saved_hold;
753
+ }
754
+
755
+ // FIRST-LIGHT ritual for a NEW panel: after gea_epd_set_vcom_mv() with THAT
756
+ // panel's own calibration, drive a gentle 4-field swept DARK band across the
757
+ // screen center, then power off and stop. The user must visually confirm the
758
+ // band DARKENED — if it lightened, the polarity is inverted and NOTHING else
759
+ // may run (the first panel took a whole session of inverted drive before the
760
+ // swap was caught). Sustained rendering stays locked until the board config
761
+ // asserts the ritual was confirmed.
762
+ void gea_epd_first_light_ritual(void)
763
+ {
764
+ if (!s_inited) return;
765
+ ESP_LOGW(TAG, "FIRST LIGHT: driving a gentle DARK band across the screen center...");
766
+ epd_poweron_internal();
767
+ const int saved_hold = s_row_hold_us;
768
+ s_row_hold_us = 80;
769
+ for (int i = 0; i < 4; i++) field_uniform_swept_range(DRV_DARK, 80, 160);
770
+ s_row_hold_us = saved_hold;
771
+ epd_poweroff();
772
+ ESP_LOGW(TAG, "FIRST LIGHT done. The center band must be DARKER than before.");
773
+ ESP_LOGW(TAG, "If it got LIGHTER: polarity is inverted — STOP, fix DRV_DARK/DRV_LIGHT.");
774
+ ESP_LOGW(TAG, "If darker: set kFirstLightConfirmed=true in display.cpp and reflash.");
775
+ }
776
+
777
+ // RECOVERY-ONLY program: runs forever, never returns. Alternating treatment
778
+ // and REST blocks:
779
+ // - treatment: power on, activation shake + strong solid black/white
780
+ // alternation (every transition flips every pixel — exactly zero-mean,
781
+ // nothing patterned), end white;
782
+ // - rest: power fully OFF (TPS rails + VCOM down, no bias across the film)
783
+ // for minutes — trapped charge dissipates on the minutes timescale, and
784
+ // resting under zero bias recovers more than continuous drive.
785
+ // Use by flashing a build whose display init calls this INSTEAD of starting
786
+ // the app: the panel gets treatment with zero app interference until a new
787
+ // firmware is flashed. Warming the panel during treatment blocks helps.
788
+ void gea_epd_recovery_forever(void)
789
+ {
790
+ if (!s_inited || !experimental_ok("gea_epd_recovery_forever")) return;
791
+ // Swept saturation costs MORE fields than raw drive: in a swept pass a
792
+ // pixel is driven for one gate window, then its row is rewritten with NOP
793
+ // on the next pass — unlike a raw solid where the latched drive holds
794
+ // between scans. 6 swept fields at hold 80 read visibly-not-black on
795
+ // glass (2026-07-20); 16 fields per direction at hold 150 triples the
796
+ // integrated per-pixel drive. The swept form is the ONLY solid drive that
797
+ // reaches the halo region (net-VCOM-current collapse under solid rows).
798
+ const int fields_per_phase = 16;
799
+ // The halo region (portrait bottom = physical row bytes [120,240) — the
800
+ // far, high-droop end) reads brighter than the rest at equal drive, so it
801
+ // gets extra balanced fields per cycle on top of the global fill.
802
+ const int halo_extra_fields = 12;
803
+ const int halo_byte_lo = 120, halo_byte_hi = 240;
804
+ int round = 0;
805
+ for (;;) {
806
+ if (!experimental_ok("gea_epd_recovery_forever")) { epd_poweroff(); for (;;) vTaskDelay(pdMS_TO_TICKS(60000)); }
807
+ round++;
808
+ ESP_LOGI(TAG, "recovery round %d: treatment (~8 min, deep swept + halo top-up)...", round);
809
+ epd_poweron();
810
+ const int saved_hold = s_row_hold_us;
811
+ for (int c = 0; c < 4; c++) {
812
+ shake(2, 20);
813
+ s_row_hold_us = 200;
814
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_DARK);
815
+ for (int i = 0; i < halo_extra_fields; i++) field_uniform_swept_range(DRV_DARK, halo_byte_lo, halo_byte_hi);
816
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
817
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
818
+ for (int i = 0; i < halo_extra_fields; i++) field_uniform_swept_range(DRV_LIGHT, halo_byte_lo, halo_byte_hi);
819
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
820
+ s_row_hold_us = saved_hold;
821
+ }
822
+ // Rest white with rails fully off.
823
+ s_row_hold_us = 80;
824
+ for (int i = 0; i < fields_per_phase; i++) field_uniform_swept16(DRV_LIGHT);
825
+ s_row_hold_us = saved_hold;
826
+ epd_poweroff();
827
+ ESP_LOGI(TAG, "recovery round %d: rest 3 min (power off)...", round);
828
+ vTaskDelay(pdMS_TO_TICKS(180 * 1000));
829
+ }
830
+ }
831
+
832
+ // Swept solid restricted to row bytes [byte_lo, byte_hi) — same 16-group
833
+ // current-limited sweep, but only within the region; everything outside gets
834
+ // NOP. Used to give the halo region (the far, high-droop end of the panel —
835
+ // it needs MORE integrated drive than the rest for the same optical result)
836
+ // extra balanced fields per treatment cycle. Callers MUST apply equal dark
837
+ // and light top-ups so the region stays zero-mean.
838
+ static void field_uniform_swept_range(uint8_t cmd, int byte_lo, int byte_hi)
839
+ {
840
+ if (byte_lo < 0) byte_lo = 0;
841
+ if (byte_hi > EPD_LINE_BYTES) byte_hi = EPD_LINE_BYTES;
842
+ if (byte_lo >= byte_hi) return;
843
+ for (int group = 0; group < 16; group++) {
844
+ uint8_t tile[4] = { 0, 0, 0, 0 };
845
+ tile[group >> 2] = (uint8_t)(cmd << ((group & 3) * 2));
846
+ frame_start();
847
+ for (int y = 0; y < EPD_HEIGHT; y++) {
848
+ uint8_t *out = s_dma[s_cur];
849
+ memset(out, 0, EPD_LINE_BYTES);
850
+ for (int xb = byte_lo; xb < byte_hi; xb++) out[xb] = tile[xb & 3];
851
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
852
+ send_row(out);
853
+ s_cur ^= 1;
854
+ }
855
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
856
+ send_row(s_dma[s_cur]);
857
+ s_cur ^= 1;
858
+ while (!s_dma_done) {}
859
+ }
860
+ }
861
+
862
+ // DIAGNOSTIC loop discriminating the two remaining bottom-halo theories
863
+ // (2026-07-20). Cycles three visually distinct phases, ~20s each, separated by
864
+ // ~3s of stillness, forever:
865
+ // A: true checker alternation — every row carries BOTH polarities (net VCOM
866
+ // return current ~0). If the halo FLICKERS here, the region receives
867
+ // data and the failure is single-polarity drive (VCOM iR-droop): fix =
868
+ // current-balanced waveforms.
869
+ // B: split-masked solids (single polarity + NOP) — current recovery drive.
870
+ // C: raw full solids — the original failing mode.
871
+ // If the halo stays inert in ALL phases including A, the region never gets
872
+ // source data at all (geometric/scan defect — e.g. trailing pad bytes
873
+ // clocking data through the source shift chain) and "checkers work" was the
874
+ // periodicity illusion (stale checker looks like checker).
875
+ void gea_epd_diagnostic_forever(void)
876
+ {
877
+ if (!s_inited || !experimental_ok("gea_epd_diagnostic_forever")) return;
878
+ int round = 0;
879
+ for (;;) {
880
+ if (!experimental_ok("gea_epd_diagnostic_forever")) { epd_poweroff(); for (;;) vTaskDelay(pdMS_TO_TICKS(60000)); }
881
+ round++;
882
+ epd_poweron();
883
+ const int saved_hold = s_row_hold_us;
884
+ s_row_hold_us = 80;
885
+ ESP_LOGI(TAG, "diag round %d phase A: checker alternation 20s", round);
886
+ for (int i = 0; i < 90; i++) {
887
+ field_checker(8, 0);
888
+ field_checker(8, 1);
889
+ }
890
+ s_row_hold_us = saved_hold;
891
+ epd_poweroff();
892
+ vTaskDelay(pdMS_TO_TICKS(3000));
893
+ epd_poweron();
894
+ s_row_hold_us = 80;
895
+ ESP_LOGI(TAG, "diag round %d phase B: SWEPT-16 solids 30s", round);
896
+ for (int i = 0; i < 16; i++) {
897
+ field_uniform_swept16(DRV_DARK);
898
+ field_uniform_swept16(DRV_LIGHT);
899
+ }
900
+ s_row_hold_us = saved_hold;
901
+ epd_poweroff();
902
+ vTaskDelay(pdMS_TO_TICKS(3000));
903
+ }
904
+ }
905
+
906
+ // Region-targeted overdrive: extra black/white cycles applied only to row
907
+ // bytes [byte_lo, byte_hi); everything else gets NOP (hold). Concentrates
908
+ // treatment on a burned-in area without wearing the healthy half. Portrait
909
+ // coordinates map y -> physical x, so the portrait BOTTOM half is row bytes
910
+ // [120, 240).
911
+ void gea_epd_repair_region(int cycles, int fields_per_phase, int byte_lo, int byte_hi)
912
+ {
913
+ if (!s_inited || !experimental_ok("gea_epd_repair_region")) return;
914
+ if (byte_lo < 0) byte_lo = 0;
915
+ if (byte_hi > EPD_LINE_BYTES) byte_hi = EPD_LINE_BYTES;
916
+ if (byte_lo >= byte_hi) return;
917
+ const int saved_hold = s_row_hold_us;
918
+ s_row_hold_us = REPAIR_ROW_HOLD_US;
919
+ for (int c = 0; c < cycles; c++) {
920
+ for (int phase = 0; phase < 2; phase++) {
921
+ const uint8_t cmd = phase ? DRV_LIGHT : DRV_DARK;
922
+ const uint8_t fill = (uint8_t)((cmd << 6) | (cmd << 4) | (cmd << 2) | cmd);
923
+ for (int i = 0; i < fields_per_phase; i++) {
924
+ frame_start();
925
+ for (int y = 0; y < EPD_HEIGHT; y++) {
926
+ uint8_t *out = s_dma[s_cur];
927
+ memset(out, DRV_HOLD, EPD_LINE_BYTES);
928
+ memset(out + byte_lo, fill, (size_t)(byte_hi - byte_lo));
929
+ memset(out + EPD_LINE_BYTES, 0, EPD_LINE_PAD);
930
+ send_row(out);
931
+ s_cur ^= 1;
932
+ }
933
+ memset(s_dma[s_cur], 0, EPD_LINE_BYTES + EPD_LINE_PAD);
934
+ send_row(s_dma[s_cur]);
935
+ s_cur ^= 1;
936
+ while (!s_dma_done) {}
937
+ }
938
+ }
939
+ if ((c % 25) == 24) ESP_LOGI(TAG, "region repair cycle %d/%d", c + 1, cycles);
940
+ vTaskDelay(pdMS_TO_TICKS(REPAIR_SETTLE_MS));
941
+ }
942
+ s_row_hold_us = saved_hold;
943
+ }
944
+
945
+ Rect_t epd_full_screen(void)
946
+ {
947
+ Rect_t r = { .x = 0, .y = 0, .width = EPD_WIDTH, .height = EPD_HEIGHT };
948
+ return r;
949
+ }
950
+
951
+ // STAGE 0: 1-bit black-on-white. `data` = panel-native 4bpp grayscale
952
+ // framebuffer (EPD_WIDTH/2 bytes/row, even x = low nibble). Darker-than-mid
953
+ // pixels are driven dark over EPD_IMAGE_FIELDS fields; the rest hold white.
954
+ void IRAM_ATTR epd_draw_grayscale_image(Rect_t area, uint8_t *data)
955
+ {
956
+ if (!s_inited || !data) return;
957
+ (void)area;
958
+ // Quality draw: extend the row-select window so each field is a real
959
+ // push (the bare ~21µs scan leaves text gray). ~40µs x 540 rows x 12
960
+ // fields ≈ 0.4s per refresh — fine for page turns; the 60fps per-pixel
961
+ // engine will run with hold=0 and many weak fields instead.
962
+ const int saved_hold = s_row_hold_us;
963
+ s_row_hold_us = 40;
964
+ for (int f = 0; f < EPD_IMAGE_FIELDS; f++)
965
+ field_from_rows(data);
966
+ s_row_hold_us = saved_hold;
967
+ }
968
+
969
+ void IRAM_ATTR epd_draw_image(Rect_t area, uint8_t *data, DrawMode_t mode)
970
+ {
971
+ (void)mode;
972
+ epd_draw_grayscale_image(area, data);
973
+ }
974
+
975
+ // Classic flashing FULL refresh, the "usual e-paper refresh" sequence:
976
+ // activation shake (rapid B/W flicker), NEGATIVE of the image, white reset,
977
+ // then the image. Clears ghosting far better than repeated target-driving
978
+ // because every pixel traverses its full range with alternation.
979
+ void gea_epd_draw_full_flash(uint8_t *data)
980
+ {
981
+ if (!s_inited || !data) return;
982
+ const int saved_hold = s_row_hold_us;
983
+ s_row_hold_us = 40;
984
+ shake(3, 20);
985
+ for (int f = 0; f < 4; f++) field_from_rows_cmds(data, DRV_LIGHT, DRV_DARK); // negative image
986
+ for (int f = 0; f < 3; f++) field_uniform_swept16(DRV_LIGHT); // white reset
987
+ for (int f = 0; f < EPD_IMAGE_FIELDS; f++) field_from_rows(data); // final image
988
+ s_row_hold_us = saved_hold;
989
+ }