@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/src/pwm-pin.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// PWM — the thin Zephyr-shaped PWM channel
|
|
3
|
+
//
|
|
4
|
+
// The period is a CONSTRUCTION fact (Zephyr's model — the period lives with
|
|
5
|
+
// the channel, not with each write): `new PWM(PA5, { periodNs: 20_000_000 })`.
|
|
6
|
+
// The first use applies the construction period (pwm_set_dt with an idle
|
|
7
|
+
// pulse — Zephyr 4.4 has no period-only setter), then setPulse lowers to
|
|
8
|
+
// pwm_set_pulse_dt verbatim. setDuty(0.0–1.0) is sugar that lowers to
|
|
9
|
+
// exactly one pwm_set_pulse_dt against the known period — no 0–255 scaling
|
|
10
|
+
// anywhere. Nanoseconds throughout.
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
import { pwmSetPulse, pwmSetDuty, pwmSetPeriod } from './emit.js';
|
|
14
|
+
import type { Pin } from './gpio.js';
|
|
15
|
+
|
|
16
|
+
export class PWM {
|
|
17
|
+
private readonly _pin: number;
|
|
18
|
+
private readonly _periodNs: number;
|
|
19
|
+
// Routing overrides (the inline escape hatch): the DT controller nodelabel
|
|
20
|
+
// and channel for pins the facts layer does not cover.
|
|
21
|
+
private readonly _controller: string;
|
|
22
|
+
private readonly _channel: number;
|
|
23
|
+
|
|
24
|
+
/** Construct a PWM channel. `periodNs` is required — the channel's period
|
|
25
|
+
* in nanoseconds (50 Hz servo = 20_000_000; 1 kHz LED dimming = 1_000_000).
|
|
26
|
+
* `controller`/`channel` override the routing when the board's facts do
|
|
27
|
+
* not map this pin. */
|
|
28
|
+
constructor(
|
|
29
|
+
pin: number | Pin,
|
|
30
|
+
opts: { periodNs: number; controller?: string; channel?: number },
|
|
31
|
+
) {
|
|
32
|
+
this._pin = typeof pin === 'number' ? pin : pin.number;
|
|
33
|
+
this._periodNs = opts.periodNs;
|
|
34
|
+
this._controller = opts?.controller ?? '';
|
|
35
|
+
this._channel = opts?.channel ?? -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Set the pulse width in nanoseconds (pwm_set_pulse_dt). */
|
|
39
|
+
setPulse(pulseNs: number): void {
|
|
40
|
+
pwmSetPulse(this._pin, this._periodNs, pulseNs, this._controller, this._channel);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Set the duty cycle as a fraction 0.0–1.0. Sugar: lowers to one
|
|
44
|
+
* pwm_set_pulse_dt with pulse = duty × the constructed period. */
|
|
45
|
+
setDuty(duty: number): void {
|
|
46
|
+
pwmSetDuty(this._pin, this._periodNs, duty, this._controller, this._channel);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Change the period at runtime (pwm_set_dt). Zephyr 4.4 has no period-only
|
|
50
|
+
* setter, so the pulse resets to idle — follow with setPulse/setDuty. */
|
|
51
|
+
setPeriod(periodNs: number): void {
|
|
52
|
+
pwmSetPeriod(this._pin, periodNs, this._controller, this._channel);
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/random.ts
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Random — the thin PRNG surface
|
|
3
|
+
//
|
|
4
|
+
// The Random namespace methods (seed/upTo/between/int) are intercepted by the
|
|
5
|
+
// transpiler's namespace-method resolver and lowered to the random.* HAL op
|
|
6
|
+
// family (random.seed / random.range / random.int), which each framework lowers
|
|
7
|
+
// to its platform PRNG (Zephyr: a userspace xorshift32 seeded from
|
|
8
|
+
// sys_rand_get). The bodies below are inert runtime stubs for host-side
|
|
9
|
+
// type-checking only — never emitted.
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
5
11
|
|
|
6
12
|
export class Random {
|
|
7
13
|
/** Seeds the PRNG with a starting value. */
|
|
8
|
-
static seed(val: number): void {
|
|
9
|
-
rawCpp(`randomSeed(${val});`);
|
|
10
|
-
}
|
|
14
|
+
static seed(val: number): void {}
|
|
11
15
|
|
|
12
16
|
/** Returns a random number in range [0, max-1]. */
|
|
13
|
-
static upTo(max: number): number {
|
|
14
|
-
rawCpp(`return random(${max});`);
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
+
static upTo(max: number): number { return 0; }
|
|
17
18
|
|
|
18
19
|
/** Returns a random number in range [min, max-1]. */
|
|
19
|
-
static between(min: number, max: number): number {
|
|
20
|
-
rawCpp(`return random(${min}, ${max});`);
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
20
|
+
static between(min: number, max: number): number { return 0; }
|
|
23
21
|
|
|
24
22
|
/** Returns a random non-negative 31-bit integer [0, 2147483646]. */
|
|
25
|
-
static int(): number {
|
|
26
|
-
// Arduino random(max) returns [0, max-1]; 2147483647 = INT_MAX gives a
|
|
27
|
-
// non-negative 31-bit range (sign bit always 0).
|
|
28
|
-
rawCpp(`return random(2147483647);`);
|
|
29
|
-
return 0;
|
|
30
|
-
}
|
|
23
|
+
static int(): number { return 0; }
|
|
31
24
|
}
|