rp2040js 0.19.0 → 0.19.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.
@@ -5,6 +5,8 @@ export declare class RP2040RTC extends BasePeripheral implements Peripheral {
5
5
  rtc1: number;
6
6
  rtc0: number;
7
7
  ctrl: number;
8
+ baseline: Date;
9
+ baselineMicros: number;
8
10
  readUint32(offset: number): number;
9
11
  writeUint32(offset: number, value: number): void;
10
12
  }
@@ -11,6 +11,34 @@ const RTC_RTC0 = 0x1c;
11
11
  const RTC_ENABLE_BITS = 0x01;
12
12
  const RTC_ACTIVE_BITS = 0x2;
13
13
  const RTC_LOAD_BITS = 0x10;
14
+ const SETUP_0_YEAR_SHIFT = 12;
15
+ const SETUP_0_YEAR_MASK = 0xfff;
16
+ const SETUP_0_MONTH_SHIFT = 8;
17
+ const SETUP_0_MONTH_MASK = 0xf;
18
+ const SETUP_0_DAY_SHIFT = 0;
19
+ const SETUP_0_DAY_MASK = 0x1f;
20
+ const SETUP_1_DOTW_SHIFT = 24;
21
+ const SETUP_1_DOTW_MASK = 0x7;
22
+ const SETUP_1_HOUR_SHIFT = 16;
23
+ const SETUP_1_HOUR_MASK = 0x1f;
24
+ const SETUP_1_MIN_SHIFT = 8;
25
+ const SETUP_1_MIN_MASK = 0x3f;
26
+ const SETUP_1_SEC_SHIFT = 0;
27
+ const SETUP_1_SEC_MASK = 0x3f;
28
+ const RTC_0_YEAR_SHIFT = 12;
29
+ const RTC_0_YEAR_MASK = 0xfff;
30
+ const RTC_0_MONTH_SHIFT = 8;
31
+ const RTC_0_MONTH_MASK = 0xf;
32
+ const RTC_0_DAY_SHIFT = 0;
33
+ const RTC_0_DAY_MASK = 0x1f;
34
+ const RTC_1_DOTW_SHIFT = 24;
35
+ const RTC_1_DOTW_MASK = 0x7;
36
+ const RTC_1_HOUR_SHIFT = 16;
37
+ const RTC_1_HOUR_MASK = 0x1f;
38
+ const RTC_1_MIN_SHIFT = 8;
39
+ const RTC_1_MIN_MASK = 0x3f;
40
+ const RTC_1_SEC_SHIFT = 0;
41
+ const RTC_1_SEC_MASK = 0x3f;
14
42
  class RP2040RTC extends peripheral_js_1.BasePeripheral {
15
43
  constructor() {
16
44
  super(...arguments);
@@ -19,8 +47,11 @@ class RP2040RTC extends peripheral_js_1.BasePeripheral {
19
47
  this.rtc1 = 0;
20
48
  this.rtc0 = 0;
21
49
  this.ctrl = 0;
50
+ this.baseline = new Date(2021, 0, 1);
51
+ this.baselineMicros = 0;
22
52
  }
23
53
  readUint32(offset) {
54
+ const date = new Date(this.baseline.getTime() + (this.rp2040.clock.micros - this.baselineMicros) / 1000);
24
55
  switch (offset) {
25
56
  case RTC_SETUP0:
26
57
  return this.setup0;
@@ -31,9 +62,16 @@ class RP2040RTC extends peripheral_js_1.BasePeripheral {
31
62
  case IRQ_SETUP_0:
32
63
  return 0;
33
64
  case RTC_RTC1:
34
- return this.rtc1;
65
+ return (((date.getFullYear() & RTC_0_YEAR_MASK) << RTC_0_YEAR_SHIFT) |
66
+ (((date.getMonth() + 1) & RTC_0_MONTH_MASK) << RTC_0_MONTH_SHIFT) |
67
+ ((date.getDate() & RTC_0_DAY_MASK) << RTC_0_DAY_SHIFT));
35
68
  case RTC_RTC0:
36
- return this.rtc0;
69
+ return (((date.getDay() & RTC_1_DOTW_MASK) << RTC_1_DOTW_SHIFT) |
70
+ ((date.getHours() & RTC_1_HOUR_MASK) << RTC_1_HOUR_SHIFT) |
71
+ ((date.getMinutes() & RTC_1_MIN_MASK) << RTC_1_MIN_SHIFT) |
72
+ ((date.getSeconds() & RTC_1_SEC_MASK) << RTC_1_SEC_SHIFT));
73
+ default:
74
+ break;
37
75
  }
38
76
  return super.readUint32(offset);
39
77
  }
@@ -56,8 +94,14 @@ class RP2040RTC extends peripheral_js_1.BasePeripheral {
56
94
  this.ctrl |= RTC_ENABLE_BITS;
57
95
  this.ctrl |= RTC_ACTIVE_BITS;
58
96
  if (this.ctrl & RTC_LOAD_BITS) {
59
- this.rtc1 = this.setup0;
60
- this.rtc0 = this.setup1;
97
+ const year = (this.setup0 >> SETUP_0_YEAR_SHIFT) & SETUP_0_YEAR_MASK;
98
+ const month = (this.setup0 >> SETUP_0_MONTH_SHIFT) & SETUP_0_MONTH_MASK;
99
+ const day = (this.setup0 >> SETUP_0_DAY_SHIFT) & SETUP_0_DAY_MASK;
100
+ const hour = (this.setup1 >> SETUP_1_HOUR_SHIFT) & SETUP_1_HOUR_MASK;
101
+ const min = (this.setup1 >> SETUP_1_MIN_SHIFT) & SETUP_1_MIN_MASK;
102
+ const sec = (this.setup1 >> SETUP_1_SEC_SHIFT) & SETUP_1_SEC_MASK;
103
+ this.baseline = new Date(year, month - 1, day, hour, min, sec);
104
+ this.baselineMicros = this.rp2040.clock.micros;
61
105
  this.ctrl &= ~RTC_LOAD_BITS;
62
106
  }
63
107
  }
@@ -32,6 +32,7 @@ const RXE = 1 << 9;
32
32
  const TXE = 1 << 8;
33
33
  const UARTEN = 1 << 0;
34
34
  // Interrupt bits
35
+ const UARTTXINTR = 1 << 5;
35
36
  const UARTRXINTR = 1 << 4;
36
37
  class RPUART extends peripheral_js_1.BasePeripheral {
37
38
  constructor(rp2040, name, irq, dreq) {
@@ -83,6 +84,8 @@ class RPUART extends peripheral_js_1.BasePeripheral {
83
84
  return (this.rxFIFO.full ? RXFF : 0) | (this.rxFIFO.empty ? RXFE : 0) | TXFE;
84
85
  }
85
86
  checkInterrupts() {
87
+ // TODO We should actually implement a proper FIFO for TX
88
+ this.interruptStatus |= UARTTXINTR;
86
89
  this.rp2040.setInterrupt(this.irq, !!(this.interruptStatus & this.interruptMask));
87
90
  }
88
91
  feedByte(value) {
@@ -97,8 +100,11 @@ class RPUART extends peripheral_js_1.BasePeripheral {
97
100
  const value = this.rxFIFO.pull();
98
101
  if (!this.rxFIFO.empty) {
99
102
  this.interruptStatus |= UARTRXINTR;
100
- this.checkInterrupts();
101
103
  }
104
+ else {
105
+ this.interruptStatus &= ~UARTRXINTR;
106
+ }
107
+ this.checkInterrupts();
102
108
  return value;
103
109
  }
104
110
  case UARTFR:
@@ -5,6 +5,8 @@ export declare class RP2040RTC extends BasePeripheral implements Peripheral {
5
5
  rtc1: number;
6
6
  rtc0: number;
7
7
  ctrl: number;
8
+ baseline: Date;
9
+ baselineMicros: number;
8
10
  readUint32(offset: number): number;
9
11
  writeUint32(offset: number, value: number): void;
10
12
  }
@@ -8,6 +8,34 @@ const RTC_RTC0 = 0x1c;
8
8
  const RTC_ENABLE_BITS = 0x01;
9
9
  const RTC_ACTIVE_BITS = 0x2;
10
10
  const RTC_LOAD_BITS = 0x10;
11
+ const SETUP_0_YEAR_SHIFT = 12;
12
+ const SETUP_0_YEAR_MASK = 0xfff;
13
+ const SETUP_0_MONTH_SHIFT = 8;
14
+ const SETUP_0_MONTH_MASK = 0xf;
15
+ const SETUP_0_DAY_SHIFT = 0;
16
+ const SETUP_0_DAY_MASK = 0x1f;
17
+ const SETUP_1_DOTW_SHIFT = 24;
18
+ const SETUP_1_DOTW_MASK = 0x7;
19
+ const SETUP_1_HOUR_SHIFT = 16;
20
+ const SETUP_1_HOUR_MASK = 0x1f;
21
+ const SETUP_1_MIN_SHIFT = 8;
22
+ const SETUP_1_MIN_MASK = 0x3f;
23
+ const SETUP_1_SEC_SHIFT = 0;
24
+ const SETUP_1_SEC_MASK = 0x3f;
25
+ const RTC_0_YEAR_SHIFT = 12;
26
+ const RTC_0_YEAR_MASK = 0xfff;
27
+ const RTC_0_MONTH_SHIFT = 8;
28
+ const RTC_0_MONTH_MASK = 0xf;
29
+ const RTC_0_DAY_SHIFT = 0;
30
+ const RTC_0_DAY_MASK = 0x1f;
31
+ const RTC_1_DOTW_SHIFT = 24;
32
+ const RTC_1_DOTW_MASK = 0x7;
33
+ const RTC_1_HOUR_SHIFT = 16;
34
+ const RTC_1_HOUR_MASK = 0x1f;
35
+ const RTC_1_MIN_SHIFT = 8;
36
+ const RTC_1_MIN_MASK = 0x3f;
37
+ const RTC_1_SEC_SHIFT = 0;
38
+ const RTC_1_SEC_MASK = 0x3f;
11
39
  export class RP2040RTC extends BasePeripheral {
12
40
  constructor() {
13
41
  super(...arguments);
@@ -16,8 +44,11 @@ export class RP2040RTC extends BasePeripheral {
16
44
  this.rtc1 = 0;
17
45
  this.rtc0 = 0;
18
46
  this.ctrl = 0;
47
+ this.baseline = new Date(2021, 0, 1);
48
+ this.baselineMicros = 0;
19
49
  }
20
50
  readUint32(offset) {
51
+ const date = new Date(this.baseline.getTime() + (this.rp2040.clock.micros - this.baselineMicros) / 1000);
21
52
  switch (offset) {
22
53
  case RTC_SETUP0:
23
54
  return this.setup0;
@@ -28,9 +59,16 @@ export class RP2040RTC extends BasePeripheral {
28
59
  case IRQ_SETUP_0:
29
60
  return 0;
30
61
  case RTC_RTC1:
31
- return this.rtc1;
62
+ return (((date.getFullYear() & RTC_0_YEAR_MASK) << RTC_0_YEAR_SHIFT) |
63
+ (((date.getMonth() + 1) & RTC_0_MONTH_MASK) << RTC_0_MONTH_SHIFT) |
64
+ ((date.getDate() & RTC_0_DAY_MASK) << RTC_0_DAY_SHIFT));
32
65
  case RTC_RTC0:
33
- return this.rtc0;
66
+ return (((date.getDay() & RTC_1_DOTW_MASK) << RTC_1_DOTW_SHIFT) |
67
+ ((date.getHours() & RTC_1_HOUR_MASK) << RTC_1_HOUR_SHIFT) |
68
+ ((date.getMinutes() & RTC_1_MIN_MASK) << RTC_1_MIN_SHIFT) |
69
+ ((date.getSeconds() & RTC_1_SEC_MASK) << RTC_1_SEC_SHIFT));
70
+ default:
71
+ break;
34
72
  }
35
73
  return super.readUint32(offset);
36
74
  }
@@ -53,8 +91,14 @@ export class RP2040RTC extends BasePeripheral {
53
91
  this.ctrl |= RTC_ENABLE_BITS;
54
92
  this.ctrl |= RTC_ACTIVE_BITS;
55
93
  if (this.ctrl & RTC_LOAD_BITS) {
56
- this.rtc1 = this.setup0;
57
- this.rtc0 = this.setup1;
94
+ const year = (this.setup0 >> SETUP_0_YEAR_SHIFT) & SETUP_0_YEAR_MASK;
95
+ const month = (this.setup0 >> SETUP_0_MONTH_SHIFT) & SETUP_0_MONTH_MASK;
96
+ const day = (this.setup0 >> SETUP_0_DAY_SHIFT) & SETUP_0_DAY_MASK;
97
+ const hour = (this.setup1 >> SETUP_1_HOUR_SHIFT) & SETUP_1_HOUR_MASK;
98
+ const min = (this.setup1 >> SETUP_1_MIN_SHIFT) & SETUP_1_MIN_MASK;
99
+ const sec = (this.setup1 >> SETUP_1_SEC_SHIFT) & SETUP_1_SEC_MASK;
100
+ this.baseline = new Date(year, month - 1, day, hour, min, sec);
101
+ this.baselineMicros = this.rp2040.clock.micros;
58
102
  this.ctrl &= ~RTC_LOAD_BITS;
59
103
  }
60
104
  }
@@ -29,6 +29,7 @@ const RXE = 1 << 9;
29
29
  const TXE = 1 << 8;
30
30
  const UARTEN = 1 << 0;
31
31
  // Interrupt bits
32
+ const UARTTXINTR = 1 << 5;
32
33
  const UARTRXINTR = 1 << 4;
33
34
  export class RPUART extends BasePeripheral {
34
35
  constructor(rp2040, name, irq, dreq) {
@@ -80,6 +81,8 @@ export class RPUART extends BasePeripheral {
80
81
  return (this.rxFIFO.full ? RXFF : 0) | (this.rxFIFO.empty ? RXFE : 0) | TXFE;
81
82
  }
82
83
  checkInterrupts() {
84
+ // TODO We should actually implement a proper FIFO for TX
85
+ this.interruptStatus |= UARTTXINTR;
83
86
  this.rp2040.setInterrupt(this.irq, !!(this.interruptStatus & this.interruptMask));
84
87
  }
85
88
  feedByte(value) {
@@ -94,8 +97,11 @@ export class RPUART extends BasePeripheral {
94
97
  const value = this.rxFIFO.pull();
95
98
  if (!this.rxFIFO.empty) {
96
99
  this.interruptStatus |= UARTRXINTR;
97
- this.checkInterrupts();
98
100
  }
101
+ else {
102
+ this.interruptStatus &= ~UARTRXINTR;
103
+ }
104
+ this.checkInterrupts();
99
105
  return value;
100
106
  }
101
107
  case UARTFR:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rp2040js",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "description": "Raspberry Pi Pico (RP2040) Emulator",
5
5
  "repository": "https://github.com/wokwi/rp2040js",
6
6
  "keywords": [