@typecad/hal 1.0.0-alpha.3 → 1.0.0-alpha.7
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.
- package/README.md +3 -2
- package/dist/ble.d.ts +160 -0
- package/dist/ble.js +157 -0
- package/dist/emit.d.ts +139 -0
- package/dist/emit.js +147 -0
- package/dist/http.d.ts +48 -0
- package/dist/http.js +104 -0
- package/dist/i2c.d.ts +7 -0
- package/dist/i2c.js +15 -4
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/power.d.ts +7 -0
- package/dist/power.js +10 -1
- package/dist/preferences.d.ts +11 -2
- package/dist/preferences.js +28 -27
- package/dist/register.d.ts +12 -4
- package/dist/register.js +18 -1
- package/dist/rmt.d.ts +48 -0
- package/dist/rmt.js +81 -0
- package/dist/spi.js +10 -7
- package/dist/wifi.d.ts +68 -0
- package/dist/wifi.js +154 -0
- package/package.json +4 -4
- package/src/ble.ts +209 -0
- package/src/emit.ts +175 -0
- package/src/http.ts +144 -0
- package/src/i2c.ts +16 -4
- package/src/index.ts +9 -1
- package/src/power.ts +11 -1
- package/src/preferences.ts +56 -27
- package/src/register.ts +16 -4
- package/src/rmt.ts +125 -0
- package/src/spi.ts +10 -7
- package/src/wifi.ts +225 -0
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
|
-
|
|
37
|
-
|
|
38
|
-
rawCpp
|
|
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';
|
|
@@ -35,3 +35,8 @@ export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
|
|
|
35
35
|
export { FSClass, FS } from './fs.js';
|
|
36
36
|
export { PowerClass, Power } from './power.js';
|
|
37
37
|
export { AsyncClass, Async } from './async.js';
|
|
38
|
+
export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
|
|
39
|
+
export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
|
|
40
|
+
export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
|
|
41
|
+
export type { GattCharacteristicDef, CharValue } from './ble.js';
|
|
42
|
+
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';
|
|
@@ -28,3 +28,7 @@ export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
|
|
|
28
28
|
export { FSClass, FS } from './fs.js';
|
|
29
29
|
export { PowerClass, Power } from './power.js';
|
|
30
30
|
export { AsyncClass, Async } from './async.js';
|
|
31
|
+
export { WiFiClass, WiFi, WiFiStatus, WiFiEncryption } from './wifi.js';
|
|
32
|
+
export { HttpClass, Http, HttpRequest, HttpMethod } from './http.js';
|
|
33
|
+
export { BleClass, Ble, BleServer, BleValueType, BlePerm, BleStatus, BleAdvertisingMode, GATT, } from './ble.js';
|
|
34
|
+
export { RmtChannel } from './rmt.js';
|
package/dist/power.d.ts
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
export declare class PowerClass {
|
|
9
9
|
static readonly __instance_name = "Power";
|
|
10
10
|
deepSleep(ms: number): void;
|
|
11
|
+
/** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
|
|
12
|
+
*
|
|
13
|
+
* Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
|
|
14
|
+
* variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
|
|
15
|
+
* the framework flags non-RTC pins at compile time. Wakeup resets the chip,
|
|
16
|
+
* so this call never returns. */
|
|
17
|
+
deepSleepPin(pin: number, level: 0 | 1): void;
|
|
11
18
|
lightSleep(): void;
|
|
12
19
|
setCpuFrequency(mhz: number): void;
|
|
13
20
|
}
|
package/dist/power.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency } from './emit.js';
|
|
1
|
+
import { powerDeepSleep, powerLightSleep, powerSetCpuFrequency, powerDeepSleepPin } from './emit.js';
|
|
2
2
|
/**
|
|
3
3
|
* PowerClass provides control over MCU power states and clock frequencies.
|
|
4
4
|
*
|
|
@@ -10,6 +10,15 @@ export class PowerClass {
|
|
|
10
10
|
deepSleep(ms) {
|
|
11
11
|
powerDeepSleep(ms);
|
|
12
12
|
}
|
|
13
|
+
/** Enter deep sleep until `pin` reaches `level` (0 = low, 1 = high).
|
|
14
|
+
*
|
|
15
|
+
* Lowers to ext0 wakeup (Xtensa ESP32/S3, RTC pins only) or the gpio-wakeup
|
|
16
|
+
* variant (RISC-V C3/C6) depending on the target. `pin` must be RTC-capable;
|
|
17
|
+
* the framework flags non-RTC pins at compile time. Wakeup resets the chip,
|
|
18
|
+
* so this call never returns. */
|
|
19
|
+
deepSleepPin(pin, level) {
|
|
20
|
+
powerDeepSleepPin(pin, level);
|
|
21
|
+
}
|
|
13
22
|
lightSleep() {
|
|
14
23
|
powerLightSleep();
|
|
15
24
|
}
|
package/dist/preferences.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preferences — a persistent key/value store, lowered to native NVS
|
|
3
|
+
* (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
|
|
4
|
+
*
|
|
5
|
+
* No include() calls here — NVS headers are framework-owned and added via
|
|
6
|
+
* forcedIncludes when the program uses preferences.* ops. Method bodies pass
|
|
7
|
+
* parameters directly into semantic calls so the resolver can statically track
|
|
8
|
+
* every argument (matching the WiFi/HTTP HAL pattern).
|
|
9
|
+
*/
|
|
1
10
|
export declare class PreferencesClass {
|
|
2
11
|
static readonly __instance_name = "Preferences";
|
|
3
12
|
begin(name: string, readOnly?: boolean): void;
|
|
@@ -8,10 +17,10 @@ export declare class PreferencesClass {
|
|
|
8
17
|
getInt(key: string, defaultValue?: number): number;
|
|
9
18
|
putUInt(key: string, value: number): void;
|
|
10
19
|
getUInt(key: string, defaultValue?: number): number;
|
|
11
|
-
putFloat(key: string, value: number): void;
|
|
12
|
-
getFloat(key: string, defaultValue?: number): number;
|
|
13
20
|
putBool(key: string, value: boolean): void;
|
|
14
21
|
getBool(key: string, defaultValue?: boolean): boolean;
|
|
22
|
+
putFloat(key: string, value: number): void;
|
|
23
|
+
getFloat(key: string, defaultValue?: number): number;
|
|
15
24
|
putString(key: string, value: string): void;
|
|
16
25
|
getString(key: string, defaultValue?: string): string;
|
|
17
26
|
}
|
package/dist/preferences.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { preferencesBegin, preferencesEnd, preferencesClear, preferencesRemove, preferencesPutInt, preferencesGetInt, preferencesPutUInt, preferencesGetUInt, preferencesPutBool, preferencesGetBool, preferencesPutFloat, preferencesGetFloat, preferencesPutString, preferencesGetString, } from './emit.js';
|
|
2
|
+
/**
|
|
3
|
+
* Preferences — a persistent key/value store, lowered to native NVS
|
|
4
|
+
* (nvs_flash / nvs_open / nvs_set_* / nvs_get_*) by framework-esp32.
|
|
5
|
+
*
|
|
6
|
+
* No include() calls here — NVS headers are framework-owned and added via
|
|
7
|
+
* forcedIncludes when the program uses preferences.* ops. Method bodies pass
|
|
8
|
+
* parameters directly into semantic calls so the resolver can statically track
|
|
9
|
+
* every argument (matching the WiFi/HTTP HAL pattern).
|
|
10
|
+
*/
|
|
2
11
|
export class PreferencesClass {
|
|
3
|
-
// NOTE: no __includes here. The transpiler emits singleton __includes on
|
|
4
|
-
// every architecture with no filtering, and <Preferences.h> is ESP32-only —
|
|
5
|
-
// adding it would break AVR builds. The class is ESP32-only by convention.
|
|
6
12
|
begin(name, readOnly = false) {
|
|
7
|
-
|
|
13
|
+
preferencesBegin(name, readOnly);
|
|
8
14
|
}
|
|
9
15
|
end() {
|
|
10
|
-
|
|
16
|
+
preferencesEnd();
|
|
11
17
|
}
|
|
12
18
|
clear() {
|
|
13
|
-
|
|
19
|
+
preferencesClear();
|
|
14
20
|
}
|
|
15
21
|
remove(key) {
|
|
16
|
-
|
|
22
|
+
preferencesRemove(key);
|
|
17
23
|
}
|
|
18
24
|
putInt(key, value) {
|
|
19
|
-
|
|
25
|
+
preferencesPutInt(key, value);
|
|
20
26
|
}
|
|
21
27
|
getInt(key, defaultValue = 0) {
|
|
22
|
-
|
|
23
|
-
return 0;
|
|
28
|
+
return preferencesGetInt(key, defaultValue);
|
|
24
29
|
}
|
|
25
30
|
putUInt(key, value) {
|
|
26
|
-
|
|
31
|
+
preferencesPutUInt(key, value);
|
|
27
32
|
}
|
|
28
33
|
getUInt(key, defaultValue = 0) {
|
|
29
|
-
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
putFloat(key, value) {
|
|
33
|
-
rawCpp(`Preferences.putFloat(${key}.c_str(), ${value});`);
|
|
34
|
-
}
|
|
35
|
-
getFloat(key, defaultValue = 0) {
|
|
36
|
-
rawCpp(`return Preferences.getFloat(${key}.c_str(), ${defaultValue});`);
|
|
37
|
-
return 0;
|
|
34
|
+
return preferencesGetUInt(key, defaultValue);
|
|
38
35
|
}
|
|
39
36
|
putBool(key, value) {
|
|
40
|
-
|
|
37
|
+
preferencesPutBool(key, value);
|
|
41
38
|
}
|
|
42
39
|
getBool(key, defaultValue = false) {
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
return preferencesGetBool(key, defaultValue);
|
|
41
|
+
}
|
|
42
|
+
putFloat(key, value) {
|
|
43
|
+
preferencesPutFloat(key, value);
|
|
44
|
+
}
|
|
45
|
+
getFloat(key, defaultValue = 0) {
|
|
46
|
+
return preferencesGetFloat(key, defaultValue);
|
|
45
47
|
}
|
|
46
48
|
putString(key, value) {
|
|
47
|
-
|
|
49
|
+
preferencesPutString(key, value);
|
|
48
50
|
}
|
|
49
51
|
getString(key, defaultValue = "") {
|
|
50
|
-
|
|
51
|
-
return "";
|
|
52
|
+
return preferencesGetString(key, defaultValue);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
PreferencesClass.__instance_name = "Preferences";
|
package/dist/register.d.ts
CHANGED
|
@@ -4,8 +4,16 @@ export type Bit = 0 | 1;
|
|
|
4
4
|
* the bit width for documentation only; the value is the raw field contents. */
|
|
5
5
|
export type Bits<N extends number = number> = number;
|
|
6
6
|
/** Class decorator marking a struct as a memory-mapped register at `address`.
|
|
7
|
-
* Erased at transpile time — the class becomes a `volatile uint32_t*`.
|
|
8
|
-
|
|
7
|
+
* Erased at transpile time — the class becomes a `volatile uint32_t*`.
|
|
8
|
+
*
|
|
9
|
+
* These carry real (inert) runtime bodies rather than `declare`, so the
|
|
10
|
+
* `export { register, bits }` re-export in index.ts resolves under Node's ESM
|
|
11
|
+
* loader, which validates that re-exported bindings exist at runtime. They are
|
|
12
|
+
* never invoked: the cuttlefish transpiler detects them by name and lowers the
|
|
13
|
+
* decorated struct away, so these stubs are only reached when the decorator
|
|
14
|
+
* source is imported without transpilation (e.g. host-side tests). */
|
|
15
|
+
export declare function register(_address: number): ClassDecorator;
|
|
9
16
|
/** Property decorator carrying the bit range [lo, hi] (inclusive) of a field
|
|
10
|
-
* within its register. Erased at transpile time.
|
|
11
|
-
|
|
17
|
+
* within its register. Erased at transpile time. See `register` for why these
|
|
18
|
+
* have runtime bodies. */
|
|
19
|
+
export declare function bits(_hi: number, _lo: number): PropertyDecorator;
|
package/dist/register.js
CHANGED
|
@@ -18,4 +18,21 @@
|
|
|
18
18
|
// USART1.UE = 1; // (*USART1 & ~1UL) | ((1 & 1UL) << 0)
|
|
19
19
|
// const parity = USART1.PS; // ((*USART1 >> 8) & ((1UL << 2) - 1))
|
|
20
20
|
// ---------------------------------------------------------------------------
|
|
21
|
-
|
|
21
|
+
/** Class decorator marking a struct as a memory-mapped register at `address`.
|
|
22
|
+
* Erased at transpile time — the class becomes a `volatile uint32_t*`.
|
|
23
|
+
*
|
|
24
|
+
* These carry real (inert) runtime bodies rather than `declare`, so the
|
|
25
|
+
* `export { register, bits }` re-export in index.ts resolves under Node's ESM
|
|
26
|
+
* loader, which validates that re-exported bindings exist at runtime. They are
|
|
27
|
+
* never invoked: the cuttlefish transpiler detects them by name and lowers the
|
|
28
|
+
* decorated struct away, so these stubs are only reached when the decorator
|
|
29
|
+
* source is imported without transpilation (e.g. host-side tests). */
|
|
30
|
+
export function register(_address) {
|
|
31
|
+
return () => { };
|
|
32
|
+
}
|
|
33
|
+
/** Property decorator carrying the bit range [lo, hi] (inclusive) of a field
|
|
34
|
+
* within its register. Erased at transpile time. See `register` for why these
|
|
35
|
+
* have runtime bodies. */
|
|
36
|
+
export function bits(_hi, _lo) {
|
|
37
|
+
return () => { };
|
|
38
|
+
}
|
package/dist/rmt.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Pin } from './gpio.js';
|
|
2
|
+
/** Pin identifier accepted by RmtChannel: a Pin object, raw GPIO number, or port name. */
|
|
3
|
+
type RmtPin = Pin | number | string;
|
|
4
|
+
/**
|
|
5
|
+
* RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
|
|
6
|
+
* are independent roles on the same channel object.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const led = new RmtChannel(LED);
|
|
10
|
+
* led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
|
|
11
|
+
* led.txWriteBytes([0, 16, 0]);
|
|
12
|
+
* led.txWaitDone();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class RmtChannel {
|
|
16
|
+
private _pin;
|
|
17
|
+
constructor(pin: RmtPin);
|
|
18
|
+
/** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
|
|
19
|
+
* at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
|
|
20
|
+
* mutation API. Tick units are 1/resolutionHz seconds.
|
|
21
|
+
*
|
|
22
|
+
* Args are positional scalars (not an opts object) because the transpiler's
|
|
23
|
+
* method-body renderer folds scalar params but not property accesses on an
|
|
24
|
+
* object param (opts.resolutionHz would render as a collapsed object + dead
|
|
25
|
+
* property access). Mirrors how I2CBus.begin(address) takes a scalar. */
|
|
26
|
+
txInit(resolutionHz: number, bit0Hi: number, bit0Lo: number, bit1Hi: number, bit1Lo: number, msbFirst?: boolean, queueDepth?: number): void;
|
|
27
|
+
/** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
|
|
28
|
+
txWriteBytes(bytes: number[] | Uint8Array): void;
|
|
29
|
+
/** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
|
|
30
|
+
txWriteSymbols(symbols: [number, number][]): void;
|
|
31
|
+
/** Block until the queued TX completes. */
|
|
32
|
+
txWaitDone(timeoutMs?: number): void;
|
|
33
|
+
/** Tear down the TX channel and release its slot. */
|
|
34
|
+
txDeinit(): void;
|
|
35
|
+
/** Initialize the channel for RX. Idempotent per pin. */
|
|
36
|
+
rxInit(resolutionHz: number): void;
|
|
37
|
+
/** Register a callback-by-name invoked when an RX burst completes. */
|
|
38
|
+
rxOnReceived(handler: string): void;
|
|
39
|
+
/** Start receiving. */
|
|
40
|
+
rxStart(): void;
|
|
41
|
+
/** Stop receiving. */
|
|
42
|
+
rxStop(): void;
|
|
43
|
+
/** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
|
|
44
|
+
rxRead(maxCount: number): number[];
|
|
45
|
+
/** Tear down the RX channel and release its slot. */
|
|
46
|
+
rxDeinit(): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
package/dist/rmt.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// @typecad/hal — RMT (Remote Control Transceiver) ergonomic API
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Exposes RMT via a RmtChannel class, mirroring the I2CBus/I2CDevice pattern.
|
|
5
|
+
// The transpiler only resolves semantic calls made inside class-method bodies
|
|
6
|
+
// (free top-level calls emit verbatim), so every peripheral exposes its API
|
|
7
|
+
// through a class whose methods call the positional semantic primitives in
|
|
8
|
+
// emit.ts. The resolver collapses object literals, so HALOpIR fields must be
|
|
9
|
+
// scalars; these methods destructure `opts` at the call site before forwarding.
|
|
10
|
+
//
|
|
11
|
+
// Channel identity is the GPIO pin (like pwm.ts's LEDC channel-per-pin model).
|
|
12
|
+
import { rmtTxInit, rmtRxInit, rmtTxWriteBytes, rmtTxWriteSymbols, rmtTxWaitDone, rmtTxDeinit, rmtRxOnReceived, rmtRxStart, rmtRxStop, rmtRxRead, rmtRxDeinit, } from './emit.js';
|
|
13
|
+
/**
|
|
14
|
+
* RMT transceiver channel bound to a GPIO pin. One channel per pin; TX and RX
|
|
15
|
+
* are independent roles on the same channel object.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const led = new RmtChannel(LED);
|
|
19
|
+
* led.txInit({ resolutionHz: 10_000_000, bit0: [4, 9], bit1: [9, 4] });
|
|
20
|
+
* led.txWriteBytes([0, 16, 0]);
|
|
21
|
+
* led.txWaitDone();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class RmtChannel {
|
|
25
|
+
constructor(pin) {
|
|
26
|
+
this._pin = pin;
|
|
27
|
+
}
|
|
28
|
+
// ── TX ─────────────────────────────────────────────────────────────────────
|
|
29
|
+
/** Initialize the channel for TX. Idempotent per pin. Bit timings are fixed
|
|
30
|
+
* at init — ESP-IDF bakes them into the bytes-encoder and exposes no public
|
|
31
|
+
* mutation API. Tick units are 1/resolutionHz seconds.
|
|
32
|
+
*
|
|
33
|
+
* Args are positional scalars (not an opts object) because the transpiler's
|
|
34
|
+
* method-body renderer folds scalar params but not property accesses on an
|
|
35
|
+
* object param (opts.resolutionHz would render as a collapsed object + dead
|
|
36
|
+
* property access). Mirrors how I2CBus.begin(address) takes a scalar. */
|
|
37
|
+
txInit(resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst = false, queueDepth = 4) {
|
|
38
|
+
rmtTxInit(this._pin, resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst, queueDepth);
|
|
39
|
+
}
|
|
40
|
+
/** Write bytes via the channel's bytes-encoder (timings fixed at txInit). */
|
|
41
|
+
txWriteBytes(bytes) {
|
|
42
|
+
rmtTxWriteBytes(this._pin, bytes);
|
|
43
|
+
}
|
|
44
|
+
/** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
|
|
45
|
+
txWriteSymbols(symbols) {
|
|
46
|
+
rmtTxWriteSymbols(this._pin, symbols);
|
|
47
|
+
}
|
|
48
|
+
/** Block until the queued TX completes. */
|
|
49
|
+
txWaitDone(timeoutMs) {
|
|
50
|
+
rmtTxWaitDone(this._pin, timeoutMs);
|
|
51
|
+
}
|
|
52
|
+
/** Tear down the TX channel and release its slot. */
|
|
53
|
+
txDeinit() {
|
|
54
|
+
rmtTxDeinit(this._pin);
|
|
55
|
+
}
|
|
56
|
+
// ── RX ─────────────────────────────────────────────────────────────────────
|
|
57
|
+
/** Initialize the channel for RX. Idempotent per pin. */
|
|
58
|
+
rxInit(resolutionHz) {
|
|
59
|
+
rmtRxInit(this._pin, resolutionHz);
|
|
60
|
+
}
|
|
61
|
+
/** Register a callback-by-name invoked when an RX burst completes. */
|
|
62
|
+
rxOnReceived(handler) {
|
|
63
|
+
rmtRxOnReceived(this._pin, handler);
|
|
64
|
+
}
|
|
65
|
+
/** Start receiving. */
|
|
66
|
+
rxStart() {
|
|
67
|
+
rmtRxStart(this._pin);
|
|
68
|
+
}
|
|
69
|
+
/** Stop receiving. */
|
|
70
|
+
rxStop() {
|
|
71
|
+
rmtRxStop(this._pin);
|
|
72
|
+
}
|
|
73
|
+
/** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
|
|
74
|
+
rxRead(maxCount) {
|
|
75
|
+
return rmtRxRead(this._pin, maxCount);
|
|
76
|
+
}
|
|
77
|
+
/** Tear down the RX channel and release its slot. */
|
|
78
|
+
rxDeinit() {
|
|
79
|
+
rmtRxDeinit(this._pin);
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/spi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spiBegin, spiEnd, spiTransfer, spiBeginTx, spiEndTx, spiCsLow, spiCsHigh, spiSetMode, spiSetBitOrder, rawCpp } from './emit.js';
|
|
1
|
+
import { spiBegin, spiEnd, spiTransfer, spiBeginTx, spiEndTx, spiCsLow, spiCsHigh, spiSetMode, spiSetBitOrder, spiReadBuffer, rawCpp } from './emit.js';
|
|
2
2
|
import { include } from './include.js';
|
|
3
3
|
export class SPIDevice {
|
|
4
4
|
constructor(bus, chipSelect) {
|
|
@@ -21,12 +21,15 @@ export class SPIDevice {
|
|
|
21
21
|
}
|
|
22
22
|
readRegister(register, count) {
|
|
23
23
|
include("<SPI.h>");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
rawCpp
|
|
29
|
-
|
|
24
|
+
spiCsLow(this._cs);
|
|
25
|
+
spiTransfer(this._bus, register);
|
|
26
|
+
// Clock `count` dummy bytes and drain them into the caller's buffer
|
|
27
|
+
// (declared by the Uint8Array return marker as `uint8_t data[count]`).
|
|
28
|
+
// Using the semantic primitive — NOT rawCpp — keeps the buffer in user
|
|
29
|
+
// scope so it survives the return (no decayed pointer) and `data.length`
|
|
30
|
+
// / `data[i]` work, mirroring I2CDevice.readBytes.
|
|
31
|
+
spiReadBuffer(this._bus, count, new Uint8Array(count));
|
|
32
|
+
spiCsHigh(this._cs);
|
|
30
33
|
return new Uint8Array(count);
|
|
31
34
|
}
|
|
32
35
|
writeRegister(register, value) {
|
package/dist/wifi.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Normalized WiFi link status (mapped from esp_wifi events by the runtime shim). */
|
|
2
|
+
export declare enum WiFiStatus {
|
|
3
|
+
Idle = 0,
|
|
4
|
+
Connecting = 1,
|
|
5
|
+
Connected = 2,
|
|
6
|
+
ConnectFailed = 3,
|
|
7
|
+
Disconnected = 4
|
|
8
|
+
}
|
|
9
|
+
export declare enum WiFiEncryption {
|
|
10
|
+
Open = 0,
|
|
11
|
+
WEP = 1,
|
|
12
|
+
WPA = 2,
|
|
13
|
+
WPA2 = 3,
|
|
14
|
+
WPA3 = 4,
|
|
15
|
+
Enterprise = 5
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* WiFi radio / link control, lowered to native ESP-IDF (`esp_wifi` /
|
|
19
|
+
* `esp_netif` / `esp_event` / `nvs_flash`) by framework-esp32.
|
|
20
|
+
*
|
|
21
|
+
* No `include()` calls here — ESP-IDF headers are framework-owned and added
|
|
22
|
+
* via forcedIncludes when the program uses wifi.* ops (the Preferences
|
|
23
|
+
* lesson: HAL files must not carry platform headers). Frameworks without a
|
|
24
|
+
* wifi lowering reject these ops with a diagnostic.
|
|
25
|
+
*/
|
|
26
|
+
export declare class WiFiClass {
|
|
27
|
+
static readonly __instance_name = "WiFi";
|
|
28
|
+
/** Blocking at top level; cooperatively awaitable inside async functions. */
|
|
29
|
+
connect(ssid: string, password?: string, timeoutMs?: number): Promise<boolean>;
|
|
30
|
+
/** Fire-and-forget STA begin; poll status() / untilConnected(). */
|
|
31
|
+
connectAsync(ssid: string, password?: string): void;
|
|
32
|
+
untilConnected(timeoutMs?: number): Promise<boolean>;
|
|
33
|
+
untilDisconnected(): Promise<void>;
|
|
34
|
+
disconnect(): void;
|
|
35
|
+
isConnected(): boolean;
|
|
36
|
+
status(): WiFiStatus;
|
|
37
|
+
localIP(): string;
|
|
38
|
+
rssi(): number;
|
|
39
|
+
macAddress(): string;
|
|
40
|
+
hostname(name: string): this;
|
|
41
|
+
staticIP(ip: string, gateway: string, subnet: string, dns?: string): this;
|
|
42
|
+
autoReconnect(enabled: boolean): this;
|
|
43
|
+
powerSave(mode: "default" | "none"): this;
|
|
44
|
+
/** Cap TX power in dBm (roughly 2–20). Safe to call before connect() —
|
|
45
|
+
* the value is applied after the radio starts. */
|
|
46
|
+
txPower(dbm: number): this;
|
|
47
|
+
saveCredentials(ssid: string, password: string): void;
|
|
48
|
+
connectSaved(timeoutMs?: number): boolean;
|
|
49
|
+
clearCredentials(): void;
|
|
50
|
+
onConnect(handler: () => void): void;
|
|
51
|
+
onDisconnect(handler: () => void): void;
|
|
52
|
+
onGotIP(handler: () => void): void;
|
|
53
|
+
startAP(ssid: string, password?: string): boolean;
|
|
54
|
+
apChannel(ch: number): this;
|
|
55
|
+
apHidden(hidden: boolean): this;
|
|
56
|
+
apMaxClients(n: number): this;
|
|
57
|
+
stopAP(): void;
|
|
58
|
+
apClientCount(): number;
|
|
59
|
+
apIP(): string;
|
|
60
|
+
scan(): number;
|
|
61
|
+
scanAsync(): Promise<void>;
|
|
62
|
+
scanCount(): number;
|
|
63
|
+
scanSSID(i: number): string;
|
|
64
|
+
scanRSSI(i: number): number;
|
|
65
|
+
scanEncryption(i: number): WiFiEncryption;
|
|
66
|
+
scanChannel(i: number): number;
|
|
67
|
+
}
|
|
68
|
+
export declare const WiFi: WiFiClass;
|