@typecad/hal 0.1.0-alpha.1 → 1.0.0-alpha.10

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 (57) hide show
  1. package/README.md +8 -7
  2. package/dist/ble.d.ts +160 -0
  3. package/dist/ble.js +157 -0
  4. package/dist/capacitive.d.ts +22 -0
  5. package/dist/capacitive.js +27 -0
  6. package/dist/emit.d.ts +139 -0
  7. package/dist/emit.js +152 -0
  8. package/dist/fs.d.ts +21 -1
  9. package/dist/fs.js +29 -21
  10. package/dist/http.d.ts +48 -0
  11. package/dist/http.js +104 -0
  12. package/dist/i2c.d.ts +7 -0
  13. package/dist/i2c.js +15 -4
  14. package/dist/index.d.ts +18 -1
  15. package/dist/index.js +17 -1
  16. package/dist/mdns.d.ts +31 -0
  17. package/dist/mdns.js +43 -0
  18. package/dist/mqtt.d.ts +33 -0
  19. package/dist/mqtt.js +48 -0
  20. package/dist/ota.d.ts +29 -0
  21. package/dist/ota.js +38 -0
  22. package/dist/power.d.ts +7 -0
  23. package/dist/power.js +10 -1
  24. package/dist/preferences.d.ts +11 -2
  25. package/dist/preferences.js +28 -27
  26. package/dist/register.d.ts +12 -4
  27. package/dist/register.js +18 -1
  28. package/dist/rmt.d.ts +48 -0
  29. package/dist/rmt.js +81 -0
  30. package/dist/spi.js +10 -7
  31. package/dist/temperature.d.ts +14 -0
  32. package/dist/temperature.js +17 -0
  33. package/dist/timer.d.ts +14 -17
  34. package/dist/timer.js +20 -22
  35. package/dist/types.d.ts +1 -1
  36. package/dist/wifi.d.ts +67 -0
  37. package/dist/wifi.js +151 -0
  38. package/package.json +65 -64
  39. package/src/ble.ts +209 -0
  40. package/src/capacitive.ts +31 -0
  41. package/src/emit.ts +180 -0
  42. package/src/fs.ts +30 -22
  43. package/src/http.ts +144 -0
  44. package/src/i2c.ts +16 -4
  45. package/src/index.ts +21 -1
  46. package/src/mdns.ts +50 -0
  47. package/src/mqtt.ts +57 -0
  48. package/src/ota.ts +44 -0
  49. package/src/power.ts +11 -1
  50. package/src/preferences.ts +56 -27
  51. package/src/register.ts +16 -4
  52. package/src/rmt.ts +125 -0
  53. package/src/spi.ts +10 -7
  54. package/src/temperature.ts +20 -0
  55. package/src/timer.ts +22 -23
  56. package/src/types.ts +1 -0
  57. package/src/wifi.ts +221 -0
package/dist/mqtt.js ADDED
@@ -0,0 +1,48 @@
1
+ import { callback } from './callback.js';
2
+ /**
3
+ * MqttClass — MQTT 3.1.1 pub/sub client (ESP-IDF esp_mqtt).
4
+ *
5
+ * Lowered to native MQTT HAL ops (mqtt.*): ESP-IDF's esp_mqtt_client_* API.
6
+ * Covers the common IoT pub/sub path: connect to a broker, publish, subscribe
7
+ * with an onMessage callback, and disconnect. The runtime shim owns the event
8
+ * loop translation (ESP-IDF's MQTT event handler → the user's TS callback).
9
+ *
10
+ * Requires a network connection (WiFi) before connect().
11
+ */
12
+ export class MqttClass {
13
+ /** Connect to a broker URI (e.g. "mqtt://broker.local" or "mqtts://..."). */
14
+ connect(brokerUri, clientId) {
15
+ mqttConnect(brokerUri, clientId);
16
+ return true;
17
+ }
18
+ /** Set a handler invoked for every received PUBLISH on a subscribed topic.
19
+ * The handler receives (topic, payload). */
20
+ onMessage(handler) {
21
+ mqttOnMessage(callback(handler));
22
+ }
23
+ /** Subscribe to a topic filter (e.g. "sensors/#"). */
24
+ subscribe(topic) {
25
+ mqttSubscribe(topic);
26
+ }
27
+ /** Publish a message to a topic. */
28
+ publish(topic, data) {
29
+ mqttPublish(topic, data);
30
+ }
31
+ /** True if the client is currently connected to the broker. */
32
+ connected() {
33
+ return mqttConnected();
34
+ }
35
+ /** Disconnect from the broker and free the client. */
36
+ disconnect() {
37
+ mqttDisconnect();
38
+ }
39
+ }
40
+ MqttClass.__instance_name = "MQTT";
41
+ export const MQTT = new MqttClass();
42
+ // ── Semantic primitives (resolved to mqtt.* HAL ops by the transpiler) ──
43
+ export function mqttConnect(brokerUri, clientId) { }
44
+ export function mqttOnMessage(handler) { }
45
+ export function mqttSubscribe(topic) { }
46
+ export function mqttPublish(topic, data) { }
47
+ export function mqttConnected() { return false; }
48
+ export function mqttDisconnect() { }
package/dist/ota.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * OtaClass — over-the-air firmware update (ESP-IDF esp_https_ota / esp_app_format).
3
+ *
4
+ * Lowered to native OTA HAL ops (ota.*): ESP-IDF's esp_https_ota downloads a
5
+ * firmware image over HTTPS and writes it to the OTA partition, then reboots
6
+ * into it. The runtime shim owns the session/progress/verification dance.
7
+ *
8
+ * Requires a network connection (WiFi) and that the partition table defines
9
+ * at least two OTA app slots (the framework's default partitions.csv does).
10
+ */
11
+ export declare class OtaClass {
12
+ static readonly __instance_name = "OTA";
13
+ /** Download and apply a firmware image from an HTTPS URL, then reboot.
14
+ * Blocks until the update is written and verified. Returns true on success
15
+ * (the reboot happens inside the shim on success, so a true return means
16
+ * the new firmware is about to boot). */
17
+ fromUrl(url: string): boolean;
18
+ /** Begin a manual update session (caller writes chunks via write()). */
19
+ begin(): boolean;
20
+ /** Write a chunk of firmware data to the OTA partition. */
21
+ write(chunk: string): void;
22
+ /** Finalize the update: verify, set the boot partition, and reboot. */
23
+ apply(): void;
24
+ }
25
+ export declare const OTA: OtaClass;
26
+ export declare function otaFromUrl(url: string): boolean;
27
+ export declare function otaBegin(): boolean;
28
+ export declare function otaWrite(chunk: string): void;
29
+ export declare function otaApply(): void;
package/dist/ota.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * OtaClass — over-the-air firmware update (ESP-IDF esp_https_ota / esp_app_format).
3
+ *
4
+ * Lowered to native OTA HAL ops (ota.*): ESP-IDF's esp_https_ota downloads a
5
+ * firmware image over HTTPS and writes it to the OTA partition, then reboots
6
+ * into it. The runtime shim owns the session/progress/verification dance.
7
+ *
8
+ * Requires a network connection (WiFi) and that the partition table defines
9
+ * at least two OTA app slots (the framework's default partitions.csv does).
10
+ */
11
+ export class OtaClass {
12
+ /** Download and apply a firmware image from an HTTPS URL, then reboot.
13
+ * Blocks until the update is written and verified. Returns true on success
14
+ * (the reboot happens inside the shim on success, so a true return means
15
+ * the new firmware is about to boot). */
16
+ fromUrl(url) {
17
+ return otaFromUrl(url);
18
+ }
19
+ /** Begin a manual update session (caller writes chunks via write()). */
20
+ begin() {
21
+ return otaBegin();
22
+ }
23
+ /** Write a chunk of firmware data to the OTA partition. */
24
+ write(chunk) {
25
+ otaWrite(chunk);
26
+ }
27
+ /** Finalize the update: verify, set the boot partition, and reboot. */
28
+ apply() {
29
+ otaApply();
30
+ }
31
+ }
32
+ OtaClass.__instance_name = "OTA";
33
+ export const OTA = new OtaClass();
34
+ // ── Semantic primitives (resolved to ota.* HAL ops by the transpiler) ──
35
+ export function otaFromUrl(url) { return false; }
36
+ export function otaBegin() { return false; }
37
+ export function otaWrite(chunk) { }
38
+ export function otaApply() { }
package/dist/power.d.ts CHANGED
@@ -8,6 +8,13 @@
8
8
  export declare class PowerClass {
9
9
  static readonly __instance_name = "Power";
10
10
  deepSleep(ms: number): void;
11
+ /** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
12
+ *
13
+ * Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
14
+ * variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
15
+ * the framework flags non-RTC pins at compile time. Wakeup resets the chip,
16
+ * so this call never returns. */
17
+ deepSleepPin(pin: number, level: 0 | 1): void;
11
18
  lightSleep(): void;
12
19
  setCpuFrequency(mhz: number): void;
13
20
  }
package/dist/power.js CHANGED
@@ -1,4 +1,4 @@
1
- import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency } from './emit.js';
1
+ import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency, powerDeepSleepPin } from './emit.js';
2
2
  /**
3
3
  * PowerClass provides control over MCU power states and clock frequencies.
4
4
  *
@@ -10,6 +10,15 @@ export class PowerClass {
10
10
  deepSleep(ms) {
11
11
  powerDeepSleep(ms);
12
12
  }
13
+ /** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
14
+ *
15
+ * Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
16
+ * variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
17
+ * the framework flags non-RTC pins at compile time. Wakeup resets the chip,
18
+ * so this call never returns. */
19
+ deepSleepPin(pin, level) {
20
+ powerDeepSleepPin(pin, level);
21
+ }
13
22
  lightSleep() {
14
23
  powerLightSleep();
15
24
  }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Preferences — a persistent key/value store, lowered to native NVS
3
+ * (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
4
+ *
5
+ * No include() calls here — NVS headers are framework-owned and added via
6
+ * forcedIncludes when the program uses preferences.* ops. Method bodies pass
7
+ * parameters directly into semantic calls so the resolver can statically track
8
+ * every argument (matching the WiFi/HTTP HAL pattern).
9
+ */
1
10
  export declare class PreferencesClass {
2
11
  static readonly __instance_name = "Preferences";
3
12
  begin(name: string, readOnly?: boolean): void;
@@ -8,10 +17,10 @@ export declare class PreferencesClass {
8
17
  getInt(key: string, defaultValue?: number): number;
9
18
  putUInt(key: string, value: number): void;
10
19
  getUInt(key: string, defaultValue?: number): number;
11
- putFloat(key: string, value: number): void;
12
- getFloat(key: string, defaultValue?: number): number;
13
20
  putBool(key: string, value: boolean): void;
14
21
  getBool(key: string, defaultValue?: boolean): boolean;
22
+ putFloat(key: string, value: number): void;
23
+ getFloat(key: string, defaultValue?: number): number;
15
24
  putString(key: string, value: string): void;
16
25
  getString(key: string, defaultValue?: string): string;
17
26
  }
@@ -1,54 +1,55 @@
1
- import { rawCpp } from './emit.js';
1
+ import { preferencesBegin, preferencesEnd, preferencesClear, preferencesRemove, preferencesPutInt, preferencesGetInt, preferencesPutUInt, preferencesGetUInt, preferencesPutBool, preferencesGetBool, preferencesPutFloat, preferencesGetFloat, preferencesPutString, preferencesGetString, } from './emit.js';
2
+ /**
3
+ * Preferences — a persistent key/value store, lowered to native NVS
4
+ * (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
5
+ *
6
+ * No include() calls here — NVS headers are framework-owned and added via
7
+ * forcedIncludes when the program uses preferences.* ops. Method bodies pass
8
+ * parameters directly into semantic calls so the resolver can statically track
9
+ * every argument (matching the WiFi/HTTP HAL pattern).
10
+ */
2
11
  export class PreferencesClass {
3
- // NOTE: no __includes here. The transpiler emits singleton __includes on
4
- // every architecture with no filtering, and <Preferences.h> is ESP32-only —
5
- // adding it would break AVR builds. The class is ESP32-only by convention.
6
12
  begin(name, readOnly = false) {
7
- rawCpp(`Preferences.begin(${name}.c_str(), ${readOnly});`);
13
+ preferencesBegin(name, readOnly);
8
14
  }
9
15
  end() {
10
- rawCpp(`Preferences.end();`);
16
+ preferencesEnd();
11
17
  }
12
18
  clear() {
13
- rawCpp(`Preferences.clear();`);
19
+ preferencesClear();
14
20
  }
15
21
  remove(key) {
16
- rawCpp(`Preferences.remove(${key}.c_str());`);
22
+ preferencesRemove(key);
17
23
  }
18
24
  putInt(key, value) {
19
- rawCpp(`Preferences.putInt(${key}.c_str(), ${value});`);
25
+ preferencesPutInt(key, value);
20
26
  }
21
27
  getInt(key, defaultValue = 0) {
22
- rawCpp(`return Preferences.getInt(${key}.c_str(), ${defaultValue});`);
23
- return 0;
28
+ return preferencesGetInt(key, defaultValue);
24
29
  }
25
30
  putUInt(key, value) {
26
- rawCpp(`Preferences.putUInt(${key}.c_str(), ${value});`);
31
+ preferencesPutUInt(key, value);
27
32
  }
28
33
  getUInt(key, defaultValue = 0) {
29
- rawCpp(`return Preferences.getUInt(${key}.c_str(), ${defaultValue});`);
30
- return 0;
31
- }
32
- putFloat(key, value) {
33
- rawCpp(`Preferences.putFloat(${key}.c_str(), ${value});`);
34
- }
35
- getFloat(key, defaultValue = 0) {
36
- rawCpp(`return Preferences.getFloat(${key}.c_str(), ${defaultValue});`);
37
- return 0;
34
+ return preferencesGetUInt(key, defaultValue);
38
35
  }
39
36
  putBool(key, value) {
40
- rawCpp(`Preferences.putBool(${key}.c_str(), ${value});`);
37
+ preferencesPutBool(key, value);
41
38
  }
42
39
  getBool(key, defaultValue = false) {
43
- rawCpp(`return Preferences.getBool(${key}.c_str(), ${defaultValue});`);
44
- return false;
40
+ return preferencesGetBool(key, defaultValue);
41
+ }
42
+ putFloat(key, value) {
43
+ preferencesPutFloat(key, value);
44
+ }
45
+ getFloat(key, defaultValue = 0) {
46
+ return preferencesGetFloat(key, defaultValue);
45
47
  }
46
48
  putString(key, value) {
47
- rawCpp(`Preferences.putString(${key}.c_str(), ${value}.c_str());`);
49
+ preferencesPutString(key, value);
48
50
  }
49
51
  getString(key, defaultValue = "") {
50
- rawCpp(`return Preferences.getString(${key}.c_str(), ${defaultValue}.c_str());`);
51
- return "";
52
+ return preferencesGetString(key, defaultValue);
52
53
  }
53
54
  }
54
55
  PreferencesClass.__instance_name = "Preferences";
@@ -4,8 +4,16 @@ export type Bit = 0 | 1;
4
4
  * the bit width for documentation only; the value is the raw field contents. */
5
5
  export type Bits<N extends number = number> = number;
6
6
  /** Class decorator marking a struct as a memory-mapped register at `address`.
7
- * Erased at transpile time — the class becomes a `volatile uint32_t*`. */
8
- export declare function register(address: number): ClassDecorator;
7
+ * Erased at transpile time — the class becomes a `volatile uint32_t*`.
8
+ *
9
+ * These carry real (inert) runtime bodies rather than `declare`, so the
10
+ * `export { register, bits }` re-export in index.ts resolves under Node's ESM
11
+ * loader, which validates that re-exported bindings exist at runtime. They are
12
+ * never invoked: the cuttlefish transpiler detects them by name and lowers the
13
+ * decorated struct away, so these stubs are only reached when the decorator
14
+ * source is imported without transpilation (e.g. host-side tests). */
15
+ export declare function register(_address: number): ClassDecorator;
9
16
  /** Property decorator carrying the bit range [lo, hi] (inclusive) of a field
10
- * within its register. Erased at transpile time. */
11
- export declare function bits(hi: number, lo: number): PropertyDecorator;
17
+ * within its register. Erased at transpile time. See `register` for why these
18
+ * have runtime bodies. */
19
+ export declare function bits(_hi: number, _lo: number): PropertyDecorator;
package/dist/register.js CHANGED
@@ -18,4 +18,21 @@
18
18
  // USART1.UE = 1; // (*USART1 & ~1UL) | ((1 & 1UL) << 0)
19
19
  // const parity = USART1.PS; // ((*USART1 >> 8) & ((1UL << 2) - 1))
20
20
  // ---------------------------------------------------------------------------
21
- export {};
21
+ /** Class decorator marking a struct as a memory-mapped register at `address`.
22
+ * Erased at transpile time — the class becomes a `volatile uint32_t*`.
23
+ *
24
+ * These carry real (inert) runtime bodies rather than `declare`, so the
25
+ * `export { register, bits }` re-export in index.ts resolves under Node's ESM
26
+ * loader, which validates that re-exported bindings exist at runtime. They are
27
+ * never invoked: the cuttlefish transpiler detects them by name and lowers the
28
+ * decorated struct away, so these stubs are only reached when the decorator
29
+ * source is imported without transpilation (e.g. host-side tests). */
30
+ export function register(_address) {
31
+ return () => { };
32
+ }
33
+ /** Property decorator carrying the bit range [lo, hi] (inclusive) of a field
34
+ * within its register. Erased at transpile time. See `register` for why these
35
+ * have runtime bodies. */
36
+ export function bits(_hi, _lo) {
37
+ return () => { };
38
+ }
package/dist/rmt.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { Pin } from './gpio.js';
2
+ /** Pin identifier accepted by RmtChannel: a Pin object, raw GPIO number, or port name. */
3
+ type RmtPin = Pin | number | string;
4
+ /**
5
+ * RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
6
+ * are independent roles on the same channel object.
7
+ *
8
+ * ```ts
9
+ * const led = new RmtChannel(LED);
10
+ * led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
11
+ * led.txWriteBytes([0, 16, 0]);
12
+ * led.txWaitDone();
13
+ * ```
14
+ */
15
+ export declare class RmtChannel {
16
+ private _pin;
17
+ constructor(pin: RmtPin);
18
+ /** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
19
+ * at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
20
+ * mutation API. Tick units are 1/resolutionHz seconds.
21
+ *
22
+ * Args are positional scalars (not an opts object) because the transpiler's
23
+ * method-body renderer folds scalar params but not property accesses on an
24
+ * object param (opts.resolutionHz would render as a collapsed object + dead
25
+ * property access). Mirrors how I2CBus.begin(address) takes a scalar. */
26
+ txInit(resolutionHz: number, bit0Hi: number, bit0Lo: number, bit1Hi: number, bit1Lo: number, msbFirst?: boolean, queueDepth?: number): void;
27
+ /** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
28
+ txWriteBytes(bytes: number[] | Uint8Array): void;
29
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
30
+ txWriteSymbols(symbols: [number, number][]): void;
31
+ /** Block until the queued TX completes. */
32
+ txWaitDone(timeoutMs?: number): void;
33
+ /** Tear down the TX channel and release its slot. */
34
+ txDeinit(): void;
35
+ /** Initialize the channel for RX. Idempotent per pin. */
36
+ rxInit(resolutionHz: number): void;
37
+ /** Register a callback-by-name invoked when an RX burst completes. */
38
+ rxOnReceived(handler: string): void;
39
+ /** Start receiving. */
40
+ rxStart(): void;
41
+ /** Stop receiving. */
42
+ rxStop(): void;
43
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
44
+ rxRead(maxCount: number): number[];
45
+ /** Tear down the RX channel and release its slot. */
46
+ rxDeinit(): void;
47
+ }
48
+ export {};
package/dist/rmt.js ADDED
@@ -0,0 +1,81 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @typecad/hal — RMT (Remote Control Transceiver) ergonomic API
3
+ // ---------------------------------------------------------------------------
4
+ // Exposes RMT via a RmtChannel class, mirroring the I2CBus/I2CDevice pattern.
5
+ // The transpiler only resolves semantic calls made inside class-method bodies
6
+ // (free top-level calls emit verbatim), so every peripheral exposes its API
7
+ // through a class whose methods call the positional semantic primitives in
8
+ // emit.ts. The resolver collapses object literals, so HALOpIR fields must be
9
+ // scalars; these methods destructure `opts` at the call site before forwarding.
10
+ //
11
+ // Channel identity is the GPIO pin (like pwm.ts's LEDC channel-per-pin model).
12
+ import { rmtTxInit, rmtRxInit, rmtTxWriteBytes, rmtTxWriteSymbols, rmtTxWaitDone, rmtTxDeinit, rmtRxOnReceived, rmtRxStart, rmtRxStop, rmtRxRead, rmtRxDeinit, } from './emit.js';
13
+ /**
14
+ * RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
15
+ * are independent roles on the same channel object.
16
+ *
17
+ * ```ts
18
+ * const led = new RmtChannel(LED);
19
+ * led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
20
+ * led.txWriteBytes([0, 16, 0]);
21
+ * led.txWaitDone();
22
+ * ```
23
+ */
24
+ export class RmtChannel {
25
+ constructor(pin) {
26
+ this._pin = pin;
27
+ }
28
+ // ── TX ─────────────────────────────────────────────────────────────────────
29
+ /** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
30
+ * at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
31
+ * mutation API. Tick units are 1/resolutionHz seconds.
32
+ *
33
+ * Args are positional scalars (not an opts object) because the transpiler's
34
+ * method-body renderer folds scalar params but not property accesses on an
35
+ * object param (opts.resolutionHz would render as a collapsed object + dead
36
+ * property access). Mirrors how I2CBus.begin(address) takes a scalar. */
37
+ txInit(resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst = false, queueDepth = 4) {
38
+ rmtTxInit(this._pin, resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst, queueDepth);
39
+ }
40
+ /** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
41
+ txWriteBytes(bytes) {
42
+ rmtTxWriteBytes(this._pin, bytes);
43
+ }
44
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
45
+ txWriteSymbols(symbols) {
46
+ rmtTxWriteSymbols(this._pin, symbols);
47
+ }
48
+ /** Block until the queued TX completes. */
49
+ txWaitDone(timeoutMs) {
50
+ rmtTxWaitDone(this._pin, timeoutMs);
51
+ }
52
+ /** Tear down the TX channel and release its slot. */
53
+ txDeinit() {
54
+ rmtTxDeinit(this._pin);
55
+ }
56
+ // ── RX ─────────────────────────────────────────────────────────────────────
57
+ /** Initialize the channel for RX. Idempotent per pin. */
58
+ rxInit(resolutionHz) {
59
+ rmtRxInit(this._pin, resolutionHz);
60
+ }
61
+ /** Register a callback-by-name invoked when an RX burst completes. */
62
+ rxOnReceived(handler) {
63
+ rmtRxOnReceived(this._pin, handler);
64
+ }
65
+ /** Start receiving. */
66
+ rxStart() {
67
+ rmtRxStart(this._pin);
68
+ }
69
+ /** Stop receiving. */
70
+ rxStop() {
71
+ rmtRxStop(this._pin);
72
+ }
73
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
74
+ rxRead(maxCount) {
75
+ return rmtRxRead(this._pin, maxCount);
76
+ }
77
+ /** Tear down the RX channel and release its slot. */
78
+ rxDeinit() {
79
+ rmtRxDeinit(this._pin);
80
+ }
81
+ }
package/dist/spi.js CHANGED
@@ -1,4 +1,4 @@
1
- import { spiBegin, spiEnd, spiTransfer, spiBeginTx, spiEndTx, spiCsLow, spiCsHigh, spiSetMode, spiSetBitOrder, rawCpp } from './emit.js';
1
+ import { spiBegin, spiEnd, spiTransfer, spiBeginTx, spiEndTx, spiCsLow, spiCsHigh, spiSetMode, spiSetBitOrder, spiReadBuffer, rawCpp } from './emit.js';
2
2
  import { include } from './include.js';
3
3
  export class SPIDevice {
4
4
  constructor(bus, chipSelect) {
@@ -21,12 +21,15 @@ export class SPIDevice {
21
21
  }
22
22
  readRegister(register, count) {
23
23
  include("<SPI.h>");
24
- rawCpp(`digitalWrite(${this._cs}, LOW);`);
25
- rawCpp(`${this._bus}.transfer(${register});`);
26
- rawCpp(`static uint8_t __spi_buf[${count}];`);
27
- rawCpp(`for (int i=0; i<${count}; i++) __spi_buf[i] = ${this._bus}.transfer(0x00);`);
28
- rawCpp(`digitalWrite(${this._cs}, HIGH);`);
29
- rawCpp(`return __spi_buf;`);
24
+ spiCsLow(this._cs);
25
+ spiTransfer(this._bus, register);
26
+ // Clock `count` dummy bytes and drain them into the caller's buffer
27
+ // (declared by the Uint8Array return marker as `uint8_t data[count]`).
28
+ // Using the semantic primitive — NOT rawCpp — keeps the buffer in user
29
+ // scope so it survives the return (no decayed pointer) and `data.length`
30
+ // / `data[i]` work, mirroring I2CDevice.readBytes.
31
+ spiReadBuffer(this._bus, count, new Uint8Array(count));
32
+ spiCsHigh(this._cs);
30
33
  return new Uint8Array(count);
31
34
  }
32
35
  writeRegister(register, value) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * TemperatureClass — on-chip die temperature sensor.
3
+ *
4
+ * Lowered to the temp.* HAL op: ESP-IDF's temperature_sensor driver reads the
5
+ * internal die temperature in °C. Useful for thermal monitoring and
6
+ * compensation. No external components required.
7
+ */
8
+ export declare class TemperatureClass {
9
+ static readonly __instance_name = "Temperature";
10
+ /** Read the on-chip die temperature in degrees Celsius. */
11
+ read(): number;
12
+ }
13
+ export declare const Temperature: TemperatureClass;
14
+ export declare function tempRead(): number;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TemperatureClass — on-chip die temperature sensor.
3
+ *
4
+ * Lowered to the temp.* HAL op: ESP-IDF's temperature_sensor driver reads the
5
+ * internal die temperature in °C. Useful for thermal monitoring and
6
+ * compensation. No external components required.
7
+ */
8
+ export class TemperatureClass {
9
+ /** Read the on-chip die temperature in degrees Celsius. */
10
+ read() {
11
+ return tempRead();
12
+ }
13
+ }
14
+ TemperatureClass.__instance_name = "Temperature";
15
+ export const Temperature = new TemperatureClass();
16
+ // ── Semantic primitive (resolved to temp.* HAL op by the transpiler) ──
17
+ export function tempRead() { return 0; }
package/dist/timer.d.ts CHANGED
@@ -3,33 +3,30 @@
3
3
  *
4
4
  * Hardware timers are distinct from the software-based setInterval/setTimeout
5
5
  * and are typically used for high-precision timing, PWM generation, or
6
- * interrupt-driven tasks.
6
+ * interrupt-driven tasks. Lowered to hwtimer.* HAL ops: ESP-IDF's GPTimer
7
+ * driver (driver/gptimer.h); Arduino's HardwareTimer (Timer0/1/2 on STM32).
8
+ *
9
+ * The instance index maps to the platform's timer numbering (ESP-IDF GPTimer
10
+ * unit 0..n, STM32 TIM0..n).
7
11
  */
8
12
  export declare class HardwareTimer {
9
13
  private _instance;
10
14
  constructor(instance: number);
11
- /**
12
- * Sets the timer frequency in Hertz.
13
- * Note: The actual frequency may be limited by the hardware's clock dividers.
14
- */
15
+ /** Sets the timer frequency in Hertz. */
15
16
  setFrequency(hz: number): void;
16
- /**
17
- * Attaches an interrupt handler that executes when the timer overflows.
18
- */
17
+ /** Attaches an interrupt handler that executes when the timer overflows. */
19
18
  onOverflow(handler: () => void): void;
20
- /**
21
- * Starts the timer.
22
- */
19
+ /** Starts the timer. */
23
20
  start(): void;
24
- /**
25
- * Stops the timer.
26
- */
21
+ /** Stops the timer. */
27
22
  stop(): void;
28
- /**
29
- * Returns the bit resolution of the timer (e.g., 8, 16, 32).
30
- */
23
+ /** Returns the bit resolution of the timer (e.g., 8, 16, 32). */
31
24
  getBits(): number;
32
25
  }
33
26
  export declare const Timer0: HardwareTimer;
34
27
  export declare const Timer1: HardwareTimer;
35
28
  export declare const Timer2: HardwareTimer;
29
+ export declare function hwtimerSetFrequency(instance: number, hz: number): void;
30
+ export declare function hwtimerOnOverflow(instance: number, handler: string): void;
31
+ export declare function hwtimerStart(instance: number): void;
32
+ export declare function hwtimerStop(instance: number): void;
package/dist/timer.js CHANGED
@@ -1,44 +1,37 @@
1
- import { rawCpp, boardResolve } from './emit.js';
1
+ import { boardResolve } from './emit.js';
2
2
  import { callback } from './callback.js';
3
3
  /**
4
4
  * HardwareTimer provides direct control over the board's hardware timers.
5
5
  *
6
6
  * Hardware timers are distinct from the software-based setInterval/setTimeout
7
7
  * and are typically used for high-precision timing, PWM generation, or
8
- * interrupt-driven tasks.
8
+ * interrupt-driven tasks. Lowered to hwtimer.* HAL ops: ESP-IDF's GPTimer
9
+ * driver (driver/gptimer.h); Arduino's HardwareTimer (Timer0/1/2 on STM32).
10
+ *
11
+ * The instance index maps to the platform's timer numbering (ESP-IDF GPTimer
12
+ * unit 0..n, STM32 TIM0..n).
9
13
  */
10
14
  export class HardwareTimer {
11
15
  constructor(instance) {
12
16
  this._instance = instance;
13
17
  }
14
- /**
15
- * Sets the timer frequency in Hertz.
16
- * Note: The actual frequency may be limited by the hardware's clock dividers.
17
- */
18
+ /** Sets the timer frequency in Hertz. */
18
19
  setFrequency(hz) {
19
- rawCpp(`Timer${this._instance}.setFrequency(${hz});`);
20
+ hwtimerSetFrequency(this._instance, hz);
20
21
  }
21
- /**
22
- * Attaches an interrupt handler that executes when the timer overflows.
23
- */
22
+ /** Attaches an interrupt handler that executes when the timer overflows. */
24
23
  onOverflow(handler) {
25
- rawCpp(`Timer${this._instance}.onOverflow(${callback(handler)});`);
24
+ hwtimerOnOverflow(this._instance, callback(handler));
26
25
  }
27
- /**
28
- * Starts the timer.
29
- */
26
+ /** Starts the timer. */
30
27
  start() {
31
- rawCpp(`Timer${this._instance}.start();`);
28
+ hwtimerStart(this._instance);
32
29
  }
33
- /**
34
- * Stops the timer.
35
- */
30
+ /** Stops the timer. */
36
31
  stop() {
37
- rawCpp(`Timer${this._instance}.stop();`);
32
+ hwtimerStop(this._instance);
38
33
  }
39
- /**
40
- * Returns the bit resolution of the timer (e.g., 8, 16, 32).
41
- */
34
+ /** Returns the bit resolution of the timer (e.g., 8, 16, 32). */
42
35
  getBits() {
43
36
  // "peripherals.timer" (singular) matches the board-resolver's array-key
44
37
  // derivation (TIMER_INSTANCES → peripherals.timer.<index>.*).
@@ -48,3 +41,8 @@ export class HardwareTimer {
48
41
  export const Timer0 = new HardwareTimer(0);
49
42
  export const Timer1 = new HardwareTimer(1);
50
43
  export const Timer2 = new HardwareTimer(2);
44
+ // ── Semantic primitives (resolved to hwtimer.* HAL ops by the transpiler) ──
45
+ export function hwtimerSetFrequency(instance, hz) { }
46
+ export function hwtimerOnOverflow(instance, handler) { }
47
+ export function hwtimerStart(instance) { }
48
+ export function hwtimerStop(instance) { }
package/dist/types.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface IPinGroup<T extends PinGroupMember = PinGroupMember> {
37
37
  fill(value: DigitalValue): void;
38
38
  }
39
39
  export declare function createPinGroup<T extends PinGroupMember>(pins: T[]): IPinGroup<T>;
40
- export type ArchitectureIdentifier = 'avr' | 'esp32' | 'esp32s2' | 'esp32s3' | 'esp32c3' | 'esp32c6' | 'rp2040' | 'samd' | 'stm32' | 'nrf52' | (string & {});
40
+ export type ArchitectureIdentifier = 'avr' | 'esp32' | 'esp32s2' | 'esp32s3' | 'esp32c3' | 'esp32c6' | 'rp2040' | 'rp2350' | 'samd' | 'stm32' | 'nrf52' | (string & {});
41
41
  export type I2CAddress = number;
42
42
  export type SPIBitOrder = 'msb' | 'lsb';
43
43
  export type SPIMode = 0 | 1 | 2 | 3;