@typecad/framework-zephyr 1.0.0-alpha.16 → 1.0.0-alpha.19
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/LICENSE +202 -21
- package/README.md +49 -87
- package/dist/as-built.d.ts +2 -2
- package/dist/as-built.js +2 -2
- package/dist/audit.d.ts +111 -0
- package/dist/audit.js +416 -0
- package/dist/boardgen.d.ts +1 -9
- package/dist/boardgen.js +288 -47
- package/dist/chips/resolve.js +20 -0
- package/dist/chips/types.d.ts +22 -1
- package/dist/debug-codegen.js +1 -1
- package/dist/display/bindings.d.ts +55 -0
- package/dist/display/bindings.js +316 -0
- package/dist/display/gfx.d.ts +2 -3
- package/dist/display/gfx.js +166 -154
- package/dist/display/index.js +20 -1
- package/dist/display/mipi-dbi-host.d.ts +9 -0
- package/dist/display/mipi-dbi-host.js +174 -0
- package/dist/display/profiles.d.ts +109 -4
- package/dist/display/profiles.js +270 -7
- package/dist/display/touch-adapter.js +119 -49
- package/dist/display/ui-adapter-eink.d.ts +2 -0
- package/dist/display/ui-adapter-eink.js +4 -0
- package/dist/display/ui-adapter-gray.d.ts +8 -0
- package/dist/display/ui-adapter-gray.js +170 -0
- package/dist/display/ui-adapter-mono.d.ts +13 -0
- package/dist/display/ui-adapter-mono.js +230 -0
- package/dist/display/ui-adapter-native.d.ts +10 -0
- package/dist/display/ui-adapter-native.js +295 -0
- package/dist/display/ui-adapter-shared.d.ts +11 -0
- package/dist/display/ui-adapter-shared.js +122 -0
- package/dist/display/ui-adapter.js +510 -558
- package/dist/doctor.js +4 -4
- package/dist/dt-config/custom-board.js +2 -2
- package/dist/dt-config/kconfig.d.ts +62 -1
- package/dist/dt-config/kconfig.js +141 -38
- package/dist/dt-config/overlay.d.ts +15 -2
- package/dist/dt-config/overlay.js +433 -18
- package/dist/framework.manifest.d.ts +10 -4
- package/dist/framework.manifest.js +133 -17
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -6
- package/dist/licenses.d.ts +2 -2
- package/dist/licenses.js +13 -92
- package/dist/lowering/can.d.ts +25 -0
- package/dist/lowering/can.js +97 -0
- package/dist/lowering/clock.d.ts +17 -0
- package/dist/lowering/clock.js +58 -0
- package/dist/lowering/fs.js +1 -1
- package/dist/lowering/gpio.js +0 -32
- package/dist/lowering/hid.d.ts +27 -0
- package/dist/lowering/hid.js +244 -0
- package/dist/lowering/http.js +264 -32
- package/dist/lowering/i2c.d.ts +8 -0
- package/dist/lowering/i2c.js +137 -5
- package/dist/lowering/i2s.d.ts +27 -0
- package/dist/lowering/i2s.js +98 -0
- package/dist/lowering/index.d.ts +9 -1
- package/dist/lowering/index.js +25 -1
- package/dist/lowering/interrupts.js +6 -0
- package/dist/lowering/matrix.d.ts +15 -0
- package/dist/lowering/matrix.js +63 -0
- package/dist/lowering/mqtt.js +110 -8
- package/dist/lowering/power.d.ts +3 -2
- package/dist/lowering/power.js +20 -45
- package/dist/lowering/pwm.js +25 -0
- package/dist/lowering/sensor.d.ts +2 -2
- package/dist/lowering/sensor.js +8 -4
- package/dist/lowering/strip.d.ts +16 -0
- package/dist/lowering/strip.js +70 -0
- package/dist/lowering/thread.js +5 -1
- package/dist/lowering/trace.d.ts +44 -0
- package/dist/lowering/trace.js +239 -0
- package/dist/lowering/uart.js +6 -1
- package/dist/lowering/usb.d.ts +3 -1
- package/dist/lowering/usb.js +16 -13
- package/dist/lowering/wdt.js +2 -29
- package/dist/sbom.d.ts +181 -0
- package/dist/sbom.js +901 -0
- package/dist/sdk/board-catalog-sync.d.ts +1 -3
- package/dist/sdk/board-catalog-sync.js +4 -10
- package/dist/strategy.d.ts +82 -46
- package/dist/strategy.js +639 -182
- package/dist/tmp-probe.d.ts +2 -0
- package/dist/tmp-probe.js +9 -0
- package/dist/toolchain/debug-config.d.ts +50 -90
- package/dist/toolchain/debug-config.js +239 -510
- package/dist/toolchain/env-check.d.ts +1 -3
- package/dist/toolchain/env-check.js +2 -7
- package/dist/toolchain/index.d.ts +28 -3
- package/dist/toolchain/index.js +498 -62
- package/dist/toolchain/runners.d.ts +16 -0
- package/dist/toolchain/runners.js +75 -0
- package/dist/toolchain/scaffold.d.ts +5 -2
- package/dist/toolchain/scaffold.js +79 -15
- package/dist/toolchain/west-discover.d.ts +6 -0
- package/dist/toolchain/west-discover.js +36 -13
- package/dist/toolchain/west-spawn.js +8 -2
- package/dist/west-inventory.d.ts +25 -0
- package/dist/west-inventory.js +97 -0
- package/installer/README.md +328 -328
- package/installer/install.sh +2 -2
- package/installer/templates/project/.typecad/activate-zephyr.ps1 +1 -1
- package/installer/templates/project/.typecad/activate-zephyr.sh +1 -1
- package/installer/templates/project/.vscode/settings.json +1 -1
- package/installer/templates/project/README.md +2 -2
- package/package.json +5 -5
- package/src/as-built.ts +206 -206
- package/src/audit.ts +529 -0
- package/src/boardgen.ts +265 -50
- package/src/chips/resolve.ts +21 -0
- package/src/chips/types.ts +10 -1
- package/src/display/bindings.ts +347 -0
- package/src/display/gfx.ts +318 -306
- package/src/display/index.ts +87 -70
- package/src/display/mipi-dbi-host.ts +183 -0
- package/src/display/profiles.ts +458 -139
- package/src/display/touch-adapter.ts +119 -49
- package/src/display/ui-adapter-eink.ts +13 -0
- package/src/display/ui-adapter-gray.ts +178 -0
- package/src/display/ui-adapter-mono.ts +238 -0
- package/src/display/ui-adapter-native.ts +304 -0
- package/src/display/ui-adapter-shared.ts +125 -0
- package/src/display/ui-adapter.ts +732 -781
- package/src/doctor.ts +4 -4
- package/src/dt-config/custom-board.ts +2 -2
- package/src/dt-config/kconfig.ts +647 -505
- package/src/dt-config/overlay.ts +1475 -1058
- package/src/framework.manifest.ts +659 -535
- package/src/index.ts +16 -6
- package/src/licenses.ts +346 -425
- package/src/lowering/can.ts +140 -0
- package/src/lowering/clock.ts +91 -0
- package/src/lowering/fs.ts +135 -135
- package/src/lowering/gpio.ts +0 -33
- package/src/lowering/hid.ts +261 -0
- package/src/lowering/http.ts +264 -32
- package/src/lowering/i2c.ts +142 -5
- package/src/lowering/i2s.ts +143 -0
- package/src/lowering/index.ts +18 -1
- package/src/lowering/interrupts.ts +6 -0
- package/src/lowering/matrix.ts +70 -0
- package/src/lowering/mqtt.ts +109 -8
- package/src/lowering/power.ts +41 -0
- package/src/lowering/pwm.ts +192 -167
- package/src/lowering/sensor.ts +159 -155
- package/src/lowering/strip.ts +81 -0
- package/src/lowering/thread.ts +5 -1
- package/src/lowering/trace.ts +270 -0
- package/src/lowering/uart.ts +6 -1
- package/src/lowering/usb.ts +16 -13
- package/src/lowering/wdt.ts +2 -25
- package/src/sbom.ts +1117 -0
- package/src/sdk/board-catalog-sync.ts +4 -25
- package/src/strategy.ts +2680 -2309
- package/src/toolchain/debug-config.ts +262 -522
- package/src/toolchain/env-check.ts +279 -285
- package/src/toolchain/index.ts +1792 -1359
- package/src/toolchain/runners.ts +80 -0
- package/src/toolchain/scaffold.ts +355 -296
- package/src/toolchain/west-discover.ts +35 -13
- package/src/toolchain/west-spawn.ts +174 -168
- package/src/west-inventory.ts +102 -0
- package/dist/async/timer-polyfill.d.ts +0 -10
- package/dist/async/timer-polyfill.js +0 -95
- package/dist/chips/board-overrides.d.ts +0 -7
- package/dist/chips/board-overrides.js +0 -11
- package/dist/chips/esp32.d.ts +0 -2
- package/dist/chips/esp32.js +0 -71
- package/dist/chips/esp32s3.d.ts +0 -2
- package/dist/chips/esp32s3.js +0 -103
- package/dist/chips/soc/.d.ts +0 -2
- package/dist/chips/soc/.js +0 -129
- package/dist/chips/soc/esp32.d.ts +0 -2
- package/dist/chips/soc/esp32.js +0 -120
- package/dist/chips/soc/esp32c3.d.ts +0 -2
- package/dist/chips/soc/esp32c3.js +0 -90
- package/dist/chips/soc/esp32c6.d.ts +0 -2
- package/dist/chips/soc/esp32c6.js +0 -109
- package/dist/chips/soc/esp32s3.d.ts +0 -2
- package/dist/chips/soc/esp32s3.js +0 -189
- package/dist/chips/soc/index.d.ts +0 -2
- package/dist/chips/soc/index.js +0 -23
- package/dist/chips/soc/nrf52840.d.ts +0 -2
- package/dist/chips/soc/nrf52840.js +0 -130
- package/dist/chips/soc/rp2040.d.ts +0 -2
- package/dist/chips/soc/rp2040.js +0 -141
- package/dist/chips/soc/rp2350a.d.ts +0 -2
- package/dist/chips/soc/rp2350a.js +0 -145
- package/dist/chips/soc/samd21g18a.d.ts +0 -2
- package/dist/chips/soc/samd21g18a.js +0 -143
- package/dist/chips/soc/stm32f411xe.d.ts +0 -2
- package/dist/chips/soc/stm32f411xe.js +0 -251
- package/dist/chips/xiao-ble.d.ts +0 -2
- package/dist/chips/xiao-ble.js +0 -100
- package/dist/lowering/pulse.d.ts +0 -7
- package/dist/lowering/pulse.js +0 -51
- package/dist/lowering/tone.d.ts +0 -10
- package/dist/lowering/tone.js +0 -63
- package/dist/lowering/worker-backing.d.ts +0 -14
- package/dist/lowering/worker-backing.js +0 -79
- package/dist/lowering/worker.d.ts +0 -6
- package/dist/lowering/worker.js +0 -14
- package/dist/sdk/board-data.generated.d.ts +0 -2
- package/dist/sdk/board-data.generated.js +0 -4
- package/dist/sdk/catalog-walker.d.ts +0 -90
- package/dist/sdk/catalog-walker.js +0 -682
- package/dist/sdk/dts-reader.d.ts +0 -83
- package/dist/sdk/dts-reader.js +0 -596
- package/src/debug-codegen.ts +0 -207
package/src/lowering/sensor.ts
CHANGED
|
@@ -1,155 +1,159 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Sensor lowering — Zephyr's uniform sensor API over the generated catalog
|
|
3
|
-
//
|
|
4
|
-
// One code shape for every part in @typecad/hal's sensor catalog: the op's
|
|
5
|
-
// part token resolves to the DT compatible, the bus string to the controller
|
|
6
|
-
// index, and the address to the I2C reg. The names are derived identically
|
|
7
|
-
// here (device handles), in strategy.ts state blocks, and in the overlay
|
|
8
|
-
// scanner (dt-config/overlay.ts + toolchain/index.ts) — the tc-pwm<pin>
|
|
9
|
-
// discipline: both sides derive from the same facts, so they cannot drift.
|
|
10
|
-
//
|
|
11
|
-
// Kconfig: nothing per-part. The in-tree driver Kconfigs are `default y` on
|
|
12
|
-
// DT_HAS_<COMPAT>_ENABLED, so the overlay's child node IS the enable switch;
|
|
13
|
-
// CONFIG_SENSOR (the umbrella under `if SENSOR`) is usage-gated in
|
|
14
|
-
// dt-config/kconfig.ts off the lowered `sensor_` tokens.
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
import { SENSOR_PART_INFO } from '@typecad/hal';
|
|
18
|
-
import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
|
|
19
|
-
import { parseControllerIndex } from './util.js';
|
|
20
|
-
|
|
21
|
-
/** Strip the 'SENSOR.' property-access prefix from a part token arg. */
|
|
22
|
-
export function sensorPartKey(part: string): string {
|
|
23
|
-
return part.replace(/^SENSOR\./, '');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Strip the 'CHAN.' property-access prefix from a channel arg. */
|
|
27
|
-
export function sensorChanName(chan: string): string {
|
|
28
|
-
return chan.replace(/^CHAN\./, '');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** All names a constructed sensor is known by, derived from the op facts. */
|
|
32
|
-
export interface SensorNames {
|
|
33
|
-
/** DT nodelabel of the child node the overlay emits
|
|
34
|
-
* (tc_<part>_i2c<N>_0x<addr> / tc_<part>_spi<N>_cs<pin>). */
|
|
35
|
-
dtLabel: string;
|
|
36
|
-
/** C device-handle variable (__tc_sensor_<stem>_dev). */
|
|
37
|
-
devVar: string;
|
|
38
|
-
/** C sensor_value scratch variable (__tc_sensor_<stem>_val). */
|
|
39
|
-
valVar: string;
|
|
40
|
-
/** The controller index the bus string carries. */
|
|
41
|
-
busIndex: number;
|
|
42
|
-
/** The bus port: I2C address or SPI CS pin. */
|
|
43
|
-
port: number;
|
|
44
|
-
/** 'i2c' | 'spi'. */
|
|
45
|
-
busKind: 'i2c' | 'spi';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Derive a sensor's DT/C++ names. The scanner regexes the emitted __tc_
|
|
49
|
-
* prefix form, so the part group must stay [a-z0-9_]+ and greedy. */
|
|
50
|
-
export function sensorNames(part: string, bus: string, port: number | string, busKind: string = 'i2c'): SensorNames {
|
|
51
|
-
const partKey = sensorPartKey(String(part));
|
|
52
|
-
const busIndex = parseControllerIndex(typeof bus === 'string' ? bus : String(bus));
|
|
53
|
-
const portNum = typeof port === 'number' ? port : parseInt(String(port));
|
|
54
|
-
const stem = busKind === 'spi'
|
|
55
|
-
? `${partKey}_spi${busIndex}_cs${portNum}`
|
|
56
|
-
:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'//
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Sensor lowering — Zephyr's uniform sensor API over the generated catalog
|
|
3
|
+
//
|
|
4
|
+
// One code shape for every part in @typecad/hal's sensor catalog: the op's
|
|
5
|
+
// part token resolves to the DT compatible, the bus string to the controller
|
|
6
|
+
// index, and the address to the I2C reg. The names are derived identically
|
|
7
|
+
// here (device handles), in strategy.ts state blocks, and in the overlay
|
|
8
|
+
// scanner (dt-config/overlay.ts + toolchain/index.ts) — the tc-pwm<pin>
|
|
9
|
+
// discipline: both sides derive from the same facts, so they cannot drift.
|
|
10
|
+
//
|
|
11
|
+
// Kconfig: nothing per-part. The in-tree driver Kconfigs are `default y` on
|
|
12
|
+
// DT_HAS_<COMPAT>_ENABLED, so the overlay's child node IS the enable switch;
|
|
13
|
+
// CONFIG_SENSOR (the umbrella under `if SENSOR`) is usage-gated in
|
|
14
|
+
// dt-config/kconfig.ts off the lowered `sensor_` tokens.
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
import { SENSOR_PART_INFO } from '@typecad/hal';
|
|
18
|
+
import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
|
|
19
|
+
import { parseControllerIndex } from './util.js';
|
|
20
|
+
|
|
21
|
+
/** Strip the 'SENSOR.' property-access prefix from a part token arg. */
|
|
22
|
+
export function sensorPartKey(part: string): string {
|
|
23
|
+
return part.replace(/^SENSOR\./, '');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Strip the 'CHAN.' property-access prefix from a channel arg. */
|
|
27
|
+
export function sensorChanName(chan: string): string {
|
|
28
|
+
return chan.replace(/^CHAN\./, '');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** All names a constructed sensor is known by, derived from the op facts. */
|
|
32
|
+
export interface SensorNames {
|
|
33
|
+
/** DT nodelabel of the child node the overlay emits
|
|
34
|
+
* (tc_<part>_i2c<N>_0x<addr> / tc_<part>_spi<N>_cs<pin>). */
|
|
35
|
+
dtLabel: string;
|
|
36
|
+
/** C device-handle variable (__tc_sensor_<stem>_dev). */
|
|
37
|
+
devVar: string;
|
|
38
|
+
/** C sensor_value scratch variable (__tc_sensor_<stem>_val). */
|
|
39
|
+
valVar: string;
|
|
40
|
+
/** The controller index the bus string carries. */
|
|
41
|
+
busIndex: number;
|
|
42
|
+
/** The bus port: I2C address or SPI CS pin. */
|
|
43
|
+
port: number;
|
|
44
|
+
/** 'i2c' | 'spi'. */
|
|
45
|
+
busKind: 'i2c' | 'spi' | 'w1';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Derive a sensor's DT/C++ names. The scanner regexes the emitted __tc_
|
|
49
|
+
* prefix form, so the part group must stay [a-z0-9_]+ and greedy. */
|
|
50
|
+
export function sensorNames(part: string, bus: string, port: number | string, busKind: string = 'i2c'): SensorNames {
|
|
51
|
+
const partKey = sensorPartKey(String(part));
|
|
52
|
+
const busIndex = parseControllerIndex(typeof bus === 'string' ? bus : String(bus));
|
|
53
|
+
const portNum = typeof port === 'number' ? port : parseInt(String(port));
|
|
54
|
+
const stem = busKind === 'spi'
|
|
55
|
+
? `${partKey}_spi${busIndex}_cs${portNum}`
|
|
56
|
+
: busKind === 'w1'
|
|
57
|
+
? `${partKey}_w1_p${portNum}`
|
|
58
|
+
: `${partKey}_i2c${busIndex}_0x${portNum.toString(16)}`;
|
|
59
|
+
return {
|
|
60
|
+
dtLabel: `tc_${stem}`,
|
|
61
|
+
devVar: `__tc_sensor_${stem}_dev`,
|
|
62
|
+
valVar: `__tc_sensor_${stem}_val`,
|
|
63
|
+
busIndex,
|
|
64
|
+
port: portNum,
|
|
65
|
+
busKind: busKind === 'spi' ? 'spi' : busKind === 'w1' ? 'w1' : 'i2c',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Resolve the part token against the generated catalog, validating the bus
|
|
71
|
+
* kind and (when the driver scan knows them) the channel. Throws a build-time
|
|
72
|
+
* error with the Zephyr-facing name — the same words the user would meet in
|
|
73
|
+
* Zephyr docs, checked before west ever runs.
|
|
74
|
+
*/
|
|
75
|
+
/** @internal */
|
|
76
|
+
function requirePartInfo(partKey: string) {
|
|
77
|
+
const info = SENSOR_PART_INFO[partKey];
|
|
78
|
+
if (!info) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Sensor part '${partKey}' is not in the Zephyr sensor catalog (SENSOR in @typecad/hal). ` +
|
|
81
|
+
`Check the token against the catalog — it is the compatible with , and - replaced by _.`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return info;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Validate the op's bus kind against the part's bindings. */
|
|
88
|
+
function requireBusKind(partKey: string, info: ReturnType<typeof requirePartInfo>, busKind: string) {
|
|
89
|
+
if (!info.buses.includes(busKind)) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Sensor part '${partKey}' (${info.compatible}) does not bind on ${busKind.toUpperCase()} — ` +
|
|
92
|
+
`its bindings are ${info.buses.join('/').toUpperCase()}.`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Emit the per-sensor state block (device handle + sensor_value scratch).
|
|
99
|
+
* Called from shimLines for each distinct sensor the program's ops reference.
|
|
100
|
+
*/
|
|
101
|
+
export function sensorStateLines(part: string, bus: string, port: number | string, busKind: string = 'i2c', spiHz: number | string = 0, spiMode: number | string = 0, alertPin: number | string = -1, resolution: number | string = 12): string[] {
|
|
102
|
+
const partKey = sensorPartKey(String(part));
|
|
103
|
+
requireBusKind(partKey, requirePartInfo(partKey), busKind);
|
|
104
|
+
const n = sensorNames(part, bus, port, busKind);
|
|
105
|
+
// The config comment carries construction facts (SPI clock, mode, alert
|
|
106
|
+
// GPIO) to the overlay scanner — they shape the DT node, not the C++.
|
|
107
|
+
const cfg = busKind === 'w1'
|
|
108
|
+
? `// tc-sensor-cfg: ${n.dtLabel} res=${Number(resolution)}`
|
|
109
|
+
: `// tc-sensor-cfg: ${n.dtLabel} hz=${Number(spiHz)} mode=${Number(spiMode)} alert=${Number(alertPin)}`;
|
|
110
|
+
return [
|
|
111
|
+
'// CUTTLEFISH_SENSOR_BEGIN',
|
|
112
|
+
`static const struct device* ${n.devVar} = DEVICE_DT_GET(DT_NODELABEL(${n.dtLabel}));`,
|
|
113
|
+
`static struct sensor_value ${n.valVar};`,
|
|
114
|
+
cfg,
|
|
115
|
+
'// CUTTLEFISH_SENSOR_END',
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolve a HAL sensor.* op to Zephyr C++.
|
|
121
|
+
* Returns `{ code }` for fetch (statement), `{ expression }` for get (value).
|
|
122
|
+
*/
|
|
123
|
+
export function lowerSensor(op: HALOpIR): { code?: string; expression?: string } {
|
|
124
|
+
const o = op as any;
|
|
125
|
+
const partKey = sensorPartKey(String(o.part));
|
|
126
|
+
const info = requirePartInfo(partKey);
|
|
127
|
+
requireBusKind(partKey, info, String(o.busKind ?? 'i2c'));
|
|
128
|
+
const n = sensorNames(o.part, o.bus, o.port ?? o.address, String(o.busKind ?? 'i2c'));
|
|
129
|
+
|
|
130
|
+
switch (op.operation) {
|
|
131
|
+
case 'sensor.fetch':
|
|
132
|
+
// sensor_sample_fetch. The leading (void) keeps the value scratch
|
|
133
|
+
// referenced under Zephyr's -Werror when the program fetches but never
|
|
134
|
+
// reads a channel (the state block is emitted per referenced sensor).
|
|
135
|
+
return {
|
|
136
|
+
code: `(void)${n.valVar}; sensor_sample_fetch(${n.devVar});`,
|
|
137
|
+
};
|
|
138
|
+
case 'sensor.get': {
|
|
139
|
+
const chan = sensorChanName(String(o.chan));
|
|
140
|
+
if (info.channels.length > 0 && !info.channels.includes(chan)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Sensor part '${partKey}' (${info.compatible}) does not serve channel '${chan}' — ` +
|
|
143
|
+
`its driver serves: ${info.channels.join(', ')}.`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
// sensor_value is val1 + val2 * 1e-6; evaluate once per read.
|
|
147
|
+
return {
|
|
148
|
+
expression:
|
|
149
|
+
`(sensor_channel_get(${n.devVar}, SENSOR_CHAN_${chan}, &${n.valVar}), ` +
|
|
150
|
+
`static_cast<double>(${n.valVar}.val1) + static_cast<double>(${n.valVar}.val2) / 1000000.0)`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
throw new Error(
|
|
155
|
+
`framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
|
|
156
|
+
`Open an issue or use rawCpp() to emit it manually.`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Strip lowering — ws2812-spi child node + led_strip_update_rgb
|
|
3
|
+
//
|
|
4
|
+
// The strip is an spi-device child of one of the board's wired SPI
|
|
5
|
+
// controllers (Zephyr's ws2812-spi driver synthesizes the WS2812 waveform
|
|
6
|
+
// on the bus's MOSI line — the board-equal form: the strip uses whatever
|
|
7
|
+
// pads the board's devicetree routes that SPI to). The shim block declares
|
|
8
|
+
// the pixel buffer + device handle; the overlay generator synthesizes the
|
|
9
|
+
// DT child node (chain length + tuned frames — see dt-config/overlay.ts).
|
|
10
|
+
// set/fill edit the buffer; show() is one led_strip_update_rgb.
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
import type { HALOpIR } from '@typecad/cuttlefish/api/shared';
|
|
14
|
+
import type { ZephyrChipDescriptor } from '../chips/types.js';
|
|
15
|
+
import { parseControllerIndex } from './util.js';
|
|
16
|
+
|
|
17
|
+
/** The C variable names for a strip on controller index `idx`. */
|
|
18
|
+
function stripVars(idx: number): { buf: string; dev: string } {
|
|
19
|
+
return { buf: `__tc_strip${idx}_buf`, dev: `__tc_strip${idx}_dev` };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Emit the per-strip state. Called from shimLines for each SPI controller
|
|
24
|
+
* the program drives a strip on: one `struct led_rgb` buffer sized by the
|
|
25
|
+
* construction chain length + the DT device handle.
|
|
26
|
+
*/
|
|
27
|
+
export function stripInitLines(chip: ZephyrChipDescriptor, busIndex: number, count: number): string[] {
|
|
28
|
+
const ctrl = chip.spi?.controllers[busIndex];
|
|
29
|
+
if (!ctrl) return [];
|
|
30
|
+
const { buf, dev } = stripVars(busIndex);
|
|
31
|
+
return [
|
|
32
|
+
'// CUTTLEFISH_STRIP_BEGIN',
|
|
33
|
+
`static struct led_rgb ${buf}[${count}];`,
|
|
34
|
+
`static const struct device* ${dev} = DEVICE_DT_GET(DT_NODELABEL(tc_strip${busIndex}));`,
|
|
35
|
+
'// CUTTLEFISH_STRIP_END',
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolve a HAL strip.* op to Zephyr C++.
|
|
41
|
+
* Returns `{ code }` for statement ops.
|
|
42
|
+
*/
|
|
43
|
+
export function lowerStrip(
|
|
44
|
+
op: HALOpIR,
|
|
45
|
+
chip: ZephyrChipDescriptor,
|
|
46
|
+
): { code?: string; expression?: string } {
|
|
47
|
+
const o = op as any;
|
|
48
|
+
// DAC discipline: a board with no wired SPI (or an out-of-range bus)
|
|
49
|
+
// lowers to a comment naming the constraint — the honest per-board answer
|
|
50
|
+
// (the manifest probe runs boardless; profileDiagnostics flags the usage).
|
|
51
|
+
const idx = parseControllerIndex(typeof o.bus === 'string' ? o.bus : String(o.bus));
|
|
52
|
+
if (!chip.spi || idx >= chip.spi.controllers.length) {
|
|
53
|
+
const wired = chip.spi ? `this board wires ${chip.spi.controllers.length} SPI controller(s)` : 'this board wires no SPI controller';
|
|
54
|
+
return { code: `/* strip on bus ${o.bus}: no such SPI controller — ${wired}; a Strip rides one of the board's SPI buses */` };
|
|
55
|
+
}
|
|
56
|
+
const { buf, dev } = stripVars(idx);
|
|
57
|
+
const count = Number(o.count ?? 1) || 1;
|
|
58
|
+
|
|
59
|
+
switch (op.operation) {
|
|
60
|
+
case 'strip.set_pixel': {
|
|
61
|
+
// Buffer assignment — runtime index and channel values splice as C++.
|
|
62
|
+
// The driver applies the strip's color order (GRB mapping) at show.
|
|
63
|
+
return {
|
|
64
|
+
code: `{ uint32_t __tc_strip_i = static_cast<uint32_t>(${o.index}); if (__tc_strip_i < ${count}U) { ${buf}[__tc_strip_i].r = static_cast<uint8_t>(${o.r}); ${buf}[__tc_strip_i].g = static_cast<uint8_t>(${o.g}); ${buf}[__tc_strip_i].b = static_cast<uint8_t>(${o.b}); } }`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case 'strip.fill': {
|
|
68
|
+
return {
|
|
69
|
+
code: `{ for (uint32_t __tc_strip_j = 0U; __tc_strip_j < ${count}U; ++__tc_strip_j) { ${buf}[__tc_strip_j].r = static_cast<uint8_t>(${o.r}); ${buf}[__tc_strip_j].g = static_cast<uint8_t>(${o.g}); ${buf}[__tc_strip_j].b = static_cast<uint8_t>(${o.b}); } }`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
case 'strip.show': {
|
|
73
|
+
return { code: `(void)led_strip_update_rgb(${dev}, ${buf}, ${count}U);` };
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(
|
|
77
|
+
`framework-zephyr does not yet support HAL op \`${op.operation}\`. ` +
|
|
78
|
+
`Open an issue or use rawCpp() to emit it manually.`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/lowering/thread.ts
CHANGED
|
@@ -48,8 +48,12 @@ export function lowerThread(op: HALOpIR): { code?: string; expression?: string }
|
|
|
48
48
|
case 'thread.start': {
|
|
49
49
|
// Store the entry, create + schedule immediately. The stack size comes
|
|
50
50
|
// from the state block (the construction fact), via K_THREAD_STACK_SIZEOF.
|
|
51
|
+
// The thread gets a name so trace heartbeats report it as something
|
|
52
|
+
// other than "unnamed" — k_thread_name_set returns -ENOSYS without
|
|
53
|
+
// CONFIG_THREAD_NAME (which the scaffold turns on for traced builds),
|
|
54
|
+
// so the call is emitted unconditionally.
|
|
51
55
|
return {
|
|
52
|
-
code: `${p}_fn = (${o.handler}); (void)k_thread_create(&${p}_thread, ${p}_stack, K_THREAD_STACK_SIZEOF(${p}_stack), ${p}_tramp, NULL, NULL, NULL, ${o.priority ?? 5}, 0, K_NO_WAIT);`,
|
|
56
|
+
code: `${p}_fn = (${o.handler}); (void)k_thread_create(&${p}_thread, ${p}_stack, K_THREAD_STACK_SIZEOF(${p}_stack), ${p}_tramp, NULL, NULL, NULL, ${o.priority ?? 5}, 0, K_NO_WAIT); (void)k_thread_name_set(&${p}_thread, "tc_thread_${instance}");`,
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
59
|
case 'thread.join':
|