@geastack/targets 0.1.82 → 0.1.84

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.
package/README.md CHANGED
@@ -68,6 +68,30 @@ See the `tutorials` repository's
68
68
  `embedded-tutorials/02-custom-board-composition` course for a complete target
69
69
  definition and firmware build.
70
70
 
71
+ ## ES8311 audio duplex mode
72
+
73
+ The ESP32 ES8311 binding defaults to half duplex. Applications can opt into
74
+ simultaneous capture and playback with `"GEA_AUDIO_FULL_DUPLEX=1"` in their
75
+ `gea.defines` array. Removing the define restores the default; it is not a
76
+ board-wide setting. On the AMOLED 2.06, capture uses its separate ES7210 ADC.
77
+
78
+ In full duplex, opening either direction preserves the other. RX uses 20 ms
79
+ blocks and does not hold the TX write lock while waiting for samples. Both
80
+ directions must use the same sample rate because they share I2S clocks; a
81
+ conflicting open fails without closing the existing stream. Capture is 16 kHz,
82
+ so simultaneous playback must also be 16 kHz. Closing playback leaves capture
83
+ running, and audio resources are released once neither direction uses them.
84
+
85
+ The driver exposes raw microphone audio; this option does not add acoustic
86
+ echo cancellation. Applications using a loudspeaker must provide their own
87
+ echo processing if required. Default half-duplex capture keeps its existing
88
+ 2048-sample blocks and playback arbitration.
89
+
90
+ `node targets/esp32/test/audio-full-duplex.test.mjs` compiles the production
91
+ open/capture methods in both modes, checks clock conflicts, and verifies that
92
+ a blocked RX read permits TX progress only in the opted-in mode. Its executable
93
+ uses the board's existing ignored `build/` directory.
94
+
71
95
  ## License
72
96
 
73
97
  This repo is the GeaStack **embedded board support** (ESP32, RP2350) and is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/targets",
3
- "version": "0.1.82",
3
+ "version": "0.1.84",
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": {
@@ -36,15 +36,16 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@geastack/chips": "^0.1.4",
39
- "@geastack/compiler": "^1.0.15",
40
- "@geastack/core": "^0.1.24",
41
- "@geastack/elements": "^0.1.2",
42
- "@geastack/engine": "^0.1.5",
39
+ "@geastack/compiler": "^1.0.19",
40
+ "@geastack/core": "^0.1.30",
41
+ "@geastack/elements": "^0.1.3",
42
+ "@geastack/engine": "^0.1.8",
43
43
  "@geastack/geaos": "^0.1.3",
44
- "@geastack/geatsc-plugin-gea": "^0.1.6",
45
- "@geastack/host": "^0.1.8"
44
+ "@geastack/geatsc-plugin-gea": "^0.1.11",
45
+ "@geastack/host": "^0.1.9"
46
46
  },
47
47
  "scripts": {
48
48
  "test": "for f in $(git ls-files | grep -E '(^|/)(test[-_][^/]*|[^/]*\\.test)\\.mjs$'); do echo \"==> $f\"; node \"$f\" || exit 1; done"
49
- }
49
+ },
50
+ "gitHead": "10230ddd9bec0287a8705c8e1f96fb06a063c845"
50
51
  }
@@ -23,10 +23,15 @@
23
23
 
24
24
  #include "host/media.h"
25
25
 
26
- // AFE (acoustic echo cancellation) integration deferred — esp-sr 2.4.4's API
27
- // requires afe_config_init("MR", models, AFE_TYPE_VC, AFE_MODE_LOW_COST) and
28
- // esp_afe_handle_from_config(). Phase 5.0 ships raw mic mix; AEC is a Phase 5.1
29
- // follow-up once the basic call flow is on-device verified.
26
+ // Full duplex is an app opt-in. Both directions share a clock, so a live
27
+ // capture stream cannot coexist with playback at a different sample rate.
28
+ #ifndef GEA_AUDIO_FULL_DUPLEX
29
+ #define GEA_AUDIO_FULL_DUPLEX 0
30
+ #endif
31
+ static_assert(GEA_AUDIO_FULL_DUPLEX == 0 || GEA_AUDIO_FULL_DUPLEX == 1);
32
+
33
+ // Capture is raw microphone PCM. Full duplex does not imply acoustic echo
34
+ // cancellation; the application must supply any required echo processing.
30
35
 
31
36
  namespace gea::platform::esp32::chip_bindings::es8311 {
32
37
 
@@ -42,6 +47,18 @@ constexpr gpio_num_t kDinPin = gea::platform::board::audio.din;
42
47
  constexpr gpio_num_t kPaPin = gea::platform::board::audio.powerAmplifier;
43
48
  constexpr int kCodecDataPort = 0;
44
49
 
50
+ // Boards whose microphones sit on an ES7210 ADC sharing this I2S bus (Waveshare AMOLED 2.06) name its
51
+ // 7-bit I2C address as `audio.es7210Address`; everywhere else the ES8311's own ADC records.
52
+ template <typename AudioConfig>
53
+ constexpr int micAdcAddressOf(const AudioConfig &audio) {
54
+ if constexpr (requires { audio.es7210Address; }) {
55
+ return audio.es7210Address;
56
+ } else {
57
+ return 0;
58
+ }
59
+ }
60
+ constexpr int kMicAdcAddress = micAdcAddressOf(gea::platform::board::audio);
61
+
45
62
  class AudioOutputDriver {
46
63
  public:
47
64
  static AudioOutputDriver &instance() {
@@ -54,6 +71,7 @@ public:
54
71
 
55
72
  bool open(int sampleRate, int channels, int bitsPerSample) {
56
73
  std::lock_guard<std::mutex> lock(writeMutex_);
74
+ std::lock_guard<std::mutex> captureLock(readMutex_);
57
75
  const gea::chips::es8311::OutputFormat format(sampleRate, channels, bitsPerSample);
58
76
  if (!format.isPcm16()) return false;
59
77
 
@@ -65,7 +83,11 @@ public:
65
83
  return true;
66
84
  }
67
85
 
68
- if (recordOpen_) closeRecorderLocked();
86
+ if constexpr (GEA_AUDIO_FULL_DUPLEX) {
87
+ if (recordOpen_ && i2sSampleRate_ != sampleRate) return false;
88
+ } else {
89
+ if (recordOpen_) closeRecorderLocked();
90
+ }
69
91
  if (speakerOpen_) closeSpeakerLocked();
70
92
 
71
93
  const esp_err_t initErr = initSpeaker(sampleRate);
@@ -104,9 +126,12 @@ public:
104
126
 
105
127
  bool write(const std::int16_t *pcm, std::size_t sampleCount, int timeoutMs) {
106
128
  (void)timeoutMs;
107
- if (!speakerCodec_ || !speakerOpen_ || !pcm || sampleCount == 0) return false;
129
+ if (!pcm || sampleCount == 0) return false;
108
130
 
131
+ // Checked under the lock, so idle-capture cleanup cannot delete the codec between check and write.
109
132
  std::lock_guard<std::mutex> lock(writeMutex_);
133
+ if (!speakerCodec_ || !speakerOpen_) return false;
134
+
110
135
  auto *cursor = reinterpret_cast<const std::uint8_t *>(pcm);
111
136
  std::size_t remaining = sampleCount * sizeof(std::int16_t);
112
137
  while (remaining > 0) {
@@ -127,7 +152,10 @@ public:
127
152
 
128
153
  void close() {
129
154
  std::lock_guard<std::mutex> lock(writeMutex_);
155
+ std::lock_guard<std::mutex> captureLock(readMutex_);
130
156
  closeSpeakerLocked();
157
+ // An idle capture task leaves the audio path up while the speaker plays; free it once neither uses it.
158
+ if (!micInUse()) releaseAudioLocked();
131
159
  }
132
160
 
133
161
  int volume() const {
@@ -218,6 +246,26 @@ private:
218
246
  i2sDataIf_ = nullptr;
219
247
  }
220
248
 
249
+ // Frees everything the audio path holds in internal RAM: the codec devices, the I2S data
250
+ // interface, and both I2S channels with their DMA buffers. A recording app that also uses the
251
+ // network needs this RAM back once the mic stops (esp_wifi_init fails with ESP_ERR_NO_MEM
252
+ // otherwise). initCodecDevice() rebuilds it all on the next open. Call with writeMutex_ held.
253
+ void releaseAudioLocked() {
254
+ closeRecorderLocked();
255
+ closeSpeakerLocked();
256
+ if (speakerCodec_) {
257
+ esp_codec_dev_delete(speakerCodec_);
258
+ speakerCodec_ = nullptr;
259
+ }
260
+ if (recordCodec_) {
261
+ esp_codec_dev_delete(recordCodec_);
262
+ recordCodec_ = nullptr;
263
+ }
264
+ if (i2sDataIf_) audio_codec_delete_data_if(i2sDataIf_);
265
+ releaseI2s();
266
+ i2sSampleRate_ = 0;
267
+ }
268
+
221
269
  esp_err_t initI2s(int sampleRate) {
222
270
  if (txChannel_ && i2sDataIf_) {
223
271
  if (i2sSampleRate_ == sampleRate) return ESP_OK;
@@ -240,6 +288,8 @@ private:
240
288
  return err;
241
289
  }
242
290
 
291
+ // esp_codec_dev_open() reconfigures each channel's slots to Philips I2S (the format the ES8311 and
292
+ // ES7210 use) before any data moves, so this initial slot format is only a placeholder.
243
293
  i2s_std_config_t stdConfig = {};
244
294
  stdConfig.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(static_cast<std::uint32_t>(sampleRate));
245
295
  stdConfig.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_STEREO);
@@ -338,8 +388,13 @@ private:
338
388
 
339
389
  esp_err_t initRecorder(int sampleRate) {
340
390
  if (recordOpen_ && i2sSampleRate_ == sampleRate) return ESP_OK;
391
+ if constexpr (GEA_AUDIO_FULL_DUPLEX) {
392
+ if (speakerOpen_ && speakerSampleRate_ != sampleRate) return ESP_ERR_NOT_SUPPORTED;
393
+ }
341
394
  if (recordOpen_) closeRecorderLocked();
342
- if (speakerOpen_) closeSpeakerLocked();
395
+ if constexpr (!GEA_AUDIO_FULL_DUPLEX) {
396
+ if (speakerOpen_) closeSpeakerLocked();
397
+ }
343
398
 
344
399
  esp_err_t err = initCodecDevice(sampleRate, ESP_CODEC_DEV_TYPE_IN, recordCodec_);
345
400
  if (err != ESP_OK) return err;
@@ -416,6 +471,10 @@ private:
416
471
  esp_codec_dev_cfg_t codecConfig = {};
417
472
  codecConfig.dev_type = deviceType;
418
473
  codecConfig.codec_if = codecIf_;
474
+ if (deviceType == ESP_CODEC_DEV_TYPE_IN && kMicAdcAddress != 0) {
475
+ codecConfig.codec_if = micAdcIf();
476
+ if (!codecConfig.codec_if) return ESP_ERR_NO_MEM;
477
+ }
419
478
  codecConfig.data_if = i2sDataIf_;
420
479
  device = esp_codec_dev_new(&codecConfig);
421
480
  if (!device) return ESP_ERR_NO_MEM;
@@ -423,6 +482,32 @@ private:
423
482
  return ESP_OK;
424
483
  }
425
484
 
485
+ // The ES7210 codec interface, created on first use: slave mode on the shared bus, mics 1 and 2 as
486
+ // the stereo pair (the capture task keeps mic 1).
487
+ const audio_codec_if_t *micAdcIf() {
488
+ if (micAdcIf_) return micAdcIf_;
489
+
490
+ auto i2cBus = gea::platform::i2c::Bus::primary();
491
+ audio_codec_i2c_cfg_t i2cConfig = {};
492
+ i2cConfig.addr = static_cast<std::uint8_t>(kMicAdcAddress << 1);
493
+ i2cConfig.bus_handle = static_cast<i2c_master_bus_handle_t>(i2cBus.nativeHandle());
494
+ micAdcCtrlIf_ = audio_codec_new_i2c_ctrl(&i2cConfig);
495
+ if (!micAdcCtrlIf_) return nullptr;
496
+
497
+ es7210_codec_cfg_t es7210Config = {};
498
+ es7210Config.ctrl_if = micAdcCtrlIf_;
499
+ es7210Config.master_mode = false;
500
+ es7210Config.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2;
501
+ es7210Config.mclk_src = ES7210_MCLK_FROM_PAD;
502
+ es7210Config.mclk_div = 256;
503
+ micAdcIf_ = es7210_codec_new(&es7210Config);
504
+ if (!micAdcIf_) {
505
+ audio_codec_delete_ctrl_if(micAdcCtrlIf_);
506
+ micAdcCtrlIf_ = nullptr;
507
+ }
508
+ return micAdcIf_;
509
+ }
510
+
426
511
  static constexpr const char *kTag = "audio";
427
512
 
428
513
  i2s_chan_handle_t txChannel_ = nullptr;
@@ -431,6 +516,8 @@ private:
431
516
  const audio_codec_ctrl_if_t *i2cCtrlIf_ = nullptr;
432
517
  const audio_codec_gpio_if_t *gpioIf_ = nullptr;
433
518
  const audio_codec_if_t *codecIf_ = nullptr;
519
+ const audio_codec_ctrl_if_t *micAdcCtrlIf_ = nullptr;
520
+ const audio_codec_if_t *micAdcIf_ = nullptr;
434
521
  esp_codec_dev_handle_t speakerCodec_ = nullptr;
435
522
  esp_codec_dev_handle_t recordCodec_ = nullptr;
436
523
  bool i2sChannelEnabled_ = false;
@@ -442,16 +529,24 @@ private:
442
529
  int speakerChannels_ = 0;
443
530
  int speakerBitsPerSample_ = 0;
444
531
  int speakerVolume_ = 100;
532
+ // Configuration/destruction takes write then read. A duplex read releases
533
+ // write before blocking on RX, allowing TX to run at the same time.
445
534
  std::mutex writeMutex_;
535
+ std::mutex readMutex_;
446
536
 
447
537
  TaskHandle_t captureTask_ = nullptr;
448
538
  std::vector<gea::host::NativeMediaTrackHandle> attachedTracks_;
449
539
  std::vector<gea::host::NativeMediaTrackHandle> captureSnapshot_;
450
540
  std::mutex attachedMutex_;
451
- static constexpr std::size_t kCaptureFrameSamples = 2048;
541
+ static constexpr std::size_t kCaptureFrameSamples = GEA_AUDIO_FULL_DUPLEX ? 320 : 2048;
452
542
  std::array<std::int16_t, kCaptureFrameSamples * 2> stereoFrame_{};
453
543
  std::array<std::int16_t, kCaptureFrameSamples> monoFrame_{};
454
544
 
545
+ bool micInUse() {
546
+ std::lock_guard<std::mutex> lock(attachedMutex_);
547
+ return !attachedTracks_.empty();
548
+ }
549
+
455
550
  static void captureTaskTrampoline(void *arg) {
456
551
  static_cast<AudioOutputDriver *>(arg)->runCaptureTask();
457
552
  }
@@ -460,25 +555,39 @@ private:
460
555
  int consecutiveReadErrors = 0;
461
556
 
462
557
  while (true) {
558
+ bool idle = false;
463
559
  {
464
560
  std::lock_guard<std::mutex> lock(attachedMutex_);
465
561
  captureSnapshot_ = attachedTracks_;
562
+ idle = captureSnapshot_.empty();
563
+ // Cleared under the same lock attachTrack() checks, so a track attached from here on
564
+ // starts a fresh capture task instead of relying on this one.
565
+ if (idle) captureTask_ = nullptr;
466
566
  }
467
567
 
468
- if (captureSnapshot_.empty()) {
568
+ // The last track detached: close the mic and, unless the speaker is still playing, free the
569
+ // I2S channels and codec devices, then end this task so its stack is freed too.
570
+ if (idle) {
469
571
  {
470
572
  std::lock_guard<std::mutex> lock(writeMutex_);
471
- closeRecorderLocked();
573
+ std::lock_guard<std::mutex> captureLock(readMutex_);
574
+ // A track attached since the check started a new capture task, which now owns the audio path.
575
+ if (!micInUse()) {
576
+ closeRecorderLocked();
577
+ if (!speakerOpen_) releaseAudioLocked();
578
+ }
472
579
  }
473
- vTaskDelay(pdMS_TO_TICKS(50));
474
- continue;
580
+ vTaskDelete(nullptr);
581
+ return;
475
582
  }
476
583
 
477
584
  int err = ESP_OK;
478
585
  {
479
- std::lock_guard<std::mutex> lock(writeMutex_);
586
+ std::unique_lock<std::mutex> lock(writeMutex_);
587
+ std::lock_guard<std::mutex> captureLock(readMutex_);
480
588
  err = initRecorder(16000);
481
589
  if (err == ESP_OK && recordCodec_) {
590
+ if constexpr (GEA_AUDIO_FULL_DUPLEX) lock.unlock();
482
591
  err = esp_codec_dev_read(recordCodec_, stereoFrame_.data(), stereoFrame_.size() * sizeof(std::int16_t));
483
592
  }
484
593
  }
@@ -506,10 +615,9 @@ private:
506
615
 
507
616
  public:
508
617
  void attachTrack(gea::host::NativeMediaTrackHandle handle) {
509
- {
510
- std::lock_guard<std::mutex> lock(attachedMutex_);
511
- attachedTracks_.push_back(handle);
512
- }
618
+ std::lock_guard<std::mutex> lock(attachedMutex_);
619
+ attachedTracks_.push_back(handle);
620
+ // Checked and set under the lock the capture task clears it with, so only one capture task runs.
513
621
  if (captureTask_ == nullptr) {
514
622
  xTaskCreatePinnedToCore(captureTaskTrampoline, "gea_mic", 8192, this, 5, &captureTask_, 1);
515
623
  }
@@ -41,6 +41,7 @@
41
41
  #include "freertos/task.h"
42
42
  #include "freertos/idf_additions.h"
43
43
  #include "ui/state_init.h"
44
+ #include "ui/dirty_regions.h"
44
45
 
45
46
  #if GEA_BOARD_PREPARE_DISPLAY_PANEL
46
47
  namespace gea::platform::board
@@ -267,12 +268,13 @@ namespace gea::platform::esp32::display
267
268
  constexpr std::uint16_t kConsoleBackground = pixel::fromRgb565(0x0000);
268
269
  constexpr int kFlushChunkDefault = GEA_EMBEDDED_DISPLAY_FLUSH_CHUNK_MAX;
269
270
  constexpr int kFlushChunkLimit = GEA_EMBEDDED_DISPLAY_FLUSH_CHUNK_LIMIT;
270
- // One scanline is the final correctness-preserving fallback. Normal builds
271
- // still start at the board's requested chunk/depth and only descend this far
272
- // when radios and recovery services leave a few KiB of DMA heap. A radio-heavy
273
- // AMOLED build reached the old 4-row floor with only 48 bytes free; allowing a
274
- // 1-row, 820-byte strip keeps the UI alive instead of parking the runtime.
275
- constexpr int kFlushChunkMin = 1;
271
+ // Preserve the even-row windows used by the QSPI AMOLED path, including
272
+ // under Wi-Fi memory pressure. CO5300 and RM69080/RM690B0 reject one-row
273
+ // windows. Aligning only the outer dirty rectangle is insufficient: every
274
+ // independently addressed DMA chunk must also contain an even row count.
275
+ // Two rows, one-deep is the smallest safe fallback (1640 bytes at 410 px).
276
+ constexpr int kFlushChunkMin = 2;
277
+ static_assert(kFlushChunkLimit >= kFlushChunkMin, "flush limit is below the panel minimum");
276
278
  // Leave enough DMA-capable internal RAM for the WiFi driver to receive a
277
279
  // packet after the display pipeline is allocated. On the 2.06-inch S3 board,
278
280
  // accepting a 1-row, 2-deep pipeline consumed all but 80 bytes and made the
@@ -1015,6 +1017,7 @@ namespace gea::platform::esp32::display
1015
1017
  #endif
1016
1018
  const int colCount = colEnd - colStart + 1;
1017
1019
 
1020
+ #if !GEA_EMBEDDED_RM690B0_PANEL
1018
1021
  // Program one full-scanline window for the entire native row band. Color
1019
1022
  // chunks continue with RAMWRC, avoiding repeated CASET/RASET while keeping
1020
1023
  // every command strictly serialized with the preceding DMA.
@@ -1030,6 +1033,8 @@ namespace gea::platform::esp32::display
1030
1033
  return false;
1031
1034
  }
1032
1035
 
1036
+ #endif
1037
+
1033
1038
  // Rows per chunk come from what the staging slot HOLDS, not from a row count
1034
1039
  // fixed for full-width transfers. A narrowed window makes each row colCount
1035
1040
  // pixels instead of nativeWidth, so the same buffer takes proportionally more
@@ -1044,7 +1049,9 @@ namespace gea::platform::esp32::display
1044
1049
  if (colCount <= 0)
1045
1050
  return flushChunkRows_;
1046
1051
  const int fits = flushBufferCapacity_ / colCount;
1047
- return fits < 1 ? 1 : fits;
1052
+ // Narrow windows can fit an odd number of native rows. Keep every
1053
+ // independently addressed RM69080 chunk aligned, including the tail.
1054
+ return fits < kFlushChunkMin ? kFlushChunkMin : fits - fits % kFlushChunkMin;
1048
1055
  }();
1049
1056
 
1050
1057
  auto rowsAt = [&](int row)
@@ -1105,7 +1112,9 @@ namespace gea::platform::esp32::display
1105
1112
  std::uint16_t *prefetchedBuffer = nullptr;
1106
1113
  int prefetchedRow = -1;
1107
1114
  int prefetchedRows = 0;
1115
+ #if !GEA_EMBEDDED_RM690B0_PANEL
1108
1116
  bool firstChunk = true;
1117
+ #endif
1109
1118
  for (int physicalRow = physicalY0; physicalRow <= physicalY1;)
1110
1119
  {
1111
1120
  const int rows = rowsAt(physicalRow);
@@ -1148,10 +1157,17 @@ namespace gea::platform::esp32::display
1148
1157
 
1149
1158
  setFlushStage(FlushStage::Tx, physicalRow);
1150
1159
  const int64_t txStartUs = esp_timer_get_time();
1160
+ #if GEA_EMBEDDED_RM690B0_PANEL
1161
+ // This panel needs a fresh window per chunk. drawBitmap also applies
1162
+ // the panel's column gap, which raw setWindow/txColor bypasses.
1163
+ const esp_err_t err = panel().drawBitmap(
1164
+ colStart, physicalRow, colEnd + 1, physicalRow + rows, buffer);
1165
+ #else
1151
1166
  const esp_err_t err = panel().txColor(
1152
1167
  firstChunk ? LCD_CMD_RAMWR : LCD_CMD_RAMWRC,
1153
1168
  buffer,
1154
1169
  static_cast<std::size_t>(pixelCount) * sizeof(std::uint16_t));
1170
+ #endif
1155
1171
  flushStats_.txUs += esp_timer_get_time() - txStartUs;
1156
1172
  flushStats_.chunkCount++;
1157
1173
  if (err != ESP_OK)
@@ -1161,7 +1177,9 @@ namespace gea::platform::esp32::display
1161
1177
  setFlushStage(FlushStage::Idle, 0);
1162
1178
  return false;
1163
1179
  }
1180
+ #if !GEA_EMBEDDED_RM690B0_PANEL
1164
1181
  firstChunk = false;
1182
+ #endif
1165
1183
 
1166
1184
  // While this chunk streams from internal DMA RAM, pull the next native
1167
1185
  // rows out of PSRAM into the other staging slot. We still wait before
@@ -1291,6 +1309,15 @@ namespace gea::platform::esp32::display
1291
1309
  const int width = x1 - x0 + 1;
1292
1310
  const int totalRows = y1 - y0 + 1;
1293
1311
 
1312
+ #if GEA_EMBEDDED_RM690B0_PANEL && !GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_CS_HELD_STREAM && \
1313
+ !GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_STREAM_FLUSH && !GEA_EMBEDDED_DISPLAY_CO5300_STREAM_FLUSH
1314
+ // Keep separate panel windows, but rasterize the alternate slot while
1315
+ // the previous band transmits. A pending resize must drain first.
1316
+ const bool deferEntryDrain = raster && flushQueueDepth_ > 1 && !g_flushBudgetDirty;
1317
+ #else
1318
+ constexpr bool deferEntryDrain = false;
1319
+ #endif
1320
+
1294
1321
  // Drain any tail DMA left in flight by a prior flushFramebufferRectFrom
1295
1322
  // that returned with waitAtEnd=false. Cheap (semaphore takes return
1296
1323
  // immediately) when nothing is pending. Must run before setWindow so
@@ -1299,7 +1326,7 @@ namespace gea::platform::esp32::display
1299
1326
  // rect — that's what capped the fused path at 35fps.
1300
1327
  setFlushStage(FlushStage::WaitComplete, 0);
1301
1328
  const int64_t entryWaitStartUs = esp_timer_get_time();
1302
- if (!waitForFlushCompleteSpin())
1329
+ if (!deferEntryDrain && !waitForFlushCompleteSpin())
1303
1330
  {
1304
1331
  setFlushStage(FlushStage::Idle, 0);
1305
1332
  return false;
@@ -1379,12 +1406,21 @@ namespace gea::platform::esp32::display
1379
1406
  #endif
1380
1407
 
1381
1408
  #if (GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_STREAM_FLUSH || GEA_EMBEDDED_DISPLAY_CO5300_STREAM_FLUSH) && \
1409
+ !GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_CS_HELD_STREAM && \
1382
1410
  GEA_EMBEDDED_DISPLAY_CO5300_STREAM_PACE_CHUNKS > 0
1383
1411
  int streamChunksSincePace = 0;
1384
1412
  #endif
1385
- for (int row = y0; row <= y1; row += flushChunkRows_)
1413
+ // Partial-width windows fit more rows in the same DMA slot. Preserve
1414
+ // the app's requested row limit and the panel's two-row alignment.
1415
+ const int packedChunkRows = [&] {
1416
+ const int fits = flushBufferCapacity_ / width;
1417
+ const int requested = normalizeFlushChunkRows(requestedFlushChunkRows_);
1418
+ const int rows = fits < requested ? fits : requested;
1419
+ return rows - rows % kFlushChunkMin;
1420
+ }();
1421
+ for (int row = y0; row <= y1; row += packedChunkRows)
1386
1422
  {
1387
- int chunkRows = flushChunkRows_;
1423
+ int chunkRows = packedChunkRows;
1388
1424
  if (row + chunkRows > y1 + 1)
1389
1425
  chunkRows = y1 - row + 1;
1390
1426
  if (chunkRows <= 0)
@@ -1446,6 +1482,21 @@ namespace gea::platform::esp32::display
1446
1482
  flushStats_.byteSwapUs += esp_timer_get_time() - byteSwapStartUs;
1447
1483
  #endif
1448
1484
 
1485
+ if (deferEntryDrain)
1486
+ {
1487
+ // This slot is reserved but not submitted. Only earlier submissions
1488
+ // must finish before this band's CASET/RASET/RAMWR can be issued.
1489
+ const int64_t pendingStartUs = esp_timer_get_time();
1490
+ if (!waitForFlushCompleteSpin(4000, 1))
1491
+ {
1492
+ xSemaphoreGive(flushSlots_);
1493
+ setFlushStage(FlushStage::Idle, 0);
1494
+ return false;
1495
+ }
1496
+ const int64_t waitUs = esp_timer_get_time() - pendingStartUs;
1497
+ flushStats_.completeWaitUs += waitUs;
1498
+ flushStats_.chunkWaitUs += waitUs;
1499
+ }
1449
1500
  const int64_t txStartUs = esp_timer_get_time();
1450
1501
  setFlushStage(FlushStage::Tx, row);
1451
1502
  #if GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_CS_HELD_STREAM
@@ -1491,6 +1542,7 @@ namespace gea::platform::esp32::display
1491
1542
  }
1492
1543
 
1493
1544
  #if (GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_STREAM_FLUSH || GEA_EMBEDDED_DISPLAY_CO5300_STREAM_FLUSH) && \
1545
+ !GEA_EMBEDDED_DISPLAY_CO5300_FRAMEBUFFER_CS_HELD_STREAM && \
1494
1546
  GEA_EMBEDDED_DISPLAY_CO5300_STREAM_PACE_CHUNKS > 0
1495
1547
  if (streamFlush)
1496
1548
  {
@@ -1563,7 +1615,10 @@ namespace gea::platform::esp32::display
1563
1615
  // panel — verified on-device 2026-07-08).
1564
1616
  setFlushStage(FlushStage::WaitComplete, y1);
1565
1617
  const int64_t waitStartUs = esp_timer_get_time();
1566
- const bool ok = waitForFlushCompleteSpin();
1618
+ // Two 64-row DMA chunks can exceed 2 ms at 80 MHz QSPI.
1619
+ // Match the slot-wait budget so a normal tail does not fall back to
1620
+ // a scheduler wakeup just before DMA completes.
1621
+ const bool ok = waitForFlushCompleteSpin(4000);
1567
1622
  closeCsHeldStream();
1568
1623
  flushStats_.completeWaitUs += esp_timer_get_time() - waitStartUs;
1569
1624
  setFlushStage(FlushStage::Idle, 0);
@@ -1725,7 +1780,7 @@ namespace gea::platform::esp32::display
1725
1780
  // overlap; flushing each separately re-sends that overlap every frame
1726
1781
  // (~2.5x pixel inflation). Merging flushes each pixel once. Pad-then-coalesce,
1727
1782
  // not coalesce-then-pad, so the pad participates in the merge.
1728
- constexpr int kFlushMergeCap = 32; // == DirtyRegions::kMaxRects
1783
+ constexpr int kFlushMergeCap = gea::embedded::ui::DirtyRegions::kMaxRects;
1729
1784
  present::Rect win[kFlushMergeCap];
1730
1785
  int n = 0;
1731
1786
  for (int i = 0; i < count; i++)
@@ -1763,7 +1818,7 @@ namespace gea::platform::esp32::display
1763
1818
  else if (n > 0)
1764
1819
  win[n - 1] = present::unite(win[n - 1], w); // overflow: fold into last
1765
1820
  }
1766
- // Greedy merge of overlapping windows until stable (n <= 32, cheap).
1821
+ // Greedy merge of overlapping windows until stable.
1767
1822
  bool changed = true;
1768
1823
  while (changed)
1769
1824
  {
@@ -2127,6 +2182,14 @@ namespace gea::platform::esp32::display
2127
2182
  int y0 = y;
2128
2183
  int x1 = x + w - 1;
2129
2184
  int y1 = y + h - 1;
2185
+ #if GEA_EMBEDDED_RM690B0_PANEL
2186
+ const auto aligned = present::clampAndAlign(
2187
+ {x0, y0, x1, y1}, platform_display::kWidth, platform_display::kHeight);
2188
+ x0 = aligned.x0;
2189
+ y0 = aligned.y0;
2190
+ x1 = aligned.x1;
2191
+ y1 = aligned.y1;
2192
+ #endif
2130
2193
  if (x0 < 0)
2131
2194
  x0 = 0;
2132
2195
  if (y0 < 0)
@@ -2539,7 +2602,7 @@ namespace gea::platform::esp32::display
2539
2602
  }
2540
2603
 
2541
2604
  // Then grow to the board's profile immediately, instead of leaving that to
2542
- // start(). The floor above is a 1-row, 1-DEEP pipeline, and 1-deep is not
2605
+ // start(). The floor above is a 2-row, 1-DEEP pipeline, and 1-deep is not
2543
2606
  // merely slower: it disables the color-stream path (which requires depth >= 2)
2544
2607
  // and the rotated flush then times out waiting for a slot, so the panel paints
2545
2608
  // NOTHING while the pipeline sits there. An app whose own native bring-up
@@ -3008,6 +3071,7 @@ namespace gea::platform::esp32::display
3008
3071
  rows = kFlushChunkMin;
3009
3072
  if (rows > kFlushChunkLimit)
3010
3073
  rows = kFlushChunkLimit;
3074
+ rows &= ~1;
3011
3075
  return rows;
3012
3076
  }
3013
3077
 
@@ -3070,13 +3134,13 @@ namespace gea::platform::esp32::display
3070
3134
  return true;
3071
3135
  }
3072
3136
 
3073
- bool waitForFlushComplete()
3137
+ bool waitForFlushComplete(int reservedSlots = 0)
3074
3138
  {
3075
- if (!flushSlots_ || flushQueueDepth_ <= 0)
3139
+ if (!flushSlots_ || flushQueueDepth_ <= reservedSlots)
3076
3140
  return true;
3077
3141
 
3078
3142
  int taken = 0;
3079
- for (int i = 0; i < flushQueueDepth_; i++)
3143
+ for (int i = 0; i < flushQueueDepth_ - reservedSlots; i++)
3080
3144
  {
3081
3145
  if (xSemaphoreTake(flushSlots_, pdMS_TO_TICKS(1000)) != pdTRUE)
3082
3146
  {
@@ -3099,17 +3163,17 @@ namespace gea::platform::esp32::display
3099
3163
  // tiny tail DMAs this drain waits on (a few chunks), polling returns within the real
3100
3164
  // ~35-150us completion time. The blocking fallback keeps the cross-core safety net
3101
3165
  // for an unexpectedly long drain without spinning a core indefinitely.
3102
- bool waitForFlushCompleteSpin(int64_t spinBudgetUs = 2000)
3166
+ bool waitForFlushCompleteSpin(int64_t spinBudgetUs = 2000, int reservedSlots = 0)
3103
3167
  {
3104
- if (!flushSlots_ || flushQueueDepth_ <= 0)
3168
+ if (!flushSlots_ || flushQueueDepth_ <= reservedSlots)
3105
3169
  return true;
3106
3170
  const int64_t start = esp_timer_get_time();
3107
3171
  while (esp_timer_get_time() - start < spinBudgetUs)
3108
3172
  {
3109
- if (uxSemaphoreGetCount(flushSlots_) >= static_cast<UBaseType_t>(flushQueueDepth_))
3173
+ if (uxSemaphoreGetCount(flushSlots_) >= static_cast<UBaseType_t>(flushQueueDepth_ - reservedSlots))
3110
3174
  return true;
3111
3175
  }
3112
- return waitForFlushComplete();
3176
+ return waitForFlushComplete(reservedSlots);
3113
3177
  }
3114
3178
 
3115
3179
  esp_err_t tryConfigureFlushPipelineCandidate(int chunkRows, int depth, int targetRows, int targetDepth)
@@ -132,6 +132,13 @@ if(COMMAND idf_build_set_property)
132
132
  idf_build_set_property(COMPILE_DEFINITIONS "${_GEA_APP_DEFINE}" APPEND)
133
133
  endif()
134
134
  endforeach()
135
+ # The runtime sizes its allocation pools for a board when GEA_EMBEDDED_CPP_BOARD is defined
136
+ # (gea_runtime.h: 16 KiB chunks instead of the desktop's 2 MiB). geatsc v1 defined it from
137
+ # `--cpp-board`; the current compiler reports that option as unhonored, so every ESP32 build lost
138
+ # it and pooled freed memory in 2 MiB chunks that are never returned. Every build through this
139
+ # file is a board, and the runtime only tests that the macro is defined, so it is set here for
140
+ # the whole build: the app, main and the framework must agree on the pool layout.
141
+ idf_build_set_property(COMPILE_DEFINITIONS "GEA_EMBEDDED_CPP_BOARD" APPEND)
135
142
  endif()
136
143
 
137
144
  # Linker fragments are absolute paths from the CLI. ldgen merges every
@@ -24,6 +24,13 @@
24
24
  #define GEA_EMBEDDED_GEA_INIT_TASK_STACK_BYTES 65536
25
25
  #endif
26
26
 
27
+ // A task that uses floating point can be pinned implicitly by FreeRTOS. Apps
28
+ // with asymmetric real-time work can choose an initialization core explicitly
29
+ // so first-use scheduling does not change startup latency between boots.
30
+ #ifndef GEA_EMBEDDED_GEA_INIT_TASK_CORE
31
+ #define GEA_EMBEDDED_GEA_INIT_TASK_CORE -1
32
+ #endif
33
+
27
34
  #ifndef GEA_EMBEDDED_APP_FRAME_TASK_STACK_WORDS
28
35
  #define GEA_EMBEDDED_APP_FRAME_TASK_STACK_WORDS 3072
29
36
  #endif
@@ -29,6 +29,11 @@ namespace {
29
29
  constexpr const char *kTag = "gea_esp32_app";
30
30
 
31
31
  constexpr int kGeaAppInitTaskStack = GEA_EMBEDDED_GEA_INIT_TASK_STACK_BYTES;
32
+ static_assert(GEA_EMBEDDED_GEA_INIT_TASK_CORE >= -1 &&
33
+ GEA_EMBEDDED_GEA_INIT_TASK_CORE < portNUM_PROCESSORS,
34
+ "Gea initialization core must be -1 or an available CPU");
35
+ constexpr BaseType_t kGeaAppInitTaskCore = GEA_EMBEDDED_GEA_INIT_TASK_CORE < 0
36
+ ? tskNO_AFFINITY : GEA_EMBEDDED_GEA_INIT_TASK_CORE;
32
37
 
33
38
  #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG && CONFIG_HEAP_TRACING_STANDALONE
34
39
  constexpr std::size_t kAppInitHeapTraceRecords = 1024;
@@ -108,11 +113,13 @@ void logCurrentTaskStack(const char *stage, int stackBytes)
108
113
  {
109
114
  TaskHandle_t currentTask = xTaskGetCurrentTaskHandle();
110
115
  ESP_LOGI(kTag,
111
- "stack probe [%s] task=%s stack_arg=%d hwm=%u",
116
+ "stack probe [%s] task=%s stack_arg=%d hwm=%u core=%d affinity=%d",
112
117
  stage ? stage : "?",
113
118
  currentTask ? pcTaskGetName(currentTask) : "?",
114
119
  stackBytes,
115
- static_cast<unsigned>(uxTaskGetStackHighWaterMark(currentTask)));
120
+ static_cast<unsigned>(uxTaskGetStackHighWaterMark(currentTask)),
121
+ xPortGetCoreID(),
122
+ static_cast<int>(xTaskGetCoreID(currentTask)));
116
123
  }
117
124
  #endif
118
125
 
@@ -200,24 +207,26 @@ bool runGeaInitTask(int width, int height)
200
207
  // only touched by FreeRTOS context save/restore (word-aligned) and user
201
208
  // code (via cache, which doesn't care about cap flags), so dropping the
202
209
  // 8BIT requirement here is safe.
203
- created = xTaskCreateWithCaps(
210
+ created = xTaskCreatePinnedToCoreWithCaps(
204
211
  &GeaInitTask::run,
205
212
  "gea_init",
206
213
  kGeaAppInitTaskStack,
207
214
  &args,
208
215
  5,
209
216
  &task,
217
+ kGeaAppInitTaskCore,
210
218
  MALLOC_CAP_SPIRAM);
211
219
  ESP_LOGI("app_runner", "gea_init SPIRAM create: %s", created == pdPASS ? "ok" : "FAIL");
212
220
  #endif
213
221
  if (created != pdPASS) {
214
- created = xTaskCreateWithCaps(
222
+ created = xTaskCreatePinnedToCoreWithCaps(
215
223
  &GeaInitTask::run,
216
224
  "gea_init",
217
225
  kGeaAppInitTaskStack,
218
226
  &args,
219
227
  5,
220
228
  &task,
229
+ kGeaAppInitTaskCore,
221
230
  MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
222
231
  ESP_LOGI("app_runner", "gea_init INTERNAL create: %s", created == pdPASS ? "ok" : "FAIL");
223
232
  }
@@ -16,12 +16,22 @@
16
16
  #include "ui/tree_internal.h"
17
17
  #include "ui/virtual_keyboard.h"
18
18
 
19
+ #if defined(GEA_EMBEDDED_SHARED_STYLES) && GEA_EMBEDDED_SHARED_STYLES
20
+ #define GEA_DIAGNOSTIC_NODE_STYLE(node) ((node).computedStyle())
21
+ #else
22
+ #define GEA_DIAGNOSTIC_NODE_STYLE(node) ((node).style)
23
+ #endif
24
+
19
25
  #include "driver/i2c_master.h"
20
26
  #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
21
27
  #include "driver/usb_serial_jtag.h"
22
28
  #include "driver/usb_serial_jtag_vfs.h"
23
29
  #endif
24
30
  #include "esp_heap_caps.h"
31
+ #if CONFIG_HEAP_TRACING_STANDALONE
32
+ #include "esp_heap_trace.h"
33
+ #include "esp_memory_utils.h"
34
+ #endif
25
35
  #include "platform/file_cache.h" // gea::platform::storage::ensureMounted for GEADEV PUSH
26
36
  #include "esp_log.h"
27
37
  #include "esp_err.h"
@@ -50,6 +60,11 @@
50
60
  #include "host/backends.h" // WifiBackend for GEADEV WIFI
51
61
  #include "host/storage.h" // gea::host::Storage for GEADEV STORAGE SET
52
62
 
63
+ // Older engines expose all four direct position fields.
64
+ #ifndef GEA_CSS_POSITION_PX
65
+ #define GEA_CSS_POSITION_PX(style, side) ((style).pos_offsets[side])
66
+ #endif
67
+
53
68
  namespace gea::platform::esp32::services {
54
69
 
55
70
  namespace {
@@ -756,22 +771,22 @@ void handleNode(char *&cursor)
756
771
  nodeId,
757
772
  node.parent,
758
773
  static_cast<int>(node.type),
759
- node.style.display,
760
- node.style.width,
761
- node.style.height,
762
- node.style.min_width,
763
- node.style.min_height,
764
- node.style.max_width,
765
- node.style.max_height,
766
- node.style.pos_offsets[3],
767
- node.style.pos_offsets[0],
768
- node.style.pos_offsets[1],
769
- node.style.pos_offsets[2],
770
- gea::embedded::ui::rstyle(node.style).transform_translate_x,
771
- gea::embedded::ui::rstyle(node.style).transform_translate_y,
772
- gea::embedded::ui::rstyle(node.style).transform_translate_x_percent,
773
- gea::embedded::ui::rstyle(node.style).transform_translate_y_percent,
774
- gea::embedded::ui::rstyle(node.style).transform_rotate,
774
+ GEA_DIAGNOSTIC_NODE_STYLE(node).display,
775
+ GEA_DIAGNOSTIC_NODE_STYLE(node).width,
776
+ GEA_DIAGNOSTIC_NODE_STYLE(node).height,
777
+ GEA_DIAGNOSTIC_NODE_STYLE(node).min_width,
778
+ GEA_DIAGNOSTIC_NODE_STYLE(node).min_height,
779
+ GEA_DIAGNOSTIC_NODE_STYLE(node).max_width,
780
+ GEA_DIAGNOSTIC_NODE_STYLE(node).max_height,
781
+ GEA_CSS_POSITION_PX(GEA_DIAGNOSTIC_NODE_STYLE(node), 3),
782
+ GEA_CSS_POSITION_PX(GEA_DIAGNOSTIC_NODE_STYLE(node), 0),
783
+ GEA_CSS_POSITION_PX(GEA_DIAGNOSTIC_NODE_STYLE(node), 1),
784
+ GEA_CSS_POSITION_PX(GEA_DIAGNOSTIC_NODE_STYLE(node), 2),
785
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_x,
786
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_y,
787
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_x_percent,
788
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_y_percent,
789
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_rotate,
775
790
  node.layout.x,
776
791
  node.layout.y,
777
792
  node.layout.width,
@@ -784,9 +799,9 @@ void handleNode(char *&cursor)
784
799
  ys[2],
785
800
  xs[3],
786
801
  ys[3],
787
- static_cast<int>(node.style.overflow),
788
- static_cast<int>(node.style.overflow_x),
789
- static_cast<int>(node.style.overflow_y),
802
+ static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).overflow),
803
+ static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).overflow_x),
804
+ static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).overflow_y),
790
805
  static_cast<int>(node.layout.scroll_x),
791
806
  static_cast<int>(node.layout.scroll_y),
792
807
  static_cast<int>(node.layout.scroll_content_width),
@@ -825,15 +840,15 @@ void handleHitTest(char *&cursor)
825
840
  nodeId,
826
841
  node.parent,
827
842
  static_cast<int>(node.type),
828
- node.style.display,
843
+ GEA_DIAGNOSTIC_NODE_STYLE(node).display,
829
844
  classes.c_str(),
830
845
  pressTarget,
831
846
  pressId,
832
- gea::embedded::ui::rstyle(node.style).transform_translate_x,
833
- gea::embedded::ui::rstyle(node.style).transform_translate_y,
834
- gea::embedded::ui::rstyle(node.style).transform_translate_x_percent,
835
- gea::embedded::ui::rstyle(node.style).transform_translate_y_percent,
836
- gea::embedded::ui::rstyle(node.style).transform_rotate,
847
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_x,
848
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_y,
849
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_x_percent,
850
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_translate_y_percent,
851
+ gea::embedded::ui::rstyle(GEA_DIAGNOSTIC_NODE_STYLE(node)).transform_rotate,
837
852
  node.layout.x,
838
853
  node.layout.y,
839
854
  node.layout.width,
@@ -1529,6 +1544,46 @@ void handleCommand(char *line, CommandSource source)
1529
1544
  appId ? appId : "",
1530
1545
  intTotal - intFree, intFree, intTotal, intLargest, intMinFree,
1531
1546
  psramTotal - psramFree, psramFree, psramTotal, psramLargest);
1547
+ } else if (tokenEquals(command, "HEAPTRACE")) {
1548
+ #if CONFIG_HEAP_TRACING_STANDALONE
1549
+ // Allocate records only on demand, outside internal DMA RAM. Emit
1550
+ // addresses/sizes/stacks, never allocation contents or credentials.
1551
+ static heap_trace_record_t *records = nullptr;
1552
+ constexpr size_t recordCount = 4096;
1553
+ char *action = nextToken(cursor);
1554
+ if (action && tokenEquals(action, "START")) {
1555
+ if (!records) {
1556
+ records = static_cast<heap_trace_record_t *>(heap_caps_calloc(recordCount, sizeof(heap_trace_record_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
1557
+ if (!records) { std::printf("GEADEV:ERR HEAPTRACE no-memory\n"); return; }
1558
+ const esp_err_t init = heap_trace_init_standalone(records, recordCount);
1559
+ if (init != ESP_OK) {
1560
+ heap_caps_free(records); records = nullptr;
1561
+ std::printf("GEADEV:ERR HEAPTRACE init=%s\n", esp_err_to_name(init)); return;
1562
+ }
1563
+ }
1564
+ const esp_err_t start = heap_trace_start(HEAP_TRACE_LEAKS);
1565
+ std::printf("GEADEV:HEAPTRACE START result=%s\n", esp_err_to_name(start));
1566
+ } else if (action && tokenEquals(action, "STOP") && records) {
1567
+ const esp_err_t stop = heap_trace_stop();
1568
+ if (stop != ESP_OK) { std::printf("GEADEV:ERR HEAPTRACE stop=%s\n", esp_err_to_name(stop)); return; }
1569
+ heap_trace_summary_t summary{};
1570
+ heap_trace_summary(&summary);
1571
+ std::printf("GEADEV:HEAPTRACE SUMMARY count=%u capacity=%u high_water=%u overflow=%u\n",
1572
+ unsigned(summary.count), unsigned(summary.capacity), unsigned(summary.high_water_mark), unsigned(summary.has_overflowed));
1573
+ for (size_t i = 0; i < heap_trace_get_count(); ++i) {
1574
+ heap_trace_record_t record{};
1575
+ if (heap_trace_get(i, &record) != ESP_OK || record.freed) continue;
1576
+ std::printf("GEADEV:HEAPTRACE RECORD bytes=%u region=%s address=%p stack=",
1577
+ unsigned(record.size), esp_ptr_internal(record.address) ? "internal" : "external", record.address);
1578
+ for (int j = 0; j < CONFIG_HEAP_TRACING_STACK_DEPTH; ++j) std::printf("%s%p", j ? "," : "", record.alloced_by[j]);
1579
+ std::printf("\n");
1580
+ }
1581
+ if (heap_trace_init_standalone(nullptr, 0) == ESP_OK) { heap_caps_free(records); records = nullptr; }
1582
+ std::printf("GEADEV:HEAPTRACE END\n");
1583
+ } else std::printf("GEADEV:ERR HEAPTRACE usage=START_or_STOP\n");
1584
+ #else
1585
+ std::printf("GEADEV:ERR HEAPTRACE standalone-tracing-not-enabled\n");
1586
+ #endif
1532
1587
  } else if (tokenEquals(command, "CANVASSTATS")) {
1533
1588
  int tBegin = 0, tEnd = 0, tFillRect = 0, tDrawImage = 0, tNullPx = 0, tPresentOk = 0;
1534
1589
  gea::embedded::ui::canvasTotalsRead(&tBegin, &tEnd, &tFillRect, &tDrawImage, &tNullPx, &tPresentOk);
@@ -1546,8 +1601,8 @@ void handleCommand(char *line, CommandSource source)
1546
1601
  if (kb >= 0 && kb < tree.nodeCount()) {
1547
1602
  const auto &node = tree.node(kb);
1548
1603
  std::printf("GEADEV:KBINFO kb=%d active=%d parent=%d display=%d layout=%d,%d %dx%d styleTop=%d styleW=%d styleH=%d\n",
1549
- kb, active, node.parent, node.style.display, node.layout.x, node.layout.y,
1550
- node.layout.width, node.layout.height, node.style.pos_offsets[0], node.style.width, node.style.height);
1604
+ kb, active, node.parent, GEA_DIAGNOSTIC_NODE_STYLE(node).display, node.layout.x, node.layout.y,
1605
+ node.layout.width, node.layout.height, GEA_CSS_POSITION_PX(GEA_DIAGNOSTIC_NODE_STYLE(node), 0), GEA_DIAGNOSTIC_NODE_STYLE(node).width, GEA_DIAGNOSTIC_NODE_STYLE(node).height);
1551
1606
  } else {
1552
1607
  std::printf("GEADEV:KBINFO kb=%d active=%d\n", kb, active);
1553
1608
  }
@@ -21,6 +21,114 @@
21
21
  #include "freertos/queue.h"
22
22
  #include "freertos/task.h"
23
23
 
24
+ #if defined(GEA_EMBEDDED_FRAME_BENCHMARK) && GEA_EMBEDDED_FRAME_BENCHMARK
25
+ extern "C" void gea_frame_benchmark_sample(int64_t start, int64_t done);
26
+ #if GEA_EMBEDDED_FRAME_BENCHMARK == 2
27
+ // Called at the end of the real target frame, including the display flush.
28
+ // Warm up for 300 frames, collect 3600 frames, then log once outside the sample.
29
+ #include <cstdint>
30
+ #include "esp_attr.h"
31
+ #include "esp_heap_caps.h"
32
+ #include "esp_log.h"
33
+ #include "ui/node_model.h"
34
+ #include "ui/tree_state.h"
35
+ #include "ui/internal.h"
36
+
37
+ namespace {
38
+ constexpr unsigned kWarmup = 300;
39
+ constexpr unsigned kSamples = 3600;
40
+ constexpr unsigned kBins = 1024;
41
+ constexpr unsigned kBinUs = 250;
42
+ struct Distribution {
43
+ std::uint32_t bins[kBins]{};
44
+ std::int64_t sum{};
45
+ std::int64_t maximum{};
46
+ unsigned over_budget{};
47
+ void add(std::int64_t value) {
48
+ sum += value;
49
+ if (value > maximum)
50
+ maximum = value;
51
+ if (value > 16667)
52
+ ++over_budget;
53
+ const auto bin = static_cast<unsigned>(value / kBinUs);
54
+ ++bins[bin < kBins ? bin : kBins - 1];
55
+ }
56
+ unsigned percentile(unsigned percent) const {
57
+ unsigned count = 0;
58
+ for (unsigned i = 0; i < kBins; ++i) {
59
+ count += bins[i];
60
+ if (count * 100 >= kSamples * percent)
61
+ return (i + 1) * kBinUs;
62
+ }
63
+ return kBins * kBinUs;
64
+ }
65
+ };
66
+ EXT_RAM_BSS_ATTR Distribution work;
67
+ EXT_RAM_BSS_ATTR Distribution cadence;
68
+ unsigned frames{};
69
+ std::int64_t previous_done{};
70
+ } // namespace
71
+
72
+ extern "C" void gea_frame_benchmark_sample(std::int64_t start, std::int64_t done) {
73
+ ++frames;
74
+ if (frames > kWarmup && frames <= kWarmup + kSamples) {
75
+ work.add(done - start);
76
+ cadence.add(done - previous_done);
77
+ }
78
+ previous_done = done;
79
+ if (frames != kWarmup + kSamples + 1)
80
+ return;
81
+ unsigned shared = 0, records = 0, payload = 0, heapBytes = 0, staticBytes = 0;
82
+ #if defined(GEA_EMBEDDED_SHARED_STYLES) && GEA_EMBEDDED_SHARED_STYLES
83
+ shared = 1;
84
+ records = unsigned(gea::embedded::ui::NodeStyleStorage::allocatedRecords());
85
+ payload = unsigned(gea::embedded::ui::NodeStyleStorage::allocatedBytes());
86
+ heapBytes = unsigned(gea::embedded::ui::NodeStyleStorage::allocatedHeapBytes());
87
+ staticBytes = unsigned(sizeof(gea::embedded::ui::SharedStyleRecord) + sizeof(void *) + sizeof(std::size_t));
88
+ #endif
89
+ ESP_LOGI("ui_bench", "STORAGE shared=%u nodes=%u capacity=%u tree_bytes=%u node_array_bytes=%u "
90
+ "records=%u record_payload=%u record_heap=%u record_static=%u "
91
+ "memo_active=%u memo_peak_heap=%u memo_static=%u "
92
+ "layout_aux_payload=%u layout_aux_heap=%u layout_aux_allocs=%u "
93
+ "layout_aux_peak=%u layout_aux_peak_allocs=%u layout_aux_static=%u",
94
+ shared, unsigned(gea::embedded::ui::treeState().nodeCount), unsigned(gea::embedded::ui::kMaxNodes),
95
+ unsigned(sizeof(gea::embedded::ui::TreeState)),
96
+ unsigned(sizeof(gea::embedded::ui::Node) * gea::embedded::ui::kMaxNodes),
97
+ records, payload, heapBytes, staticBytes,
98
+ unsigned(gea::embedded::ui::LayoutEngine::memoStorageBytes()),
99
+ unsigned(gea::embedded::ui::LayoutEngine::memoPeakHeapBytes()),
100
+ unsigned(sizeof(void *) + sizeof(std::size_t) + sizeof(int)),
101
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutStorageBytes()),
102
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutHeapBytes()),
103
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutAllocationCount()),
104
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutPeakBytes()),
105
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutPeakAllocations()),
106
+ unsigned(gea::embedded::ui::LayoutEngine::persistentLayoutStaticBytes()));
107
+ const auto owned = gea::embedded::ui::nodeAuxiliaryStorageUsage();
108
+ const auto logOwned = [](const char *group, const gea::embedded::ui::StorageUsage &usage) {
109
+ ESP_LOGI("ui_bench", "OWNED group=%s payload=%u heap=%u allocs=%u static=%u untracked=%u",
110
+ group, unsigned(usage.payload), unsigned(usage.heap), unsigned(usage.allocations),
111
+ unsigned(usage.staticBytes), unsigned(usage.untrackedOwners));
112
+ };
113
+ logOwned("tree", owned.tree); logOwned("text", owned.text);
114
+ logOwned("rare", owned.rare); logOwned("overrides", owned.overrides);
115
+ logOwned("dependencies", owned.dependencies);
116
+ ESP_LOGI("ui_bench",
117
+ "RESULT frames=%u warmup=%u done_total=%lld node=%u style=%u work_avg=%lld work_p99_le=%u work_max=%lld "
118
+ "work_over16667=%u done_avg=%lld done_p99_le=%u done_max=%lld done_over16667=%u "
119
+ "fps_milli=%lld psram_free=%u internal_free=%u",
120
+ kSamples, kWarmup, cadence.sum, unsigned(sizeof(gea::embedded::ui::Node)),
121
+ unsigned(sizeof(gea::embedded::ui::ComputedStyle)), work.sum / kSamples,
122
+ work.percentile(99), work.maximum, work.over_budget, cadence.sum / kSamples,
123
+ cadence.percentile(99), cadence.maximum, cadence.over_budget,
124
+ 1000000000LL * kSamples / cadence.sum,
125
+ unsigned(heap_caps_get_free_size(MALLOC_CAP_SPIRAM)),
126
+ unsigned(heap_caps_get_free_size(MALLOC_CAP_INTERNAL)));
127
+ }
128
+
129
+ #endif
130
+ #endif
131
+
24
132
  namespace gea::framework::services {
25
133
 
26
134
  namespace {
@@ -59,8 +167,10 @@ constexpr int kTaskCore = GEA_EMBEDDED_APP_FRAME_TASK_CORE;
59
167
  #define GEA_EMBEDDED_FRAME_SCHEDULER_IDLE_YIELD_TICKS 1
60
168
  #endif
61
169
 
170
+ // Bound sustained catch-up so idle housekeeping still runs when display DMA
171
+ // completes without blocking the frame task. Boards may override this cadence.
62
172
  #ifndef GEA_EMBEDDED_FRAME_SCHEDULER_MAX_CATCHUP_FRAMES_BEFORE_YIELD
63
- #define GEA_EMBEDDED_FRAME_SCHEDULER_MAX_CATCHUP_FRAMES_BEFORE_YIELD 0
173
+ #define GEA_EMBEDDED_FRAME_SCHEDULER_MAX_CATCHUP_FRAMES_BEFORE_YIELD 32
64
174
  #endif
65
175
 
66
176
  #ifndef GEA_EMBEDDED_FRAME_SCHEDULER_USE_ESP_TIMER
@@ -465,6 +575,9 @@ public:
465
575
  frameInProgress_.store(false, std::memory_order_release);
466
576
  setFrameStage(FrameStage::Idle);
467
577
  const int64_t frameDoneUs = esp_timer_get_time();
578
+ #if defined(GEA_EMBEDDED_FRAME_BENCHMARK) && GEA_EMBEDDED_FRAME_BENCHMARK
579
+ gea_frame_benchmark_sample(frameStartUs, frameDoneUs);
580
+ #endif
468
581
  // Production-fps probe: deliberately outside GEA_EMBEDDED_PERF, so it still
469
582
  // reports the TRUE production frame rate when every other perf subsystem is
470
583
  // stripped. It has its own switch because it is otherwise a once-a-second
@@ -684,7 +797,9 @@ public:
684
797
  }
685
798
  #endif
686
799
  if (forceIdleYield) {
687
- vTaskDelay(1);
800
+ // One tick can expire immediately at a tick boundary. Two guarantee
801
+ // a full tick for idle housekeeping under sustained catch-up.
802
+ vTaskDelay(2);
688
803
  } else if (!catchUpRequested && GEA_EMBEDDED_FRAME_SCHEDULER_IDLE_YIELD_TICKS > 0) {
689
804
  vTaskDelay(GEA_EMBEDDED_FRAME_SCHEDULER_IDLE_YIELD_TICKS);
690
805
  }
@@ -95,17 +95,29 @@ endif()
95
95
  if(NOT DEFINED GEA_BOARD_EXTRA_COMPILE_DEFINITIONS)
96
96
  set(GEA_BOARD_EXTRA_COMPILE_DEFINITIONS "")
97
97
  endif()
98
+ if(GEA_EMBEDDED_CPP_BOARD STREQUAL "esp32-s3-touch-amoled-1.8")
99
+ list(APPEND GEA_BOARD_PLATFORM_SOURCES "${CMAKE_CURRENT_LIST_DIR}/panel_reset.cpp")
100
+ list(APPEND GEA_BOARD_EXTRA_COMPILE_DEFINITIONS GEA_BOARD_PREPARE_DISPLAY_PANEL=1)
101
+ endif()
98
102
  if(NOT DEFINED GEA_BOARD_GEATSC_OPTIMIZATION)
99
- set(GEA_BOARD_GEATSC_OPTIMIZATION -Os)
103
+ if(GEA_EMBEDDED_CPP_BOARD STREQUAL "esp32-s3-touch-amoled-1.8" AND GEA_EMBEDDED_APP STREQUAL "bouncing-balls-jsx")
104
+ set(GEA_BOARD_GEATSC_OPTIMIZATION -O2)
105
+ else()
106
+ set(GEA_BOARD_GEATSC_OPTIMIZATION -Os)
107
+ endif()
100
108
  endif()
101
109
  if(NOT DEFINED GEA_BOARD_OPTIMIZE_BOUNCING_BALLS_JSX)
102
- set(GEA_BOARD_OPTIMIZE_BOUNCING_BALLS_JSX 0)
110
+ if(GEA_EMBEDDED_CPP_BOARD STREQUAL "esp32-s3-touch-amoled-1.8")
111
+ set(GEA_BOARD_OPTIMIZE_BOUNCING_BALLS_JSX 1)
112
+ else()
113
+ set(GEA_BOARD_OPTIMIZE_BOUNCING_BALLS_JSX 0)
114
+ endif()
103
115
  endif()
104
116
 
105
117
  # Keep app-sensitive renderer/codegen choices explicit at the board wrapper.
106
- # The shared 1.8-inch target retains its measured defaults; boards opting into
107
- # the bouncing-balls-jsx profile get the same native-number and retained-tree
108
- # shortcuts as the faster AMOLED target without affecting unrelated apps.
118
+ # The 1.8-inch board and wrappers opting into the bouncing-balls-jsx profile
119
+ # use native-number and retained-tree shortcuts for that app. Other apps keep
120
+ # their existing settings.
109
121
  set(GEA_EMBEDDED_NUMBER_F32 0)
110
122
  set(GEA_EMBEDDED_FUSE_FLUSH_VALUE 0)
111
123
  set(GEA_EMBEDDED_REVEAL_CHECK_VALUE 1)
@@ -129,6 +141,13 @@ if(GEA_BOARD_OPTIMIZE_BOUNCING_BALLS_JSX AND GEA_EMBEDDED_APP STREQUAL "bouncing
129
141
  set(GEA_EMBEDDED_PERF_LITE_VALUE 0)
130
142
  list(APPEND GEA_BOARD_EXTRA_COMPILE_DEFINITIONS GEA_NUMBER_FLOAT=1)
131
143
  endif()
144
+ # An explicit diagnostic build may override the profile's instrumentation
145
+ # default. Keep the component definition consistent with the app-wide one.
146
+ foreach(_GEA_APP_DEFINE IN LISTS GEA_EMBEDDED_APP_DEFINES)
147
+ if(_GEA_APP_DEFINE MATCHES "^GEA_EMBEDDED_PERF=([01])$")
148
+ set(GEA_EMBEDDED_PERF_VALUE "${CMAKE_MATCH_1}")
149
+ endif()
150
+ endforeach()
132
151
  if(DEFINED GEA_BOARD_FRAMEBUFFER_CS_HELD_STREAM)
133
152
  set(GEA_EMBEDDED_FB_CS_HELD_VALUE ${GEA_BOARD_FRAMEBUFFER_CS_HELD_STREAM})
134
153
  endif()
@@ -530,6 +549,7 @@ idf_component_register(
530
549
  esp_http_client
531
550
  ${GEA_EMBEDDED_HTTPS_REQUIRES}
532
551
  app_update
552
+ spi_flash
533
553
  esp_mm
534
554
  esp_netif
535
555
  esp_event
@@ -549,11 +569,31 @@ if(DEFINED ENV{GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG})
549
569
  set(GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG_VALUE "$ENV{GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG}")
550
570
  endif()
551
571
 
552
- target_compile_definitions(${COMPONENT_LIB} PRIVATE
572
+ # App dimensions are already applied to every component by gea_framework.cmake.
573
+ # Only supply missing board defaults: repeating a portrait default beside an
574
+ # app's landscape dimension produces conflicting -D flags and incompatible types.
575
+ set(_GEA_BOARD_DISPLAY_DEFAULTS
553
576
  GEA_EMBEDDED_DISPLAY_WIDTH=${GEA_BOARD_DISPLAY_WIDTH}
554
577
  GEA_EMBEDDED_DISPLAY_HEIGHT=${GEA_BOARD_DISPLAY_HEIGHT}
555
578
  GEA_EMBEDDED_DISPLAY_NATIVE_WIDTH=${GEA_BOARD_NATIVE_DISPLAY_WIDTH}
556
579
  GEA_EMBEDDED_DISPLAY_NATIVE_HEIGHT=${GEA_BOARD_NATIVE_DISPLAY_HEIGHT}
580
+ )
581
+ set(_GEA_BOARD_DISPLAY_DEFINITIONS "")
582
+ foreach(_GEA_DISPLAY_DEFAULT IN LISTS _GEA_BOARD_DISPLAY_DEFAULTS)
583
+ string(REGEX REPLACE "=.*$" "" _GEA_DISPLAY_NAME "${_GEA_DISPLAY_DEFAULT}")
584
+ set(_GEA_DISPLAY_OVERRIDDEN OFF)
585
+ foreach(_GEA_APP_DEFINE IN LISTS GEA_EMBEDDED_APP_DEFINES)
586
+ if(_GEA_APP_DEFINE MATCHES "^${_GEA_DISPLAY_NAME}=")
587
+ set(_GEA_DISPLAY_OVERRIDDEN ON)
588
+ endif()
589
+ endforeach()
590
+ if(NOT _GEA_DISPLAY_OVERRIDDEN)
591
+ list(APPEND _GEA_BOARD_DISPLAY_DEFINITIONS "${_GEA_DISPLAY_DEFAULT}")
592
+ endif()
593
+ endforeach()
594
+
595
+ target_compile_definitions(${COMPONENT_LIB} PRIVATE
596
+ ${_GEA_BOARD_DISPLAY_DEFINITIONS}
557
597
  GEA_EMBEDDED_FLUSH_ANCHOR_LEFT_PARTIAL_RECTS=0
558
598
  GEA_EMBEDDED_PIXEL_PANEL_ENDIAN=1
559
599
  GEA_CPP_ENABLE_REGEX=0
@@ -19,9 +19,8 @@ void registerDriver();
19
19
  #include "runtime.h"
20
20
  #include "services/device_control.h"
21
21
 
22
- #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
22
+ #include <cstdlib>
23
23
  #include "esp_heap_caps.h"
24
- #endif
25
24
  #include "esp_log.h"
26
25
  #include "sdkconfig.h"
27
26
  #include "freertos/FreeRTOS.h"
@@ -55,6 +54,16 @@ constexpr int kAppMainTaskStack = CONFIG_ESP_MAIN_TASK_STACK_SIZE;
55
54
  #endif
56
55
  constexpr UBaseType_t kRuntimeTaskPriority = GEA_EMBEDDED_RUNTIME_TASK_PRIORITY;
57
56
 
57
+ // Match the 2.06 target: keep flash-touching boot on the internal main stack,
58
+ // then optionally give the event loop its own stack and release main's stack.
59
+ #ifndef GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES
60
+ #define GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES 0
61
+ #endif
62
+ #ifndef GEA_EMBEDDED_RUNTIME_TASK_STACK_EXTERNAL
63
+ #define GEA_EMBEDDED_RUNTIME_TASK_STACK_EXTERNAL 0
64
+ #endif
65
+ constexpr int kRuntimeTaskStackBytes = GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES;
66
+
58
67
  #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
59
68
  void logCurrentTaskStack(const char *stage, int stackBytes)
60
69
  {
@@ -69,7 +78,7 @@ void logCurrentTaskStack(const char *stage, int stackBytes)
69
78
  }
70
79
  #endif
71
80
 
72
- void runRuntime()
81
+ gea::framework::RuntimeOptions runtimeOptions()
73
82
  {
74
83
  gea::framework::RuntimeOptions options{};
75
84
  #if GEA_EMBEDDED_DISPLAY_RUNTIME_SOFTWARE_ORIENTATION
@@ -92,8 +101,26 @@ void runRuntime()
92
101
  options.width = gea::platform::display::kWidth;
93
102
  options.height = gea::platform::display::kHeight;
94
103
  #endif
95
- gea::framework::Runtime::run(options);
104
+ return options;
105
+ }
106
+
107
+ void runRuntime()
108
+ {
109
+ gea::framework::Runtime::run(runtimeOptions());
110
+ }
111
+
112
+ #if GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES
113
+ void runtimeTask(void *)
114
+ {
115
+ ESP_LOGI(kTag, "Gea runtime task started stack=%d %s", kRuntimeTaskStackBytes,
116
+ GEA_EMBEDDED_RUNTIME_TASK_STACK_EXTERNAL ? "external" : "internal");
117
+ runRuntime();
118
+ ESP_LOGE(kTag, "Runtime returned unexpectedly; parking runtime task");
119
+ while (true) {
120
+ vTaskDelay(pdMS_TO_TICKS(1000));
121
+ }
96
122
  }
123
+ #endif
97
124
 
98
125
  } // namespace
99
126
 
@@ -152,7 +179,9 @@ extern "C" void app_main(void)
152
179
  gea::targets::esp32::ble::registerHidDriver();
153
180
  #endif
154
181
 
182
+ #if !GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES
155
183
  vTaskPrioritySet(nullptr, kRuntimeTaskPriority);
184
+ #endif
156
185
  #if GEA_EMBEDDED_FRAME_SCHEDULER_PERF_LOG
157
186
  logCurrentTaskStack("main_task:before_runtime", kAppMainTaskStack);
158
187
  #endif
@@ -163,10 +192,32 @@ extern "C" void app_main(void)
163
192
  #if GEA_EMBEDDED_HEAP_DIAGNOSTICS_LOG
164
193
  logHeapProbe("app_main:before_runtime");
165
194
  #endif
195
+ #if GEA_EMBEDDED_RUNTIME_TASK_STACK_BYTES
196
+ // Boot includes SPIFFS/NVS and must finish before entering a PSRAM stack.
197
+ if (!gea::framework::Runtime::boot(runtimeOptions())) {
198
+ ESP_LOGE(kTag, "Gea bring-up failed; the UI will not start (the app's own tasks keep running)");
199
+ return;
200
+ }
201
+ #if !GEA_EMBEDDED_NO_DISPLAY
202
+ TaskHandle_t runtime = nullptr;
203
+ const BaseType_t created = xTaskCreatePinnedToCoreWithCaps(
204
+ &runtimeTask, "gea_runtime", kRuntimeTaskStackBytes, nullptr,
205
+ kRuntimeTaskPriority, &runtime, xPortGetCoreID(),
206
+ GEA_EMBEDDED_RUNTIME_TASK_STACK_EXTERNAL ? (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)
207
+ : (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
208
+ if (created != pdPASS) {
209
+ ESP_LOGE(kTag, "Failed to allocate %d-byte Gea runtime stack", kRuntimeTaskStackBytes);
210
+ std::abort();
211
+ }
212
+ ESP_LOGI(kTag, "Bootstrap complete; Gea runtime task=%p stack=%d", runtime, kRuntimeTaskStackBytes);
213
+ #endif
214
+ // Returning releases the internal main stack; the runtime task owns the loop.
215
+ #else
166
216
  runRuntime();
167
217
 
168
218
  ESP_LOGE(kTag, "Runtime returned unexpectedly; parking main task");
169
219
  while (true) {
170
220
  vTaskDelay(pdMS_TO_TICKS(1000));
171
221
  }
222
+ #endif
172
223
  }
@@ -0,0 +1,54 @@
1
+ // The 1.8-inch board routes its peripheral reset lines through an XCA9554.
2
+ // Follow Waveshare's original 04_GFX_FT3168_Image sequence: EXIO0..2 low for
3
+ // 20 ms, then high. Preserve the remaining pins and reuse the shared I2C bus.
4
+ // https://github.com/waveshareteam/ESP32-S3-Touch-AMOLED-1.8/blob/main/examples/arduino/examples/04_GFX_FT3168_Image/04_GFX_FT3168_Image.ino
5
+ #include "i2c.h"
6
+ #include "driver/i2c_master.h"
7
+ #include "esp_log.h"
8
+ #include "freertos/FreeRTOS.h"
9
+ #include "freertos/task.h"
10
+ #include <cstdint>
11
+
12
+ namespace gea::platform::board {
13
+ void prepareDisplayPanel()
14
+ {
15
+ const auto bus = gea::platform::i2c::Bus::primary();
16
+ if (!bus.available()) {
17
+ ESP_LOGE("panel_reset", "shared I2C bus unavailable");
18
+ return;
19
+ }
20
+ i2c_device_config_t config{};
21
+ config.dev_addr_length = I2C_ADDR_BIT_LEN_7;
22
+ config.device_address = 0x20;
23
+ config.scl_speed_hz = 400000;
24
+ i2c_master_dev_handle_t device = nullptr;
25
+ esp_err_t err = i2c_master_bus_add_device(
26
+ static_cast<i2c_master_bus_handle_t>(bus.nativeHandle()), &config, &device);
27
+ if (err != ESP_OK) {
28
+ ESP_LOGE("panel_reset", "expander attach failed: %s", esp_err_to_name(err));
29
+ return;
30
+ }
31
+ constexpr std::uint8_t pins = 0x07;
32
+ const auto read = [&](std::uint8_t reg, std::uint8_t &value) {
33
+ return i2c_master_transmit_receive(device, &reg, 1, &value, 1, 100);
34
+ };
35
+ const auto write = [&](std::uint8_t reg, std::uint8_t value) {
36
+ const std::uint8_t bytes[]{reg, value};
37
+ return i2c_master_transmit(device, bytes, sizeof(bytes), 100);
38
+ };
39
+ std::uint8_t output = 0, direction = 0;
40
+ err = read(0x01, output);
41
+ if (err == ESP_OK) err = read(0x03, direction);
42
+ // Set the low latch before enabling outputs to avoid an unintended pulse.
43
+ if (err == ESP_OK) err = write(0x01, output & ~pins);
44
+ if (err == ESP_OK) err = write(0x03, direction & ~pins);
45
+ if (err == ESP_OK) {
46
+ vTaskDelay(pdMS_TO_TICKS(20));
47
+ err = write(0x01, output | pins);
48
+ vTaskDelay(pdMS_TO_TICKS(50));
49
+ }
50
+ i2c_master_bus_rm_device(device);
51
+ if (err == ESP_OK) ESP_LOGI("panel_reset", "peripherals reset through XCA9554 EXIO0..2");
52
+ else ESP_LOGE("panel_reset", "expander reset failed: %s", esp_err_to_name(err));
53
+ }
54
+ } // namespace gea::platform::board
@@ -59,6 +59,6 @@ direct_dependencies:
59
59
  - espressif/esp_lcd_co5300
60
60
  - espressif/esp_lcd_panel_io_additions
61
61
  - idf
62
- manifest_hash: 4251b5a6af848c92c5fbc8b9dbb076a8b2a53c265de5eadaa6d4357945f77209
62
+ manifest_hash: 34ae4cf7c0b000b13ee85d92cb57e298a904e8345f7b179f0b61b01b2f42de35
63
63
  target: esp32s3
64
64
  version: 3.0.0
@@ -42,6 +42,9 @@ struct Es8311AudioConfig {
42
42
  gpio_num_t dout;
43
43
  gpio_num_t din;
44
44
  gpio_num_t powerAmplifier;
45
+ // The microphones are on an ES7210 ADC (I2C 0x40) sharing the I2S bus; the ES8311's own input
46
+ // is not wired to a mic on this board.
47
+ int es7210Address;
45
48
  };
46
49
 
47
50
  struct SdMmcConfig {
@@ -92,6 +95,7 @@ public:
92
95
  .dout = GPIO_NUM_40,
93
96
  .din = GPIO_NUM_42,
94
97
  .powerAmplifier = GPIO_NUM_46,
98
+ .es7210Address = 0x40,
95
99
  };
96
100
  };
97
101
 
@@ -56,6 +56,10 @@ CONFIG_SPIRAM_MODE_OCT=y
56
56
  CONFIG_SPIRAM_SPEED_80M=y
57
57
  CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
58
58
  CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM=y
59
+ # vTaskDeleteWithCaps(NULL) (fetchAsync job tasks end this way) deletes the task from a helper task with
60
+ # configMINIMAL_STACK_SIZE, which follows this; the default 1536 overflows while the job's thread-local
61
+ # state is torn down and reboots the board.
62
+ CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=3072
59
63
  CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
60
64
  CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=0
61
65
  # IDF defaults this to 32 KiB when SPIRAM malloc is enabled. That creates a
@@ -75,6 +75,6 @@ direct_dependencies:
75
75
  - espressif/esp_lcd_panel_io_additions
76
76
  - espressif/esp_lcd_sh8601
77
77
  - idf
78
- manifest_hash: 97466cb9f001785e379d20688aed5569777e3f55dbc12f90f65fdc4d195fb22e
78
+ manifest_hash: 877cab124fe9bc18750b436566feb51710be048484445812ba342e0427c514a8
79
79
  target: esp32s3
80
80
  version: 3.0.0