@typecad/hal 1.0.0-alpha.6 → 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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # `@typecad/hal`
2
2
 
3
3
  Hardware abstraction layer for [TypeCAD](https://cuttlefish.typecad.net) —
4
- GPIO, I2C, SPI, UART, timers, ADC/DAC, EEPROM, and more, written as regular
5
- TypeScript.
4
+ GPIO, I2C, SPI, UART, timers, ADC/DAC, EEPROM, WiFi/HTTP, and more, written as
5
+ regular TypeScript.
6
6
 
7
7
  `@typecad/hal` is what firmware code imports to talk to hardware. You write
8
8
  normal TypeScript (`pin.high()`, `i2c.write(...)`, `Serial0.print(...)`); the
@@ -41,6 +41,7 @@ add new HAL features.
41
41
  | **I2C** | `I2CBus`, `II2CBus`, `I2CStatus`, `i2cName` |
42
42
  | **SPI** | `SPIBus`, `ISPIBus`, `SPIStatus`, `SPISettings`, `spiName` |
43
43
  | **UART / Serial** | `SerialPort`, `IUARTBus`, `UARTStatus`, `serialName` |
44
+ | **Networking** | `WiFi`, `WiFiClass`, `WiFiStatus`, `WiFiEncryption`, `Http`, `HttpClass`, `HttpRequest`, `HttpMethod` |
44
45
  | **Timing** | `delay`, `millis`, `micros`, `delayMicroseconds`, `Timing`, `map`, `constrain` |
45
46
  | **Pulse / Shift** | `pulseIn`, `shiftIn`, `shiftOut` |
46
47
  | **Interrupts** | `attachInterrupt`, `detachInterrupt`, `noInterrupts`, `interrupts`, `InterruptMode` |
package/dist/ble.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ /** Characteristic value encoding — drives both TS callback types and C++ marshalling. */
2
+ export declare enum BleValueType {
3
+ Uint8 = "uint8",
4
+ Uint16 = "uint16",
5
+ Uint32 = "uint32",
6
+ Int8 = "int8",
7
+ Int16 = "int16",
8
+ Int32 = "int32",
9
+ Float32 = "float32",
10
+ Utf8 = "utf8",
11
+ Boolean = "boolean",
12
+ Bytes = "bytes"
13
+ }
14
+ /** GATT characteristic permission flags. Combine with `|`. */
15
+ export declare enum BlePerm {
16
+ Read = 1,
17
+ Write = 2,
18
+ Notify = 4
19
+ }
20
+ /** BLE peripheral status (mirrored by the runtime shim). */
21
+ export declare enum BleStatus {
22
+ Idle = 0,
23
+ Initializing = 1,
24
+ Advertising = 2,
25
+ Connected = 3,
26
+ Error = 4
27
+ }
28
+ export declare enum BleAdvertisingMode {
29
+ Connectable = "connectable",
30
+ NonConnectable = "non_connectable"
31
+ }
32
+ /** A well-known GATT characteristic entry in the catalog. */
33
+ export interface GattCharacteristicDef {
34
+ readonly uuid: string;
35
+ readonly type: BleValueType;
36
+ readonly read?: boolean;
37
+ readonly write?: boolean;
38
+ readonly notify?: boolean;
39
+ }
40
+ /**
41
+ * Standard GATT services/characteristics. Autocomplete walks the hierarchy:
42
+ * GATT.ENVIRONMENTAL. -> TEMPERATURE, HUMIDITY, ...
43
+ * Pass the .uuid, .type, and computed perms to BleServer.characteristic().
44
+ */
45
+ export declare const GATT: {
46
+ readonly DEVICE_INFO: {
47
+ readonly MANUFACTURER_NAME: {
48
+ readonly uuid: "2A29";
49
+ readonly type: BleValueType.Utf8;
50
+ readonly read: true;
51
+ };
52
+ readonly MODEL_NUMBER: {
53
+ readonly uuid: "2A24";
54
+ readonly type: BleValueType.Utf8;
55
+ readonly read: true;
56
+ };
57
+ readonly FIRMWARE_REVISION: {
58
+ readonly uuid: "2A26";
59
+ readonly type: BleValueType.Utf8;
60
+ readonly read: true;
61
+ };
62
+ };
63
+ readonly ENVIRONMENTAL: {
64
+ readonly TEMPERATURE: {
65
+ readonly uuid: "2A6E";
66
+ readonly type: BleValueType.Int16;
67
+ readonly read: true;
68
+ readonly notify: true;
69
+ };
70
+ readonly HUMIDITY: {
71
+ readonly uuid: "2A6F";
72
+ readonly type: BleValueType.Uint16;
73
+ readonly read: true;
74
+ readonly notify: true;
75
+ };
76
+ readonly PRESSURE: {
77
+ readonly uuid: "2A6D";
78
+ readonly type: BleValueType.Uint32;
79
+ readonly read: true;
80
+ readonly notify: true;
81
+ };
82
+ };
83
+ readonly BATTERY: {
84
+ readonly LEVEL: {
85
+ readonly uuid: "2A19";
86
+ readonly type: BleValueType.Uint8;
87
+ readonly read: true;
88
+ readonly notify: true;
89
+ };
90
+ };
91
+ };
92
+ /** The value passed to/from callbacks — narrowed per characteristic by type. */
93
+ export type CharValue = number | string | boolean | Uint8Array;
94
+ /**
95
+ * BLE GATT peripheral control, lowered to native ESP-IDF NimBLE
96
+ * (`nimble_host` / `ble_gap` / `ble_gatts`) by framework-esp32.
97
+ *
98
+ * No `include()` calls here — NimBLE headers are framework-owned and added via
99
+ * forcedIncludes when the program uses ble.* ops.
100
+ *
101
+ * Transpiler note: method bodies pass parameters directly into semantic calls
102
+ * (no local consts / module counters) so the resolver can statically track every
103
+ * argument. The characteristic index is carried through the chain via
104
+ * `this._charCount` fieldValues, mirroring how HttpRequest carries _method/_url.
105
+ */
106
+ export declare class BleClass {
107
+ static readonly __instance_name = "Ble";
108
+ /** Begin building a GATT server with the given advertised device name. */
109
+ server(name: string): BleServer;
110
+ /** Initialize NimBLE, register services, and start advertising. */
111
+ begin(): void;
112
+ advertise(): void;
113
+ stopAdvertising(): void;
114
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
115
+ untilConnected(timeoutMs?: number): Promise<boolean>;
116
+ untilConnectedStart(): void;
117
+ isConnected(): boolean;
118
+ status(): BleStatus;
119
+ clientCount(): number;
120
+ txPower(dbm: number): this;
121
+ notify(index: number, value: number): void;
122
+ }
123
+ /**
124
+ * Fluent GATT server builder. Returned by `Ble.server()`.
125
+ *
126
+ * Single-class fluent chain (like HttpRequest): characteristic() returns `this`,
127
+ * so onRead/onWrite/onSubscribe chain directly. The _charCount field tracks
128
+ * which characteristic slot the callbacks attach to.
129
+ *
130
+ * Field tracking (read by the transpiler resolver via ctor field assignment):
131
+ * _name — advertised device name
132
+ * _charCount — current characteristic index (the last characteristic() target)
133
+ * _svcCount — current service index
134
+ */
135
+ export declare class BleServer {
136
+ private _name;
137
+ private _charCount;
138
+ private _lastChar;
139
+ private _svcCount;
140
+ constructor(name: string, charCount: number, svcCount: number);
141
+ /** Add a characteristic by UUID, value type, and permissions.
142
+ * Combine permissions with `|`: `BlePerm.Read | BlePerm.Notify`.
143
+ * Returns this for chaining. */
144
+ characteristic(uuid: string, type: BleValueType, perms: number): this;
145
+ /** Begin a new service grouping. Subsequent characteristics attach to it. */
146
+ service(uuid: string): this;
147
+ /** Register a read handler for the most recently added characteristic. */
148
+ onRead(handler: () => CharValue): this;
149
+ /** Register a write handler for the most recently added characteristic. */
150
+ onWrite(handler: (value: number) => void): this;
151
+ /** Register a connect handler (called when a central connects). */
152
+ onConnect(handler: () => void): this;
153
+ /** Register a disconnect handler (called when a central disconnects). */
154
+ onDisconnect(handler: () => void): this;
155
+ /** Push a new value to subscribed clients on the most recently added characteristic. */
156
+ notify(value: number): void;
157
+ /** Initialize NimBLE, register services, and start advertising. */
158
+ begin(): void;
159
+ }
160
+ export declare const Ble: BleClass;
package/dist/ble.js ADDED
@@ -0,0 +1,157 @@
1
+ import { bleServerBegin, bleAdvertiseStart, bleAdvertiseStop, bleAddService, bleAddChar, bleOnRead, bleOnWrite, bleOnConnect, bleOnDisconnect, bleNotify, bleIsConnected, bleClientCount, bleSetName, bleUntilConnected, bleUntilConnectedStart, bleSetTxPower, bleStatus, } from './emit.js';
2
+ import { callback } from './callback.js';
3
+ /** Characteristic value encoding — drives both TS callback types and C++ marshalling. */
4
+ export var BleValueType;
5
+ (function (BleValueType) {
6
+ BleValueType["Uint8"] = "uint8";
7
+ BleValueType["Uint16"] = "uint16";
8
+ BleValueType["Uint32"] = "uint32";
9
+ BleValueType["Int8"] = "int8";
10
+ BleValueType["Int16"] = "int16";
11
+ BleValueType["Int32"] = "int32";
12
+ BleValueType["Float32"] = "float32";
13
+ BleValueType["Utf8"] = "utf8";
14
+ BleValueType["Boolean"] = "boolean";
15
+ BleValueType["Bytes"] = "bytes";
16
+ })(BleValueType || (BleValueType = {}));
17
+ /** GATT characteristic permission flags. Combine with `|`. */
18
+ export var BlePerm;
19
+ (function (BlePerm) {
20
+ BlePerm[BlePerm["Read"] = 1] = "Read";
21
+ BlePerm[BlePerm["Write"] = 2] = "Write";
22
+ BlePerm[BlePerm["Notify"] = 4] = "Notify";
23
+ })(BlePerm || (BlePerm = {}));
24
+ /** BLE peripheral status (mirrored by the runtime shim). */
25
+ export var BleStatus;
26
+ (function (BleStatus) {
27
+ BleStatus[BleStatus["Idle"] = 0] = "Idle";
28
+ BleStatus[BleStatus["Initializing"] = 1] = "Initializing";
29
+ BleStatus[BleStatus["Advertising"] = 2] = "Advertising";
30
+ BleStatus[BleStatus["Connected"] = 3] = "Connected";
31
+ BleStatus[BleStatus["Error"] = 4] = "Error";
32
+ })(BleStatus || (BleStatus = {}));
33
+ export var BleAdvertisingMode;
34
+ (function (BleAdvertisingMode) {
35
+ BleAdvertisingMode["Connectable"] = "connectable";
36
+ BleAdvertisingMode["NonConnectable"] = "non_connectable";
37
+ })(BleAdvertisingMode || (BleAdvertisingMode = {}));
38
+ /**
39
+ * Standard GATT services/characteristics. Autocomplete walks the hierarchy:
40
+ * GATT.ENVIRONMENTAL. -> TEMPERATURE, HUMIDITY, ...
41
+ * Pass the .uuid, .type, and computed perms to BleServer.characteristic().
42
+ */
43
+ export const GATT = {
44
+ DEVICE_INFO: {
45
+ MANUFACTURER_NAME: { uuid: '2A29', type: BleValueType.Utf8, read: true },
46
+ MODEL_NUMBER: { uuid: '2A24', type: BleValueType.Utf8, read: true },
47
+ FIRMWARE_REVISION: { uuid: '2A26', type: BleValueType.Utf8, read: true },
48
+ },
49
+ ENVIRONMENTAL: {
50
+ TEMPERATURE: { uuid: '2A6E', type: BleValueType.Int16, read: true, notify: true },
51
+ HUMIDITY: { uuid: '2A6F', type: BleValueType.Uint16, read: true, notify: true },
52
+ PRESSURE: { uuid: '2A6D', type: BleValueType.Uint32, read: true, notify: true },
53
+ },
54
+ BATTERY: {
55
+ LEVEL: { uuid: '2A19', type: BleValueType.Uint8, read: true, notify: true },
56
+ },
57
+ };
58
+ /**
59
+ * BLE GATT peripheral control, lowered to native ESP-IDF NimBLE
60
+ * (`nimble_host` / `ble_gap` / `ble_gatts`) by framework-esp32.
61
+ *
62
+ * No `include()` calls here — NimBLE headers are framework-owned and added via
63
+ * forcedIncludes when the program uses ble.* ops.
64
+ *
65
+ * Transpiler note: method bodies pass parameters directly into semantic calls
66
+ * (no local consts / module counters) so the resolver can statically track every
67
+ * argument. The characteristic index is carried through the chain via
68
+ * `this._charCount` fieldValues, mirroring how HttpRequest carries _method/_url.
69
+ */
70
+ export class BleClass {
71
+ /** Begin building a GATT server with the given advertised device name. */
72
+ server(name) {
73
+ bleSetName(name);
74
+ return new BleServer(name, 0, 1);
75
+ }
76
+ /** Initialize NimBLE, register services, and start advertising. */
77
+ begin() {
78
+ bleServerBegin("TypeCAD");
79
+ bleAdvertiseStart();
80
+ }
81
+ advertise() { bleAdvertiseStart(); }
82
+ stopAdvertising() { bleAdvertiseStop(); }
83
+ /** Blocking at top level; cooperatively awaitable inside async functions. */
84
+ untilConnected(timeoutMs = 0) {
85
+ bleUntilConnected(timeoutMs);
86
+ return Promise.resolve(false);
87
+ }
88
+ untilConnectedStart() { bleUntilConnectedStart(); }
89
+ isConnected() { return bleIsConnected(); }
90
+ status() { return bleStatus(); }
91
+ clientCount() { return bleClientCount(); }
92
+ txPower(dbm) { bleSetTxPower(dbm); return this; }
93
+ notify(index, value) { bleNotify(index, value); }
94
+ }
95
+ BleClass.__instance_name = "Ble";
96
+ /**
97
+ * Fluent GATT server builder. Returned by `Ble.server()`.
98
+ *
99
+ * Single-class fluent chain (like HttpRequest): characteristic() returns `this`,
100
+ * so onRead/onWrite/onSubscribe chain directly. The _charCount field tracks
101
+ * which characteristic slot the callbacks attach to.
102
+ *
103
+ * Field tracking (read by the transpiler resolver via ctor field assignment):
104
+ * _name — advertised device name
105
+ * _charCount — current characteristic index (the last characteristic() target)
106
+ * _svcCount — current service index
107
+ */
108
+ export class BleServer {
109
+ constructor(name, charCount, svcCount) {
110
+ this._name = name;
111
+ this._charCount = charCount;
112
+ this._lastChar = charCount;
113
+ this._svcCount = svcCount;
114
+ }
115
+ /** Add a characteristic by UUID, value type, and permissions.
116
+ * Combine permissions with `|`: `BlePerm.Read | BlePerm.Notify`.
117
+ * Returns this for chaining. */
118
+ characteristic(uuid, type, perms) {
119
+ bleAddChar(this._charCount, uuid, type, perms, this._svcCount);
120
+ return this;
121
+ }
122
+ /** Begin a new service grouping. Subsequent characteristics attach to it. */
123
+ service(uuid) {
124
+ bleAddService(uuid);
125
+ return this;
126
+ }
127
+ /** Register a read handler for the most recently added characteristic. */
128
+ onRead(handler) {
129
+ bleOnRead(this._lastChar, callback(handler));
130
+ return this;
131
+ }
132
+ /** Register a write handler for the most recently added characteristic. */
133
+ onWrite(handler) {
134
+ bleOnWrite(this._lastChar, callback(handler));
135
+ return this;
136
+ }
137
+ /** Register a connect handler (called when a central connects). */
138
+ onConnect(handler) {
139
+ bleOnConnect(callback(handler));
140
+ return this;
141
+ }
142
+ /** Register a disconnect handler (called when a central disconnects). */
143
+ onDisconnect(handler) {
144
+ bleOnDisconnect(callback(handler));
145
+ return this;
146
+ }
147
+ /** Push a new value to subscribed clients on the most recently added characteristic. */
148
+ notify(value) {
149
+ bleNotify(this._lastChar, value);
150
+ }
151
+ /** Initialize NimBLE, register services, and start advertising. */
152
+ begin() {
153
+ bleServerBegin(this._name);
154
+ bleAdvertiseStart();
155
+ }
156
+ }
157
+ export const Ble = new BleClass();
package/dist/emit.d.ts CHANGED
@@ -8,6 +8,31 @@ export declare function gpioToggle(pin: number | string): void;
8
8
  export declare function gpioSetMode(pin: number | string, mode: string): void;
9
9
  /** Write PWM duty cycle to a pin. */
10
10
  export declare function pwmWrite(pin: number | string, duty: number): void;
11
+ import type { Pin } from './gpio.js';
12
+ type RmtPin = Pin | number | string;
13
+ /** Positional semantic primitive. Args: pin, resolutionHz, bit0Hi, bit0Lo,
14
+ * bit1Hi, bit1Lo, msbFirst, queueDepth. Use rmtTxInit() from hal/rmt.ts. */
15
+ export declare function rmtTxInit(pin: RmtPin, resolutionHz: number, bit0Hi: number, bit0Lo: number, bit1Hi: number, bit1Lo: number, msbFirst: boolean, queueDepth: number): void;
16
+ /** Write bytes via the channel's bytes-encoder (timings fixed at init). */
17
+ export declare function rmtTxWriteBytes(pin: RmtPin, bytes: number[] | Uint8Array): void;
18
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
19
+ export declare function rmtTxWriteSymbols(pin: RmtPin, symbols: [number, number][]): void;
20
+ /** Block until the queued TX completes. */
21
+ export declare function rmtTxWaitDone(pin: RmtPin, timeoutMs?: number): void;
22
+ /** Tear down the TX channel and release its slot. */
23
+ export declare function rmtTxDeinit(pin: RmtPin): void;
24
+ /** Positional semantic primitive — use rmtRxInit() from hal/rmt.ts. */
25
+ export declare function rmtRxInit(pin: RmtPin, resolutionHz: number): void;
26
+ /** Register a callback-by-name invoked when an RX burst completes. */
27
+ export declare function rmtRxOnReceived(pin: RmtPin, handler: string): void;
28
+ /** Start receiving. */
29
+ export declare function rmtRxStart(pin: RmtPin): void;
30
+ /** Stop receiving. */
31
+ export declare function rmtRxStop(pin: RmtPin): void;
32
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
33
+ export declare function rmtRxRead(pin: RmtPin, maxCount: number): number[];
34
+ /** Tear down the RX channel and release its slot. */
35
+ export declare function rmtRxDeinit(pin: RmtPin): void;
11
36
  /** Read analog value from a pin. */
12
37
  export declare function adcRead(pin: number | string): number;
13
38
  /** Read analog voltage from a pin (ADC value converted to voltage). */
@@ -134,5 +159,102 @@ export declare function powerDeepSleep(ms: number): void;
134
159
  export declare function powerLightSleep(): void;
135
160
  /** Set the CPU frequency (MHz). */
136
161
  export declare function powerSetCpuFrequency(mhz: number): void;
162
+ /** Enter deep sleep until `pin` reaches `level` (pin wakeup). Architecture-aware:
163
+ * ext0 on Xtensa (RTC pins), gpio-wakeup on RISC-V. */
164
+ export declare function powerDeepSleepPin(pin: number, level: number): void;
165
+ export declare function preferencesBegin(namespace: string, readOnly: boolean): void;
166
+ export declare function preferencesEnd(): void;
167
+ export declare function preferencesClear(): void;
168
+ export declare function preferencesRemove(key: string): void;
169
+ export declare function preferencesPutInt(key: string, value: number): void;
170
+ export declare function preferencesGetInt(key: string, defaultValue: number): number;
171
+ export declare function preferencesPutUInt(key: string, value: number): void;
172
+ export declare function preferencesGetUInt(key: string, defaultValue: number): number;
173
+ export declare function preferencesPutBool(key: string, value: boolean): void;
174
+ export declare function preferencesGetBool(key: string, defaultValue: boolean): boolean;
175
+ export declare function preferencesPutFloat(key: string, value: number): void;
176
+ export declare function preferencesGetFloat(key: string, defaultValue: number): number;
177
+ export declare function preferencesPutString(key: string, value: string): void;
178
+ export declare function preferencesGetString(key: string, defaultValue: string): string;
179
+ export declare function wifiConnect(ssid: string, password?: string, timeoutMs?: number): boolean;
180
+ export declare function wifiConnectStart(ssid: string, password?: string): void;
181
+ export declare function wifiDisconnect(): void;
182
+ export declare function wifiStatus(): number;
183
+ export declare function wifiIsConnected(): boolean;
184
+ export declare function wifiLocalIp(): string;
185
+ export declare function wifiRssi(): number;
186
+ export declare function wifiMac(): string;
187
+ export declare function wifiSetHostname(name: string): void;
188
+ export declare function wifiSetStaticIp(ip: string, gateway: string, subnet: string, dns?: string): void;
189
+ export declare function wifiSetAutoReconnect(enabled: boolean): void;
190
+ export declare function wifiSetPowerSave(mode: string): void;
191
+ export declare function wifiSetTxPower(dbm: number): void;
192
+ export declare function wifiOnEvent(event: string, handler: string): void;
193
+ export declare function wifiApStart(ssid: string, password?: string, channel?: number, hidden?: boolean, maxClients?: number): boolean;
194
+ export declare function wifiApStop(): void;
195
+ export declare function wifiApClientCount(): number;
196
+ export declare function wifiApIp(): string;
197
+ export declare function wifiApSetChannel(channel: number): void;
198
+ export declare function wifiApSetHidden(hidden: boolean): void;
199
+ export declare function wifiApSetMaxClients(maxClients: number): void;
200
+ export declare function wifiScan(): number;
201
+ export declare function wifiScanStart(): void;
202
+ export declare function wifiScanCount(): number;
203
+ export declare function wifiScanSsid(index: number): string;
204
+ export declare function wifiScanRssi(index: number): number;
205
+ export declare function wifiScanEncryption(index: number): number;
206
+ export declare function wifiScanChannel(index: number): number;
207
+ export declare function wifiSaveCredentials(ssid: string, password: string): void;
208
+ export declare function wifiConnectSaved(timeoutMs?: number): boolean;
209
+ export declare function wifiClearCredentials(): void;
210
+ export declare function wifiWaitConnected(timeoutMs?: number): boolean;
211
+ export declare function wifiWaitDisconnected(): void;
212
+ export declare function httpBegin(method: string, url: string): void;
213
+ export declare function httpReset(): void;
214
+ export declare function httpSetHeader(name: string, value: string): void;
215
+ export declare function httpSetTimeout(ms: number): void;
216
+ export declare function httpSetMaxBody(bytes: number): void;
217
+ export declare function httpSetBody(data: string, json?: boolean): void;
218
+ export declare function httpSetInsecure(): void;
219
+ export declare function httpSetCaCert(pem: string): void;
220
+ export declare function httpSend(): boolean;
221
+ export declare function httpSendStart(): void;
222
+ export declare function httpStatus(): number;
223
+ export declare function httpOk(): boolean;
224
+ export declare function httpBody(): string;
225
+ export declare function httpContentLength(): number;
226
+ export declare function httpResponseHeader(name: string): string;
227
+ export declare function bleServerBegin(name: string): void;
228
+ export declare function bleAdvertiseStart(): void;
229
+ export declare function bleAdvertiseStop(): void;
230
+ export declare function bleAddService(uuid: string): void;
231
+ export declare function bleAddChar(index: number, uuid: string, type: string, perms: number, svcIndex: number): void;
232
+ export declare function bleOnRead(index: number, handler: string): void;
233
+ export declare function bleOnWrite(index: number, handler: string): void;
234
+ export declare function bleOnConnect(handler: string): void;
235
+ export declare function bleOnDisconnect(handler: string): void;
236
+ export declare function bleNotify(index: number, value: number | string): void;
237
+ export declare function bleIsConnected(): boolean;
238
+ export declare function bleClientCount(): number;
239
+ export declare function bleSetName(name: string): void;
240
+ export declare function bleUntilConnected(timeoutMs?: number): boolean;
241
+ export declare function bleUntilConnectedStart(): void;
242
+ export declare function bleSetTxPower(dbm: number): void;
243
+ export declare function bleStatus(): number;
137
244
  /** Emit raw C++ code (escape hatch for unsupported operations). */
138
245
  export declare function rawCpp(code: string): void;
246
+ /**
247
+ * Emit raw C++ in expression context. Use when an IDF macro or constructor
248
+ * must produce a value (e.g. `WIFI_INIT_CONFIG_DEFAULT()` expands to a struct
249
+ * initializer; there's no TS-side way to construct it). The type parameter
250
+ * is purely a TS hint — the transpiler doesn't check it; it just emits the
251
+ * raw text in expression position.
252
+ *
253
+ * const cfg = rawCpp<wifi_init_config_t>('WIFI_INIT_CONFIG_DEFAULT()');
254
+ *
255
+ * lowers to:
256
+ *
257
+ * wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
258
+ */
259
+ export declare function rawCppExpr<T>(code: string): T;
260
+ export {};
package/dist/emit.js CHANGED
@@ -25,6 +25,29 @@ export function gpioSetMode(pin, mode) { }
25
25
  // ---------------------------------------------------------------------------
26
26
  /** Write PWM duty cycle to a pin. */
27
27
  export function pwmWrite(pin, duty) { }
28
+ /** Positional semantic primitive. Args: pin, resolutionHz, bit0Hi, bit0Lo,
29
+ * bit1Hi, bit1Lo, msbFirst, queueDepth. Use rmtTxInit() from hal/rmt.ts. */
30
+ export function rmtTxInit(pin, resolutionHz, bit0Hi, bit0Lo, bit1Hi, bit1Lo, msbFirst, queueDepth) { }
31
+ /** Write bytes via the channel's bytes-encoder (timings fixed at init). */
32
+ export function rmtTxWriteBytes(pin, bytes) { }
33
+ /** Write raw RMT symbols — arbitrary [hiTicks, loTicks] pairs. */
34
+ export function rmtTxWriteSymbols(pin, symbols) { }
35
+ /** Block until the queued TX completes. */
36
+ export function rmtTxWaitDone(pin, timeoutMs) { }
37
+ /** Tear down the TX channel and release its slot. */
38
+ export function rmtTxDeinit(pin) { }
39
+ /** Positional semantic primitive — use rmtRxInit() from hal/rmt.ts. */
40
+ export function rmtRxInit(pin, resolutionHz) { }
41
+ /** Register a callback-by-name invoked when an RX burst completes. */
42
+ export function rmtRxOnReceived(pin, handler) { }
43
+ /** Start receiving. */
44
+ export function rmtRxStart(pin) { }
45
+ /** Stop receiving. */
46
+ export function rmtRxStop(pin) { }
47
+ /** Blocking read — returns flattened symbols [d0,l0,d1,l1,…] in ticks. */
48
+ export function rmtRxRead(pin, maxCount) { return []; }
49
+ /** Tear down the RX channel and release its slot. */
50
+ export function rmtRxDeinit(pin) { }
28
51
  // ---------------------------------------------------------------------------
29
52
  // ADC — analog-to-digital conversion
30
53
  // ---------------------------------------------------------------------------
@@ -187,8 +210,115 @@ export function powerDeepSleep(ms) { }
187
210
  export function powerLightSleep() { }
188
211
  /** Set the CPU frequency (MHz). */
189
212
  export function powerSetCpuFrequency(mhz) { }
213
+ /** Enter deep sleep until `pin` reaches `level` (pin wakeup). Architecture-aware:
214
+ * ext0 on Xtensa (RTC pins), gpio-wakeup on RISC-V. */
215
+ export function powerDeepSleepPin(pin, level) { }
216
+ // ---------------------------------------------------------------------------
217
+ // Preferences (NVS-backed key/value store)
218
+ // ---------------------------------------------------------------------------
219
+ export function preferencesBegin(namespace, readOnly) { }
220
+ export function preferencesEnd() { }
221
+ export function preferencesClear() { }
222
+ export function preferencesRemove(key) { }
223
+ export function preferencesPutInt(key, value) { }
224
+ export function preferencesGetInt(key, defaultValue) { return 0; }
225
+ export function preferencesPutUInt(key, value) { }
226
+ export function preferencesGetUInt(key, defaultValue) { return 0; }
227
+ export function preferencesPutBool(key, value) { }
228
+ export function preferencesGetBool(key, defaultValue) { return false; }
229
+ export function preferencesPutFloat(key, value) { }
230
+ export function preferencesGetFloat(key, defaultValue) { return 0; }
231
+ export function preferencesPutString(key, value) { }
232
+ export function preferencesGetString(key, defaultValue) { return ""; }
233
+ export function wifiConnect(ssid, password, timeoutMs) { return false; }
234
+ export function wifiConnectStart(ssid, password) { }
235
+ export function wifiDisconnect() { }
236
+ export function wifiStatus() { return 0; }
237
+ export function wifiIsConnected() { return false; }
238
+ export function wifiLocalIp() { return ""; }
239
+ export function wifiRssi() { return 0; }
240
+ export function wifiMac() { return ""; }
241
+ export function wifiSetHostname(name) { }
242
+ export function wifiSetStaticIp(ip, gateway, subnet, dns) { }
243
+ export function wifiSetAutoReconnect(enabled) { }
244
+ export function wifiSetPowerSave(mode) { }
245
+ export function wifiSetTxPower(dbm) { }
246
+ export function wifiOnEvent(event, handler) { }
247
+ export function wifiApStart(ssid, password, channel, hidden, maxClients) { return false; }
248
+ export function wifiApStop() { }
249
+ export function wifiApClientCount() { return 0; }
250
+ export function wifiApIp() { return ""; }
251
+ export function wifiApSetChannel(channel) { }
252
+ export function wifiApSetHidden(hidden) { }
253
+ export function wifiApSetMaxClients(maxClients) { }
254
+ export function wifiScan() { return 0; }
255
+ export function wifiScanStart() { }
256
+ export function wifiScanCount() { return 0; }
257
+ export function wifiScanSsid(index) { return ""; }
258
+ export function wifiScanRssi(index) { return 0; }
259
+ export function wifiScanEncryption(index) { return 0; }
260
+ export function wifiScanChannel(index) { return 0; }
261
+ export function wifiSaveCredentials(ssid, password) { }
262
+ export function wifiConnectSaved(timeoutMs) { return false; }
263
+ export function wifiClearCredentials() { }
264
+ export function wifiWaitConnected(timeoutMs) { return false; }
265
+ export function wifiWaitDisconnected() { }
266
+ // ---------------------------------------------------------------------------
267
+ // HTTP client
268
+ // ---------------------------------------------------------------------------
269
+ export function httpBegin(method, url) { }
270
+ export function httpReset() { }
271
+ export function httpSetHeader(name, value) { }
272
+ export function httpSetTimeout(ms) { }
273
+ export function httpSetMaxBody(bytes) { }
274
+ export function httpSetBody(data, json) { }
275
+ export function httpSetInsecure() { }
276
+ export function httpSetCaCert(pem) { }
277
+ export function httpSend() { return false; }
278
+ export function httpSendStart() { }
279
+ export function httpStatus() { return 0; }
280
+ export function httpOk() { return false; }
281
+ export function httpBody() { return ""; }
282
+ export function httpContentLength() { return 0; }
283
+ export function httpResponseHeader(name) { return ""; }
284
+ // ---------------------------------------------------------------------------
285
+ // BLE (NimBLE GATT peripheral)
286
+ // ---------------------------------------------------------------------------
287
+ export function bleServerBegin(name) { }
288
+ export function bleAdvertiseStart() { }
289
+ export function bleAdvertiseStop() { }
290
+ export function bleAddService(uuid) { }
291
+ export function bleAddChar(index, uuid, type, perms, svcIndex) { }
292
+ export function bleOnRead(index, handler) { }
293
+ export function bleOnWrite(index, handler) { }
294
+ export function bleOnConnect(handler) { }
295
+ export function bleOnDisconnect(handler) { }
296
+ export function bleNotify(index, value) { }
297
+ export function bleIsConnected() { return false; }
298
+ export function bleClientCount() { return 0; }
299
+ export function bleSetName(name) { }
300
+ export function bleUntilConnected(timeoutMs) { return false; }
301
+ export function bleUntilConnectedStart() { }
302
+ export function bleSetTxPower(dbm) { }
303
+ export function bleStatus() { return 0; }
190
304
  // ---------------------------------------------------------------------------
191
305
  // Raw C++ escape hatch
192
306
  // ---------------------------------------------------------------------------
193
307
  /** Emit raw C++ code (escape hatch for unsupported operations). */
194
308
  export function rawCpp(code) { }
309
+ /**
310
+ * Emit raw C++ in expression context. Use when an IDF macro or constructor
311
+ * must produce a value (e.g. `WIFI_INIT_CONFIG_DEFAULT()` expands to a struct
312
+ * initializer; there's no TS-side way to construct it). The type parameter
313
+ * is purely a TS hint — the transpiler doesn't check it; it just emits the
314
+ * raw text in expression position.
315
+ *
316
+ * const cfg = rawCpp<wifi_init_config_t>('WIFI_INIT_CONFIG_DEFAULT()');
317
+ *
318
+ * lowers to:
319
+ *
320
+ * wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
321
+ */
322
+ export function rawCppExpr(code) {
323
+ return undefined;
324
+ }
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;