rp2040js 0.19.2 → 0.19.4

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.
@@ -1,11 +1,11 @@
1
1
  export { GDBConnection } from './gdb/gdb-connection.js';
2
2
  export { GDBServer } from './gdb/gdb-server.js';
3
3
  export { GPIOPin, GPIOPinState } from './gpio-pin.js';
4
- export { BasePeripheral, Peripheral } from './peripherals/peripheral.js';
4
+ export { BasePeripheral, type Peripheral } from './peripherals/peripheral.js';
5
5
  export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c.js';
6
6
  export { RPUSBController } from './peripherals/usb.js';
7
7
  export { RP2040 } from './rp2040.js';
8
8
  export { USBCDC } from './usb/cdc.js';
9
- export { DataDirection, DescriptorType, ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces.js';
9
+ export { DataDirection, DescriptorType, type ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces.js';
10
10
  export { createSetupPacket, getDescriptorPacket, setDeviceAddressPacket, setDeviceConfigurationPacket, } from './usb/setup.js';
11
- export { ConsoleLogger, Logger, LogLevel } from './utils/logging.js';
11
+ export { ConsoleLogger, type Logger, LogLevel } from './utils/logging.js';
@@ -28,6 +28,10 @@ export declare class RPI2C extends BasePeripheral implements Peripheral {
28
28
  rxThreshold: number;
29
29
  txThreshold: number;
30
30
  control: number;
31
+ ssClockHighPeriod: number;
32
+ ssClockLowPeriod: number;
33
+ fsClockHighPeriod: number;
34
+ fsClockLowPeriod: number;
31
35
  targetAddress: number;
32
36
  slaveAddress: number;
33
37
  abortSource: number;
@@ -35,6 +39,8 @@ export declare class RPI2C extends BasePeripheral implements Peripheral {
35
39
  intEnable: number;
36
40
  get intStatus(): number;
37
41
  get speed(): I2CSpeed;
42
+ get sclLowPeriod(): number;
43
+ get sclHighPeriod(): number;
38
44
  get masterBits(): 7 | 10;
39
45
  constructor(rp2040: RP2040, name: string, irq: number);
40
46
  checkInterrupts(): void;
@@ -142,6 +142,12 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
142
142
  get speed() {
143
143
  return ((this.control >> SPEED_SHIFT) & SPEED_MASK);
144
144
  }
145
+ get sclLowPeriod() {
146
+ return this.speed === I2CSpeed.Standard ? this.ssClockLowPeriod : this.fsClockLowPeriod;
147
+ }
148
+ get sclHighPeriod() {
149
+ return this.speed === I2CSpeed.Standard ? this.ssClockHighPeriod : this.fsClockHighPeriod;
150
+ }
145
151
  get masterBits() {
146
152
  return this.control & IC_10BITADDR_MASTER ? 10 : 7;
147
153
  }
@@ -165,6 +171,10 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
165
171
  this.rxThreshold = 0;
166
172
  this.txThreshold = 0;
167
173
  this.control = IC_SLAVE_DISABLE | IC_RESTART_EN | (I2CSpeed.FastMode << SPEED_SHIFT) | MASTER_MODE;
174
+ this.ssClockHighPeriod = 0x0028;
175
+ this.ssClockLowPeriod = 0x002f;
176
+ this.fsClockHighPeriod = 0x0006;
177
+ this.fsClockLowPeriod = 0x000d;
168
178
  this.targetAddress = 0x55;
169
179
  this.slaveAddress = 0x55;
170
180
  this.abortSource = 0;
@@ -323,6 +333,14 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
323
333
  }
324
334
  this.clearInterrupts(R_RX_FULL);
325
335
  return this.rxFIFO.pull();
336
+ case IC_SS_SCL_HCNT:
337
+ return this.ssClockHighPeriod;
338
+ case IC_SS_SCL_LCNT:
339
+ return this.ssClockLowPeriod;
340
+ case IC_FS_SCL_HCNT:
341
+ return this.fsClockHighPeriod;
342
+ case IC_FS_SCL_LCNT:
343
+ return this.fsClockLowPeriod;
326
344
  case IC_INTR_STAT:
327
345
  return this.intStatus;
328
346
  case IC_INTR_MASK:
@@ -419,6 +437,18 @@ class RPI2C extends peripheral_js_1.BasePeripheral {
419
437
  this.nextCommand();
420
438
  }
421
439
  return;
440
+ case IC_SS_SCL_HCNT:
441
+ this.ssClockHighPeriod = value & 0xffff;
442
+ return;
443
+ case IC_SS_SCL_LCNT:
444
+ this.ssClockLowPeriod = value & 0xffff;
445
+ return;
446
+ case IC_FS_SCL_HCNT:
447
+ this.fsClockHighPeriod = value & 0xffff;
448
+ return;
449
+ case IC_FS_SCL_LCNT:
450
+ this.fsClockLowPeriod = value & 0xffff;
451
+ return;
422
452
  case IC_RX_TL:
423
453
  this.rxThreshold = value & 0xff;
424
454
  if (this.rxThreshold > this.rxFIFO.size) {
@@ -2,8 +2,6 @@ import { BasePeripheral, Peripheral } from './peripheral.js';
2
2
  export declare class RP2040RTC extends BasePeripheral implements Peripheral {
3
3
  setup0: number;
4
4
  setup1: number;
5
- rtc1: number;
6
- rtc0: number;
7
5
  ctrl: number;
8
6
  baseline: Date;
9
7
  baselineMicros: number;
@@ -44,8 +44,6 @@ class RP2040RTC extends peripheral_js_1.BasePeripheral {
44
44
  super(...arguments);
45
45
  this.setup0 = 0;
46
46
  this.setup1 = 0;
47
- this.rtc1 = 0;
48
- this.rtc0 = 0;
49
47
  this.ctrl = 0;
50
48
  this.baseline = new Date(2021, 0, 1);
51
49
  this.baselineMicros = 0;
@@ -14,6 +14,7 @@ import { RPUSBController } from './peripherals/usb.js';
14
14
  import { RPSIO } from './sio.js';
15
15
  import { Logger } from './utils/logging.js';
16
16
  export declare const FLASH_START_ADDRESS = 268435456;
17
+ export declare const FLASH_END_ADDRESS = 335544320;
17
18
  export declare const RAM_START_ADDRESS = 536870912;
18
19
  export declare const APB_START_ADDRESS = 1073741824;
19
20
  export declare const DPRAM_START_ADDRESS = 1343225856;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RP2040 = exports.SIO_START_ADDRESS = exports.DPRAM_START_ADDRESS = exports.APB_START_ADDRESS = exports.RAM_START_ADDRESS = exports.FLASH_START_ADDRESS = void 0;
3
+ exports.RP2040 = exports.SIO_START_ADDRESS = exports.DPRAM_START_ADDRESS = exports.APB_START_ADDRESS = exports.RAM_START_ADDRESS = exports.FLASH_END_ADDRESS = exports.FLASH_START_ADDRESS = void 0;
4
4
  const realtime_clock_js_1 = require("./clock/realtime-clock.js");
5
5
  const cortex_m0_core_js_1 = require("./cortex-m0-core.js");
6
6
  const gpio_pin_js_1 = require("./gpio-pin.js");
@@ -30,6 +30,7 @@ const watchdog_js_1 = require("./peripherals/watchdog.js");
30
30
  const sio_js_1 = require("./sio.js");
31
31
  const logging_js_1 = require("./utils/logging.js");
32
32
  exports.FLASH_START_ADDRESS = 0x10000000;
33
+ exports.FLASH_END_ADDRESS = 0x14000000;
33
34
  exports.RAM_START_ADDRESS = 0x20000000;
34
35
  exports.APB_START_ADDRESS = 0x40000000;
35
36
  exports.DPRAM_START_ADDRESS = 0x50100000;
@@ -188,9 +189,14 @@ class RP2040 {
188
189
  if (address < bootrom.length * 4) {
189
190
  return bootrom[address / 4];
190
191
  }
191
- else if (address >= exports.FLASH_START_ADDRESS &&
192
- address < exports.FLASH_START_ADDRESS + this.flash.length) {
193
- return this.flashView.getUint32(address - exports.FLASH_START_ADDRESS, true);
192
+ else if (address >= exports.FLASH_START_ADDRESS && address < exports.FLASH_END_ADDRESS) {
193
+ // Flash is mirrored four times:
194
+ // - 0x10000000 XIP
195
+ // - 0x11000000 XIP_NOALLOC
196
+ // - 0x12000000 XIP_NOCACHE
197
+ // - 0x13000000 XIP_NOCACHE_NOALLOC
198
+ const offset = address & 16777215;
199
+ return this.flashView.getUint32(offset, true);
194
200
  }
195
201
  else if (address >= exports.RAM_START_ADDRESS && address < exports.RAM_START_ADDRESS + this.sram.length) {
196
202
  return this.sramView.getUint32(address - exports.RAM_START_ADDRESS, true);
@@ -1,11 +1,11 @@
1
1
  export { GDBConnection } from './gdb/gdb-connection.js';
2
2
  export { GDBServer } from './gdb/gdb-server.js';
3
3
  export { GPIOPin, GPIOPinState } from './gpio-pin.js';
4
- export { BasePeripheral, Peripheral } from './peripherals/peripheral.js';
4
+ export { BasePeripheral, type Peripheral } from './peripherals/peripheral.js';
5
5
  export { RPI2C, I2CSpeed, I2CMode } from './peripherals/i2c.js';
6
6
  export { RPUSBController } from './peripherals/usb.js';
7
7
  export { RP2040 } from './rp2040.js';
8
8
  export { USBCDC } from './usb/cdc.js';
9
- export { DataDirection, DescriptorType, ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces.js';
9
+ export { DataDirection, DescriptorType, type ISetupPacketParams, SetupRecipient, SetupRequest, SetupType, } from './usb/interfaces.js';
10
10
  export { createSetupPacket, getDescriptorPacket, setDeviceAddressPacket, setDeviceConfigurationPacket, } from './usb/setup.js';
11
- export { ConsoleLogger, Logger, LogLevel } from './utils/logging.js';
11
+ export { ConsoleLogger, type Logger, LogLevel } from './utils/logging.js';
@@ -28,6 +28,10 @@ export declare class RPI2C extends BasePeripheral implements Peripheral {
28
28
  rxThreshold: number;
29
29
  txThreshold: number;
30
30
  control: number;
31
+ ssClockHighPeriod: number;
32
+ ssClockLowPeriod: number;
33
+ fsClockHighPeriod: number;
34
+ fsClockLowPeriod: number;
31
35
  targetAddress: number;
32
36
  slaveAddress: number;
33
37
  abortSource: number;
@@ -35,6 +39,8 @@ export declare class RPI2C extends BasePeripheral implements Peripheral {
35
39
  intEnable: number;
36
40
  get intStatus(): number;
37
41
  get speed(): I2CSpeed;
42
+ get sclLowPeriod(): number;
43
+ get sclHighPeriod(): number;
38
44
  get masterBits(): 7 | 10;
39
45
  constructor(rp2040: RP2040, name: string, irq: number);
40
46
  checkInterrupts(): void;
@@ -139,6 +139,12 @@ export class RPI2C extends BasePeripheral {
139
139
  get speed() {
140
140
  return ((this.control >> SPEED_SHIFT) & SPEED_MASK);
141
141
  }
142
+ get sclLowPeriod() {
143
+ return this.speed === I2CSpeed.Standard ? this.ssClockLowPeriod : this.fsClockLowPeriod;
144
+ }
145
+ get sclHighPeriod() {
146
+ return this.speed === I2CSpeed.Standard ? this.ssClockHighPeriod : this.fsClockHighPeriod;
147
+ }
142
148
  get masterBits() {
143
149
  return this.control & IC_10BITADDR_MASTER ? 10 : 7;
144
150
  }
@@ -162,6 +168,10 @@ export class RPI2C extends BasePeripheral {
162
168
  this.rxThreshold = 0;
163
169
  this.txThreshold = 0;
164
170
  this.control = IC_SLAVE_DISABLE | IC_RESTART_EN | (I2CSpeed.FastMode << SPEED_SHIFT) | MASTER_MODE;
171
+ this.ssClockHighPeriod = 0x0028;
172
+ this.ssClockLowPeriod = 0x002f;
173
+ this.fsClockHighPeriod = 0x0006;
174
+ this.fsClockLowPeriod = 0x000d;
165
175
  this.targetAddress = 0x55;
166
176
  this.slaveAddress = 0x55;
167
177
  this.abortSource = 0;
@@ -320,6 +330,14 @@ export class RPI2C extends BasePeripheral {
320
330
  }
321
331
  this.clearInterrupts(R_RX_FULL);
322
332
  return this.rxFIFO.pull();
333
+ case IC_SS_SCL_HCNT:
334
+ return this.ssClockHighPeriod;
335
+ case IC_SS_SCL_LCNT:
336
+ return this.ssClockLowPeriod;
337
+ case IC_FS_SCL_HCNT:
338
+ return this.fsClockHighPeriod;
339
+ case IC_FS_SCL_LCNT:
340
+ return this.fsClockLowPeriod;
323
341
  case IC_INTR_STAT:
324
342
  return this.intStatus;
325
343
  case IC_INTR_MASK:
@@ -416,6 +434,18 @@ export class RPI2C extends BasePeripheral {
416
434
  this.nextCommand();
417
435
  }
418
436
  return;
437
+ case IC_SS_SCL_HCNT:
438
+ this.ssClockHighPeriod = value & 0xffff;
439
+ return;
440
+ case IC_SS_SCL_LCNT:
441
+ this.ssClockLowPeriod = value & 0xffff;
442
+ return;
443
+ case IC_FS_SCL_HCNT:
444
+ this.fsClockHighPeriod = value & 0xffff;
445
+ return;
446
+ case IC_FS_SCL_LCNT:
447
+ this.fsClockLowPeriod = value & 0xffff;
448
+ return;
419
449
  case IC_RX_TL:
420
450
  this.rxThreshold = value & 0xff;
421
451
  if (this.rxThreshold > this.rxFIFO.size) {
@@ -2,8 +2,6 @@ import { BasePeripheral, Peripheral } from './peripheral.js';
2
2
  export declare class RP2040RTC extends BasePeripheral implements Peripheral {
3
3
  setup0: number;
4
4
  setup1: number;
5
- rtc1: number;
6
- rtc0: number;
7
5
  ctrl: number;
8
6
  baseline: Date;
9
7
  baselineMicros: number;
@@ -41,8 +41,6 @@ export class RP2040RTC extends BasePeripheral {
41
41
  super(...arguments);
42
42
  this.setup0 = 0;
43
43
  this.setup1 = 0;
44
- this.rtc1 = 0;
45
- this.rtc0 = 0;
46
44
  this.ctrl = 0;
47
45
  this.baseline = new Date(2021, 0, 1);
48
46
  this.baselineMicros = 0;
@@ -14,6 +14,7 @@ import { RPUSBController } from './peripherals/usb.js';
14
14
  import { RPSIO } from './sio.js';
15
15
  import { Logger } from './utils/logging.js';
16
16
  export declare const FLASH_START_ADDRESS = 268435456;
17
+ export declare const FLASH_END_ADDRESS = 335544320;
17
18
  export declare const RAM_START_ADDRESS = 536870912;
18
19
  export declare const APB_START_ADDRESS = 1073741824;
19
20
  export declare const DPRAM_START_ADDRESS = 1343225856;
@@ -27,6 +27,7 @@ import { RPWatchdog } from './peripherals/watchdog.js';
27
27
  import { RPSIO } from './sio.js';
28
28
  import { ConsoleLogger, LogLevel } from './utils/logging.js';
29
29
  export const FLASH_START_ADDRESS = 0x10000000;
30
+ export const FLASH_END_ADDRESS = 0x14000000;
30
31
  export const RAM_START_ADDRESS = 0x20000000;
31
32
  export const APB_START_ADDRESS = 0x40000000;
32
33
  export const DPRAM_START_ADDRESS = 0x50100000;
@@ -185,9 +186,14 @@ export class RP2040 {
185
186
  if (address < bootrom.length * 4) {
186
187
  return bootrom[address / 4];
187
188
  }
188
- else if (address >= FLASH_START_ADDRESS &&
189
- address < FLASH_START_ADDRESS + this.flash.length) {
190
- return this.flashView.getUint32(address - FLASH_START_ADDRESS, true);
189
+ else if (address >= FLASH_START_ADDRESS && address < FLASH_END_ADDRESS) {
190
+ // Flash is mirrored four times:
191
+ // - 0x10000000 XIP
192
+ // - 0x11000000 XIP_NOALLOC
193
+ // - 0x12000000 XIP_NOCACHE
194
+ // - 0x13000000 XIP_NOCACHE_NOALLOC
195
+ const offset = address & 16777215;
196
+ return this.flashView.getUint32(offset, true);
191
197
  }
192
198
  else if (address >= RAM_START_ADDRESS && address < RAM_START_ADDRESS + this.sram.length) {
193
199
  return this.sramView.getUint32(address - RAM_START_ADDRESS, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rp2040js",
3
- "version": "0.19.2",
3
+ "version": "0.19.4",
4
4
  "description": "Raspberry Pi Pico (RP2040) Emulator",
5
5
  "repository": "https://github.com/wokwi/rp2040js",
6
6
  "keywords": [
@@ -48,13 +48,13 @@
48
48
  "prepare": "husky install",
49
49
  "format:check": "prettier --check **/*.{ts,js} !**/dist/** !**/node_modules/**",
50
50
  "lint": "eslint . --ext .ts",
51
- "start": "ts-node --esm demo/emulator-run.ts",
52
- "start:micropython": "ts-node --esm demo/micropython-run.ts",
53
- "start:circuitpython": "ts-node --esm demo/micropython-run.ts --circuitpython",
54
- "start:gdbdiff": "ts-node --esm debug/gdbdiff.ts",
51
+ "start": "tsx demo/emulator-run.ts",
52
+ "start:micropython": "tsx demo/micropython-run.ts",
53
+ "start:circuitpython": "tsx demo/micropython-run.ts --circuitpython",
54
+ "start:gdbdiff": "tsx debug/gdbdiff.ts",
55
55
  "test": "vitest run",
56
56
  "test:watch": "vitest",
57
- "test:micropython-spi": "ts-node --esm test/micropython-spi-test.ts"
57
+ "test:micropython-spi": "tsx test/micropython-spi-test.ts"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/minimist": "^1.2.2",
@@ -67,7 +67,7 @@
67
67
  "minimist": "^1.2.7",
68
68
  "prettier": "^3.0.3",
69
69
  "rimraf": "^5.0.5",
70
- "ts-node": "^10.9.1",
70
+ "tsx": "^4.6.2",
71
71
  "typescript": "^5.2.2",
72
72
  "uf2": "^1.0.0",
73
73
  "vitest": "^0.34.5"