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.
Files changed (183) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/clock/clock.d.ts +11 -11
  3. package/dist/cjs/clock/clock.js +2 -2
  4. package/dist/cjs/clock/mock-clock.d.ts +17 -17
  5. package/dist/cjs/clock/mock-clock.js +52 -52
  6. package/dist/cjs/clock/realtime-clock.d.ts +23 -23
  7. package/dist/cjs/clock/realtime-clock.js +73 -73
  8. package/dist/cjs/cortex-m0-core.d.ts +87 -87
  9. package/dist/cjs/cortex-m0-core.js +1251 -1251
  10. package/dist/cjs/gdb/gdb-connection.d.ts +11 -11
  11. package/dist/cjs/gdb/gdb-connection.js +57 -57
  12. package/dist/cjs/gdb/gdb-server.d.ts +23 -23
  13. package/dist/cjs/gdb/gdb-server.js +232 -232
  14. package/dist/cjs/gdb/gdb-tcp-server.d.ts +10 -10
  15. package/dist/cjs/gdb/gdb-tcp-server.js +34 -34
  16. package/dist/cjs/gdb/gdb-utils.d.ts +9 -9
  17. package/dist/cjs/gdb/gdb-utils.js +48 -48
  18. package/dist/cjs/gpio-pin.d.ts +56 -56
  19. package/dist/cjs/gpio-pin.js +216 -216
  20. package/dist/cjs/index.d.ts +11 -11
  21. package/dist/cjs/index.js +36 -36
  22. package/dist/cjs/interpolator.d.ts +36 -36
  23. package/dist/cjs/interpolator.js +150 -150
  24. package/dist/cjs/irq.d.ts +29 -29
  25. package/dist/cjs/irq.js +33 -33
  26. package/dist/cjs/peripherals/adc.d.ts +52 -52
  27. package/dist/cjs/peripherals/adc.js +261 -261
  28. package/dist/cjs/peripherals/busctrl.d.ts +10 -10
  29. package/dist/cjs/peripherals/busctrl.js +84 -84
  30. package/dist/cjs/peripherals/clocks.d.ts +9 -9
  31. package/dist/cjs/peripherals/clocks.js +42 -42
  32. package/dist/cjs/peripherals/dma.d.ts +109 -109
  33. package/dist/cjs/peripherals/dma.js +520 -520
  34. package/dist/cjs/peripherals/i2c.d.ts +54 -54
  35. package/dist/cjs/peripherals/i2c.js +458 -458
  36. package/dist/cjs/peripherals/io.d.ts +11 -11
  37. package/dist/cjs/peripherals/io.js +100 -100
  38. package/dist/cjs/peripherals/pads.d.ts +13 -13
  39. package/dist/cjs/peripherals/pads.js +58 -58
  40. package/dist/cjs/peripherals/peripheral.d.ts +22 -22
  41. package/dist/cjs/peripherals/peripheral.js +61 -61
  42. package/dist/cjs/peripherals/pio.d.ts +120 -120
  43. package/dist/cjs/peripherals/pio.js +1086 -1086
  44. package/dist/cjs/peripherals/ppb.d.ts +25 -25
  45. package/dist/cjs/peripherals/ppb.js +229 -229
  46. package/dist/cjs/peripherals/pwm.d.ts +65 -65
  47. package/dist/cjs/peripherals/pwm.js +372 -372
  48. package/dist/cjs/peripherals/reset.d.ts +8 -8
  49. package/dist/cjs/peripherals/reset.js +40 -40
  50. package/dist/cjs/peripherals/rtc.d.ts +10 -10
  51. package/dist/cjs/peripherals/rtc.js +74 -74
  52. package/dist/cjs/peripherals/spi.d.ts +38 -30
  53. package/dist/cjs/peripherals/spi.js +240 -218
  54. package/dist/cjs/peripherals/ssi.d.ts +6 -6
  55. package/dist/cjs/peripherals/ssi.js +43 -43
  56. package/dist/cjs/peripherals/syscfg.d.ts +5 -5
  57. package/dist/cjs/peripherals/syscfg.js +26 -26
  58. package/dist/cjs/peripherals/sysinfo.d.ts +4 -4
  59. package/dist/cjs/peripherals/sysinfo.js +22 -22
  60. package/dist/cjs/peripherals/tbman.d.ts +4 -4
  61. package/dist/cjs/peripherals/tbman.js +17 -17
  62. package/dist/cjs/peripherals/timer.d.ts +18 -18
  63. package/dist/cjs/peripherals/timer.js +156 -156
  64. package/dist/cjs/peripherals/uart.d.ts +31 -28
  65. package/dist/cjs/peripherals/uart.js +132 -135
  66. package/dist/cjs/peripherals/usb.d.ts +29 -29
  67. package/dist/cjs/peripherals/usb.js +309 -309
  68. package/dist/cjs/rp2040.d.ts +71 -71
  69. package/dist/cjs/rp2040.js +361 -346
  70. package/dist/cjs/sio.d.ts +21 -21
  71. package/dist/cjs/sio.js +425 -425
  72. package/dist/cjs/usb/cdc.d.ts +20 -20
  73. package/dist/cjs/usb/cdc.js +126 -126
  74. package/dist/cjs/usb/interfaces.d.ts +47 -47
  75. package/dist/cjs/usb/interfaces.js +46 -46
  76. package/dist/cjs/usb/setup.d.ts +5 -5
  77. package/dist/cjs/usb/setup.js +53 -53
  78. package/dist/cjs/utils/assembler.d.ts +79 -79
  79. package/dist/cjs/utils/assembler.js +328 -328
  80. package/dist/cjs/utils/bit.d.ts +3 -3
  81. package/dist/cjs/utils/bit.js +15 -15
  82. package/dist/cjs/utils/fifo.d.ts +15 -15
  83. package/dist/cjs/utils/fifo.js +56 -56
  84. package/dist/cjs/utils/logging.d.ts +23 -23
  85. package/dist/cjs/utils/logging.js +48 -48
  86. package/dist/cjs/utils/pio-assembler.d.ts +45 -45
  87. package/dist/cjs/utils/pio-assembler.js +87 -87
  88. package/dist/cjs/utils/time.d.ts +2 -2
  89. package/dist/cjs/utils/time.js +32 -32
  90. package/dist/cjs/utils/timer32.d.ts +57 -57
  91. package/dist/cjs/utils/timer32.js +208 -208
  92. package/dist/esm/clock/clock.d.ts +11 -11
  93. package/dist/esm/clock/clock.js +1 -1
  94. package/dist/esm/clock/mock-clock.d.ts +17 -17
  95. package/dist/esm/clock/mock-clock.js +47 -47
  96. package/dist/esm/clock/realtime-clock.d.ts +23 -23
  97. package/dist/esm/clock/realtime-clock.js +68 -68
  98. package/dist/esm/cortex-m0-core.d.ts +87 -87
  99. package/dist/esm/cortex-m0-core.js +1247 -1247
  100. package/dist/esm/gdb/gdb-connection.d.ts +11 -11
  101. package/dist/esm/gdb/gdb-connection.js +53 -53
  102. package/dist/esm/gdb/gdb-server.d.ts +23 -23
  103. package/dist/esm/gdb/gdb-server.js +228 -228
  104. package/dist/esm/gdb/gdb-tcp-server.d.ts +10 -10
  105. package/dist/esm/gdb/gdb-tcp-server.js +30 -30
  106. package/dist/esm/gdb/gdb-utils.d.ts +9 -9
  107. package/dist/esm/gdb/gdb-utils.js +36 -36
  108. package/dist/esm/gpio-pin.d.ts +56 -56
  109. package/dist/esm/gpio-pin.js +212 -212
  110. package/dist/esm/index.d.ts +11 -11
  111. package/dist/esm/index.js +11 -11
  112. package/dist/esm/interpolator.d.ts +36 -36
  113. package/dist/esm/interpolator.js +145 -145
  114. package/dist/esm/irq.d.ts +29 -29
  115. package/dist/esm/irq.js +30 -30
  116. package/dist/esm/peripherals/adc.d.ts +52 -52
  117. package/dist/esm/peripherals/adc.js +257 -257
  118. package/dist/esm/peripherals/busctrl.d.ts +10 -10
  119. package/dist/esm/peripherals/busctrl.js +80 -80
  120. package/dist/esm/peripherals/clocks.d.ts +9 -9
  121. package/dist/esm/peripherals/clocks.js +38 -38
  122. package/dist/esm/peripherals/dma.d.ts +109 -109
  123. package/dist/esm/peripherals/dma.js +515 -515
  124. package/dist/esm/peripherals/i2c.d.ts +54 -54
  125. package/dist/esm/peripherals/i2c.js +454 -454
  126. package/dist/esm/peripherals/io.d.ts +11 -11
  127. package/dist/esm/peripherals/io.js +96 -96
  128. package/dist/esm/peripherals/pads.d.ts +13 -13
  129. package/dist/esm/peripherals/pads.js +54 -54
  130. package/dist/esm/peripherals/peripheral.d.ts +22 -22
  131. package/dist/esm/peripherals/peripheral.js +55 -55
  132. package/dist/esm/peripherals/pio.d.ts +120 -120
  133. package/dist/esm/peripherals/pio.js +1081 -1081
  134. package/dist/esm/peripherals/ppb.d.ts +25 -25
  135. package/dist/esm/peripherals/ppb.js +225 -225
  136. package/dist/esm/peripherals/pwm.d.ts +65 -65
  137. package/dist/esm/peripherals/pwm.js +368 -368
  138. package/dist/esm/peripherals/reset.d.ts +8 -8
  139. package/dist/esm/peripherals/reset.js +36 -36
  140. package/dist/esm/peripherals/rtc.d.ts +10 -10
  141. package/dist/esm/peripherals/rtc.js +70 -70
  142. package/dist/esm/peripherals/spi.d.ts +38 -30
  143. package/dist/esm/peripherals/spi.js +236 -214
  144. package/dist/esm/peripherals/ssi.d.ts +6 -6
  145. package/dist/esm/peripherals/ssi.js +39 -39
  146. package/dist/esm/peripherals/syscfg.d.ts +5 -5
  147. package/dist/esm/peripherals/syscfg.js +22 -22
  148. package/dist/esm/peripherals/sysinfo.d.ts +4 -4
  149. package/dist/esm/peripherals/sysinfo.js +18 -18
  150. package/dist/esm/peripherals/tbman.d.ts +4 -4
  151. package/dist/esm/peripherals/tbman.js +13 -13
  152. package/dist/esm/peripherals/timer.d.ts +18 -18
  153. package/dist/esm/peripherals/timer.js +152 -152
  154. package/dist/esm/peripherals/uart.d.ts +31 -28
  155. package/dist/esm/peripherals/uart.js +128 -131
  156. package/dist/esm/peripherals/usb.d.ts +29 -29
  157. package/dist/esm/peripherals/usb.js +305 -305
  158. package/dist/esm/rp2040.d.ts +71 -71
  159. package/dist/esm/rp2040.js +357 -342
  160. package/dist/esm/sio.d.ts +21 -21
  161. package/dist/esm/sio.js +421 -421
  162. package/dist/esm/usb/cdc.d.ts +20 -20
  163. package/dist/esm/usb/cdc.js +121 -121
  164. package/dist/esm/usb/interfaces.d.ts +47 -47
  165. package/dist/esm/usb/interfaces.js +43 -43
  166. package/dist/esm/usb/setup.d.ts +5 -5
  167. package/dist/esm/usb/setup.js +46 -46
  168. package/dist/esm/utils/assembler.d.ts +79 -79
  169. package/dist/esm/utils/assembler.js +245 -245
  170. package/dist/esm/utils/bit.d.ts +3 -3
  171. package/dist/esm/utils/bit.js +9 -9
  172. package/dist/esm/utils/fifo.d.ts +15 -15
  173. package/dist/esm/utils/fifo.js +52 -52
  174. package/dist/esm/utils/logging.d.ts +23 -23
  175. package/dist/esm/utils/logging.js +44 -44
  176. package/dist/esm/utils/pio-assembler.d.ts +45 -45
  177. package/dist/esm/utils/pio-assembler.js +75 -75
  178. package/dist/esm/utils/time.d.ts +2 -2
  179. package/dist/esm/utils/time.js +27 -27
  180. package/dist/esm/utils/timer32.d.ts +57 -57
  181. package/dist/esm/utils/timer32.js +203 -203
  182. package/package.json +34 -22
  183. package/dist/esm/package.json +0 -1
@@ -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
+ }
@@ -1,126 +1,126 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.USBCDC = exports.extractEndpointNumbers = void 0;
4
- const fifo_1 = require("../utils/fifo");
5
- const interfaces_1 = require("./interfaces");
6
- const setup_1 = require("./setup");
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_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_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_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(setup_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(setup_1.getDescriptorPacket(interfaces_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_1.DescriptorType.Configration &&
81
- this.descriptorsSize == null) {
82
- this.descriptorsSize = (buffer[3] << 8) | buffer[2];
83
- this.usb.sendSetupPacket(setup_1.getDescriptorPacket(interfaces_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(setup_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(setup_1.createSetupPacket({
112
- dataDirection: interfaces_1.DataDirection.HostToDevice,
113
- type: interfaces_1.SetupType.Class,
114
- recipient: interfaces_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
+ "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 = exports.DataDirection || (exports.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 || (exports.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 || (exports.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 || (exports.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 || (exports.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 = {}));
@@ -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;
@@ -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 interfaces_1 = require("./interfaces");
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_1.DataDirection.HostToDevice,
21
- type: interfaces_1.SetupType.Standard,
22
- recipient: interfaces_1.SetupRecipient.Device,
23
- bRequest: interfaces_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_1.DataDirection.DeviceToHost,
33
- type: interfaces_1.SetupType.Standard,
34
- recipient: interfaces_1.SetupRecipient.Device,
35
- bRequest: interfaces_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_1.DataDirection.HostToDevice,
45
- type: interfaces_1.SetupType.Standard,
46
- recipient: interfaces_1.SetupRecipient.Device,
47
- bRequest: interfaces_1.SetupRequest.SetDeviceConfiguration,
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;