rp2040js 1.0.1 → 1.1.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 (47) hide show
  1. package/README.md +9 -0
  2. package/dist/cjs/cortex-m0-core.d.ts +1 -1
  3. package/dist/cjs/gdb/gdb-tcp-server.d.ts +0 -1
  4. package/dist/cjs/gdb/gdb-utils.d.ts +2 -2
  5. package/dist/cjs/gdb/gdb-utils.js +9 -10
  6. package/dist/cjs/gpio-pin.d.ts +2 -1
  7. package/dist/cjs/gpio-pin.js +8 -2
  8. package/dist/cjs/peripherals/clocks.d.ts +18 -0
  9. package/dist/cjs/peripherals/clocks.js +160 -2
  10. package/dist/cjs/peripherals/i2c.d.ts +1 -0
  11. package/dist/cjs/peripherals/i2c.js +20 -0
  12. package/dist/cjs/peripherals/peripheral.js +4 -4
  13. package/dist/cjs/peripherals/pio.d.ts +1 -1
  14. package/dist/cjs/peripherals/ssi.d.ts +9 -0
  15. package/dist/cjs/peripherals/ssi.js +76 -3
  16. package/dist/cjs/peripherals/usb.d.ts +1 -0
  17. package/dist/cjs/peripherals/usb.js +7 -0
  18. package/dist/cjs/peripherals/watchdog.d.ts +1 -1
  19. package/dist/cjs/rp2040.d.ts +8 -8
  20. package/dist/cjs/usb/cdc.js +2 -2
  21. package/dist/cjs/usb/setup.d.ts +4 -4
  22. package/dist/cjs/usb/setup.js +4 -5
  23. package/dist/cjs/utils/assembler.js +79 -81
  24. package/dist/cjs/utils/bit.js +3 -4
  25. package/dist/cjs/utils/pio-assembler.js +10 -10
  26. package/dist/cjs/utils/time.js +2 -3
  27. package/dist/cjs/utils/timer32.js +1 -1
  28. package/dist/esm/cortex-m0-core.d.ts +1 -1
  29. package/dist/esm/gdb/gdb-tcp-server.d.ts +0 -1
  30. package/dist/esm/gdb/gdb-utils.d.ts +2 -2
  31. package/dist/esm/gpio-pin.d.ts +2 -1
  32. package/dist/esm/gpio-pin.js +8 -2
  33. package/dist/esm/peripherals/clocks.d.ts +18 -0
  34. package/dist/esm/peripherals/clocks.js +160 -2
  35. package/dist/esm/peripherals/i2c.d.ts +1 -0
  36. package/dist/esm/peripherals/i2c.js +20 -0
  37. package/dist/esm/peripherals/peripheral.js +2 -2
  38. package/dist/esm/peripherals/pio.d.ts +1 -1
  39. package/dist/esm/peripherals/ssi.d.ts +9 -0
  40. package/dist/esm/peripherals/ssi.js +76 -3
  41. package/dist/esm/peripherals/usb.d.ts +1 -0
  42. package/dist/esm/peripherals/usb.js +7 -0
  43. package/dist/esm/peripherals/watchdog.d.ts +1 -1
  44. package/dist/esm/rp2040.d.ts +8 -8
  45. package/dist/esm/usb/setup.d.ts +4 -4
  46. package/dist/esm/utils/timer32.js +1 -1
  47. package/package.json +7 -7
package/README.md CHANGED
@@ -28,6 +28,15 @@ npm install
28
28
  npm start
29
29
  ```
30
30
 
31
+ You can also specify the path to the image on the command line and/or load an UF2 image:
32
+
33
+ ```sh
34
+ npm run start -- --image ./my-pico-project.uf2
35
+ ```
36
+
37
+ A GDB server will be available on port 3333, and the data written to UART0 will be printed
38
+ to the console.
39
+
31
40
  ### MicroPython code
32
41
 
33
42
  To run the MicroPython demo, first download [RPI_PICO-20230426-v1.20.0.uf2](https://micropython.org/resources/firmware/RPI_PICO-20230426-v1.20.0.uf2), place it in the rp2040js root directory, then run:
@@ -13,7 +13,7 @@ declare enum StackPointerBank {
13
13
  }
14
14
  export declare class CortexM0Core {
15
15
  readonly rp2040: RP2040;
16
- readonly registers: Uint32Array;
16
+ readonly registers: Uint32Array<ArrayBuffer>;
17
17
  bankedSP: number;
18
18
  cycles: number;
19
19
  eventRegistered: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Socket } from 'net';
3
2
  import { GDBServer } from './gdb-server.js';
4
3
  import { IGDBTarget } from './gdb-target.js';
@@ -2,8 +2,8 @@ export declare function encodeHexByte(value: number): string;
2
2
  export declare function encodeHexBuf(buf: Uint8Array): string;
3
3
  export declare function encodeHexUint32BE(value: number): string;
4
4
  export declare function encodeHexUint32(value: number): string;
5
- export declare function decodeHexBuf(encoded: string): Uint8Array;
6
- export declare function decodeHexUint32Array(encoded: string): Uint32Array;
5
+ export declare function decodeHexBuf(encoded: string): Uint8Array<ArrayBuffer>;
6
+ export declare function decodeHexUint32Array(encoded: string): Uint32Array<ArrayBuffer>;
7
7
  export declare function decodeHexUint32(encoded: string): number;
8
8
  export declare function gdbChecksum(text: string): string;
9
9
  export declare function gdbMessage(value: string): string;
@@ -1,23 +1,27 @@
1
1
  "use strict";
2
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;
3
+ exports.encodeHexByte = encodeHexByte;
4
+ exports.encodeHexBuf = encodeHexBuf;
5
+ exports.encodeHexUint32BE = encodeHexUint32BE;
6
+ exports.encodeHexUint32 = encodeHexUint32;
7
+ exports.decodeHexBuf = decodeHexBuf;
8
+ exports.decodeHexUint32Array = decodeHexUint32Array;
9
+ exports.decodeHexUint32 = decodeHexUint32;
10
+ exports.gdbChecksum = gdbChecksum;
11
+ exports.gdbMessage = gdbMessage;
4
12
  function encodeHexByte(value) {
5
13
  return (value >> 4).toString(16) + (value & 0xf).toString(16);
6
14
  }
7
- exports.encodeHexByte = encodeHexByte;
8
15
  function encodeHexBuf(buf) {
9
16
  return Array.from(buf).map(encodeHexByte).join('');
10
17
  }
11
- exports.encodeHexBuf = encodeHexBuf;
12
18
  function encodeHexUint32BE(value) {
13
19
  return encodeHexBuf(new Uint8Array([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]));
14
20
  }
15
- exports.encodeHexUint32BE = encodeHexUint32BE;
16
21
  function encodeHexUint32(value) {
17
22
  const buf = new Uint32Array([value]);
18
23
  return encodeHexBuf(new Uint8Array(buf.buffer));
19
24
  }
20
- exports.encodeHexUint32 = encodeHexUint32;
21
25
  function decodeHexBuf(encoded) {
22
26
  const result = new Uint8Array(encoded.length / 2);
23
27
  for (let i = 0; i < result.length; i++) {
@@ -25,15 +29,12 @@ function decodeHexBuf(encoded) {
25
29
  }
26
30
  return result;
27
31
  }
28
- exports.decodeHexBuf = decodeHexBuf;
29
32
  function decodeHexUint32Array(encoded) {
30
33
  return new Uint32Array(decodeHexBuf(encoded).buffer);
31
34
  }
32
- exports.decodeHexUint32Array = decodeHexUint32Array;
33
35
  function decodeHexUint32(encoded) {
34
36
  return decodeHexUint32Array(encoded)[0];
35
37
  }
36
- exports.decodeHexUint32 = decodeHexUint32;
37
38
  function gdbChecksum(text) {
38
39
  const value = text
39
40
  .split('')
@@ -41,8 +42,6 @@ function gdbChecksum(text) {
41
42
  .reduce((a, b) => a + b, 0) & 0xff;
42
43
  return encodeHexByte(value);
43
44
  }
44
- exports.gdbChecksum = gdbChecksum;
45
45
  function gdbMessage(value) {
46
46
  return `$${value}#${gdbChecksum(value)}`;
47
47
  }
48
- exports.gdbMessage = gdbMessage;
@@ -4,7 +4,8 @@ export declare enum GPIOPinState {
4
4
  High = 1,
5
5
  Input = 2,
6
6
  InputPullUp = 3,
7
- InputPullDown = 4
7
+ InputPullDown = 4,
8
+ InputBusKeeper = 5
8
9
  }
9
10
  export declare const FUNCTION_PWM = 4;
10
11
  export declare const FUNCTION_SIO = 5;
@@ -9,6 +9,7 @@ var GPIOPinState;
9
9
  GPIOPinState[GPIOPinState["Input"] = 2] = "Input";
10
10
  GPIOPinState[GPIOPinState["InputPullUp"] = 3] = "InputPullUp";
11
11
  GPIOPinState[GPIOPinState["InputPullDown"] = 4] = "InputPullDown";
12
+ GPIOPinState[GPIOPinState["InputBusKeeper"] = 5] = "InputBusKeeper";
12
13
  })(GPIOPinState || (exports.GPIOPinState = GPIOPinState = {}));
13
14
  exports.FUNCTION_PWM = 4;
14
15
  exports.FUNCTION_SIO = 5;
@@ -149,10 +150,15 @@ class GPIOPin {
149
150
  }
150
151
  else {
151
152
  // TODO: check what happens when we enable both pullup/pulldown
152
- if (this.pulldownEnabled) {
153
+ // ANSWER: It is valid, see: 2.19.4.1. Bus Keeper Mode, datasheet p240
154
+ if (this.pulldownEnabled && this.pullupEnabled) {
155
+ // Pull high when high, pull low when low:
156
+ return GPIOPinState.InputBusKeeper;
157
+ }
158
+ else if (this.pulldownEnabled) {
153
159
  return GPIOPinState.InputPullDown;
154
160
  }
155
- if (this.pullupEnabled) {
161
+ else if (this.pullupEnabled) {
156
162
  return GPIOPinState.InputPullUp;
157
163
  }
158
164
  return GPIOPinState.Input;
@@ -1,8 +1,26 @@
1
1
  import { RP2040 } from '../rp2040.js';
2
2
  import { BasePeripheral, Peripheral } from './peripheral.js';
3
3
  export declare class RPClocks extends BasePeripheral implements Peripheral {
4
+ gpout0Ctrl: number;
5
+ gpout0Div: number;
6
+ gpout1Ctrl: number;
7
+ gpout1Div: number;
8
+ gpout2Ctrl: number;
9
+ gpout2Div: number;
10
+ gpout3Ctrl: number;
11
+ gpout3Div: number;
4
12
  refCtrl: number;
13
+ refDiv: number;
14
+ periCtrl: number;
15
+ periDiv: number;
16
+ usbCtrl: number;
17
+ usbDiv: number;
5
18
  sysCtrl: number;
19
+ sysDiv: number;
20
+ adcCtrl: number;
21
+ adcDiv: number;
22
+ rtcCtrl: number;
23
+ rtcDiv: number;
6
24
  constructor(rp2040: RP2040, name: string);
7
25
  readUint32(offset: number): number;
8
26
  writeUint32(offset: number, value: number): void;
@@ -2,37 +2,195 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RPClocks = void 0;
4
4
  const peripheral_js_1 = require("./peripheral.js");
5
+ const CLK_GPOUT0_CTRL = 0x00;
6
+ const CLK_GPOUT0_DIV = 0x04;
7
+ const CLK_GPOUT0_SELECTED = 0x8;
8
+ const CLK_GPOUT1_CTRL = 0x0c;
9
+ const CLK_GPOUT1_DIV = 0x10;
10
+ const CLK_GPOUT1_SELECTED = 0x14;
11
+ const CLK_GPOUT2_CTRL = 0x18;
12
+ const CLK_GPOUT2_DIV = 0x01c;
13
+ const CLK_GPOUT2_SELECTED = 0x20;
14
+ const CLK_GPOUT3_CTRL = 0x24;
15
+ const CLK_GPOUT3_DIV = 0x28;
16
+ const CLK_GPOUT3_SELECTED = 0x2c;
5
17
  const CLK_REF_CTRL = 0x30;
18
+ const CLK_REF_DIV = 0x34;
6
19
  const CLK_REF_SELECTED = 0x38;
7
20
  const CLK_SYS_CTRL = 0x3c;
21
+ const CLK_SYS_DIV = 0x40;
8
22
  const CLK_SYS_SELECTED = 0x44;
23
+ const CLK_PERI_CTRL = 0x48;
24
+ const CLK_PERI_DIV = 0x4c;
25
+ const CLK_PERI_SELECTED = 0x50;
26
+ const CLK_USB_CTRL = 0x54;
27
+ const CLK_USB_DIV = 0x58;
28
+ const CLK_USB_SELECTED = 0x5c;
29
+ const CLK_ADC_CTRL = 0x60;
30
+ const CLK_ADC_DIV = 0x64;
31
+ const CLK_ADC_SELECTED = 0x68;
32
+ const CLK_RTC_CTRL = 0x6c;
33
+ const CLK_RTC_DIV = 0x70;
34
+ const CLK_RTC_SELECTED = 0x74;
35
+ const CLK_SYS_RESUS_CTRL = 0x78;
36
+ const CLK_SYS_RESUS_STATUS = 0x7c;
9
37
  class RPClocks extends peripheral_js_1.BasePeripheral {
10
38
  constructor(rp2040, name) {
11
39
  super(rp2040, name);
40
+ this.gpout0Ctrl = 0;
41
+ this.gpout0Div = 0x100;
42
+ this.gpout1Ctrl = 0;
43
+ this.gpout1Div = 0x100;
44
+ this.gpout2Ctrl = 0;
45
+ this.gpout2Div = 0x100;
46
+ this.gpout3Ctrl = 0;
47
+ this.gpout3Div = 0x100;
12
48
  this.refCtrl = 0;
49
+ this.refDiv = 0x100;
50
+ this.periCtrl = 0;
51
+ this.periDiv = 0x100;
52
+ this.usbCtrl = 0;
53
+ this.usbDiv = 0x100;
13
54
  this.sysCtrl = 0;
55
+ this.sysDiv = 0x100;
56
+ this.adcCtrl = 0;
57
+ this.adcDiv = 0x100;
58
+ this.rtcCtrl = 0;
59
+ this.rtcDiv = 0x100;
14
60
  }
15
61
  readUint32(offset) {
16
62
  switch (offset) {
63
+ case CLK_GPOUT0_CTRL:
64
+ return this.gpout0Ctrl & 0b100110001110111100000;
65
+ case CLK_GPOUT0_DIV:
66
+ return this.gpout0Div;
67
+ case CLK_GPOUT0_SELECTED:
68
+ return 1;
69
+ case CLK_GPOUT1_CTRL:
70
+ return this.gpout1Ctrl & 0b100110001110111100000;
71
+ case CLK_GPOUT1_DIV:
72
+ return this.gpout1Div;
73
+ case CLK_GPOUT1_SELECTED:
74
+ return 1;
75
+ case CLK_GPOUT2_CTRL:
76
+ return this.gpout2Ctrl & 0b100110001110111100000;
77
+ case CLK_GPOUT2_DIV:
78
+ return this.gpout2Div;
79
+ case CLK_GPOUT2_SELECTED:
80
+ return 1;
81
+ case CLK_GPOUT3_CTRL:
82
+ return this.gpout3Ctrl & 0b100110001110111100000;
83
+ case CLK_GPOUT3_DIV:
84
+ return this.gpout3Div;
85
+ case CLK_GPOUT3_SELECTED:
86
+ return 1;
17
87
  case CLK_REF_CTRL:
18
- return this.refCtrl;
88
+ return this.refCtrl & 0b000001100011;
89
+ case CLK_REF_DIV:
90
+ return this.refDiv & 0x30; // b8..9 = int divisor. no frac divisor present
19
91
  case CLK_REF_SELECTED:
20
92
  return 1 << (this.refCtrl & 0x03);
21
93
  case CLK_SYS_CTRL:
22
- return this.sysCtrl;
94
+ return this.sysCtrl & 0b000011100001;
95
+ case CLK_SYS_DIV:
96
+ return this.sysDiv;
23
97
  case CLK_SYS_SELECTED:
24
98
  return 1 << (this.sysCtrl & 0x01);
99
+ case CLK_PERI_CTRL:
100
+ return this.periCtrl & 0b110011100000;
101
+ case CLK_PERI_DIV:
102
+ return this.periDiv;
103
+ case CLK_PERI_SELECTED:
104
+ return 1;
105
+ case CLK_USB_CTRL:
106
+ return this.usbCtrl & 0b100110000110011100000;
107
+ case CLK_USB_DIV:
108
+ return this.usbDiv;
109
+ case CLK_USB_SELECTED:
110
+ return 1;
111
+ case CLK_ADC_CTRL:
112
+ return this.adcCtrl & 0b100110000110011100000;
113
+ case CLK_ADC_DIV:
114
+ return this.adcDiv & 0x30;
115
+ case CLK_ADC_SELECTED:
116
+ return 1;
117
+ case CLK_RTC_CTRL:
118
+ return this.rtcCtrl & 0b100110000110011100000;
119
+ case CLK_RTC_DIV:
120
+ return this.rtcDiv & 0x30;
121
+ case CLK_RTC_SELECTED:
122
+ return 1;
123
+ case CLK_SYS_RESUS_CTRL:
124
+ return 0xff;
125
+ case CLK_SYS_RESUS_STATUS:
126
+ return 0; /* clock resus not implemented */
25
127
  }
26
128
  return super.readUint32(offset);
27
129
  }
28
130
  writeUint32(offset, value) {
29
131
  switch (offset) {
132
+ case CLK_GPOUT0_CTRL:
133
+ this.gpout0Ctrl = value;
134
+ break;
135
+ case CLK_GPOUT0_DIV:
136
+ this.gpout0Div = value;
137
+ break;
138
+ case CLK_GPOUT1_CTRL:
139
+ this.gpout1Ctrl = value;
140
+ break;
141
+ case CLK_GPOUT1_DIV:
142
+ this.gpout1Div = value;
143
+ break;
144
+ case CLK_GPOUT2_CTRL:
145
+ this.gpout2Ctrl = value;
146
+ break;
147
+ case CLK_GPOUT2_DIV:
148
+ this.gpout2Div = value;
149
+ break;
150
+ case CLK_GPOUT3_CTRL:
151
+ this.gpout3Ctrl = value;
152
+ break;
153
+ case CLK_GPOUT3_DIV:
154
+ this.gpout3Div = value;
155
+ break;
30
156
  case CLK_REF_CTRL:
31
157
  this.refCtrl = value;
32
158
  break;
159
+ case CLK_REF_DIV:
160
+ this.refDiv = value;
161
+ break;
33
162
  case CLK_SYS_CTRL:
34
163
  this.sysCtrl = value;
35
164
  break;
165
+ case CLK_SYS_DIV:
166
+ this.sysDiv = value;
167
+ break;
168
+ case CLK_PERI_CTRL:
169
+ this.periCtrl = value;
170
+ break;
171
+ case CLK_PERI_DIV:
172
+ this.periDiv = value;
173
+ break;
174
+ case CLK_USB_CTRL:
175
+ this.usbCtrl = value;
176
+ break;
177
+ case CLK_USB_DIV:
178
+ this.usbDiv = value;
179
+ break;
180
+ case CLK_ADC_CTRL:
181
+ this.adcCtrl = value;
182
+ break;
183
+ case CLK_ADC_DIV:
184
+ this.adcDiv = value;
185
+ break;
186
+ case CLK_RTC_CTRL:
187
+ this.rtcCtrl = value;
188
+ break;
189
+ case CLK_RTC_DIV:
190
+ this.rtcDiv = value;
191
+ break;
192
+ case CLK_SYS_RESUS_CTRL:
193
+ return; /* clock resus not implemented */
36
194
  default:
37
195
  super.writeUint32(offset, value);
38
196
  break;
@@ -37,6 +37,7 @@ export declare class RPI2C extends BasePeripheral implements Peripheral {
37
37
  abortSource: number;
38
38
  intRaw: number;
39
39
  intEnable: number;
40
+ private spikelen;
40
41
  get intStatus(): number;
41
42
  get speed(): I2CSpeed;
42
43
  get sclLowPeriod(): number;
@@ -180,6 +180,7 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
180
180
  this.abortSource = 0;
181
181
  this.intRaw = 0;
182
182
  this.intEnable = 0;
183
+ this.spikelen = 0x07;
183
184
  }
184
185
  checkInterrupts() {
185
186
  this.rp2040.setInterrupt(this.irq, !!this.intStatus);
@@ -396,11 +397,18 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
396
397
  return this.txFIFO.itemCount;
397
398
  case IC_RXFLR:
398
399
  return this.rxFIFO.itemCount;
400
+ case IC_SDA_HOLD:
401
+ return 0x01;
399
402
  case IC_TX_ABRT_SOURCE: {
400
403
  const value = this.abortSource;
401
404
  this.abortSource &= ABRT_SBYTE_NORSTRT; // Clear IC_TX_ABRT_SOURCE, expect for bit 9
402
405
  return value;
403
406
  }
407
+ case IC_ENABLE_STATUS:
408
+ // I2C status - read only. bit 0 reflects IC_ENABLE, bit 1,2 relate to i2c slave mode.
409
+ return this.enable & 0x1;
410
+ case IC_FS_SPKLEN:
411
+ return this.spikelen & 0xff;
404
412
  case IC_COMP_PARAM_1:
405
413
  // From the datasheet:
406
414
  // Note This register is not implemented and therefore reads as 0. If it was implemented it would be a constant read-only
@@ -449,6 +457,13 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
449
457
  case IC_FS_SCL_LCNT:
450
458
  this.fsClockLowPeriod = value & 0xffff;
451
459
  return;
460
+ case IC_SDA_HOLD:
461
+ if (!(value & ENABLE)) {
462
+ if (value != 0x1) {
463
+ this.warn('Unimplemented write to IC_SDA_HOLD');
464
+ }
465
+ }
466
+ return;
452
467
  case IC_RX_TL:
453
468
  this.rxThreshold = value & 0xff;
454
469
  if (this.rxThreshold > this.rxFIFO.size) {
@@ -480,6 +495,11 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
480
495
  this.enable = value;
481
496
  this.nextCommand(); // TX_CMD_BLOCK may have changed
482
497
  return;
498
+ case IC_FS_SPKLEN:
499
+ if (!(value & ENABLE) && value > 0) {
500
+ this.spikelen = value;
501
+ }
502
+ return;
483
503
  default:
484
504
  super.writeUint32(offset, value);
485
505
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnimplementedPeripheral = exports.BasePeripheral = exports.atomicUpdate = void 0;
3
+ exports.UnimplementedPeripheral = exports.BasePeripheral = void 0;
4
+ exports.atomicUpdate = atomicUpdate;
4
5
  const ATOMIC_NORMAL = 0;
5
6
  const ATOMIC_XOR = 1;
6
7
  const ATOMIC_SET = 2;
@@ -18,7 +19,6 @@ function atomicUpdate(currentValue, atomicType, newValue) {
18
19
  return newValue;
19
20
  }
20
21
  }
21
- exports.atomicUpdate = atomicUpdate;
22
22
  class BasePeripheral {
23
23
  constructor(rp2040, name) {
24
24
  this.rp2040 = rp2040;
@@ -26,14 +26,14 @@ class BasePeripheral {
26
26
  this.rawWriteValue = 0;
27
27
  }
28
28
  readUint32(offset) {
29
- this.warn(`Unimplemented peripheral read from ${offset.toString(16)}`);
29
+ this.warn(`Unimplemented peripheral read from 0x${offset.toString(16)}`);
30
30
  if (offset > 0x1000) {
31
31
  this.warn('Unimplemented read from peripheral in the atomic operation region');
32
32
  }
33
33
  return 0xffffffff;
34
34
  }
35
35
  writeUint32(offset, value) {
36
- this.warn(`Unimplemented peripheral write to ${offset.toString(16)}: ${value}`);
36
+ this.warn(`Unimplemented peripheral write to 0x${offset.toString(16)}: 0x${value.toString(16)}`);
37
37
  }
38
38
  writeUint32Atomic(offset, value, atomicType) {
39
39
  this.rawWriteValue = value;
@@ -86,7 +86,7 @@ export declare class StateMachine {
86
86
  export declare class RPPIO extends BasePeripheral implements Peripheral {
87
87
  readonly firstIrq: number;
88
88
  readonly index: number;
89
- readonly instructions: Uint32Array;
89
+ readonly instructions: Uint32Array<ArrayBuffer>;
90
90
  readonly dreqRx: DREQChannel[];
91
91
  readonly dreqTx: DREQChannel[];
92
92
  readonly machines: StateMachine[];
@@ -1,6 +1,15 @@
1
1
  import { BasePeripheral, Peripheral } from './peripheral.js';
2
2
  export declare class RPSSI extends BasePeripheral implements Peripheral {
3
3
  private dr0;
4
+ private txflr;
5
+ private rxflr;
6
+ private baudr;
7
+ private crtlr0;
8
+ private crtlr1;
9
+ private ssienr;
10
+ private spictlr0;
11
+ private rxsampldly;
12
+ private txddriveedge;
4
13
  readUint32(offset: number): number;
5
14
  writeUint32(offset: number, value: number): void;
6
15
  }
@@ -2,34 +2,80 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RPSSI = void 0;
4
4
  const peripheral_js_1 = require("./peripheral.js");
5
+ /* See RP2040 datasheet sect 4.10.13 */
6
+ const SSI_CTRLR0 = 0x00000000;
7
+ const SSI_CTRLR1 = 0x00000004;
8
+ const SSI_SSIENR = 0x00000008;
9
+ const SSI_MWCR = 0x0000000c;
10
+ const SSI_SER = 0x00000010;
11
+ const SSI_BAUDR = 0x00000014;
12
+ const SSI_TXFTLR = 0x00000018;
13
+ const SSI_RXFTLR = 0x0000001c;
5
14
  const SSI_TXFLR = 0x00000020;
6
15
  const SSI_RXFLR = 0x00000024;
7
16
  const SSI_SR = 0x00000028;
8
- const SSI_DR0 = 0x00000060;
9
17
  const SSI_SR_TFNF_BITS = 0x00000002;
10
18
  const SSI_SR_TFE_BITS = 0x00000004;
11
19
  const SSI_SR_RFNE_BITS = 0x00000008;
20
+ const SSI_IMR = 0x0000002c;
21
+ const SSI_ISR = 0x00000030;
22
+ const SSI_RISR = 0x00000034;
23
+ const SSI_TXOICR = 0x00000038;
24
+ const SSI_RXOICR = 0x0000003c;
25
+ const SSI_RXUICR = 0x00000040;
26
+ const SSI_MSTICR = 0x00000044;
27
+ const SSI_ICR = 0x00000048;
28
+ const SSI_DMACR = 0x0000004c;
29
+ const SSI_DMATDLR = 0x00000050;
30
+ const SSI_DMARDLR = 0x00000054;
12
31
  /** Identification register */
13
32
  const SSI_IDR = 0x00000058;
14
33
  const SSI_VERSION_ID = 0x0000005c;
34
+ const SSI_DR0 = 0x00000060;
35
+ const SSI_RX_SAMPLE_DLY = 0x000000f0;
36
+ const SSI_SPI_CTRL_R0 = 0x000000f4;
37
+ const SSI_TXD_DRIVE_EDGE = 0x000000f8;
15
38
  const CMD_READ_STATUS = 0x05;
16
39
  class RPSSI extends peripheral_js_1.BasePeripheral {
17
40
  constructor() {
18
41
  super(...arguments);
19
42
  this.dr0 = 0;
43
+ this.txflr = 0;
44
+ this.rxflr = 0;
45
+ this.baudr = 0;
46
+ this.crtlr0 = 0;
47
+ this.crtlr1 = 0;
48
+ this.ssienr = 0;
49
+ this.spictlr0 = 0;
50
+ this.rxsampldly = 0;
51
+ this.txddriveedge = 0;
20
52
  }
21
53
  readUint32(offset) {
22
54
  switch (offset) {
23
55
  case SSI_TXFLR:
24
- return 0;
56
+ return this.txflr;
25
57
  case SSI_RXFLR:
26
- return 0;
58
+ return this.rxflr;
59
+ case SSI_CTRLR0:
60
+ return this.crtlr0; /* & 0x017FFFFF = b23,b25..31 reserved */
61
+ case SSI_CTRLR1:
62
+ return this.crtlr1;
63
+ case SSI_SSIENR:
64
+ return this.ssienr;
65
+ case SSI_BAUDR:
66
+ return this.baudr;
27
67
  case SSI_SR:
28
68
  return SSI_SR_TFE_BITS | SSI_SR_RFNE_BITS | SSI_SR_TFNF_BITS;
29
69
  case SSI_IDR:
30
70
  return 0x51535049;
31
71
  case SSI_VERSION_ID:
32
72
  return 0x3430312a;
73
+ case SSI_RX_SAMPLE_DLY:
74
+ return this.rxsampldly;
75
+ case SSI_TXD_DRIVE_EDGE:
76
+ return this.txddriveedge;
77
+ case SSI_SPI_CTRL_R0:
78
+ return this.spictlr0; /* b6,7,10,19..23 reserved */
33
79
  case SSI_DR0:
34
80
  return this.dr0;
35
81
  }
@@ -37,6 +83,33 @@ class RPSSI extends peripheral_js_1.BasePeripheral {
37
83
  }
38
84
  writeUint32(offset, value) {
39
85
  switch (offset) {
86
+ case SSI_TXFLR:
87
+ this.txflr = value;
88
+ return;
89
+ case SSI_RXFLR:
90
+ this.rxflr = value;
91
+ return;
92
+ case SSI_CTRLR0:
93
+ this.crtlr0 = value; /* & 0x017FFFFF = b23,b25..31 reserved */
94
+ return;
95
+ case SSI_CTRLR1:
96
+ this.crtlr1 = value;
97
+ return;
98
+ case SSI_SSIENR:
99
+ this.ssienr = value;
100
+ return;
101
+ case SSI_BAUDR:
102
+ this.baudr = value;
103
+ return;
104
+ case SSI_RX_SAMPLE_DLY:
105
+ this.rxsampldly = value & 0xff;
106
+ return;
107
+ case SSI_TXD_DRIVE_EDGE:
108
+ this.txddriveedge = value & 0xff;
109
+ return;
110
+ case SSI_SPI_CTRL_R0:
111
+ this.spictlr0 = value;
112
+ return;
40
113
  case SSI_DR0:
41
114
  if (value === CMD_READ_STATUS) {
42
115
  this.dr0 = 0; // tell stage2 that we completed a write
@@ -1,6 +1,7 @@
1
1
  import { RP2040 } from '../rp2040.js';
2
2
  import { BasePeripheral } from './peripheral.js';
3
3
  export declare class RPUSBController extends BasePeripheral {
4
+ private addrEndp;
4
5
  private mainCtrl;
5
6
  private intRaw;
6
7
  private intEnable;
@@ -20,6 +20,7 @@ const USB_BUF_CTRL_LEN_MASK = 0x3ff;
20
20
  const USB_BUF1_SHIFT = 16;
21
21
  const USB_BUF1_OFFSET = 64;
22
22
  // USB Peripheral Register
23
+ const ADDR_ENDP = 0x0;
23
24
  const MAIN_CTRL = 0x40;
24
25
  const SIE_STATUS = 0x50;
25
26
  const BUFF_STATUS = 0x58;
@@ -97,6 +98,7 @@ class RPUSBController extends peripheral_js_1.BasePeripheral {
97
98
  }
98
99
  constructor(rp2040, name) {
99
100
  super(rp2040, name);
101
+ this.addrEndp = 0;
100
102
  this.mainCtrl = 0;
101
103
  this.intRaw = 0;
102
104
  this.intEnable = 0;
@@ -130,6 +132,8 @@ class RPUSBController extends peripheral_js_1.BasePeripheral {
130
132
  }
131
133
  readUint32(offset) {
132
134
  switch (offset) {
135
+ case ADDR_ENDP:
136
+ return this.addrEndp & 0b1111000000001111111;
133
137
  case MAIN_CTRL:
134
138
  return this.mainCtrl;
135
139
  case SIE_STATUS:
@@ -152,6 +156,9 @@ class RPUSBController extends peripheral_js_1.BasePeripheral {
152
156
  writeUint32(offset, value) {
153
157
  var _a, _b;
154
158
  switch (offset) {
159
+ case ADDR_ENDP:
160
+ this.addrEndp = value;
161
+ break;
155
162
  case MAIN_CTRL:
156
163
  this.mainCtrl = value & (SIM_TIMING | CONTROLLER_EN | HOST_NDEVICE);
157
164
  if (value & CONTROLLER_EN && !(value & HOST_NDEVICE)) {
@@ -4,7 +4,7 @@ import { BasePeripheral, Peripheral } from './peripheral.js';
4
4
  export declare class RPWatchdog extends BasePeripheral implements Peripheral {
5
5
  readonly timer: Timer32;
6
6
  readonly alarm: Timer32PeriodicAlarm;
7
- readonly scratchData: Uint32Array;
7
+ readonly scratchData: Uint32Array<ArrayBuffer>;
8
8
  private enable;
9
9
  private tickEnable;
10
10
  private reason;
@@ -21,14 +21,14 @@ export declare const DPRAM_START_ADDRESS = 1343225856;
21
21
  export declare const SIO_START_ADDRESS = 3489660928;
22
22
  export declare class RP2040 {
23
23
  readonly clock: IClock;
24
- readonly bootrom: Uint32Array;
25
- readonly sram: Uint8Array;
26
- readonly sramView: DataView;
27
- readonly flash: Uint8Array;
28
- readonly flash16: Uint16Array;
29
- readonly flashView: DataView;
30
- readonly usbDPRAM: Uint8Array;
31
- readonly usbDPRAMView: DataView;
24
+ readonly bootrom: Uint32Array<ArrayBuffer>;
25
+ readonly sram: Uint8Array<ArrayBuffer>;
26
+ readonly sramView: DataView<ArrayBuffer>;
27
+ readonly flash: Uint8Array<ArrayBuffer>;
28
+ readonly flash16: Uint16Array<ArrayBuffer>;
29
+ readonly flashView: DataView<ArrayBuffer>;
30
+ readonly usbDPRAM: Uint8Array<ArrayBuffer>;
31
+ readonly usbDPRAMView: DataView<ArrayBuffer>;
32
32
  readonly core: CortexM0Core;
33
33
  clkSys: number;
34
34
  clkPeri: number;