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,48 +1,48 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gdbMessage = exports.gdbChecksum = exports.decodeHexUint32 = exports.decodeHexUint32Array = exports.decodeHexBuf = exports.encodeHexUint32 = exports.encodeHexUint32BE = exports.encodeHexBuf = exports.encodeHexByte = void 0;
4
- function encodeHexByte(value) {
5
- return (value >> 4).toString(16) + (value & 0xf).toString(16);
6
- }
7
- exports.encodeHexByte = encodeHexByte;
8
- function encodeHexBuf(buf) {
9
- return Array.from(buf).map(encodeHexByte).join('');
10
- }
11
- exports.encodeHexBuf = encodeHexBuf;
12
- function encodeHexUint32BE(value) {
13
- return encodeHexBuf(new Uint8Array([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]));
14
- }
15
- exports.encodeHexUint32BE = encodeHexUint32BE;
16
- function encodeHexUint32(value) {
17
- const buf = new Uint32Array([value]);
18
- return encodeHexBuf(new Uint8Array(buf.buffer));
19
- }
20
- exports.encodeHexUint32 = encodeHexUint32;
21
- function decodeHexBuf(encoded) {
22
- const result = new Uint8Array(encoded.length / 2);
23
- for (let i = 0; i < result.length; i++) {
24
- result[i] = parseInt(encoded.substr(i * 2, 2), 16);
25
- }
26
- return result;
27
- }
28
- exports.decodeHexBuf = decodeHexBuf;
29
- function decodeHexUint32Array(encoded) {
30
- return new Uint32Array(decodeHexBuf(encoded).buffer);
31
- }
32
- exports.decodeHexUint32Array = decodeHexUint32Array;
33
- function decodeHexUint32(encoded) {
34
- return decodeHexUint32Array(encoded)[0];
35
- }
36
- exports.decodeHexUint32 = decodeHexUint32;
37
- function gdbChecksum(text) {
38
- const value = text
39
- .split('')
40
- .map((c) => c.charCodeAt(0))
41
- .reduce((a, b) => a + b, 0) & 0xff;
42
- return encodeHexByte(value);
43
- }
44
- exports.gdbChecksum = gdbChecksum;
45
- function gdbMessage(value) {
46
- return `$${value}#${gdbChecksum(value)}`;
47
- }
48
- exports.gdbMessage = gdbMessage;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gdbMessage = exports.gdbChecksum = exports.decodeHexUint32 = exports.decodeHexUint32Array = exports.decodeHexBuf = exports.encodeHexUint32 = exports.encodeHexUint32BE = exports.encodeHexBuf = exports.encodeHexByte = void 0;
4
+ function encodeHexByte(value) {
5
+ return (value >> 4).toString(16) + (value & 0xf).toString(16);
6
+ }
7
+ exports.encodeHexByte = encodeHexByte;
8
+ function encodeHexBuf(buf) {
9
+ return Array.from(buf).map(encodeHexByte).join('');
10
+ }
11
+ exports.encodeHexBuf = encodeHexBuf;
12
+ function encodeHexUint32BE(value) {
13
+ return encodeHexBuf(new Uint8Array([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]));
14
+ }
15
+ exports.encodeHexUint32BE = encodeHexUint32BE;
16
+ function encodeHexUint32(value) {
17
+ const buf = new Uint32Array([value]);
18
+ return encodeHexBuf(new Uint8Array(buf.buffer));
19
+ }
20
+ exports.encodeHexUint32 = encodeHexUint32;
21
+ function decodeHexBuf(encoded) {
22
+ const result = new Uint8Array(encoded.length / 2);
23
+ for (let i = 0; i < result.length; i++) {
24
+ result[i] = parseInt(encoded.substr(i * 2, 2), 16);
25
+ }
26
+ return result;
27
+ }
28
+ exports.decodeHexBuf = decodeHexBuf;
29
+ function decodeHexUint32Array(encoded) {
30
+ return new Uint32Array(decodeHexBuf(encoded).buffer);
31
+ }
32
+ exports.decodeHexUint32Array = decodeHexUint32Array;
33
+ function decodeHexUint32(encoded) {
34
+ return decodeHexUint32Array(encoded)[0];
35
+ }
36
+ exports.decodeHexUint32 = decodeHexUint32;
37
+ function gdbChecksum(text) {
38
+ const value = text
39
+ .split('')
40
+ .map((c) => c.charCodeAt(0))
41
+ .reduce((a, b) => a + b, 0) & 0xff;
42
+ return encodeHexByte(value);
43
+ }
44
+ exports.gdbChecksum = gdbChecksum;
45
+ function gdbMessage(value) {
46
+ return `$${value}#${gdbChecksum(value)}`;
47
+ }
48
+ exports.gdbMessage = gdbMessage;
@@ -1,56 +1,56 @@
1
- import { RP2040 } from './rp2040';
2
- export declare enum GPIOPinState {
3
- Low = 0,
4
- High = 1,
5
- Input = 2,
6
- InputPullUp = 3,
7
- InputPullDown = 4
8
- }
9
- export declare const FUNCTION_PWM = 4;
10
- export declare const FUNCTION_SIO = 5;
11
- export declare const FUNCTION_PIO0 = 6;
12
- export declare const FUNCTION_PIO1 = 7;
13
- export declare type GPIOPinListener = (state: GPIOPinState, oldState: GPIOPinState) => void;
14
- export declare class GPIOPin {
15
- readonly rp2040: RP2040;
16
- readonly index: number;
17
- readonly name: string;
18
- private rawInputValue;
19
- private lastValue;
20
- ctrl: number;
21
- padValue: number;
22
- irqEnableMask: number;
23
- irqForceMask: number;
24
- irqStatus: number;
25
- private readonly listeners;
26
- constructor(rp2040: RP2040, index: number, name?: string);
27
- get rawInterrupt(): boolean;
28
- get isSlewFast(): boolean;
29
- get schmittEnabled(): boolean;
30
- get pulldownEnabled(): boolean;
31
- get pullupEnabled(): boolean;
32
- get driveStrength(): number;
33
- get inputEnable(): boolean;
34
- get outputDisable(): boolean;
35
- get functionSelect(): number;
36
- get outputOverride(): number;
37
- get outputEnableOverride(): number;
38
- get inputOverride(): number;
39
- get irqOverride(): number;
40
- get rawOutputEnable(): boolean;
41
- get rawOutputValue(): boolean;
42
- get inputValue(): boolean;
43
- get irqValue(): boolean;
44
- get outputEnable(): boolean;
45
- get outputValue(): boolean;
46
- /**
47
- * Returns the STATUS register value for the pin, as outlined in section 2.19.6 of the datasheet
48
- */
49
- get status(): number;
50
- get value(): GPIOPinState;
51
- setInputValue(value: boolean): void;
52
- checkForUpdates(): void;
53
- refreshInput(): void;
54
- updateIRQValue(value: number): void;
55
- addListener(callback: GPIOPinListener): () => boolean;
56
- }
1
+ import { RP2040 } from './rp2040.js';
2
+ export declare enum GPIOPinState {
3
+ Low = 0,
4
+ High = 1,
5
+ Input = 2,
6
+ InputPullUp = 3,
7
+ InputPullDown = 4
8
+ }
9
+ export declare const FUNCTION_PWM = 4;
10
+ export declare const FUNCTION_SIO = 5;
11
+ export declare const FUNCTION_PIO0 = 6;
12
+ export declare const FUNCTION_PIO1 = 7;
13
+ export type GPIOPinListener = (state: GPIOPinState, oldState: GPIOPinState) => void;
14
+ export declare class GPIOPin {
15
+ readonly rp2040: RP2040;
16
+ readonly index: number;
17
+ readonly name: string;
18
+ private rawInputValue;
19
+ private lastValue;
20
+ ctrl: number;
21
+ padValue: number;
22
+ irqEnableMask: number;
23
+ irqForceMask: number;
24
+ irqStatus: number;
25
+ private readonly listeners;
26
+ constructor(rp2040: RP2040, index: number, name?: string);
27
+ get rawInterrupt(): boolean;
28
+ get isSlewFast(): boolean;
29
+ get schmittEnabled(): boolean;
30
+ get pulldownEnabled(): boolean;
31
+ get pullupEnabled(): boolean;
32
+ get driveStrength(): number;
33
+ get inputEnable(): boolean;
34
+ get outputDisable(): boolean;
35
+ get functionSelect(): number;
36
+ get outputOverride(): number;
37
+ get outputEnableOverride(): number;
38
+ get inputOverride(): number;
39
+ get irqOverride(): number;
40
+ get rawOutputEnable(): boolean;
41
+ get rawOutputValue(): boolean;
42
+ get inputValue(): boolean;
43
+ get irqValue(): boolean;
44
+ get outputEnable(): boolean;
45
+ get outputValue(): boolean;
46
+ /**
47
+ * Returns the STATUS register value for the pin, as outlined in section 2.19.6 of the datasheet
48
+ */
49
+ get status(): number;
50
+ get value(): GPIOPinState;
51
+ setInputValue(value: boolean): void;
52
+ checkForUpdates(): void;
53
+ refreshInput(): void;
54
+ updateIRQValue(value: number): void;
55
+ addListener(callback: GPIOPinListener): () => boolean;
56
+ }
@@ -1,216 +1,216 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GPIOPin = exports.FUNCTION_PIO1 = exports.FUNCTION_PIO0 = exports.FUNCTION_SIO = exports.FUNCTION_PWM = exports.GPIOPinState = void 0;
4
- const pio_1 = require("./peripherals/pio");
5
- var GPIOPinState;
6
- (function (GPIOPinState) {
7
- GPIOPinState[GPIOPinState["Low"] = 0] = "Low";
8
- GPIOPinState[GPIOPinState["High"] = 1] = "High";
9
- GPIOPinState[GPIOPinState["Input"] = 2] = "Input";
10
- GPIOPinState[GPIOPinState["InputPullUp"] = 3] = "InputPullUp";
11
- GPIOPinState[GPIOPinState["InputPullDown"] = 4] = "InputPullDown";
12
- })(GPIOPinState = exports.GPIOPinState || (exports.GPIOPinState = {}));
13
- exports.FUNCTION_PWM = 4;
14
- exports.FUNCTION_SIO = 5;
15
- exports.FUNCTION_PIO0 = 6;
16
- exports.FUNCTION_PIO1 = 7;
17
- function applyOverride(value, overrideType) {
18
- switch (overrideType) {
19
- case 0:
20
- return value;
21
- case 1:
22
- return !value;
23
- case 2:
24
- return false;
25
- case 3:
26
- return true;
27
- }
28
- console.error('applyOverride received invalid override type', overrideType);
29
- return value;
30
- }
31
- const IRQ_EDGE_HIGH = 1 << 3;
32
- const IRQ_EDGE_LOW = 1 << 2;
33
- const IRQ_LEVEL_HIGH = 1 << 1;
34
- const IRQ_LEVEL_LOW = 1 << 0;
35
- class GPIOPin {
36
- constructor(rp2040, index, name = index.toString()) {
37
- this.rp2040 = rp2040;
38
- this.index = index;
39
- this.name = name;
40
- this.rawInputValue = false;
41
- this.lastValue = this.value;
42
- this.ctrl = 0x1f;
43
- this.padValue = 0b0110110;
44
- this.irqEnableMask = 0;
45
- this.irqForceMask = 0;
46
- this.irqStatus = 0;
47
- this.listeners = new Set();
48
- }
49
- get rawInterrupt() {
50
- return !!((this.irqStatus & this.irqEnableMask) | this.irqForceMask);
51
- }
52
- get isSlewFast() {
53
- return !!(this.padValue & 1);
54
- }
55
- get schmittEnabled() {
56
- return !!(this.padValue & 2);
57
- }
58
- get pulldownEnabled() {
59
- return !!(this.padValue & 4);
60
- }
61
- get pullupEnabled() {
62
- return !!(this.padValue & 8);
63
- }
64
- get driveStrength() {
65
- return (this.padValue >> 4) & 0x3;
66
- }
67
- get inputEnable() {
68
- return !!(this.padValue & 0x40);
69
- }
70
- get outputDisable() {
71
- return !!(this.padValue & 0x80);
72
- }
73
- get functionSelect() {
74
- return this.ctrl & 0x1f;
75
- }
76
- get outputOverride() {
77
- return (this.ctrl >> 8) & 0x3;
78
- }
79
- get outputEnableOverride() {
80
- return (this.ctrl >> 12) & 0x3;
81
- }
82
- get inputOverride() {
83
- return (this.ctrl >> 16) & 0x3;
84
- }
85
- get irqOverride() {
86
- return (this.ctrl >> 28) & 0x3;
87
- }
88
- get rawOutputEnable() {
89
- const { index, rp2040, functionSelect } = this;
90
- const bitmask = 1 << index;
91
- switch (functionSelect) {
92
- case exports.FUNCTION_PWM:
93
- return !!(rp2040.pwm.gpioDirection & bitmask);
94
- case exports.FUNCTION_SIO:
95
- return !!(rp2040.sio.gpioOutputEnable & bitmask);
96
- case exports.FUNCTION_PIO0:
97
- return !!(rp2040.pio[0].pinDirections & bitmask);
98
- case exports.FUNCTION_PIO1:
99
- return !!(rp2040.pio[1].pinDirections & bitmask);
100
- default:
101
- return false;
102
- }
103
- }
104
- get rawOutputValue() {
105
- const { index, rp2040, functionSelect } = this;
106
- const bitmask = 1 << index;
107
- switch (functionSelect) {
108
- case exports.FUNCTION_PWM:
109
- return !!(rp2040.pwm.gpioValue & bitmask);
110
- case exports.FUNCTION_SIO:
111
- return !!(rp2040.sio.gpioValue & bitmask);
112
- case exports.FUNCTION_PIO0:
113
- return !!(rp2040.pio[0].pinValues & bitmask);
114
- case exports.FUNCTION_PIO1:
115
- return !!(rp2040.pio[1].pinValues & bitmask);
116
- default:
117
- return false;
118
- }
119
- }
120
- get inputValue() {
121
- return applyOverride(this.rawInputValue && this.inputEnable, this.inputOverride);
122
- }
123
- get irqValue() {
124
- return applyOverride(this.rawInterrupt, this.irqOverride);
125
- }
126
- get outputEnable() {
127
- return applyOverride(this.rawOutputEnable, this.outputEnableOverride);
128
- }
129
- get outputValue() {
130
- return applyOverride(this.rawOutputValue, this.outputOverride);
131
- }
132
- /**
133
- * Returns the STATUS register value for the pin, as outlined in section 2.19.6 of the datasheet
134
- */
135
- get status() {
136
- const irqToProc = this.irqValue ? 1 << 26 : 0;
137
- const irqFromPad = this.rawInterrupt ? 1 << 24 : 0;
138
- const inToPeri = this.inputValue ? 1 << 19 : 0;
139
- const inFromPad = this.rawInputValue ? 1 << 17 : 0;
140
- const oeToPad = this.outputEnable ? 1 << 13 : 0;
141
- const oeFromPeri = this.rawOutputEnable ? 1 << 12 : 0;
142
- const outToPad = this.outputValue ? 1 << 9 : 0;
143
- const outFromPeri = this.rawOutputValue ? 1 << 8 : 0;
144
- return (irqToProc | irqFromPad | inToPeri | inFromPad | oeToPad | oeFromPeri | outToPad | outFromPeri);
145
- }
146
- get value() {
147
- if (this.outputEnable) {
148
- return this.outputValue ? GPIOPinState.High : GPIOPinState.Low;
149
- }
150
- else {
151
- // TODO: check what happens when we enable both pullup/pulldown
152
- if (this.pulldownEnabled) {
153
- return GPIOPinState.InputPullDown;
154
- }
155
- if (this.pullupEnabled) {
156
- return GPIOPinState.InputPullUp;
157
- }
158
- return GPIOPinState.Input;
159
- }
160
- }
161
- setInputValue(value) {
162
- this.rawInputValue = value;
163
- const prevIrqValue = this.irqValue;
164
- if (value && this.inputEnable) {
165
- this.irqStatus |= IRQ_EDGE_HIGH | IRQ_LEVEL_HIGH;
166
- this.irqStatus &= ~IRQ_LEVEL_LOW;
167
- }
168
- else {
169
- this.irqStatus |= IRQ_EDGE_LOW | IRQ_LEVEL_LOW;
170
- this.irqStatus &= ~IRQ_LEVEL_HIGH;
171
- }
172
- if (this.irqValue !== prevIrqValue) {
173
- this.rp2040.updateIOInterrupt();
174
- }
175
- if (this.functionSelect === exports.FUNCTION_PWM) {
176
- this.rp2040.pwm.gpioOnInput(this.index);
177
- }
178
- for (const pio of this.rp2040.pio) {
179
- for (const machine of pio.machines) {
180
- if (machine.enabled &&
181
- machine.waiting &&
182
- machine.waitType === pio_1.WaitType.Pin &&
183
- machine.waitIndex === this.index) {
184
- machine.checkWait();
185
- }
186
- }
187
- }
188
- }
189
- checkForUpdates() {
190
- const { lastValue, value } = this;
191
- if (value !== lastValue) {
192
- this.lastValue = value;
193
- for (const listener of this.listeners) {
194
- listener(value, lastValue);
195
- }
196
- }
197
- }
198
- refreshInput() {
199
- this.setInputValue(this.rawInputValue);
200
- }
201
- updateIRQValue(value) {
202
- if (value & IRQ_EDGE_LOW && this.irqStatus & IRQ_EDGE_LOW) {
203
- this.irqStatus &= ~IRQ_EDGE_LOW;
204
- this.rp2040.updateIOInterrupt();
205
- }
206
- if (value & IRQ_EDGE_HIGH && this.irqStatus & IRQ_EDGE_HIGH) {
207
- this.irqStatus &= ~IRQ_EDGE_HIGH;
208
- this.rp2040.updateIOInterrupt();
209
- }
210
- }
211
- addListener(callback) {
212
- this.listeners.add(callback);
213
- return () => this.listeners.delete(callback);
214
- }
215
- }
216
- exports.GPIOPin = GPIOPin;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GPIOPin = exports.FUNCTION_PIO1 = exports.FUNCTION_PIO0 = exports.FUNCTION_SIO = exports.FUNCTION_PWM = exports.GPIOPinState = void 0;
4
+ const pio_js_1 = require("./peripherals/pio.js");
5
+ var GPIOPinState;
6
+ (function (GPIOPinState) {
7
+ GPIOPinState[GPIOPinState["Low"] = 0] = "Low";
8
+ GPIOPinState[GPIOPinState["High"] = 1] = "High";
9
+ GPIOPinState[GPIOPinState["Input"] = 2] = "Input";
10
+ GPIOPinState[GPIOPinState["InputPullUp"] = 3] = "InputPullUp";
11
+ GPIOPinState[GPIOPinState["InputPullDown"] = 4] = "InputPullDown";
12
+ })(GPIOPinState || (exports.GPIOPinState = GPIOPinState = {}));
13
+ exports.FUNCTION_PWM = 4;
14
+ exports.FUNCTION_SIO = 5;
15
+ exports.FUNCTION_PIO0 = 6;
16
+ exports.FUNCTION_PIO1 = 7;
17
+ function applyOverride(value, overrideType) {
18
+ switch (overrideType) {
19
+ case 0:
20
+ return value;
21
+ case 1:
22
+ return !value;
23
+ case 2:
24
+ return false;
25
+ case 3:
26
+ return true;
27
+ }
28
+ console.error('applyOverride received invalid override type', overrideType);
29
+ return value;
30
+ }
31
+ const IRQ_EDGE_HIGH = 1 << 3;
32
+ const IRQ_EDGE_LOW = 1 << 2;
33
+ const IRQ_LEVEL_HIGH = 1 << 1;
34
+ const IRQ_LEVEL_LOW = 1 << 0;
35
+ class GPIOPin {
36
+ constructor(rp2040, index, name = index.toString()) {
37
+ this.rp2040 = rp2040;
38
+ this.index = index;
39
+ this.name = name;
40
+ this.rawInputValue = false;
41
+ this.lastValue = this.value;
42
+ this.ctrl = 0x1f;
43
+ this.padValue = 0b0110110;
44
+ this.irqEnableMask = 0;
45
+ this.irqForceMask = 0;
46
+ this.irqStatus = 0;
47
+ this.listeners = new Set();
48
+ }
49
+ get rawInterrupt() {
50
+ return !!((this.irqStatus & this.irqEnableMask) | this.irqForceMask);
51
+ }
52
+ get isSlewFast() {
53
+ return !!(this.padValue & 1);
54
+ }
55
+ get schmittEnabled() {
56
+ return !!(this.padValue & 2);
57
+ }
58
+ get pulldownEnabled() {
59
+ return !!(this.padValue & 4);
60
+ }
61
+ get pullupEnabled() {
62
+ return !!(this.padValue & 8);
63
+ }
64
+ get driveStrength() {
65
+ return (this.padValue >> 4) & 0x3;
66
+ }
67
+ get inputEnable() {
68
+ return !!(this.padValue & 0x40);
69
+ }
70
+ get outputDisable() {
71
+ return !!(this.padValue & 0x80);
72
+ }
73
+ get functionSelect() {
74
+ return this.ctrl & 0x1f;
75
+ }
76
+ get outputOverride() {
77
+ return (this.ctrl >> 8) & 0x3;
78
+ }
79
+ get outputEnableOverride() {
80
+ return (this.ctrl >> 12) & 0x3;
81
+ }
82
+ get inputOverride() {
83
+ return (this.ctrl >> 16) & 0x3;
84
+ }
85
+ get irqOverride() {
86
+ return (this.ctrl >> 28) & 0x3;
87
+ }
88
+ get rawOutputEnable() {
89
+ const { index, rp2040, functionSelect } = this;
90
+ const bitmask = 1 << index;
91
+ switch (functionSelect) {
92
+ case exports.FUNCTION_PWM:
93
+ return !!(rp2040.pwm.gpioDirection & bitmask);
94
+ case exports.FUNCTION_SIO:
95
+ return !!(rp2040.sio.gpioOutputEnable & bitmask);
96
+ case exports.FUNCTION_PIO0:
97
+ return !!(rp2040.pio[0].pinDirections & bitmask);
98
+ case exports.FUNCTION_PIO1:
99
+ return !!(rp2040.pio[1].pinDirections & bitmask);
100
+ default:
101
+ return false;
102
+ }
103
+ }
104
+ get rawOutputValue() {
105
+ const { index, rp2040, functionSelect } = this;
106
+ const bitmask = 1 << index;
107
+ switch (functionSelect) {
108
+ case exports.FUNCTION_PWM:
109
+ return !!(rp2040.pwm.gpioValue & bitmask);
110
+ case exports.FUNCTION_SIO:
111
+ return !!(rp2040.sio.gpioValue & bitmask);
112
+ case exports.FUNCTION_PIO0:
113
+ return !!(rp2040.pio[0].pinValues & bitmask);
114
+ case exports.FUNCTION_PIO1:
115
+ return !!(rp2040.pio[1].pinValues & bitmask);
116
+ default:
117
+ return false;
118
+ }
119
+ }
120
+ get inputValue() {
121
+ return applyOverride(this.rawInputValue && this.inputEnable, this.inputOverride);
122
+ }
123
+ get irqValue() {
124
+ return applyOverride(this.rawInterrupt, this.irqOverride);
125
+ }
126
+ get outputEnable() {
127
+ return applyOverride(this.rawOutputEnable, this.outputEnableOverride);
128
+ }
129
+ get outputValue() {
130
+ return applyOverride(this.rawOutputValue, this.outputOverride);
131
+ }
132
+ /**
133
+ * Returns the STATUS register value for the pin, as outlined in section 2.19.6 of the datasheet
134
+ */
135
+ get status() {
136
+ const irqToProc = this.irqValue ? 1 << 26 : 0;
137
+ const irqFromPad = this.rawInterrupt ? 1 << 24 : 0;
138
+ const inToPeri = this.inputValue ? 1 << 19 : 0;
139
+ const inFromPad = this.rawInputValue ? 1 << 17 : 0;
140
+ const oeToPad = this.outputEnable ? 1 << 13 : 0;
141
+ const oeFromPeri = this.rawOutputEnable ? 1 << 12 : 0;
142
+ const outToPad = this.outputValue ? 1 << 9 : 0;
143
+ const outFromPeri = this.rawOutputValue ? 1 << 8 : 0;
144
+ return (irqToProc | irqFromPad | inToPeri | inFromPad | oeToPad | oeFromPeri | outToPad | outFromPeri);
145
+ }
146
+ get value() {
147
+ if (this.outputEnable) {
148
+ return this.outputValue ? GPIOPinState.High : GPIOPinState.Low;
149
+ }
150
+ else {
151
+ // TODO: check what happens when we enable both pullup/pulldown
152
+ if (this.pulldownEnabled) {
153
+ return GPIOPinState.InputPullDown;
154
+ }
155
+ if (this.pullupEnabled) {
156
+ return GPIOPinState.InputPullUp;
157
+ }
158
+ return GPIOPinState.Input;
159
+ }
160
+ }
161
+ setInputValue(value) {
162
+ this.rawInputValue = value;
163
+ const prevIrqValue = this.irqValue;
164
+ if (value && this.inputEnable) {
165
+ this.irqStatus |= IRQ_EDGE_HIGH | IRQ_LEVEL_HIGH;
166
+ this.irqStatus &= ~IRQ_LEVEL_LOW;
167
+ }
168
+ else {
169
+ this.irqStatus |= IRQ_EDGE_LOW | IRQ_LEVEL_LOW;
170
+ this.irqStatus &= ~IRQ_LEVEL_HIGH;
171
+ }
172
+ if (this.irqValue !== prevIrqValue) {
173
+ this.rp2040.updateIOInterrupt();
174
+ }
175
+ if (this.functionSelect === exports.FUNCTION_PWM) {
176
+ this.rp2040.pwm.gpioOnInput(this.index);
177
+ }
178
+ for (const pio of this.rp2040.pio) {
179
+ for (const machine of pio.machines) {
180
+ if (machine.enabled &&
181
+ machine.waiting &&
182
+ machine.waitType === pio_js_1.WaitType.Pin &&
183
+ machine.waitIndex === this.index) {
184
+ machine.checkWait();
185
+ }
186
+ }
187
+ }
188
+ }
189
+ checkForUpdates() {
190
+ const { lastValue, value } = this;
191
+ if (value !== lastValue) {
192
+ this.lastValue = value;
193
+ for (const listener of this.listeners) {
194
+ listener(value, lastValue);
195
+ }
196
+ }
197
+ }
198
+ refreshInput() {
199
+ this.setInputValue(this.rawInputValue);
200
+ }
201
+ updateIRQValue(value) {
202
+ if (value & IRQ_EDGE_LOW && this.irqStatus & IRQ_EDGE_LOW) {
203
+ this.irqStatus &= ~IRQ_EDGE_LOW;
204
+ this.rp2040.updateIOInterrupt();
205
+ }
206
+ if (value & IRQ_EDGE_HIGH && this.irqStatus & IRQ_EDGE_HIGH) {
207
+ this.irqStatus &= ~IRQ_EDGE_HIGH;
208
+ this.rp2040.updateIOInterrupt();
209
+ }
210
+ }
211
+ addListener(callback) {
212
+ this.listeners.add(callback);
213
+ return () => this.listeners.delete(callback);
214
+ }
215
+ }
216
+ exports.GPIOPin = GPIOPin;
@@ -1,11 +1,11 @@
1
- export { GDBConnection } from './gdb/gdb-connection';
2
- export { GDBServer } from './gdb/gdb-server';
3
- export { GPIOPin, GPIOPinState } from './gpio-pin';
4
- export { BasePeripheral, Peripheral } from './peripherals/peripheral';
5
- export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c';
6
- export { RPUSBController } from './peripherals/usb';
7
- export { RP2040 } from './rp2040';
8
- export { USBCDC } from './usb/cdc';
9
- export { DataDirection, DescriptorType, ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces';
10
- export { createSetupPacket, getDescriptorPacket, setDeviceAddressPacket, setDeviceConfigurationPacket, } from './usb/setup';
11
- export { ConsoleLogger, Logger, LogLevel } from './utils/logging';
1
+ export { GDBConnection } from './gdb/gdb-connection.js';
2
+ export { GDBServer } from './gdb/gdb-server.js';
3
+ export { GPIOPin, GPIOPinState } from './gpio-pin.js';
4
+ export { BasePeripheral, Peripheral } from './peripherals/peripheral.js';
5
+ export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c.js';
6
+ export { RPUSBController } from './peripherals/usb.js';
7
+ export { RP2040 } from './rp2040.js';
8
+ export { USBCDC } from './usb/cdc.js';
9
+ export { DataDirection, DescriptorType, ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces.js';
10
+ export { createSetupPacket, getDescriptorPacket, setDeviceAddressPacket, setDeviceConfigurationPacket, } from './usb/setup.js';
11
+ export { ConsoleLogger, Logger, LogLevel } from './utils/logging.js';