@geastack/cli 0.1.113 → 0.1.115

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/docs/SETUP.md CHANGED
@@ -335,13 +335,14 @@ at call time, so never record a port path.
335
335
 
336
336
  ### Composed targets
337
337
 
338
- A composed target is a JSON definition that extends the `esp32-s3` base and
339
- picks its chips from the `@geastack/chips` catalog (`gea chips list`). Every
338
+ A composed target is a JSON definition that extends a base (`esp32-s3` or
339
+ `esp32-p4`, with `mcu` set to `esp32s3` or `esp32p4` to match) and picks its chips from the `@geastack/chips` catalog (`gea chips list`). Every
340
340
  role is optional, so the definition describes the hardware that is there:
341
341
  `display`, `touch`, `power`, `imu`, `audio`, `rtc` and `expander`. Some boards are
342
342
  shipped composed in `@geastack/targets` and need no definition of your own,
343
343
  for example `esp32-s3-devkit-n16r8` (a bare module),
344
- `esp32-s3-waveshare-touch-lcd-7` and `esp32-s3-elecrow-crowpanel-advance-7.0`.
344
+ `esp32-s3-waveshare-touch-lcd-7`, `esp32-s3-elecrow-crowpanel-advance-7.0` and
345
+ `esp32-p4-elecrow-crowpanel-advanced-5.0`.
345
346
 
346
347
  Two kinds of display are understood. A QSPI controller (`co5300`) takes the
347
348
  `spiHost` and `cs`/`pclk`/`data0-3`/`reset`/`te` pins. A bare parallel RGB
@@ -410,6 +411,37 @@ hardware switch the firmware does not drive, `pinSharing` lists the roles that
410
411
  may coincide, e.g. `[["audio", "microSD"]]`; every other pin must still belong
411
412
  to one role. The CrowPanel Advance 7.0 definition uses all of these.
412
413
 
414
+ #### The `esp32-p4` base
415
+
416
+ A P4 definition takes the same roles, with GPIOs up to 54. Its display is a
417
+ parallel RGB panel scanned straight out of the P4's in-package PSRAM by the
418
+ LCD driver, through only a small FIFO: a PSRAM stall of a few microseconds
419
+ underruns it and the picture creeps right. The base therefore runs flash at
420
+ QIO 80MHz, as the vendors' own firmware does (DIO 40MHz underran the CrowPanel
421
+ Advance 5.0 every few seconds); a board whose flash is wired DIO-only sets
422
+ `flashMode`. Use
423
+ `scanFramebuffers: 3` so the renderer draws straight into a buffer not being
424
+ scanned (one buffer adds a PSRAM-to-PSRAM copy of every changed region; with
425
+ two, each swap can wait up to a frame for the panel to let go of the old
426
+ front). Scroll copies and full-width patches between the buffers go through
427
+ the AXI-GDMA, about three times faster than the CPU. Keep the L2 cache's
428
+ 64-byte lines: 128-byte lines speed CPU copies up but stall PSRAM long enough
429
+ for the panel to underrun at 60Hz. Leave `restartInVsync` off; the driver restarts the DMA itself at the next VSYNC
430
+ if it ever falls behind. `psram` is not configurable (the base sets
431
+ it up). `pclkIdleHigh: true` idles the pixel clock high between lines, which
432
+ some panels need. Two sections exist only on this base:
433
+
434
+ - `wireless`: the WiFi/BLE coprocessor (an ESP32-C6, say) on SDIO through
435
+ esp_hosted: `slot`, `busWidth` (1 or 4), `clockKhz`, `resetActiveHigh`, and
436
+ `pins` `clk`/`cmd`/`d0`-`d3`/`reset`.
437
+ - `camera`: a MIPI-CSI sensor: `sensor` (the esp_cam_sensor name, e.g.
438
+ `sc2336`), `mode` (its Kconfig mode, e.g. `MIPI_RAW8_1024x600_30FPS`),
439
+ `width`/`height`, `rotation` (degrees counter-clockwise), the `sccb` bus's
440
+ `sda`/`scl`, and a `reset` that is a GPIO (`pin`) or an expander line
441
+ (`expander`).
442
+
443
+ The CrowPanel Advanced 5.0 definition is the reference.
444
+
413
445
  ## Common Verification Flow
414
446
 
415
447
  After installing tools:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.113",
3
+ "version": "0.1.115",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@clack/prompts": "^1.8.0",
40
40
  "@geastack/simulator": "^0.1.15",
41
- "@geastack/targets": "^0.1.110",
41
+ "@geastack/targets": "^0.1.112",
42
42
  "picocolors": "^1.1.1",
43
43
  "serialport": "^13.0.0"
44
44
  },
@@ -8,7 +8,9 @@ import { writePartitionTable } from '../esp32/partitions-from-manifest.mjs'
8
8
  // generated board.h + target.cmake inside the app's build directory before
9
9
  // IDF configures, so the target project only ever includes generated files.
10
10
 
11
- const supportedBase = 'esp32-s3'
11
+ // Each base is a target project that includes the generated files, keyed by
12
+ // the `extends` a definition names, with the MCU it runs on.
13
+ const supportedBases = { 'esp32-s3': 'esp32s3', 'esp32-p4': 'esp32p4' }
12
14
 
13
15
  function object(value, label) {
14
16
  if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${label} must be an object.`)
@@ -40,15 +42,20 @@ function boolean(value, label, fallback) {
40
42
  throw new Error(`${label} must be true or false.`)
41
43
  }
42
44
 
45
+ // The highest GPIO of the MCU being normalized: GPIO0-48 on the S3, 0-54 on
46
+ // the P4. Set once per definition, before any pin is read.
47
+ const maxGpioByMcu = { esp32s3: 48, esp32p4: 54 }
48
+ let maxGpio = maxGpioByMcu.esp32s3
49
+
43
50
  function pin(value, label, { optional = false } = {}) {
44
51
  if (optional && (value === null || value === undefined || value === 'none')) return -1
45
- return integer(value, label)
52
+ return integer(value, label, { max: maxGpio })
46
53
  }
47
54
 
48
55
  function exact(value, expected, label) {
49
56
  const actual = text(value, label).toLowerCase()
50
57
  if (actual !== expected) {
51
- throw new Error(`${label} '${actual}' is not supported by the ${supportedBase} base. Supported value: ${expected}.`)
58
+ throw new Error(`${label} '${actual}' is not supported. Supported value: ${expected}.`)
52
59
  }
53
60
  return actual
54
61
  }
@@ -129,8 +136,11 @@ export function normalizeCustomTarget(raw, catalog) {
129
136
  const definition = object(raw, 'Target definition')
130
137
  const id = text(definition.id, 'id')
131
138
  if (!/^[a-z0-9][a-z0-9._-]*$/.test(id)) throw new Error('id may contain lowercase letters, digits, dots, underscores, and hyphens.')
132
- const base = exact(definition.extends, supportedBase, 'extends')
133
- const mcu = exact(definition.mcu, 'esp32s3', 'mcu')
139
+ const base = text(definition.extends, 'extends')
140
+ if (!Object.hasOwn(supportedBases, base)) throw new Error(`extends must be one of ${Object.keys(supportedBases).join(', ')}, not '${base}'.`)
141
+ const mcu = exact(definition.mcu, supportedBases[base], 'mcu')
142
+ const p4 = mcu === 'esp32p4'
143
+ maxGpio = maxGpioByMcu[mcu]
134
144
  const adapter = definition.adapter ? exact(definition.adapter, 'esp32-idf', 'adapter') : 'esp32-idf'
135
145
  const chips = absent(definition.chips) ? {} : object(definition.chips, 'chips')
136
146
  const display = optionalChip(chips, 'display', 'display', adapter, mcu, catalog)
@@ -178,9 +188,10 @@ export function normalizeCustomTarget(raw, catalog) {
178
188
  // share nothing but a size, so each carries its own pins and parameters.
179
189
  const displayInterface = display ? display.interface : ''
180
190
  if (display && !['qspi', 'rgb'].includes(displayInterface)) {
181
- throw new Error(`chips.display.interface '${displayInterface}' is not supported by the ${supportedBase} base. Supported values: qspi, rgb.`)
191
+ throw new Error(`chips.display.interface '${displayInterface}' is not supported by the ${base} base. Supported values: qspi, rgb.`)
182
192
  }
183
193
  const spiHost = display && displayInterface === 'qspi' ? String(display.spiHost ?? 'spi2').toLowerCase() : 'spi2'
194
+ if (p4 && display && displayInterface !== 'rgb') throw new Error(`chips.display.interface '${displayInterface}' is not supported by the esp32-p4 base yet. Supported values: rgb.`)
184
195
  if (display && displayInterface === 'qspi' && !['spi2', 'spi3'].includes(spiHost)) throw new Error("chips.display.spiHost must be 'spi2' or 'spi3'.")
185
196
  const expanderOutputs = expander ? (absent(expander.outputs) ? {} : object(expander.outputs, 'chips.expander.outputs')) : null
186
197
  const expanderMaxPin = ['tca9554', 'pca9557', 'elecrow_board_control'].includes(expander?.driver) ? 7 : expander?.driver === 'ch422g' ? 11 : 15
@@ -227,6 +238,9 @@ export function normalizeCustomTarget(raw, catalog) {
227
238
  // console: octal settings on a quad-wired part do not fail cleanly, they
228
239
  // bring up a device that reports the wrong size and corrupts under load.
229
240
  const psram = absent(definition.psram) ? null : object(definition.psram, 'psram')
241
+ // The P4's PSRAM is in the package (16-line HEX, 200MHz), not a module
242
+ // choice: the base configures it, and the S3's octal/quad knobs mean nothing.
243
+ if (psram && p4) throw new Error('psram is not configurable on the esp32-p4 base: its PSRAM is in-package and the base sets it up.')
230
244
  const psramModes = ['octal', 'quad', 'none']
231
245
  const psramMode = psram && !absent(psram.mode) ? text(psram.mode, 'psram.mode').toLowerCase() : ''
232
246
  if (psramMode && !psramModes.includes(psramMode)) {
@@ -291,6 +305,63 @@ export function normalizeCustomTarget(raw, catalog) {
291
305
  }
292
306
  }
293
307
 
308
+ // A P4 has no radio: WiFi/BLE come from an ESP32-C6/C5 coprocessor on
309
+ // SDIO, through esp_hosted. Its bus and reset line are board wiring.
310
+ const wireless = absent(definition.wireless) ? null : object(definition.wireless, 'wireless')
311
+ if (wireless && !p4) throw new Error('wireless (a hosted coprocessor) is only supported by the esp32-p4 base.')
312
+ const wirelessPins = wireless ? object(wireless.pins, 'wireless.pins') : null
313
+ const wirelessConfig = wireless ? (() => {
314
+ exact(wireless.transport ?? 'sdio', 'sdio', 'wireless.transport')
315
+ const busWidth = integer(wireless.busWidth ?? 4, 'wireless.busWidth', { min: 1, max: 4 })
316
+ if (![1, 4].includes(busWidth)) throw new Error('wireless.busWidth must be 1 or 4.')
317
+ return {
318
+ coprocessor: text(wireless.coprocessor ?? 'esp32c6', 'wireless.coprocessor'),
319
+ transport: 'sdio',
320
+ slot: integer(wireless.slot ?? 1, 'wireless.slot', { min: 0, max: 1 }),
321
+ busWidth,
322
+ clockKhz: integer(wireless.clockKhz ?? 40000, 'wireless.clockKhz', { min: 400, max: 50000 }),
323
+ resetActiveHigh: boolean(wireless.resetActiveHigh, 'wireless.resetActiveHigh', true),
324
+ pins: {
325
+ clk: pin(wirelessPins.clk, 'wireless.pins.clk'),
326
+ cmd: pin(wirelessPins.cmd, 'wireless.pins.cmd'),
327
+ d0: pin(wirelessPins.d0, 'wireless.pins.d0'),
328
+ d1: busWidth === 4 ? pin(wirelessPins.d1, 'wireless.pins.d1') : -1,
329
+ d2: busWidth === 4 ? pin(wirelessPins.d2, 'wireless.pins.d2') : -1,
330
+ d3: busWidth === 4 ? pin(wirelessPins.d3, 'wireless.pins.d3') : -1,
331
+ reset: pin(wirelessPins.reset, 'wireless.pins.reset', { optional: true })
332
+ }
333
+ }
334
+ })() : null
335
+ // A MIPI-CSI camera: the sensor (an esp_cam_sensor driver), its mode, and
336
+ // its SCCB control bus. Reset may be a GPIO or a board-control line.
337
+ const camera = absent(definition.camera) ? null : object(definition.camera, 'camera')
338
+ if (camera && !p4) throw new Error('camera is only supported by the esp32-p4 base.')
339
+ const cameraConfig = camera ? (() => {
340
+ exact(camera.interface ?? 'mipi-csi', 'mipi-csi', 'camera.interface')
341
+ const sensor = text(camera.sensor, 'camera.sensor').toLowerCase()
342
+ if (!/^[a-z0-9]+$/.test(sensor)) throw new Error(`camera.sensor must be an esp_cam_sensor name such as sc2336 or ov5647, not '${sensor}'.`)
343
+ // Spelled exactly as the sensor's Kconfig spells it (the resolution keeps its lowercase x).
344
+ const mode = absent(camera.mode) ? '' : text(camera.mode, 'camera.mode')
345
+ if (mode && !/^[A-Za-z0-9_]+$/.test(mode)) throw new Error(`camera.mode must be the sensor's Kconfig mode name such as MIPI_RAW8_1024x600_30FPS, not '${mode}'.`)
346
+ const sccb = object(camera.sccb, 'camera.sccb')
347
+ const reset = absent(camera.reset) ? {} : object(camera.reset, 'camera.reset')
348
+ if (!absent(reset.expander) && !expander) throw new Error('camera.reset.expander names an expander line, but the board has no chips.expander.')
349
+ return {
350
+ sensor,
351
+ mode,
352
+ width: integer(camera.width, 'camera.width', { min: 1, max: 4096 }),
353
+ height: integer(camera.height, 'camera.height', { min: 1, max: 4096 }),
354
+ // Sensor mounting relative to the panel, degrees counter-clockwise.
355
+ rotation: (() => {
356
+ const value = integer(camera.rotation ?? 0, 'camera.rotation', { min: 0, max: 270 })
357
+ if (value % 90) throw new Error('camera.rotation must be 0, 90, 180 or 270.')
358
+ return value
359
+ })(),
360
+ sccb: { sda: pin(sccb.sda, 'camera.sccb.sda'), scl: pin(sccb.scl, 'camera.sccb.scl') },
361
+ reset: { pin: pin(reset.pin, 'camera.reset.pin', { optional: true }), expander: expanderPin(reset.expander, 'camera.reset.expander') }
362
+ }
363
+ })() : null
364
+
294
365
  const target = {
295
366
  id,
296
367
  extends: base,
@@ -313,6 +384,8 @@ export function normalizeCustomTarget(raw, catalog) {
313
384
  return roles
314
385
  }),
315
386
  console: consoleTransport ? { transport: consoleTransport, baud: consoleBaud, uart: consoleUart } : null,
387
+ wireless: wirelessConfig,
388
+ camera: cameraConfig,
316
389
  psram: psramMode ? { mode: psramMode, speed: psramSpeed, xip: psramXip } : null,
317
390
  buses: {
318
391
  i2c: i2c === null ? null : {
@@ -336,6 +409,8 @@ export function normalizeCustomTarget(raw, catalog) {
336
409
  vsyncBackPorch: integer(display.vsyncBackPorch ?? 8, 'chips.display.vsyncBackPorch', { min: 0, max: 1024 }),
337
410
  vsyncFrontPorch: integer(display.vsyncFrontPorch ?? 8, 'chips.display.vsyncFrontPorch', { min: 0, max: 1024 }),
338
411
  pclkActiveNeg: boolean(display.pclkActiveNeg, 'chips.display.pclkActiveNeg', true),
412
+ // PCLK's level between lines; some panels sample garbage unless it idles high.
413
+ pclkIdleHigh: boolean(display.pclkIdleHigh, 'chips.display.pclkIdleHigh', false),
339
414
  scanFramebuffers: integer(display.scanFramebuffers ?? 3, 'chips.display.scanFramebuffers', { min: 1, max: 3 }),
340
415
  backlightActiveLow: boolean(display.backlightActiveLow, 'chips.display.backlightActiveLow', false),
341
416
  bounceRows: integer(display.bounceRows ?? 0, 'chips.display.bounceRows', { min: 0, max: 120 }),
@@ -512,7 +587,7 @@ export function normalizeCustomTarget(raw, catalog) {
512
587
  return target
513
588
  }
514
589
 
515
- const pinRoles = ['i2c', 'display', 'touch', 'audio', 'microphone', 'microSD', 'launcherButton']
590
+ const pinRoles = ['i2c', 'display', 'touch', 'audio', 'microphone', 'microSD', 'launcherButton', 'wireless', 'camera']
516
591
 
517
592
  function pinRoleOf(label) {
518
593
  if (label.startsWith('I2C ')) return 'i2c'
@@ -521,6 +596,8 @@ function pinRoleOf(label) {
521
596
  if (label.startsWith('audio ')) return 'audio'
522
597
  if (label.startsWith('microphone ')) return 'microphone'
523
598
  if (label.startsWith('microSD ')) return 'microSD'
599
+ if (label.startsWith('wireless ')) return 'wireless'
600
+ if (label.startsWith('camera ')) return 'camera'
524
601
  return 'launcherButton'
525
602
  }
526
603
 
@@ -580,7 +657,13 @@ function validatePinAssignments(target) {
580
657
  ['microSD CS', sd.pins.cs]
581
658
  ] : [])
582
659
  ] : []),
583
- ...(launcher ? [['launcher button', launcher.pin]] : [])
660
+ ...(launcher ? [['launcher button', launcher.pin]] : []),
661
+ ...(target.wireless ? Object.entries(target.wireless.pins).map(([name, value]) => [`wireless ${name.toUpperCase()}`, value]) : []),
662
+ ...(target.camera ? [
663
+ ['camera SCCB SDA', target.camera.sccb.sda],
664
+ ['camera SCCB SCL', target.camera.sccb.scl],
665
+ ['camera reset', target.camera.reset.pin]
666
+ ] : [])
584
667
  ]
585
668
  const shared = (a, b) => a !== b && target.pinSharing.some((group) => group.includes(a) && group.includes(b))
586
669
  const used = new Map()
@@ -640,6 +723,8 @@ ${includes}
640
723
  #define GEA_BOARD_HAS_LAUNCHER_BUTTON ${target.controls.launcherButton ? 1 : 0}
641
724
  #define GEA_BOARD_HAS_EXPANDER ${expander ? 1 : 0}
642
725
  #define GEA_BOARD_HAS_RGB_CONTROLLER ${rgb?.controller ? 1 : 0}
726
+ #define GEA_BOARD_HAS_CAMERA ${target.camera ? 1 : 0}
727
+ #define GEA_BOARD_HAS_HOSTED_WIRELESS ${target.wireless ? 1 : 0}
643
728
 
644
729
  namespace gea::platform::board {
645
730
 
@@ -694,6 +779,13 @@ inline constexpr Es8311AudioConfig audio{
694
779
  .ws = ${gpio(audioPins.ws)}, .dout = ${gpio(audioPins.dout)}, .din = ${gpio(audioPins.din)},
695
780
  .powerAmplifier = ${gpio(audioPins.powerAmplifier)}, .es7210Address = ${audio.es7210Address}
696
781
  };` : ''}
782
+ ${target.camera ? `
783
+ // The MIPI-CSI camera's SCCB bus and reset: a GPIO, or a board-control line (-1 where neither).
784
+ struct CameraConfig { const char *name; gpio_num_t sccbSda; gpio_num_t sccbScl; gpio_num_t reset; int expanderReset; int width; int height; int rotateCcw; };
785
+ inline constexpr CameraConfig camera{ .name = "mipi-csi-${target.camera.sensor}", .sccbSda = ${gpio(target.camera.sccb.sda)}, .sccbScl = ${gpio(target.camera.sccb.scl)}, .reset = ${gpio(target.camera.reset.pin)}, .expanderReset = ${target.camera.reset.expander}, .width = ${target.camera.width}, .height = ${target.camera.height}, .rotateCcw = ${target.camera.rotation / 90} };` : ''}${target.wireless ? `
786
+ // The hosted WiFi/BLE coprocessor's SDIO bus (esp_hosted reads the same pins from sdkconfig).
787
+ struct HostedConfig { gpio_num_t clk; gpio_num_t cmd; gpio_num_t d0; gpio_num_t d1; gpio_num_t d2; gpio_num_t d3; gpio_num_t reset; };
788
+ inline constexpr HostedConfig hosted{ .clk = ${gpio(target.wireless.pins.clk)}, .cmd = ${gpio(target.wireless.pins.cmd)}, .d0 = ${gpio(target.wireless.pins.d0)}, .d1 = ${gpio(target.wireless.pins.d1)}, .d2 = ${gpio(target.wireless.pins.d2)}, .d3 = ${gpio(target.wireless.pins.d3)}, .reset = ${gpio(target.wireless.pins.reset)} };` : ''}
697
789
 
698
790
  ${rgb?.controller ? `struct RgbControllerConfig { int cs; int clock; int data; int reset; int addressSelect; };
699
791
  inline constexpr RgbControllerConfig rgbController{ ${rgb.controller.cs}, ${rgb.controller.clock}, ${rgb.controller.data}, ${rgb.controller.reset}, ${rgb.controller.addressSelect} };
@@ -782,7 +874,10 @@ export function renderTargetCmake(target, includeDir, appDefines = new Set()) {
782
874
  // it stores native order -- exactly what the Elecrow rotary target does.
783
875
  display?.panel ? boardDefine('GEA_CUSTOM_QSPI_PANEL_CONFIG', 1) : '',
784
876
  display?.panel?.minChunkRows ? boardDefine('GEA_EMBEDDED_DISPLAY_FLUSH_CHUNK_MIN', display.panel.minChunkRows) : '',
785
- display && display.interface === 'rgb' ? boardDefine('GEA_EMBEDDED_PIXEL_PANEL_ENDIAN', 0) : ''
877
+ display && display.interface === 'rgb' ? boardDefine('GEA_EMBEDDED_PIXEL_PANEL_ENDIAN', 0) : '',
878
+ display?.pclkIdleHigh ? boardDefine('GEA_EMBEDDED_DISPLAY_RGB_PCLK_IDLE_HIGH', 1) : '',
879
+ // The P4's driver-owned framebuffers take the direct path in rgb_panel.cpp.
880
+ display && display.interface === 'rgb' && target.mcu === 'esp32p4' ? boardDefine('GEA_EMBEDDED_DISPLAY_RGB_BOUNCE', 0) : ''
786
881
  ].join('')
787
882
  // The board's own identity and pixel order reach geatsc too: the base project
788
883
  // is another board's, and its defaults (name, viewport, byte-swapped RGB565)
@@ -802,6 +897,9 @@ set(GEA_CUSTOM_TARGET_TOUCH_DRIVER "${touch ? touch.driver : ''}")
802
897
  set(GEA_CUSTOM_TARGET_HAS_EXPANDER ${expander ? 1 : 0})
803
898
  set(GEA_CUSTOM_TARGET_HAS_MICROSD ${target.storage.microSD ? 1 : 0})
804
899
  set(GEA_CUSTOM_TARGET_AUDIO_DRIVER "${audio ? audio.driver : ''}")
900
+ set(GEA_CUSTOM_TARGET_HAS_CAMERA ${target.camera ? 1 : 0})
901
+ set(GEA_CUSTOM_TARGET_CAMERA_SENSOR "${target.camera ? target.camera.sensor : ''}")
902
+ set(GEA_CUSTOM_TARGET_HAS_HOSTED_WIRELESS ${target.wireless ? 1 : 0})
805
903
  set(GEA_CUSTOM_TARGET_AUDIO_SOURCES
806
904
  ${audio?.kind === 'i2s-amplifier' ? sourcesFor(audio).join('\n') : ''}
807
905
  )
@@ -453,7 +453,10 @@ export const geadev = {
453
453
  },
454
454
 
455
455
  async screenshot(d, { timeoutMs = 12000, fallbackTimeoutMs = 30000, attempts = 3, legacy = false } = {}) {
456
- if (legacy) return geadev.screenshotRle(d, fallbackTimeoutMs)
456
+ // A 115200-baud UART console moves ~11 KB/s, so a busy 800x480 frame can
457
+ // need longer than the default: a longer --timeout covers the RLE path too.
458
+ const rleTimeoutMs = Math.max(timeoutMs, fallbackTimeoutMs)
459
+ if (legacy) return geadev.screenshotRle(d, rleTimeoutMs)
457
460
  let lastError = null
458
461
  for (let attempt = 0; attempt < Math.max(1, attempts); attempt += 1) {
459
462
  try {
@@ -465,7 +468,7 @@ export const geadev = {
465
468
  }
466
469
  }
467
470
  if (d.trace) d.stderr(`binary screenshot unavailable, falling back to RLE: ${lastError?.message}`)
468
- return geadev.screenshotRle(d, fallbackTimeoutMs)
471
+ return geadev.screenshotRle(d, rleTimeoutMs)
469
472
  },
470
473
 
471
474
  // Streams a file onto the device's storage over USB. Throttled bursts keep
@@ -2,7 +2,7 @@ import { debugFps } from '../debug-fps.mjs'
2
2
  import { spawnSync } from 'node:child_process'
3
3
  import { createHash } from 'node:crypto'
4
4
  import { appForNativeDebugger, resolveBuildConfig, writeBuildConfig } from '../build-config.mjs'
5
- import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs'
5
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, renameSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs'
6
6
  import path from 'node:path'
7
7
 
8
8
  import { geastackHome } from '../boards/config.mjs'
@@ -169,7 +169,7 @@ export function requireEspIdf(env, log, selection = null) {
169
169
 
170
170
  // The per-app sdkconfig policy: development logging, the board's stack
171
171
  // sizes, the S3 instruction cache and the BLE host exactly as the app needs.
172
- export function applySdkconfigPolicy(sdkconfig, { selection, app, capabilities, bleOta, partitionCsv, boardConsole, boardPsram, boardRgbPanel }) {
172
+ export function applySdkconfigPolicy(sdkconfig, { selection, app, capabilities, bleOta, partitionCsv, boardConsole, boardPsram, boardRgbPanel, boardWireless = null, boardCamera = null }) {
173
173
  const set = (key, value) => sdkconfig.set(key, value)
174
174
  const unset = (key) => sdkconfig.unset(key)
175
175
  // A board value the app's own defaults may replace. Every value this policy
@@ -198,9 +198,13 @@ export function applySdkconfigPolicy(sdkconfig, { selection, app, capabilities,
198
198
  // firmware would run correctly and log into a port nobody is connected to,
199
199
  // which is indistinguishable from a board that never booted.
200
200
  if (boardConsole) {
201
- for (const key of ['CONFIG_ESP_CONSOLE_UART_DEFAULT', 'CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG', 'CONFIG_ESP_CONSOLE_USB_CDC', 'CONFIG_ESP_CONSOLE_NONE']) {
201
+ // A base's own console choice goes with it: the esp32-p4 base (the Waveshare
202
+ // 7-inch project) runs a CUSTOM UART at 921600 with the USB-Serial/JTAG as a
203
+ // secondary console, none of which a composed board's wiring has.
204
+ for (const key of ['CONFIG_ESP_CONSOLE_UART_DEFAULT', 'CONFIG_ESP_CONSOLE_UART_CUSTOM', 'CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0', 'CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1', 'CONFIG_ESP_CONSOLE_UART_TX_GPIO', 'CONFIG_ESP_CONSOLE_UART_RX_GPIO', 'CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG', 'CONFIG_ESP_CONSOLE_USB_CDC', 'CONFIG_ESP_CONSOLE_NONE', 'CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG']) {
202
205
  unset(key)
203
206
  }
207
+ board('CONFIG_ESP_CONSOLE_SECONDARY_NONE', 'y')
204
208
  if (boardConsole.transport === 'uart') {
205
209
  board('CONFIG_ESP_CONSOLE_UART_DEFAULT', 'y')
206
210
  board('CONFIG_ESP_CONSOLE_UART', 'y')
@@ -266,6 +270,68 @@ export function applySdkconfigPolicy(sdkconfig, { selection, app, capabilities,
266
270
  // `restartInVsync: false` skips the restart: it runs in the VSYNC interrupt,
267
271
  // which waits out a refill in progress, and once that pushes it past the
268
272
  // vertical blanking the restarted frame lands shifted sideways.
273
+ // A P4's hosted WiFi/BLE coprocessor: esp_hosted takes its SDIO bus and the
274
+ // coprocessor's reset line from these, so they are the board's wiring.
275
+ if (boardWireless) {
276
+ for (const slot of [0, 1]) if (slot !== boardWireless.slot) unset(`CONFIG_ESP_HOSTED_SDIO_SLOT_${slot}`)
277
+ board(`CONFIG_ESP_HOSTED_SDIO_SLOT_${boardWireless.slot}`, 'y')
278
+ if (boardWireless.busWidth === 4) {
279
+ unset('CONFIG_ESP_HOSTED_SDIO_1_BIT_BUS')
280
+ board('CONFIG_ESP_HOSTED_SDIO_4_BIT_BUS', 'y')
281
+ } else {
282
+ unset('CONFIG_ESP_HOSTED_SDIO_4_BIT_BUS')
283
+ board('CONFIG_ESP_HOSTED_SDIO_1_BIT_BUS', 'y')
284
+ }
285
+ board('CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ', String(boardWireless.clockKhz))
286
+ if (boardWireless.resetActiveHigh) {
287
+ unset('CONFIG_ESP_HOSTED_SDIO_RESET_ACTIVE_LOW')
288
+ board('CONFIG_ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH', 'y')
289
+ } else {
290
+ unset('CONFIG_ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH')
291
+ board('CONFIG_ESP_HOSTED_SDIO_RESET_ACTIVE_LOW', 'y')
292
+ }
293
+ board('CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE', String(boardWireless.pins.reset))
294
+ // esp_hosted's settable pins are the per-slot PRIV symbols; the plain
295
+ // CONFIG_ESP_HOSTED_SDIO_PIN_* are derived from them and a value written
296
+ // there is recomputed away. D1 is the interrupt line in 1-bit mode too.
297
+ const slot = `SLOT_${boardWireless.slot}`
298
+ const bus = boardWireless.busWidth === 4 ? '4BIT_BUS' : '1BIT_BUS'
299
+ const pins = {
300
+ [`CMD_${slot}`]: 'cmd',
301
+ [`CLK_${slot}`]: 'clk',
302
+ [`D0_${slot}`]: 'd0',
303
+ [`D1_${bus}_${slot}`]: 'd1',
304
+ ...(boardWireless.busWidth === 4 ? { [`D2_${bus}_${slot}`]: 'd2', [`D3_${bus}_${slot}`]: 'd3' } : {})
305
+ }
306
+ for (const [name, key] of Object.entries(pins)) {
307
+ if (boardWireless.pins[key] >= 0) board(`CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_${name}`, String(boardWireless.pins[key]))
308
+ }
309
+ }
310
+
311
+ // A P4's MIPI-CSI camera: the esp_cam_sensor driver and the mode it streams.
312
+ if (boardCamera) {
313
+ const sensor = boardCamera.sensor.toUpperCase()
314
+ // Only the board's sensor: the esp32-p4 base enables the Waveshare board's
315
+ // OV5647, and esp_video would probe it too.
316
+ for (const line of `${sdkconfig.defaults}\n${sdkconfig.text}`.split('\n')) {
317
+ const other = /^(CONFIG_CAMERA_([A-Z0-9]+))=y$/.exec(line)
318
+ if (other && other[2] !== sensor && other[2] !== 'XCLK') unset(other[1])
319
+ }
320
+ board('CONFIG_IDF_EXPERIMENTAL_FEATURES', 'y')
321
+ board(`CONFIG_CAMERA_${sensor}`, 'y')
322
+ board(`CONFIG_CAMERA_${sensor}_AUTO_DETECT_MIPI_INTERFACE_SENSOR`, 'y')
323
+ if (boardCamera.mode) {
324
+ // The mode is a choice: clear the one already selected (the sensor's
325
+ // default, or a previous board's) so the two cannot both stand.
326
+ const prefix = `CONFIG_CAMERA_${sensor}_${boardCamera.mode.split('_')[0]}_`
327
+ for (const line of sdkconfig.text.split('\n')) {
328
+ const key = line.endsWith('=y') ? line.slice(0, -2) : ''
329
+ if (key.startsWith(prefix) && !key.includes('_IF_FORMAT_') && key !== `CONFIG_CAMERA_${sensor}_${boardCamera.mode}`) unset(key)
330
+ }
331
+ board(`CONFIG_CAMERA_${sensor}_${boardCamera.mode}`, 'y')
332
+ }
333
+ }
334
+
269
335
  if (boardRgbPanel) {
270
336
  board('CONFIG_LCD_RGB_ISR_IRAM_SAFE', 'y')
271
337
  if (boardRgbPanel.restartInVsync) board('CONFIG_LCD_RGB_RESTART_IN_VSYNC', 'y')
@@ -527,6 +593,8 @@ export function prepareEsp32Build({ ctx, selection, app = null, env = ctx.env ||
527
593
  let boardConsole = null
528
594
  let boardPsram = null
529
595
  let boardRgbPanel = false
596
+ let boardWireless = null
597
+ let boardCamera = null
530
598
  // Physical buttons: the board's JSON list with the app's changes, generated
531
599
  // into a header the firmware's button service includes.
532
600
  const buttons = resolveButtons({ board: selection.buttons || [], app, platform: 'esp32', boardId: selection.target })
@@ -563,6 +631,8 @@ export function prepareEsp32Build({ ctx, selection, app = null, env = ctx.env ||
563
631
  if (boardPsram && appEsp32Config?.psram) boardPsram = { ...boardPsram, ...appEsp32Config.psram }
564
632
  const display = generated.target.chips?.display
565
633
  boardRgbPanel = display?.interface === 'rgb' ? { restartInVsync: display.restartInVsync !== false } : false
634
+ boardWireless = generated.target.wireless
635
+ boardCamera = generated.target.camera
566
636
  log(`Generated custom board files in ${outDir} (${path.basename(generated.headerPath)}, ${path.basename(generated.cmakePath)})`)
567
637
  }
568
638
 
@@ -694,7 +764,9 @@ function preparePartitions(app, config, buildDir, targetId) {
694
764
  partitionCsv: appPartitionCsv || boardPartitionCsv,
695
765
  boardConsole,
696
766
  boardPsram,
697
- boardRgbPanel
767
+ boardRgbPanel,
768
+ boardWireless,
769
+ boardCamera
698
770
  }).save()
699
771
 
700
772
  const defaultsArg = [defaultsFile, appSdkconfigFile].filter(Boolean).join(';')
@@ -742,7 +814,24 @@ function runInTarget(command, args, { cwd, env, dryRun, verbose, label, logFile,
742
814
  // App capability flags are CMake cache entries. Reconfigure only when those
743
815
  // inputs change; ordinary source/CMake dependency changes remain the build
744
816
  // system's responsibility. This retains Ninja's sub-second no-op.
817
+ // A build directory belongs to the CMake project it was configured from, and
818
+ // CMake refuses to reuse it for another ("does not match the source used to
819
+ // generate cache"). A target whose project moved -- the esp32-p4 base moving
820
+ // onto the Waveshare 7-inch project -- leaves such a directory behind, so its
821
+ // cache goes and configure starts the directory afresh.
822
+ export function dropCacheFromOtherSource(buildDir, sourceDir) {
823
+ const cacheFile = path.join(buildDir, 'CMakeCache.txt')
824
+ if (!existsSync(cacheFile)) return false
825
+ const home = /^CMAKE_HOME_DIRECTORY:INTERNAL=(.*)$/m.exec(readFileSync(cacheFile, 'utf8'))?.[1]
826
+ const real = (dir) => (existsSync(dir) ? realpathSync(dir) : path.resolve(dir))
827
+ if (!home || real(home) === real(sourceDir)) return false
828
+ rmSync(cacheFile, { force: true })
829
+ rmSync(path.join(buildDir, 'CMakeFiles'), { recursive: true, force: true })
830
+ return true
831
+ }
832
+
745
833
  export async function ensureConfigured({ idf, prepared, env, dryRun = false, verbose = false, stdout, stderr = console.error }) {
834
+ if (!dryRun) dropCacheFromOtherSource(prepared.binaryDir || prepared.buildDir, prepared.targetDir)
746
835
  const signatureFile = path.join(prepared.buildDir, '.gea-configure-args')
747
836
  const signature = [`IDF_PATH=${idf.idfDir}`, `IDF_PYTHON_ENV_PATH=${idf.pythonEnv}`, `-DSDKCONFIG=${prepared.sdkconfigFile}`, `-DSDKCONFIG_DEFAULTS=${prepared.defaultsArg || prepared.defaultsFile}`, ...prepared.idfArgs, ...(prepared.sourceSet || [])].join('\n') + '\n'
748
837
  if (existsSync(path.join(prepared.buildDir, 'CMakeCache.txt')) && existsSync(signatureFile) && readFileSync(signatureFile, 'utf8') === signature) {