@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.
- package/README.md +145 -87
- package/dist/adc-pin.d.ts +53 -0
- package/dist/adc-pin.js +69 -0
- package/dist/async.d.ts +3 -11
- package/dist/async.js +3 -15
- package/dist/ble.d.ts +42 -78
- package/dist/ble.js +79 -98
- package/dist/counter.d.ts +16 -0
- package/dist/counter.js +32 -0
- package/dist/dac-pin.d.ts +13 -0
- package/dist/dac-pin.js +21 -0
- package/dist/emit.d.ts +123 -196
- package/dist/emit.js +146 -208
- package/dist/fs.d.ts +12 -31
- package/dist/fs.js +30 -40
- package/dist/gpio-pin.d.ts +46 -0
- package/dist/gpio-pin.js +77 -0
- package/dist/gpio.d.ts +0 -103
- package/dist/gpio.js +16 -227
- package/dist/http.d.ts +38 -39
- package/dist/http.js +53 -78
- package/dist/i2c-target.d.ts +28 -0
- package/dist/i2c-target.js +52 -0
- package/dist/i2c.d.ts +5 -43
- package/dist/i2c.js +17 -130
- package/dist/index.d.ts +30 -42
- package/dist/index.js +27 -39
- package/dist/math.d.ts +0 -13
- package/dist/math.js +9 -13
- package/dist/mqtt.d.ts +15 -25
- package/dist/mqtt.js +32 -28
- package/dist/power.d.ts +9 -17
- package/dist/power.js +22 -20
- package/dist/preferences.d.ts +17 -25
- package/dist/preferences.js +54 -52
- package/dist/pulse.d.ts +4 -4
- package/dist/pulse.js +6 -2
- package/dist/pwm-pin.d.ts +24 -0
- package/dist/pwm-pin.js +38 -0
- package/dist/random.d.ts +0 -2
- package/dist/random.js +14 -20
- package/dist/sensor-catalog.generated.d.ts +997 -0
- package/dist/sensor-catalog.generated.js +764 -0
- package/dist/sensor.d.ts +46 -0
- package/dist/sensor.js +52 -0
- package/dist/shift-pin.d.ts +2 -0
- package/dist/shift-pin.js +13 -0
- package/dist/spi-target.d.ts +25 -0
- package/dist/spi-target.js +42 -0
- package/dist/spi.d.ts +8 -26
- package/dist/spi.js +15 -87
- package/dist/thread.d.ts +18 -0
- package/dist/thread.js +36 -0
- package/dist/time.d.ts +23 -0
- package/dist/time.js +43 -0
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +17 -7
- package/dist/types.d.ts +4 -34
- package/dist/types.js +5 -47
- package/dist/uart-port.d.ts +26 -0
- package/dist/uart-port.js +52 -0
- package/dist/uart.d.ts +0 -17
- package/dist/uart.js +10 -53
- package/dist/usb.d.ts +26 -0
- package/dist/usb.js +66 -0
- package/dist/watchdog.d.ts +12 -0
- package/dist/watchdog.js +28 -0
- package/dist/wifi.d.ts +88 -64
- package/dist/wifi.js +112 -126
- package/dist/zephyr-tokens.generated.d.ts +8 -0
- package/dist/zephyr-tokens.generated.js +73 -0
- package/package.json +7 -8
- package/src/adc-pin.ts +89 -0
- package/src/async.ts +3 -16
- package/src/ble.ts +84 -111
- package/src/counter.ts +40 -0
- package/src/dac-pin.ts +28 -0
- package/src/emit.ts +157 -238
- package/src/fs.ts +47 -54
- package/src/gpio-pin.ts +91 -0
- package/src/gpio.ts +49 -320
- package/src/http.ts +75 -95
- package/src/i2c-target.ts +63 -0
- package/src/i2c.ts +29 -167
- package/src/index.ts +32 -46
- package/src/math.ts +9 -14
- package/src/mqtt.ts +39 -31
- package/src/preferences.ts +52 -61
- package/src/pwm-pin.ts +54 -0
- package/src/random.ts +14 -21
- package/src/sensor-catalog.generated.ts +1238 -0
- package/src/sensor.ts +80 -0
- package/src/shift-pin.ts +16 -0
- package/src/spi-target.ts +53 -0
- package/src/spi.ts +27 -121
- package/src/thread.ts +44 -0
- package/src/time.ts +50 -0
- package/src/types.ts +14 -89
- package/src/uart-port.ts +64 -0
- package/src/usb.ts +82 -0
- package/src/watchdog.ts +35 -0
- package/src/wifi.ts +147 -179
- package/src/zephyr-tokens.generated.ts +77 -0
- package/src/adc.ts +0 -30
- package/src/capacitive.ts +0 -31
- package/src/constants.ts +0 -23
- package/src/dac.ts +0 -21
- package/src/eeprom.ts +0 -26
- package/src/interrupts.ts +0 -35
- package/src/mdns.ts +0 -50
- package/src/ota.ts +0 -44
- package/src/power.ts +0 -36
- package/src/pulse.ts +0 -63
- package/src/rmt.ts +0 -125
- package/src/shift.ts +0 -88
- package/src/temperature.ts +0 -20
- package/src/timer.ts +0 -58
- package/src/timing.ts +0 -67
- package/src/uart.ts +0 -77
- package/src/utils.ts +0 -17
- package/src/wdt.ts +0 -17
package/dist/types.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// ---------------------------------------------------------------------------
|
|
2
2
|
// @typecad/hal — Public type definitions
|
|
3
3
|
//
|
|
4
|
-
// Transpiler-shim type surface:
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// Transpiler-shim type surface: value aliases and the enums consumed by the
|
|
5
|
+
// HAL's transpiler-shim classes (Pin, GPIO, I2CBus/SPIBus) and re-exported
|
|
6
|
+
// for downstream type-checking.
|
|
7
7
|
//
|
|
8
8
|
// Runtime-contract interfaces (BasePin, II2CBus, ISPIBus, ISerialPort, the
|
|
9
|
-
// status enums, capability guards,
|
|
9
|
+
// status enums, capability guards, and the legacy Wire/SPI protocol-shape
|
|
10
|
+
// types I2CAddress/SPIMode/SPIBitOrder/SPISettings) have been relocated to
|
|
10
11
|
// @typecad/simulator/src/contracts.ts — they describe the runtime objects the
|
|
11
12
|
// simulator implements, not the transpiler shims that live here.
|
|
12
13
|
// ---------------------------------------------------------------------------
|
|
@@ -22,46 +23,3 @@ export var PinMode;
|
|
|
22
23
|
PinMode["OUTPUT_OPEN_DRAIN"] = "OUTPUT_OPEN_DRAIN";
|
|
23
24
|
PinMode["ANALOG"] = "ANALOG";
|
|
24
25
|
})(PinMode || (PinMode = {}));
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
// Interrupt mode enum
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
export var InterruptMode;
|
|
29
|
-
(function (InterruptMode) {
|
|
30
|
-
InterruptMode["RISING"] = "RISING";
|
|
31
|
-
InterruptMode["FALLING"] = "FALLING";
|
|
32
|
-
InterruptMode["CHANGE"] = "CHANGE";
|
|
33
|
-
InterruptMode["LOW"] = "LOW";
|
|
34
|
-
InterruptMode["HIGH"] = "HIGH";
|
|
35
|
-
})(InterruptMode || (InterruptMode = {}));
|
|
36
|
-
export function createPinGroup(pins) {
|
|
37
|
-
return {
|
|
38
|
-
name: 'PinGroup',
|
|
39
|
-
pins: Object.freeze(pins),
|
|
40
|
-
writePattern(pattern) {
|
|
41
|
-
for (let i = 0; i < this.pins.length; i++) {
|
|
42
|
-
const bit = (pattern >> i) & 1;
|
|
43
|
-
const pin = this.pins[i];
|
|
44
|
-
if ('write' in pin && typeof pin.write === 'function') {
|
|
45
|
-
pin.write(bit === 1);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
readPattern() {
|
|
50
|
-
let value = 0;
|
|
51
|
-
for (let i = 0; i < this.pins.length; i++) {
|
|
52
|
-
const pin = this.pins[i];
|
|
53
|
-
if ('isHigh' in pin && typeof pin.isHigh === 'function' && pin.isHigh()) {
|
|
54
|
-
value |= (1 << i);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
},
|
|
59
|
-
fill(value) {
|
|
60
|
-
for (const pin of this.pins) {
|
|
61
|
-
if ('write' in pin && typeof pin.write === 'function') {
|
|
62
|
-
pin.write(value);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SerialValue } from './types.js';
|
|
2
|
+
export declare class UART {
|
|
3
|
+
private readonly _port;
|
|
4
|
+
private readonly _baud;
|
|
5
|
+
private readonly _rxBufferBytes;
|
|
6
|
+
/** Construct a port handle. `port` is the UART instance (UART0, UART1, …);
|
|
7
|
+
* `baud` applies once at first use (default 115200, 8N1);
|
|
8
|
+
* `rxBufferBytes` sizes the receive ring (default 64). */
|
|
9
|
+
constructor(port: string, opts?: {
|
|
10
|
+
baud?: number;
|
|
11
|
+
rxBufferBytes?: number;
|
|
12
|
+
});
|
|
13
|
+
/** Write text, a number, or a boolean (uart_poll_out per byte). No newline
|
|
14
|
+
* appended. Numbers format as decimal; booleans print as 1/0. */
|
|
15
|
+
write(data: SerialValue): void;
|
|
16
|
+
/** Write a value followed by a newline. */
|
|
17
|
+
writeLine(data: SerialValue): void;
|
|
18
|
+
/** Bytes waiting in the receive ring. Arms the RX interrupt on first
|
|
19
|
+
* use (uart_irq_callback_user_data_set + uart_irq_rx_enable — the
|
|
20
|
+
* callback drains the FIFO into the ring). */
|
|
21
|
+
available(): number;
|
|
22
|
+
/** The oldest received byte WITHOUT consuming it; -1 when empty. */
|
|
23
|
+
peek(): number;
|
|
24
|
+
/** Pop the oldest received byte; -1 when the ring is empty. */
|
|
25
|
+
read(): number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// UART — the thin Zephyr-shaped serial port
|
|
3
|
+
//
|
|
4
|
+
// TX is poll-based (uart_poll_out — synchronous, fine for writes); RX is
|
|
5
|
+
// INTERRUPT-backed: the first receive call arms the driver's IRQ callback,
|
|
6
|
+
// which drains the FIFO into a construction-sized ring buffer. That makes
|
|
7
|
+
// the honest versions of the calls the poll API couldn't support:
|
|
8
|
+
// available() — bytes waiting in the ring (the poll driver cannot report
|
|
9
|
+
// this without draining the byte you want next)
|
|
10
|
+
// peek() — the oldest byte WITHOUT consuming it
|
|
11
|
+
// read() — pop the oldest byte, or -1 when the ring is empty
|
|
12
|
+
//
|
|
13
|
+
// Construction: `new UART('UART0', { baud: 9600, rxBufferBytes: 128 })` —
|
|
14
|
+
// the ring size (default 64) is a construction fact that sizes the shim's
|
|
15
|
+
// static buffer; bytes arriving with a full ring are dropped (the embedded
|
|
16
|
+
// honest answer — no unbounded buffering).
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
import { uartPollWrite, uartRxAvailable, uartRxPeek, uartRxRead } from './emit.js';
|
|
19
|
+
export class UART {
|
|
20
|
+
/** Construct a port handle. `port` is the UART instance (UART0, UART1, …);
|
|
21
|
+
* `baud` applies once at first use (default 115200, 8N1);
|
|
22
|
+
* `rxBufferBytes` sizes the receive ring (default 64). */
|
|
23
|
+
constructor(port, opts) {
|
|
24
|
+
this._port = port;
|
|
25
|
+
this._baud = opts?.baud ?? 115200;
|
|
26
|
+
this._rxBufferBytes = opts?.rxBufferBytes ?? 64;
|
|
27
|
+
}
|
|
28
|
+
/** Write text, a number, or a boolean (uart_poll_out per byte). No newline
|
|
29
|
+
* appended. Numbers format as decimal; booleans print as 1/0. */
|
|
30
|
+
write(data) {
|
|
31
|
+
uartPollWrite(this._port, this._baud, data);
|
|
32
|
+
}
|
|
33
|
+
/** Write a value followed by a newline. */
|
|
34
|
+
writeLine(data) {
|
|
35
|
+
uartPollWrite(this._port, this._baud, data);
|
|
36
|
+
uartPollWrite(this._port, this._baud, "\n");
|
|
37
|
+
}
|
|
38
|
+
/** Bytes waiting in the receive ring. Arms the RX interrupt on first
|
|
39
|
+
* use (uart_irq_callback_user_data_set + uart_irq_rx_enable — the
|
|
40
|
+
* callback drains the FIFO into the ring). */
|
|
41
|
+
available() {
|
|
42
|
+
return uartRxAvailable(this._port, this._rxBufferBytes);
|
|
43
|
+
}
|
|
44
|
+
/** The oldest received byte WITHOUT consuming it; -1 when empty. */
|
|
45
|
+
peek() {
|
|
46
|
+
return uartRxPeek(this._port, this._rxBufferBytes);
|
|
47
|
+
}
|
|
48
|
+
/** Pop the oldest received byte; -1 when the ring is empty. */
|
|
49
|
+
read() {
|
|
50
|
+
return uartRxRead(this._port, this._rxBufferBytes);
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/uart.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
export declare class SerialPort {
|
|
2
|
-
static readonly __includes: string[];
|
|
3
2
|
private _port;
|
|
4
3
|
constructor(port: string);
|
|
5
|
-
begin(baud?: number): this;
|
|
6
|
-
end(): void;
|
|
7
|
-
print(value: any): void;
|
|
8
|
-
println(value: any): void;
|
|
9
|
-
printf(format: string, ...args: any[]): void;
|
|
10
|
-
write(data: any): void;
|
|
11
|
-
read(): number;
|
|
12
|
-
readLine(): string;
|
|
13
|
-
peek(): number;
|
|
14
|
-
available(): number;
|
|
15
|
-
flush(): void;
|
|
16
|
-
waitForConnection(timeout?: number): Promise<void>;
|
|
17
|
-
take(): this | null;
|
|
18
|
-
release(): void;
|
|
19
4
|
}
|
|
20
|
-
/** Map TypeCAD UART instance number to Arduino C++ object name. UART0→Serial, UART1→Serial1 */
|
|
21
|
-
export declare function serialName(instance: number): string;
|
package/dist/uart.js
CHANGED
|
@@ -1,58 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// SerialPort — controller identity carrier (legacy UART API removed)
|
|
3
|
+
//
|
|
4
|
+
// The class carries ONLY the controller identity (the canonical controller
|
|
5
|
+
// name: UART0, UART1, …). Generated board modules construct the singletons;
|
|
6
|
+
// program-level serial is the thin `UART` (uart-port.ts — interrupt-drained
|
|
7
|
+
// RX ring + poll TX, construction baud) or `USBConsole` (usb.ts) for the CDC
|
|
8
|
+
// connector. The former print/printf/read/peek/available/waitForConnection
|
|
9
|
+
// surface was removed with the legacy Arduino surface.
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
2
11
|
export class SerialPort {
|
|
3
12
|
constructor(port) {
|
|
4
13
|
this._port = port;
|
|
5
14
|
}
|
|
6
|
-
begin(baud = 9600) {
|
|
7
|
-
uartBegin(this._port, baud);
|
|
8
|
-
return this;
|
|
9
|
-
}
|
|
10
|
-
end() {
|
|
11
|
-
uartEnd(this._port);
|
|
12
|
-
}
|
|
13
|
-
print(value) {
|
|
14
|
-
uartPrint(this._port, value);
|
|
15
|
-
}
|
|
16
|
-
println(value) {
|
|
17
|
-
uartPrintln(this._port, value);
|
|
18
|
-
}
|
|
19
|
-
printf(format, ...args) {
|
|
20
|
-
uartPrintf(this._port, format, args);
|
|
21
|
-
}
|
|
22
|
-
write(data) {
|
|
23
|
-
uartWrite(this._port, data);
|
|
24
|
-
}
|
|
25
|
-
read() {
|
|
26
|
-
return uartRead(this._port);
|
|
27
|
-
}
|
|
28
|
-
readLine() {
|
|
29
|
-
rawCpp(`return ${this._port}.readStringUntil('\\n');`);
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
peek() {
|
|
33
|
-
return uartPeek(this._port);
|
|
34
|
-
}
|
|
35
|
-
available() {
|
|
36
|
-
return uartAvailable(this._port);
|
|
37
|
-
}
|
|
38
|
-
flush() {
|
|
39
|
-
uartFlush(this._port);
|
|
40
|
-
}
|
|
41
|
-
waitForConnection(timeout) {
|
|
42
|
-
rawCpp(`while (!${this._port}) { delay(10); }`);
|
|
43
|
-
return Promise.resolve();
|
|
44
|
-
}
|
|
45
|
-
take() {
|
|
46
|
-
// Basic implementation for single-threaded Arduino;
|
|
47
|
-
// real locking would be framework-specific.
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
release() {
|
|
51
|
-
// No-op for standard Arduino.
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
SerialPort.__includes = ["<Arduino.h>"];
|
|
55
|
-
/** Map TypeCAD UART instance number to Arduino C++ object name. UART0→Serial, UART1→Serial1 */
|
|
56
|
-
export function serialName(instance) {
|
|
57
|
-
return instance === 0 ? "Serial" : `Serial${instance}`;
|
|
58
15
|
}
|
package/dist/usb.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SerialValue } from './types.js';
|
|
2
|
+
export declare class USBConsole {
|
|
3
|
+
private readonly _port;
|
|
4
|
+
/** Construct the console for a CDC instance ('USB0' = instance 0). */
|
|
5
|
+
constructor(port?: string);
|
|
6
|
+
/** Start the USB device stack and bring the CDC port up. Idempotent. */
|
|
7
|
+
open(): void;
|
|
8
|
+
/** Stop using the port. Observable no-op on Zephyr — the device stack is
|
|
9
|
+
* shared by every CDC instance and is not torn down per-port. */
|
|
10
|
+
close(): void;
|
|
11
|
+
/** Write text, a number, or a boolean. Numbers format as decimal;
|
|
12
|
+
* booleans print as 1/0. */
|
|
13
|
+
write(value: SerialValue): void;
|
|
14
|
+
/** Write a value followed by a newline. */
|
|
15
|
+
writeLine(value: SerialValue): void;
|
|
16
|
+
/** True when the host has the port open (DTR asserted). Output written
|
|
17
|
+
* before this is true is silently dropped by most hosts. */
|
|
18
|
+
linked(): boolean;
|
|
19
|
+
/** Block until the host opens the port, polling in the shim (no user-code
|
|
20
|
+
* busy loop). `timeoutMs` 0 = wait forever. Returns true once linked. */
|
|
21
|
+
waitLinked(timeoutMs?: number): boolean;
|
|
22
|
+
/** Read one byte, or -1 when no byte is ready (non-blocking). */
|
|
23
|
+
read(): number;
|
|
24
|
+
/** Bytes ready to read (the CDC poll path reports 0/1 — see the lowering). */
|
|
25
|
+
available(): number;
|
|
26
|
+
}
|
package/dist/usb.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// USBConsole — the thin CDC-ACM console
|
|
3
|
+
//
|
|
4
|
+
// A serial pipe over the board's USB connector (Communication Device Class,
|
|
5
|
+
// Abstract Control Model). The construction fact is the port identity
|
|
6
|
+
// ('USB0' — the CDC instance index the devicetree overlay composes); the
|
|
7
|
+
// verbs map 1:1 onto Zephyr's CDC device stack:
|
|
8
|
+
//
|
|
9
|
+
// open() → start the USB device stack (idempotent; CDC has no
|
|
10
|
+
// wire baud — line coding is the host's business)
|
|
11
|
+
// close() → observable no-op (tearing down the shared device
|
|
12
|
+
// stack would drop every other CDC instance)
|
|
13
|
+
// write(v) → one typed write (text | number | boolean — the
|
|
14
|
+
// writeLine(v) __tc_print contract, not print(any))
|
|
15
|
+
// linked() → the host has the port open (DTR asserted); output
|
|
16
|
+
// written before this is silently dropped by hosts
|
|
17
|
+
// waitLinked(ms) → ONE op: bounded DTR poll in the shim (k_msleep
|
|
18
|
+
// slices), boolean, no user-code busy loop. 0 = forever.
|
|
19
|
+
// read()/available()→ poll RX (the byte or -1 / a ready count)
|
|
20
|
+
//
|
|
21
|
+
// Unlike a hardware UART, output before the host opens the port is lost —
|
|
22
|
+
// gate on linked()/waitLinked() when early output matters.
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
import { usbBegin, usbEnd, usbPrint, usbPrintln, usbRead, usbAvailable, usbConnected, usbWaitReady, } from './emit.js';
|
|
25
|
+
export class USBConsole {
|
|
26
|
+
/** Construct the console for a CDC instance ('USB0' = instance 0). */
|
|
27
|
+
constructor(port = 'USB0') {
|
|
28
|
+
this._port = port;
|
|
29
|
+
}
|
|
30
|
+
/** Start the USB device stack and bring the CDC port up. Idempotent. */
|
|
31
|
+
open() {
|
|
32
|
+
usbBegin(this._port);
|
|
33
|
+
}
|
|
34
|
+
/** Stop using the port. Observable no-op on Zephyr — the device stack is
|
|
35
|
+
* shared by every CDC instance and is not torn down per-port. */
|
|
36
|
+
close() {
|
|
37
|
+
usbEnd(this._port);
|
|
38
|
+
}
|
|
39
|
+
/** Write text, a number, or a boolean. Numbers format as decimal;
|
|
40
|
+
* booleans print as 1/0. */
|
|
41
|
+
write(value) {
|
|
42
|
+
usbPrint(this._port, value);
|
|
43
|
+
}
|
|
44
|
+
/** Write a value followed by a newline. */
|
|
45
|
+
writeLine(value) {
|
|
46
|
+
usbPrintln(this._port, value);
|
|
47
|
+
}
|
|
48
|
+
/** True when the host has the port open (DTR asserted). Output written
|
|
49
|
+
* before this is true is silently dropped by most hosts. */
|
|
50
|
+
linked() {
|
|
51
|
+
return usbConnected(this._port);
|
|
52
|
+
}
|
|
53
|
+
/** Block until the host opens the port, polling in the shim (no user-code
|
|
54
|
+
* busy loop). `timeoutMs` 0 = wait forever. Returns true once linked. */
|
|
55
|
+
waitLinked(timeoutMs = 0) {
|
|
56
|
+
return usbWaitReady(this._port, timeoutMs);
|
|
57
|
+
}
|
|
58
|
+
/** Read one byte, or -1 when no byte is ready (non-blocking). */
|
|
59
|
+
read() {
|
|
60
|
+
return usbRead(this._port);
|
|
61
|
+
}
|
|
62
|
+
/** Bytes ready to read (the CDC poll path reports 0/1 — see the lowering). */
|
|
63
|
+
available() {
|
|
64
|
+
return usbAvailable(this._port);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class Watchdog {
|
|
2
|
+
private readonly _timeoutMs;
|
|
3
|
+
/** Construct with the timeout in milliseconds. */
|
|
4
|
+
constructor(timeoutMs: number);
|
|
5
|
+
/** Arm the watchdog (wdt_install_timeout + wdt_setup). Full CPU reset on
|
|
6
|
+
* expiry. Call feed() at least once per timeout window afterwards. */
|
|
7
|
+
enable(): void;
|
|
8
|
+
/** Feed the watchdog (wdt_feed). */
|
|
9
|
+
feed(): void;
|
|
10
|
+
/** Disable (wdt_disable). Not all drivers support runtime disable. */
|
|
11
|
+
disable(): void;
|
|
12
|
+
}
|
package/dist/watchdog.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Watchdog — the thin Zephyr-shaped watchdog
|
|
3
|
+
//
|
|
4
|
+
// The timeout is a CONSTRUCTION fact in milliseconds (Zephyr's own unit for
|
|
5
|
+
// wdt_timeout_cfg.window.max). enable() arms (wdt_install_timeout +
|
|
6
|
+
// wdt_setup, reset-CPU-core flag); feed() keeps it alive (wdt_feed) —
|
|
7
|
+
// Zephyr's verbs, no WDTO_* presets, no string parsing.
|
|
8
|
+
// ----------------------------------------------------------------------------
|
|
9
|
+
import { wdtSetup, wdtFeed, wdtDisable } from './emit.js';
|
|
10
|
+
export class Watchdog {
|
|
11
|
+
/** Construct with the timeout in milliseconds. */
|
|
12
|
+
constructor(timeoutMs) {
|
|
13
|
+
this._timeoutMs = timeoutMs;
|
|
14
|
+
}
|
|
15
|
+
/** Arm the watchdog (wdt_install_timeout + wdt_setup). Full CPU reset on
|
|
16
|
+
* expiry. Call feed() at least once per timeout window afterwards. */
|
|
17
|
+
enable() {
|
|
18
|
+
wdtSetup(this._timeoutMs);
|
|
19
|
+
}
|
|
20
|
+
/** Feed the watchdog (wdt_feed). */
|
|
21
|
+
feed() {
|
|
22
|
+
wdtFeed();
|
|
23
|
+
}
|
|
24
|
+
/** Disable (wdt_disable). Not all drivers support runtime disable. */
|
|
25
|
+
disable() {
|
|
26
|
+
wdtDisable();
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/wifi.d.ts
CHANGED
|
@@ -1,67 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare class WiFi {
|
|
2
|
+
/** Security tokens — lowered to Zephyr's wifi_security_type enum. */
|
|
3
|
+
static readonly OPEN = 0;
|
|
4
|
+
static readonly WPA2 = 1;
|
|
5
|
+
static readonly WPA3 = 2;
|
|
6
|
+
static readonly WPA2_WPA3 = 3;
|
|
7
|
+
/** Band tokens. */
|
|
8
|
+
static readonly BAND_2_4 = 0;
|
|
9
|
+
static readonly BAND_5 = 1;
|
|
10
|
+
/** Power-save token — pass PS_OFF to disable the radio's modem sleep. */
|
|
11
|
+
static readonly PS_OFF = 0;
|
|
12
|
+
private readonly _ssid;
|
|
13
|
+
private readonly _psk;
|
|
14
|
+
private readonly _security;
|
|
15
|
+
private readonly _channel;
|
|
16
|
+
private readonly _band;
|
|
17
|
+
private readonly _timeoutMs;
|
|
18
|
+
private readonly _ps;
|
|
19
|
+
private readonly _ipAddr;
|
|
20
|
+
private readonly _gateway;
|
|
21
|
+
private readonly _netmask;
|
|
22
|
+
/** Construct a station link policy. `psk` omitted → open network;
|
|
23
|
+
* `security` defaults WPA2 when a psk is present, OPEN otherwise;
|
|
24
|
+
* `channel` 0/omitted = any. `ipv4` opts out of DHCP with static facts. */
|
|
25
|
+
constructor(ssid: string, opts?: {
|
|
26
|
+
psk?: string;
|
|
27
|
+
security?: number;
|
|
28
|
+
channel?: number;
|
|
29
|
+
band?: number;
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
powerSave?: number;
|
|
32
|
+
ipv4?: {
|
|
33
|
+
addr: string;
|
|
34
|
+
gateway: string;
|
|
35
|
+
netmask: string;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
/** Join the network. Blocks (bounded by timeoutMs, pumping a mounted UI's
|
|
39
|
+
* tick between polls); returns true once IP connectivity is up, false on
|
|
40
|
+
* timeout or missing radio. Idempotent-ish: re-joining re-associates. */
|
|
41
|
+
join(): boolean;
|
|
42
|
+
/** Fire-and-forget join — poll linked() or await in an async function. */
|
|
43
|
+
joinStart(): void;
|
|
44
|
+
/** Leave the network (NET_REQUEST_WIFI_DISCONNECT). */
|
|
45
|
+
leave(): void;
|
|
46
|
+
/** True once IP connectivity is up (the L4 flag — post-DHCP, or after
|
|
47
|
+
* static IPv4 facts are applied). */
|
|
48
|
+
linked(): boolean;
|
|
49
|
+
/** Signal strength in dBm (iface-status query). */
|
|
50
|
+
rssi(): number;
|
|
51
|
+
/** The interface's global IPv4 address as text ("0.0.0.0" when down). */
|
|
52
|
+
ip(): string;
|
|
53
|
+
/** The radio's BSSID packed into a number (iface-status query). */
|
|
54
|
+
mac(): number;
|
|
55
|
+
/** Fires once DHCP (or static config) assigns an address. */
|
|
56
|
+
onUp(handler: () => void): void;
|
|
57
|
+
/** Fires on link loss (deferred off the net_mgmt event chain so the
|
|
58
|
+
* callback may safely call join()). */
|
|
59
|
+
onDrop(handler: () => void): void;
|
|
60
|
+
/** One blocking scan; read the results through the returned handle.
|
|
61
|
+
* Fixed pool of 16 — no heap. */
|
|
62
|
+
scan(): Scan;
|
|
8
63
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
64
|
+
/** Read-only view over the last scan's fixed result pool. */
|
|
65
|
+
export declare class Scan {
|
|
66
|
+
/** Number of networks found. */
|
|
67
|
+
count(): number;
|
|
68
|
+
/** Network name ("" when out of range). */
|
|
69
|
+
ssid(i: number): string;
|
|
70
|
+
/** Signal strength in dBm. */
|
|
71
|
+
rssi(i: number): number;
|
|
72
|
+
/** Security family as text: "open" / "wpa" / "wpa2" / "wpa3". */
|
|
73
|
+
security(i: number): string;
|
|
74
|
+
/** Channel number (0 when unknown). */
|
|
75
|
+
channel(i: number): number;
|
|
16
76
|
}
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
connectAsync(ssid: string, password?: string): void;
|
|
32
|
-
untilConnected(timeoutMs?: number): Promise<boolean>;
|
|
33
|
-
untilDisconnected(): Promise<void>;
|
|
34
|
-
disconnect(): void;
|
|
35
|
-
isConnected(): boolean;
|
|
36
|
-
status(): WiFiStatus;
|
|
37
|
-
localIP(): string;
|
|
38
|
-
rssi(): number;
|
|
39
|
-
macAddress(): string;
|
|
40
|
-
hostname(name: string): this;
|
|
41
|
-
staticIP(ip: string, gateway: string, subnet: string, dns?: string): this;
|
|
42
|
-
autoReconnect(enabled: boolean): this;
|
|
43
|
-
powerSave(mode: "default" | "none"): this;
|
|
44
|
-
/** Cap TX power in dBm (roughly 2–20). Safe to call before connect() —
|
|
45
|
-
* the value is applied after the radio starts. */
|
|
46
|
-
txPower(dbm: number): this;
|
|
47
|
-
saveCredentials(ssid: string, password: string): void;
|
|
48
|
-
connectSaved(timeoutMs?: number): boolean;
|
|
49
|
-
clearCredentials(): void;
|
|
50
|
-
onConnect(handler: () => void): void;
|
|
51
|
-
onDisconnect(handler: () => void): void;
|
|
52
|
-
startAP(ssid: string, password?: string): boolean;
|
|
53
|
-
apChannel(ch: number): this;
|
|
54
|
-
apHidden(hidden: boolean): this;
|
|
55
|
-
apMaxClients(n: number): this;
|
|
56
|
-
stopAP(): void;
|
|
57
|
-
apClientCount(): number;
|
|
58
|
-
apIP(): string;
|
|
59
|
-
scan(): number;
|
|
60
|
-
scanAsync(): Promise<void>;
|
|
61
|
-
scanCount(): number;
|
|
62
|
-
scanSSID(i: number): string;
|
|
63
|
-
scanRSSI(i: number): number;
|
|
64
|
-
scanEncryption(i: number): WiFiEncryption;
|
|
65
|
-
scanChannel(i: number): number;
|
|
77
|
+
/** SoftAP — the AP facts at construction, then start/stop. */
|
|
78
|
+
export declare class WiFiAP {
|
|
79
|
+
private readonly _ssid;
|
|
80
|
+
private readonly _psk;
|
|
81
|
+
private readonly _channel;
|
|
82
|
+
/** Construct an AP. `psk` omitted → open network. `channel` 0 = auto. */
|
|
83
|
+
constructor(ssid: string, opts?: {
|
|
84
|
+
psk?: string;
|
|
85
|
+
channel?: number;
|
|
86
|
+
});
|
|
87
|
+
/** Bring the interface up as an AP (NET_REQUEST_WIFI_AP_ENABLE). */
|
|
88
|
+
start(): void;
|
|
89
|
+
/** Tear the AP down (NET_REQUEST_WIFI_AP_DISABLE). */
|
|
90
|
+
stop(): void;
|
|
66
91
|
}
|
|
67
|
-
export declare const WiFi: WiFiClass;
|