@typecad/hal 1.0.0-alpha.14 → 1.0.0-alpha.16
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 +6 -7
- 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/http.js
CHANGED
|
@@ -1,65 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Request — the thin HTTP/S client
|
|
3
|
+
//
|
|
4
|
+
// The request is CONSTRUCTION facts: method, URL, and the policy opts
|
|
5
|
+
// (timeout, body, TLS mode) ride the constructor; headers attach with the
|
|
6
|
+
// header() chain; send() lowers the facts into the shim and performs the
|
|
7
|
+
// request; the response is read from this request afterwards (the shim
|
|
8
|
+
// holds the response until the next request).
|
|
9
|
+
//
|
|
10
|
+
// const req = new Request(Request.POST, url, {
|
|
11
|
+
// timeoutMs: 10_000,
|
|
12
|
+
// body: '{"v":1}', json: true,
|
|
13
|
+
// caCert: PEM, // pin a CA (verified TLS)
|
|
14
|
+
// });
|
|
15
|
+
// req.header('X-Custom', 'v');
|
|
16
|
+
// if (req.send()) { console.log(req.status()); }
|
|
17
|
+
//
|
|
18
|
+
// Method tokens: Request.GET / POST / PUT / DELETE / HEAD / PATCH (plain
|
|
19
|
+
// 'GET' strings also accepted). `insecure: true` skips TLS certificate
|
|
20
|
+
// verification (development only). Awaiting send() inside async functions
|
|
21
|
+
// still splits into a background request + done-poll (the async machinery
|
|
22
|
+
// intercepts the send op; the facts were already lowered at send()).
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
import { httpBegin, httpSetHeader, httpSetTimeout, httpSetBody, httpSetInsecure, httpSetCaCert, httpSend, httpStatus, httpOk, httpBody, httpContentLength, httpResponseHeader, } from './emit.js';
|
|
25
|
+
export class Request {
|
|
26
|
+
constructor(method, url, opts = {}) {
|
|
27
|
+
this._method = method.toUpperCase();
|
|
23
28
|
this._url = url;
|
|
29
|
+
this._timeoutMs = opts.timeoutMs ?? 10_000;
|
|
30
|
+
this._body = opts.body ?? '';
|
|
31
|
+
this._json = opts.json === true;
|
|
32
|
+
this._insecure = opts.insecure === true;
|
|
33
|
+
this._caCert = opts.caCert ?? '';
|
|
24
34
|
}
|
|
35
|
+
/** Attach a request header. Chainable — one per header. */
|
|
25
36
|
header(name, value) {
|
|
26
37
|
httpSetHeader(name, value);
|
|
27
38
|
return this;
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
maxBody(bytes) {
|
|
34
|
-
httpSetMaxBody(bytes);
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
body(data) {
|
|
38
|
-
httpSetBody(data, false);
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
jsonBody(json) {
|
|
42
|
-
httpSetBody(json, true);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
/** Skip TLS certificate verification (development only). */
|
|
46
|
-
insecure() {
|
|
47
|
-
httpSetInsecure();
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
caCert(pem) {
|
|
51
|
-
httpSetCaCert(pem);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
/** Blocking at top level; cooperatively awaitable inside async functions. */
|
|
40
|
+
/** Send the request (blocking). The construction facts lower into the
|
|
41
|
+
* shim first (timeout/body/TLS mode), then the request performs.
|
|
42
|
+
* Awaitable inside async functions — the async machinery splits the
|
|
43
|
+
* send into a background request + done-poll. */
|
|
55
44
|
send() {
|
|
45
|
+
httpSetTimeout(this._timeoutMs);
|
|
46
|
+
httpSetBody(this._body, this._json);
|
|
47
|
+
httpSetInsecure(this._insecure);
|
|
48
|
+
httpSetCaCert(this._caCert);
|
|
56
49
|
httpBegin(this._method, this._url);
|
|
57
|
-
httpSend();
|
|
58
|
-
return Promise.resolve(false);
|
|
50
|
+
return httpSend();
|
|
59
51
|
}
|
|
52
|
+
/** Response status code (0 before a completed send). */
|
|
60
53
|
status() {
|
|
61
54
|
return httpStatus();
|
|
62
55
|
}
|
|
56
|
+
/** True when the response status is 2xx. */
|
|
63
57
|
ok() {
|
|
64
58
|
return httpOk();
|
|
65
59
|
}
|
|
@@ -67,38 +61,19 @@ export class HttpRequest {
|
|
|
67
61
|
text() {
|
|
68
62
|
return httpBody();
|
|
69
63
|
}
|
|
64
|
+
/** Response Content-Length (0 when absent). */
|
|
70
65
|
contentLength() {
|
|
71
66
|
return httpContentLength();
|
|
72
67
|
}
|
|
68
|
+
/** One response header value ("" when absent; valid until the next
|
|
69
|
+
* request). */
|
|
73
70
|
responseHeader(name) {
|
|
74
71
|
return httpResponseHeader(name);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
httpReset();
|
|
84
|
-
return new HttpRequest("POST", url);
|
|
85
|
-
}
|
|
86
|
-
put(url) {
|
|
87
|
-
httpReset();
|
|
88
|
-
return new HttpRequest("PUT", url);
|
|
89
|
-
}
|
|
90
|
-
del(url) {
|
|
91
|
-
httpReset();
|
|
92
|
-
return new HttpRequest("DELETE", url);
|
|
93
|
-
}
|
|
94
|
-
head(url) {
|
|
95
|
-
httpReset();
|
|
96
|
-
return new HttpRequest("HEAD", url);
|
|
97
|
-
}
|
|
98
|
-
patch(url) {
|
|
99
|
-
httpReset();
|
|
100
|
-
return new HttpRequest("PATCH", url);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
HttpClass.__instance_name = "Http";
|
|
104
|
-
export const Http = new HttpClass();
|
|
74
|
+
Request.GET = 'GET';
|
|
75
|
+
Request.POST = 'POST';
|
|
76
|
+
Request.PUT = 'PUT';
|
|
77
|
+
Request.DELETE = 'DELETE';
|
|
78
|
+
Request.HEAD = 'HEAD';
|
|
79
|
+
Request.PATCH = 'PATCH';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class I2CTarget {
|
|
2
|
+
private readonly _bus;
|
|
3
|
+
private readonly _address;
|
|
4
|
+
private readonly _hz;
|
|
5
|
+
/** Construct a device handle. `bus` is the bus instance (I2C0, I2C1, …);
|
|
6
|
+
* `address` is the 7-bit I2C address; `hz` optionally sets the bus speed
|
|
7
|
+
* once at first use (100k/400k/1M map to Zephyr's I2C_SPEED_* tiers). */
|
|
8
|
+
constructor(bus: string, address: number, opts?: {
|
|
9
|
+
hz?: number;
|
|
10
|
+
});
|
|
11
|
+
/** Write one register byte (i2c_reg_write_byte). */
|
|
12
|
+
writeReg(reg: number, value: number): void;
|
|
13
|
+
/** Read one register byte (i2c_reg_read_byte). */
|
|
14
|
+
readReg(reg: number): number;
|
|
15
|
+
/** Read-modify-write one register field (i2c_reg_update_byte): the bits in
|
|
16
|
+
* `mask` are replaced by `value`. Atomic on the wire — no read-back race. */
|
|
17
|
+
updateReg(reg: number, mask: number, value: number): void;
|
|
18
|
+
/** Write raw bytes (i2c_write) — commands and data with no register
|
|
19
|
+
* convention. */
|
|
20
|
+
write(data: number[] | Uint8Array): void;
|
|
21
|
+
/** The 7-bit I2C address this target addresses. Exposed so I2CTarget
|
|
22
|
+
* structurally satisfies the @typecad/simulator II2CDeviceAccessor
|
|
23
|
+
* contract (`readonly address`), letting the same driver function be
|
|
24
|
+
* typed against the contract and accept either a real board device or a
|
|
25
|
+
* simulated one. The transpiler strips HAL class bodies to IR, so this
|
|
26
|
+
* getter carries no runtime cost in the generated C++. */
|
|
27
|
+
get address(): number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// I2CTarget — the thin Zephyr-shaped I2C device
|
|
3
|
+
//
|
|
4
|
+
// One address on a bus, Zephyr's register verbs verbatim: writeReg/readReg
|
|
5
|
+
// are i2c_reg_write_byte / i2c_reg_read_byte, updateReg is the native
|
|
6
|
+
// read-modify-write (i2c_reg_update_byte — mask and all, no read-back race),
|
|
7
|
+
// and write() is i2c_write. No begin/end transaction dance, no Wire
|
|
8
|
+
// vocabulary — the controller device handle and the per-call address are all
|
|
9
|
+
// Zephyr needs.
|
|
10
|
+
//
|
|
11
|
+
// `bus` is the board's bus instance export (I2C0/I2C1); the address is the
|
|
12
|
+
// 7-bit form (0x44). The optional bus `hz` applies once (i2c_configure,
|
|
13
|
+
// guarded) — Zephyr's own I2C_SPEED_SET mapping.
|
|
14
|
+
// ----------------------------------------------------------------------------
|
|
15
|
+
import { i2cRegWrite, i2cRegRead, i2cRegUpdate, i2cDevWrite } from './emit.js';
|
|
16
|
+
export class I2CTarget {
|
|
17
|
+
/** Construct a device handle. `bus` is the bus instance (I2C0, I2C1, …);
|
|
18
|
+
* `address` is the 7-bit I2C address; `hz` optionally sets the bus speed
|
|
19
|
+
* once at first use (100k/400k/1M map to Zephyr's I2C_SPEED_* tiers). */
|
|
20
|
+
constructor(bus, address, opts) {
|
|
21
|
+
this._bus = bus;
|
|
22
|
+
this._address = address;
|
|
23
|
+
this._hz = opts?.hz ?? 0;
|
|
24
|
+
}
|
|
25
|
+
/** Write one register byte (i2c_reg_write_byte). */
|
|
26
|
+
writeReg(reg, value) {
|
|
27
|
+
i2cRegWrite(this._bus, this._address, this._hz, reg, value);
|
|
28
|
+
}
|
|
29
|
+
/** Read one register byte (i2c_reg_read_byte). */
|
|
30
|
+
readReg(reg) {
|
|
31
|
+
return i2cRegRead(this._bus, this._address, this._hz, reg);
|
|
32
|
+
}
|
|
33
|
+
/** Read-modify-write one register field (i2c_reg_update_byte): the bits in
|
|
34
|
+
* `mask` are replaced by `value`. Atomic on the wire — no read-back race. */
|
|
35
|
+
updateReg(reg, mask, value) {
|
|
36
|
+
i2cRegUpdate(this._bus, this._address, this._hz, reg, mask, value);
|
|
37
|
+
}
|
|
38
|
+
/** Write raw bytes (i2c_write) — commands and data with no register
|
|
39
|
+
* convention. */
|
|
40
|
+
write(data) {
|
|
41
|
+
i2cDevWrite(this._bus, this._address, this._hz, data);
|
|
42
|
+
}
|
|
43
|
+
/** The 7-bit I2C address this target addresses. Exposed so I2CTarget
|
|
44
|
+
* structurally satisfies the @typecad/simulator II2CDeviceAccessor
|
|
45
|
+
* contract (`readonly address`), letting the same driver function be
|
|
46
|
+
* typed against the contract and accept either a real board device or a
|
|
47
|
+
* simulated one. The transpiler strips HAL class bodies to IR, so this
|
|
48
|
+
* getter carries no runtime cost in the generated C++. */
|
|
49
|
+
get address() {
|
|
50
|
+
return this._address;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/dist/i2c.d.ts
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
private _bus;
|
|
3
|
-
private _address;
|
|
4
|
-
constructor(bus: string, address: number);
|
|
5
|
-
/** The 7-bit I2C address this accessor targets. Exposed so I2CDevice
|
|
6
|
-
* structurally satisfies the @typecad/simulator II2CDeviceAccessor contract
|
|
7
|
-
* (which declares `readonly address`), letting the same driver function be
|
|
8
|
-
* typed against the contract and accept either a real board device or a
|
|
9
|
-
* simulated one. The transpiler strips HAL class bodies to IR, so this
|
|
10
|
-
* getter carries no runtime cost in the generated C++. */
|
|
11
|
-
get address(): number;
|
|
12
|
-
writeByte(register: number, value: number): void;
|
|
13
|
-
readByte(register: number): number;
|
|
14
|
-
writeBytes(register: number, data: number[] | Uint8Array): void;
|
|
15
|
-
readBytes(register: number, count: number): Uint8Array;
|
|
16
|
-
}
|
|
1
|
+
import { I2CTarget } from './i2c-target.js';
|
|
17
2
|
export declare class I2CBus {
|
|
18
|
-
static readonly __includes: string[];
|
|
19
3
|
private _bus;
|
|
20
4
|
constructor(bus: string);
|
|
21
|
-
device
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setClock(hz: number): void;
|
|
26
|
-
/** Recover a locked I2C bus by clocking SCL until the stuck slave releases SDA.
|
|
27
|
-
*
|
|
28
|
-
* NOTE: This references the board-defined `SCL` pin macro. All current MCU
|
|
29
|
-
* packages (atmega328p, esp32, esp32c3, esp32c6, esp32s3) export SCL, so
|
|
30
|
-
* this works in practice. A fully portable version would resolve the SCL
|
|
31
|
-
* pin number via a board constant (e.g. peripherals.i2c.0.sclPin), but that
|
|
32
|
-
* requires adding resolved numeric pin fields to the board-constants
|
|
33
|
-
* pipeline — deferred for now. */
|
|
34
|
-
recover(): void;
|
|
35
|
-
take(): this | null;
|
|
36
|
-
release(): void;
|
|
37
|
-
writeByte(address: number, register: number, value: number): void;
|
|
38
|
-
readByte(address: number, register: number): number;
|
|
39
|
-
beginTransmission(address: number): void;
|
|
40
|
-
write(data: number | number[] | Uint8Array): void;
|
|
41
|
-
endTransmission(stop?: boolean): number;
|
|
42
|
-
requestFrom(address: number, quantity: number, stop?: boolean): number;
|
|
43
|
-
available(): number;
|
|
44
|
-
read(): number;
|
|
5
|
+
/** The functional device target at `address` on this controller —
|
|
6
|
+
* register verbs callable directly, and the fact-carrier `new Sensor(...)`
|
|
7
|
+
* accepts. Equivalent to `new I2CTarget(this, address)`. */
|
|
8
|
+
device(address: number): I2CTarget;
|
|
45
9
|
}
|
|
46
|
-
/** Map TypeCAD I2C instance number to Arduino C++ object name. I2C0→Wire, I2C1→Wire1 */
|
|
47
|
-
export declare function i2cName(instance: number): string;
|
package/dist/i2c.js
CHANGED
|
@@ -1,137 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
get address() {
|
|
15
|
-
return this._address;
|
|
16
|
-
}
|
|
17
|
-
writeByte(register, value) {
|
|
18
|
-
include("<Wire.h>");
|
|
19
|
-
i2cBeginTx(this._bus, this._address);
|
|
20
|
-
i2cWrite(this._bus, register);
|
|
21
|
-
i2cWrite(this._bus, value);
|
|
22
|
-
i2cEndTx(this._bus, true);
|
|
23
|
-
}
|
|
24
|
-
readByte(register) {
|
|
25
|
-
include("<Wire.h>");
|
|
26
|
-
i2cBeginTx(this._bus, this._address);
|
|
27
|
-
i2cWrite(this._bus, register);
|
|
28
|
-
i2cEndTx(this._bus, false);
|
|
29
|
-
i2cRequestFrom(this._bus, this._address, 1);
|
|
30
|
-
return i2cRead(this._bus);
|
|
31
|
-
}
|
|
32
|
-
writeBytes(register, data) {
|
|
33
|
-
include("<Wire.h>");
|
|
34
|
-
i2cBeginTx(this._bus, this._address);
|
|
35
|
-
i2cWrite(this._bus, register);
|
|
36
|
-
i2cWriteBuffer(this._bus, data);
|
|
37
|
-
i2cEndTx(this._bus, true);
|
|
38
|
-
}
|
|
39
|
-
readBytes(register, count) {
|
|
40
|
-
include("<Wire.h>");
|
|
41
|
-
i2cBeginTx(this._bus, this._address);
|
|
42
|
-
i2cWrite(this._bus, register);
|
|
43
|
-
i2cEndTx(this._bus, false);
|
|
44
|
-
i2cRequestFrom(this._bus, this._address, count, true);
|
|
45
|
-
// Drain the requested bytes into the caller's buffer (declared by the
|
|
46
|
-
// Uint8Array return marker as `uint8_t data[count]`). Using the semantic
|
|
47
|
-
// primitive — NOT rawCpp — keeps the buffer in user scope so it survives
|
|
48
|
-
// the return (no decayed pointer) and `data.length` / `data[i]` work.
|
|
49
|
-
i2cReadBuffer(this._bus, count, new Uint8Array(count));
|
|
50
|
-
return new Uint8Array(count);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// I2C — controller selector (legacy Wire API removed)
|
|
3
|
+
//
|
|
4
|
+
// The bus singletons (I2C0/I2C1…) are CONTROLLER SELECTORS; device(address)
|
|
5
|
+
// hands back the FUNCTIONAL I2CTarget directly — register verbs callable with
|
|
6
|
+
// no further construction (`I2C0.device(0x44).writeReg(...)`) and the same
|
|
7
|
+
// fact-carrier `new Sensor(SENSOR.x, I2C0.device(0x44))` consumes. Explicit
|
|
8
|
+
// construction `new I2CTarget(I2C0, 0x44)` is equivalent. The former
|
|
9
|
+
// begin/endTransmission/requestFrom Wire reconstruction was removed with the
|
|
10
|
+
// legacy Arduino surface; the standalone I2CDevice fact-carrier was absorbed
|
|
11
|
+
// by I2CTarget (same facts, plus the verbs).
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
import { I2CTarget } from './i2c-target.js';
|
|
53
14
|
export class I2CBus {
|
|
54
15
|
constructor(bus) {
|
|
55
16
|
this._bus = bus;
|
|
56
17
|
}
|
|
18
|
+
/** The functional device target at `address` on this controller —
|
|
19
|
+
* register verbs callable directly, and the fact-carrier `new Sensor(...)`
|
|
20
|
+
* accepts. Equivalent to `new I2CTarget(this, address)`. */
|
|
57
21
|
device(address) {
|
|
58
|
-
return new
|
|
59
|
-
}
|
|
60
|
-
begin() {
|
|
61
|
-
include("<Wire.h>");
|
|
62
|
-
i2cBegin(this._bus);
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
beginSlave(address) {
|
|
66
|
-
i2cBegin(this._bus, address);
|
|
67
|
-
}
|
|
68
|
-
end() {
|
|
69
|
-
i2cEnd(this._bus);
|
|
70
|
-
}
|
|
71
|
-
setClock(hz) {
|
|
72
|
-
i2cSetClock(this._bus, hz);
|
|
22
|
+
return new I2CTarget(this._bus, address);
|
|
73
23
|
}
|
|
74
|
-
/** Recover a locked I2C bus by clocking SCL until the stuck slave releases SDA.
|
|
75
|
-
*
|
|
76
|
-
* NOTE: This references the board-defined `SCL` pin macro. All current MCU
|
|
77
|
-
* packages (atmega328p, esp32, esp32c3, esp32c6, esp32s3) export SCL, so
|
|
78
|
-
* this works in practice. A fully portable version would resolve the SCL
|
|
79
|
-
* pin number via a board constant (e.g. peripherals.i2c.0.sclPin), but that
|
|
80
|
-
* requires adding resolved numeric pin fields to the board-constants
|
|
81
|
-
* pipeline — deferred for now. */
|
|
82
|
-
recover() {
|
|
83
|
-
include("<Wire.h>");
|
|
84
|
-
rawCpp(`pinMode(SCL, OUTPUT);`);
|
|
85
|
-
rawCpp(`for (int i = 0; i < 16; i++) {`);
|
|
86
|
-
rawCpp(` digitalWrite(SCL, LOW);`);
|
|
87
|
-
rawCpp(` delayMicroseconds(10);`);
|
|
88
|
-
rawCpp(` digitalWrite(SCL, HIGH);`);
|
|
89
|
-
rawCpp(` delayMicroseconds(10);`);
|
|
90
|
-
rawCpp(`}`);
|
|
91
|
-
rawCpp(`${this._bus}.begin();`);
|
|
92
|
-
}
|
|
93
|
-
take() {
|
|
94
|
-
include("<Wire.h>");
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
release() {
|
|
98
|
-
// No-op for standard Arduino.
|
|
99
|
-
}
|
|
100
|
-
writeByte(address, register, value) {
|
|
101
|
-
i2cBeginTx(this._bus, address);
|
|
102
|
-
i2cWrite(this._bus, register);
|
|
103
|
-
i2cWrite(this._bus, value);
|
|
104
|
-
i2cEndTx(this._bus, true);
|
|
105
|
-
}
|
|
106
|
-
readByte(address, register) {
|
|
107
|
-
i2cBeginTx(this._bus, address);
|
|
108
|
-
i2cWrite(this._bus, register);
|
|
109
|
-
i2cEndTx(this._bus, false);
|
|
110
|
-
i2cRequestFrom(this._bus, address, 1);
|
|
111
|
-
return i2cRead(this._bus);
|
|
112
|
-
}
|
|
113
|
-
// Low-level Wire API pass-through methods
|
|
114
|
-
beginTransmission(address) {
|
|
115
|
-
i2cBeginTx(this._bus, address);
|
|
116
|
-
}
|
|
117
|
-
write(data) {
|
|
118
|
-
i2cWrite(this._bus, data);
|
|
119
|
-
}
|
|
120
|
-
endTransmission(stop) {
|
|
121
|
-
return i2cEndTx(this._bus, stop ?? true);
|
|
122
|
-
}
|
|
123
|
-
requestFrom(address, quantity, stop) {
|
|
124
|
-
return i2cRequestFrom(this._bus, address, quantity, stop ?? true);
|
|
125
|
-
}
|
|
126
|
-
available() {
|
|
127
|
-
return i2cAvailable(this._bus);
|
|
128
|
-
}
|
|
129
|
-
read() {
|
|
130
|
-
return i2cRead(this._bus);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
I2CBus.__includes = ["<Wire.h>"];
|
|
134
|
-
/** Map TypeCAD I2C instance number to Arduino C++ object name. I2C0→Wire, I2C1→Wire1 */
|
|
135
|
-
export function i2cName(instance) {
|
|
136
|
-
return instance === 0 ? "Wire" : `Wire${instance}`;
|
|
137
24
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,42 @@
|
|
|
1
1
|
export type { DigitalValue, AnalogValue } from './types.js';
|
|
2
|
-
export { PinMode
|
|
3
|
-
export type { IPinGroup, PinGroupMember } from './types.js';
|
|
4
|
-
export { createPinGroup } from './types.js';
|
|
2
|
+
export { PinMode } from './types.js';
|
|
5
3
|
export type { InterruptHandler } from './types.js';
|
|
6
4
|
export type { ArchitectureIdentifier } from './types.js';
|
|
7
|
-
export type {
|
|
8
|
-
export type { SPIBitOrder, SPIMode, SPISettings } from './types.js';
|
|
5
|
+
export type { SerialValue } from './types.js';
|
|
9
6
|
export { include } from './include.js';
|
|
10
7
|
export { board } from './board.js';
|
|
11
8
|
export { callback } from './callback.js';
|
|
12
9
|
export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
|
|
16
|
-
export { abs, min, max, NumClass, Num, MapChain, ConstrainChain } from './math.js';
|
|
17
|
-
export { Pulse, pulseIn, pulseInLong } from './pulse.js';
|
|
18
|
-
export { Shift, shiftIn, shiftOut } from './shift.js';
|
|
10
|
+
export { TimeClass, Time } from './time.js';
|
|
11
|
+
export { abs, min, max, NumClass, Num } from './math.js';
|
|
19
12
|
export { Random } from './random.js';
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
13
|
+
export { Pin } from './gpio.js';
|
|
14
|
+
export { GPIO } from './gpio-pin.js';
|
|
15
|
+
export { shiftOut, shiftIn } from './shift-pin.js';
|
|
16
|
+
export { PWM } from './pwm-pin.js';
|
|
17
|
+
export { ADC } from './adc-pin.js';
|
|
18
|
+
export { DAC } from './dac-pin.js';
|
|
19
|
+
export { Watchdog } from './watchdog.js';
|
|
20
|
+
export { Counter } from './counter.js';
|
|
21
|
+
export { I2CTarget } from './i2c-target.js';
|
|
22
|
+
export { SPITarget } from './spi-target.js';
|
|
23
|
+
export { UART } from './uart-port.js';
|
|
24
|
+
export { Thread } from './thread.js';
|
|
25
|
+
export { I2CBus } from './i2c.js';
|
|
26
|
+
export { Sensor } from './sensor.js';
|
|
27
|
+
export { SENSOR, CHAN, SENSOR_PART_INFO } from './sensor-catalog.generated.js';
|
|
28
|
+
export { ZEPHYR_ADC_GAINS, ZEPHYR_ADC_REFERENCES, ZEPHYR_GPIO_FLAGS, ZEPHYR_GPIO_INTS } from './zephyr-tokens.generated.js';
|
|
29
|
+
export type { SensorToken, SensorChannelName, SensorPartInfo } from './sensor-catalog.generated.js';
|
|
30
|
+
export { SPIBus } from './spi.js';
|
|
31
|
+
export { USBConsole } from './usb.js';
|
|
27
32
|
export type { Bit, Bits } from './register.js';
|
|
28
33
|
export { register, bits } from './register.js';
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export { DACClass, DAC } from './dac.js';
|
|
33
|
-
export { PreferencesClass, Preferences } from './preferences.js';
|
|
34
|
-
export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
|
|
35
|
-
export { FSClass, FS } from './fs.js';
|
|
36
|
-
export { fsBegin, fsReadText, fsWriteText, fsExists, fsRemove } from './fs.js';
|
|
37
|
-
export { MdnsClass, MDNS } from './mdns.js';
|
|
38
|
-
export { mdnsStart, mdnsSetHostname, mdnsAddService, mdnsAnnounce, mdnsStop } from './mdns.js';
|
|
39
|
-
export { MqttClass, MQTT } from './mqtt.js';
|
|
40
|
-
export { mqttConnect, mqttOnMessage, mqttSubscribe, mqttPublish, mqttConnected, mqttDisconnect } from './mqtt.js';
|
|
41
|
-
export { OtaClass, OTA } from './ota.js';
|
|
42
|
-
export { otaFromUrl, otaBegin, otaWrite, otaApply } from './ota.js';
|
|
43
|
-
export { TemperatureClass, Temperature } from './temperature.js';
|
|
44
|
-
export { tempRead } from './temperature.js';
|
|
45
|
-
export { hwtimerSetFrequency, hwtimerOnOverflow, hwtimerStart, hwtimerStop } from './timer.js';
|
|
46
|
-
export { CapacitiveClass, Capacitive } from './capacitive.js';
|
|
47
|
-
export { capacitiveRead } from './capacitive.js';
|
|
48
|
-
export { PowerClass, Power } from './power.js';
|
|
34
|
+
export { Store } from './preferences.js';
|
|
35
|
+
export { File } from './fs.js';
|
|
36
|
+
export { Mqtt } from './mqtt.js';
|
|
49
37
|
export { AsyncClass, Async } from './async.js';
|
|
50
|
-
export {
|
|
51
|
-
export {
|
|
52
|
-
export {
|
|
38
|
+
export { WiFi, Scan, WiFiAP } from './wifi.js';
|
|
39
|
+
export { Request } from './http.js';
|
|
40
|
+
export type { RequestOpts } from './http.js';
|
|
41
|
+
export { BLE, BleChain, BleValueType, BlePerm, GATT } from './ble.js';
|
|
53
42
|
export type { GattCharacteristicDef, CharValue } from './ble.js';
|
|
54
|
-
export { RmtChannel } from './rmt.js';
|
package/dist/index.js
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
|
-
export { PinMode
|
|
2
|
-
export { createPinGroup } from './types.js';
|
|
1
|
+
export { PinMode } from './types.js';
|
|
3
2
|
export { include } from './include.js';
|
|
4
3
|
export { board } from './board.js';
|
|
5
4
|
export { callback } from './callback.js';
|
|
6
5
|
export { rawCpp, rawCppExpr, boardResolve } from './emit.js';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export { freeHeap, setInterval, setTimeout, clearInterval, clearTimeout } from './timing.js';
|
|
10
|
-
export { abs, min, max, NumClass, Num, MapChain, ConstrainChain } from './math.js';
|
|
11
|
-
export { Pulse, pulseIn, pulseInLong } from './pulse.js';
|
|
12
|
-
export { Shift, shiftIn, shiftOut } from './shift.js';
|
|
6
|
+
export { TimeClass, Time } from './time.js';
|
|
7
|
+
export { abs, min, max, NumClass, Num } from './math.js';
|
|
13
8
|
export { Random } from './random.js';
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
9
|
+
export { Pin } from './gpio.js';
|
|
10
|
+
export { GPIO } from './gpio-pin.js';
|
|
11
|
+
export { shiftOut, shiftIn } from './shift-pin.js';
|
|
12
|
+
export { PWM } from './pwm-pin.js';
|
|
13
|
+
export { ADC } from './adc-pin.js';
|
|
14
|
+
export { DAC } from './dac-pin.js';
|
|
15
|
+
export { Watchdog } from './watchdog.js';
|
|
16
|
+
export { Counter } from './counter.js';
|
|
17
|
+
export { I2CTarget } from './i2c-target.js';
|
|
18
|
+
export { SPITarget } from './spi-target.js';
|
|
19
|
+
export { UART } from './uart-port.js';
|
|
20
|
+
export { Thread } from './thread.js';
|
|
21
|
+
export { I2CBus } from './i2c.js';
|
|
22
|
+
export { Sensor } from './sensor.js';
|
|
23
|
+
export { SENSOR, CHAN, SENSOR_PART_INFO } from './sensor-catalog.generated.js';
|
|
24
|
+
export { ZEPHYR_ADC_GAINS, ZEPHYR_ADC_REFERENCES, ZEPHYR_GPIO_FLAGS, ZEPHYR_GPIO_INTS } from './zephyr-tokens.generated.js';
|
|
25
|
+
export { SPIBus } from './spi.js';
|
|
26
|
+
export { USBConsole } from './usb.js';
|
|
21
27
|
export { register, bits } from './register.js';
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export { DACClass, DAC } from './dac.js';
|
|
26
|
-
export { PreferencesClass, Preferences } from './preferences.js';
|
|
27
|
-
export { HardwareTimer, Timer0, Timer1, Timer2 } from './timer.js';
|
|
28
|
-
export { FSClass, FS } from './fs.js';
|
|
29
|
-
export { fsBegin, fsReadText, fsWriteText, fsExists, fsRemove } from './fs.js';
|
|
30
|
-
export { MdnsClass, MDNS } from './mdns.js';
|
|
31
|
-
export { mdnsStart, mdnsSetHostname, mdnsAddService, mdnsAnnounce, mdnsStop } from './mdns.js';
|
|
32
|
-
export { MqttClass, MQTT } from './mqtt.js';
|
|
33
|
-
export { mqttConnect, mqttOnMessage, mqttSubscribe, mqttPublish, mqttConnected, mqttDisconnect } from './mqtt.js';
|
|
34
|
-
export { OtaClass, OTA } from './ota.js';
|
|
35
|
-
export { otaFromUrl, otaBegin, otaWrite, otaApply } from './ota.js';
|
|
36
|
-
export { TemperatureClass, Temperature } from './temperature.js';
|
|
37
|
-
export { tempRead } from './temperature.js';
|
|
38
|
-
export { hwtimerSetFrequency, hwtimerOnOverflow, hwtimerStart, hwtimerStop } from './timer.js';
|
|
39
|
-
export { CapacitiveClass, Capacitive } from './capacitive.js';
|
|
40
|
-
export { capacitiveRead } from './capacitive.js';
|
|
41
|
-
export { PowerClass, Power } from './power.js';
|
|
28
|
+
export { Store } from './preferences.js';
|
|
29
|
+
export { File } from './fs.js';
|
|
30
|
+
export { Mqtt } from './mqtt.js';
|
|
42
31
|
export { AsyncClass, Async } from './async.js';
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
46
|
-
export { RmtChannel } from './rmt.js';
|
|
32
|
+
export { WiFi, Scan, WiFiAP } from './wifi.js';
|
|
33
|
+
export { Request } from './http.js';
|
|
34
|
+
export { BLE, BleChain, BleValueType, BlePerm, GATT } from './ble.js';
|
package/dist/math.d.ts
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
export declare class MapChain {
|
|
2
|
-
constructor(value: number);
|
|
3
|
-
from(low: number, high: number): MapChain;
|
|
4
|
-
to(low: number, high: number): number;
|
|
5
|
-
toPercent(): number;
|
|
6
|
-
toByte(): number;
|
|
7
|
-
}
|
|
8
|
-
export declare class ConstrainChain {
|
|
9
|
-
constructor(value: number);
|
|
10
|
-
between(low: number, high: number): number;
|
|
11
|
-
}
|
|
12
1
|
export declare class NumClass {
|
|
13
2
|
abs(x: number): number;
|
|
14
3
|
min(a: number, b: number): number;
|
|
15
4
|
max(a: number, b: number): number;
|
|
16
|
-
constrain(value: number): ConstrainChain;
|
|
17
|
-
map(value: number): MapChain;
|
|
18
5
|
}
|
|
19
6
|
export declare const Num: NumClass;
|
|
20
7
|
export declare function abs(x: number): number;
|