@typecad/hal 0.1.0-alpha.1

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 (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -0
  3. package/dist/adc.d.ts +13 -0
  4. package/dist/adc.js +22 -0
  5. package/dist/async.d.ts +30 -0
  6. package/dist/async.js +56 -0
  7. package/dist/board.d.ts +3 -0
  8. package/dist/board.js +5 -0
  9. package/dist/callback.d.ts +4 -0
  10. package/dist/callback.js +6 -0
  11. package/dist/constants.d.ts +21 -0
  12. package/dist/constants.js +23 -0
  13. package/dist/dac.d.ts +12 -0
  14. package/dist/dac.js +17 -0
  15. package/dist/eeprom.d.ts +16 -0
  16. package/dist/eeprom.js +21 -0
  17. package/dist/emit.d.ts +121 -0
  18. package/dist/emit.js +177 -0
  19. package/dist/fs.d.ts +13 -0
  20. package/dist/fs.js +39 -0
  21. package/dist/gpio.d.ts +108 -0
  22. package/dist/gpio.js +230 -0
  23. package/dist/i2c.d.ts +40 -0
  24. package/dist/i2c.js +126 -0
  25. package/dist/include.d.ts +5 -0
  26. package/dist/include.js +5 -0
  27. package/dist/index.d.ts +37 -0
  28. package/dist/index.js +30 -0
  29. package/dist/interrupts.d.ts +17 -0
  30. package/dist/interrupts.js +25 -0
  31. package/dist/math.d.ts +22 -0
  32. package/dist/math.js +28 -0
  33. package/dist/power.d.ts +14 -0
  34. package/dist/power.js +21 -0
  35. package/dist/preferences.d.ts +18 -0
  36. package/dist/preferences.js +55 -0
  37. package/dist/pulse.d.ts +24 -0
  38. package/dist/pulse.js +53 -0
  39. package/dist/random.d.ts +12 -0
  40. package/dist/random.js +26 -0
  41. package/dist/register.d.ts +11 -0
  42. package/dist/register.js +21 -0
  43. package/dist/shift.d.ts +31 -0
  44. package/dist/shift.js +71 -0
  45. package/dist/spi.d.ts +31 -0
  46. package/dist/spi.js +90 -0
  47. package/dist/timer.d.ts +35 -0
  48. package/dist/timer.js +50 -0
  49. package/dist/timing.d.ts +29 -0
  50. package/dist/timing.js +53 -0
  51. package/dist/types.d.ts +48 -0
  52. package/dist/types.js +67 -0
  53. package/dist/uart.d.ts +21 -0
  54. package/dist/uart.js +58 -0
  55. package/dist/utils.d.ts +10 -0
  56. package/dist/utils.js +14 -0
  57. package/dist/wdt.d.ts +7 -0
  58. package/dist/wdt.js +14 -0
  59. package/package.json +64 -0
  60. package/src/adc.ts +30 -0
  61. package/src/async.ts +63 -0
  62. package/src/board.ts +5 -0
  63. package/src/callback.ts +6 -0
  64. package/src/constants.ts +23 -0
  65. package/src/dac.ts +21 -0
  66. package/src/eeprom.ts +26 -0
  67. package/src/emit.ts +210 -0
  68. package/src/fs.ts +46 -0
  69. package/src/gpio.ts +298 -0
  70. package/src/i2c.ts +155 -0
  71. package/src/include.ts +5 -0
  72. package/src/index.ts +48 -0
  73. package/src/interrupts.ts +35 -0
  74. package/src/math.ts +32 -0
  75. package/src/power.ts +26 -0
  76. package/src/preferences.ts +58 -0
  77. package/src/pulse.ts +63 -0
  78. package/src/random.ts +31 -0
  79. package/src/register.ts +35 -0
  80. package/src/shift.ts +88 -0
  81. package/src/spi.ts +118 -0
  82. package/src/timer.ts +59 -0
  83. package/src/timing.ts +67 -0
  84. package/src/types.ts +144 -0
  85. package/src/uart.ts +77 -0
  86. package/src/utils.ts +17 -0
  87. package/src/wdt.ts +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 typecad0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # `@typecad/hal`
2
+
3
+ Hardware abstraction layer for [TypeCAD](https://github.com/justind000/typecode) —
4
+ GPIO, I2C, SPI, UART, timers, ADC/DAC, EEPROM, and more, written as regular
5
+ TypeScript.
6
+
7
+ `@typecad/hal` is what firmware code imports to talk to hardware. You write
8
+ normal TypeScript (`pin.high()`, `i2c.write(...)`, `Serial0.print(...)`); the
9
+ TypeCAD transpiler (`@typecad/cuttlefish`) resolves each HAL call against the
10
+ active MCU/board packages and emits the equivalent C++ at build time.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @typecad/hal @typecad/cuttlefish
16
+ ```
17
+
18
+ You'll also want an MCU package (e.g. `@typecad/mcu-esp32`) and a board package
19
+ (e.g. `@typecad/board-esp32-devkit`) to pin and bus definitions for your target.
20
+
21
+ ## Overview
22
+
23
+ The HAL is built on three compile-time directives that look like ordinary
24
+ TypeScript but are intercepted by the transpiler:
25
+
26
+ - **`emit(text)`** — appends a line of C++ to the output (with parameter/field substitution).
27
+ - **`include(header)`** — adds a deduplicated `#include` to the output.
28
+ - **`board(path)`** — looks up a board-specific constant (e.g. pin numbers) inside an `emit()` template.
29
+
30
+ This means there are no runtime fallbacks: if the HAL doesn't `emit()` it, it
31
+ doesn't appear in the firmware. See [`HAL-GUIDE.md`](./HAL-GUIDE.md) for how to
32
+ add new HAL features.
33
+
34
+ ## What's included
35
+
36
+ | Area | Exports |
37
+ | --- | --- |
38
+ | **Digital I/O** | `Pin`, `OutputPin`, `InputPin`, `PinMode`, `HIGH`, `LOW`, `INPUT`, `OUTPUT`, `INPUT_PULLUP` |
39
+ | **Pin groups** | `createPinGroup`, `IPinGroup`, `PinCapabilityFlags` |
40
+ | **Analog** | `ADC`, `ADCClass`, `DAC`, `DACClass`, `AnalogValue` |
41
+ | **I2C** | `I2CBus`, `II2CBus`, `I2CStatus`, `i2cName` |
42
+ | **SPI** | `SPIBus`, `ISPIBus`, `SPIStatus`, `SPISettings`, `spiName` |
43
+ | **UART / Serial** | `SerialPort`, `IUARTBus`, `UARTStatus`, `serialName` |
44
+ | **Timing** | `delay`, `millis`, `micros`, `delayMicroseconds`, `Timing`, `map`, `constrain` |
45
+ | **Pulse / Shift** | `pulseIn`, `shiftIn`, `shiftOut` |
46
+ | **Interrupts** | `attachInterrupt`, `detachInterrupt`, `noInterrupts`, `interrupts`, `InterruptMode` |
47
+ | **Timers** | `HardwareTimer`, `Timer0`, `Timer1`, `Timer2` |
48
+ | **Storage** | `EEPROM`, `Preferences` (NVFlash), `FS` |
49
+ | **Power / Watchdog** | `Power`, `WDT` (`WDTO_1S`, …) |
50
+ | **Math / Random** | `abs`, `min`, `max`, `Num`, `random`, `randomSeed` |
51
+ | **Async** | `Async` (cooperative scheduling) |
52
+ | **Directives** | `emit`, `include`, `board`, `callback` |
53
+
54
+ ## Example
55
+
56
+ ```ts
57
+ import { OutputPin, HIGH, LOW, delay } from '@typecad/hal';
58
+
59
+ const led = new OutputPin('LED_BUILTIN');
60
+
61
+ export function setup() {
62
+ led.mode();
63
+ }
64
+
65
+ export function loop() {
66
+ led.write(HIGH);
67
+ delay(500);
68
+ led.write(LOW);
69
+ delay(500);
70
+ }
71
+ ```
72
+
73
+ For I2C/SPI/UART, instantiate the bus class with the board's pinned instance
74
+ (see your `@typecad/board-*` package for available bus names).
75
+
76
+ ## Hardware tests
77
+
78
+ The [`tests/`](./tests/) directory contains a hardware test suite that
79
+ exercises every AVR-compilable HAL subsystem against real Arduino Uno hardware,
80
+ using [`@typecad/expect`](https://github.com/justind000/typecode/tree/main/packages/expect)
81
+ (`describe()` / `.it()` / `.expect()` / `done()`) over serial. Each file covers
82
+ one subsystem: GPIO, timing, math, random, pulse, shift, interrupts, UART,
83
+ I2C, SPI, ADC, EEPROM, WDT, Preferences, async, and constants.
84
+
85
+ ESP32-only subsystems (DAC, `FS`, `Power`, `HardwareTimer`) are intentionally
86
+ omitted — they require an ESP32 target.
87
+
88
+ Run on a connected Uno:
89
+
90
+ ```bash
91
+ npm exec --workspace @typecad/hal -- cuttlefish-test
92
+ ```
93
+
94
+ The suite is configured by [`cuttlefish.config.ts`](./cuttlefish.config.ts).
95
+ Like the [`@typecad/framework-arduino`](https://github.com/justind000/typecode/tree/main/packages/framework-arduino/tests)
96
+ tests, it imports through `@typecad/board` (the board package) and ambient globals
97
+ declared in `cuttlefish-env.d.ts`, never directly from `@typecad/board`, so the
98
+ transpiler resolves each call against the active MCU/board packages.
99
+
100
+ ### Skipped on AVR
101
+
102
+ One file is skipped on AVR by a `@typecad-skip-target` directive, for a
103
+ genuine hardware reason (not a transpiler limitation):
104
+
105
+ - **`08-uart`** — the Uno has a single hardware UART, which the test runner
106
+ itself uses as the `[TC:...]` protocol channel. Any `UART0` call disrupts
107
+ that channel. Runs on multi-UART targets (ESP32).
108
+
109
+ The async test (`15-async`) **runs on AVR**: on heap-less targets the
110
+ transpiler emits a fixed-capacity, allocation-free static timer/task runtime
111
+ (`async-runtime-static.ts`) in place of the full `Promise<T>` runtime used on
112
+ ESP32, so `Async.sleep`/`yield`/`sleepUntil`/`currentTask` link and run on the
113
+ ATmega328P.
114
+
115
+ ESP32-only subsystems (DAC, `FS`, `Power`, `HardwareTimer`) are omitted
116
+ entirely — they require an ESP32 target.
117
+
118
+ ## Ecosystem
119
+
120
+ - [`@typecad/cuttlefish`](https://github.com/justind000/typecode/tree/main/packages/cuttlefish) — the transpiler that resolves HAL calls to C++.
121
+ - [`@typecad/ui`](https://github.com/justind000/typecode/tree/main/packages/ui) — HTML/CSS-driven display graphics.
122
+ - `@typecad/mcu-*` — silicon pin/port/peripheral definitions.
123
+ - `@typecad/board-*` — board-level pin mappings and bus aliases.
124
+
125
+ ## License
126
+
127
+ MIT
package/dist/adc.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare class ADCClass {
2
+ static readonly __instance_name = "ADC";
3
+ static readonly __default_fields: {
4
+ _reference: string;
5
+ };
6
+ _reference: string;
7
+ constructor();
8
+ getAnalogResolution(): number;
9
+ setAnalogReference(ref: string): void;
10
+ getAnalogReference(): number;
11
+ read(pin: number): number;
12
+ }
13
+ export declare const ADC: ADCClass;
package/dist/adc.js ADDED
@@ -0,0 +1,22 @@
1
+ import { adcRead, adcSetReference, boardResolve } from './emit.js';
2
+ export class ADCClass {
3
+ constructor() {
4
+ this._reference = "DEFAULT";
5
+ }
6
+ getAnalogResolution() {
7
+ return boardResolve("peripherals.adc.0.resolution");
8
+ }
9
+ setAnalogReference(ref) {
10
+ this._reference = ref;
11
+ adcSetReference(ref);
12
+ }
13
+ getAnalogReference() {
14
+ return boardResolve("peripherals.adc.0.referenceVoltages." + this._reference);
15
+ }
16
+ read(pin) {
17
+ return adcRead(pin);
18
+ }
19
+ }
20
+ ADCClass.__instance_name = "ADC";
21
+ ADCClass.__default_fields = { _reference: "DEFAULT" };
22
+ export const ADC = new ADCClass();
@@ -0,0 +1,30 @@
1
+ export declare class AsyncClass {
2
+ static readonly __instance_name = "Async";
3
+ /**
4
+ * Non-blocking sleep for `ms` milliseconds.
5
+ * Returns a Promise<void> that resolves after the given delay.
6
+ * The underlying C++ implementation uses the platform's timer/microtask
7
+ * mechanism (e.g. millis-based polling on Arduino, std::this_thread::sleep_for
8
+ * on native, or a FreeRTOS vTaskDelay in the future).
9
+ */
10
+ sleep(ms: number): Promise<void>;
11
+ /**
12
+ * Cooperative yield — suspend the current task and allow other tasks
13
+ * (microtasks, timers) to run. Resumes on the next microtask pump cycle.
14
+ */
15
+ yield(): Promise<void>;
16
+ /**
17
+ * Await a polling condition.
18
+ * Repeatedly checks `condition()` every `pollIntervalMs` milliseconds
19
+ * until it returns true, then resolves.
20
+ * The underlying implementation uses the platform's timer mechanism.
21
+ */
22
+ sleepUntil(condition: () => boolean, pollIntervalMs?: number): Promise<void>;
23
+ /**
24
+ * Return a human-readable description of the currently executing async task.
25
+ * Useful for debugging / logging in cooperative multitasking environments.
26
+ */
27
+ currentTask(): string;
28
+ }
29
+ /** Singleton instance — consumers use `Async.sleep(...)` directly. */
30
+ export declare const Async: AsyncClass;
package/dist/async.js ADDED
@@ -0,0 +1,56 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Async — Top-level cooperative async / scheduling abstraction for TypeCAD
3
+ //
4
+ // Provides a platform-independent API for:
5
+ // - sleep(ms) — non-blocking delay via Promise + microtask
6
+ // - yield() — cooperative yield to other tasks
7
+ // - sleepUntil(condition) — await a condition (promise-based)
8
+ // - currentTask() — return a description of the currently executing task
9
+ //
10
+ // Framework packages (Arduino, Native, etc.) provide the C++ runtime behind
11
+ // the rawCpp() markers; the transpiler resolves these to the correct platform
12
+ // implementation at compile time.
13
+ // ---------------------------------------------------------------------------
14
+ import { rawCpp } from './emit.js';
15
+ export class AsyncClass {
16
+ /**
17
+ * Non-blocking sleep for `ms` milliseconds.
18
+ * Returns a Promise<void> that resolves after the given delay.
19
+ * The underlying C++ implementation uses the platform's timer/microtask
20
+ * mechanism (e.g. millis-based polling on Arduino, std::this_thread::sleep_for
21
+ * on native, or a FreeRTOS vTaskDelay in the future).
22
+ */
23
+ sleep(ms) {
24
+ rawCpp(`__cuttlefish_async_sleep(${ms});`);
25
+ return Promise.resolve();
26
+ }
27
+ /**
28
+ * Cooperative yield — suspend the current task and allow other tasks
29
+ * (microtasks, timers) to run. Resumes on the next microtask pump cycle.
30
+ */
31
+ yield() {
32
+ rawCpp(`__cuttlefish_async_yield();`);
33
+ return Promise.resolve();
34
+ }
35
+ /**
36
+ * Await a polling condition.
37
+ * Repeatedly checks `condition()` every `pollIntervalMs` milliseconds
38
+ * until it returns true, then resolves.
39
+ * The underlying implementation uses the platform's timer mechanism.
40
+ */
41
+ sleepUntil(condition, pollIntervalMs = 10) {
42
+ rawCpp(`__cuttlefish_async_sleep_until(${pollIntervalMs});`);
43
+ return Promise.resolve();
44
+ }
45
+ /**
46
+ * Return a human-readable description of the currently executing async task.
47
+ * Useful for debugging / logging in cooperative multitasking environments.
48
+ */
49
+ currentTask() {
50
+ rawCpp(`return __cuttlefish_async_current_task();`);
51
+ return "";
52
+ }
53
+ }
54
+ AsyncClass.__instance_name = "Async";
55
+ /** Singleton instance — consumers use `Async.sleep(...)` directly. */
56
+ export const Async = new AsyncClass();
@@ -0,0 +1,3 @@
1
+ /** Compile-time function: resolves a board definition path to a literal value.
2
+ * At runtime (tests, type-checking) this is a no-op that returns undefined. */
3
+ export declare function board(_path: string): any;
package/dist/board.js ADDED
@@ -0,0 +1,5 @@
1
+ /** Compile-time function: resolves a board definition path to a literal value.
2
+ * At runtime (tests, type-checking) this is a no-op that returns undefined. */
3
+ export function board(_path) {
4
+ return undefined;
5
+ }
@@ -0,0 +1,4 @@
1
+ /** Compile-time function: registers a function argument as a standalone C++ callback.
2
+ * Returns the generated function name for use in rawCpp() templates.
3
+ * At runtime (tests, type-checking) this is a no-op. */
4
+ export declare function callback<T extends (...args: any[]) => any>(_fn: T): string;
@@ -0,0 +1,6 @@
1
+ /** Compile-time function: registers a function argument as a standalone C++ callback.
2
+ * Returns the generated function name for use in rawCpp() templates.
3
+ * At runtime (tests, type-checking) this is a no-op. */
4
+ export function callback(_fn) {
5
+ return "";
6
+ }
@@ -0,0 +1,21 @@
1
+ export declare const INPUT: number;
2
+ export declare const OUTPUT: number;
3
+ export declare const INPUT_PULLUP: number;
4
+ export declare const INPUT_PULLDOWN: number;
5
+ export declare const OUTPUT_OPEN_DRAIN: number;
6
+ export declare const ANALOG: number;
7
+ export declare const HIGH: number;
8
+ export declare const LOW: number;
9
+ export declare const LED_BUILTIN: number;
10
+ export declare const LSBFIRST: number;
11
+ export declare const MSBFIRST: number;
12
+ export declare const WDTO_15MS: number;
13
+ export declare const WDTO_30MS: number;
14
+ export declare const WDTO_60MS: number;
15
+ export declare const WDTO_120MS: number;
16
+ export declare const WDTO_250MS: number;
17
+ export declare const WDTO_500MS: number;
18
+ export declare const WDTO_1S: number;
19
+ export declare const WDTO_2S: number;
20
+ export declare const WDTO_4S: number;
21
+ export declare const WDTO_8S: number;
@@ -0,0 +1,23 @@
1
+ // These constants are resolved from the board definition at compile time by the
2
+ // transpiler. At runtime (tests, type-checking) they default to 0.
3
+ export const INPUT = 0;
4
+ export const OUTPUT = 0;
5
+ export const INPUT_PULLUP = 0;
6
+ export const INPUT_PULLDOWN = 0;
7
+ export const OUTPUT_OPEN_DRAIN = 0;
8
+ export const ANALOG = 0;
9
+ export const HIGH = 0;
10
+ export const LOW = 0;
11
+ export const LED_BUILTIN = 0;
12
+ export const LSBFIRST = 0;
13
+ export const MSBFIRST = 0;
14
+ export const WDTO_15MS = 0;
15
+ export const WDTO_30MS = 0;
16
+ export const WDTO_60MS = 0;
17
+ export const WDTO_120MS = 0;
18
+ export const WDTO_250MS = 0;
19
+ export const WDTO_500MS = 0;
20
+ export const WDTO_1S = 0;
21
+ export const WDTO_2S = 0;
22
+ export const WDTO_4S = 0;
23
+ export const WDTO_8S = 0;
package/dist/dac.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * DACClass provides access to true digital-to-analog converters.
3
+ *
4
+ * Note: This is for true analog output (DAC), distinct from PWM-based
5
+ * analog simulation provided by Pin.pwm().
6
+ */
7
+ export declare class DACClass {
8
+ static readonly __instance_name = "DAC";
9
+ write(pin: number, value: number): void;
10
+ getResolution(): number;
11
+ }
12
+ export declare const DAC: DACClass;
package/dist/dac.js ADDED
@@ -0,0 +1,17 @@
1
+ import { dacWrite, boardResolve } from './emit.js';
2
+ /**
3
+ * DACClass provides access to true digital-to-analog converters.
4
+ *
5
+ * Note: This is for true analog output (DAC), distinct from PWM-based
6
+ * analog simulation provided by Pin.pwm().
7
+ */
8
+ export class DACClass {
9
+ write(pin, value) {
10
+ dacWrite(pin, value);
11
+ }
12
+ getResolution() {
13
+ return boardResolve("peripherals.dac.0.resolution");
14
+ }
15
+ }
16
+ DACClass.__instance_name = "DAC";
17
+ export const DAC = new DACClass();
@@ -0,0 +1,16 @@
1
+ export declare class EEPROMClass {
2
+ static readonly __instance_name = "EEPROM";
3
+ static readonly __includes: string[];
4
+ static readonly __default_fields: {
5
+ _name: string;
6
+ };
7
+ private _name;
8
+ constructor(name: string);
9
+ read(address: number): number;
10
+ write(address: number, value: number): void;
11
+ update(address: number, value: number): void;
12
+ length(): number;
13
+ get<T>(address: number, ref: T): T;
14
+ put<T>(address: number, value: T): void;
15
+ }
16
+ export declare const EEPROM: EEPROMClass;
package/dist/eeprom.js ADDED
@@ -0,0 +1,21 @@
1
+ import { rawCpp } from './emit.js';
2
+ import { include } from './include.js';
3
+ export class EEPROMClass {
4
+ constructor(name) {
5
+ include("<EEPROM.h>");
6
+ this._name = name;
7
+ }
8
+ read(address) { return 0; }
9
+ write(address, value) { rawCpp(`${this._name}.write(${address}, ${value});`); }
10
+ update(address, value) { rawCpp(`${this._name}.update(${address}, ${value});`); }
11
+ length() { return 0; }
12
+ get(address, ref) {
13
+ rawCpp(`${this._name}.get(${address}, ${ref});`);
14
+ return ref;
15
+ }
16
+ put(address, value) { rawCpp(`${this._name}.put(${address}, ${value});`); }
17
+ }
18
+ EEPROMClass.__instance_name = "EEPROM";
19
+ EEPROMClass.__includes = ["<EEPROM.h>"];
20
+ EEPROMClass.__default_fields = { _name: "EEPROM" };
21
+ export const EEPROM = new EEPROMClass("EEPROM");
package/dist/emit.d.ts ADDED
@@ -0,0 +1,121 @@
1
+ /** Set a digital pin HIGH or LOW. */
2
+ export declare function gpioWrite(pin: number | string, value: number | boolean): void;
3
+ /** Read a digital pin. Returns HIGH (1) or LOW (0). */
4
+ export declare function gpioRead(pin: number | string): number;
5
+ /** Toggle a digital pin. */
6
+ export declare function gpioToggle(pin: number | string): void;
7
+ /** Set pin mode: "output" | "input" | "input_pullup" | "input_pulldown". */
8
+ export declare function gpioSetMode(pin: number | string, mode: string): void;
9
+ /** Write PWM duty cycle to a pin. */
10
+ export declare function pwmWrite(pin: number | string, duty: number): void;
11
+ /** Read analog value from a pin. */
12
+ export declare function adcRead(pin: number | string): number;
13
+ /** Read analog voltage from a pin (ADC value converted to voltage). */
14
+ export declare function adcReadVoltage(pin: number | string): number;
15
+ /** Set the analog reference. */
16
+ export declare function adcSetReference(ref: string | number): void;
17
+ /** Attach an interrupt handler to a pin. */
18
+ export declare function interruptAttach(pin: number | string, handler: string, mode: string): void;
19
+ /** Detach an interrupt from a pin. */
20
+ export declare function interruptDetach(pin: number | string): void;
21
+ /** Play a tone on a pin at the given frequency, optionally for a duration. */
22
+ export declare function tonePlay(pin: number | string, frequency: number, duration?: number): void;
23
+ /** Stop tone playback on a pin. */
24
+ export declare function toneStop(pin: number | string): void;
25
+ /** Delay for the given number of milliseconds. */
26
+ export declare function delayMs(ms: number): void;
27
+ /** Delay for the given number of microseconds. */
28
+ export declare function delayMicro(us: number): void;
29
+ /** Get milliseconds since boot. */
30
+ export declare function getMillis(): number;
31
+ /** Get microseconds since boot. */
32
+ export declare function getMicros(): number;
33
+ /** Get free heap bytes. Architecture-aware: the strategy maps this to the right
34
+ * symbol per target (ESP.getFreeHeap() on ESP32, __heap_start trick on AVR). */
35
+ export declare function getFreeHeap(): number;
36
+ /** Initialize I2C bus (master mode if no address, slave mode with address). */
37
+ export declare function i2cBegin(bus: string, address?: number): void;
38
+ /** Disable I2C bus. */
39
+ export declare function i2cEnd(bus: string): void;
40
+ /** Set I2C bus clock speed. */
41
+ export declare function i2cSetClock(bus: string, hz: number): void;
42
+ /** Begin I2C transmission to a slave address. */
43
+ export declare function i2cBeginTx(bus: string, address: number): void;
44
+ /** Write data to I2C bus. */
45
+ export declare function i2cWrite(bus: string, data: string | number | number[] | Uint8Array): void;
46
+ /** Write a byte buffer to I2C bus (expands array literals to per-byte writes). */
47
+ export declare function i2cWriteBuffer(bus: string, data: number[] | Uint8Array): void;
48
+ /** End I2C transmission. Returns status. */
49
+ export declare function i2cEndTx(bus: string, stop: boolean): number;
50
+ /** Request bytes from I2C slave. */
51
+ export declare function i2cRequestFrom(bus: string, address: number, quantity: number, stop?: boolean): number;
52
+ /** Check if bytes are available from I2C. */
53
+ export declare function i2cAvailable(bus: string): number;
54
+ /** Read a byte from I2C. */
55
+ export declare function i2cRead(bus: string): number;
56
+ /** Initialize SPI bus. */
57
+ export declare function spiBegin(bus: string): void;
58
+ /** Disable SPI bus. */
59
+ export declare function spiEnd(bus: string): void;
60
+ /** Transfer data on SPI bus. */
61
+ export declare function spiTransfer(bus: string, data: string | number | Uint8Array): number;
62
+ /** Begin SPI transaction with settings. */
63
+ export declare function spiBeginTx(bus: string, settings: string | any): void;
64
+ /** End SPI transaction. */
65
+ export declare function spiEndTx(bus: string): void;
66
+ /** Set SPI chip-select pin LOW. */
67
+ export declare function spiCsLow(pin: number | string): void;
68
+ /** Set SPI chip-select pin HIGH. */
69
+ export declare function spiCsHigh(pin: number | string): void;
70
+ /** Set SPI data mode. */
71
+ export declare function spiSetMode(bus: string, mode: number): void;
72
+ /** Set SPI bit order. */
73
+ export declare function spiSetBitOrder(bus: string, order: string): void;
74
+ /** Initialize serial port with baud rate. */
75
+ export declare function uartBegin(port: string, baud: number): void;
76
+ /** Disable serial port. */
77
+ export declare function uartEnd(port: string): void;
78
+ /** Print value to serial. */
79
+ export declare function uartPrint(port: string, value: any): void;
80
+ /** Print value with newline to serial. */
81
+ export declare function uartPrintln(port: string, value: any): void;
82
+ /** printf-style formatted print to serial. */
83
+ export declare function uartPrintf(port: string, format: any, args: any[]): void;
84
+ /** Write raw data to serial. */
85
+ export declare function uartWrite(port: string, data: any): void;
86
+ /** Read a byte from serial. */
87
+ export declare function uartRead(port: string): number;
88
+ /** Peek at next byte from serial without consuming. */
89
+ export declare function uartPeek(port: string): number;
90
+ /** Check if bytes are available from serial. */
91
+ export declare function uartAvailable(port: string): number;
92
+ /** Flush serial output. */
93
+ export declare function uartFlush(port: string): void;
94
+ /** Measure pulse duration on a pin. */
95
+ export declare function pulseIn_(pin: number | string, value: number, timeout?: number): number;
96
+ /** Measure long pulse using high-precision timer. */
97
+ export declare function pulseInLong_(pin: number | string, value: number): number;
98
+ /** Shift a byte out to a pin. */
99
+ export declare function shiftOut_(dataPin: number | string, clockPin: number | string, bitOrder: number, value: number): void;
100
+ /** Shift a byte in from a pin. */
101
+ export declare function shiftIn_(dataPin: number | string, clockPin: number | string, bitOrder: number): number;
102
+ /** Write a value to a DAC pin. */
103
+ export declare function dacWrite(pin: number | string, value: number): void;
104
+ /** Enable the watchdog timer with the given timeout (string preset or number). */
105
+ export declare function wdtEnable(timeout: string | number): void;
106
+ /** Reset (kick) the watchdog timer. */
107
+ export declare function wdtReset(): void;
108
+ /** Disable the watchdog timer. */
109
+ export declare function wdtDisable(): void;
110
+ /** Resolve a board definition path to a compile-time constant. */
111
+ export declare function boardResolve(path: string): any;
112
+ /** Enter deep sleep for the given duration (ms). Architecture-aware: the
113
+ * strategy emits the right call per target (esp_deep_sleep on ESP32, a
114
+ * not-supported comment elsewhere). */
115
+ export declare function powerDeepSleep(ms: number): void;
116
+ /** Enter light sleep. Architecture-aware. */
117
+ export declare function powerLightSleep(): void;
118
+ /** Set the CPU frequency (MHz). */
119
+ export declare function powerSetCpuFrequency(mhz: number): void;
120
+ /** Emit raw C++ code (escape hatch for unsupported operations). */
121
+ export declare function rawCpp(code: string): void;