@typecad/hal 1.0.0-alpha.6 → 1.0.0-alpha.8
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/capacitive.d.ts +22 -0
- package/dist/capacitive.js +27 -0
- package/dist/emit.d.ts +122 -0
- package/dist/emit.js +135 -0
- package/dist/fs.d.ts +21 -1
- package/dist/fs.js +29 -21
- package/dist/http.d.ts +48 -0
- package/dist/http.js +104 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.js +17 -1
- package/dist/mdns.d.ts +31 -0
- package/dist/mdns.js +43 -0
- package/dist/mqtt.d.ts +33 -0
- package/dist/mqtt.js +48 -0
- package/dist/ota.d.ts +29 -0
- package/dist/ota.js +38 -0
- 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/rmt.d.ts +48 -0
- package/dist/rmt.js +81 -0
- package/dist/temperature.d.ts +14 -0
- package/dist/temperature.js +17 -0
- package/dist/timer.d.ts +14 -17
- package/dist/timer.js +20 -22
- package/dist/wifi.d.ts +67 -0
- package/dist/wifi.js +151 -0
- package/package.json +6 -5
- package/src/ble.ts +209 -0
- package/src/capacitive.ts +31 -0
- package/src/emit.ts +163 -0
- package/src/fs.ts +30 -22
- package/src/http.ts +144 -0
- package/src/index.ts +21 -1
- package/src/mdns.ts +50 -0
- package/src/mqtt.ts +57 -0
- package/src/ota.ts +44 -0
- package/src/power.ts +11 -1
- package/src/preferences.ts +56 -27
- package/src/rmt.ts +125 -0
- package/src/temperature.ts +20 -0
- package/src/timer.ts +22 -23
- package/src/wifi.ts +221 -0
package/dist/ota.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OtaClass — over-the-air firmware update (ESP-IDF esp_https_ota / esp_app_format).
|
|
3
|
+
*
|
|
4
|
+
* Lowered to native OTA HAL ops (ota.*): ESP-IDF's esp_https_ota downloads a
|
|
5
|
+
* firmware image over HTTPS and writes it to the OTA partition, then reboots
|
|
6
|
+
* into it. The runtime shim owns the session/progress/verification dance.
|
|
7
|
+
*
|
|
8
|
+
* Requires a network connection (WiFi) and that the partition table defines
|
|
9
|
+
* at least two OTA app slots (the framework's default partitions.csv does).
|
|
10
|
+
*/
|
|
11
|
+
export class OtaClass {
|
|
12
|
+
/** Download and apply a firmware image from an HTTPS URL, then reboot.
|
|
13
|
+
* Blocks until the update is written and verified. Returns true on success
|
|
14
|
+
* (the reboot happens inside the shim on success, so a true return means
|
|
15
|
+
* the new firmware is about to boot). */
|
|
16
|
+
fromUrl(url) {
|
|
17
|
+
return otaFromUrl(url);
|
|
18
|
+
}
|
|
19
|
+
/** Begin a manual update session (caller writes chunks via write()). */
|
|
20
|
+
begin() {
|
|
21
|
+
return otaBegin();
|
|
22
|
+
}
|
|
23
|
+
/** Write a chunk of firmware data to the OTA partition. */
|
|
24
|
+
write(chunk) {
|
|
25
|
+
otaWrite(chunk);
|
|
26
|
+
}
|
|
27
|
+
/** Finalize the update: verify, set the boot partition, and reboot. */
|
|
28
|
+
apply() {
|
|
29
|
+
otaApply();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
OtaClass.__instance_name = "OTA";
|
|
33
|
+
export const OTA = new OtaClass();
|
|
34
|
+
// ── Semantic primitives (resolved to ota.* HAL ops by the transpiler) ──
|
|
35
|
+
export function otaFromUrl(url) { return false; }
|
|
36
|
+
export function otaBegin() { return false; }
|
|
37
|
+
export function otaWrite(chunk) { }
|
|
38
|
+
export function otaApply() { }
|
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/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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TemperatureClass — on-chip die temperature sensor.
|
|
3
|
+
*
|
|
4
|
+
* Lowered to the temp.* HAL op: ESP-IDF's temperature_sensor driver reads the
|
|
5
|
+
* internal die temperature in °C. Useful for thermal monitoring and
|
|
6
|
+
* compensation. No external components required.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TemperatureClass {
|
|
9
|
+
static readonly __instance_name = "Temperature";
|
|
10
|
+
/** Read the on-chip die temperature in degrees Celsius. */
|
|
11
|
+
read(): number;
|
|
12
|
+
}
|
|
13
|
+
export declare const Temperature: TemperatureClass;
|
|
14
|
+
export declare function tempRead(): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TemperatureClass — on-chip die temperature sensor.
|
|
3
|
+
*
|
|
4
|
+
* Lowered to the temp.* HAL op: ESP-IDF's temperature_sensor driver reads the
|
|
5
|
+
* internal die temperature in °C. Useful for thermal monitoring and
|
|
6
|
+
* compensation. No external components required.
|
|
7
|
+
*/
|
|
8
|
+
export class TemperatureClass {
|
|
9
|
+
/** Read the on-chip die temperature in degrees Celsius. */
|
|
10
|
+
read() {
|
|
11
|
+
return tempRead();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
TemperatureClass.__instance_name = "Temperature";
|
|
15
|
+
export const Temperature = new TemperatureClass();
|
|
16
|
+
// ── Semantic primitive (resolved to temp.* HAL op by the transpiler) ──
|
|
17
|
+
export function tempRead() { return 0; }
|
package/dist/timer.d.ts
CHANGED
|
@@ -3,33 +3,30 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Hardware timers are distinct from the software-based setInterval/setTimeout
|
|
5
5
|
* and are typically used for high-precision timing, PWM generation, or
|
|
6
|
-
* interrupt-driven tasks.
|
|
6
|
+
* interrupt-driven tasks. Lowered to hwtimer.* HAL ops: ESP-IDF's GPTimer
|
|
7
|
+
* driver (driver/gptimer.h); Arduino's HardwareTimer (Timer0/1/2 on STM32).
|
|
8
|
+
*
|
|
9
|
+
* The instance index maps to the platform's timer numbering (ESP-IDF GPTimer
|
|
10
|
+
* unit 0..n, STM32 TIM0..n).
|
|
7
11
|
*/
|
|
8
12
|
export declare class HardwareTimer {
|
|
9
13
|
private _instance;
|
|
10
14
|
constructor(instance: number);
|
|
11
|
-
/**
|
|
12
|
-
* Sets the timer frequency in Hertz.
|
|
13
|
-
* Note: The actual frequency may be limited by the hardware's clock dividers.
|
|
14
|
-
*/
|
|
15
|
+
/** Sets the timer frequency in Hertz. */
|
|
15
16
|
setFrequency(hz: number): void;
|
|
16
|
-
/**
|
|
17
|
-
* Attaches an interrupt handler that executes when the timer overflows.
|
|
18
|
-
*/
|
|
17
|
+
/** Attaches an interrupt handler that executes when the timer overflows. */
|
|
19
18
|
onOverflow(handler: () => void): void;
|
|
20
|
-
/**
|
|
21
|
-
* Starts the timer.
|
|
22
|
-
*/
|
|
19
|
+
/** Starts the timer. */
|
|
23
20
|
start(): void;
|
|
24
|
-
/**
|
|
25
|
-
* Stops the timer.
|
|
26
|
-
*/
|
|
21
|
+
/** Stops the timer. */
|
|
27
22
|
stop(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Returns the bit resolution of the timer (e.g., 8, 16, 32).
|
|
30
|
-
*/
|
|
23
|
+
/** Returns the bit resolution of the timer (e.g., 8, 16, 32). */
|
|
31
24
|
getBits(): number;
|
|
32
25
|
}
|
|
33
26
|
export declare const Timer0: HardwareTimer;
|
|
34
27
|
export declare const Timer1: HardwareTimer;
|
|
35
28
|
export declare const Timer2: HardwareTimer;
|
|
29
|
+
export declare function hwtimerSetFrequency(instance: number, hz: number): void;
|
|
30
|
+
export declare function hwtimerOnOverflow(instance: number, handler: string): void;
|
|
31
|
+
export declare function hwtimerStart(instance: number): void;
|
|
32
|
+
export declare function hwtimerStop(instance: number): void;
|
package/dist/timer.js
CHANGED
|
@@ -1,44 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { boardResolve } from './emit.js';
|
|
2
2
|
import { callback } from './callback.js';
|
|
3
3
|
/**
|
|
4
4
|
* HardwareTimer provides direct control over the board's hardware timers.
|
|
5
5
|
*
|
|
6
6
|
* Hardware timers are distinct from the software-based setInterval/setTimeout
|
|
7
7
|
* and are typically used for high-precision timing, PWM generation, or
|
|
8
|
-
* interrupt-driven tasks.
|
|
8
|
+
* interrupt-driven tasks. Lowered to hwtimer.* HAL ops: ESP-IDF's GPTimer
|
|
9
|
+
* driver (driver/gptimer.h); Arduino's HardwareTimer (Timer0/1/2 on STM32).
|
|
10
|
+
*
|
|
11
|
+
* The instance index maps to the platform's timer numbering (ESP-IDF GPTimer
|
|
12
|
+
* unit 0..n, STM32 TIM0..n).
|
|
9
13
|
*/
|
|
10
14
|
export class HardwareTimer {
|
|
11
15
|
constructor(instance) {
|
|
12
16
|
this._instance = instance;
|
|
13
17
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Sets the timer frequency in Hertz.
|
|
16
|
-
* Note: The actual frequency may be limited by the hardware's clock dividers.
|
|
17
|
-
*/
|
|
18
|
+
/** Sets the timer frequency in Hertz. */
|
|
18
19
|
setFrequency(hz) {
|
|
19
|
-
|
|
20
|
+
hwtimerSetFrequency(this._instance, hz);
|
|
20
21
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Attaches an interrupt handler that executes when the timer overflows.
|
|
23
|
-
*/
|
|
22
|
+
/** Attaches an interrupt handler that executes when the timer overflows. */
|
|
24
23
|
onOverflow(handler) {
|
|
25
|
-
|
|
24
|
+
hwtimerOnOverflow(this._instance, callback(handler));
|
|
26
25
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Starts the timer.
|
|
29
|
-
*/
|
|
26
|
+
/** Starts the timer. */
|
|
30
27
|
start() {
|
|
31
|
-
|
|
28
|
+
hwtimerStart(this._instance);
|
|
32
29
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Stops the timer.
|
|
35
|
-
*/
|
|
30
|
+
/** Stops the timer. */
|
|
36
31
|
stop() {
|
|
37
|
-
|
|
32
|
+
hwtimerStop(this._instance);
|
|
38
33
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns the bit resolution of the timer (e.g., 8, 16, 32).
|
|
41
|
-
*/
|
|
34
|
+
/** Returns the bit resolution of the timer (e.g., 8, 16, 32). */
|
|
42
35
|
getBits() {
|
|
43
36
|
// "peripherals.timer" (singular) matches the board-resolver's array-key
|
|
44
37
|
// derivation (TIMER_INSTANCES → peripherals.timer.<index>.*).
|
|
@@ -48,3 +41,8 @@ export class HardwareTimer {
|
|
|
48
41
|
export const Timer0 = new HardwareTimer(0);
|
|
49
42
|
export const Timer1 = new HardwareTimer(1);
|
|
50
43
|
export const Timer2 = new HardwareTimer(2);
|
|
44
|
+
// ── Semantic primitives (resolved to hwtimer.* HAL ops by the transpiler) ──
|
|
45
|
+
export function hwtimerSetFrequency(instance, hz) { }
|
|
46
|
+
export function hwtimerOnOverflow(instance, handler) { }
|
|
47
|
+
export function hwtimerStart(instance) { }
|
|
48
|
+
export function hwtimerStop(instance) { }
|
package/dist/wifi.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
startAP(ssid: string, password?: string): boolean;
|
|
53
|
+
apChannel(ch: number): this;
|
|
54
|
+
apHidden(hidden: boolean): this;
|
|
55
|
+
apMaxClients(n: number): this;
|
|
56
|
+
stopAP(): void;
|
|
57
|
+
apClientCount(): number;
|
|
58
|
+
apIP(): string;
|
|
59
|
+
scan(): number;
|
|
60
|
+
scanAsync(): Promise<void>;
|
|
61
|
+
scanCount(): number;
|
|
62
|
+
scanSSID(i: number): string;
|
|
63
|
+
scanRSSI(i: number): number;
|
|
64
|
+
scanEncryption(i: number): WiFiEncryption;
|
|
65
|
+
scanChannel(i: number): number;
|
|
66
|
+
}
|
|
67
|
+
export declare const WiFi: WiFiClass;
|