@typecad/hal 0.1.0-alpha.2 → 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 +6 -5
  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/emit.js CHANGED
@@ -5,6 +5,11 @@
5
5
  // resolver. The framework strategy translates each operation into
6
6
  // framework-specific C++ at code generation time.
7
7
  //
8
+ // EMIT BOUNDARY: This file is a canonical entry point of the HAL lowering
9
+ // surface (A) — its C++ output lands in user sketches. The emitted bytes are
10
+ // covered by the TypeCAD Runtime Exception (see RUNTIME_EXCEPTION.md at the
11
+ // repository root) and are not subject to the license of this tool source.
12
+ //
8
13
  // Pin parameters accept both `number` (legacy framework pin number) and
9
14
  // `string` (MCU port name like "PB5"). The transpiler resolves port names
10
15
  // to framework pin numbers via the MCU package's pin mapping.
@@ -25,6 +30,29 @@ export function gpioSetMode(pin, mode) { }
25
30
  // ---------------------------------------------------------------------------
26
31
  /** Write PWM duty cycle to a pin. */
27
32
  export function pwmWrite(pin, duty) { }
33
+ /** Positional semantic primitive. Args: pin, resolutionHz, bit0Hi, bit0Lo,
34
+ * bit1Hi, bit1Lo, msbFirst, queueDepth. Use rmtTxInit() from hal/rmt.ts. */
35
+ export function rmtTxInit(pin, resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst, queueDepth) { }
36
+ /** Write bytes via the channel's bytes-encoder (timings fixed at init). */
37
+ export function rmtTxWriteBytes(pin, bytes) { }
38
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
39
+ export function rmtTxWriteSymbols(pin, symbols) { }
40
+ /** Block until the queued TX completes. */
41
+ export function rmtTxWaitDone(pin, timeoutMs) { }
42
+ /** Tear down the TX channel and release its slot. */
43
+ export function rmtTxDeinit(pin) { }
44
+ /** Positional semantic primitive — use rmtRxInit() from hal/rmt.ts. */
45
+ export function rmtRxInit(pin, resolutionHz) { }
46
+ /** Register a callback-by-name invoked when an RX burst completes. */
47
+ export function rmtRxOnReceived(pin, handler) { }
48
+ /** Start receiving. */
49
+ export function rmtRxStart(pin) { }
50
+ /** Stop receiving. */
51
+ export function rmtRxStop(pin) { }
52
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
53
+ export function rmtRxRead(pin, maxCount) { return []; }
54
+ /** Tear down the RX channel and release its slot. */
55
+ export function rmtRxDeinit(pin) { }
28
56
  // ---------------------------------------------------------------------------
29
57
  // ADC — analog-to-digital conversion
30
58
  // ---------------------------------------------------------------------------
@@ -85,6 +113,15 @@ export function i2cRequestFrom(bus, address, quantity, stop) { return 0; }
85
113
  export function i2cAvailable(bus) { return 0; }
86
114
  /** Read a byte from I2C. */
87
115
  export function i2cRead(bus) { return 0; }
116
+ /**
117
+ * Drain `count` bytes requested from the I2C bus into a caller-provided buffer.
118
+ * Semantic primitive: lowers to the `i2c.read_buffer` HAL op. The `buffer`
119
+ * argument is emitted as a placeholder (`__HAL_READ_BUF__`) that the var-init
120
+ * transformer rewrites to the caller's own buffer variable, so bytes land in
121
+ * the `uint8_t data[N]` declared in user scope — NOT an internal temp that
122
+ * decays to a pointer on return. Keeps `data.length` / `data[i]` valid.
123
+ */
124
+ export function i2cReadBuffer(bus, count, buffer) { }
88
125
  // ---------------------------------------------------------------------------
89
126
  // SPI — serial peripheral interface
90
127
  // ---------------------------------------------------------------------------
@@ -102,6 +139,14 @@ export function spiEndTx(bus) { }
102
139
  export function spiCsLow(pin) { }
103
140
  /** Set SPI chip-select pin HIGH. */
104
141
  export function spiCsHigh(pin) { }
142
+ /**
143
+ * Read `count` bytes from the SPI bus into a caller-provided buffer by clocking
144
+ * dummy (0x00) transfers. Semantic primitive: lowers to the `spi.read_buffer`
145
+ * HAL op (per-byte `bus.transfer(0)` read loop). The `buffer` placeholder is
146
+ * rewritten to the caller's variable. Mirrors i2cReadBuffer. The caller is
147
+ * responsible for asserting/de-asserting chip-select around it.
148
+ */
149
+ export function spiReadBuffer(bus, count, buffer) { }
105
150
  /** Set SPI data mode. */
106
151
  export function spiSetMode(bus, mode) { }
107
152
  /** Set SPI bit order. */
@@ -170,8 +215,115 @@ export function powerDeepSleep(ms) { }
170
215
  export function powerLightSleep() { }
171
216
  /** Set the CPU frequency (MHz). */
172
217
  export function powerSetCpuFrequency(mhz) { }
218
+ /** Enter deep sleep until `pin` reaches `level` (pin wakeup). Architecture-aware:
219
+ * ext0 on Xtensa (RTC pins), gpio-wakeup on RISC-V. */
220
+ export function powerDeepSleepPin(pin, level) { }
221
+ // ---------------------------------------------------------------------------
222
+ // Preferences (NVS-backed key/value store)
223
+ // ---------------------------------------------------------------------------
224
+ export function preferencesBegin(namespace, readOnly) { }
225
+ export function preferencesEnd() { }
226
+ export function preferencesClear() { }
227
+ export function preferencesRemove(key) { }
228
+ export function preferencesPutInt(key, value) { }
229
+ export function preferencesGetInt(key, defaultValue) { return 0; }
230
+ export function preferencesPutUInt(key, value) { }
231
+ export function preferencesGetUInt(key, defaultValue) { return 0; }
232
+ export function preferencesPutBool(key, value) { }
233
+ export function preferencesGetBool(key, defaultValue) { return false; }
234
+ export function preferencesPutFloat(key, value) { }
235
+ export function preferencesGetFloat(key, defaultValue) { return 0; }
236
+ export function preferencesPutString(key, value) { }
237
+ export function preferencesGetString(key, defaultValue) { return ""; }
238
+ export function wifiConnect(ssid, password, timeoutMs) { return false; }
239
+ export function wifiConnectStart(ssid, password) { }
240
+ export function wifiDisconnect() { }
241
+ export function wifiStatus() { return 0; }
242
+ export function wifiIsConnected() { return false; }
243
+ export function wifiLocalIp() { return ""; }
244
+ export function wifiRssi() { return 0; }
245
+ export function wifiMac() { return ""; }
246
+ export function wifiSetHostname(name) { }
247
+ export function wifiSetStaticIp(ip, gateway, subnet, dns) { }
248
+ export function wifiSetAutoReconnect(enabled) { }
249
+ export function wifiSetPowerSave(mode) { }
250
+ export function wifiSetTxPower(dbm) { }
251
+ export function wifiOnEvent(event, handler) { }
252
+ export function wifiApStart(ssid, password, channel, hidden, maxClients) { return false; }
253
+ export function wifiApStop() { }
254
+ export function wifiApClientCount() { return 0; }
255
+ export function wifiApIp() { return ""; }
256
+ export function wifiApSetChannel(channel) { }
257
+ export function wifiApSetHidden(hidden) { }
258
+ export function wifiApSetMaxClients(maxClients) { }
259
+ export function wifiScan() { return 0; }
260
+ export function wifiScanStart() { }
261
+ export function wifiScanCount() { return 0; }
262
+ export function wifiScanSsid(index) { return ""; }
263
+ export function wifiScanRssi(index) { return 0; }
264
+ export function wifiScanEncryption(index) { return 0; }
265
+ export function wifiScanChannel(index) { return 0; }
266
+ export function wifiSaveCredentials(ssid, password) { }
267
+ export function wifiConnectSaved(timeoutMs) { return false; }
268
+ export function wifiClearCredentials() { }
269
+ export function wifiWaitConnected(timeoutMs) { return false; }
270
+ export function wifiWaitDisconnected() { }
271
+ // ---------------------------------------------------------------------------
272
+ // HTTP client
273
+ // ---------------------------------------------------------------------------
274
+ export function httpBegin(method, url) { }
275
+ export function httpReset() { }
276
+ export function httpSetHeader(name, value) { }
277
+ export function httpSetTimeout(ms) { }
278
+ export function httpSetMaxBody(bytes) { }
279
+ export function httpSetBody(data, json) { }
280
+ export function httpSetInsecure() { }
281
+ export function httpSetCaCert(pem) { }
282
+ export function httpSend() { return false; }
283
+ export function httpSendStart() { }
284
+ export function httpStatus() { return 0; }
285
+ export function httpOk() { return false; }
286
+ export function httpBody() { return ""; }
287
+ export function httpContentLength() { return 0; }
288
+ export function httpResponseHeader(name) { return ""; }
289
+ // ---------------------------------------------------------------------------
290
+ // BLE (NimBLE GATT peripheral)
291
+ // ---------------------------------------------------------------------------
292
+ export function bleServerBegin(name) { }
293
+ export function bleAdvertiseStart() { }
294
+ export function bleAdvertiseStop() { }
295
+ export function bleAddService(uuid) { }
296
+ export function bleAddChar(index, uuid, type, perms, svcIndex) { }
297
+ export function bleOnRead(index, handler) { }
298
+ export function bleOnWrite(index, handler) { }
299
+ export function bleOnConnect(handler) { }
300
+ export function bleOnDisconnect(handler) { }
301
+ export function bleNotify(index, value) { }
302
+ export function bleIsConnected() { return false; }
303
+ export function bleClientCount() { return 0; }
304
+ export function bleSetName(name) { }
305
+ export function bleUntilConnected(timeoutMs) { return false; }
306
+ export function bleUntilConnectedStart() { }
307
+ export function bleSetTxPower(dbm) { }
308
+ export function bleStatus() { return 0; }
173
309
  // ---------------------------------------------------------------------------
174
310
  // Raw C++ escape hatch
175
311
  // ---------------------------------------------------------------------------
176
312
  /** Emit raw C++ code (escape hatch for unsupported operations). */
177
313
  export function rawCpp(code) { }
314
+ /**
315
+ * Emit raw C++ in expression context. Use when an IDF macro or constructor
316
+ * must produce a value (e.g. `WIFI_INIT_CONFIG_DEFAULT()` expands to a struct
317
+ * initializer; there's no TS-side way to construct it). The type parameter
318
+ * is purely a TS hint — the transpiler doesn't check it; it just emits the
319
+ * raw text in expression position.
320
+ *
321
+ * const cfg = rawCpp<wifi_init_config_t>('WIFI_INIT_CONFIG_DEFAULT()');
322
+ *
323
+ * lowers to:
324
+ *
325
+ * wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
326
+ */
327
+ export function rawCppExpr(code) {
328
+ return undefined;
329
+ }
package/dist/fs.d.ts CHANGED
@@ -1,13 +1,33 @@
1
1
  /**
2
2
  * FSClass provides a high-level abstraction for filesystem operations.
3
- * Maps to SD.h or LittleFS depending on the board configuration.
3
+ *
4
+ * Lowered to native filesystem HAL ops (fs.*): ESP-IDF mounts an SD card via
5
+ * esp_vfs_fat_sdmmc_mount (FAT on SDMMC/SDSPI); Arduino uses SD.h / LittleFS.
6
+ * The per-framework runtime shim owns the open/read/write/close dance and
7
+ * returns heap strings for readText.
8
+ *
9
+ * The semantic primitives (fsBegin / fsReadText / ...) are resolved to fs.*
10
+ * HAL ops by the transpiler's hal-plugins switch; this class is the
11
+ * ergonomic, type-checking surface.
4
12
  */
5
13
  export declare class FSClass {
6
14
  static readonly __instance_name = "FS";
15
+ /** Mount the filesystem. Returns true on success. */
7
16
  begin(): boolean;
17
+ /** Read a UTF-8 text file into a string. Returns "" if the file is missing
18
+ * or unreadable. The returned buffer is caller-owned. */
8
19
  readText(path: string): string;
20
+ /** Write a string to a file (overwrites). Silently no-ops if the file
21
+ * cannot be opened for writing. */
9
22
  writeText(path: string, content: string): void;
23
+ /** True if a file exists at the path. */
10
24
  exists(path: string): boolean;
25
+ /** Delete a file. Returns true if deleted. */
11
26
  remove(path: string): boolean;
12
27
  }
13
28
  export declare const FS: FSClass;
29
+ export declare function fsBegin(): void;
30
+ export declare function fsReadText(path: string): string;
31
+ export declare function fsWriteText(path: string, content: string): void;
32
+ export declare function fsExists(path: string): boolean;
33
+ export declare function fsRemove(path: string): boolean;
package/dist/fs.js CHANGED
@@ -1,39 +1,47 @@
1
- import { rawCpp } from './emit.js';
2
- import { include } from './include.js';
3
1
  /**
4
2
  * FSClass provides a high-level abstraction for filesystem operations.
5
- * Maps to SD.h or LittleFS depending on the board configuration.
3
+ *
4
+ * Lowered to native filesystem HAL ops (fs.*): ESP-IDF mounts an SD card via
5
+ * esp_vfs_fat_sdmmc_mount (FAT on SDMMC/SDSPI); Arduino uses SD.h / LittleFS.
6
+ * The per-framework runtime shim owns the open/read/write/close dance and
7
+ * returns heap strings for readText.
8
+ *
9
+ * The semantic primitives (fsBegin / fsReadText / ...) are resolved to fs.*
10
+ * HAL ops by the transpiler's hal-plugins switch; this class is the
11
+ * ergonomic, type-checking surface.
6
12
  */
7
13
  export class FSClass {
14
+ /** Mount the filesystem. Returns true on success. */
8
15
  begin() {
9
- include("<FS.h>");
10
- rawCpp(`return FS.begin();`);
16
+ fsBegin();
11
17
  return true;
12
18
  }
19
+ /** Read a UTF-8 text file into a string. Returns "" if the file is missing
20
+ * or unreadable. The returned buffer is caller-owned. */
13
21
  readText(path) {
14
- include("<FS.h>");
15
- rawCpp(`File f = FS.open(${path}.c_str(), "r");`);
16
- rawCpp(`if (!f) return "";`);
17
- rawCpp(`String s = f.readString();`);
18
- rawCpp(`f.close();`);
19
- rawCpp(`return s.c_str();`);
20
- return "";
22
+ return fsReadText(path);
21
23
  }
24
+ /** Write a string to a file (overwrites). Silently no-ops if the file
25
+ * cannot be opened for writing. */
22
26
  writeText(path, content) {
23
- include("<FS.h>");
24
- rawCpp(`File f = FS.open(${path}.c_str(), "w");`);
25
- rawCpp(`if (f) { f.print(${content}.c_str()); f.close(); }`);
27
+ fsWriteText(path, content);
26
28
  }
29
+ /** True if a file exists at the path. */
27
30
  exists(path) {
28
- include("<FS.h>");
29
- rawCpp(`return FS.exists(${path}.c_str());`);
30
- return false;
31
+ return fsExists(path);
31
32
  }
33
+ /** Delete a file. Returns true if deleted. */
32
34
  remove(path) {
33
- include("<FS.h>");
34
- rawCpp(`return FS.remove(${path}.c_str());`);
35
- return false;
35
+ return fsRemove(path);
36
36
  }
37
37
  }
38
38
  FSClass.__instance_name = "FS";
39
39
  export const FS = new FSClass();
40
+ // ── Semantic primitives (resolved to fs.* HAL ops by the transpiler) ──
41
+ // These are inert at runtime (tests, type-checking); the cuttlefish transpiler
42
+ // intercepts calls by name and lowers them to typed HAL op IR.
43
+ export function fsBegin() { }
44
+ export function fsReadText(path) { return ""; }
45
+ export function fsWriteText(path, content) { }
46
+ export function fsExists(path) { return false; }
47
+ export function fsRemove(path) { return false; }
package/dist/http.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export declare enum HttpMethod {
2
+ GET = 0,
3
+ POST = 1,
4
+ PUT = 2,
5
+ DELETE = 3,
6
+ HEAD = 4,
7
+ PATCH = 5
8
+ }
9
+ /**
10
+ * Fluent HTTP/S request builder, lowered to native ESP-IDF
11
+ * `esp_http_client` by framework-esp32 (TLS via esp-tls / mbedTLS bundle).
12
+ * Response fields are read from this object after send() — mirrors
13
+ * `await WiFi.connect(); WiFi.localIP()`.
14
+ *
15
+ * No `include()` calls here — ESP-IDF headers are framework-owned and added
16
+ * via forcedIncludes when the program uses http.* ops.
17
+ */
18
+ export declare class HttpRequest {
19
+ private _method;
20
+ private _url;
21
+ constructor(method: string, url: string);
22
+ header(name: string, value: string): this;
23
+ timeout(ms: number): this;
24
+ maxBody(bytes: number): this;
25
+ body(data: string): this;
26
+ jsonBody(json: string): this;
27
+ /** Skip TLS certificate verification (development only). */
28
+ insecure(): this;
29
+ caCert(pem: string): this;
30
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
31
+ send(): Promise<boolean>;
32
+ status(): number;
33
+ ok(): boolean;
34
+ /** Response body as a C string (valid until the next request). */
35
+ text(): string;
36
+ contentLength(): number;
37
+ responseHeader(name: string): string;
38
+ }
39
+ export declare class HttpClass {
40
+ static readonly __instance_name = "Http";
41
+ get(url: string): HttpRequest;
42
+ post(url: string): HttpRequest;
43
+ put(url: string): HttpRequest;
44
+ del(url: string): HttpRequest;
45
+ head(url: string): HttpRequest;
46
+ patch(url: string): HttpRequest;
47
+ }
48
+ export declare const Http: HttpClass;
package/dist/http.js ADDED
@@ -0,0 +1,104 @@
1
+ import { httpBegin, httpReset, httpSetHeader, httpSetTimeout, httpSetMaxBody, httpSetBody, httpSetInsecure, httpSetCaCert, httpSend, httpStatus, httpOk, httpBody, httpContentLength, httpResponseHeader, } from './emit.js';
2
+ export var HttpMethod;
3
+ (function (HttpMethod) {
4
+ HttpMethod[HttpMethod["GET"] = 0] = "GET";
5
+ HttpMethod[HttpMethod["POST"] = 1] = "POST";
6
+ HttpMethod[HttpMethod["PUT"] = 2] = "PUT";
7
+ HttpMethod[HttpMethod["DELETE"] = 3] = "DELETE";
8
+ HttpMethod[HttpMethod["HEAD"] = 4] = "HEAD";
9
+ HttpMethod[HttpMethod["PATCH"] = 5] = "PATCH";
10
+ })(HttpMethod || (HttpMethod = {}));
11
+ /**
12
+ * Fluent HTTP/S request builder, lowered to native ESP-IDF
13
+ * `esp_http_client` by framework-esp32 (TLS via esp-tls / mbedTLS bundle).
14
+ * Response fields are read from this object after send() — mirrors
15
+ * `await WiFi.connect(); WiFi.localIP()`.
16
+ *
17
+ * No `include()` calls here — ESP-IDF headers are framework-owned and added
18
+ * via forcedIncludes when the program uses http.* ops.
19
+ */
20
+ export class HttpRequest {
21
+ constructor(method, url) {
22
+ this._method = method;
23
+ this._url = url;
24
+ }
25
+ header(name, value) {
26
+ httpSetHeader(name, value);
27
+ return this;
28
+ }
29
+ timeout(ms) {
30
+ httpSetTimeout(ms);
31
+ return this;
32
+ }
33
+ maxBody(bytes) {
34
+ httpSetMaxBody(bytes);
35
+ return this;
36
+ }
37
+ body(data) {
38
+ httpSetBody(data, false);
39
+ return this;
40
+ }
41
+ jsonBody(json) {
42
+ httpSetBody(json, true);
43
+ return this;
44
+ }
45
+ /** Skip TLS certificate verification (development only). */
46
+ insecure() {
47
+ httpSetInsecure();
48
+ return this;
49
+ }
50
+ caCert(pem) {
51
+ httpSetCaCert(pem);
52
+ return this;
53
+ }
54
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
55
+ send() {
56
+ httpBegin(this._method, this._url);
57
+ httpSend();
58
+ return Promise.resolve(false);
59
+ }
60
+ status() {
61
+ return httpStatus();
62
+ }
63
+ ok() {
64
+ return httpOk();
65
+ }
66
+ /** Response body as a C string (valid until the next request). */
67
+ text() {
68
+ return httpBody();
69
+ }
70
+ contentLength() {
71
+ return httpContentLength();
72
+ }
73
+ responseHeader(name) {
74
+ return httpResponseHeader(name);
75
+ }
76
+ }
77
+ export class HttpClass {
78
+ get(url) {
79
+ httpReset();
80
+ return new HttpRequest("GET", url);
81
+ }
82
+ post(url) {
83
+ httpReset();
84
+ return new HttpRequest("POST", url);
85
+ }
86
+ put(url) {
87
+ httpReset();
88
+ return new HttpRequest("PUT", url);
89
+ }
90
+ del(url) {
91
+ httpReset();
92
+ return new HttpRequest("DELETE", url);
93
+ }
94
+ head(url) {
95
+ httpReset();
96
+ return new HttpRequest("HEAD", url);
97
+ }
98
+ patch(url) {
99
+ httpReset();
100
+ return new HttpRequest("PATCH", url);
101
+ }
102
+ }
103
+ HttpClass.__instance_name = "Http";
104
+ export const Http = new HttpClass();
package/dist/i2c.d.ts CHANGED
@@ -2,6 +2,13 @@ export declare class I2CDevice {
2
2
  private _bus;
3
3
  private _address;
4
4
  constructor(bus: string, address: number);
5
+ /** The 7-bit I2C address this accessor targets. Exposed so I2CDevice
6
+ * structurally satisfies the @typecad/simulator II2CDeviceAccessor contract
7
+ * (which declares `readonly address`), letting the same driver function be
8
+ * typed against the contract and accept either a real board device or a
9
+ * simulated one. The transpiler strips HAL class bodies to IR, so this
10
+ * getter carries no runtime cost in the generated C++. */
11
+ get address(): number;
5
12
  writeByte(register: number, value: number): void;
6
13
  readByte(register: number): number;
7
14
  writeBytes(register: number, data: number[] | Uint8Array): void;
package/dist/i2c.js CHANGED
@@ -1,10 +1,19 @@
1
- import { i2cBegin, i2cEnd, i2cSetClock, i2cBeginTx, i2cWrite, i2cWriteBuffer, i2cEndTx, i2cRequestFrom, i2cAvailable, i2cRead, rawCpp } from './emit.js';
1
+ import { i2cBegin, i2cEnd, i2cSetClock, i2cBeginTx, i2cWrite, i2cWriteBuffer, i2cEndTx, i2cRequestFrom, i2cAvailable, i2cRead, i2cReadBuffer, rawCpp } from './emit.js';
2
2
  import { include } from './include.js';
3
3
  export class I2CDevice {
4
4
  constructor(bus, address) {
5
5
  this._bus = bus;
6
6
  this._address = address;
7
7
  }
8
+ /** The 7-bit I2C address this accessor targets. Exposed so I2CDevice
9
+ * structurally satisfies the @typecad/simulator II2CDeviceAccessor contract
10
+ * (which declares `readonly address`), letting the same driver function be
11
+ * typed against the contract and accept either a real board device or a
12
+ * simulated one. The transpiler strips HAL class bodies to IR, so this
13
+ * getter carries no runtime cost in the generated C++. */
14
+ get address() {
15
+ return this._address;
16
+ }
8
17
  writeByte(register, value) {
9
18
  include("<Wire.h>");
10
19
  i2cBeginTx(this._bus, this._address);
@@ -33,9 +42,11 @@ export class I2CDevice {
33
42
  i2cWrite(this._bus, register);
34
43
  i2cEndTx(this._bus, false);
35
44
  i2cRequestFrom(this._bus, this._address, count, true);
36
- rawCpp(`static uint8_t __buf[${count}];`);
37
- rawCpp(`for (int __i = 0; __i < ${count}; __i++) __buf[__i] = ${this._bus}.read();`);
38
- rawCpp(`return __buf;`);
45
+ // Drain the requested bytes into the caller's buffer (declared by the
46
+ // Uint8Array return marker as `uint8_t data[count]`). Using the semantic
47
+ // primitive — NOT rawCpp — keeps the buffer in user scope so it survives
48
+ // the return (no decayed pointer) and `data.length` / `data[i]` work.
49
+ i2cReadBuffer(this._bus, count, new Uint8Array(count));
39
50
  return new Uint8Array(count);
40
51
  }
41
52
  }
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export type { SPIBitOrder, SPIMode, SPISettings } from './types.js';
9
9
  export { include } from './include.js';
10
10
  export { board } from './board.js';
11
11
  export { callback } from './callback.js';
12
- export { rawCpp, boardResolve } from './emit.js';
12
+ export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
13
13
  export { HIGH, LOW, OUTPUT, INPUT, INPUT_PULLUP, INPUT_PULLDOWN, OUTPUT_OPEN_DRAIN, ANALOG, LED_BUILTIN, LSBFIRST, MSBFIRST, WDTO_15MS, WDTO_30MS, WDTO_60MS, WDTO_120MS, WDTO_250MS, WDTO_500MS, WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S } from './constants.js';
14
14
  export { delay, millis, micros, delayMicroseconds, map, constrain, TimingClass, Timing } from './timing.js';
15
15
  export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
@@ -33,5 +33,22 @@ export { DACClass, DAC } from './dac.js';
33
33
  export { PreferencesClass, Preferences } from './preferences.js';
34
34
  export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
35
35
  export { FSClass, FS } from './fs.js';
36
+ export { fsBegin, fsReadText, fsWriteText, fsExists, fsRemove } from './fs.js';
37
+ export { MdnsClass, MDNS } from './mdns.js';
38
+ export { mdnsStart, mdnsSetHostname, mdnsAddService, mdnsAnnounce, mdnsStop } from './mdns.js';
39
+ export { MqttClass, MQTT } from './mqtt.js';
40
+ export { mqttConnect, mqttOnMessage, mqttSubscribe, mqttPublish, mqttConnected, mqttDisconnect } from './mqtt.js';
41
+ export { OtaClass, OTA } from './ota.js';
42
+ export { otaFromUrl, otaBegin, otaWrite, otaApply } from './ota.js';
43
+ export { TemperatureClass, Temperature } from './temperature.js';
44
+ export { tempRead } from './temperature.js';
45
+ export { hwtimerSetFrequency, hwtimerOnOverflow, hwtimerStart, hwtimerStop } from './timer.js';
46
+ export { CapacitiveClass, Capacitive } from './capacitive.js';
47
+ export { capacitiveRead } from './capacitive.js';
36
48
  export { PowerClass, Power } from './power.js';
37
49
  export { AsyncClass, Async } from './async.js';
50
+ export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
51
+ export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
52
+ export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
53
+ export type { GattCharacteristicDef, CharValue } from './ble.js';
54
+ export { RmtChannel } from './rmt.js';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { createPinGroup } from './types.js';
3
3
  export { include } from './include.js';
4
4
  export { board } from './board.js';
5
5
  export { callback } from './callback.js';
6
- export { rawCpp, boardResolve } from './emit.js';
6
+ export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
7
7
  export { HIGH, LOW, OUTPUT, INPUT, INPUT_PULLUP, INPUT_PULLDOWN, OUTPUT_OPEN_DRAIN, ANALOG, LED_BUILTIN, LSBFIRST, MSBFIRST, WDTO_15MS, WDTO_30MS, WDTO_60MS, WDTO_120MS, WDTO_250MS, WDTO_500MS, WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S } from './constants.js';
8
8
  export { delay, millis, micros, delayMicroseconds, map, constrain, TimingClass, Timing } from './timing.js';
9
9
  export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
@@ -26,5 +26,21 @@ export { DACClass, DAC } from './dac.js';
26
26
  export { PreferencesClass, Preferences } from './preferences.js';
27
27
  export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
28
28
  export { FSClass, FS } from './fs.js';
29
+ export { fsBegin, fsReadText, fsWriteText, fsExists, fsRemove } from './fs.js';
30
+ export { MdnsClass, MDNS } from './mdns.js';
31
+ export { mdnsStart, mdnsSetHostname, mdnsAddService, mdnsAnnounce, mdnsStop } from './mdns.js';
32
+ export { MqttClass, MQTT } from './mqtt.js';
33
+ export { mqttConnect, mqttOnMessage, mqttSubscribe, mqttPublish, mqttConnected, mqttDisconnect } from './mqtt.js';
34
+ export { OtaClass, OTA } from './ota.js';
35
+ export { otaFromUrl, otaBegin, otaWrite, otaApply } from './ota.js';
36
+ export { TemperatureClass, Temperature } from './temperature.js';
37
+ export { tempRead } from './temperature.js';
38
+ export { hwtimerSetFrequency, hwtimerOnOverflow, hwtimerStart, hwtimerStop } from './timer.js';
39
+ export { CapacitiveClass, Capacitive } from './capacitive.js';
40
+ export { capacitiveRead } from './capacitive.js';
29
41
  export { PowerClass, Power } from './power.js';
30
42
  export { AsyncClass, Async } from './async.js';
43
+ export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
44
+ export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
45
+ export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
46
+ export { RmtChannel } from './rmt.js';
package/dist/mdns.d.ts ADDED
@@ -0,0 +1,31 @@
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 declare class MdnsClass {
14
+ static readonly __instance_name = "MDNS";
15
+ /** Initialize mDNS and set the host name (advertised as <name>.local). */
16
+ start(hostname: string): boolean;
17
+ /** Set/override the host name after start(). */
18
+ setHostname(name: string): void;
19
+ /** Publish a service instance. proto is "_tcp" or "_udp". */
20
+ addService(instance: string, proto: string, port: number): void;
21
+ /** Advertise that the device is reachable (sends a probe/announce). */
22
+ announce(): void;
23
+ /** Tear down the mDNS responder. */
24
+ stop(): void;
25
+ }
26
+ export declare const MDNS: MdnsClass;
27
+ export declare function mdnsStart(hostname: string): void;
28
+ export declare function mdnsSetHostname(name: string): void;
29
+ export declare function mdnsAddService(instance: string, proto: string, port: number): void;
30
+ export declare function mdnsAnnounce(): void;
31
+ export declare function mdnsStop(): void;
package/dist/mdns.js ADDED
@@ -0,0 +1,43 @@
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
+ /** Initialize mDNS and set the host name (advertised as <name>.local). */
15
+ start(hostname) {
16
+ mdnsStart(hostname);
17
+ return true;
18
+ }
19
+ /** Set/override the host name after start(). */
20
+ setHostname(name) {
21
+ mdnsSetHostname(name);
22
+ }
23
+ /** Publish a service instance. proto is "_tcp" or "_udp". */
24
+ addService(instance, proto, port) {
25
+ mdnsAddService(instance, proto, port);
26
+ }
27
+ /** Advertise that the device is reachable (sends a probe/announce). */
28
+ announce() {
29
+ mdnsAnnounce();
30
+ }
31
+ /** Tear down the mDNS responder. */
32
+ stop() {
33
+ mdnsStop();
34
+ }
35
+ }
36
+ MdnsClass.__instance_name = "MDNS";
37
+ export const MDNS = new MdnsClass();
38
+ // ── Semantic primitives (resolved to mdns.* HAL ops by the transpiler) ──
39
+ export function mdnsStart(hostname) { }
40
+ export function mdnsSetHostname(name) { }
41
+ export function mdnsAddService(instance, proto, port) { }
42
+ export function mdnsAnnounce() { }
43
+ export function mdnsStop() { }
package/dist/mqtt.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * MqttClass — MQTT 3.1.1 pub/sub client (ESP-IDF esp_mqtt).
3
+ *
4
+ * Lowered to native MQTT HAL ops (mqtt.*): ESP-IDF's esp_mqtt_client_* API.
5
+ * Covers the common IoT pub/sub path: connect to a broker, publish, subscribe
6
+ * with an onMessage callback, and disconnect. The runtime shim owns the event
7
+ * loop translation (ESP-IDF's MQTT event handler → the user's TS callback).
8
+ *
9
+ * Requires a network connection (WiFi) before connect().
10
+ */
11
+ export declare class MqttClass {
12
+ static readonly __instance_name = "MQTT";
13
+ /** Connect to a broker URI (e.g. "mqtt://broker.local" or "mqtts://..."). */
14
+ connect(brokerUri: string, clientId: string): boolean;
15
+ /** Set a handler invoked for every received PUBLISH on a subscribed topic.
16
+ * The handler receives (topic, payload). */
17
+ onMessage(handler: (topic: string, payload: string) => void): void;
18
+ /** Subscribe to a topic filter (e.g. "sensors/#"). */
19
+ subscribe(topic: string): void;
20
+ /** Publish a message to a topic. */
21
+ publish(topic: string, data: string): void;
22
+ /** True if the client is currently connected to the broker. */
23
+ connected(): boolean;
24
+ /** Disconnect from the broker and free the client. */
25
+ disconnect(): void;
26
+ }
27
+ export declare const MQTT: MqttClass;
28
+ export declare function mqttConnect(brokerUri: string, clientId: string): void;
29
+ export declare function mqttOnMessage(handler: string): void;
30
+ export declare function mqttSubscribe(topic: string): void;
31
+ export declare function mqttPublish(topic: string, data: string): void;
32
+ export declare function mqttConnected(): boolean;
33
+ export declare function mqttDisconnect(): void;