@geastack/targets 0.1.91 → 0.1.93

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 (26) hide show
  1. package/build-config.json +32 -0
  2. package/package.json +6 -6
  3. package/targets/cmake/geatsc_generated_archive.cmake +18 -2
  4. package/targets/esp32/chip_bindings/audio/es8311.cpp +10 -1
  5. package/targets/esp32/chip_bindings/displays/co5300.cpp +40 -0
  6. package/targets/esp32/chip_bindings/imu/bmi270.cpp +6 -1
  7. package/targets/esp32/chip_bindings/touch/cst9217.cpp +67 -3
  8. package/targets/esp32/display.cpp +35 -32
  9. package/targets/esp32/render_worker_join.h +32 -0
  10. package/targets/esp32/services/device_control.cpp +130 -0
  11. package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +8 -1
  12. package/targets/esp32-s3-touch-amoled-1.8/main/app_main.cpp +8 -0
  13. package/targets/esp32-s3-touch-amoled-1.8/main/launcher_button.cpp +6 -1
  14. package/targets/esp32-s31-espressif-mosaico/CMakeLists.txt +10 -0
  15. package/targets/esp32-s31-espressif-mosaico/README.md +65 -0
  16. package/targets/esp32-s31-espressif-mosaico/dependencies.lock +141 -0
  17. package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +77 -0
  18. package/targets/esp32-s31-espressif-mosaico/main/Kconfig.projbuild +12 -0
  19. package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +440 -0
  20. package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +37 -0
  21. package/targets/esp32-s31-espressif-mosaico/main/include/board.h +147 -0
  22. package/targets/esp32-s31-espressif-mosaico/main/include/wifi_config.h.example +5 -0
  23. package/targets/esp32-s31-espressif-mosaico/main/touch.cpp +45 -0
  24. package/targets/esp32-s31-espressif-mosaico/partitions.csv +10 -0
  25. package/targets/esp32-s31-espressif-mosaico/sdkconfig.defaults +200 -0
  26. package/targets.json +12 -0
package/build-config.json CHANGED
@@ -516,6 +516,38 @@
516
516
  false
517
517
  ]
518
518
  }
519
+ },
520
+ "esp32-s31-espressif-mosaico": {
521
+ "supported": [
522
+ "compiler.generatedCodeOptimization",
523
+ "renderer.fuseReplayFlush",
524
+ "renderer.adaptiveCoalescing",
525
+ "renderer.broadDirtyBounds",
526
+ "display.framebufferStream",
527
+ "display.presentStream"
528
+ ],
529
+ "defaults": {
530
+ "compiler": {
531
+ "generatedCodeOptimization": "O2",
532
+ "numberPrecision": "float32"
533
+ },
534
+ "renderer": {
535
+ "fuseReplayFlush": false,
536
+ "subtreeRevealChecks": true,
537
+ "recordInlinePositions": true,
538
+ "adaptiveCoalescing": true,
539
+ "broadDirtyBounds": true
540
+ },
541
+ "display": {
542
+ "framebufferStream": "continuous",
543
+ "presentStream": "continuous"
544
+ },
545
+ "diagnostics": {
546
+ "performanceCounters": false,
547
+ "frameTiming": false
548
+ }
549
+ },
550
+ "cssDevicePixelRatio": 1.5
519
551
  }
520
552
  }
521
553
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/targets",
3
- "version": "0.1.91",
3
+ "version": "0.1.93",
4
4
  "description": "Native embedded build targets (ESP32-IDF, RP2350) for geastack apps: board sources, target catalog, and CMake glue driven by the gea CLI.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {
@@ -37,12 +37,12 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@geastack/chips": "^0.1.5",
40
- "@geastack/compiler": "^1.0.20",
41
- "@geastack/core": "^0.1.34",
42
- "@geastack/elements": "^0.1.4",
43
- "@geastack/engine": "^0.1.9",
40
+ "@geastack/compiler": "^1.0.22",
41
+ "@geastack/core": "^0.1.37",
42
+ "@geastack/elements": "^0.1.5",
43
+ "@geastack/engine": "^0.1.13",
44
44
  "@geastack/geaos": "^0.1.3",
45
- "@geastack/geatsc-plugin-gea": "^0.1.15",
45
+ "@geastack/geatsc-plugin-gea": "^0.1.19",
46
46
  "@geastack/host": "^0.1.14"
47
47
  },
48
48
  "scripts": {
@@ -88,6 +88,22 @@ function(gea_geatsc_add_generated_archive)
88
88
  # forward the launcher explicitly to retain clean-build cache hits.
89
89
  get_property(_compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
90
90
 
91
+ # The archive builder runs outside CMake's rules, so a tool CMake knows only
92
+ # by name would be looked up relative to the build directory. IDF 6.2's
93
+ # RISC-V toolchain file sets CMAKE_AR/CMAKE_RANLIB to bare names
94
+ # (riscv32-esp-elf-gcc-ar); resolve them beside the compiler, then on PATH.
95
+ get_filename_component(_compiler_dir "${CMAKE_CXX_COMPILER}" DIRECTORY)
96
+ foreach(_tool IN ITEMS AR RANLIB)
97
+ set(_tool_path "${CMAKE_${_tool}}")
98
+ if(_tool_path AND NOT IS_ABSOLUTE "${_tool_path}")
99
+ find_program(_resolved_${_tool} NAMES "${_tool_path}" HINTS "${_compiler_dir}" NO_CACHE)
100
+ if(_resolved_${_tool})
101
+ set(_tool_path "${_resolved_${_tool}}")
102
+ endif()
103
+ endif()
104
+ set(_geatsc_${_tool} "${_tool_path}")
105
+ endforeach()
106
+
91
107
  add_custom_command(
92
108
  OUTPUT "${GEA_GEATSC_OUTPUT}"
93
109
  COMMAND "${CMAKE_COMMAND}"
@@ -98,8 +114,8 @@ function(gea_geatsc_add_generated_archive)
98
114
  "-DGEA_GEATSC_FLAGS_FILE=${_flags_file}"
99
115
  "-DGEA_GEATSC_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
100
116
  "-DGEA_GEATSC_COMPILER_LAUNCHER=${_compiler_launcher}"
101
- "-DGEA_GEATSC_AR=${CMAKE_AR}"
102
- "-DGEA_GEATSC_RANLIB=${CMAKE_RANLIB}"
117
+ "-DGEA_GEATSC_AR=${_geatsc_AR}"
118
+ "-DGEA_GEATSC_RANLIB=${_geatsc_RANLIB}"
103
119
  -P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/geatsc_generated_archive_build.cmake"
104
120
  DEPENDS
105
121
  ${GEA_GEATSC_DEPENDS}
@@ -86,6 +86,15 @@ esp_err_t setAmplifierEnabled(bool enabled) {
86
86
 
87
87
  constexpr int kCodecDataPort = 0;
88
88
 
89
+ // esp_codec_dev takes the 8-bit address. CE low answers at 7-bit 0x18, the
90
+ // component default; a board that straps CE high (the ESP-Mosaico, 0x19)
91
+ // names its 7-bit address with GEA_BOARD_ES8311_I2C_ADDRESS.
92
+ #ifdef GEA_BOARD_ES8311_I2C_ADDRESS
93
+ constexpr std::uint8_t kCodecI2cAddress = static_cast<std::uint8_t>(GEA_BOARD_ES8311_I2C_ADDRESS << 1);
94
+ #else
95
+ constexpr std::uint8_t kCodecI2cAddress = ES8311_CODEC_DEFAULT_ADDR;
96
+ #endif
97
+
89
98
  // Boards whose microphones sit on an ES7210 ADC sharing this I2S bus (Waveshare AMOLED 2.06) name its
90
99
  // 7-bit I2C address as `audio.es7210Address`; everywhere else the ES8311's own ADC records.
91
100
  template <typename AudioConfig>
@@ -655,7 +664,7 @@ private:
655
664
  }
656
665
 
657
666
  audio_codec_i2c_cfg_t i2cConfig = {};
658
- i2cConfig.addr = ES8311_CODEC_DEFAULT_ADDR;
667
+ i2cConfig.addr = kCodecI2cAddress;
659
668
  i2cConfig.bus_handle = static_cast<i2c_master_bus_handle_t>(i2cBus.nativeHandle());
660
669
  i2cCtrlIf_ = audio_codec_new_i2c_ctrl(&i2cConfig);
661
670
  if (!i2cCtrlIf_) return ESP_ERR_NO_MEM;
@@ -69,6 +69,42 @@ namespace gea::platform::esp32::chip_bindings::co5300
69
69
  };
70
70
  #endif
71
71
 
72
+ #if GEA_EMBEDDED_CO5300_MOSAICO_INIT
73
+ // ESP-Mosaico 480x480 panel, transcribed from the board's own BSP
74
+ // (esp-mosaico-bsp components/esp-mosaico-bsp/onboard/display.c,
75
+ // s_vendor_init). Sleep Out comes first here, unlike the Waveshare 1.75
76
+ // sequence, and the window spans the full 480 columns with no gap.
77
+ static const std::uint8_t kMosaicoFe20[] = {0x20};
78
+ static const std::uint8_t kMosaico19[] = {0x10};
79
+ static const std::uint8_t kMosaico1c[] = {0xA0};
80
+ static const std::uint8_t kMosaicoFe00[] = {0x00};
81
+ static const std::uint8_t kMosaicoC4[] = {0x80};
82
+ static const std::uint8_t kMosaico3a[] = {0x55};
83
+ static const std::uint8_t kMosaico35[] = {0x00};
84
+ static const std::uint8_t kMosaico53[] = {0x20};
85
+ static const std::uint8_t kMosaico51[] = {0xFF};
86
+ static const std::uint8_t kMosaico63[] = {0xFF};
87
+ static const std::uint8_t kMosaico2a[] = {0x00, 0x00, 0x01, 0xDF};
88
+ static const std::uint8_t kMosaico2b[] = {0x00, 0x00, 0x01, 0xDF};
89
+
90
+ static const co5300_lcd_init_cmd_t kMosaicoInitCommands[] = {
91
+ {0x11, nullptr, 0, 600},
92
+ {0xFE, kMosaicoFe20, sizeof(kMosaicoFe20), 0},
93
+ {0x19, kMosaico19, sizeof(kMosaico19), 0},
94
+ {0x1C, kMosaico1c, sizeof(kMosaico1c), 0},
95
+ {0xFE, kMosaicoFe00, sizeof(kMosaicoFe00), 0},
96
+ {0xC4, kMosaicoC4, sizeof(kMosaicoC4), 0},
97
+ {0x3A, kMosaico3a, sizeof(kMosaico3a), 0},
98
+ {0x35, kMosaico35, sizeof(kMosaico35), 0},
99
+ {0x53, kMosaico53, sizeof(kMosaico53), 0},
100
+ {0x51, kMosaico51, sizeof(kMosaico51), 0},
101
+ {0x63, kMosaico63, sizeof(kMosaico63), 0},
102
+ {0x2A, kMosaico2a, sizeof(kMosaico2a), 0},
103
+ {0x2B, kMosaico2b, sizeof(kMosaico2b), 0},
104
+ {0x29, nullptr, 0, 600},
105
+ };
106
+ #endif
107
+
72
108
  esp_lcd_panel_handle_t panelHandle(void *panel)
73
109
  {
74
110
  return static_cast<esp_lcd_panel_handle_t>(panel);
@@ -246,6 +282,10 @@ namespace gea::platform::esp32::chip_bindings::co5300
246
282
  #if GEA_EMBEDDED_CO5300_WAVESHARE_175_INIT
247
283
  vendorConfig.init_cmds = kWaveshare175InitCommands;
248
284
  vendorConfig.init_cmds_size = sizeof(kWaveshare175InitCommands) / sizeof(kWaveshare175InitCommands[0]);
285
+ #endif
286
+ #if GEA_EMBEDDED_CO5300_MOSAICO_INIT
287
+ vendorConfig.init_cmds = kMosaicoInitCommands;
288
+ vendorConfig.init_cmds_size = sizeof(kMosaicoInitCommands) / sizeof(kMosaicoInitCommands[0]);
249
289
  #endif
250
290
  vendorConfig.flags.use_qspi_interface = 1;
251
291
 
@@ -30,7 +30,12 @@ namespace {
30
30
  #include "bmi270_config.inl" // static constexpr const uint8_t bmi270_config_file[8192]
31
31
 
32
32
  constexpr char kTag[] = "bmi270";
33
- constexpr std::uint8_t kI2cAddress = 0x68;
33
+ // SDO strapped low gives 0x68 (M5StickC S3); boards that strap it high (the
34
+ // ESP-Mosaico) answer at 0x69 and say so with GEA_BOARD_BMI270_I2C_ADDRESS.
35
+ #ifndef GEA_BOARD_BMI270_I2C_ADDRESS
36
+ #define GEA_BOARD_BMI270_I2C_ADDRESS 0x68
37
+ #endif
38
+ constexpr std::uint8_t kI2cAddress = GEA_BOARD_BMI270_I2C_ADDRESS;
34
39
  constexpr std::uint32_t kI2cFrequencyHz = 400000;
35
40
  constexpr int kI2cTimeoutMs = 100;
36
41
  constexpr int64_t kRetryIntervalUs = 5000000;
@@ -6,8 +6,38 @@
6
6
 
7
7
  #include <algorithm>
8
8
 
9
+ #include "driver/gpio.h"
10
+ #include "esp_attr.h"
9
11
  #include "esp_lcd_panel_io.h"
12
+ // The CST92xx family shares this binding. A board whose controller is the
13
+ // CST9220 (the ESP-Mosaico) sets GEA_BOARD_TOUCH_CST9220: that part speaks
14
+ // either the legacy report protocol or HYN212, which needs a mode switch
15
+ // before reports arrive, and only Espressif's CST9220 driver handles both.
16
+ #if GEA_BOARD_TOUCH_CST9220
17
+ #include "esp_lcd_touch_cst9220.h"
18
+ #define GEA_CST92XX_NEW esp_lcd_touch_new_i2c_cst9220
19
+ namespace {
20
+ // ESP_LCD_TOUCH_IO_I2C_CST9220_CONFIG() lists its designators out of
21
+ // declaration order, which C++ rejects; the same values, field by field.
22
+ esp_lcd_panel_io_i2c_config_t cst9220IoConfig()
23
+ {
24
+ esp_lcd_panel_io_i2c_config_t config = {};
25
+ config.dev_addr = ESP_LCD_TOUCH_IO_I2C_CST9220_ADDRESS;
26
+ config.control_phase_bytes = 1;
27
+ config.dc_bit_offset = 0;
28
+ config.lcd_cmd_bits = 8;
29
+ config.lcd_param_bits = 8;
30
+ config.flags.disable_control_phase = 1;
31
+ config.scl_speed_hz = 400000;
32
+ return config;
33
+ }
34
+ } // namespace
35
+ #define GEA_CST92XX_IO_CONFIG cst9220IoConfig
36
+ #else
10
37
  #include "esp_lcd_touch_cst9217.h"
38
+ #define GEA_CST92XX_IO_CONFIG ESP_LCD_TOUCH_IO_I2C_CST9217_CONFIG
39
+ #define GEA_CST92XX_NEW esp_lcd_touch_new_i2c_cst9217
40
+ #endif
11
41
  #include "esp_log.h"
12
42
 
13
43
  namespace {
@@ -18,6 +48,23 @@ constexpr gpio_num_t kInterruptPin = gea::platform::board::touch.interrupt;
18
48
  constexpr int kPollIntervalMs = 10;
19
49
  constexpr int kTaskPriority = 10;
20
50
 
51
+ #if GEA_BOARD_TOUCH_CST9220
52
+ // The CST9220 raises INT (low) once per report. Reading between reports finds
53
+ // the frame the driver already acknowledged -- it logs "Malformed report
54
+ // header" and drops the sample -- so this binding reads on INT instead of on
55
+ // a timer. While a finger is down it still re-reads after kLiftTimeoutMs of
56
+ // silence, so a missed final report cannot leave a finger stuck down.
57
+ constexpr int kLiftTimeoutMs = 60;
58
+
59
+ void IRAM_ATTR touchInterrupt(void *arg)
60
+ {
61
+ auto *task = static_cast<TaskHandle_t *>(arg);
62
+ BaseType_t woken = pdFALSE;
63
+ if (*task) vTaskNotifyGiveFromISR(*task, &woken);
64
+ portYIELD_FROM_ISR(woken);
65
+ }
66
+ #endif
67
+
21
68
  } // namespace
22
69
 
23
70
  namespace gea::platform::esp32::chip_bindings::cst9217 {
@@ -87,7 +134,7 @@ void TouchController::consumeLatestMove(int *x, int *y)
87
134
 
88
135
  esp_err_t TouchController::attachTouchDevice()
89
136
  {
90
- esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_CST9217_CONFIG();
137
+ esp_lcd_panel_io_i2c_config_t io_config = GEA_CST92XX_IO_CONFIG();
91
138
  io_config.scl_speed_hz = 400000;
92
139
  esp_err_t err = esp_lcd_new_panel_io_i2c(bus_, &io_config, &io_);
93
140
  if (err != ESP_OK) {
@@ -110,8 +157,19 @@ esp_err_t TouchController::attachTouchDevice()
110
157
  .mirror_y = gea::platform::board::touch.mirrorY,
111
158
  },
112
159
  };
113
- err = esp_lcd_touch_new_i2c_cst9217(io_, &touch_config, &touch_);
114
- if (err != ESP_OK) ESP_LOGE(kTag, "Failed to create CST9217 touch device: %s", esp_err_to_name(err));
160
+ err = GEA_CST92XX_NEW(io_, &touch_config, &touch_);
161
+ if (err != ESP_OK) {
162
+ ESP_LOGE(kTag, "Failed to create CST92xx touch device: %s", esp_err_to_name(err));
163
+ return err;
164
+ }
165
+ #if GEA_BOARD_TOUCH_CST9220
166
+ // The driver configured INT as a falling-edge input; hook it to the task.
167
+ err = gpio_install_isr_service(0);
168
+ if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) return err;
169
+ err = gpio_isr_handler_add(kInterruptPin, touchInterrupt, &task_);
170
+ if (err == ESP_OK) err = gpio_intr_enable(kInterruptPin);
171
+ if (err != ESP_OK) ESP_LOGE(kTag, "Touch INT GPIO%d hook failed: %s", static_cast<int>(kInterruptPin), esp_err_to_name(err));
172
+ #endif
115
173
  return err;
116
174
  }
117
175
 
@@ -155,7 +213,13 @@ void TouchController::pollLoop()
155
213
  int slotY[kMaxFingers] = {0, 0};
156
214
 
157
215
  while (true) {
216
+ #if GEA_BOARD_TOUCH_CST9220
217
+ const bool anyActive = slotActive[0] || slotActive[1];
218
+ if (ulTaskNotifyTake(pdTRUE, anyActive ? pdMS_TO_TICKS(kLiftTimeoutMs) : portMAX_DELAY) == 0 && !anyActive)
219
+ continue;
220
+ #else
158
221
  vTaskDelay(pdMS_TO_TICKS(kPollIntervalMs));
222
+ #endif
159
223
 
160
224
  const MultiSample multi = readMulti();
161
225
  if (multi.count > 0) {
@@ -1,4 +1,5 @@
1
1
  #include "display.h"
2
+ #include "render_worker_join.h"
2
3
 
3
4
  #include "board.h"
4
5
  #include "canvas.h"
@@ -27,6 +28,8 @@
27
28
  #endif
28
29
  #include "esp_err.h"
29
30
  #include "esp_heap_caps.h"
31
+ // esp_ptr_external_ram/esp_ptr_dma_capable; reached transitively on Xtensa only.
32
+ #include "esp_memory_utils.h"
30
33
  #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG && CONFIG_HEAP_TRACING_STANDALONE
31
34
  #include "esp_attr.h"
32
35
  #include "esp_heap_trace.h"
@@ -5261,6 +5264,16 @@ extern "C" std::uint16_t *gea_bg_cache(int *cap_px)
5261
5264
  return buffer;
5262
5265
  }
5263
5266
 
5267
+ // The S3's PIE vector unit is Xtensa-only. On every other chip these kernels
5268
+ // are absent and render.cpp's weak fallbacks report them unavailable, so the
5269
+ // renderer takes its scalar paths.
5270
+ #if CONFIG_IDF_TARGET_ESP32S3
5271
+ #define GEA_DISPLAY_HAS_PIE 1
5272
+ #else
5273
+ #define GEA_DISPLAY_HAS_PIE 0
5274
+ #endif
5275
+
5276
+ #if GEA_DISPLAY_HAS_PIE
5264
5277
  // ── PIE/SIMD throughput probe ──────────────────────────────────────────────
5265
5278
  // Decisive question before investing in a full RGB565 blend kernel: does the S3
5266
5279
  // PIE actually deliver multiply-add throughput over a PSRAM buffer (the per-pixel
@@ -5394,6 +5407,7 @@ static void pieBlendSpan8(std::uint16_t *dst, const std::uint16_t *fgN, const st
5394
5407
  : [cb] "r"(cb2)
5395
5408
  : "memory");
5396
5409
  }
5410
+ #endif // GEA_DISPLAY_HAS_PIE
5397
5411
 
5398
5412
  // ── face-drawer hooks (consumed by render.cpp via weak symbols) ──────────────
5399
5413
  // The PIE vector regs aren't preserved across FreeRTOS context switches, so a
@@ -5430,6 +5444,7 @@ extern "C" void *gea_render_fast_scratch(int bytes, int align)
5430
5444
  return p;
5431
5445
  }
5432
5446
 
5447
+ #if GEA_DISPLAY_HAS_PIE
5433
5448
  extern "C" bool gea_pie_blend_available() { return true; }
5434
5449
  extern "C" void gea_pie_blend_span8(std::uint16_t *dst, const std::uint16_t *fgN, const std::int16_t *a5, int count8)
5435
5450
  {
@@ -5835,6 +5850,7 @@ extern "C" void gea_pie_bench()
5835
5850
  heap_caps_free(b);
5836
5851
  heap_caps_free(ref);
5837
5852
  }
5853
+ #endif // GEA_DISPLAY_HAS_PIE
5838
5854
 
5839
5855
  // Full-screen PSRAM scratch for the static-backdrop cache (bg gradient + stage +
5840
5856
  // dithered floor baked once). Separate from gea_bg_cache so the Phase-1 gradient
@@ -6038,25 +6054,20 @@ extern "C" void gea_render_parallel_wait()
6038
6054
  {
6039
6055
  if (!g_geaRenderWorker.task)
6040
6056
  return;
6041
- // The worker's band is sub-millisecond; spin (the render core's idle task only
6042
- // needs to run within the ~5s watchdog window, so a short spin is fine). The
6043
- // esp_timer deadline guards against a wedged worker so we can never hang.
6057
+ // Keep the borrowed band context alive until completion, including when
6058
+ // higher-priority audio work delays the worker beyond the slow-job threshold.
6044
6059
  const std::int64_t w0 = esp_timer_get_time();
6045
- const std::int64_t deadline = w0 + 100000; // 100ms safety net
6046
- while (!g_geaRenderWorker.done.load(std::memory_order_acquire))
6047
- {
6060
+ gea::platform::esp32::display::detail::joinRenderWorker(g_geaRenderWorker.done,
6061
+ [] {
6048
6062
  #if defined(GEA_EMBEDDED_APP_USES_AUDIO) && GEA_EMBEDDED_APP_USES_AUDIO
6049
- // Media load makes a band much longer than the graphics-only spin window.
6050
- // Its worker already notifies completion: park instead of burning CPU0
6051
- // while the microphone encoder and idle task need to run.
6052
- ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(2));
6053
- #endif
6054
- if (esp_timer_get_time() > deadline)
6055
- {
6056
- std::printf("[render-worker] WAIT TIMEOUT — worker wedged?\n");
6057
- break;
6058
- }
6059
- }
6063
+ ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(2));
6064
+ #endif
6065
+ },
6066
+ [] { return esp_timer_get_time(); },
6067
+ [](std::int64_t elapsed, bool stuck) {
6068
+ std::printf("[render-worker] WAIT %s after %lld us; job still pending\n",
6069
+ stuck ? "STUCK" : "SLOW", static_cast<long long>(elapsed));
6070
+ });
6060
6071
  const std::int64_t waitThis = esp_timer_get_time() - w0;
6061
6072
  g_wkWaitUs += waitThis;
6062
6073
  // Adaptive row-share controller (visual-neutral: only shifts WHICH rows each core
@@ -6093,21 +6104,13 @@ extern "C" void gea_render_parallel_wait_blocking()
6093
6104
  {
6094
6105
  if (!g_geaRenderWorker.task)
6095
6106
  return;
6096
- // Unlike the spin wait above, PARK the caller (yield the core) until the worker
6097
- // finishes — so a lower-priority task sharing this core (the app frame task,
6098
- // pinned to core 0 alongside the gea3d present) runs during the chunk raster
6099
- // instead of the present spinning it away. The worker notifyGives us on done;
6100
- // the short timeout re-checks in case the notify landed before we parked.
6101
- const std::int64_t deadline = esp_timer_get_time() + 100000; // 100ms safety net
6102
- while (!g_geaRenderWorker.done.load(std::memory_order_acquire))
6103
- {
6104
- ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(2));
6105
- if (esp_timer_get_time() > deadline)
6106
- {
6107
- std::printf("[render-worker] BLOCKING WAIT TIMEOUT — worker wedged?\n");
6108
- break;
6109
- }
6110
- }
6107
+ gea::platform::esp32::display::detail::joinRenderWorker(g_geaRenderWorker.done,
6108
+ [] { ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(2)); },
6109
+ [] { return esp_timer_get_time(); },
6110
+ [](std::int64_t elapsed, bool stuck) {
6111
+ std::printf("[render-worker] BLOCKING WAIT %s after %lld us; job still pending\n",
6112
+ stuck ? "STUCK" : "SLOW", static_cast<long long>(elapsed));
6113
+ });
6111
6114
  }
6112
6115
 
6113
6116
  // Adaptive main-core row share for the 2-core replay split (overrides the renderer's
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <atomic>
4
+ #include <cstdint>
5
+ #include <cstdlib>
6
+
7
+ namespace gea::platform::esp32::display::detail {
8
+
9
+ // A submitted raster job borrows its caller's stack and framebuffer. A slow
10
+ // worker cannot be abandoned: returning would release both while it still draws.
11
+ template <typename Park, typename Clock, typename Report>
12
+ void joinRenderWorker(const std::atomic<bool> &done, Park park, Clock now, Report report) {
13
+ const std::int64_t started = now();
14
+ bool reportedSlow = false;
15
+ while (!done.load(std::memory_order_acquire)) {
16
+ park();
17
+ const std::int64_t elapsed = now() - started;
18
+ if (done.load(std::memory_order_acquire))
19
+ break;
20
+ if (elapsed >= 5000000) {
21
+ report(elapsed, true);
22
+ // A genuinely stuck worker must stop the app, never return a live job.
23
+ std::abort();
24
+ }
25
+ if (!reportedSlow && elapsed >= 100000) {
26
+ report(elapsed, false);
27
+ reportedSlow = true;
28
+ }
29
+ }
30
+ }
31
+
32
+ } // namespace gea::platform::esp32::display::detail
@@ -61,6 +61,15 @@ extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
61
61
  #include <sys/stat.h> // ::mkdir for GEADEV PUSH parent dirs
62
62
  #include <sys/time.h>
63
63
  #include "esp_system.h" // esp_restart() for GEADEV REBOOT
64
+ #if CONFIG_IDF_TARGET_ESP32P4
65
+ #include "soc/lp_system_reg.h" // FORCE_DOWNLOAD_BOOT for GEADEV DOWNLOAD
66
+ #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
67
+ #include "soc/rtc_cntl_reg.h" // FORCE_DOWNLOAD_BOOT for GEADEV DOWNLOAD
68
+ #endif
69
+ #if GEA_DEVICE_CONTROL_USB_OTA
70
+ #include "esp_ota_ops.h" // GEADEV OTA
71
+ #include <algorithm>
72
+ #endif
64
73
  #include "audio.h" // gea::platform::audio::AudioSystem for GEADEV PLAYFILE
65
74
  #include "power.h" // Power::batteryPercent() for STATE battery
66
75
  #include "host/notify.h" // gea::host::postNotification() for GEADEV NOTIFY
@@ -1291,6 +1300,7 @@ void handlePush(char *args)
1291
1300
  while (got < size) {
1292
1301
  const std::size_t n = std::fread(mem + got, 1, static_cast<std::size_t>(size - got), stdin);
1293
1302
  if (n == 0) {
1303
+ std::clearerr(stdin); // an idle read sets the sticky EOF flag
1294
1304
  if (++stalls > 20000) { // ~40s of silence → abort
1295
1305
  ioError = true;
1296
1306
  break;
@@ -1321,6 +1331,98 @@ void handlePush(char *args)
1321
1331
  std::printf("GEADEV:PUSH OK path=%s bytes=%ld crc=0x%08x\n", path, size, static_cast<unsigned>(finalCrc));
1322
1332
  }
1323
1333
 
1334
+ // ── GEADEV OTA: install a new app image over the USB console ─────────────────
1335
+ // The PUSH transfer, written to the next OTA slot instead of a file:
1336
+ // GEADEV OTA <size> <crc32>\n
1337
+ // then exactly <size> raw bytes. The image is drained into PSRAM first (the
1338
+ // console has no flow control, so flash erases must not stall the read),
1339
+ // checked against the CRC, written with esp_ota_*, selected for boot, and the
1340
+ // board restarts into it. This is how a board whose USB port is not a ROM
1341
+ // console -- the ESP32-S31's OTG port -- is flashed without the BOOT button.
1342
+ // Compiled only for boards that ask for it (GEA_DEVICE_CONTROL_USB_OTA).
1343
+ #if GEA_DEVICE_CONTROL_USB_OTA
1344
+ void handleOta(char *args)
1345
+ {
1346
+ char *sizeTok = nextToken(args);
1347
+ char *crcTok = nextToken(args);
1348
+ if (!sizeTok || !crcTok) {
1349
+ std::printf("GEADEV:OTA ERR usage=GEADEV_OTA_size_crc32\n");
1350
+ return;
1351
+ }
1352
+ char *end = nullptr;
1353
+ const long size = std::strtol(sizeTok, &end, 10);
1354
+ if (!end || *end != '\0' || size <= 0) {
1355
+ std::printf("GEADEV:OTA ERR bad-size\n");
1356
+ return;
1357
+ }
1358
+ const std::uint32_t expectCrc = static_cast<std::uint32_t>(std::strtoul(crcTok, nullptr, 0));
1359
+ const esp_partition_t *slot = esp_ota_get_next_update_partition(nullptr);
1360
+ if (!slot) {
1361
+ std::printf("GEADEV:OTA ERR no-ota-slot\n");
1362
+ return;
1363
+ }
1364
+ if (static_cast<std::size_t>(size) > slot->size) {
1365
+ std::printf("GEADEV:OTA ERR too-large bytes=%ld slot=%u\n", size, static_cast<unsigned>(slot->size));
1366
+ return;
1367
+ }
1368
+ auto *mem = static_cast<std::uint8_t *>(heap_caps_malloc(static_cast<std::size_t>(size), MALLOC_CAP_SPIRAM));
1369
+ if (!mem) {
1370
+ std::printf("GEADEV:OTA ERR no-memory bytes=%ld\n", size);
1371
+ return;
1372
+ }
1373
+ std::printf("GEADEV:OTA READY slot=%s bytes=%ld\n", slot->label, size);
1374
+ std::fflush(stdout);
1375
+
1376
+ long got = 0;
1377
+ int stalls = 0;
1378
+ while (got < size) {
1379
+ const std::size_t n = std::fread(mem + got, 1, static_cast<std::size_t>(size - got), stdin);
1380
+ if (n == 0) {
1381
+ std::clearerr(stdin); // an idle read sets the sticky EOF flag
1382
+ if (++stalls > 5000) break; // ~10s of silence
1383
+ vTaskDelay(pdMS_TO_TICKS(2));
1384
+ continue;
1385
+ }
1386
+ stalls = 0;
1387
+ got += static_cast<long>(n);
1388
+ }
1389
+ if (got != size) {
1390
+ heap_caps_free(mem);
1391
+ std::printf("GEADEV:OTA ERR transfer-failed got=%ld\n", got);
1392
+ return;
1393
+ }
1394
+ const std::uint32_t crc = crc32Stream(0xFFFFFFFFu, mem, static_cast<std::size_t>(size)) ^ 0xFFFFFFFFu;
1395
+ if (crc != expectCrc) {
1396
+ heap_caps_free(mem);
1397
+ std::printf("GEADEV:OTA ERR crc-mismatch got=0x%08x want=0x%08x\n",
1398
+ static_cast<unsigned>(crc), static_cast<unsigned>(expectCrc));
1399
+ return;
1400
+ }
1401
+
1402
+ esp_ota_handle_t handle = 0;
1403
+ esp_err_t err = esp_ota_begin(slot, static_cast<std::size_t>(size), &handle);
1404
+ if (err == ESP_OK) {
1405
+ constexpr std::size_t kChunk = 64 * 1024;
1406
+ for (long offset = 0; offset < size && err == ESP_OK; offset += static_cast<long>(kChunk)) {
1407
+ const std::size_t n = std::min<std::size_t>(kChunk, static_cast<std::size_t>(size - offset));
1408
+ err = esp_ota_write(handle, mem + offset, n);
1409
+ }
1410
+ const esp_err_t ended = esp_ota_end(handle);
1411
+ if (err == ESP_OK) err = ended;
1412
+ }
1413
+ heap_caps_free(mem);
1414
+ if (err == ESP_OK) err = esp_ota_set_boot_partition(slot);
1415
+ if (err != ESP_OK) {
1416
+ std::printf("GEADEV:OTA ERR write-failed slot=%s err=%s\n", slot->label, esp_err_to_name(err));
1417
+ return;
1418
+ }
1419
+ std::printf("GEADEV:OTA OK slot=%s bytes=%ld crc=0x%08x\n", slot->label, size, static_cast<unsigned>(crc));
1420
+ std::fflush(stdout);
1421
+ vTaskDelay(pdMS_TO_TICKS(200)); // let the reply reach the host before the reset
1422
+ esp_restart();
1423
+ }
1424
+ #endif // GEA_DEVICE_CONTROL_USB_OTA
1425
+
1324
1426
  void handlePushBase64(char *args)
1325
1427
  {
1326
1428
  char *pathTok = nextToken(args);
@@ -1866,6 +1968,25 @@ void handleCommand(char *line, CommandSource source)
1866
1968
  handleNode(cursor);
1867
1969
  } else if (tokenEquals(command, "HITTEST")) {
1868
1970
  handleHitTest(cursor);
1971
+ } else if (tokenEquals(command, "DOWNLOAD")) {
1972
+ // Restart into ROM download mode, so a host can flash over a UART bridge
1973
+ // whose DTR/RTS lines cannot reset the chip (e.g. the Waveshare P4 LCD-3.5).
1974
+ // The flag survives a watchdog reset; the flasher clears it before resetting.
1975
+ #if CONFIG_IDF_TARGET_ESP32P4
1976
+ std::printf("GEADEV:OK DOWNLOAD\n");
1977
+ std::fflush(stdout);
1978
+ vTaskDelay(pdMS_TO_TICKS(120));
1979
+ REG_SET_BIT(LP_SYSTEM_REG_SYS_CTRL_REG, LP_SYSTEM_REG_FORCE_DOWNLOAD_BOOT);
1980
+ esp_restart();
1981
+ #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
1982
+ std::printf("GEADEV:OK DOWNLOAD\n");
1983
+ std::fflush(stdout);
1984
+ vTaskDelay(pdMS_TO_TICKS(120));
1985
+ REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
1986
+ esp_restart();
1987
+ #else
1988
+ std::printf("GEADEV:ERR DOWNLOAD unsupported-chip\n");
1989
+ #endif
1869
1990
  } else if (tokenEquals(command, "REBOOT")) {
1870
1991
  // Soft-reboot the device. Lets the Mac companion apply a face change
1871
1992
  // (SETDEFAULT writes NVS; the new default only takes effect on boot).
@@ -1882,6 +2003,11 @@ void handleCommand(char *line, CommandSource source)
1882
2003
  } else if (tokenEquals(command, "PUSH")) {
1883
2004
  if (source == CommandSource::Stdio) handlePush(cursor);
1884
2005
  else std::printf("GEADEV:PUSH ERR unsupported-on-usb-direct\n");
2006
+ #if GEA_DEVICE_CONTROL_USB_OTA
2007
+ } else if (tokenEquals(command, "OTA")) {
2008
+ if (source == CommandSource::Stdio) handleOta(cursor);
2009
+ else std::printf("GEADEV:OTA ERR unsupported-on-usb-direct\n");
2010
+ #endif
1885
2011
  } else if (tokenEquals(command, "PUSH64")) {
1886
2012
  if (source == CommandSource::Stdio) handlePushBase64(cursor);
1887
2013
  else std::printf("GEADEV:PUSH64 ERR unsupported-on-usb-direct\n");
@@ -2035,6 +2161,10 @@ public:
2035
2161
  CommandLineAccumulator parser(CommandSource::Stdio);
2036
2162
  while (true) {
2037
2163
  if (!std::fgets(readBuffer, sizeof(readBuffer), stdin)) {
2164
+ // A console whose read returns 0 when idle (the TinyUSB CDC VFS)
2165
+ // sets stdin's end-of-file flag, and that flag is sticky: every
2166
+ // later fgets fails at once until it is cleared.
2167
+ std::clearerr(stdin);
2038
2168
  vTaskDelay(pdMS_TO_TICKS(50));
2039
2169
  continue;
2040
2170
  }
@@ -307,7 +307,9 @@ set(GEATSC_COMPILE_OPTIONS
307
307
  -Wno-dangling-reference
308
308
  -Wno-dangling-pointer
309
309
  -${GEA_BUILD_COMPILER_GENERATED_CODE_OPTIMIZATION}
310
- -mtext-section-literals
310
+ # Xtensa only (gea_framework.cmake); a RISC-V board on this base (the
311
+ # ESP32-S31 Mosaico) has no such option and gcc refuses the whole archive.
312
+ ${GEA_XTENSA_LITERALS}
311
313
  )
312
314
  set(GEATSC_COMPILE_DEFINITIONS "")
313
315
  if(NOT CMAKE_SCRIPT_MODE_FILE)
@@ -499,6 +501,8 @@ idf_component_register(
499
501
  esp_netif
500
502
  esp_event
501
503
  nvs_flash
504
+ # storage_service.cpp mounts the storage partition (esp_spiffs.h).
505
+ spiffs
502
506
  esp_lcd
503
507
  driver
504
508
  esp_driver_i2c
@@ -653,6 +657,9 @@ add_custom_command(
653
657
  --font-device-pixel-ratio ${GEA_EMBEDDED_CSS_DEVICE_PIXEL_RATIO}
654
658
  --pixel-panel-endian 1
655
659
  --gea-ir-backend
660
+ # Stylesheet registration becomes a function app_main calls, not a
661
+ # static constructor on the small pre-FreeRTOS startup stack.
662
+ --cpp-prelude-symbol gea_plugin_cpp_register_prelude
656
663
  # gea.compilerPlugins: an app's own geatsc plugins, e.g. the one that
657
664
  # declares its native host-function boundary. Empty for most apps.
658
665
  ${GEA_EMBEDDED_APP_GEATSC_PLUGIN_ARGS}