rp2040js 0.17.16 → 0.18.0
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 +1 -1
- package/dist/cjs/clock/clock.d.ts +11 -11
- package/dist/cjs/clock/clock.js +2 -2
- package/dist/cjs/clock/mock-clock.d.ts +17 -17
- package/dist/cjs/clock/mock-clock.js +52 -52
- package/dist/cjs/clock/realtime-clock.d.ts +23 -23
- package/dist/cjs/clock/realtime-clock.js +73 -73
- package/dist/cjs/cortex-m0-core.d.ts +87 -87
- package/dist/cjs/cortex-m0-core.js +1251 -1251
- package/dist/cjs/gdb/gdb-connection.d.ts +11 -11
- package/dist/cjs/gdb/gdb-connection.js +57 -57
- package/dist/cjs/gdb/gdb-server.d.ts +23 -23
- package/dist/cjs/gdb/gdb-server.js +232 -232
- package/dist/cjs/gdb/gdb-tcp-server.d.ts +10 -10
- package/dist/cjs/gdb/gdb-tcp-server.js +34 -34
- package/dist/cjs/gdb/gdb-utils.d.ts +9 -9
- package/dist/cjs/gdb/gdb-utils.js +48 -48
- package/dist/cjs/gpio-pin.d.ts +56 -56
- package/dist/cjs/gpio-pin.js +216 -216
- package/dist/cjs/index.d.ts +11 -11
- package/dist/cjs/index.js +36 -36
- package/dist/cjs/interpolator.d.ts +36 -36
- package/dist/cjs/interpolator.js +150 -150
- package/dist/cjs/irq.d.ts +29 -29
- package/dist/cjs/irq.js +33 -33
- package/dist/cjs/peripherals/adc.d.ts +52 -52
- package/dist/cjs/peripherals/adc.js +261 -261
- package/dist/cjs/peripherals/busctrl.d.ts +10 -10
- package/dist/cjs/peripherals/busctrl.js +84 -84
- package/dist/cjs/peripherals/clocks.d.ts +9 -9
- package/dist/cjs/peripherals/clocks.js +42 -42
- package/dist/cjs/peripherals/dma.d.ts +109 -109
- package/dist/cjs/peripherals/dma.js +520 -520
- package/dist/cjs/peripherals/i2c.d.ts +54 -54
- package/dist/cjs/peripherals/i2c.js +458 -458
- package/dist/cjs/peripherals/io.d.ts +11 -11
- package/dist/cjs/peripherals/io.js +100 -100
- package/dist/cjs/peripherals/pads.d.ts +13 -13
- package/dist/cjs/peripherals/pads.js +58 -58
- package/dist/cjs/peripherals/peripheral.d.ts +22 -22
- package/dist/cjs/peripherals/peripheral.js +61 -61
- package/dist/cjs/peripherals/pio.d.ts +120 -120
- package/dist/cjs/peripherals/pio.js +1086 -1086
- package/dist/cjs/peripherals/ppb.d.ts +25 -25
- package/dist/cjs/peripherals/ppb.js +229 -229
- package/dist/cjs/peripherals/pwm.d.ts +65 -65
- package/dist/cjs/peripherals/pwm.js +372 -372
- package/dist/cjs/peripherals/reset.d.ts +8 -8
- package/dist/cjs/peripherals/reset.js +40 -40
- package/dist/cjs/peripherals/rtc.d.ts +10 -10
- package/dist/cjs/peripherals/rtc.js +74 -74
- package/dist/cjs/peripherals/spi.d.ts +38 -30
- package/dist/cjs/peripherals/spi.js +240 -218
- package/dist/cjs/peripherals/ssi.d.ts +6 -6
- package/dist/cjs/peripherals/ssi.js +43 -43
- package/dist/cjs/peripherals/syscfg.d.ts +5 -5
- package/dist/cjs/peripherals/syscfg.js +26 -26
- package/dist/cjs/peripherals/sysinfo.d.ts +4 -4
- package/dist/cjs/peripherals/sysinfo.js +22 -22
- package/dist/cjs/peripherals/tbman.d.ts +4 -4
- package/dist/cjs/peripherals/tbman.js +17 -17
- package/dist/cjs/peripherals/timer.d.ts +18 -18
- package/dist/cjs/peripherals/timer.js +156 -156
- package/dist/cjs/peripherals/uart.d.ts +31 -28
- package/dist/cjs/peripherals/uart.js +132 -135
- package/dist/cjs/peripherals/usb.d.ts +29 -29
- package/dist/cjs/peripherals/usb.js +309 -309
- package/dist/cjs/rp2040.d.ts +71 -71
- package/dist/cjs/rp2040.js +361 -346
- package/dist/cjs/sio.d.ts +21 -21
- package/dist/cjs/sio.js +425 -425
- package/dist/cjs/usb/cdc.d.ts +20 -20
- package/dist/cjs/usb/cdc.js +126 -126
- package/dist/cjs/usb/interfaces.d.ts +47 -47
- package/dist/cjs/usb/interfaces.js +46 -46
- package/dist/cjs/usb/setup.d.ts +5 -5
- package/dist/cjs/usb/setup.js +53 -53
- package/dist/cjs/utils/assembler.d.ts +79 -79
- package/dist/cjs/utils/assembler.js +328 -328
- package/dist/cjs/utils/bit.d.ts +3 -3
- package/dist/cjs/utils/bit.js +15 -15
- package/dist/cjs/utils/fifo.d.ts +15 -15
- package/dist/cjs/utils/fifo.js +56 -56
- package/dist/cjs/utils/logging.d.ts +23 -23
- package/dist/cjs/utils/logging.js +48 -48
- package/dist/cjs/utils/pio-assembler.d.ts +45 -45
- package/dist/cjs/utils/pio-assembler.js +87 -87
- package/dist/cjs/utils/time.d.ts +2 -2
- package/dist/cjs/utils/time.js +32 -32
- package/dist/cjs/utils/timer32.d.ts +57 -57
- package/dist/cjs/utils/timer32.js +208 -208
- package/dist/esm/clock/clock.d.ts +11 -11
- package/dist/esm/clock/clock.js +1 -1
- package/dist/esm/clock/mock-clock.d.ts +17 -17
- package/dist/esm/clock/mock-clock.js +47 -47
- package/dist/esm/clock/realtime-clock.d.ts +23 -23
- package/dist/esm/clock/realtime-clock.js +68 -68
- package/dist/esm/cortex-m0-core.d.ts +87 -87
- package/dist/esm/cortex-m0-core.js +1247 -1247
- package/dist/esm/gdb/gdb-connection.d.ts +11 -11
- package/dist/esm/gdb/gdb-connection.js +53 -53
- package/dist/esm/gdb/gdb-server.d.ts +23 -23
- package/dist/esm/gdb/gdb-server.js +228 -228
- package/dist/esm/gdb/gdb-tcp-server.d.ts +10 -10
- package/dist/esm/gdb/gdb-tcp-server.js +30 -30
- package/dist/esm/gdb/gdb-utils.d.ts +9 -9
- package/dist/esm/gdb/gdb-utils.js +36 -36
- package/dist/esm/gpio-pin.d.ts +56 -56
- package/dist/esm/gpio-pin.js +212 -212
- package/dist/esm/index.d.ts +11 -11
- package/dist/esm/index.js +11 -11
- package/dist/esm/interpolator.d.ts +36 -36
- package/dist/esm/interpolator.js +145 -145
- package/dist/esm/irq.d.ts +29 -29
- package/dist/esm/irq.js +30 -30
- package/dist/esm/peripherals/adc.d.ts +52 -52
- package/dist/esm/peripherals/adc.js +257 -257
- package/dist/esm/peripherals/busctrl.d.ts +10 -10
- package/dist/esm/peripherals/busctrl.js +80 -80
- package/dist/esm/peripherals/clocks.d.ts +9 -9
- package/dist/esm/peripherals/clocks.js +38 -38
- package/dist/esm/peripherals/dma.d.ts +109 -109
- package/dist/esm/peripherals/dma.js +515 -515
- package/dist/esm/peripherals/i2c.d.ts +54 -54
- package/dist/esm/peripherals/i2c.js +454 -454
- package/dist/esm/peripherals/io.d.ts +11 -11
- package/dist/esm/peripherals/io.js +96 -96
- package/dist/esm/peripherals/pads.d.ts +13 -13
- package/dist/esm/peripherals/pads.js +54 -54
- package/dist/esm/peripherals/peripheral.d.ts +22 -22
- package/dist/esm/peripherals/peripheral.js +55 -55
- package/dist/esm/peripherals/pio.d.ts +120 -120
- package/dist/esm/peripherals/pio.js +1081 -1081
- package/dist/esm/peripherals/ppb.d.ts +25 -25
- package/dist/esm/peripherals/ppb.js +225 -225
- package/dist/esm/peripherals/pwm.d.ts +65 -65
- package/dist/esm/peripherals/pwm.js +368 -368
- package/dist/esm/peripherals/reset.d.ts +8 -8
- package/dist/esm/peripherals/reset.js +36 -36
- package/dist/esm/peripherals/rtc.d.ts +10 -10
- package/dist/esm/peripherals/rtc.js +70 -70
- package/dist/esm/peripherals/spi.d.ts +38 -30
- package/dist/esm/peripherals/spi.js +236 -214
- package/dist/esm/peripherals/ssi.d.ts +6 -6
- package/dist/esm/peripherals/ssi.js +39 -39
- package/dist/esm/peripherals/syscfg.d.ts +5 -5
- package/dist/esm/peripherals/syscfg.js +22 -22
- package/dist/esm/peripherals/sysinfo.d.ts +4 -4
- package/dist/esm/peripherals/sysinfo.js +18 -18
- package/dist/esm/peripherals/tbman.d.ts +4 -4
- package/dist/esm/peripherals/tbman.js +13 -13
- package/dist/esm/peripherals/timer.d.ts +18 -18
- package/dist/esm/peripherals/timer.js +152 -152
- package/dist/esm/peripherals/uart.d.ts +31 -28
- package/dist/esm/peripherals/uart.js +128 -131
- package/dist/esm/peripherals/usb.d.ts +29 -29
- package/dist/esm/peripherals/usb.js +305 -305
- package/dist/esm/rp2040.d.ts +71 -71
- package/dist/esm/rp2040.js +357 -342
- package/dist/esm/sio.d.ts +21 -21
- package/dist/esm/sio.js +421 -421
- package/dist/esm/usb/cdc.d.ts +20 -20
- package/dist/esm/usb/cdc.js +121 -121
- package/dist/esm/usb/interfaces.d.ts +47 -47
- package/dist/esm/usb/interfaces.js +43 -43
- package/dist/esm/usb/setup.d.ts +5 -5
- package/dist/esm/usb/setup.js +46 -46
- package/dist/esm/utils/assembler.d.ts +79 -79
- package/dist/esm/utils/assembler.js +245 -245
- package/dist/esm/utils/bit.d.ts +3 -3
- package/dist/esm/utils/bit.js +9 -9
- package/dist/esm/utils/fifo.d.ts +15 -15
- package/dist/esm/utils/fifo.js +52 -52
- package/dist/esm/utils/logging.d.ts +23 -23
- package/dist/esm/utils/logging.js +44 -44
- package/dist/esm/utils/pio-assembler.d.ts +45 -45
- package/dist/esm/utils/pio-assembler.js +75 -75
- package/dist/esm/utils/time.d.ts +2 -2
- package/dist/esm/utils/time.js +27 -27
- package/dist/esm/utils/timer32.d.ts +57 -57
- package/dist/esm/utils/timer32.js +203 -203
- package/package.json +34 -22
- package/dist/esm/package.json +0 -1
package/dist/cjs/usb/cdc.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { RPUSBController } from '../peripherals/usb';
|
|
2
|
-
import { FIFO } from '../utils/fifo';
|
|
3
|
-
export declare function extractEndpointNumbers(descriptors: ArrayLike<number>): {
|
|
4
|
-
in: number;
|
|
5
|
-
out: number;
|
|
6
|
-
};
|
|
7
|
-
export declare class USBCDC {
|
|
8
|
-
readonly usb: RPUSBController;
|
|
9
|
-
readonly txFIFO: FIFO;
|
|
10
|
-
onSerialData?: (buffer: Uint8Array) => void;
|
|
11
|
-
onDeviceConnected?: () => void;
|
|
12
|
-
private initialized;
|
|
13
|
-
private descriptorsSize;
|
|
14
|
-
private descriptors;
|
|
15
|
-
private outEndpoint;
|
|
16
|
-
private inEndpoint;
|
|
17
|
-
constructor(usb: RPUSBController);
|
|
18
|
-
private cdcSetControlLineState;
|
|
19
|
-
sendSerialByte(data: number): void;
|
|
20
|
-
}
|
|
1
|
+
import { RPUSBController } from '../peripherals/usb.js';
|
|
2
|
+
import { FIFO } from '../utils/fifo.js';
|
|
3
|
+
export declare function extractEndpointNumbers(descriptors: ArrayLike<number>): {
|
|
4
|
+
in: number;
|
|
5
|
+
out: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class USBCDC {
|
|
8
|
+
readonly usb: RPUSBController;
|
|
9
|
+
readonly txFIFO: FIFO;
|
|
10
|
+
onSerialData?: (buffer: Uint8Array) => void;
|
|
11
|
+
onDeviceConnected?: () => void;
|
|
12
|
+
private initialized;
|
|
13
|
+
private descriptorsSize;
|
|
14
|
+
private descriptors;
|
|
15
|
+
private outEndpoint;
|
|
16
|
+
private inEndpoint;
|
|
17
|
+
constructor(usb: RPUSBController);
|
|
18
|
+
private cdcSetControlLineState;
|
|
19
|
+
sendSerialByte(data: number): void;
|
|
20
|
+
}
|
package/dist/cjs/usb/cdc.js
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.USBCDC = exports.extractEndpointNumbers = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
// CDC stuff
|
|
8
|
-
const CDC_REQUEST_SET_CONTROL_LINE_STATE = 0x22;
|
|
9
|
-
const CDC_DTR = 1 << 0;
|
|
10
|
-
const CDC_RTS = 1 << 1;
|
|
11
|
-
const CDC_DATA_CLASS = 10;
|
|
12
|
-
const ENDPOINT_BULK = 2;
|
|
13
|
-
const TX_FIFO_SIZE = 512;
|
|
14
|
-
const ENDPOINT_ZERO = 0;
|
|
15
|
-
const CONFIGURATION_DESCRIPTOR_SIZE = 9;
|
|
16
|
-
function extractEndpointNumbers(descriptors) {
|
|
17
|
-
let index = 0;
|
|
18
|
-
let foundInterface = false;
|
|
19
|
-
const result = {
|
|
20
|
-
in: -1,
|
|
21
|
-
out: -1,
|
|
22
|
-
};
|
|
23
|
-
while (index < descriptors.length) {
|
|
24
|
-
const len = descriptors[index];
|
|
25
|
-
if (len < 2 || descriptors.length < index + len) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
const type = descriptors[index + 1];
|
|
29
|
-
if (type ===
|
|
30
|
-
const numEndpoints = descriptors[index + 4];
|
|
31
|
-
const interfaceClass = descriptors[index + 5];
|
|
32
|
-
foundInterface = numEndpoints === 2 && interfaceClass === CDC_DATA_CLASS;
|
|
33
|
-
}
|
|
34
|
-
if (foundInterface && type ===
|
|
35
|
-
const address = descriptors[index + 2];
|
|
36
|
-
const attributes = descriptors[index + 3];
|
|
37
|
-
if ((attributes & 0x3) === ENDPOINT_BULK) {
|
|
38
|
-
if (address & 0x80) {
|
|
39
|
-
result.in = address & 0xf;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
result.out = address & 0xf;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
index += descriptors[index];
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
exports.extractEndpointNumbers = extractEndpointNumbers;
|
|
51
|
-
class USBCDC {
|
|
52
|
-
constructor(usb) {
|
|
53
|
-
this.usb = usb;
|
|
54
|
-
this.txFIFO = new
|
|
55
|
-
this.initialized = false;
|
|
56
|
-
this.descriptorsSize = null;
|
|
57
|
-
this.descriptors = [];
|
|
58
|
-
this.outEndpoint = -1;
|
|
59
|
-
this.inEndpoint = -1;
|
|
60
|
-
this.usb.onUSBEnabled = () => {
|
|
61
|
-
this.usb.resetDevice();
|
|
62
|
-
};
|
|
63
|
-
this.usb.onResetReceived = () => {
|
|
64
|
-
this.usb.sendSetupPacket(
|
|
65
|
-
};
|
|
66
|
-
this.usb.onEndpointWrite = (endpoint, buffer) => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
if (endpoint === ENDPOINT_ZERO && buffer.length === 0) {
|
|
69
|
-
if (this.descriptorsSize == null) {
|
|
70
|
-
this.usb.sendSetupPacket(
|
|
71
|
-
}
|
|
72
|
-
// Acknowledgement
|
|
73
|
-
else if (!this.initialized) {
|
|
74
|
-
this.cdcSetControlLineState();
|
|
75
|
-
(_a = this.onDeviceConnected) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (endpoint === ENDPOINT_ZERO && buffer.length > 1) {
|
|
79
|
-
if (buffer.length === CONFIGURATION_DESCRIPTOR_SIZE &&
|
|
80
|
-
buffer[1] ===
|
|
81
|
-
this.descriptorsSize == null) {
|
|
82
|
-
this.descriptorsSize = (buffer[3] << 8) | buffer[2];
|
|
83
|
-
this.usb.sendSetupPacket(
|
|
84
|
-
}
|
|
85
|
-
else if (this.descriptorsSize != null && this.descriptors.length < this.descriptorsSize) {
|
|
86
|
-
this.descriptors.push(...buffer);
|
|
87
|
-
}
|
|
88
|
-
if (this.descriptorsSize === this.descriptors.length) {
|
|
89
|
-
const endpoints = extractEndpointNumbers(this.descriptors);
|
|
90
|
-
this.inEndpoint = endpoints.in;
|
|
91
|
-
this.outEndpoint = endpoints.out;
|
|
92
|
-
// Now configure the device
|
|
93
|
-
this.usb.sendSetupPacket(
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (endpoint === this.inEndpoint) {
|
|
97
|
-
(_b = this.onSerialData) === null || _b === void 0 ? void 0 : _b.call(this, buffer);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
this.usb.onEndpointRead = (endpoint, size) => {
|
|
101
|
-
if (endpoint === this.outEndpoint) {
|
|
102
|
-
const buffer = new Uint8Array(Math.min(size, this.txFIFO.itemCount));
|
|
103
|
-
for (let i = 0; i < buffer.length; i++) {
|
|
104
|
-
buffer[i] = this.txFIFO.pull();
|
|
105
|
-
}
|
|
106
|
-
this.usb.endpointReadDone(this.outEndpoint, buffer);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
cdcSetControlLineState(value = CDC_DTR | CDC_RTS, interfaceNumber = 0) {
|
|
111
|
-
this.usb.sendSetupPacket(
|
|
112
|
-
dataDirection:
|
|
113
|
-
type:
|
|
114
|
-
recipient:
|
|
115
|
-
bRequest: CDC_REQUEST_SET_CONTROL_LINE_STATE,
|
|
116
|
-
wValue: value,
|
|
117
|
-
wIndex: interfaceNumber,
|
|
118
|
-
wLength: 0,
|
|
119
|
-
}));
|
|
120
|
-
this.initialized = true;
|
|
121
|
-
}
|
|
122
|
-
sendSerialByte(data) {
|
|
123
|
-
this.txFIFO.push(data);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.USBCDC = USBCDC;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USBCDC = exports.extractEndpointNumbers = void 0;
|
|
4
|
+
const fifo_js_1 = require("../utils/fifo.js");
|
|
5
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
6
|
+
const setup_js_1 = require("./setup.js");
|
|
7
|
+
// CDC stuff
|
|
8
|
+
const CDC_REQUEST_SET_CONTROL_LINE_STATE = 0x22;
|
|
9
|
+
const CDC_DTR = 1 << 0;
|
|
10
|
+
const CDC_RTS = 1 << 1;
|
|
11
|
+
const CDC_DATA_CLASS = 10;
|
|
12
|
+
const ENDPOINT_BULK = 2;
|
|
13
|
+
const TX_FIFO_SIZE = 512;
|
|
14
|
+
const ENDPOINT_ZERO = 0;
|
|
15
|
+
const CONFIGURATION_DESCRIPTOR_SIZE = 9;
|
|
16
|
+
function extractEndpointNumbers(descriptors) {
|
|
17
|
+
let index = 0;
|
|
18
|
+
let foundInterface = false;
|
|
19
|
+
const result = {
|
|
20
|
+
in: -1,
|
|
21
|
+
out: -1,
|
|
22
|
+
};
|
|
23
|
+
while (index < descriptors.length) {
|
|
24
|
+
const len = descriptors[index];
|
|
25
|
+
if (len < 2 || descriptors.length < index + len) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
const type = descriptors[index + 1];
|
|
29
|
+
if (type === interfaces_js_1.DescriptorType.Interface && len === 9) {
|
|
30
|
+
const numEndpoints = descriptors[index + 4];
|
|
31
|
+
const interfaceClass = descriptors[index + 5];
|
|
32
|
+
foundInterface = numEndpoints === 2 && interfaceClass === CDC_DATA_CLASS;
|
|
33
|
+
}
|
|
34
|
+
if (foundInterface && type === interfaces_js_1.DescriptorType.Endpoint && len === 7) {
|
|
35
|
+
const address = descriptors[index + 2];
|
|
36
|
+
const attributes = descriptors[index + 3];
|
|
37
|
+
if ((attributes & 0x3) === ENDPOINT_BULK) {
|
|
38
|
+
if (address & 0x80) {
|
|
39
|
+
result.in = address & 0xf;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
result.out = address & 0xf;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
index += descriptors[index];
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
exports.extractEndpointNumbers = extractEndpointNumbers;
|
|
51
|
+
class USBCDC {
|
|
52
|
+
constructor(usb) {
|
|
53
|
+
this.usb = usb;
|
|
54
|
+
this.txFIFO = new fifo_js_1.FIFO(TX_FIFO_SIZE);
|
|
55
|
+
this.initialized = false;
|
|
56
|
+
this.descriptorsSize = null;
|
|
57
|
+
this.descriptors = [];
|
|
58
|
+
this.outEndpoint = -1;
|
|
59
|
+
this.inEndpoint = -1;
|
|
60
|
+
this.usb.onUSBEnabled = () => {
|
|
61
|
+
this.usb.resetDevice();
|
|
62
|
+
};
|
|
63
|
+
this.usb.onResetReceived = () => {
|
|
64
|
+
this.usb.sendSetupPacket((0, setup_js_1.setDeviceAddressPacket)(1));
|
|
65
|
+
};
|
|
66
|
+
this.usb.onEndpointWrite = (endpoint, buffer) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (endpoint === ENDPOINT_ZERO && buffer.length === 0) {
|
|
69
|
+
if (this.descriptorsSize == null) {
|
|
70
|
+
this.usb.sendSetupPacket((0, setup_js_1.getDescriptorPacket)(interfaces_js_1.DescriptorType.Configration, CONFIGURATION_DESCRIPTOR_SIZE));
|
|
71
|
+
}
|
|
72
|
+
// Acknowledgement
|
|
73
|
+
else if (!this.initialized) {
|
|
74
|
+
this.cdcSetControlLineState();
|
|
75
|
+
(_a = this.onDeviceConnected) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (endpoint === ENDPOINT_ZERO && buffer.length > 1) {
|
|
79
|
+
if (buffer.length === CONFIGURATION_DESCRIPTOR_SIZE &&
|
|
80
|
+
buffer[1] === interfaces_js_1.DescriptorType.Configration &&
|
|
81
|
+
this.descriptorsSize == null) {
|
|
82
|
+
this.descriptorsSize = (buffer[3] << 8) | buffer[2];
|
|
83
|
+
this.usb.sendSetupPacket((0, setup_js_1.getDescriptorPacket)(interfaces_js_1.DescriptorType.Configration, this.descriptorsSize));
|
|
84
|
+
}
|
|
85
|
+
else if (this.descriptorsSize != null && this.descriptors.length < this.descriptorsSize) {
|
|
86
|
+
this.descriptors.push(...buffer);
|
|
87
|
+
}
|
|
88
|
+
if (this.descriptorsSize === this.descriptors.length) {
|
|
89
|
+
const endpoints = extractEndpointNumbers(this.descriptors);
|
|
90
|
+
this.inEndpoint = endpoints.in;
|
|
91
|
+
this.outEndpoint = endpoints.out;
|
|
92
|
+
// Now configure the device
|
|
93
|
+
this.usb.sendSetupPacket((0, setup_js_1.setDeviceConfigurationPacket)(1));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (endpoint === this.inEndpoint) {
|
|
97
|
+
(_b = this.onSerialData) === null || _b === void 0 ? void 0 : _b.call(this, buffer);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.usb.onEndpointRead = (endpoint, size) => {
|
|
101
|
+
if (endpoint === this.outEndpoint) {
|
|
102
|
+
const buffer = new Uint8Array(Math.min(size, this.txFIFO.itemCount));
|
|
103
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
104
|
+
buffer[i] = this.txFIFO.pull();
|
|
105
|
+
}
|
|
106
|
+
this.usb.endpointReadDone(this.outEndpoint, buffer);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
cdcSetControlLineState(value = CDC_DTR | CDC_RTS, interfaceNumber = 0) {
|
|
111
|
+
this.usb.sendSetupPacket((0, setup_js_1.createSetupPacket)({
|
|
112
|
+
dataDirection: interfaces_js_1.DataDirection.HostToDevice,
|
|
113
|
+
type: interfaces_js_1.SetupType.Class,
|
|
114
|
+
recipient: interfaces_js_1.SetupRecipient.Device,
|
|
115
|
+
bRequest: CDC_REQUEST_SET_CONTROL_LINE_STATE,
|
|
116
|
+
wValue: value,
|
|
117
|
+
wIndex: interfaceNumber,
|
|
118
|
+
wLength: 0,
|
|
119
|
+
}));
|
|
120
|
+
this.initialized = true;
|
|
121
|
+
}
|
|
122
|
+
sendSerialByte(data) {
|
|
123
|
+
this.txFIFO.push(data);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.USBCDC = USBCDC;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
export declare enum DataDirection {
|
|
2
|
-
HostToDevice = 0,
|
|
3
|
-
DeviceToHost = 1
|
|
4
|
-
}
|
|
5
|
-
export declare enum SetupType {
|
|
6
|
-
Standard = 0,
|
|
7
|
-
Class = 1,
|
|
8
|
-
Vendor = 2,
|
|
9
|
-
Reserved = 3
|
|
10
|
-
}
|
|
11
|
-
export declare enum SetupRecipient {
|
|
12
|
-
Device = 0,
|
|
13
|
-
Interface = 1,
|
|
14
|
-
Endpoint = 2,
|
|
15
|
-
Other = 3
|
|
16
|
-
}
|
|
17
|
-
export declare enum SetupRequest {
|
|
18
|
-
GetStatus = 0,
|
|
19
|
-
ClearFeature = 1,
|
|
20
|
-
Reserved1 = 2,
|
|
21
|
-
SetFeature = 3,
|
|
22
|
-
Reserved2 = 4,
|
|
23
|
-
SetAddress = 5,
|
|
24
|
-
GetDescriptor = 6,
|
|
25
|
-
SetDescriptor = 7,
|
|
26
|
-
GetConfiguration = 8,
|
|
27
|
-
SetDeviceConfiguration = 9,
|
|
28
|
-
GetInterface = 10,
|
|
29
|
-
SetInterface = 11,
|
|
30
|
-
SynchFrame = 12
|
|
31
|
-
}
|
|
32
|
-
export declare enum DescriptorType {
|
|
33
|
-
Device = 1,
|
|
34
|
-
Configration = 2,
|
|
35
|
-
String = 3,
|
|
36
|
-
Interface = 4,
|
|
37
|
-
Endpoint = 5
|
|
38
|
-
}
|
|
39
|
-
export interface ISetupPacketParams {
|
|
40
|
-
dataDirection: DataDirection;
|
|
41
|
-
type: SetupType;
|
|
42
|
-
recipient: SetupRecipient;
|
|
43
|
-
bRequest: SetupRequest;
|
|
44
|
-
wValue: number;
|
|
45
|
-
wIndex: number;
|
|
46
|
-
wLength: number;
|
|
47
|
-
}
|
|
1
|
+
export declare enum DataDirection {
|
|
2
|
+
HostToDevice = 0,
|
|
3
|
+
DeviceToHost = 1
|
|
4
|
+
}
|
|
5
|
+
export declare enum SetupType {
|
|
6
|
+
Standard = 0,
|
|
7
|
+
Class = 1,
|
|
8
|
+
Vendor = 2,
|
|
9
|
+
Reserved = 3
|
|
10
|
+
}
|
|
11
|
+
export declare enum SetupRecipient {
|
|
12
|
+
Device = 0,
|
|
13
|
+
Interface = 1,
|
|
14
|
+
Endpoint = 2,
|
|
15
|
+
Other = 3
|
|
16
|
+
}
|
|
17
|
+
export declare enum SetupRequest {
|
|
18
|
+
GetStatus = 0,
|
|
19
|
+
ClearFeature = 1,
|
|
20
|
+
Reserved1 = 2,
|
|
21
|
+
SetFeature = 3,
|
|
22
|
+
Reserved2 = 4,
|
|
23
|
+
SetAddress = 5,
|
|
24
|
+
GetDescriptor = 6,
|
|
25
|
+
SetDescriptor = 7,
|
|
26
|
+
GetConfiguration = 8,
|
|
27
|
+
SetDeviceConfiguration = 9,
|
|
28
|
+
GetInterface = 10,
|
|
29
|
+
SetInterface = 11,
|
|
30
|
+
SynchFrame = 12
|
|
31
|
+
}
|
|
32
|
+
export declare enum DescriptorType {
|
|
33
|
+
Device = 1,
|
|
34
|
+
Configration = 2,
|
|
35
|
+
String = 3,
|
|
36
|
+
Interface = 4,
|
|
37
|
+
Endpoint = 5
|
|
38
|
+
}
|
|
39
|
+
export interface ISetupPacketParams {
|
|
40
|
+
dataDirection: DataDirection;
|
|
41
|
+
type: SetupType;
|
|
42
|
+
recipient: SetupRecipient;
|
|
43
|
+
bRequest: SetupRequest | number;
|
|
44
|
+
wValue: number;
|
|
45
|
+
wIndex: number;
|
|
46
|
+
wLength: number;
|
|
47
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DescriptorType = exports.SetupRequest = exports.SetupRecipient = exports.SetupType = exports.DataDirection = void 0;
|
|
4
|
-
var DataDirection;
|
|
5
|
-
(function (DataDirection) {
|
|
6
|
-
DataDirection[DataDirection["HostToDevice"] = 0] = "HostToDevice";
|
|
7
|
-
DataDirection[DataDirection["DeviceToHost"] = 1] = "DeviceToHost";
|
|
8
|
-
})(DataDirection
|
|
9
|
-
var SetupType;
|
|
10
|
-
(function (SetupType) {
|
|
11
|
-
SetupType[SetupType["Standard"] = 0] = "Standard";
|
|
12
|
-
SetupType[SetupType["Class"] = 1] = "Class";
|
|
13
|
-
SetupType[SetupType["Vendor"] = 2] = "Vendor";
|
|
14
|
-
SetupType[SetupType["Reserved"] = 3] = "Reserved";
|
|
15
|
-
})(SetupType
|
|
16
|
-
var SetupRecipient;
|
|
17
|
-
(function (SetupRecipient) {
|
|
18
|
-
SetupRecipient[SetupRecipient["Device"] = 0] = "Device";
|
|
19
|
-
SetupRecipient[SetupRecipient["Interface"] = 1] = "Interface";
|
|
20
|
-
SetupRecipient[SetupRecipient["Endpoint"] = 2] = "Endpoint";
|
|
21
|
-
SetupRecipient[SetupRecipient["Other"] = 3] = "Other";
|
|
22
|
-
})(SetupRecipient
|
|
23
|
-
var SetupRequest;
|
|
24
|
-
(function (SetupRequest) {
|
|
25
|
-
SetupRequest[SetupRequest["GetStatus"] = 0] = "GetStatus";
|
|
26
|
-
SetupRequest[SetupRequest["ClearFeature"] = 1] = "ClearFeature";
|
|
27
|
-
SetupRequest[SetupRequest["Reserved1"] = 2] = "Reserved1";
|
|
28
|
-
SetupRequest[SetupRequest["SetFeature"] = 3] = "SetFeature";
|
|
29
|
-
SetupRequest[SetupRequest["Reserved2"] = 4] = "Reserved2";
|
|
30
|
-
SetupRequest[SetupRequest["SetAddress"] = 5] = "SetAddress";
|
|
31
|
-
SetupRequest[SetupRequest["GetDescriptor"] = 6] = "GetDescriptor";
|
|
32
|
-
SetupRequest[SetupRequest["SetDescriptor"] = 7] = "SetDescriptor";
|
|
33
|
-
SetupRequest[SetupRequest["GetConfiguration"] = 8] = "GetConfiguration";
|
|
34
|
-
SetupRequest[SetupRequest["SetDeviceConfiguration"] = 9] = "SetDeviceConfiguration";
|
|
35
|
-
SetupRequest[SetupRequest["GetInterface"] = 10] = "GetInterface";
|
|
36
|
-
SetupRequest[SetupRequest["SetInterface"] = 11] = "SetInterface";
|
|
37
|
-
SetupRequest[SetupRequest["SynchFrame"] = 12] = "SynchFrame";
|
|
38
|
-
})(SetupRequest
|
|
39
|
-
var DescriptorType;
|
|
40
|
-
(function (DescriptorType) {
|
|
41
|
-
DescriptorType[DescriptorType["Device"] = 1] = "Device";
|
|
42
|
-
DescriptorType[DescriptorType["Configration"] = 2] = "Configration";
|
|
43
|
-
DescriptorType[DescriptorType["String"] = 3] = "String";
|
|
44
|
-
DescriptorType[DescriptorType["Interface"] = 4] = "Interface";
|
|
45
|
-
DescriptorType[DescriptorType["Endpoint"] = 5] = "Endpoint";
|
|
46
|
-
})(DescriptorType
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DescriptorType = exports.SetupRequest = exports.SetupRecipient = exports.SetupType = exports.DataDirection = void 0;
|
|
4
|
+
var DataDirection;
|
|
5
|
+
(function (DataDirection) {
|
|
6
|
+
DataDirection[DataDirection["HostToDevice"] = 0] = "HostToDevice";
|
|
7
|
+
DataDirection[DataDirection["DeviceToHost"] = 1] = "DeviceToHost";
|
|
8
|
+
})(DataDirection || (exports.DataDirection = DataDirection = {}));
|
|
9
|
+
var SetupType;
|
|
10
|
+
(function (SetupType) {
|
|
11
|
+
SetupType[SetupType["Standard"] = 0] = "Standard";
|
|
12
|
+
SetupType[SetupType["Class"] = 1] = "Class";
|
|
13
|
+
SetupType[SetupType["Vendor"] = 2] = "Vendor";
|
|
14
|
+
SetupType[SetupType["Reserved"] = 3] = "Reserved";
|
|
15
|
+
})(SetupType || (exports.SetupType = SetupType = {}));
|
|
16
|
+
var SetupRecipient;
|
|
17
|
+
(function (SetupRecipient) {
|
|
18
|
+
SetupRecipient[SetupRecipient["Device"] = 0] = "Device";
|
|
19
|
+
SetupRecipient[SetupRecipient["Interface"] = 1] = "Interface";
|
|
20
|
+
SetupRecipient[SetupRecipient["Endpoint"] = 2] = "Endpoint";
|
|
21
|
+
SetupRecipient[SetupRecipient["Other"] = 3] = "Other";
|
|
22
|
+
})(SetupRecipient || (exports.SetupRecipient = SetupRecipient = {}));
|
|
23
|
+
var SetupRequest;
|
|
24
|
+
(function (SetupRequest) {
|
|
25
|
+
SetupRequest[SetupRequest["GetStatus"] = 0] = "GetStatus";
|
|
26
|
+
SetupRequest[SetupRequest["ClearFeature"] = 1] = "ClearFeature";
|
|
27
|
+
SetupRequest[SetupRequest["Reserved1"] = 2] = "Reserved1";
|
|
28
|
+
SetupRequest[SetupRequest["SetFeature"] = 3] = "SetFeature";
|
|
29
|
+
SetupRequest[SetupRequest["Reserved2"] = 4] = "Reserved2";
|
|
30
|
+
SetupRequest[SetupRequest["SetAddress"] = 5] = "SetAddress";
|
|
31
|
+
SetupRequest[SetupRequest["GetDescriptor"] = 6] = "GetDescriptor";
|
|
32
|
+
SetupRequest[SetupRequest["SetDescriptor"] = 7] = "SetDescriptor";
|
|
33
|
+
SetupRequest[SetupRequest["GetConfiguration"] = 8] = "GetConfiguration";
|
|
34
|
+
SetupRequest[SetupRequest["SetDeviceConfiguration"] = 9] = "SetDeviceConfiguration";
|
|
35
|
+
SetupRequest[SetupRequest["GetInterface"] = 10] = "GetInterface";
|
|
36
|
+
SetupRequest[SetupRequest["SetInterface"] = 11] = "SetInterface";
|
|
37
|
+
SetupRequest[SetupRequest["SynchFrame"] = 12] = "SynchFrame";
|
|
38
|
+
})(SetupRequest || (exports.SetupRequest = SetupRequest = {}));
|
|
39
|
+
var DescriptorType;
|
|
40
|
+
(function (DescriptorType) {
|
|
41
|
+
DescriptorType[DescriptorType["Device"] = 1] = "Device";
|
|
42
|
+
DescriptorType[DescriptorType["Configration"] = 2] = "Configration";
|
|
43
|
+
DescriptorType[DescriptorType["String"] = 3] = "String";
|
|
44
|
+
DescriptorType[DescriptorType["Interface"] = 4] = "Interface";
|
|
45
|
+
DescriptorType[DescriptorType["Endpoint"] = 5] = "Endpoint";
|
|
46
|
+
})(DescriptorType || (exports.DescriptorType = DescriptorType = {}));
|
package/dist/cjs/usb/setup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DescriptorType, ISetupPacketParams } from './interfaces';
|
|
2
|
-
export declare function createSetupPacket(params: ISetupPacketParams): Uint8Array;
|
|
3
|
-
export declare function setDeviceAddressPacket(address: number): Uint8Array;
|
|
4
|
-
export declare function getDescriptorPacket(type: DescriptorType, length: number, index?: number): Uint8Array;
|
|
5
|
-
export declare function setDeviceConfigurationPacket(configurationNumber: number): Uint8Array;
|
|
1
|
+
import { DescriptorType, ISetupPacketParams } from './interfaces.js';
|
|
2
|
+
export declare function createSetupPacket(params: ISetupPacketParams): Uint8Array;
|
|
3
|
+
export declare function setDeviceAddressPacket(address: number): Uint8Array;
|
|
4
|
+
export declare function getDescriptorPacket(type: DescriptorType, length: number, index?: number): Uint8Array;
|
|
5
|
+
export declare function setDeviceConfigurationPacket(configurationNumber: number): Uint8Array;
|
package/dist/cjs/usb/setup.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setDeviceConfigurationPacket = exports.getDescriptorPacket = exports.setDeviceAddressPacket = exports.createSetupPacket = void 0;
|
|
4
|
-
const
|
|
5
|
-
function createSetupPacket(params) {
|
|
6
|
-
const setupPacket = new Uint8Array(8);
|
|
7
|
-
setupPacket[0] = (params.dataDirection << 7) | (params.type << 5) | params.recipient;
|
|
8
|
-
setupPacket[1] = params.bRequest;
|
|
9
|
-
setupPacket[2] = params.wValue & 0xff;
|
|
10
|
-
setupPacket[3] = (params.wValue >> 8) & 0xff;
|
|
11
|
-
setupPacket[4] = params.wIndex & 0xff;
|
|
12
|
-
setupPacket[5] = (params.wIndex >> 8) & 0xff;
|
|
13
|
-
setupPacket[6] = params.wLength & 0xff;
|
|
14
|
-
setupPacket[7] = (params.wLength >> 8) & 0xff;
|
|
15
|
-
return setupPacket;
|
|
16
|
-
}
|
|
17
|
-
exports.createSetupPacket = createSetupPacket;
|
|
18
|
-
function setDeviceAddressPacket(address) {
|
|
19
|
-
return createSetupPacket({
|
|
20
|
-
dataDirection:
|
|
21
|
-
type:
|
|
22
|
-
recipient:
|
|
23
|
-
bRequest:
|
|
24
|
-
wValue: address,
|
|
25
|
-
wIndex: 0,
|
|
26
|
-
wLength: 0,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.setDeviceAddressPacket = setDeviceAddressPacket;
|
|
30
|
-
function getDescriptorPacket(type, length, index = 0) {
|
|
31
|
-
return createSetupPacket({
|
|
32
|
-
dataDirection:
|
|
33
|
-
type:
|
|
34
|
-
recipient:
|
|
35
|
-
bRequest:
|
|
36
|
-
wValue: type << 8,
|
|
37
|
-
wIndex: index,
|
|
38
|
-
wLength: length,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
exports.getDescriptorPacket = getDescriptorPacket;
|
|
42
|
-
function setDeviceConfigurationPacket(configurationNumber) {
|
|
43
|
-
return createSetupPacket({
|
|
44
|
-
dataDirection:
|
|
45
|
-
type:
|
|
46
|
-
recipient:
|
|
47
|
-
bRequest:
|
|
48
|
-
wValue: configurationNumber,
|
|
49
|
-
wIndex: 0,
|
|
50
|
-
wLength: 0,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
exports.setDeviceConfigurationPacket = setDeviceConfigurationPacket;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDeviceConfigurationPacket = exports.getDescriptorPacket = exports.setDeviceAddressPacket = exports.createSetupPacket = void 0;
|
|
4
|
+
const interfaces_js_1 = require("./interfaces.js");
|
|
5
|
+
function createSetupPacket(params) {
|
|
6
|
+
const setupPacket = new Uint8Array(8);
|
|
7
|
+
setupPacket[0] = (params.dataDirection << 7) | (params.type << 5) | params.recipient;
|
|
8
|
+
setupPacket[1] = params.bRequest;
|
|
9
|
+
setupPacket[2] = params.wValue & 0xff;
|
|
10
|
+
setupPacket[3] = (params.wValue >> 8) & 0xff;
|
|
11
|
+
setupPacket[4] = params.wIndex & 0xff;
|
|
12
|
+
setupPacket[5] = (params.wIndex >> 8) & 0xff;
|
|
13
|
+
setupPacket[6] = params.wLength & 0xff;
|
|
14
|
+
setupPacket[7] = (params.wLength >> 8) & 0xff;
|
|
15
|
+
return setupPacket;
|
|
16
|
+
}
|
|
17
|
+
exports.createSetupPacket = createSetupPacket;
|
|
18
|
+
function setDeviceAddressPacket(address) {
|
|
19
|
+
return createSetupPacket({
|
|
20
|
+
dataDirection: interfaces_js_1.DataDirection.HostToDevice,
|
|
21
|
+
type: interfaces_js_1.SetupType.Standard,
|
|
22
|
+
recipient: interfaces_js_1.SetupRecipient.Device,
|
|
23
|
+
bRequest: interfaces_js_1.SetupRequest.SetAddress,
|
|
24
|
+
wValue: address,
|
|
25
|
+
wIndex: 0,
|
|
26
|
+
wLength: 0,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.setDeviceAddressPacket = setDeviceAddressPacket;
|
|
30
|
+
function getDescriptorPacket(type, length, index = 0) {
|
|
31
|
+
return createSetupPacket({
|
|
32
|
+
dataDirection: interfaces_js_1.DataDirection.DeviceToHost,
|
|
33
|
+
type: interfaces_js_1.SetupType.Standard,
|
|
34
|
+
recipient: interfaces_js_1.SetupRecipient.Device,
|
|
35
|
+
bRequest: interfaces_js_1.SetupRequest.GetDescriptor,
|
|
36
|
+
wValue: type << 8,
|
|
37
|
+
wIndex: index,
|
|
38
|
+
wLength: length,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.getDescriptorPacket = getDescriptorPacket;
|
|
42
|
+
function setDeviceConfigurationPacket(configurationNumber) {
|
|
43
|
+
return createSetupPacket({
|
|
44
|
+
dataDirection: interfaces_js_1.DataDirection.HostToDevice,
|
|
45
|
+
type: interfaces_js_1.SetupType.Standard,
|
|
46
|
+
recipient: interfaces_js_1.SetupRecipient.Device,
|
|
47
|
+
bRequest: interfaces_js_1.SetupRequest.SetDeviceConfiguration,
|
|
48
|
+
wValue: configurationNumber,
|
|
49
|
+
wIndex: 0,
|
|
50
|
+
wLength: 0,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.setDeviceConfigurationPacket = setDeviceConfigurationPacket;
|