@typecad/hal 1.0.0-alpha.13 → 1.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +145 -87
  2. package/dist/adc-pin.d.ts +53 -0
  3. package/dist/adc-pin.js +69 -0
  4. package/dist/async.d.ts +3 -11
  5. package/dist/async.js +3 -15
  6. package/dist/ble.d.ts +42 -78
  7. package/dist/ble.js +79 -98
  8. package/dist/counter.d.ts +16 -0
  9. package/dist/counter.js +32 -0
  10. package/dist/dac-pin.d.ts +13 -0
  11. package/dist/dac-pin.js +21 -0
  12. package/dist/emit.d.ts +123 -196
  13. package/dist/emit.js +146 -208
  14. package/dist/fs.d.ts +12 -31
  15. package/dist/fs.js +30 -40
  16. package/dist/gpio-pin.d.ts +46 -0
  17. package/dist/gpio-pin.js +77 -0
  18. package/dist/gpio.d.ts +0 -103
  19. package/dist/gpio.js +16 -227
  20. package/dist/http.d.ts +38 -39
  21. package/dist/http.js +53 -78
  22. package/dist/i2c-target.d.ts +28 -0
  23. package/dist/i2c-target.js +52 -0
  24. package/dist/i2c.d.ts +5 -43
  25. package/dist/i2c.js +17 -130
  26. package/dist/index.d.ts +30 -42
  27. package/dist/index.js +27 -39
  28. package/dist/math.d.ts +0 -13
  29. package/dist/math.js +9 -13
  30. package/dist/mqtt.d.ts +15 -25
  31. package/dist/mqtt.js +32 -28
  32. package/dist/power.d.ts +9 -17
  33. package/dist/power.js +22 -20
  34. package/dist/preferences.d.ts +17 -25
  35. package/dist/preferences.js +54 -52
  36. package/dist/pulse.d.ts +4 -4
  37. package/dist/pulse.js +6 -2
  38. package/dist/pwm-pin.d.ts +24 -0
  39. package/dist/pwm-pin.js +38 -0
  40. package/dist/random.d.ts +0 -2
  41. package/dist/random.js +14 -20
  42. package/dist/sensor-catalog.generated.d.ts +997 -0
  43. package/dist/sensor-catalog.generated.js +764 -0
  44. package/dist/sensor.d.ts +46 -0
  45. package/dist/sensor.js +52 -0
  46. package/dist/shift-pin.d.ts +2 -0
  47. package/dist/shift-pin.js +13 -0
  48. package/dist/spi-target.d.ts +25 -0
  49. package/dist/spi-target.js +42 -0
  50. package/dist/spi.d.ts +8 -26
  51. package/dist/spi.js +15 -87
  52. package/dist/thread.d.ts +18 -0
  53. package/dist/thread.js +36 -0
  54. package/dist/time.d.ts +23 -0
  55. package/dist/time.js +43 -0
  56. package/dist/timing.d.ts +17 -7
  57. package/dist/timing.js +17 -7
  58. package/dist/types.d.ts +4 -34
  59. package/dist/types.js +5 -47
  60. package/dist/uart-port.d.ts +26 -0
  61. package/dist/uart-port.js +52 -0
  62. package/dist/uart.d.ts +0 -17
  63. package/dist/uart.js +10 -53
  64. package/dist/usb.d.ts +26 -0
  65. package/dist/usb.js +66 -0
  66. package/dist/watchdog.d.ts +12 -0
  67. package/dist/watchdog.js +28 -0
  68. package/dist/wifi.d.ts +88 -64
  69. package/dist/wifi.js +112 -126
  70. package/dist/zephyr-tokens.generated.d.ts +8 -0
  71. package/dist/zephyr-tokens.generated.js +73 -0
  72. package/package.json +7 -8
  73. package/src/adc-pin.ts +89 -0
  74. package/src/async.ts +3 -16
  75. package/src/ble.ts +84 -111
  76. package/src/counter.ts +40 -0
  77. package/src/dac-pin.ts +28 -0
  78. package/src/emit.ts +157 -238
  79. package/src/fs.ts +47 -54
  80. package/src/gpio-pin.ts +91 -0
  81. package/src/gpio.ts +49 -320
  82. package/src/http.ts +75 -95
  83. package/src/i2c-target.ts +63 -0
  84. package/src/i2c.ts +29 -167
  85. package/src/index.ts +32 -46
  86. package/src/math.ts +9 -14
  87. package/src/mqtt.ts +39 -31
  88. package/src/preferences.ts +52 -61
  89. package/src/pwm-pin.ts +54 -0
  90. package/src/random.ts +14 -21
  91. package/src/sensor-catalog.generated.ts +1238 -0
  92. package/src/sensor.ts +80 -0
  93. package/src/shift-pin.ts +16 -0
  94. package/src/spi-target.ts +53 -0
  95. package/src/spi.ts +27 -121
  96. package/src/thread.ts +44 -0
  97. package/src/time.ts +50 -0
  98. package/src/types.ts +14 -89
  99. package/src/uart-port.ts +64 -0
  100. package/src/usb.ts +82 -0
  101. package/src/watchdog.ts +35 -0
  102. package/src/wifi.ts +147 -179
  103. package/src/zephyr-tokens.generated.ts +77 -0
  104. package/src/adc.ts +0 -30
  105. package/src/capacitive.ts +0 -31
  106. package/src/constants.ts +0 -23
  107. package/src/dac.ts +0 -21
  108. package/src/eeprom.ts +0 -26
  109. package/src/interrupts.ts +0 -35
  110. package/src/mdns.ts +0 -50
  111. package/src/ota.ts +0 -44
  112. package/src/power.ts +0 -36
  113. package/src/pulse.ts +0 -63
  114. package/src/rmt.ts +0 -125
  115. package/src/shift.ts +0 -88
  116. package/src/temperature.ts +0 -20
  117. package/src/timer.ts +0 -58
  118. package/src/timing.ts +0 -67
  119. package/src/uart.ts +0 -77
  120. package/src/utils.ts +0 -17
  121. package/src/wdt.ts +0 -17
package/src/emit.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  // framework-specific C++ at code generation time.
7
7
  //
8
8
  // EMIT BOUNDARY: This file is a canonical entry point of the HAL lowering
9
- // surface (A) — its C++ output lands in user sketches. The emitted bytes are
9
+ // surface (A) — its C++ output lands in user programs. The emitted bytes are
10
10
  // covered by the TypeCAD Runtime Exception (see RUNTIME_EXCEPTION.md at the
11
11
  // repository root) and are not subject to the license of this tool source.
12
12
  //
@@ -15,6 +15,8 @@
15
15
  // to framework pin numbers via the MCU package's pin mapping.
16
16
  // ---------------------------------------------------------------------------
17
17
 
18
+ import type { SerialValue } from './types.js';
19
+
18
20
  // ---------------------------------------------------------------------------
19
21
  // GPIO — digital pin control
20
22
  // ---------------------------------------------------------------------------
@@ -25,318 +27,221 @@ export function gpioWrite(pin: number | string, value: number | boolean): void {
25
27
  export function gpioRead(pin: number | string): number { return 0; }
26
28
  /** Toggle a digital pin. */
27
29
  export function gpioToggle(pin: number | string): void {}
28
- /** Set pin mode: "output" | "input" | "input_pullup" | "input_pulldown". */
29
- export function gpioSetMode(pin: number | string, mode: string): void {}
30
+ /** Thin GPIO (hal/gpio-pin.ts): configure with Zephyr flag tokens
31
+ * ("GPIO.OUTPUT | GPIO.PULL_UP"). The lowering maps token names to the
32
+ * GPIO_* macros; the emitted configure is guarded per pin (first use wins). */
33
+ export function gpioConfigure(pin: number | string, flags: number | string): void {}
34
+ /** GPIO.shiftOut/shiftIn: bit-banged shift via two pins (one op each). */
35
+ export function gpioShiftOut(dataPin: number | import('./gpio.js').Pin, clockPin: number | import('./gpio.js').Pin, value: number, msbFirst: boolean): void {}
36
+ export function gpioShiftIn(dataPin: number | import('./gpio.js').Pin, clockPin: number | import('./gpio.js').Pin, msbFirst: boolean): number { return 0; }
37
+
38
+ /** Thin GPIO read with FUSED guarded configure — one op, one statement-
39
+ * expression: correct in any expression position (if-conditions drop a
40
+ * method's leading side-effect ops, so get() must not rely on a separate
41
+ * configure op). */
42
+ export function gpioReadCfg(pin: number | string, flags: number | string): number { return 0; }
30
43
 
31
44
  // ---------------------------------------------------------------------------
32
45
  // PWM — pulse-width modulation
33
46
  // ---------------------------------------------------------------------------
34
47
 
35
- /** Write PWM duty cycle to a pin. */
36
- export function pwmWrite(pin: number | string, duty: number): void {}
37
-
38
- // ---------------------------------------------------------------------------
39
- // RMT Remote Control Transceiver (addressable LEDs, IR, raw digital waveforms)
40
- // ---------------------------------------------------------------------------
41
- // rmtTxInit/rmtRxInit are POSITIONAL semantic primitives the ergonomic
42
- // opts-object form lives in hal/rmt.ts (which destructures and forwards). The
43
- // resolver collapses object literals, so HALOpIR fields must be scalars; the
44
- // rmt.ts wrapper bridges the ergonomic API to these positional calls.
45
- //
46
- // Pin params accept Pin | number | string so callers can pass a board alias
47
- // like LED (a Pin object) directly; the transpiler resolves it to its number.
48
- import type { Pin } from './gpio.js';
49
- type RmtPin = Pin | number | string;
50
-
51
- /** Positional semantic primitive. Args: pin, resolutionHz, bit0Hi, bit0Lo,
52
- * bit1Hi, bit1Lo, msbFirst, queueDepth. Use rmtTxInit() from hal/rmt.ts. */
53
- export function rmtTxInit(
54
- pin: RmtPin,
55
- resolutionHz: number,
56
- bit0Hi: number, bit0Lo: number, bit1Hi: number, bit1Lo: number,
57
- msbFirst: boolean, queueDepth: number,
58
- ): void {}
59
- /** Write bytes via the channel's bytes-encoder (timings fixed at init). */
60
- export function rmtTxWriteBytes(pin: RmtPin, bytes: number[] | Uint8Array): void {}
61
- /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
62
- export function rmtTxWriteSymbols(pin: RmtPin, symbols: [number, number][]): void {}
63
- /** Block until the queued TX completes. */
64
- export function rmtTxWaitDone(pin: RmtPin, timeoutMs?: number): void {}
65
- /** Tear down the TX channel and release its slot. */
66
- export function rmtTxDeinit(pin: RmtPin): void {}
67
-
68
- /** Positional semantic primitive — use rmtRxInit() from hal/rmt.ts. */
69
- export function rmtRxInit(pin: RmtPin, resolutionHz: number): void {}
70
- /** Register a callback-by-name invoked when an RX burst completes. */
71
- export function rmtRxOnReceived(pin: RmtPin, handler: string): void {}
72
- /** Start receiving. */
73
- export function rmtRxStart(pin: RmtPin): void {}
74
- /** Stop receiving. */
75
- export function rmtRxStop(pin: RmtPin): void {}
76
- /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
77
- export function rmtRxRead(pin: RmtPin, maxCount: number): number[] { return []; }
78
- /** Tear down the RX channel and release its slot. */
79
- export function rmtRxDeinit(pin: RmtPin): void {}
48
+ /** Thin PWM (hal/pwm-pin.ts): set pulse width in ns against the constructed
49
+ * period. The first use also applies the construction period
50
+ * (pwm_set_dt with an idle pulse), then pwm_set_pulse_dt. */
51
+ export function pwmSetPulse(pin: number | string, periodNs: number, pulseNs: number, controller: string = '', channel: number = -1): void {}
52
+ /** Thin PWM duty sugar: pulse = duty(0.0–1.0) × periodNs one
53
+ * pwm_set_pulse_dt call, no 0–255 scaling. */
54
+ export function pwmSetDuty(pin: number | string, periodNs: number, duty: number, controller: string = '', channel: number = -1): void {}
55
+ /** Thin PWM: change the period at runtime (pwm_set_dt; the pulse resets to
56
+ * idle Zephyr 4.4 has no period-only setter). */
57
+ export function pwmSetPeriod(pin: number | string, periodNs: number, controller: string = '', channel: number = -1): void {}
80
58
 
81
59
  // ---------------------------------------------------------------------------
82
60
  // ADC — analog-to-digital conversion
83
61
  // ---------------------------------------------------------------------------
84
62
 
85
- /** Read analog value from a pin. */
86
- export function adcRead(pin: number | string): number { return 0; }
87
- /** Read analog voltage from a pin (ADC value converted to voltage). */
88
- export function adcReadVoltage(pin: number | string): number { return 0; }
89
- /** Set the analog reference. */
90
- export function adcSetReference(ref: string | number): void {}
63
+ /** Thin ADC (hal/adc-pin.ts): raw read with construction-time gain/reference
64
+ * tokens ("ADC.GAIN_1_4" / "ADC.REF_INTERNAL"); empty strings
65
+ * mean "use the chip descriptor's defaults". */
66
+ export function adcReadRaw(pin: number | string, gain: number | string, reference: number | string, channel: number = -1, device: string = '', pinctrl: string = ''): number { return 0; }
67
+ /** Thin ADC: millivolts read (adc_raw_to_millivolts) with the same
68
+ * construction-time gain/reference tokens. */
69
+ export function adcReadMv(pin: number | string, gain: number | string, reference: number | string, channel: number = -1, device: string = '', pinctrl: string = ''): number { return 0; }
91
70
 
92
71
  // ---------------------------------------------------------------------------
93
72
  // Interrupts
94
73
  // ---------------------------------------------------------------------------
95
74
 
96
- /** Attach an interrupt handler to a pin. */
97
- export function interruptAttach(pin: number | string, handler: string, mode: string): void {}
75
+ /** Thin GPIO interrupts (hal/gpio-pin.ts onInterrupt): attach with Zephyr
76
+ * INT_* tokens ("GPIO.INT_EDGE_FALLING") instead of mode strings. */
77
+ export function interruptAttachFlags(pin: number | string, handler: string, intFlags: number | string): void {}
98
78
  /** Detach an interrupt from a pin. */
99
79
  export function interruptDetach(pin: number | string): void {}
100
80
 
101
- // ---------------------------------------------------------------------------
102
- // Tone / audio output
103
- // ---------------------------------------------------------------------------
104
-
105
- /** Play a tone on a pin at the given frequency, optionally for a duration. */
106
- export function tonePlay(pin: number | string, frequency: number, duration?: number): void {}
107
- /** Stop tone playback on a pin. */
108
- export function toneStop(pin: number | string): void {}
109
-
110
81
  // ---------------------------------------------------------------------------
111
82
  // Timing
112
83
  // ---------------------------------------------------------------------------
113
84
 
114
- /** Delay for the given number of milliseconds. */
115
- export function delayMs(ms: number): void {}
116
- /** Delay for the given number of microseconds. */
117
- export function delayMicro(us: number): void {}
118
- /** Get milliseconds since boot. */
119
- export function getMillis(): number { return 0; }
120
- /** Get microseconds since boot. */
121
- export function getMicros(): number { return 0; }
122
- /** Get free heap bytes. Architecture-aware: the strategy maps this to the right
123
- * symbol per target (ESP.getFreeHeap() on ESP32, __heap_start trick on AVR). */
124
- export function getFreeHeap(): number { return 0; }
85
+ /** Time.sleep yielding sleep in milliseconds (Zephyr: k_msleep). */
86
+ export function timeSleep(ms: number): void {}
87
+ /** Time.now milliseconds since boot as a double (Zephyr: k_uptime_get). */
88
+ export function timeNow(): number { return 0; }
89
+ /** Time.nowUs microseconds since boot as a double, uptime-derived
90
+ * (k_uptime_get() * 1000) on every board — uniform, monotonic. */
91
+ export function timeNowUs(): number { return 0; }
92
+ /** Time.busyWaitUs spin-wait the given microseconds, no yield (Zephyr: k_busy_wait). */
93
+ export function timeBusyWaitUs(us: number): void {}
125
94
 
126
95
  // ---------------------------------------------------------------------------
127
96
  // I2C — inter-integrated circuit bus
128
97
  // ---------------------------------------------------------------------------
129
98
 
130
- /** Initialize I2C bus (master mode if no address, slave mode with address). */
131
- export function i2cBegin(bus: string, address?: number): void {}
132
- /** Disable I2C bus. */
133
- export function i2cEnd(bus: string): void {}
134
- /** Set I2C bus clock speed. */
135
- export function i2cSetClock(bus: string, hz: number): void {}
136
- /** Begin I2C transmission to a slave address. */
137
- export function i2cBeginTx(bus: string, address: number): void {}
138
- /** Write data to I2C bus. */
139
- export function i2cWrite(bus: string, data: string | number | number[] | Uint8Array): void {}
140
- /** Write a byte buffer to I2C bus (expands array literals to per-byte writes). */
141
- export function i2cWriteBuffer(bus: string, data: number[] | Uint8Array): void {}
142
- /** End I2C transmission. Returns status. */
143
- export function i2cEndTx(bus: string, stop: boolean): number { return 0; }
144
- /** Request bytes from I2C slave. */
145
- export function i2cRequestFrom(bus: string, address: number, quantity: number, stop?: boolean): number { return 0; }
146
- /** Check if bytes are available from I2C. */
147
- export function i2cAvailable(bus: string): number { return 0; }
148
- /** Read a byte from I2C. */
149
- export function i2cRead(bus: string): number { return 0; }
150
- /**
151
- * Drain `count` bytes requested from the I2C bus into a caller-provided buffer.
152
- * Semantic primitive: lowers to the `i2c.read_buffer` HAL op. The `buffer`
153
- * argument is emitted as a placeholder (`__HAL_READ_BUF__`) that the var-init
154
- * transformer rewrites to the caller's own buffer variable, so bytes land in
155
- * the `uint8_t data[N]` declared in user scope — NOT an internal temp that
156
- * decays to a pointer on return. Keeps `data.length` / `data[i]` valid.
157
- */
158
- export function i2cReadBuffer(bus: string, count: number, buffer: number[] | Uint8Array): void {}
99
+ // Thin I2C device (hal/i2c-target.ts): Zephyr register verbs. `hz` (0 =
100
+ // leave the bus at its current speed) applies once via a guarded
101
+ // i2c_configure on first use.
102
+ export function i2cRegWrite(bus: string, address: number, hz: number, reg: number, value: number): void {}
103
+ export function i2cRegRead(bus: string, address: number, hz: number, reg: number): number { return 0; }
104
+ export function i2cRegUpdate(bus: string, address: number, hz: number, reg: number, mask: number, value: number): void {}
105
+ export function i2cDevWrite(bus: string, address: number, hz: number, data: number[] | Uint8Array): void {}
159
106
 
160
107
  // ---------------------------------------------------------------------------
161
108
  // SPI — serial peripheral interface
162
109
  // ---------------------------------------------------------------------------
163
110
 
164
- /** Initialize SPI bus. */
165
- export function spiBegin(bus: string): void {}
166
- /** Disable SPI bus. */
167
- export function spiEnd(bus: string): void {}
168
- /** Transfer data on SPI bus. */
169
- export function spiTransfer(bus: string, data: string | number | Uint8Array): number { return 0; }
170
- /** Begin SPI transaction with settings. */
171
- export function spiBeginTx(bus: string, settings: string | any): void {}
172
- /** End SPI transaction. */
173
- export function spiEndTx(bus: string): void {}
174
- /** Set SPI chip-select pin LOW. */
175
- export function spiCsLow(pin: number | string): void {}
176
- /** Set SPI chip-select pin HIGH. */
177
- export function spiCsHigh(pin: number | string): void {}
178
- /**
179
- * Read `count` bytes from the SPI bus into a caller-provided buffer by clocking
180
- * dummy (0x00) transfers. Semantic primitive: lowers to the `spi.read_buffer`
181
- * HAL op (per-byte `bus.transfer(0)` read loop). The `buffer` placeholder is
182
- * rewritten to the caller's variable. Mirrors i2cReadBuffer. The caller is
183
- * responsible for asserting/de-asserting chip-select around it.
184
- */
185
- export function spiReadBuffer(bus: string, count: number, buffer: number[] | Uint8Array): void {}
186
- /** Set SPI data mode. */
187
- export function spiSetMode(bus: string, mode: number): void {}
188
- /** Set SPI bit order. */
189
- export function spiSetBitOrder(bus: string, order: string): void {}
190
-
191
- // ---------------------------------------------------------------------------
192
- // UART — serial communication
193
- // ---------------------------------------------------------------------------
194
-
195
- /** Initialize serial port with baud rate. */
196
- export function uartBegin(port: string, baud: number): void {}
197
- /** Disable serial port. */
198
- export function uartEnd(port: string): void {}
199
- /** Print value to serial. */
200
- export function uartPrint(port: string, value: any): void {}
201
- /** Print value with newline to serial. */
202
- export function uartPrintln(port: string, value: any): void {}
203
- /** printf-style formatted print to serial. */
204
- export function uartPrintf(port: string, format: any, args: any[]): void {}
205
- /** Write raw data to serial. */
206
- export function uartWrite(port: string, data: any): void {}
207
- /** Read a byte from serial. */
208
- export function uartRead(port: string): number { return 0; }
209
- /** Peek at next byte from serial without consuming. */
210
- export function uartPeek(port: string): number { return 0; }
211
- /** Check if bytes are available from serial. */
212
- export function uartAvailable(port: string): number { return 0; }
213
- /** Flush serial output. */
214
- export function uartFlush(port: string): void {}
215
-
216
111
  // ---------------------------------------------------------------------------
217
- // Pulse measurement
112
+ // USB — CDC-ACM serial over the USB connector (device stack)
218
113
  // ---------------------------------------------------------------------------
219
114
 
220
- /** Measure pulse duration on a pin. */
221
- export function pulseIn_(pin: number | string, value: number, timeout?: number): number { return 0; }
222
- /** Measure long pulse using high-precision timer. */
223
- export function pulseInLong_(pin: number | string, value: number): number { return 0; }
224
-
225
- // ---------------------------------------------------------------------------
226
- // Shift register
227
- // ---------------------------------------------------------------------------
228
-
229
- /** Shift a byte out to a pin. */
230
- export function shiftOut_(dataPin: number | string, clockPin: number | string, bitOrder: number, value: number): void {}
231
- /** Shift a byte in from a pin. */
232
- export function shiftIn_(dataPin: number | string, clockPin: number | string, bitOrder: number): number { return 0; }
115
+ /** Enable the USB device + open the CDC serial port with a baud hint. */
116
+ export function usbBegin(port: string): void {}
117
+ /** Disable the CDC serial port. */
118
+ export function usbEnd(port: string): void {}
119
+ /** Print value to the USB serial port. */
120
+ export function usbPrint(port: string, value: SerialValue): void {}
121
+ /** Print value with newline to the USB serial port. */
122
+ export function usbPrintln(port: string, value: SerialValue): void {}
123
+ /** Read a byte from the USB serial port (-1 if none). */
124
+ export function usbRead(port: string): number { return 0; }
125
+ /** Check if bytes are available from the USB serial port. */
126
+ export function usbAvailable(port: string): number { return 0; }
127
+ /** True when the host has opened the port (DTR asserted). */
128
+ export function usbConnected(port: string): boolean { return false; }
129
+ /** Thin waitLinked(): bounded DTR poll in the shim. */
130
+ export function usbWaitReady(port: string, timeoutMs: number): boolean { return false; }
233
131
 
234
132
  // ---------------------------------------------------------------------------
235
133
  // Board constant resolution
236
134
  // ---------------------------------------------------------------------------
237
135
 
238
- /** Write a value to a DAC pin. */
239
- export function dacWrite(pin: number | string, value: number): void {}
136
+ /** Thin DAC (hal/dac-pin.ts): raw dac_write_value with a construction-time
137
+ * resolution (0 = the chip descriptor's channel resolution). */
138
+ export function dacWriteValue(pin: number | string, value: number, resolution: number): void {}
240
139
 
241
140
  // ---------------------------------------------------------------------------
242
141
  // Watchdog timer (WDT)
243
142
  // ---------------------------------------------------------------------------
244
143
 
245
- /** Enable the watchdog timer with the given timeout (string preset or number). */
246
- export function wdtEnable(timeout: string | number): void {}
247
-
248
- /** Reset (kick) the watchdog timer. */
249
- export function wdtReset(): void {}
250
-
251
144
  /** Disable the watchdog timer. */
252
145
  export function wdtDisable(): void {}
253
146
 
147
+ /** Thin Watchdog (hal/watchdog.ts): arm with the construction timeout in ms
148
+ * (wdt_install_timeout + wdt_setup). */
149
+ export function wdtSetup(timeoutMs: number): void {}
150
+ /** Thin Watchdog: feed (wdt_feed). */
151
+ export function wdtFeed(): void {}
152
+
153
+ /** Thin Counter (hal/counter.ts): register the alarm handler. */
154
+ export function counterOnAlarm(instance: number, handler: string): void {}
155
+ /** Thin Counter: apply hz as the top value and start (counter_start). */
156
+ export function counterStart(instance: number, hz: number): void {}
157
+ /** Thin Counter: stop (counter_stop). */
158
+ export function counterStop(instance: number): void {}
159
+
160
+ // Thin SPI device (hal/spi-target.ts): the op carries the construction facts
161
+ // (cs pin, hz, mode) so the shim state block and overlay child node derive
162
+ // from op facts alone (the sensor discipline). `rx` is the caller's buffer
163
+ // identifier ('' = write-only).
164
+ export function spiTransceiveDt(bus: string, cs: number, hz: number, mode: number, tx: number[] | Uint8Array, rx: Uint8Array | number[]): void {}
165
+ export function spiWriteDt(bus: string, cs: number, hz: number, mode: number, tx: number[] | Uint8Array): void {}
166
+ /** SPITarget.readReg sugar: one-byte register read via spi_transceive_dt
167
+ * against an INTERNAL buffer — no caller array needed. */
168
+ export function spiReadReg(bus: string, cs: number, hz: number, mode: number, reg: number): number { return 0; }
169
+
170
+ // Thin UART (hal/uart-port.ts): TX is poll-based with the construction baud
171
+ // applied once (guarded uart_configure); RX is interrupt-backed into a
172
+ // construction-sized ring (armed on first receive call). `ring` sizes the
173
+ // shim's static buffer and rides every RX op (self-contained-op discipline).
174
+ export function uartPollWrite(port: string, baud: number, data: SerialValue): void {}
175
+ export function uartRxAvailable(port: string, ring: number): number { return 0; }
176
+ export function uartRxPeek(port: string, ring: number): number { return 0; }
177
+ export function uartRxRead(port: string, ring: number): number { return 0; }
178
+
179
+ // Thin Thread (hal/thread.ts): create + schedule (k_thread_create, K_NO_WAIT).
180
+ // The handler is the callback-registered entry function name.
181
+ export function threadStart(index: number, stackBytes: number, priority: number, handler: string): void {}
182
+ /** Thin Thread: block until exit (k_thread_join, K_FOREVER). */
183
+ export function threadJoin(index: number): void {}
184
+
254
185
  /** Resolve a board definition path to a compile-time constant. */
255
186
  export function boardResolve(path: string): any { return undefined as any; }
256
187
 
257
- // ---------------------------------------------------------------------------
258
- // Power MCU power states and clock frequency
259
- // ---------------------------------------------------------------------------
260
-
261
- /** Enter deep sleep for the given duration (ms). Architecture-aware: the
262
- * strategy emits the right call per target (esp_deep_sleep on ESP32, a
263
- * not-supported comment elsewhere). */
264
- export function powerDeepSleep(ms: number): void {}
265
- /** Enter light sleep. Architecture-aware. */
266
- export function powerLightSleep(): void {}
267
- /** Set the CPU frequency (MHz). */
268
- export function powerSetCpuFrequency(mhz: number): void {}
269
- /** Enter deep sleep until `pin` reaches `level` (pin wakeup). Architecture-aware:
270
- * ext0 on Xtensa (RTC pins), gpio-wakeup on RISC-V. */
271
- export function powerDeepSleepPin(pin: number, level: number): void {}
188
+ export function fsReadText(path: string): string { return ""; }
189
+ export function fsWriteText(path: string, content: string): void {}
190
+ export function fsExists(path: string): boolean { return false; }
191
+ export function fsRemove(path: string): boolean { return false; }
192
+ export function mqttConnect(brokerUri: string, clientId: string): boolean { return false; }
193
+ export function mqttOnMessage(handler: string): void {}
194
+ export function mqttSubscribe(topic: string): void {}
195
+ export function mqttPublish(topic: string, data: string): void {}
196
+ export function mqttConnected(): boolean { return false; }
197
+ export function mqttDisconnect(): void {}
272
198
 
273
199
  // ---------------------------------------------------------------------------
274
200
  // Preferences (NVS-backed key/value store)
275
201
  // ---------------------------------------------------------------------------
276
202
 
277
- export function preferencesBegin(namespace: string, readOnly: boolean): void {}
278
- export function preferencesEnd(): void {}
279
- export function preferencesClear(): void {}
280
- export function preferencesRemove(key: string): void {}
281
- export function preferencesPutInt(key: string, value: number): void {}
282
- export function preferencesGetInt(key: string, defaultValue: number): number { return 0; }
283
- export function preferencesPutUInt(key: string, value: number): void {}
284
- export function preferencesGetUInt(key: string, defaultValue: number): number { return 0; }
285
- export function preferencesPutBool(key: string, value: boolean): void {}
286
- export function preferencesGetBool(key: string, defaultValue: boolean): boolean { return false; }
287
- export function preferencesPutFloat(key: string, value: number): void {}
288
- export function preferencesGetFloat(key: string, defaultValue: number): number { return 0; }
289
- export function preferencesPutString(key: string, value: string): void {}
290
- export function preferencesGetString(key: string, defaultValue: string): string { return ""; }
291
-
292
- export function wifiConnect(ssid: string, password?: string, timeoutMs?: number): boolean { return false; }
203
+ export function preferencesClear(ns: string): void {}
204
+ export function preferencesRemove(ns: string, key: string): void {}
205
+ export function preferencesPutInt(ns: string, key: string, value: number): void {}
206
+ export function preferencesGetInt(ns: string, key: string, defaultValue: number): number { return 0; }
207
+ export function preferencesPutBool(ns: string, key: string, value: boolean): void {}
208
+ export function preferencesGetBool(ns: string, key: string, defaultValue: boolean): boolean { return false; }
209
+ export function preferencesPutFloat(ns: string, key: string, value: number): void {}
210
+ export function preferencesGetFloat(ns: string, key: string, defaultValue: number): number { return 0; }
211
+ export function preferencesPutString(ns: string, key: string, value: string): void {}
212
+ export function preferencesGetString(ns: string, key: string, defaultValue: string): string { return ""; }
213
+
293
214
  export function wifiConnectStart(ssid: string, password?: string): void {}
215
+ /** Join with the station's construction facts (the thin WiFi.join). */
216
+ export function wifiJoin(ssid: string, psk: string | undefined, security: number, channel: number, band: number, timeoutMs: number, ps: number, ipAddr: string | undefined, gateway: string | undefined, netmask: string | undefined): boolean { return false; }
294
217
  export function wifiDisconnect(): void {}
295
- export function wifiStatus(): number { return 0; }
296
218
  export function wifiIsConnected(): boolean { return false; }
297
219
  export function wifiLocalIp(): string { return ""; }
298
220
  export function wifiRssi(): number { return 0; }
299
- export function wifiMac(): string { return ""; }
300
- export function wifiSetHostname(name: string): void {}
301
- export function wifiSetStaticIp(ip: string, gateway: string, subnet: string, dns?: string): void {}
302
- export function wifiSetAutoReconnect(enabled: boolean): void {}
303
- export function wifiSetPowerSave(mode: string): void {}
304
- export function wifiSetTxPower(dbm: number): void {}
221
+ export function wifiMac(): number { return 0; }
305
222
  export function wifiOnEvent(event: string, handler: string): void {}
306
223
  export function wifiApStart(ssid: string, password?: string, channel?: number, hidden?: boolean, maxClients?: number): boolean { return false; }
307
224
  export function wifiApStop(): void {}
308
- export function wifiApClientCount(): number { return 0; }
309
- export function wifiApIp(): string { return ""; }
310
- export function wifiApSetChannel(channel: number): void {}
311
- export function wifiApSetHidden(hidden: boolean): void {}
312
- export function wifiApSetMaxClients(maxClients: number): void {}
313
225
  export function wifiScan(): number { return 0; }
314
- export function wifiScanStart(): void {}
226
+
315
227
  export function wifiScanCount(): number { return 0; }
316
228
  export function wifiScanSsid(index: number): string { return ""; }
317
229
  export function wifiScanRssi(index: number): number { return 0; }
318
- export function wifiScanEncryption(index: number): number { return 0; }
230
+ export function wifiScanEncryption(index: number): string { return ""; }
319
231
  export function wifiScanChannel(index: number): number { return 0; }
320
- export function wifiSaveCredentials(ssid: string, password: string): void {}
321
- export function wifiConnectSaved(timeoutMs?: number): boolean { return false; }
322
- export function wifiClearCredentials(): void {}
323
- export function wifiWaitConnected(timeoutMs?: number): boolean { return false; }
324
- export function wifiWaitDisconnected(): void {}
325
232
 
326
233
  // ---------------------------------------------------------------------------
327
234
  // HTTP client
328
235
  // ---------------------------------------------------------------------------
329
236
 
330
237
  export function httpBegin(method: string, url: string): void {}
331
- export function httpReset(): void {}
332
238
  export function httpSetHeader(name: string, value: string): void {}
333
239
  export function httpSetTimeout(ms: number): void {}
334
240
  export function httpSetMaxBody(bytes: number): void {}
335
241
  export function httpSetBody(data: string, json?: boolean): void {}
336
- export function httpSetInsecure(): void {}
242
+ export function httpSetInsecure(insecure: boolean): void {}
337
243
  export function httpSetCaCert(pem: string): void {}
338
244
  export function httpSend(): boolean { return false; }
339
- export function httpSendStart(): void {}
340
245
  export function httpStatus(): number { return 0; }
341
246
  export function httpOk(): boolean { return false; }
342
247
  export function httpBody(): string { return ""; }
@@ -356,14 +261,9 @@ export function bleOnRead(index: number, handler: string): void {}
356
261
  export function bleOnWrite(index: number, handler: string): void {}
357
262
  export function bleOnConnect(handler: string): void {}
358
263
  export function bleOnDisconnect(handler: string): void {}
359
- export function bleNotify(index: number, value: number | string): void {}
264
+ export function bleNotify(index: number, value: number): void {}
360
265
  export function bleIsConnected(): boolean { return false; }
361
266
  export function bleClientCount(): number { return 0; }
362
- export function bleSetName(name: string): void {}
363
- export function bleUntilConnected(timeoutMs?: number): boolean { return false; }
364
- export function bleUntilConnectedStart(): void {}
365
- export function bleSetTxPower(dbm: number): void {}
366
- export function bleStatus(): number { return 0; }
367
267
 
368
268
  // ---------------------------------------------------------------------------
369
269
  // Raw C++ escape hatch
@@ -388,3 +288,22 @@ export function rawCpp(code: string): void {}
388
288
  export function rawCppExpr<T>(code: string): T {
389
289
  return undefined as unknown as T;
390
290
  }
291
+
292
+ // ---------------------------------------------------------------------------
293
+ // Sensors — DT-bound peripheral parts (generic catalog)
294
+ //
295
+ // The part identity is a catalog token (SENSOR.<underscored-compatible> from
296
+ // sensor-catalog.generated.ts); the bus/address come from the I2CTarget the
297
+ // Sensor class was constructed with. Zephyr's uniform sensor API backs these —
298
+ // one code shape for every part in the catalog.
299
+ // ---------------------------------------------------------------------------
300
+
301
+ /** Fetch a fresh sample from a DT-bound sensor part. Args: part token, bus
302
+ * name, bus port (I2C address or SPI CS pin), bus kind ('i2c' | 'spi'),
303
+ * SPI clock Hz, SPI mode 0-3, alert pin (-1 = none). */
304
+ export function sensorFetch(part: string, bus: string, port: number, kind: string, spiHz: number, spiMode: number, alertPin: number): void {}
305
+ /** Read one channel (a SENSOR_CHAN_* suffix, see CHAN) from the fetched sample.
306
+ * Returns the value as a double (Zephyr's sensor_value val1 + val2/1e6).
307
+ * Carries the same construction facts as sensorFetch so either op alone
308
+ * yields a complete device. */
309
+ export function sensorGet(part: string, bus: string, port: number, kind: string, spiHz: number, spiMode: number, alertPin: number, chan: string): number { return 0; }
package/src/fs.ts CHANGED
@@ -1,54 +1,47 @@
1
- /**
2
- * FSClass provides a high-level abstraction for filesystem operations.
3
- *
4
- * Lowered to native filesystem HAL ops (fs.*): ESP-IDF mounts an SD card via
5
- * esp_vfs_fat_sdmmc_mount (FAT on SDMMC/SDSPI); Arduino uses SD.h / LittleFS.
6
- * The per-framework runtime shim owns the open/read/write/close dance and
7
- * returns heap strings for readText.
8
- *
9
- * The semantic primitives (fsBegin / fsReadText / ...) are resolved to fs.*
10
- * HAL ops by the transpiler's hal-plugins switch; this class is the
11
- * ergonomic, type-checking surface.
12
- */
13
- export class FSClass {
14
- static readonly __instance_name = "FS";
15
-
16
- /** Mount the filesystem. Returns true on success. */
17
- begin(): boolean {
18
- fsBegin();
19
- return true;
20
- }
21
-
22
- /** Read a UTF-8 text file into a string. Returns "" if the file is missing
23
- * or unreadable. The returned buffer is caller-owned. */
24
- readText(path: string): string {
25
- return fsReadText(path);
26
- }
27
-
28
- /** Write a string to a file (overwrites). Silently no-ops if the file
29
- * cannot be opened for writing. */
30
- writeText(path: string, content: string): void {
31
- fsWriteText(path, content);
32
- }
33
-
34
- /** True if a file exists at the path. */
35
- exists(path: string): boolean {
36
- return fsExists(path);
37
- }
38
-
39
- /** Delete a file. Returns true if deleted. */
40
- remove(path: string): boolean {
41
- return fsRemove(path);
42
- }
43
- }
44
-
45
- export const FS = new FSClass();
46
-
47
- // ── Semantic primitives (resolved to fs.* HAL ops by the transpiler) ──
48
- // These are inert at runtime (tests, type-checking); the cuttlefish transpiler
49
- // intercepts calls by name and lowers them to typed HAL op IR.
50
- export function fsBegin(): void {}
51
- export function fsReadText(path: string): string { return ""; }
52
- export function fsWriteText(path: string, content: string): void {}
53
- export function fsExists(path: string): boolean { return false; }
54
- export function fsRemove(path: string): boolean { return false; }
1
+ // ---------------------------------------------------------------------------
2
+ // File the thin persistent-file handle
3
+ //
4
+ // The path is the CONSTRUCTION fact; each verb maps 1:1 onto the Zephyr FS
5
+ // API (littlefs on the board's storage partition, mounted lazily on first
6
+ // use there is no begin()/mount session):
7
+ //
8
+ // read() → the file's text ("" when missing/unreadable; the returned
9
+ // buffer lives in the shim until the next read)
10
+ // write(s) → overwrite the file (no-op when unwritable)
11
+ // exists() → the file is present
12
+ // remove() → delete the file
13
+ // ----------------------------------------------------------------------------
14
+
15
+ import {
16
+ fsReadText, fsWriteText, fsExists, fsRemove,
17
+ } from './emit.js';
18
+
19
+ export class File {
20
+ private readonly _path: string;
21
+
22
+ constructor(path: string) {
23
+ this._path = path;
24
+ }
25
+
26
+ /** Read the file as UTF-8 text. "" when missing/unreadable; the buffer is
27
+ * shim-owned until the next read. */
28
+ read(): string {
29
+ return fsReadText(this._path);
30
+ }
31
+
32
+ /** Overwrite the file with `content`. Silently no-ops when the file
33
+ * cannot be opened for writing. */
34
+ write(content: string): void {
35
+ fsWriteText(this._path, content);
36
+ }
37
+
38
+ /** True if the file exists. */
39
+ exists(): boolean {
40
+ return fsExists(this._path);
41
+ }
42
+
43
+ /** Delete the file. */
44
+ remove(): void {
45
+ fsRemove(this._path);
46
+ }
47
+ }