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