@geastack/cli 0.1.107 → 0.1.109

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.107",
3
+ "version": "0.1.109",
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.107",
41
+ "@geastack/targets": "^0.1.108",
42
42
  "picocolors": "^1.1.1",
43
43
  "serialport": "^13.0.0"
44
44
  },
@@ -15,6 +15,22 @@ export const knownBoards = Object.freeze([
15
15
  gps: false
16
16
  }
17
17
  },
18
+ {
19
+ id: 'waveshare-lcd-349',
20
+ label: 'Waveshare ESP32-S3 Touch LCD 3.49',
21
+ alias: 'lcd-349',
22
+ target: 'esp32-s3-touch-lcd-3.49',
23
+ adapter: 'esp32-idf',
24
+ mcu: 'ESP32-S3R8',
25
+ capabilities: {
26
+ display: '3.49 inch 172x640 IPS LCD (AXS15231B QSPI)',
27
+ touch: 'AXS15231B capacitive touch',
28
+ wireless: ['WiFi', 'BLE'],
29
+ storage: ['16 MB flash', '8 MB PSRAM', 'microSD'],
30
+ audio: ['ES8311 speaker', 'ES7210 microphone array'],
31
+ gps: false
32
+ }
33
+ },
18
34
  {
19
35
  id: 'waveshare-amoled-241',
20
36
  label: 'Waveshare ESP32-S3 Touch AMOLED 2.41 (V1)',
@@ -95,6 +111,22 @@ export const knownBoards = Object.freeze([
95
111
  gps: false
96
112
  }
97
113
  },
114
+ {
115
+ id: 'waveshare-amoled-175c',
116
+ label: 'Waveshare ESP32-S3 Touch AMOLED 1.75C',
117
+ alias: 'amoled-175c',
118
+ target: 'esp32-s3-touch-amoled-1.75c',
119
+ adapter: 'esp32-idf',
120
+ mcu: 'ESP32-S3R8',
121
+ capabilities: {
122
+ display: '1.75 inch 466x466 AMOLED (CO5300 QSPI)',
123
+ touch: 'CST9217 capacitive touch',
124
+ wireless: ['WiFi', 'BLE'],
125
+ storage: ['32 MB flash', '8 MB PSRAM'],
126
+ audio: ['ES8311 speaker', 'ES7210 dual microphones'],
127
+ gps: false
128
+ }
129
+ },
98
130
  {
99
131
  id: 'waveshare-lcd-154',
100
132
  label: 'Waveshare ESP32-S3 Touch LCD 1.54',
@@ -0,0 +1,198 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ // Physical buttons are JSON, never C++. A board lists its own under `buttons`
5
+ // (its targets.json entry, its composed definition, or its alias in
6
+ // boards.json), and an app adds or replaces entries by name under
7
+ // gea.targets.<platform>.buttons or gea.targets.<platform>.boards.<id>.buttons:
8
+ //
9
+ // { "code": "Boot", "pin": 0, "activeLevel": 0, "key": "Escape" }
10
+ // { "code": "Power", "source": "pmu", "key": "Enter" }
11
+ //
12
+ // The build turns the merged list into the native table the firmware reads.
13
+
14
+ export const maxButtons = 8
15
+
16
+ // Web key names a button may stand in for, with their legacy keyCodes. A key
17
+ // outside this list states its keyCode explicitly.
18
+ const keyCodes = {
19
+ Backspace: 8, Tab: 9, Enter: 13, Escape: 27, ' ': 32, Space: 32,
20
+ PageUp: 33, PageDown: 34, End: 35, Home: 36,
21
+ ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40, Delete: 46,
22
+ F1: 112, F2: 113, F3: 114, F4: 115, F5: 116, F6: 117, F7: 118, F8: 119, F9: 120, F10: 121, F11: 122, F12: 123
23
+ }
24
+
25
+ function keyCodeFor(key) {
26
+ if (key in keyCodes) return keyCodes[key]
27
+ if (/^[A-Za-z]$/.test(key)) return key.toUpperCase().charCodeAt(0)
28
+ if (/^[0-9]$/.test(key)) return key.charCodeAt(0)
29
+ return null
30
+ }
31
+
32
+ function isObject(value) {
33
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
34
+ }
35
+
36
+ // One entry, checked and filled in. `partial` allows an app entry that only
37
+ // changes some fields of a board button it names.
38
+ function normalizeButton(raw, where, { partial = false } = {}) {
39
+ if (!isObject(raw)) throw new Error(`${where} must be an object.`)
40
+ const known = ['code', 'key', 'keyCode', 'source', 'pin', 'activeLevel', 'poll', 'remove']
41
+ for (const name of Object.keys(raw)) {
42
+ if (!known.includes(name) && !name.startsWith('_')) throw new Error(`${where}.${name} is not a button setting (${known.join(', ')}).`)
43
+ }
44
+ if (typeof raw.code !== 'string' || !/^[A-Za-z][A-Za-z0-9]{0,23}$/.test(raw.code)) {
45
+ throw new Error(`${where}.code must be a name like "Boot" or "Key1" (letters and digits, starting with a letter).`)
46
+ }
47
+ const out = { code: raw.code }
48
+ if (raw.remove !== undefined) {
49
+ if (raw.remove !== true) throw new Error(`${where}.remove can only be true.`)
50
+ return { code: raw.code, remove: true }
51
+ }
52
+ if (raw.source !== undefined) {
53
+ if (!['gpio', 'pmu'].includes(raw.source)) throw new Error(`${where}.source must be "gpio" or "pmu".`)
54
+ out.source = raw.source
55
+ }
56
+ if (raw.pin !== undefined) {
57
+ if (!Number.isInteger(raw.pin) || raw.pin < 0 || raw.pin > 63) throw new Error(`${where}.pin must be a GPIO number.`)
58
+ out.pin = raw.pin
59
+ }
60
+ if (raw.activeLevel !== undefined) {
61
+ if (raw.activeLevel !== 0 && raw.activeLevel !== 1) throw new Error(`${where}.activeLevel must be 0 (pressed reads low) or 1.`)
62
+ out.activeLevel = raw.activeLevel
63
+ }
64
+ if (raw.poll !== undefined) {
65
+ if (typeof raw.poll !== 'boolean') throw new Error(`${where}.poll must be true or false.`)
66
+ out.poll = raw.poll
67
+ }
68
+ if (raw.key !== undefined) {
69
+ if (typeof raw.key !== 'string') throw new Error(`${where}.key must be a web key name such as "Escape", or "" for none.`)
70
+ out.key = raw.key
71
+ }
72
+ if (raw.keyCode !== undefined) {
73
+ if (!Number.isInteger(raw.keyCode) || raw.keyCode < 0 || raw.keyCode > 0xfffe) throw new Error(`${where}.keyCode must be a key code.`)
74
+ out.keyCode = raw.keyCode
75
+ }
76
+ if (partial) return out
77
+ return complete(out, where)
78
+ }
79
+
80
+ function complete(button, where) {
81
+ const source = button.source || 'gpio'
82
+ if (source === 'gpio' && button.pin === undefined) throw new Error(`${where} (${button.code}) needs a pin, or "source": "pmu".`)
83
+ if (source === 'pmu' && (button.pin !== undefined || button.poll !== undefined)) {
84
+ throw new Error(`${where} (${button.code}) is the PMU's power key; it takes no pin or poll.`)
85
+ }
86
+ const key = button.key || ''
87
+ let keyCode = button.keyCode
88
+ if (keyCode === undefined) {
89
+ keyCode = key ? keyCodeFor(key) : 0
90
+ if (keyCode === null) throw new Error(`${where} (${button.code}): no keyCode is known for key "${key}"; state "keyCode".`)
91
+ }
92
+ return {
93
+ code: button.code,
94
+ key,
95
+ keyCode,
96
+ source,
97
+ pin: source === 'gpio' ? button.pin : -1,
98
+ activeLevel: button.activeLevel ?? 0,
99
+ poll: Boolean(button.poll)
100
+ }
101
+ }
102
+
103
+ export function normalizeButtons(raw, where) {
104
+ if (raw === undefined || raw === null) return []
105
+ if (!Array.isArray(raw)) throw new Error(`${where} must be an array of buttons.`)
106
+ const buttons = raw.map((entry, index) => normalizeButton(entry, `${where}[${index}]`))
107
+ return validated(buttons, where)
108
+ }
109
+
110
+ // Later layers win by name: an entry naming an existing button replaces the
111
+ // fields it states, `"remove": true` drops it, and a new name is appended.
112
+ export function mergeButtons(base, layers) {
113
+ let buttons = base.map((button) => ({ ...button }))
114
+ for (const { raw, where } of layers) {
115
+ if (raw === undefined || raw === null) continue
116
+ if (!Array.isArray(raw)) throw new Error(`${where} must be an array of buttons.`)
117
+ raw.forEach((entry, index) => {
118
+ const label = `${where}[${index}]`
119
+ const change = normalizeButton(entry, label, { partial: true })
120
+ const at = buttons.findIndex((button) => button.code === change.code)
121
+ if (change.remove) {
122
+ if (at >= 0) buttons.splice(at, 1)
123
+ return
124
+ }
125
+ if (at < 0) {
126
+ buttons.push(complete(change, label))
127
+ return
128
+ }
129
+ const merged = { ...buttons[at], ...change }
130
+ if (change.source === 'pmu') delete merged.pin
131
+ if (change.key !== undefined && change.keyCode === undefined) delete merged.keyCode
132
+ buttons[at] = complete(merged, label)
133
+ })
134
+ }
135
+ return validated(buttons, layers.at(-1)?.where || 'buttons')
136
+ }
137
+
138
+ function validated(buttons, where) {
139
+ if (buttons.length > maxButtons) throw new Error(`${where}: at most ${maxButtons} buttons.`)
140
+ const names = new Set()
141
+ const pins = new Map()
142
+ let pmu = 0
143
+ for (const button of buttons) {
144
+ if (names.has(button.code)) throw new Error(`${where}: button "${button.code}" is declared twice.`)
145
+ names.add(button.code)
146
+ if (button.source === 'pmu' && ++pmu > 1) throw new Error(`${where}: only one button can be the PMU's power key.`)
147
+ if (button.pin >= 0) {
148
+ if (pins.has(button.pin)) throw new Error(`${where}: GPIO ${button.pin} is both "${pins.get(button.pin)}" and "${button.code}".`)
149
+ pins.set(button.pin, button.code)
150
+ }
151
+ }
152
+ return buttons
153
+ }
154
+
155
+ // The board's list, then the app's platform-wide and board-specific changes.
156
+ export function resolveButtons({ board = [], app = null, platform = 'esp32', boardId = '' }) {
157
+ const target = isObject(app?.manifest?.targets?.[platform]) ? app.manifest.targets[platform] : {}
158
+ const where = `gea.targets.${platform}`
159
+ return mergeButtons(board, [
160
+ { raw: target.buttons, where: `${where}.buttons` },
161
+ { raw: target.boards?.[boardId]?.buttons, where: `${where}.boards.${boardId}.buttons` }
162
+ ])
163
+ }
164
+
165
+ function cString(value) {
166
+ return JSON.stringify(value)
167
+ }
168
+
169
+ export function renderButtonsHeader(buttons) {
170
+ const rows = buttons.map((button) => {
171
+ const source = button.source === 'pmu' ? 'Pmu' : 'Gpio'
172
+ return `\t{${cString(button.code)}, ${cString(button.key)}, ${button.keyCode}, Source::${source}, ${button.pin}, ${button.activeLevel}, ${button.poll}},`
173
+ })
174
+ return `// Generated by gea from the board's and the app's "buttons". Do not edit.
175
+ #pragma once
176
+
177
+ #include "services/buttons.h"
178
+
179
+ #define GEA_BOARD_BUTTON_COUNT ${buttons.length}
180
+
181
+ namespace gea::platform::board {
182
+ ${buttons.length ? `using gea::platform::esp32::buttons::Source;
183
+ inline constexpr gea::platform::esp32::buttons::Button buttons[] = {
184
+ ${rows.join('\n')}
185
+ };` : ''}
186
+ } // namespace gea::platform::board
187
+ `
188
+ }
189
+
190
+ // Writes gea_board_buttons.h into `outDir` (only when it changed, so an
191
+ // unchanged list does not rebuild the firmware) and returns the directory.
192
+ export function writeButtonsHeader(outDir, buttons) {
193
+ mkdirSync(outDir, { recursive: true })
194
+ const file = path.join(outDir, 'gea_board_buttons.h')
195
+ const contents = renderButtonsHeader(buttons)
196
+ if (!existsSync(file) || readFileSync(file, 'utf8') !== contents) writeFileSync(file, contents)
197
+ return outDir
198
+ }
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { boardConfigOrigins, boardConfigPath, loadBoardConfig, normalizeBoardConfig } from './config.mjs'
5
5
  import { loadTargets } from './targets.mjs'
6
+ import { mergeButtons, normalizeButtons } from './buttons.mjs'
6
7
  import { resolveUsbSerialPort } from './usb.mjs'
7
8
 
8
9
  export const usbSerialAdapters = new Set(['esp32-idf', 'rp2350-pico'])
@@ -145,8 +146,19 @@ export function resolveBoardSelection({
145
146
  }
146
147
  }
147
148
 
149
+ // A composed definition describes its own module, so its buttons replace the
150
+ // base's; a registered alias then adds or changes buttons by name (a button
151
+ // someone wired onto this particular unit).
152
+ const boardButtons = mergeButtons(
153
+ definition
154
+ ? normalizeButtons(definition.buttons, `${targetDefinition} buttons`)
155
+ : normalizeButtons(targets[target]?.buttons, `targets.json ${target}.buttons`),
156
+ [{ raw: board?.buttons, where: `board '${boardName}' buttons` }]
157
+ )
158
+
148
159
  const selection = {
149
160
  boardName,
161
+ buttons: boardButtons,
150
162
  ...(adapter === 'linux-native' ? {linuxBoard: board} : {}),
151
163
  targetBase,
152
164
  target,
@@ -37,7 +37,7 @@ export const buildOptions = {
37
37
  // against a source's path with forward slashes.
38
38
  'native.jobs': { type: 'integer', min: 0 },
39
39
  'native.arch': { values: ['default', 'AVX2', 'AVX512'] },
40
- 'native.debugInfo': { type: 'boolean' },
40
+ 'native.debugInfo': { values: [false, true, 'lines'] },
41
41
  'native.lto': { values: ['off', 'thin'] },
42
42
  'native.ltoJobs': { type: 'integer', min: 0 },
43
43
  'native.ltoCache': { type: 'string' },
@@ -125,7 +125,7 @@ export function validateBuildManifest(manifest) {
125
125
  if (!isObject(target.boards)) fail(where + '.boards must be an object')
126
126
  for (const [id, board] of Object.entries(target.boards)) {
127
127
  if (!/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(id) || !isObject(board)) fail(where + '.boards must contain board IDs mapped to objects')
128
- for (const key of Object.keys(board)) if (!['build', 'cssDevicePixelRatio', 'defines'].includes(key)) fail(`Unknown setting ${where}.boards.${id}.${key}`)
128
+ for (const key of Object.keys(board)) if (!['build', 'cssDevicePixelRatio', 'defines', 'buttons'].includes(key)) fail(`Unknown setting ${where}.boards.${id}.${key}`)
129
129
  boardDefines(board.defines, where + '.boards.' + id + '.defines')
130
130
  flatten(board.build, where + '.boards.' + id + '.build')
131
131
  if (board.cssDevicePixelRatio !== undefined) ratio(board.cssDevicePixelRatio, where + '.boards.' + id + '.cssDevicePixelRatio')
@@ -7,6 +7,7 @@ import path from 'node:path'
7
7
 
8
8
  import { geastackHome } from '../boards/config.mjs'
9
9
  import { loadChipCatalogFromDir, writeCustomTarget } from '../boards/custom-target.mjs'
10
+ import { resolveButtons, writeButtonsHeader } from '../boards/buttons.mjs'
10
11
  import { CliError, ExitCode, fail } from '../errors.mjs'
11
12
  import { appCmakeMeta, appCmakeLdFragments, appTargetConfig, appTargetPaths } from '../manifest.mjs'
12
13
  import { quietSteps, runQuiet } from '../run.mjs'
@@ -461,6 +462,18 @@ export function prepareEsp32Build({ ctx, selection, app = null, env = ctx.env ||
461
462
  let boardPartitionCsv = ''
462
463
  let boardConsole = null
463
464
  let boardPsram = null
465
+ // Physical buttons: the board's JSON list with the app's changes, generated
466
+ // into a header the firmware's button service includes.
467
+ const buttons = resolveButtons({ board: selection.buttons || [], app, platform: 'esp32', boardId: selection.target })
468
+ if (buttons.length) {
469
+ const buttonsDir = writeButtonsHeader(path.join(binaryDir, 'gea-buttons'), buttons)
470
+ idfArgs.push(`-DGEA_BOARD_BUTTONS_DIR=${cmakeValue(buttonsDir)}`)
471
+ childEnv.GEA_BOARD_BUTTONS_DIR = buttonsDir
472
+ log(`Buttons: ${buttons.map((button) => `${button.code} (${button.source === 'pmu' ? 'PMU' : `GPIO${button.pin}${button.poll ? ', polled' : ''}`}${button.key ? ` = ${button.key}` : ''})`).join(', ')}`)
473
+ } else {
474
+ idfArgs.push('-DGEA_BOARD_BUTTONS_DIR=')
475
+ delete childEnv.GEA_BOARD_BUTTONS_DIR
476
+ }
464
477
  if (selection.targetDefinition) {
465
478
  // The board header and target.cmake are generated here, once; CMake only
466
479
  // includes them.
@@ -28,19 +28,23 @@ export function nativeCircleSourceNeedsSupport(text) {
28
28
  return /#\s*include\s*[<"](?:[^>"\n]*\/)?(?:canvas|display|canvas_element)\.h[>"]|\b(?:Canvas|CanvasElement|CanvasContext|CircleEntry|Display)\b|\b(?:fillCircle\w*|strokeCircle|fillRoundedRect\w*|strokeRoundedRect|drawImageCircle|drawImageRounded)\b/.test(text)
29
29
  }
30
30
 
31
+ // Native code drives the video host only through its headers or classes.
32
+ export function nativeVideoSourceNeedsSupport(text) {
33
+ return /#\s*include\s*[<"](?:[^>"\n]*\/)?(?:video|video_\w+|mjpeg|mjpeg_parser|rtc_h264|h264_\w+)\.h[>"]|\b(?:HTMLVideoElement|VideoElement|presentFrames|esp_h264_\w+)\b|\bvideo::/.test(text)
34
+ }
35
+
31
36
  export function withNativeCssFeatures(app, features) {
32
37
  if (!features.includes('renderer-occlusion-v1') && !features.includes('node-analysis-v1') && !features.includes('node-video-analysis-v1') && !features.includes('node-aux-v1') && !features.includes('css-storage-v1') && !features.some(feature => /^node-class-capacity-v1-[123]$/.test(feature)) && !features.some(feature => /^css-analysis-v(?:[1-9]|1[0123456789])$/.test(feature))) return features
33
38
  const sources = app.nativeSources || []
34
39
  const components = app.targetConfig?.esp32?.componentDirs || []
35
40
  if (!sources.length && !components.length) return features
36
41
  // The TS proof cannot bound custom native triangle producers, including
37
- // rendering hidden behind external headers or callback registration. Native
38
- // code can also drive the video host directly.
39
- features = [...new Set([...features, 'renderer-occlusion-triangles', 'node-listeners', 'node-attributes', 'node-default-styles', 'node-videos'])]
42
+ // rendering hidden behind external headers or callback registration.
43
+ features = [...new Set([...features, 'renderer-occlusion-triangles', 'node-listeners', 'node-attributes', 'node-default-styles'])]
40
44
  // Opaque native CSS writes can supply gradient/transform values even when
41
45
  // every source-visible custom property is a literal colour. Keep their
42
46
  // renderer caches as well as semantic fields.
43
- const retain = () => [...new Set([...features.filter(feature => !feature.startsWith('node-class-capacity-') && !feature.startsWith('node-class-storage-')), ...families, 'node-images', 'node-inputs', 'css-ranges-unknown', 'css-circle-cache-unbounded', 'renderer-circles', 'renderer-occlusion-triangles', 'renderer-transforms', 'renderer-linear-gradients', 'renderer-radial-gradients'])].sort()
47
+ const retain = () => [...new Set([...features.filter(feature => !feature.startsWith('node-class-capacity-') && !feature.startsWith('node-class-storage-')), ...families, 'node-images', 'node-inputs', 'node-videos', 'css-ranges-unknown', 'css-circle-cache-unbounded', 'renderer-circles', 'renderer-occlusion-triangles', 'renderer-transforms', 'renderer-linear-gradients', 'renderer-radial-gradients'])].sort()
44
48
  const root = path.resolve(app.root)
45
49
  const headers = new Map()
46
50
  const seen = new Set()
@@ -80,6 +84,9 @@ export function withNativeCssFeatures(app, features) {
80
84
  const text = fs.readFileSync(file, 'utf8')
81
85
  if (nativeCircleSourceNeedsSupport(text)) features = [...new Set([...features, 'css-circle-cache-unbounded', 'renderer-circles'])]
82
86
  if (nativeCssSourceNeedsSupport(text)) return retain()
87
+ // Native code can drive the video host directly; only code that names it
88
+ // keeps the H.264/MJPEG decoders.
89
+ if (nativeVideoSourceNeedsSupport(text)) features = [...new Set([...features, 'node-videos'])]
83
90
  // Follow app headers, including headers provided by another component's
84
91
  // include directory. ESP-IDF and C/C++ platform headers do not depend on
85
92
  // the UI engine. An external native package is opaque above.