@typecad/hal 1.0.0-alpha.13 → 1.0.0-alpha.15
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 +145 -87
- package/dist/adc-pin.d.ts +53 -0
- package/dist/adc-pin.js +69 -0
- package/dist/async.d.ts +3 -11
- package/dist/async.js +3 -15
- package/dist/ble.d.ts +42 -78
- package/dist/ble.js +79 -98
- package/dist/counter.d.ts +16 -0
- package/dist/counter.js +32 -0
- package/dist/dac-pin.d.ts +13 -0
- package/dist/dac-pin.js +21 -0
- package/dist/emit.d.ts +123 -196
- package/dist/emit.js +146 -208
- package/dist/fs.d.ts +12 -31
- package/dist/fs.js +30 -40
- package/dist/gpio-pin.d.ts +46 -0
- package/dist/gpio-pin.js +77 -0
- package/dist/gpio.d.ts +0 -103
- package/dist/gpio.js +16 -227
- package/dist/http.d.ts +38 -39
- package/dist/http.js +53 -78
- package/dist/i2c-target.d.ts +28 -0
- package/dist/i2c-target.js +52 -0
- package/dist/i2c.d.ts +5 -43
- package/dist/i2c.js +17 -130
- package/dist/index.d.ts +30 -42
- package/dist/index.js +27 -39
- package/dist/math.d.ts +0 -13
- package/dist/math.js +9 -13
- package/dist/mqtt.d.ts +15 -25
- package/dist/mqtt.js +32 -28
- package/dist/power.d.ts +9 -17
- package/dist/power.js +22 -20
- package/dist/preferences.d.ts +17 -25
- package/dist/preferences.js +54 -52
- package/dist/pulse.d.ts +4 -4
- package/dist/pulse.js +6 -2
- package/dist/pwm-pin.d.ts +24 -0
- package/dist/pwm-pin.js +38 -0
- package/dist/random.d.ts +0 -2
- package/dist/random.js +14 -20
- package/dist/sensor-catalog.generated.d.ts +997 -0
- package/dist/sensor-catalog.generated.js +764 -0
- package/dist/sensor.d.ts +46 -0
- package/dist/sensor.js +52 -0
- package/dist/shift-pin.d.ts +2 -0
- package/dist/shift-pin.js +13 -0
- package/dist/spi-target.d.ts +25 -0
- package/dist/spi-target.js +42 -0
- package/dist/spi.d.ts +8 -26
- package/dist/spi.js +15 -87
- package/dist/thread.d.ts +18 -0
- package/dist/thread.js +36 -0
- package/dist/time.d.ts +23 -0
- package/dist/time.js +43 -0
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +17 -7
- package/dist/types.d.ts +4 -34
- package/dist/types.js +5 -47
- package/dist/uart-port.d.ts +26 -0
- package/dist/uart-port.js +52 -0
- package/dist/uart.d.ts +0 -17
- package/dist/uart.js +10 -53
- package/dist/usb.d.ts +26 -0
- package/dist/usb.js +66 -0
- package/dist/watchdog.d.ts +12 -0
- package/dist/watchdog.js +28 -0
- package/dist/wifi.d.ts +88 -64
- package/dist/wifi.js +112 -126
- package/dist/zephyr-tokens.generated.d.ts +8 -0
- package/dist/zephyr-tokens.generated.js +73 -0
- package/package.json +7 -8
- package/src/adc-pin.ts +89 -0
- package/src/async.ts +3 -16
- package/src/ble.ts +84 -111
- package/src/counter.ts +40 -0
- package/src/dac-pin.ts +28 -0
- package/src/emit.ts +157 -238
- package/src/fs.ts +47 -54
- package/src/gpio-pin.ts +91 -0
- package/src/gpio.ts +49 -320
- package/src/http.ts +75 -95
- package/src/i2c-target.ts +63 -0
- package/src/i2c.ts +29 -167
- package/src/index.ts +32 -46
- package/src/math.ts +9 -14
- package/src/mqtt.ts +39 -31
- package/src/preferences.ts +52 -61
- package/src/pwm-pin.ts +54 -0
- package/src/random.ts +14 -21
- package/src/sensor-catalog.generated.ts +1238 -0
- package/src/sensor.ts +80 -0
- package/src/shift-pin.ts +16 -0
- package/src/spi-target.ts +53 -0
- package/src/spi.ts +27 -121
- package/src/thread.ts +44 -0
- package/src/time.ts +50 -0
- package/src/types.ts +14 -89
- package/src/uart-port.ts +64 -0
- package/src/usb.ts +82 -0
- package/src/watchdog.ts +35 -0
- package/src/wifi.ts +147 -179
- package/src/zephyr-tokens.generated.ts +77 -0
- package/src/adc.ts +0 -30
- package/src/capacitive.ts +0 -31
- package/src/constants.ts +0 -23
- package/src/dac.ts +0 -21
- package/src/eeprom.ts +0 -26
- package/src/interrupts.ts +0 -35
- package/src/mdns.ts +0 -50
- package/src/ota.ts +0 -44
- package/src/power.ts +0 -36
- package/src/pulse.ts +0 -63
- package/src/rmt.ts +0 -125
- package/src/shift.ts +0 -88
- package/src/temperature.ts +0 -20
- package/src/timer.ts +0 -58
- package/src/timing.ts +0 -67
- package/src/uart.ts +0 -77
- package/src/utils.ts +0 -17
- package/src/wdt.ts +0 -17
package/dist/ble.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// BLE — the thin Zephyr-shaped GATT peripheral
|
|
3
|
+
//
|
|
4
|
+
// The advertised identity is a CONSTRUCTION fact: `new BLE('TempSensor')`.
|
|
5
|
+
// The GATT database is declared through service()/char() chains (each char's
|
|
6
|
+
// uuid/type/perms ride its add op — the sensor discipline), handlers attach
|
|
7
|
+
// with onRead/onWrite, and the verbs map 1:1 onto Zephyr's bt_* GATT surface:
|
|
8
|
+
//
|
|
9
|
+
// start() → register the deferred service table + bt_enable + advertise
|
|
10
|
+
// stop() → bt_le_adv_stop
|
|
11
|
+
// linked() → a central is connected
|
|
12
|
+
// onConnect()/onDrop() → bt_conn callbacks
|
|
13
|
+
// notify(i, v) → bt_gatt_notify on the declared characteristic i
|
|
14
|
+
//
|
|
15
|
+
// Ordering contract (same as the runtime shim's current_char keying):
|
|
16
|
+
// onRead/onWrite/notify bind to the char() they immediately follow in the
|
|
17
|
+
// chain. Declare handlers right where the characteristic is declared.
|
|
18
|
+
// ----------------------------------------------------------------------------
|
|
19
|
+
import { bleServerBegin, bleAdvertiseStart, bleAdvertiseStop, bleAddService, bleAddChar, bleOnRead, bleOnWrite, bleOnConnect, bleOnDisconnect, bleNotify, bleIsConnected, bleClientCount, } from './emit.js';
|
|
2
20
|
import { callback } from './callback.js';
|
|
3
21
|
/** Characteristic value encoding — drives both TS callback types and C++ marshalling. */
|
|
4
22
|
export var BleValueType;
|
|
@@ -21,24 +39,11 @@ export var BlePerm;
|
|
|
21
39
|
BlePerm[BlePerm["Write"] = 2] = "Write";
|
|
22
40
|
BlePerm[BlePerm["Notify"] = 4] = "Notify";
|
|
23
41
|
})(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
42
|
/**
|
|
39
|
-
* Standard GATT services/characteristics
|
|
40
|
-
*
|
|
41
|
-
*
|
|
43
|
+
* Standard GATT services/characteristics — uuid/type/perms reference data.
|
|
44
|
+
* Pass the pieces explicitly to char():
|
|
45
|
+
* GATT.ENVIRONMENTAL.TEMPERATURE →
|
|
46
|
+
* char('2A6E', BleValueType.Int16, BlePerm.Read | BlePerm.Notify)
|
|
42
47
|
*/
|
|
43
48
|
export const GATT = {
|
|
44
49
|
DEVICE_INFO: {
|
|
@@ -56,102 +61,78 @@ export const GATT = {
|
|
|
56
61
|
},
|
|
57
62
|
};
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
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.
|
|
64
|
+
* The GATT declaration chain returned by BLE.service()/BLE.char(). Each char()
|
|
65
|
+
* appends a characteristic; onRead/onWrite/notify bind to the most recent one.
|
|
69
66
|
*/
|
|
70
|
-
export class
|
|
71
|
-
/** Begin
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
67
|
+
export class BleChain {
|
|
68
|
+
/** Begin a new service grouping; subsequent char() calls attach to it. */
|
|
69
|
+
service(uuid) {
|
|
70
|
+
bleAddService(uuid);
|
|
71
|
+
return this;
|
|
75
72
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
/** Append a characteristic by uuid, value type, and permissions
|
|
74
|
+
* (`BlePerm.Read | BlePerm.Notify`). Returns this for chaining. */
|
|
75
|
+
char(uuid, type, perms) {
|
|
76
|
+
bleAddChar(0, uuid, type, perms, 0);
|
|
77
|
+
return this;
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
/** Read handler for the most recently declared characteristic. */
|
|
80
|
+
onRead(handler) {
|
|
81
|
+
bleOnRead(0, callback(handler));
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/** Write handler for the most recently declared characteristic. */
|
|
85
|
+
onWrite(handler) {
|
|
86
|
+
bleOnWrite(0, callback(handler));
|
|
87
|
+
return this;
|
|
87
88
|
}
|
|
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
89
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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) {
|
|
90
|
+
/** A GATT peripheral. The advertised device name is the construction fact. */
|
|
91
|
+
export class BLE {
|
|
92
|
+
constructor(name) {
|
|
110
93
|
this._name = name;
|
|
111
|
-
this._charCount = charCount;
|
|
112
|
-
this._lastChar = charCount;
|
|
113
|
-
this._svcCount = svcCount;
|
|
114
94
|
}
|
|
115
|
-
/**
|
|
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. */
|
|
95
|
+
/** Begin a service grouping; chain char() declarations off it. */
|
|
123
96
|
service(uuid) {
|
|
124
97
|
bleAddService(uuid);
|
|
125
|
-
return
|
|
98
|
+
return new BleChain();
|
|
126
99
|
}
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
100
|
+
/** Append a characteristic under the default (Environmental Sensing)
|
|
101
|
+
* service — the common single-service case. */
|
|
102
|
+
char(uuid, type, perms) {
|
|
103
|
+
bleAddChar(0, uuid, type, perms, 0);
|
|
104
|
+
return new BleChain();
|
|
131
105
|
}
|
|
132
|
-
/** Register
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
106
|
+
/** Register the declared GATT database, enable the stack, and start
|
|
107
|
+
* advertising the construction name. */
|
|
108
|
+
start() {
|
|
109
|
+
bleServerBegin(this._name);
|
|
110
|
+
bleAdvertiseStart();
|
|
111
|
+
}
|
|
112
|
+
/** Stop advertising (the GATT database and any link stay up). */
|
|
113
|
+
stop() {
|
|
114
|
+
bleAdvertiseStop();
|
|
136
115
|
}
|
|
137
|
-
/**
|
|
116
|
+
/** True while a central is connected. */
|
|
117
|
+
linked() {
|
|
118
|
+
return bleIsConnected();
|
|
119
|
+
}
|
|
120
|
+
/** Number of connected centrals (0 or 1 — the shim is single-connection). */
|
|
121
|
+
clients() {
|
|
122
|
+
return bleClientCount();
|
|
123
|
+
}
|
|
124
|
+
/** Fires when a central connects. */
|
|
138
125
|
onConnect(handler) {
|
|
139
126
|
bleOnConnect(callback(handler));
|
|
140
|
-
return this;
|
|
141
127
|
}
|
|
142
|
-
/**
|
|
143
|
-
|
|
128
|
+
/** Fires when the central disconnects. */
|
|
129
|
+
onDrop(handler) {
|
|
144
130
|
bleOnDisconnect(callback(handler));
|
|
145
|
-
return this;
|
|
146
131
|
}
|
|
147
|
-
/** Push a
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
begin() {
|
|
153
|
-
bleServerBegin(this._name);
|
|
154
|
-
bleAdvertiseStart();
|
|
132
|
+
/** Push a value to subscribed clients on a characteristic
|
|
133
|
+
* (bt_gatt_notify). `index` is the characteristic's declaration order
|
|
134
|
+
* (0-based — the first char() is 0). */
|
|
135
|
+
notify(index, value) {
|
|
136
|
+
bleNotify(index, value);
|
|
155
137
|
}
|
|
156
138
|
}
|
|
157
|
-
export const Ble = new BleClass();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class Counter {
|
|
2
|
+
private readonly _instance;
|
|
3
|
+
private readonly _hz;
|
|
4
|
+
/** Construct a counter handle. `hz` is the alarm frequency — start()
|
|
5
|
+
* realizes it as a top value of counter_freq / hz. */
|
|
6
|
+
constructor(instance: number, opts: {
|
|
7
|
+
hz: number;
|
|
8
|
+
});
|
|
9
|
+
/** Register the alarm handler (fires once per top-value wrap). */
|
|
10
|
+
onAlarm(handler: () => void): void;
|
|
11
|
+
/** Apply hz as the top value, arm the alarm, and start counting
|
|
12
|
+
* (counter_set_top_value + counter_start). */
|
|
13
|
+
start(): void;
|
|
14
|
+
/** Stop counting (counter_stop). */
|
|
15
|
+
stop(): void;
|
|
16
|
+
}
|
package/dist/counter.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Counter — the thin Zephyr-shaped hardware counter/timer
|
|
3
|
+
//
|
|
4
|
+
// Zephyr's counter driver with Zephyr's verbs. The instance index selects
|
|
5
|
+
// one of the chip's declared free counters (instance 0 = the first, e.g.
|
|
6
|
+
// RTC1 on the nRF52840; the build errors name the available ones). The alarm
|
|
7
|
+
// frequency is a construction fact: start() applies hz as the top value
|
|
8
|
+
// (counter_freq / hz) and arms the alarm callback.
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
import { counterOnAlarm, counterStart, counterStop } from './emit.js';
|
|
11
|
+
import { callback } from './callback.js';
|
|
12
|
+
export class Counter {
|
|
13
|
+
/** Construct a counter handle. `hz` is the alarm frequency — start()
|
|
14
|
+
* realizes it as a top value of counter_freq / hz. */
|
|
15
|
+
constructor(instance, opts) {
|
|
16
|
+
this._instance = instance;
|
|
17
|
+
this._hz = opts.hz;
|
|
18
|
+
}
|
|
19
|
+
/** Register the alarm handler (fires once per top-value wrap). */
|
|
20
|
+
onAlarm(handler) {
|
|
21
|
+
counterOnAlarm(this._instance, callback(handler));
|
|
22
|
+
}
|
|
23
|
+
/** Apply hz as the top value, arm the alarm, and start counting
|
|
24
|
+
* (counter_set_top_value + counter_start). */
|
|
25
|
+
start() {
|
|
26
|
+
counterStart(this._instance, this._hz);
|
|
27
|
+
}
|
|
28
|
+
/** Stop counting (counter_stop). */
|
|
29
|
+
stop() {
|
|
30
|
+
counterStop(this._instance);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Pin } from './gpio.js';
|
|
2
|
+
export declare class DAC {
|
|
3
|
+
private readonly _pin;
|
|
4
|
+
private readonly _resolution;
|
|
5
|
+
/** Construct a DAC channel. `resolution` in bits; 0/omitted = the chip
|
|
6
|
+
* descriptor's channel resolution (e.g. 8 on the ESP32's two channels). */
|
|
7
|
+
constructor(pin: number | Pin, opts?: {
|
|
8
|
+
resolution?: number;
|
|
9
|
+
});
|
|
10
|
+
/** Write the raw code (dac_write_value). For an 8-bit channel the range
|
|
11
|
+
* is 0–255; for 12-bit, 0–4095 — the channel's resolution decides. */
|
|
12
|
+
write(value: number): void;
|
|
13
|
+
}
|
package/dist/dac-pin.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// DAC — the thin Zephyr-shaped analog output
|
|
3
|
+
//
|
|
4
|
+
// Construction carries the resolution (default: the chip descriptor's channel
|
|
5
|
+
// resolution); write() lowers to a lazy dac_channel_setup (once) +
|
|
6
|
+
// dac_write_value with the RAW code — no 0–255 Arduino range.
|
|
7
|
+
// ----------------------------------------------------------------------------
|
|
8
|
+
import { dacWriteValue } from './emit.js';
|
|
9
|
+
export class DAC {
|
|
10
|
+
/** Construct a DAC channel. `resolution` in bits; 0/omitted = the chip
|
|
11
|
+
* descriptor's channel resolution (e.g. 8 on the ESP32's two channels). */
|
|
12
|
+
constructor(pin, opts) {
|
|
13
|
+
this._pin = typeof pin === 'number' ? pin : pin.number;
|
|
14
|
+
this._resolution = opts?.resolution ?? 0;
|
|
15
|
+
}
|
|
16
|
+
/** Write the raw code (dac_write_value). For an 8-bit channel the range
|
|
17
|
+
* is 0–255; for 12-bit, 0–4095 — the channel's resolution decides. */
|
|
18
|
+
write(value) {
|
|
19
|
+
dacWriteValue(this._pin, value, this._resolution);
|
|
20
|
+
}
|
|
21
|
+
}
|