@typecad/hal 0.1.0-alpha.2 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- 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 +139 -0
- package/dist/emit.js +152 -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/i2c.d.ts +7 -0
- package/dist/i2c.js +15 -4
- 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/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/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/types.d.ts +1 -1
- 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 +180 -0
- package/src/fs.ts +30 -22
- package/src/http.ts +144 -0
- package/src/i2c.ts +16 -4
- 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/register.ts +16 -4
- package/src/rmt.ts +125 -0
- package/src/spi.ts +10 -7
- package/src/temperature.ts +20 -0
- package/src/timer.ts +22 -23
- package/src/types.ts +1 -0
- package/src/wifi.ts +221 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# `@typecad/hal`
|
|
2
2
|
|
|
3
|
-
Hardware abstraction layer for [TypeCAD](https://
|
|
4
|
-
GPIO, I2C, SPI, UART, timers, ADC/DAC, EEPROM, and more, written as
|
|
5
|
-
TypeScript.
|
|
3
|
+
Hardware abstraction layer for [TypeCAD](https://cuttlefish.typecad.net) —
|
|
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` |
|
|
@@ -77,7 +78,7 @@ For I2C/SPI/UART, instantiate the bus class with the board's pinned instance
|
|
|
77
78
|
|
|
78
79
|
The [`tests/`](./tests/) directory contains a hardware test suite that
|
|
79
80
|
exercises every AVR-compilable HAL subsystem against real Arduino Uno hardware,
|
|
80
|
-
using [`@typecad/expect`](https://
|
|
81
|
+
using [`@typecad/expect`](https://cuttlefish.typecad.net)
|
|
81
82
|
(`describe()` / `.it()` / `.expect()` / `done()`) over serial. Each file covers
|
|
82
83
|
one subsystem: GPIO, timing, math, random, pulse, shift, interrupts, UART,
|
|
83
84
|
I2C, SPI, ADC, EEPROM, WDT, Preferences, async, and constants.
|
|
@@ -92,7 +93,7 @@ npm exec --workspace @typecad/hal -- cuttlefish-test
|
|
|
92
93
|
```
|
|
93
94
|
|
|
94
95
|
The suite is configured by [`cuttlefish.config.ts`](./cuttlefish.config.ts).
|
|
95
|
-
Like the [`@typecad/framework-arduino`](https://
|
|
96
|
+
Like the [`@typecad/framework-arduino`](https://cuttlefish.typecad.net)
|
|
96
97
|
tests, it imports through `@typecad/board` (the board package) and ambient globals
|
|
97
98
|
declared in `cuttlefish-env.d.ts`, never directly from `@typecad/board`, so the
|
|
98
99
|
transpiler resolves each call against the active MCU/board packages.
|
|
@@ -117,8 +118,8 @@ entirely — they require an ESP32 target.
|
|
|
117
118
|
|
|
118
119
|
## Ecosystem
|
|
119
120
|
|
|
120
|
-
- [`@typecad/cuttlefish`](https://
|
|
121
|
-
- [`@typecad/ui`](https://
|
|
121
|
+
- [`@typecad/cuttlefish`](https://cuttlefish.typecad.net) — the transpiler that resolves HAL calls to C++.
|
|
122
|
+
- [`@typecad/ui`](https://cuttlefish.typecad.net) — HTML/CSS-driven display graphics.
|
|
122
123
|
- `@typecad/mcu-*` — silicon pin/port/peripheral definitions.
|
|
123
124
|
- `@typecad/board-*` — board-level pin mappings and bus aliases.
|
|
124
125
|
|
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();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CapacitiveClass — ESP32 on-chip capacitive touch pins.
|
|
3
|
+
*
|
|
4
|
+
* ESP32-family chips have dedicated capacitive-sensing GPIOs (10 on classic
|
|
5
|
+
* ESP32, up to 14 on S3) that read touch/proximity without external
|
|
6
|
+
* components — distinct from the I2C/SPI touch *display* controllers (FT6336U,
|
|
7
|
+
* GT911, etc.). Lowered to capacitive.* HAL ops: ESP-IDF's touch_sensor driver.
|
|
8
|
+
*
|
|
9
|
+
* Pin numbers are the touch-pad-capable GPIOs (GPIO4, GPIO0, GPIO2, ... on
|
|
10
|
+
* classic ESP32); the framework maps them to touch_channel indices.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CapacitiveClass {
|
|
13
|
+
static readonly __instance_name = "Capacitive";
|
|
14
|
+
/** Read the raw capacitive value of a touch pin. Higher = more capacitance
|
|
15
|
+
* (touched). The raw scale is chip-dependent; use a threshold calibrated
|
|
16
|
+
* against the untouched reading. */
|
|
17
|
+
read(pin: number): number;
|
|
18
|
+
/** True when the pin's reading exceeds `threshold` (a convenience over read()). */
|
|
19
|
+
isTouched(pin: number, threshold: number): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const Capacitive: CapacitiveClass;
|
|
22
|
+
export declare function capacitiveRead(pin: number): number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CapacitiveClass — ESP32 on-chip capacitive touch pins.
|
|
3
|
+
*
|
|
4
|
+
* ESP32-family chips have dedicated capacitive-sensing GPIOs (10 on classic
|
|
5
|
+
* ESP32, up to 14 on S3) that read touch/proximity without external
|
|
6
|
+
* components — distinct from the I2C/SPI touch *display* controllers (FT6336U,
|
|
7
|
+
* GT911, etc.). Lowered to capacitive.* HAL ops: ESP-IDF's touch_sensor driver.
|
|
8
|
+
*
|
|
9
|
+
* Pin numbers are the touch-pad-capable GPIOs (GPIO4, GPIO0, GPIO2, ... on
|
|
10
|
+
* classic ESP32); the framework maps them to touch_channel indices.
|
|
11
|
+
*/
|
|
12
|
+
export class CapacitiveClass {
|
|
13
|
+
/** Read the raw capacitive value of a touch pin. Higher = more capacitance
|
|
14
|
+
* (touched). The raw scale is chip-dependent; use a threshold calibrated
|
|
15
|
+
* against the untouched reading. */
|
|
16
|
+
read(pin) {
|
|
17
|
+
return capacitiveRead(pin);
|
|
18
|
+
}
|
|
19
|
+
/** True when the pin's reading exceeds `threshold` (a convenience over read()). */
|
|
20
|
+
isTouched(pin, threshold) {
|
|
21
|
+
return capacitiveRead(pin) > threshold;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
CapacitiveClass.__instance_name = "Capacitive";
|
|
25
|
+
export const Capacitive = new CapacitiveClass();
|
|
26
|
+
// ── Semantic primitive (resolved to capacitive.* HAL op by the transpiler) ──
|
|
27
|
+
export function capacitiveRead(pin) { return 0; }
|
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). */
|
|
@@ -53,6 +78,15 @@ export declare function i2cRequestFrom(bus: string, address: number, quantity: n
|
|
|
53
78
|
export declare function i2cAvailable(bus: string): number;
|
|
54
79
|
/** Read a byte from I2C. */
|
|
55
80
|
export declare function i2cRead(bus: string): number;
|
|
81
|
+
/**
|
|
82
|
+
* Drain `count` bytes requested from the I2C bus into a caller-provided buffer.
|
|
83
|
+
* Semantic primitive: lowers to the `i2c.read_buffer` HAL op. The `buffer`
|
|
84
|
+
* argument is emitted as a placeholder (`__HAL_READ_BUF__`) that the var-init
|
|
85
|
+
* transformer rewrites to the caller's own buffer variable, so bytes land in
|
|
86
|
+
* the `uint8_t data[N]` declared in user scope — NOT an internal temp that
|
|
87
|
+
* decays to a pointer on return. Keeps `data.length` / `data[i]` valid.
|
|
88
|
+
*/
|
|
89
|
+
export declare function i2cReadBuffer(bus: string, count: number, buffer: number[] | Uint8Array): void;
|
|
56
90
|
/** Initialize SPI bus. */
|
|
57
91
|
export declare function spiBegin(bus: string): void;
|
|
58
92
|
/** Disable SPI bus. */
|
|
@@ -67,6 +101,14 @@ export declare function spiEndTx(bus: string): void;
|
|
|
67
101
|
export declare function spiCsLow(pin: number | string): void;
|
|
68
102
|
/** Set SPI chip-select pin HIGH. */
|
|
69
103
|
export declare function spiCsHigh(pin: number | string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Read `count` bytes from the SPI bus into a caller-provided buffer by clocking
|
|
106
|
+
* dummy (0x00) transfers. Semantic primitive: lowers to the `spi.read_buffer`
|
|
107
|
+
* HAL op (per-byte `bus.transfer(0)` read loop). The `buffer` placeholder is
|
|
108
|
+
* rewritten to the caller's variable. Mirrors i2cReadBuffer. The caller is
|
|
109
|
+
* responsible for asserting/de-asserting chip-select around it.
|
|
110
|
+
*/
|
|
111
|
+
export declare function spiReadBuffer(bus: string, count: number, buffer: number[] | Uint8Array): void;
|
|
70
112
|
/** Set SPI data mode. */
|
|
71
113
|
export declare function spiSetMode(bus: string, mode: number): void;
|
|
72
114
|
/** Set SPI bit order. */
|
|
@@ -117,5 +159,102 @@ export declare function powerDeepSleep(ms: number): void;
|
|
|
117
159
|
export declare function powerLightSleep(): void;
|
|
118
160
|
/** Set the CPU frequency (MHz). */
|
|
119
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;
|
|
120
244
|
/** Emit raw C++ code (escape hatch for unsupported operations). */
|
|
121
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 {};
|