rp2040js 0.18.0 → 0.18.2
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.
|
@@ -13,7 +13,10 @@ export declare class RPUART extends BasePeripheral implements Peripheral {
|
|
|
13
13
|
private rxFIFO;
|
|
14
14
|
private interruptMask;
|
|
15
15
|
private interruptStatus;
|
|
16
|
+
private intDivisor;
|
|
17
|
+
private fracDivisor;
|
|
16
18
|
onByte?: (value: number) => void;
|
|
19
|
+
onBaudRateChange?: (baudRate: number) => void;
|
|
17
20
|
constructor(rp2040: RP2040, name: string, irq: number, dreq: IUARTDMAChannels);
|
|
18
21
|
get enabled(): boolean;
|
|
19
22
|
get txEnabled(): boolean;
|
|
@@ -23,6 +26,8 @@ export declare class RPUART extends BasePeripheral implements Peripheral {
|
|
|
23
26
|
* Number of bits per UART character
|
|
24
27
|
*/
|
|
25
28
|
get wordLength(): 5 | 6 | 7 | 8 | undefined;
|
|
29
|
+
get baudDivider(): number;
|
|
30
|
+
get baudRate(): number;
|
|
26
31
|
get flags(): number;
|
|
27
32
|
checkInterrupts(): void;
|
|
28
33
|
feedByte(value: number): void;
|
|
@@ -5,12 +5,22 @@ const fifo_js_1 = require("../utils/fifo.js");
|
|
|
5
5
|
const peripheral_js_1 = require("./peripheral.js");
|
|
6
6
|
const UARTDR = 0x0;
|
|
7
7
|
const UARTFR = 0x18;
|
|
8
|
+
const UARTIBRD = 0x24;
|
|
9
|
+
const UARTFBRD = 0x28;
|
|
8
10
|
const UARTLCR_H = 0x2c;
|
|
9
11
|
const UARTCR = 0x30;
|
|
10
12
|
const UARTIMSC = 0x38;
|
|
11
13
|
const UARTIRIS = 0x3c;
|
|
12
14
|
const UARTIMIS = 0x40;
|
|
13
15
|
const UARTICR = 0x44;
|
|
16
|
+
const UARTPERIPHID0 = 0xfe0;
|
|
17
|
+
const UARTPERIPHID1 = 0xfe4;
|
|
18
|
+
const UARTPERIPHID2 = 0xfe8;
|
|
19
|
+
const UARTPERIPHID3 = 0xfec;
|
|
20
|
+
const UARTPCELLID0 = 0xff0;
|
|
21
|
+
const UARTPCELLID1 = 0xff4;
|
|
22
|
+
const UARTPCELLID2 = 0xff8;
|
|
23
|
+
const UARTPCELLID3 = 0xffc;
|
|
14
24
|
// UARTFR bits:
|
|
15
25
|
const TXFE = 1 << 7;
|
|
16
26
|
const RXFF = 1 << 6;
|
|
@@ -33,6 +43,8 @@ class RPUART extends peripheral_js_1.BasePeripheral {
|
|
|
33
43
|
this.rxFIFO = new fifo_js_1.FIFO(32);
|
|
34
44
|
this.interruptMask = 0;
|
|
35
45
|
this.interruptStatus = 0;
|
|
46
|
+
this.intDivisor = 0;
|
|
47
|
+
this.fracDivisor = 0;
|
|
36
48
|
}
|
|
37
49
|
get enabled() {
|
|
38
50
|
return !!(this.ctrlRegister & UARTEN);
|
|
@@ -61,6 +73,12 @@ class RPUART extends peripheral_js_1.BasePeripheral {
|
|
|
61
73
|
return 8;
|
|
62
74
|
}
|
|
63
75
|
}
|
|
76
|
+
get baudDivider() {
|
|
77
|
+
return this.intDivisor + this.fracDivisor / 64;
|
|
78
|
+
}
|
|
79
|
+
get baudRate() {
|
|
80
|
+
return Math.round(this.rp2040.clkPeri / (this.baudDivider * 16));
|
|
81
|
+
}
|
|
64
82
|
get flags() {
|
|
65
83
|
return (this.rxFIFO.full ? RXFF : 0) | (this.rxFIFO.empty ? RXFE : 0) | TXFE;
|
|
66
84
|
}
|
|
@@ -85,6 +103,10 @@ class RPUART extends peripheral_js_1.BasePeripheral {
|
|
|
85
103
|
}
|
|
86
104
|
case UARTFR:
|
|
87
105
|
return this.flags;
|
|
106
|
+
case UARTIBRD:
|
|
107
|
+
return this.intDivisor;
|
|
108
|
+
case UARTFBRD:
|
|
109
|
+
return this.fracDivisor;
|
|
88
110
|
case UARTLCR_H:
|
|
89
111
|
return this.lineCtrlRegister;
|
|
90
112
|
case UARTCR:
|
|
@@ -95,15 +117,39 @@ class RPUART extends peripheral_js_1.BasePeripheral {
|
|
|
95
117
|
return this.interruptStatus;
|
|
96
118
|
case UARTIMIS:
|
|
97
119
|
return this.interruptStatus & this.interruptMask;
|
|
120
|
+
case UARTPERIPHID0:
|
|
121
|
+
return 0x11;
|
|
122
|
+
case UARTPERIPHID1:
|
|
123
|
+
return 0x10;
|
|
124
|
+
case UARTPERIPHID2:
|
|
125
|
+
return 0x34;
|
|
126
|
+
case UARTPERIPHID3:
|
|
127
|
+
return 0x00;
|
|
128
|
+
case UARTPCELLID0:
|
|
129
|
+
return 0x0d;
|
|
130
|
+
case UARTPCELLID1:
|
|
131
|
+
return 0xf0;
|
|
132
|
+
case UARTPCELLID2:
|
|
133
|
+
return 0x05;
|
|
134
|
+
case UARTPCELLID3:
|
|
135
|
+
return 0xb1;
|
|
98
136
|
}
|
|
99
137
|
return super.readUint32(offset);
|
|
100
138
|
}
|
|
101
139
|
writeUint32(offset, value) {
|
|
102
|
-
var _a;
|
|
140
|
+
var _a, _b, _c;
|
|
103
141
|
switch (offset) {
|
|
104
142
|
case UARTDR:
|
|
105
143
|
(_a = this.onByte) === null || _a === void 0 ? void 0 : _a.call(this, value & 0xff);
|
|
106
144
|
break;
|
|
145
|
+
case UARTIBRD:
|
|
146
|
+
this.intDivisor = value & 0xffff;
|
|
147
|
+
(_b = this.onBaudRateChange) === null || _b === void 0 ? void 0 : _b.call(this, this.baudRate);
|
|
148
|
+
break;
|
|
149
|
+
case UARTFBRD:
|
|
150
|
+
this.fracDivisor = value & 0x3f;
|
|
151
|
+
(_c = this.onBaudRateChange) === null || _c === void 0 ? void 0 : _c.call(this, this.baudRate);
|
|
152
|
+
break;
|
|
107
153
|
case UARTLCR_H:
|
|
108
154
|
this.lineCtrlRegister = value;
|
|
109
155
|
break;
|
|
@@ -13,7 +13,10 @@ export declare class RPUART extends BasePeripheral implements Peripheral {
|
|
|
13
13
|
private rxFIFO;
|
|
14
14
|
private interruptMask;
|
|
15
15
|
private interruptStatus;
|
|
16
|
+
private intDivisor;
|
|
17
|
+
private fracDivisor;
|
|
16
18
|
onByte?: (value: number) => void;
|
|
19
|
+
onBaudRateChange?: (baudRate: number) => void;
|
|
17
20
|
constructor(rp2040: RP2040, name: string, irq: number, dreq: IUARTDMAChannels);
|
|
18
21
|
get enabled(): boolean;
|
|
19
22
|
get txEnabled(): boolean;
|
|
@@ -23,6 +26,8 @@ export declare class RPUART extends BasePeripheral implements Peripheral {
|
|
|
23
26
|
* Number of bits per UART character
|
|
24
27
|
*/
|
|
25
28
|
get wordLength(): 5 | 6 | 7 | 8 | undefined;
|
|
29
|
+
get baudDivider(): number;
|
|
30
|
+
get baudRate(): number;
|
|
26
31
|
get flags(): number;
|
|
27
32
|
checkInterrupts(): void;
|
|
28
33
|
feedByte(value: number): void;
|
|
@@ -2,12 +2,22 @@ import { FIFO } from '../utils/fifo.js';
|
|
|
2
2
|
import { BasePeripheral } from './peripheral.js';
|
|
3
3
|
const UARTDR = 0x0;
|
|
4
4
|
const UARTFR = 0x18;
|
|
5
|
+
const UARTIBRD = 0x24;
|
|
6
|
+
const UARTFBRD = 0x28;
|
|
5
7
|
const UARTLCR_H = 0x2c;
|
|
6
8
|
const UARTCR = 0x30;
|
|
7
9
|
const UARTIMSC = 0x38;
|
|
8
10
|
const UARTIRIS = 0x3c;
|
|
9
11
|
const UARTIMIS = 0x40;
|
|
10
12
|
const UARTICR = 0x44;
|
|
13
|
+
const UARTPERIPHID0 = 0xfe0;
|
|
14
|
+
const UARTPERIPHID1 = 0xfe4;
|
|
15
|
+
const UARTPERIPHID2 = 0xfe8;
|
|
16
|
+
const UARTPERIPHID3 = 0xfec;
|
|
17
|
+
const UARTPCELLID0 = 0xff0;
|
|
18
|
+
const UARTPCELLID1 = 0xff4;
|
|
19
|
+
const UARTPCELLID2 = 0xff8;
|
|
20
|
+
const UARTPCELLID3 = 0xffc;
|
|
11
21
|
// UARTFR bits:
|
|
12
22
|
const TXFE = 1 << 7;
|
|
13
23
|
const RXFF = 1 << 6;
|
|
@@ -30,6 +40,8 @@ export class RPUART extends BasePeripheral {
|
|
|
30
40
|
this.rxFIFO = new FIFO(32);
|
|
31
41
|
this.interruptMask = 0;
|
|
32
42
|
this.interruptStatus = 0;
|
|
43
|
+
this.intDivisor = 0;
|
|
44
|
+
this.fracDivisor = 0;
|
|
33
45
|
}
|
|
34
46
|
get enabled() {
|
|
35
47
|
return !!(this.ctrlRegister & UARTEN);
|
|
@@ -58,6 +70,12 @@ export class RPUART extends BasePeripheral {
|
|
|
58
70
|
return 8;
|
|
59
71
|
}
|
|
60
72
|
}
|
|
73
|
+
get baudDivider() {
|
|
74
|
+
return this.intDivisor + this.fracDivisor / 64;
|
|
75
|
+
}
|
|
76
|
+
get baudRate() {
|
|
77
|
+
return Math.round(this.rp2040.clkPeri / (this.baudDivider * 16));
|
|
78
|
+
}
|
|
61
79
|
get flags() {
|
|
62
80
|
return (this.rxFIFO.full ? RXFF : 0) | (this.rxFIFO.empty ? RXFE : 0) | TXFE;
|
|
63
81
|
}
|
|
@@ -82,6 +100,10 @@ export class RPUART extends BasePeripheral {
|
|
|
82
100
|
}
|
|
83
101
|
case UARTFR:
|
|
84
102
|
return this.flags;
|
|
103
|
+
case UARTIBRD:
|
|
104
|
+
return this.intDivisor;
|
|
105
|
+
case UARTFBRD:
|
|
106
|
+
return this.fracDivisor;
|
|
85
107
|
case UARTLCR_H:
|
|
86
108
|
return this.lineCtrlRegister;
|
|
87
109
|
case UARTCR:
|
|
@@ -92,15 +114,39 @@ export class RPUART extends BasePeripheral {
|
|
|
92
114
|
return this.interruptStatus;
|
|
93
115
|
case UARTIMIS:
|
|
94
116
|
return this.interruptStatus & this.interruptMask;
|
|
117
|
+
case UARTPERIPHID0:
|
|
118
|
+
return 0x11;
|
|
119
|
+
case UARTPERIPHID1:
|
|
120
|
+
return 0x10;
|
|
121
|
+
case UARTPERIPHID2:
|
|
122
|
+
return 0x34;
|
|
123
|
+
case UARTPERIPHID3:
|
|
124
|
+
return 0x00;
|
|
125
|
+
case UARTPCELLID0:
|
|
126
|
+
return 0x0d;
|
|
127
|
+
case UARTPCELLID1:
|
|
128
|
+
return 0xf0;
|
|
129
|
+
case UARTPCELLID2:
|
|
130
|
+
return 0x05;
|
|
131
|
+
case UARTPCELLID3:
|
|
132
|
+
return 0xb1;
|
|
95
133
|
}
|
|
96
134
|
return super.readUint32(offset);
|
|
97
135
|
}
|
|
98
136
|
writeUint32(offset, value) {
|
|
99
|
-
var _a;
|
|
137
|
+
var _a, _b, _c;
|
|
100
138
|
switch (offset) {
|
|
101
139
|
case UARTDR:
|
|
102
140
|
(_a = this.onByte) === null || _a === void 0 ? void 0 : _a.call(this, value & 0xff);
|
|
103
141
|
break;
|
|
142
|
+
case UARTIBRD:
|
|
143
|
+
this.intDivisor = value & 0xffff;
|
|
144
|
+
(_b = this.onBaudRateChange) === null || _b === void 0 ? void 0 : _b.call(this, this.baudRate);
|
|
145
|
+
break;
|
|
146
|
+
case UARTFBRD:
|
|
147
|
+
this.fracDivisor = value & 0x3f;
|
|
148
|
+
(_c = this.onBaudRateChange) === null || _c === void 0 ? void 0 : _c.call(this, this.baudRate);
|
|
149
|
+
break;
|
|
104
150
|
case UARTLCR_H:
|
|
105
151
|
this.lineCtrlRegister = value;
|
|
106
152
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rp2040js",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Raspberry Pi Pico (RP2040) Emulator",
|
|
5
5
|
"repository": "https://github.com/wokwi/rp2040js",
|
|
6
6
|
"keywords": [
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"import": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"types": "./dist/esm/index.d.ts",
|
|
27
|
+
"default": "./dist/esm/index.js"
|
|
28
28
|
},
|
|
29
29
|
"require": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"types": "./dist/cjs/index.d.ts",
|
|
31
|
+
"default": "./dist/cjs/index.js"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"./gdb-tcp-server": {
|
|
35
35
|
"import": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"types": "./dist/esm/gdb/gdb-tcp-server.d.ts",
|
|
37
|
+
"default": "./dist/esm/gdb/gdb-tcp-server.js"
|
|
38
38
|
},
|
|
39
39
|
"require": {
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"types": "./dist/cjs/gdb/gdb-tcp-server.d.ts",
|
|
41
|
+
"default": "./dist/cjs/gdb/gdb-tcp-server.js"
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
},
|
|
@@ -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 demo/emulator-run.ts",
|
|
52
|
-
"start:micropython": "ts-node demo/micropython-run.ts",
|
|
53
|
-
"start:circuitpython": "ts-node demo/micropython-run.ts --circuitpython",
|
|
54
|
-
"start:gdbdiff": "ts-node debug/gdbdiff.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",
|
|
55
55
|
"test": "vitest run",
|
|
56
56
|
"test:watch": "vitest",
|
|
57
|
-
"test:micropython-spi": "ts-node test/micropython-spi-test.ts"
|
|
57
|
+
"test:micropython-spi": "ts-node --esm test/micropython-spi-test.ts"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/minimist": "^1.2.2",
|