@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
@@ -0,0 +1,35 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Watchdog — the thin Zephyr-shaped watchdog
3
+ //
4
+ // The timeout is a CONSTRUCTION fact in milliseconds (Zephyr's own unit for
5
+ // wdt_timeout_cfg.window.max). enable() arms (wdt_install_timeout +
6
+ // wdt_setup, reset-CPU-core flag); feed() keeps it alive (wdt_feed) —
7
+ // Zephyr's verbs, no WDTO_* presets, no string parsing.
8
+ // ----------------------------------------------------------------------------
9
+
10
+ import { wdtSetup, wdtFeed, wdtDisable } from './emit.js';
11
+
12
+ export class Watchdog {
13
+ private readonly _timeoutMs: number;
14
+
15
+ /** Construct with the timeout in milliseconds. */
16
+ constructor(timeoutMs: number) {
17
+ this._timeoutMs = timeoutMs;
18
+ }
19
+
20
+ /** Arm the watchdog (wdt_install_timeout + wdt_setup). Full CPU reset on
21
+ * expiry. Call feed() at least once per timeout window afterwards. */
22
+ enable(): void {
23
+ wdtSetup(this._timeoutMs);
24
+ }
25
+
26
+ /** Feed the watchdog (wdt_feed). */
27
+ feed(): void {
28
+ wdtFeed();
29
+ }
30
+
31
+ /** Disable (wdt_disable). Not all drivers support runtime disable. */
32
+ disable(): void {
33
+ wdtDisable();
34
+ }
35
+ }
package/src/wifi.ts CHANGED
@@ -1,221 +1,189 @@
1
+ // ---------------------------------------------------------------------------
2
+ // WiFi — the thin Zephyr-shaped station/AP wrappers
3
+ //
4
+ // The link policy is CONSTRUCTION facts: credentials, security, band/channel,
5
+ // join timeout, power-save, and (optionally) static IPv4 all ride the join op
6
+ // (the sensor discipline — every op carries its construction facts). Methods
7
+ // lower 1:1 onto Zephyr's net_mgmt/wifi_mgmt surface:
8
+ //
9
+ // join() → wifi_connect_req_params from the facts + a bounded wait on
10
+ // the L4 connected flag (conn_mgr monitor raises it post-DHCP,
11
+ // or immediately when static IPv4 facts are configured).
12
+ // Returns boolean — no exceptions. Awaitable in async contexts
13
+ // (start + poll split, like Time.sleep).
14
+ // leave() → NET_REQUEST_WIFI_DISCONNECT
15
+ // linked() / rssi() / ip() / mac() → iface-status + net_if queries
16
+ // onUp() / onDrop() → the L4 / IPv4-addr net_mgmt event callbacks
17
+ // scan() → one blocking scan, results read through the Scan handle
18
+ // (fixed pool, no heap)
19
+ //
20
+ // WiFiAP carries the SoftAP facts (ssid/psk/channel) the same way:
21
+ // start()/stop() map to NET_REQUEST_WIFI_AP_ENABLE/DISABLE.
22
+ // ----------------------------------------------------------------------------
23
+
1
24
  import {
2
- wifiConnect,
3
- wifiConnectStart,
4
- wifiDisconnect,
5
- wifiStatus,
6
- wifiIsConnected,
7
- wifiLocalIp,
8
- wifiRssi,
9
- wifiMac,
10
- wifiSetHostname,
11
- wifiSetStaticIp,
12
- wifiSetAutoReconnect,
13
- wifiSetPowerSave,
14
- wifiSetTxPower,
15
- wifiOnEvent,
16
- wifiApStart,
17
- wifiApStop,
18
- wifiApClientCount,
19
- wifiApIp,
20
- wifiApSetChannel,
21
- wifiApSetHidden,
22
- wifiApSetMaxClients,
23
- wifiScan,
24
- wifiScanStart,
25
- wifiScanCount,
26
- wifiScanSsid,
27
- wifiScanRssi,
28
- wifiScanEncryption,
29
- wifiScanChannel,
30
- wifiSaveCredentials,
31
- wifiConnectSaved,
32
- wifiClearCredentials,
33
- wifiWaitConnected,
34
- wifiWaitDisconnected,
25
+ wifiJoin, wifiConnectStart, wifiDisconnect, wifiIsConnected, wifiLocalIp,
26
+ wifiRssi, wifiMac, wifiOnEvent, wifiScan, wifiScanCount, wifiScanSsid,
27
+ wifiScanRssi, wifiScanEncryption, wifiScanChannel, wifiApStart, wifiApStop,
35
28
  } from './emit.js';
36
29
  import { callback } from './callback.js';
37
30
 
38
- /** Normalized WiFi link status (mapped from esp_wifi events by the runtime shim). */
39
- export enum WiFiStatus {
40
- Idle = 0,
41
- Connecting = 1,
42
- Connected = 2,
43
- ConnectFailed = 3,
44
- Disconnected = 4,
45
- }
46
-
47
- export enum WiFiEncryption {
48
- Open = 0,
49
- WEP = 1,
50
- WPA = 2,
51
- WPA2 = 3,
52
- WPA3 = 4,
53
- Enterprise = 5,
54
- }
55
-
56
- /**
57
- * WiFi radio / link control, lowered to native ESP-IDF (`esp_wifi` /
58
- * `esp_netif` / `esp_event` / `nvs_flash`) by framework-esp32.
59
- *
60
- * No `include()` calls here — ESP-IDF headers are framework-owned and added
61
- * via forcedIncludes when the program uses wifi.* ops (the Preferences
62
- * lesson: HAL files must not carry platform headers). Frameworks without a
63
- * wifi lowering reject these ops with a diagnostic.
64
- */
65
- export class WiFiClass {
66
- static readonly __instance_name = "WiFi";
67
-
68
- /** Blocking at top level; cooperatively awaitable inside async functions. */
69
- connect(ssid: string, password?: string, timeoutMs: number = 15000): Promise<boolean> {
70
- wifiConnect(ssid, password, timeoutMs);
71
- return Promise.resolve(false);
72
- }
73
-
74
- /** Fire-and-forget STA begin; poll status() / untilConnected(). */
75
- connectAsync(ssid: string, password?: string): void {
76
- wifiConnectStart(ssid, password);
77
- }
78
-
79
- untilConnected(timeoutMs: number = 15000): Promise<boolean> {
80
- wifiWaitConnected(timeoutMs);
81
- return Promise.resolve(false);
82
- }
83
-
84
- untilDisconnected(): Promise<void> {
85
- wifiWaitDisconnected();
86
- return Promise.resolve();
87
- }
88
-
89
- disconnect(): void {
31
+ export class WiFi {
32
+ /** Security tokens — lowered to Zephyr's wifi_security_type enum. */
33
+ static readonly OPEN = 0;
34
+ static readonly WPA2 = 1;
35
+ static readonly WPA3 = 2;
36
+ static readonly WPA2_WPA3 = 3;
37
+
38
+ /** Band tokens. */
39
+ static readonly BAND_2_4 = 0;
40
+ static readonly BAND_5 = 1;
41
+
42
+ /** Power-save token — pass PS_OFF to disable the radio's modem sleep. */
43
+ static readonly PS_OFF = 0;
44
+
45
+ private readonly _ssid: string;
46
+ private readonly _psk: string | undefined;
47
+ private readonly _security: number;
48
+ private readonly _channel: number;
49
+ private readonly _band: number;
50
+ private readonly _timeoutMs: number;
51
+ private readonly _ps: number;
52
+ private readonly _ipAddr: string | undefined;
53
+ private readonly _gateway: string | undefined;
54
+ private readonly _netmask: string | undefined;
55
+
56
+ /** Construct a station link policy. `psk` omitted open network;
57
+ * `security` defaults WPA2 when a psk is present, OPEN otherwise;
58
+ * `channel` 0/omitted = any. `ipv4` opts out of DHCP with static facts. */
59
+ constructor(ssid: string, opts: {
60
+ psk?: string;
61
+ security?: number;
62
+ channel?: number;
63
+ band?: number;
64
+ timeoutMs?: number;
65
+ powerSave?: number;
66
+ ipv4?: { addr: string; gateway: string; netmask: string };
67
+ } = {}) {
68
+ this._ssid = ssid;
69
+ this._psk = opts.psk;
70
+ this._security = opts.security ?? (opts.psk !== undefined ? WiFi.WPA2 : WiFi.OPEN);
71
+ this._channel = opts.channel ?? 0;
72
+ this._band = opts.band ?? WiFi.BAND_2_4;
73
+ this._timeoutMs = opts.timeoutMs ?? 15000;
74
+ this._ps = opts.powerSave ?? 0;
75
+ this._ipAddr = opts.ipv4?.addr;
76
+ this._gateway = opts.ipv4?.gateway;
77
+ this._netmask = opts.ipv4?.netmask;
78
+ }
79
+
80
+ /** Join the network. Blocks (bounded by timeoutMs, pumping a mounted UI's
81
+ * tick between polls); returns true once IP connectivity is up, false on
82
+ * timeout or missing radio. Idempotent-ish: re-joining re-associates. */
83
+ join(): boolean {
84
+ return wifiJoin(this._ssid, this._psk, this._security, this._channel,
85
+ this._band, this._timeoutMs, this._ps, this._ipAddr, this._gateway,
86
+ this._netmask);
87
+ }
88
+
89
+ /** Fire-and-forget join — poll linked() or await in an async function. */
90
+ joinStart(): void {
91
+ wifiConnectStart(this._ssid, this._psk);
92
+ }
93
+
94
+ /** Leave the network (NET_REQUEST_WIFI_DISCONNECT). */
95
+ leave(): void {
90
96
  wifiDisconnect();
91
97
  }
92
98
 
93
- isConnected(): boolean {
99
+ /** True once IP connectivity is up (the L4 flag — post-DHCP, or after
100
+ * static IPv4 facts are applied). */
101
+ linked(): boolean {
94
102
  return wifiIsConnected();
95
103
  }
96
104
 
97
- status(): WiFiStatus {
98
- return wifiStatus() as WiFiStatus;
99
- }
100
-
101
- localIP(): string {
102
- return wifiLocalIp();
103
- }
104
-
105
+ /** Signal strength in dBm (iface-status query). */
105
106
  rssi(): number {
106
107
  return wifiRssi();
107
108
  }
108
109
 
109
- macAddress(): string {
110
- return wifiMac();
111
- }
112
-
113
- hostname(name: string): this {
114
- wifiSetHostname(name);
115
- return this;
116
- }
117
-
118
- staticIP(ip: string, gateway: string, subnet: string, dns?: string): this {
119
- wifiSetStaticIp(ip, gateway, subnet, dns);
120
- return this;
110
+ /** The interface's global IPv4 address as text ("0.0.0.0" when down). */
111
+ ip(): string {
112
+ return wifiLocalIp();
121
113
  }
122
114
 
123
- autoReconnect(enabled: boolean): this {
124
- wifiSetAutoReconnect(enabled);
125
- return this;
115
+ /** The radio's BSSID packed into a number (iface-status query). */
116
+ mac(): number {
117
+ return wifiMac();
126
118
  }
127
119
 
128
- powerSave(mode: "default" | "none"): this {
129
- wifiSetPowerSave(mode);
130
- return this;
120
+ /** Fires once DHCP (or static config) assigns an address. */
121
+ onUp(handler: () => void): void {
122
+ wifiOnEvent('connect', callback(handler));
131
123
  }
132
124
 
133
- /** Cap TX power in dBm (roughly 2–20). Safe to call before connect()
134
- * the value is applied after the radio starts. */
135
- txPower(dbm: number): this {
136
- wifiSetTxPower(dbm);
137
- return this;
125
+ /** Fires on link loss (deferred off the net_mgmt event chain so the
126
+ * callback may safely call join()). */
127
+ onDrop(handler: () => void): void {
128
+ wifiOnEvent('disconnect', callback(handler));
138
129
  }
139
130
 
140
- saveCredentials(ssid: string, password: string): void {
141
- wifiSaveCredentials(ssid, password);
131
+ /** One blocking scan; read the results through the returned handle.
132
+ * Fixed pool of 16 — no heap. */
133
+ scan(): Scan {
134
+ wifiScan();
135
+ return new Scan();
142
136
  }
137
+ }
143
138
 
144
- connectSaved(timeoutMs: number = 15000): boolean {
145
- return wifiConnectSaved(timeoutMs);
139
+ /** Read-only view over the last scan's fixed result pool. */
140
+ export class Scan {
141
+ /** Number of networks found. */
142
+ count(): number {
143
+ return wifiScanCount();
146
144
  }
147
145
 
148
- clearCredentials(): void {
149
- wifiClearCredentials();
146
+ /** Network name ("" when out of range). */
147
+ ssid(i: number): string {
148
+ return wifiScanSsid(i);
150
149
  }
151
150
 
152
- onConnect(handler: () => void): void {
153
- wifiOnEvent("connect", callback(handler));
151
+ /** Signal strength in dBm. */
152
+ rssi(i: number): number {
153
+ return wifiScanRssi(i);
154
154
  }
155
155
 
156
- onDisconnect(handler: () => void): void {
157
- wifiOnEvent("disconnect", callback(handler));
156
+ /** Security family as text: "open" / "wpa" / "wpa2" / "wpa3". */
157
+ security(i: number): string {
158
+ return wifiScanEncryption(i);
158
159
  }
159
160
 
160
- startAP(ssid: string, password?: string): boolean {
161
- return wifiApStart(ssid, password);
161
+ /** Channel number (0 when unknown). */
162
+ channel(i: number): number {
163
+ return wifiScanChannel(i);
162
164
  }
165
+ }
163
166
 
164
- apChannel(ch: number): this {
165
- wifiApSetChannel(ch);
166
- return this;
167
- }
167
+ /** SoftAP the AP facts at construction, then start/stop. */
168
+ export class WiFiAP {
169
+ private readonly _ssid: string;
170
+ private readonly _psk: string | undefined;
171
+ private readonly _channel: number;
168
172
 
169
- apHidden(hidden: boolean): this {
170
- wifiApSetHidden(hidden);
171
- return this;
173
+ /** Construct an AP. `psk` omitted → open network. `channel` 0 = auto. */
174
+ constructor(ssid: string, opts: { psk?: string; channel?: number } = {}) {
175
+ this._ssid = ssid;
176
+ this._psk = opts.psk;
177
+ this._channel = opts.channel ?? 0;
172
178
  }
173
179
 
174
- apMaxClients(n: number): this {
175
- wifiApSetMaxClients(n);
176
- return this;
180
+ /** Bring the interface up as an AP (NET_REQUEST_WIFI_AP_ENABLE). */
181
+ start(): void {
182
+ wifiApStart(this._ssid, this._psk, this._channel);
177
183
  }
178
184
 
179
- stopAP(): void {
185
+ /** Tear the AP down (NET_REQUEST_WIFI_AP_DISABLE). */
186
+ stop(): void {
180
187
  wifiApStop();
181
188
  }
182
-
183
- apClientCount(): number {
184
- return wifiApClientCount();
185
- }
186
-
187
- apIP(): string {
188
- return wifiApIp();
189
- }
190
-
191
- scan(): number {
192
- return wifiScan();
193
- }
194
-
195
- scanAsync(): Promise<void> {
196
- wifiScanStart();
197
- return Promise.resolve();
198
- }
199
-
200
- scanCount(): number {
201
- return wifiScanCount();
202
- }
203
-
204
- scanSSID(i: number): string {
205
- return wifiScanSsid(i);
206
- }
207
-
208
- scanRSSI(i: number): number {
209
- return wifiScanRssi(i);
210
- }
211
-
212
- scanEncryption(i: number): WiFiEncryption {
213
- return wifiScanEncryption(i) as WiFiEncryption;
214
- }
215
-
216
- scanChannel(i: number): number {
217
- return wifiScanChannel(i);
218
- }
219
189
  }
220
-
221
- export const WiFi = new WiFiClass();
@@ -0,0 +1,77 @@
1
+ // ---------------------------------------------------------------------------
2
+ // zephyr-tokens.generated.ts — the thin-HAL token name sets
3
+ //
4
+ // GENERATED FILE — do not edit by hand. Regenerate against the pinned
5
+ // workspace with:
6
+ //
7
+ // node scripts/gen-zephyr-hal-tokens.mjs <zephyr-base>
8
+ //
9
+ // Derived from Zephyr 4.4.2: enum adc_gain / enum adc_reference
10
+ // (include/zephyr/drivers/adc.h), the GPIO config flags (drivers/gpio.h +
11
+ // dt-bindings/gpio/gpio.h), and the GPIO_INT_* interrupt configurations
12
+ // (drivers/gpio.h). 21 gains, 7 references,
13
+ // 9 flags, 6 interrupt configs.
14
+ //
15
+ // The class statics stay hand-declared for editor typing; the token-sync
16
+ // test asserts they match these sets. The lowerings build their
17
+ // token→macro maps from these lists — names only; values never cross to C++.
18
+ // ---------------------------------------------------------------------------
19
+
20
+ /** enum adc_gain suffixes — ADC.GAIN_<name> ↔ ADC_GAIN_<name>. */
21
+ export const ZEPHYR_ADC_GAINS: readonly string[] = [
22
+ '1_6',
23
+ '1_5',
24
+ '1_4',
25
+ '2_7',
26
+ '1_3',
27
+ '2_5',
28
+ '1_2',
29
+ '2_3',
30
+ '4_5',
31
+ '1',
32
+ '2',
33
+ '3',
34
+ '4',
35
+ '6',
36
+ '8',
37
+ '12',
38
+ '16',
39
+ '24',
40
+ '32',
41
+ '64',
42
+ '128',
43
+ ];
44
+
45
+ /** enum adc_reference suffixes — ADC.REF_<name> ↔ ADC_REF_<name>. */
46
+ export const ZEPHYR_ADC_REFERENCES: readonly string[] = [
47
+ 'VDD_1',
48
+ 'VDD_1_2',
49
+ 'VDD_1_3',
50
+ 'VDD_1_4',
51
+ 'INTERNAL',
52
+ 'EXTERNAL0',
53
+ 'EXTERNAL1',
54
+ ];
55
+
56
+ /** GPIO config flag names — GPIO.<name> ↔ GPIO_<name>. */
57
+ export const ZEPHYR_GPIO_FLAGS: readonly string[] = [
58
+ 'INPUT',
59
+ 'OUTPUT',
60
+ 'OUTPUT_INIT_LOW',
61
+ 'OUTPUT_INIT_HIGH',
62
+ 'PULL_UP',
63
+ 'PULL_DOWN',
64
+ 'OPEN_DRAIN',
65
+ 'OPEN_SOURCE',
66
+ 'DISCONNECTED',
67
+ ];
68
+
69
+ /** GPIO interrupt configuration names — GPIO.INT_<name> ↔ GPIO_INT_<name>. */
70
+ export const ZEPHYR_GPIO_INTS: readonly string[] = [
71
+ 'INT_DISABLE',
72
+ 'INT_EDGE_RISING',
73
+ 'INT_EDGE_FALLING',
74
+ 'INT_EDGE_BOTH',
75
+ 'INT_LEVEL_LOW',
76
+ 'INT_LEVEL_HIGH',
77
+ ];
package/src/adc.ts DELETED
@@ -1,30 +0,0 @@
1
- import { adcRead, adcSetReference, boardResolve } from './emit.js';
2
-
3
- export class ADCClass {
4
- static readonly __instance_name = "ADC";
5
- static readonly __default_fields = { _reference: "DEFAULT" };
6
- _reference: string;
7
-
8
- constructor() {
9
- this._reference = "DEFAULT";
10
- }
11
-
12
- getAnalogResolution(): number {
13
- return boardResolve("peripherals.adc.0.resolution");
14
- }
15
-
16
- setAnalogReference(ref: string): void {
17
- this._reference = ref;
18
- adcSetReference(ref);
19
- }
20
-
21
- getAnalogReference(): number {
22
- return boardResolve("peripherals.adc.0.referenceVoltages." + this._reference);
23
- }
24
-
25
- read(pin: number): number {
26
- return adcRead(pin);
27
- }
28
- }
29
-
30
- export const ADC = new ADCClass();
package/src/capacitive.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * CapacitiveClass — ESP32 on-chip capacitive touch pins.
3
- *
4
- * ESP32-family chips have dedicated capacitive-sensing GPIOs (10 on classic
5
- * ESP32, up to 14 on S3) that read touch/proximity without external
6
- * components — distinct from the I2C/SPI touch *display* controllers (FT6336U,
7
- * GT911, etc.). Lowered to capacitive.* HAL ops: ESP-IDF's touch_sensor driver.
8
- *
9
- * Pin numbers are the touch-pad-capable GPIOs (GPIO4, GPIO0, GPIO2, ... on
10
- * classic ESP32); the framework maps them to touch_channel indices.
11
- */
12
- export class CapacitiveClass {
13
- static readonly __instance_name = "Capacitive";
14
-
15
- /** Read the raw capacitive value of a touch pin. Higher = more capacitance
16
- * (touched). The raw scale is chip-dependent; use a threshold calibrated
17
- * against the untouched reading. */
18
- read(pin: number): number {
19
- return capacitiveRead(pin);
20
- }
21
-
22
- /** True when the pin's reading exceeds `threshold` (a convenience over read()). */
23
- isTouched(pin: number, threshold: number): boolean {
24
- return capacitiveRead(pin) > threshold;
25
- }
26
- }
27
-
28
- export const Capacitive = new CapacitiveClass();
29
-
30
- // ── Semantic primitive (resolved to capacitive.* HAL op by the transpiler) ──
31
- export function capacitiveRead(pin: number): number { return 0; }
package/src/constants.ts DELETED
@@ -1,23 +0,0 @@
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: number = 0;
4
- export const OUTPUT: number = 0;
5
- export const INPUT_PULLUP: number = 0;
6
- export const INPUT_PULLDOWN: number = 0;
7
- export const OUTPUT_OPEN_DRAIN: number = 0;
8
- export const ANALOG: number = 0;
9
- export const HIGH: number = 0;
10
- export const LOW: number = 0;
11
- export const LED_BUILTIN: number = 0;
12
- export const LSBFIRST: number = 0;
13
- export const MSBFIRST: number = 0;
14
- export const WDTO_15MS: number = 0;
15
- export const WDTO_30MS: number = 0;
16
- export const WDTO_60MS: number = 0;
17
- export const WDTO_120MS: number = 0;
18
- export const WDTO_250MS: number = 0;
19
- export const WDTO_500MS: number = 0;
20
- export const WDTO_1S: number = 0;
21
- export const WDTO_2S: number = 0;
22
- export const WDTO_4S: number = 0;
23
- export const WDTO_8S: number = 0;
package/src/dac.ts DELETED
@@ -1,21 +0,0 @@
1
- import { dacWrite, boardResolve } from './emit.js';
2
-
3
- /**
4
- * DACClass provides access to true digital-to-analog converters.
5
- *
6
- * Note: This is for true analog output (DAC), distinct from PWM-based
7
- * analog simulation provided by Pin.pwm().
8
- */
9
- export class DACClass {
10
- static readonly __instance_name = "DAC";
11
-
12
- write(pin: number, value: number): void {
13
- dacWrite(pin, value);
14
- }
15
-
16
- getResolution(): number {
17
- return boardResolve("peripherals.dac.0.resolution");
18
- }
19
- }
20
-
21
- export const DAC = new DACClass();
package/src/eeprom.ts DELETED
@@ -1,26 +0,0 @@
1
- import { rawCpp } from './emit.js';
2
- import { include } from './include.js';
3
-
4
- export class EEPROMClass {
5
- static readonly __instance_name = "EEPROM";
6
- static readonly __includes = ["<EEPROM.h>"];
7
- static readonly __default_fields = { _name: "EEPROM" };
8
-
9
- private _name: string;
10
- constructor(name: string) {
11
- include("<EEPROM.h>");
12
- this._name = name;
13
- }
14
-
15
- read(address: number): number { return 0; }
16
- write(address: number, value: number): void { rawCpp(`${this._name}.write(${address}, ${value});`); }
17
- update(address: number, value: number): void { rawCpp(`${this._name}.update(${address}, ${value});`); }
18
- length(): number { return 0; }
19
- get<T>(address: number, ref: T): T {
20
- rawCpp(`${this._name}.get(${address}, ${ref});`);
21
- return ref;
22
- }
23
- put<T>(address: number, value: T): void { rawCpp(`${this._name}.put(${address}, ${value});`); }
24
- }
25
-
26
- export const EEPROM = new EEPROMClass("EEPROM");
package/src/interrupts.ts DELETED
@@ -1,35 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // @typecad/hal — Interrupt helpers
3
- // ---------------------------------------------------------------------------
4
-
5
- import { interruptAttach, interruptDetach } from './emit.js';
6
- import { callback } from './callback.js';
7
- import type { InterruptHandler, InterruptMode } from './types.js';
8
-
9
- /**
10
- * Globally disable interrupts.
11
- */
12
- export function noInterrupts(): void {}
13
-
14
- /**
15
- * Re-enable interrupts after `noInterrupts()`.
16
- */
17
- export function interrupts(): void {}
18
-
19
- /**
20
- * Attach an interrupt handler to a pin.
21
- */
22
- export function attachInterrupt(
23
- pin: number,
24
- handler: InterruptHandler,
25
- mode: InterruptMode,
26
- ): void {
27
- interruptAttach(pin, callback(handler), mode);
28
- }
29
-
30
- /**
31
- * Detach a previously attached interrupt.
32
- */
33
- export function detachInterrupt(pin: number): void {
34
- interruptDetach(pin);
35
- }