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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +145 -87
  2. package/dist/adc-pin.d.ts +53 -0
  3. package/dist/adc-pin.js +69 -0
  4. package/dist/async.d.ts +3 -11
  5. package/dist/async.js +3 -15
  6. package/dist/ble.d.ts +42 -78
  7. package/dist/ble.js +79 -98
  8. package/dist/counter.d.ts +16 -0
  9. package/dist/counter.js +32 -0
  10. package/dist/dac-pin.d.ts +13 -0
  11. package/dist/dac-pin.js +21 -0
  12. package/dist/emit.d.ts +123 -196
  13. package/dist/emit.js +146 -208
  14. package/dist/fs.d.ts +12 -31
  15. package/dist/fs.js +30 -40
  16. package/dist/gpio-pin.d.ts +46 -0
  17. package/dist/gpio-pin.js +77 -0
  18. package/dist/gpio.d.ts +0 -103
  19. package/dist/gpio.js +16 -227
  20. package/dist/http.d.ts +38 -39
  21. package/dist/http.js +53 -78
  22. package/dist/i2c-target.d.ts +28 -0
  23. package/dist/i2c-target.js +52 -0
  24. package/dist/i2c.d.ts +5 -43
  25. package/dist/i2c.js +17 -130
  26. package/dist/index.d.ts +30 -42
  27. package/dist/index.js +27 -39
  28. package/dist/math.d.ts +0 -13
  29. package/dist/math.js +9 -13
  30. package/dist/mqtt.d.ts +15 -25
  31. package/dist/mqtt.js +32 -28
  32. package/dist/power.d.ts +9 -17
  33. package/dist/power.js +22 -20
  34. package/dist/preferences.d.ts +17 -25
  35. package/dist/preferences.js +54 -52
  36. package/dist/pulse.d.ts +4 -4
  37. package/dist/pulse.js +6 -2
  38. package/dist/pwm-pin.d.ts +24 -0
  39. package/dist/pwm-pin.js +38 -0
  40. package/dist/random.d.ts +0 -2
  41. package/dist/random.js +14 -20
  42. package/dist/sensor-catalog.generated.d.ts +997 -0
  43. package/dist/sensor-catalog.generated.js +764 -0
  44. package/dist/sensor.d.ts +46 -0
  45. package/dist/sensor.js +52 -0
  46. package/dist/shift-pin.d.ts +2 -0
  47. package/dist/shift-pin.js +13 -0
  48. package/dist/spi-target.d.ts +25 -0
  49. package/dist/spi-target.js +42 -0
  50. package/dist/spi.d.ts +8 -26
  51. package/dist/spi.js +15 -87
  52. package/dist/thread.d.ts +18 -0
  53. package/dist/thread.js +36 -0
  54. package/dist/time.d.ts +23 -0
  55. package/dist/time.js +43 -0
  56. package/dist/timing.d.ts +17 -7
  57. package/dist/timing.js +17 -7
  58. package/dist/types.d.ts +4 -34
  59. package/dist/types.js +5 -47
  60. package/dist/uart-port.d.ts +26 -0
  61. package/dist/uart-port.js +52 -0
  62. package/dist/uart.d.ts +0 -17
  63. package/dist/uart.js +10 -53
  64. package/dist/usb.d.ts +26 -0
  65. package/dist/usb.js +66 -0
  66. package/dist/watchdog.d.ts +12 -0
  67. package/dist/watchdog.js +28 -0
  68. package/dist/wifi.d.ts +88 -64
  69. package/dist/wifi.js +112 -126
  70. package/dist/zephyr-tokens.generated.d.ts +8 -0
  71. package/dist/zephyr-tokens.generated.js +73 -0
  72. package/package.json +7 -8
  73. package/src/adc-pin.ts +89 -0
  74. package/src/async.ts +3 -16
  75. package/src/ble.ts +84 -111
  76. package/src/counter.ts +40 -0
  77. package/src/dac-pin.ts +28 -0
  78. package/src/emit.ts +157 -238
  79. package/src/fs.ts +47 -54
  80. package/src/gpio-pin.ts +91 -0
  81. package/src/gpio.ts +49 -320
  82. package/src/http.ts +75 -95
  83. package/src/i2c-target.ts +63 -0
  84. package/src/i2c.ts +29 -167
  85. package/src/index.ts +32 -46
  86. package/src/math.ts +9 -14
  87. package/src/mqtt.ts +39 -31
  88. package/src/preferences.ts +52 -61
  89. package/src/pwm-pin.ts +54 -0
  90. package/src/random.ts +14 -21
  91. package/src/sensor-catalog.generated.ts +1238 -0
  92. package/src/sensor.ts +80 -0
  93. package/src/shift-pin.ts +16 -0
  94. package/src/spi-target.ts +53 -0
  95. package/src/spi.ts +27 -121
  96. package/src/thread.ts +44 -0
  97. package/src/time.ts +50 -0
  98. package/src/types.ts +14 -89
  99. package/src/uart-port.ts +64 -0
  100. package/src/usb.ts +82 -0
  101. package/src/watchdog.ts +35 -0
  102. package/src/wifi.ts +147 -179
  103. package/src/zephyr-tokens.generated.ts +77 -0
  104. package/src/adc.ts +0 -30
  105. package/src/capacitive.ts +0 -31
  106. package/src/constants.ts +0 -23
  107. package/src/dac.ts +0 -21
  108. package/src/eeprom.ts +0 -26
  109. package/src/interrupts.ts +0 -35
  110. package/src/mdns.ts +0 -50
  111. package/src/ota.ts +0 -44
  112. package/src/power.ts +0 -36
  113. package/src/pulse.ts +0 -63
  114. package/src/rmt.ts +0 -125
  115. package/src/shift.ts +0 -88
  116. package/src/temperature.ts +0 -20
  117. package/src/timer.ts +0 -58
  118. package/src/timing.ts +0 -67
  119. package/src/uart.ts +0 -77
  120. package/src/utils.ts +0 -17
  121. package/src/wdt.ts +0 -17
package/src/mdns.ts DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * MdnsClass — mDNS service discovery (ESP-IDF esp_mdns).
3
- *
4
- * Lowered to native mDNS HAL ops (mdns.*): ESP-IDF's esp_mdns component
5
- * advertises the device on the local network as `<hostname>.local` and
6
- * publishes services (e.g. `_http._tcp`) for discovery by Bonjour/Avahi.
7
- *
8
- * The semantic primitives (mdnsStart / mdnsAddService / ...) are resolved to
9
- * mdns.* HAL ops by the transpiler; this class is the ergonomic surface.
10
- *
11
- * Requires WiFi to be connected (mDNS rides on the station interface).
12
- */
13
- export class MdnsClass {
14
- static readonly __instance_name = "MDNS";
15
-
16
- /** Initialize mDNS and set the host name (advertised as <name>.local). */
17
- start(hostname: string): boolean {
18
- mdnsStart(hostname);
19
- return true;
20
- }
21
-
22
- /** Set/override the host name after start(). */
23
- setHostname(name: string): void {
24
- mdnsSetHostname(name);
25
- }
26
-
27
- /** Publish a service instance. proto is "_tcp" or "_udp". */
28
- addService(instance: string, proto: string, port: number): void {
29
- mdnsAddService(instance, proto, port);
30
- }
31
-
32
- /** Advertise that the device is reachable (sends a probe/announce). */
33
- announce(): void {
34
- mdnsAnnounce();
35
- }
36
-
37
- /** Tear down the mDNS responder. */
38
- stop(): void {
39
- mdnsStop();
40
- }
41
- }
42
-
43
- export const MDNS = new MdnsClass();
44
-
45
- // ── Semantic primitives (resolved to mdns.* HAL ops by the transpiler) ──
46
- export function mdnsStart(hostname: string): void {}
47
- export function mdnsSetHostname(name: string): void {}
48
- export function mdnsAddService(instance: string, proto: string, port: number): void {}
49
- export function mdnsAnnounce(): void {}
50
- export function mdnsStop(): void {}
package/src/ota.ts DELETED
@@ -1,44 +0,0 @@
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
- static readonly __instance_name = "OTA";
13
-
14
- /** Download and apply a firmware image from an HTTPS URL, then reboot.
15
- * Blocks until the update is written and verified. Returns true on success
16
- * (the reboot happens inside the shim on success, so a true return means
17
- * the new firmware is about to boot). */
18
- fromUrl(url: string): boolean {
19
- return otaFromUrl(url);
20
- }
21
-
22
- /** Begin a manual update session (caller writes chunks via write()). */
23
- begin(): boolean {
24
- return otaBegin();
25
- }
26
-
27
- /** Write a chunk of firmware data to the OTA partition. */
28
- write(chunk: string): void {
29
- otaWrite(chunk);
30
- }
31
-
32
- /** Finalize the update: verify, set the boot partition, and reboot. */
33
- apply(): void {
34
- otaApply();
35
- }
36
- }
37
-
38
- export const OTA = new OtaClass();
39
-
40
- // ── Semantic primitives (resolved to ota.* HAL ops by the transpiler) ──
41
- export function otaFromUrl(url: string): boolean { return false; }
42
- export function otaBegin(): boolean { return false; }
43
- export function otaWrite(chunk: string): void {}
44
- export function otaApply(): void {}
package/src/power.ts DELETED
@@ -1,36 +0,0 @@
1
- import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency, powerDeepSleepPin } from './emit.js';
2
-
3
- /**
4
- * PowerClass provides control over MCU power states and clock frequencies.
5
- *
6
- * The arch guard (ESP32 family vs AVR) lives in the strategy, not here — it
7
- * relies on the FQBN-derived architecture which is always available at
8
- * transpile time, unlike `board("architecture")` which needs a board package.
9
- */
10
- export class PowerClass {
11
- static readonly __instance_name = "Power";
12
-
13
- deepSleep(ms: number): void {
14
- powerDeepSleep(ms);
15
- }
16
-
17
- /** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
18
- *
19
- * Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
20
- * variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
21
- * the framework flags non-RTC pins at compile time. Wakeup resets the chip,
22
- * so this call never returns. */
23
- deepSleepPin(pin: number, level: 0 | 1): void {
24
- powerDeepSleepPin(pin, level);
25
- }
26
-
27
- lightSleep(): void {
28
- powerLightSleep();
29
- }
30
-
31
- setCpuFrequency(mhz: number): void {
32
- powerSetCpuFrequency(mhz);
33
- }
34
- }
35
-
36
- export const Power = new PowerClass();
package/src/pulse.ts DELETED
@@ -1,63 +0,0 @@
1
- import { rawCpp } from './emit.js';
2
- import { HIGH, LOW } from './constants.js';
3
- import type { Pin, InputPin } from './gpio.js';
4
-
5
- export function pulseIn(pin: number, value: number, timeout?: number): number {
6
- if (timeout !== undefined) {
7
- rawCpp(`return pulseIn(${pin}, ${value}, ${timeout});`);
8
- } else {
9
- rawCpp(`return pulseIn(${pin}, ${value});`);
10
- }
11
- return 0;
12
- }
13
- export function pulseInLong(pin: number, value: number, timeout?: number): number {
14
- if (timeout !== undefined) {
15
- rawCpp(`return pulseInLong(${pin}, ${value}, ${timeout});`);
16
- } else {
17
- rawCpp(`return pulseInLong(${pin}, ${value});`);
18
- }
19
- return 0;
20
- }
21
-
22
- export class Pulse {
23
- /**
24
- * Functional entrypoint for measuring pulses.
25
- * @example Pulse.on(D7).high()
26
- */
27
- static on(pin: Pin | InputPin): PulseMeasurement {
28
- return new PulseMeasurement(pin);
29
- }
30
-
31
- /** Measure long pulses using high-precision 64-bit timers. */
32
- static long(pin: Pin | InputPin, value: number): number {
33
- rawCpp(`return pulseInLong(${pin.number}, ${value});`);
34
- return 0;
35
- }
36
- }
37
-
38
- class PulseMeasurement {
39
- private _pin: number;
40
- private _timeout: number | undefined;
41
-
42
- constructor(pin: Pin | InputPin) {
43
- this._pin = pin.number;
44
- }
45
-
46
- /** Set the maximum wait time for a pulse (in microseconds). */
47
- timeout(us: number): this {
48
- this._timeout = us;
49
- return this;
50
- }
51
-
52
- /** Measures the next HIGH pulse duration in microseconds. */
53
- high(): number {
54
- rawCpp(`return pulseIn(${this._pin}, HIGH${this._timeout !== undefined ? `, ${this._timeout}` : ""});`);
55
- return 0;
56
- }
57
-
58
- /** Measures the next LOW pulse duration in microseconds. */
59
- low(): number {
60
- rawCpp(`return pulseIn(${this._pin}, LOW${this._timeout !== undefined ? `, ${this._timeout}` : ""});`);
61
- return 0;
62
- }
63
- }
package/src/rmt.ts DELETED
@@ -1,125 +0,0 @@
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
-
13
- import type { Pin } from './gpio.js';
14
- import {
15
- rmtTxInit,
16
- rmtRxInit,
17
- rmtTxWriteBytes,
18
- rmtTxWriteSymbols,
19
- rmtTxWaitDone,
20
- rmtTxDeinit,
21
- rmtRxOnReceived,
22
- rmtRxStart,
23
- rmtRxStop,
24
- rmtRxRead,
25
- rmtRxDeinit,
26
- } from './emit.js';
27
-
28
- /** Pin identifier accepted by RmtChannel: a Pin object, raw GPIO number, or port name. */
29
- type RmtPin = Pin | number | string;
30
-
31
- /**
32
- * RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
33
- * are independent roles on the same channel object.
34
- *
35
- * ```ts
36
- * const led = new RmtChannel(LED);
37
- * led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
38
- * led.txWriteBytes([0, 16, 0]);
39
- * led.txWaitDone();
40
- * ```
41
- */
42
- export class RmtChannel {
43
- private _pin: RmtPin;
44
-
45
- constructor(pin: RmtPin) {
46
- this._pin = pin;
47
- }
48
-
49
- // ── TX ─────────────────────────────────────────────────────────────────────
50
- /** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
51
- * at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
52
- * mutation API. Tick units are 1/resolutionHz seconds.
53
- *
54
- * Args are positional scalars (not an opts object) because the transpiler's
55
- * method-body renderer folds scalar params but not property accesses on an
56
- * object param (opts.resolutionHz would render as a collapsed object + dead
57
- * property access). Mirrors how I2CBus.begin(address) takes a scalar. */
58
- txInit(
59
- resolutionHz: number,
60
- bit0Hi: number, bit0Lo: number,
61
- bit1Hi: number, bit1Lo: number,
62
- msbFirst: boolean = false,
63
- queueDepth: number = 4,
64
- ): void {
65
- rmtTxInit(
66
- this._pin,
67
- resolutionHz,
68
- bit0Hi, bit0Lo,
69
- bit1Hi, bit1Lo,
70
- msbFirst,
71
- queueDepth,
72
- );
73
- }
74
-
75
- /** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
76
- txWriteBytes(bytes: number[] | Uint8Array): void {
77
- rmtTxWriteBytes(this._pin, bytes);
78
- }
79
-
80
- /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
81
- txWriteSymbols(symbols: [number, number][]): void {
82
- rmtTxWriteSymbols(this._pin, symbols);
83
- }
84
-
85
- /** Block until the queued TX completes. */
86
- txWaitDone(timeoutMs?: number): void {
87
- rmtTxWaitDone(this._pin, timeoutMs);
88
- }
89
-
90
- /** Tear down the TX channel and release its slot. */
91
- txDeinit(): void {
92
- rmtTxDeinit(this._pin);
93
- }
94
-
95
- // ── RX ─────────────────────────────────────────────────────────────────────
96
- /** Initialize the channel for RX. Idempotent per pin. */
97
- rxInit(resolutionHz: number): void {
98
- rmtRxInit(this._pin, resolutionHz);
99
- }
100
-
101
- /** Register a callback-by-name invoked when an RX burst completes. */
102
- rxOnReceived(handler: string): void {
103
- rmtRxOnReceived(this._pin, handler);
104
- }
105
-
106
- /** Start receiving. */
107
- rxStart(): void {
108
- rmtRxStart(this._pin);
109
- }
110
-
111
- /** Stop receiving. */
112
- rxStop(): void {
113
- rmtRxStop(this._pin);
114
- }
115
-
116
- /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
117
- rxRead(maxCount: number): number[] {
118
- return rmtRxRead(this._pin, maxCount);
119
- }
120
-
121
- /** Tear down the RX channel and release its slot. */
122
- rxDeinit(): void {
123
- rmtRxDeinit(this._pin);
124
- }
125
- }
package/src/shift.ts DELETED
@@ -1,88 +0,0 @@
1
- import { rawCpp } from './emit.js';
2
- import { LSBFIRST, MSBFIRST } from './constants.js';
3
- import type { Pin, OutputPin, InputPin } from './gpio.js';
4
-
5
- export function shiftIn(dataPin: number, clockPin: number, bitOrder: number): number {
6
- rawCpp(`return shiftIn(${dataPin}, ${clockPin}, ${bitOrder});`);
7
- return 0;
8
- }
9
- export function shiftOut(dataPin: number, clockPin: number, bitOrder: number, value: number): void {
10
- rawCpp(`shiftOut(${dataPin}, ${clockPin}, ${bitOrder}, ${value});`);
11
- }
12
-
13
- export class Shift {
14
- /** Directly shifts a byte out to a pin. */
15
- static out(dataPin: Pin | OutputPin, clockPin: Pin | OutputPin, order: 'lsb' | 'msb', value: number): void {
16
- const bitOrder = order === 'lsb' ? LSBFIRST : MSBFIRST;
17
- rawCpp(`shiftOut(${dataPin.number}, ${clockPin.number}, ${bitOrder}, ${value});`);
18
- }
19
-
20
- /** Directly shifts a byte in from a pin. */
21
- static in(dataPin: Pin | InputPin, clockPin: Pin | OutputPin, order: 'lsb' | 'msb'): number {
22
- const bitOrder = order === 'lsb' ? LSBFIRST : MSBFIRST;
23
- rawCpp(`return shiftIn(${dataPin.number}, ${clockPin.number}, ${bitOrder});`);
24
- return 0;
25
- }
26
-
27
- /** Fluent builder for shifting out. */
28
- static write(dataPin: Pin | OutputPin, value: number): ShiftOutBuilder {
29
- return new ShiftOutBuilder(dataPin, value);
30
- }
31
-
32
- /** Fluent builder for shifting in. */
33
- static read(dataPin: Pin | InputPin): ShiftInBuilder {
34
- return new ShiftInBuilder(dataPin);
35
- }
36
- }
37
-
38
- class ShiftOutBuilder {
39
- private _dataPin: number;
40
- private _value: number;
41
- private _clockPin: number | undefined;
42
-
43
- constructor(dataPin: Pin | OutputPin, value: number) {
44
- this._dataPin = dataPin.number;
45
- this._value = value;
46
- }
47
-
48
- clock(clk: Pin | OutputPin): this {
49
- this._clockPin = clk.number;
50
- return this;
51
- }
52
-
53
- msbFirst(): void {
54
- if (this._clockPin === undefined) throw new Error("Clock pin must be specified");
55
- rawCpp(`shiftOut(${this._dataPin}, ${this._clockPin}, MSBFIRST, ${this._value});`);
56
- }
57
-
58
- lsbFirst(): void {
59
- if (this._clockPin === undefined) throw new Error("Clock pin must be specified");
60
- rawCpp(`shiftOut(${this._dataPin}, ${this._clockPin}, LSBFIRST, ${this._value});`);
61
- }
62
- }
63
-
64
- class ShiftInBuilder {
65
- private _dataPin: number;
66
- private _clockPin: number | undefined;
67
-
68
- constructor(dataPin: Pin | InputPin) {
69
- this._dataPin = dataPin.number;
70
- }
71
-
72
- clock(clk: Pin | OutputPin): this {
73
- this._clockPin = clk.number;
74
- return this;
75
- }
76
-
77
- msbFirst(): number {
78
- if (this._clockPin === undefined) throw new Error("Clock pin must be specified");
79
- rawCpp(`return shiftIn(${this._dataPin}, ${this._clockPin}, MSBFIRST);`);
80
- return 0;
81
- }
82
-
83
- lsbFirst(): number {
84
- if (this._clockPin === undefined) throw new Error("Clock pin must be specified");
85
- rawCpp(`return shiftIn(${this._dataPin}, ${this._clockPin}, LSBFIRST);`);
86
- return 0;
87
- }
88
- }
@@ -1,20 +0,0 @@
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
- static readonly __instance_name = "Temperature";
10
-
11
- /** Read the on-chip die temperature in degrees Celsius. */
12
- read(): number {
13
- return tempRead();
14
- }
15
- }
16
-
17
- export const Temperature = new TemperatureClass();
18
-
19
- // ── Semantic primitive (resolved to temp.* HAL op by the transpiler) ──
20
- export function tempRead(): number { return 0; }
package/src/timer.ts DELETED
@@ -1,58 +0,0 @@
1
- import { boardResolve } from './emit.js';
2
- import { callback } from './callback.js';
3
-
4
- /**
5
- * HardwareTimer provides direct control over the board's hardware timers.
6
- *
7
- * Hardware timers are distinct from the software-based setInterval/setTimeout
8
- * and are typically used for high-precision timing, PWM generation, or
9
- * interrupt-driven tasks. Lowered to hwtimer.* HAL ops: ESP-IDF's GPTimer
10
- * driver (driver/gptimer.h); Arduino's HardwareTimer (Timer0/1/2 on STM32).
11
- *
12
- * The instance index maps to the platform's timer numbering (ESP-IDF GPTimer
13
- * unit 0..n, STM32 TIM0..n).
14
- */
15
- export class HardwareTimer {
16
- private _instance: number;
17
-
18
- constructor(instance: number) {
19
- this._instance = instance;
20
- }
21
-
22
- /** Sets the timer frequency in Hertz. */
23
- setFrequency(hz: number): void {
24
- hwtimerSetFrequency(this._instance, hz);
25
- }
26
-
27
- /** Attaches an interrupt handler that executes when the timer overflows. */
28
- onOverflow(handler: () => void): void {
29
- hwtimerOnOverflow(this._instance, callback(handler));
30
- }
31
-
32
- /** Starts the timer. */
33
- start(): void {
34
- hwtimerStart(this._instance);
35
- }
36
-
37
- /** Stops the timer. */
38
- stop(): void {
39
- hwtimerStop(this._instance);
40
- }
41
-
42
- /** Returns the bit resolution of the timer (e.g., 8, 16, 32). */
43
- getBits(): number {
44
- // "peripherals.timer" (singular) matches the board-resolver's array-key
45
- // derivation (TIMER_INSTANCES → peripherals.timer.<index>.*).
46
- return boardResolve("peripherals.timer." + this._instance + ".bits");
47
- }
48
- }
49
-
50
- export const Timer0 = new HardwareTimer(0);
51
- export const Timer1 = new HardwareTimer(1);
52
- export const Timer2 = new HardwareTimer(2);
53
-
54
- // ── Semantic primitives (resolved to hwtimer.* HAL ops by the transpiler) ──
55
- export function hwtimerSetFrequency(instance: number, hz: number): void {}
56
- export function hwtimerOnOverflow(instance: number, handler: string): void {}
57
- export function hwtimerStart(instance: number): void {}
58
- export function hwtimerStop(instance: number): void {}
package/src/timing.ts DELETED
@@ -1,67 +0,0 @@
1
- import { rawCpp, getMillis, getMicros, getFreeHeap, delayMs, delayMicro } from './emit.js';
2
- import { callback } from './callback.js';
3
-
4
- export class TimingClass {
5
- static readonly __instance_name = "Timing";
6
- millis(): number { return getMillis(); }
7
- micros(): number { return getMicros(); }
8
- delay(ms: number): void { delayMs(ms); }
9
- delayMicroseconds(us: number): void { delayMicro(us); }
10
- freeHeap(): number {
11
- return getFreeHeap();
12
- }
13
-
14
-
15
- setInterval(handler: () => void, timeout: number): number {
16
- rawCpp(`return __tc_setInterval(${callback(handler)}, ${timeout});`);
17
- return 0;
18
- }
19
-
20
- setTimeout(handler: () => void, timeout: number): number {
21
- rawCpp(`return __tc_setTimeout(${callback(handler)}, ${timeout});`);
22
- return 0;
23
- }
24
-
25
- clearInterval(id: number): void {
26
- rawCpp(`__tc_clearInterval(${id});`);
27
- }
28
-
29
- clearTimeout(id: number): void {
30
- rawCpp(`__tc_clearTimeout(${id});`);
31
- }
32
- }
33
-
34
- export const Timing = new TimingClass();
35
-
36
- export function delay(ms: number): void { delayMs(ms); }
37
- export function millis(): number { return getMillis(); }
38
- export function micros(): number { return getMicros(); }
39
- export function delayMicroseconds(us: number): void { delayMicro(us); }
40
- export function freeHeap(): number { return Timing.freeHeap(); }
41
-
42
-
43
- export function setInterval(handler: () => void, timeout: number): number {
44
- rawCpp(`return __tc_setInterval(${callback(handler)}, ${timeout});`);
45
- return 0;
46
- }
47
-
48
- export function setTimeout(handler: () => void, timeout: number): number {
49
- rawCpp(`return __tc_setTimeout(${callback(handler)}, ${timeout});`);
50
- return 0;
51
- }
52
-
53
- export function clearInterval(id: number): void {
54
- rawCpp(`__tc_clearInterval(${id});`);
55
- }
56
-
57
- export function clearTimeout(id: number): void {
58
- rawCpp(`__tc_clearTimeout(${id});`);
59
- }
60
-
61
- /** Re-map a number from one range to another. Passes through to the Arduino
62
- * core `map()` macro — the transpiler lowers this to a bare `map(...)` call,
63
- * so the target framework must provide the implementation (Arduino.h does). */
64
- export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number { return 0; }
65
- /** Constrain a number to a range. Passes through to the Arduino core
66
- * `constrain()` macro — see note on `map()` above. */
67
- export function constrain(value: number, low: number, high: number): number { return 0; }
package/src/uart.ts DELETED
@@ -1,77 +0,0 @@
1
- import { uartBegin, uartEnd, uartPrint, uartPrintln, uartPrintf, uartWrite, uartRead, uartPeek, uartAvailable, uartFlush, rawCpp } from './emit.js';
2
-
3
- export class SerialPort {
4
- static readonly __includes = ["<Arduino.h>"];
5
- private _port: string;
6
-
7
- constructor(port: string) {
8
- this._port = port;
9
- }
10
-
11
- begin(baud: number = 9600): this {
12
- uartBegin(this._port, baud);
13
- return this;
14
- }
15
-
16
- end(): void {
17
- uartEnd(this._port);
18
- }
19
-
20
- print(value: any): void {
21
- uartPrint(this._port, value);
22
- }
23
-
24
- println(value: any): void {
25
- uartPrintln(this._port, value);
26
- }
27
-
28
- printf(format: string, ...args: any[]): void {
29
- uartPrintf(this._port, format, args);
30
- }
31
-
32
- write(data: any): void {
33
- uartWrite(this._port, data);
34
- }
35
-
36
- read(): number {
37
- return uartRead(this._port);
38
- }
39
-
40
- readLine(): string {
41
- rawCpp(`return ${this._port}.readStringUntil('\\n');`);
42
- return "";
43
- }
44
-
45
- peek(): number {
46
- return uartPeek(this._port);
47
- }
48
-
49
- available(): number {
50
- return uartAvailable(this._port);
51
- }
52
-
53
- flush(): void {
54
- uartFlush(this._port);
55
- }
56
-
57
- waitForConnection(timeout?: number): Promise<void> {
58
- rawCpp(`while (!${this._port}) { delay(10); }`);
59
- return Promise.resolve();
60
- }
61
-
62
- take(): this | null {
63
- // Basic implementation for single-threaded Arduino;
64
- // real locking would be framework-specific.
65
- return this;
66
- }
67
-
68
- release(): void {
69
- // No-op for standard Arduino.
70
- }
71
- }
72
-
73
-
74
- /** Map TypeCAD UART instance number to Arduino C++ object name. UART0→Serial, UART1→Serial1 */
75
- export function serialName(instance: number): string {
76
- return instance === 0 ? "Serial" : `Serial${instance}`;
77
- }
package/src/utils.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Helper to inflate peripheral instances from a definition list into a sparse array
3
- * for named destructuring.
4
- *
5
- * @example
6
- * export const [UART0, UART1] = createHALInstances(UART_INSTANCES, i => new SerialPort(serialName(i)));
7
- */
8
- export function createHALInstances<T>(
9
- instances: readonly { instance: number }[],
10
- factory: (instance: number) => T
11
- ): T[] {
12
- const result: T[] = [];
13
- for (const item of instances) {
14
- result[item.instance] = factory(item.instance);
15
- }
16
- return result;
17
- }
package/src/wdt.ts DELETED
@@ -1,17 +0,0 @@
1
- import { wdtEnable, wdtReset, wdtDisable } from './emit.js';
2
-
3
- export class WDTClass {
4
- static readonly __instance_name = "WDT";
5
-
6
- enable(timeout: number | string): void {
7
- wdtEnable(timeout);
8
- }
9
- reset(): void {
10
- wdtReset();
11
- }
12
- disable(): void {
13
- wdtDisable();
14
- }
15
- }
16
-
17
- export const WDT = new WDTClass();