rp2040js 0.17.17 → 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 (182) hide show
  1. package/dist/cjs/clock/clock.d.ts +11 -11
  2. package/dist/cjs/clock/clock.js +2 -2
  3. package/dist/cjs/clock/mock-clock.d.ts +17 -17
  4. package/dist/cjs/clock/mock-clock.js +52 -52
  5. package/dist/cjs/clock/realtime-clock.d.ts +23 -23
  6. package/dist/cjs/clock/realtime-clock.js +73 -73
  7. package/dist/cjs/cortex-m0-core.d.ts +87 -87
  8. package/dist/cjs/cortex-m0-core.js +1251 -1251
  9. package/dist/cjs/gdb/gdb-connection.d.ts +11 -11
  10. package/dist/cjs/gdb/gdb-connection.js +57 -57
  11. package/dist/cjs/gdb/gdb-server.d.ts +23 -23
  12. package/dist/cjs/gdb/gdb-server.js +232 -232
  13. package/dist/cjs/gdb/gdb-tcp-server.d.ts +10 -10
  14. package/dist/cjs/gdb/gdb-tcp-server.js +34 -34
  15. package/dist/cjs/gdb/gdb-utils.d.ts +9 -9
  16. package/dist/cjs/gdb/gdb-utils.js +48 -48
  17. package/dist/cjs/gpio-pin.d.ts +56 -56
  18. package/dist/cjs/gpio-pin.js +216 -216
  19. package/dist/cjs/index.d.ts +11 -11
  20. package/dist/cjs/index.js +36 -36
  21. package/dist/cjs/interpolator.d.ts +36 -36
  22. package/dist/cjs/interpolator.js +150 -150
  23. package/dist/cjs/irq.d.ts +29 -29
  24. package/dist/cjs/irq.js +33 -33
  25. package/dist/cjs/peripherals/adc.d.ts +52 -52
  26. package/dist/cjs/peripherals/adc.js +261 -261
  27. package/dist/cjs/peripherals/busctrl.d.ts +10 -10
  28. package/dist/cjs/peripherals/busctrl.js +84 -84
  29. package/dist/cjs/peripherals/clocks.d.ts +9 -9
  30. package/dist/cjs/peripherals/clocks.js +42 -42
  31. package/dist/cjs/peripherals/dma.d.ts +109 -109
  32. package/dist/cjs/peripherals/dma.js +520 -520
  33. package/dist/cjs/peripherals/i2c.d.ts +54 -54
  34. package/dist/cjs/peripherals/i2c.js +458 -458
  35. package/dist/cjs/peripherals/io.d.ts +11 -11
  36. package/dist/cjs/peripherals/io.js +100 -100
  37. package/dist/cjs/peripherals/pads.d.ts +13 -13
  38. package/dist/cjs/peripherals/pads.js +58 -58
  39. package/dist/cjs/peripherals/peripheral.d.ts +22 -22
  40. package/dist/cjs/peripherals/peripheral.js +61 -61
  41. package/dist/cjs/peripherals/pio.d.ts +120 -120
  42. package/dist/cjs/peripherals/pio.js +1086 -1086
  43. package/dist/cjs/peripherals/ppb.d.ts +25 -25
  44. package/dist/cjs/peripherals/ppb.js +229 -229
  45. package/dist/cjs/peripherals/pwm.d.ts +65 -65
  46. package/dist/cjs/peripherals/pwm.js +372 -372
  47. package/dist/cjs/peripherals/reset.d.ts +8 -8
  48. package/dist/cjs/peripherals/reset.js +40 -40
  49. package/dist/cjs/peripherals/rtc.d.ts +10 -10
  50. package/dist/cjs/peripherals/rtc.js +74 -74
  51. package/dist/cjs/peripherals/spi.d.ts +38 -38
  52. package/dist/cjs/peripherals/spi.js +240 -240
  53. package/dist/cjs/peripherals/ssi.d.ts +6 -6
  54. package/dist/cjs/peripherals/ssi.js +43 -43
  55. package/dist/cjs/peripherals/syscfg.d.ts +5 -5
  56. package/dist/cjs/peripherals/syscfg.js +26 -26
  57. package/dist/cjs/peripherals/sysinfo.d.ts +4 -4
  58. package/dist/cjs/peripherals/sysinfo.js +22 -22
  59. package/dist/cjs/peripherals/tbman.d.ts +4 -4
  60. package/dist/cjs/peripherals/tbman.js +17 -17
  61. package/dist/cjs/peripherals/timer.d.ts +18 -18
  62. package/dist/cjs/peripherals/timer.js +156 -156
  63. package/dist/cjs/peripherals/uart.d.ts +31 -31
  64. package/dist/cjs/peripherals/uart.js +132 -132
  65. package/dist/cjs/peripherals/usb.d.ts +29 -29
  66. package/dist/cjs/peripherals/usb.js +309 -309
  67. package/dist/cjs/rp2040.d.ts +71 -71
  68. package/dist/cjs/rp2040.js +361 -361
  69. package/dist/cjs/sio.d.ts +21 -21
  70. package/dist/cjs/sio.js +425 -425
  71. package/dist/cjs/usb/cdc.d.ts +20 -20
  72. package/dist/cjs/usb/cdc.js +126 -126
  73. package/dist/cjs/usb/interfaces.d.ts +47 -47
  74. package/dist/cjs/usb/interfaces.js +46 -46
  75. package/dist/cjs/usb/setup.d.ts +5 -5
  76. package/dist/cjs/usb/setup.js +53 -53
  77. package/dist/cjs/utils/assembler.d.ts +79 -79
  78. package/dist/cjs/utils/assembler.js +328 -328
  79. package/dist/cjs/utils/bit.d.ts +3 -3
  80. package/dist/cjs/utils/bit.js +15 -15
  81. package/dist/cjs/utils/fifo.d.ts +15 -15
  82. package/dist/cjs/utils/fifo.js +56 -56
  83. package/dist/cjs/utils/logging.d.ts +23 -23
  84. package/dist/cjs/utils/logging.js +48 -48
  85. package/dist/cjs/utils/pio-assembler.d.ts +45 -45
  86. package/dist/cjs/utils/pio-assembler.js +87 -87
  87. package/dist/cjs/utils/time.d.ts +2 -2
  88. package/dist/cjs/utils/time.js +32 -32
  89. package/dist/cjs/utils/timer32.d.ts +57 -57
  90. package/dist/cjs/utils/timer32.js +208 -208
  91. package/dist/esm/clock/clock.d.ts +11 -11
  92. package/dist/esm/clock/clock.js +1 -1
  93. package/dist/esm/clock/mock-clock.d.ts +17 -17
  94. package/dist/esm/clock/mock-clock.js +47 -47
  95. package/dist/esm/clock/realtime-clock.d.ts +23 -23
  96. package/dist/esm/clock/realtime-clock.js +68 -68
  97. package/dist/esm/cortex-m0-core.d.ts +87 -87
  98. package/dist/esm/cortex-m0-core.js +1247 -1247
  99. package/dist/esm/gdb/gdb-connection.d.ts +11 -11
  100. package/dist/esm/gdb/gdb-connection.js +53 -53
  101. package/dist/esm/gdb/gdb-server.d.ts +23 -23
  102. package/dist/esm/gdb/gdb-server.js +228 -228
  103. package/dist/esm/gdb/gdb-tcp-server.d.ts +10 -10
  104. package/dist/esm/gdb/gdb-tcp-server.js +30 -30
  105. package/dist/esm/gdb/gdb-utils.d.ts +9 -9
  106. package/dist/esm/gdb/gdb-utils.js +36 -36
  107. package/dist/esm/gpio-pin.d.ts +56 -56
  108. package/dist/esm/gpio-pin.js +212 -212
  109. package/dist/esm/index.d.ts +11 -11
  110. package/dist/esm/index.js +11 -11
  111. package/dist/esm/interpolator.d.ts +36 -36
  112. package/dist/esm/interpolator.js +145 -145
  113. package/dist/esm/irq.d.ts +29 -29
  114. package/dist/esm/irq.js +30 -30
  115. package/dist/esm/peripherals/adc.d.ts +52 -52
  116. package/dist/esm/peripherals/adc.js +257 -257
  117. package/dist/esm/peripherals/busctrl.d.ts +10 -10
  118. package/dist/esm/peripherals/busctrl.js +80 -80
  119. package/dist/esm/peripherals/clocks.d.ts +9 -9
  120. package/dist/esm/peripherals/clocks.js +38 -38
  121. package/dist/esm/peripherals/dma.d.ts +109 -109
  122. package/dist/esm/peripherals/dma.js +515 -515
  123. package/dist/esm/peripherals/i2c.d.ts +54 -54
  124. package/dist/esm/peripherals/i2c.js +454 -454
  125. package/dist/esm/peripherals/io.d.ts +11 -11
  126. package/dist/esm/peripherals/io.js +96 -96
  127. package/dist/esm/peripherals/pads.d.ts +13 -13
  128. package/dist/esm/peripherals/pads.js +54 -54
  129. package/dist/esm/peripherals/peripheral.d.ts +22 -22
  130. package/dist/esm/peripherals/peripheral.js +55 -55
  131. package/dist/esm/peripherals/pio.d.ts +120 -120
  132. package/dist/esm/peripherals/pio.js +1081 -1081
  133. package/dist/esm/peripherals/ppb.d.ts +25 -25
  134. package/dist/esm/peripherals/ppb.js +225 -225
  135. package/dist/esm/peripherals/pwm.d.ts +65 -65
  136. package/dist/esm/peripherals/pwm.js +368 -368
  137. package/dist/esm/peripherals/reset.d.ts +8 -8
  138. package/dist/esm/peripherals/reset.js +36 -36
  139. package/dist/esm/peripherals/rtc.d.ts +10 -10
  140. package/dist/esm/peripherals/rtc.js +70 -70
  141. package/dist/esm/peripherals/spi.d.ts +38 -38
  142. package/dist/esm/peripherals/spi.js +236 -236
  143. package/dist/esm/peripherals/ssi.d.ts +6 -6
  144. package/dist/esm/peripherals/ssi.js +39 -39
  145. package/dist/esm/peripherals/syscfg.d.ts +5 -5
  146. package/dist/esm/peripherals/syscfg.js +22 -22
  147. package/dist/esm/peripherals/sysinfo.d.ts +4 -4
  148. package/dist/esm/peripherals/sysinfo.js +18 -18
  149. package/dist/esm/peripherals/tbman.d.ts +4 -4
  150. package/dist/esm/peripherals/tbman.js +13 -13
  151. package/dist/esm/peripherals/timer.d.ts +18 -18
  152. package/dist/esm/peripherals/timer.js +152 -152
  153. package/dist/esm/peripherals/uart.d.ts +31 -31
  154. package/dist/esm/peripherals/uart.js +128 -128
  155. package/dist/esm/peripherals/usb.d.ts +29 -29
  156. package/dist/esm/peripherals/usb.js +305 -305
  157. package/dist/esm/rp2040.d.ts +71 -71
  158. package/dist/esm/rp2040.js +357 -357
  159. package/dist/esm/sio.d.ts +21 -21
  160. package/dist/esm/sio.js +421 -421
  161. package/dist/esm/usb/cdc.d.ts +20 -20
  162. package/dist/esm/usb/cdc.js +121 -121
  163. package/dist/esm/usb/interfaces.d.ts +47 -47
  164. package/dist/esm/usb/interfaces.js +43 -43
  165. package/dist/esm/usb/setup.d.ts +5 -5
  166. package/dist/esm/usb/setup.js +46 -46
  167. package/dist/esm/utils/assembler.d.ts +79 -79
  168. package/dist/esm/utils/assembler.js +245 -245
  169. package/dist/esm/utils/bit.d.ts +3 -3
  170. package/dist/esm/utils/bit.js +9 -9
  171. package/dist/esm/utils/fifo.d.ts +15 -15
  172. package/dist/esm/utils/fifo.js +52 -52
  173. package/dist/esm/utils/logging.d.ts +23 -23
  174. package/dist/esm/utils/logging.js +44 -44
  175. package/dist/esm/utils/pio-assembler.d.ts +45 -45
  176. package/dist/esm/utils/pio-assembler.js +75 -75
  177. package/dist/esm/utils/time.d.ts +2 -2
  178. package/dist/esm/utils/time.js +27 -27
  179. package/dist/esm/utils/timer32.d.ts +57 -57
  180. package/dist/esm/utils/timer32.js +203 -203
  181. package/package.json +33 -22
  182. package/dist/esm/package.json +0 -1
@@ -1,240 +1,240 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RPSPI = void 0;
4
- const fifo_1 = require("../utils/fifo");
5
- const peripheral_1 = require("./peripheral");
6
- const SSPCR0 = 0x000; // Control register 0, SSPCR0 on page 3-4
7
- const SSPCR1 = 0x004; // Control register 1, SSPCR1 on page 3-5
8
- const SSPDR = 0x008; // Data register, SSPDR on page 3-6
9
- const SSPSR = 0x00c; // Status register, SSPSR on page 3-7
10
- const SSPCPSR = 0x010; // Clock prescale register, SSPCPSR on page 3-8
11
- const SSPIMSC = 0x014; // Interrupt mask set or clear register, SSPIMSC on page 3-9
12
- const SSPRIS = 0x018; // Raw interrupt status register, SSPRIS on page 3-10
13
- const SSPMIS = 0x01c; // Masked interrupt status register, SSPMIS on page 3-11
14
- const SSPICR = 0x020; // Interrupt clear register, SSPICR on page 3-11
15
- const SSPDMACR = 0x024; // DMA control register, SSPDMACR on page 3-12
16
- const SSPPERIPHID0 = 0xfe0; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
17
- const SSPPERIPHID1 = 0xfe4; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
18
- const SSPPERIPHID2 = 0xfe8; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
19
- const SSPPERIPHID3 = 0xfec; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
20
- const SSPPCELLID0 = 0xff0; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
21
- const SSPPCELLID1 = 0xff4; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
22
- const SSPPCELLID2 = 0xff8; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
23
- const SSPPCELLID3 = 0xffc; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
24
- // SSPCR0 bits:
25
- const SCR_MASK = 0xff;
26
- const SCR_SHIFT = 8;
27
- const SPH = 1 << 7;
28
- const SPO = 1 << 6;
29
- const FRF_MASK = 0x3;
30
- const FRF_SHIFT = 4;
31
- const DSS_MASK = 0xf;
32
- const DSS_SHIFT = 0;
33
- // SSPCR1 bits:
34
- const SOD = 1 << 3;
35
- const MS = 1 << 2;
36
- const SSE = 1 << 1;
37
- const LBM = 1 << 0;
38
- // SSPSR bits:
39
- const BSY = 1 << 4;
40
- const RFF = 1 << 3;
41
- const RNE = 1 << 2;
42
- const TNF = 1 << 1;
43
- const TFE = 1 << 0;
44
- // SSPCPSR bits:
45
- const CPSDVSR_MASK = 0xfe;
46
- const CPSDVSR_SHIFT = 0;
47
- // SSPDMACR bits:
48
- const TXDMAE = 1 << 1;
49
- const RXDMAE = 1 << 0;
50
- // Interrupts:
51
- const SSPTXINTR = 1 << 3;
52
- const SSPRXINTR = 1 << 2;
53
- const SSPRTINTR = 1 << 1;
54
- const SSPRORINTR = 1 << 0;
55
- class RPSPI extends peripheral_1.BasePeripheral {
56
- constructor(rp2040, name, irq, dreq) {
57
- super(rp2040, name);
58
- this.irq = irq;
59
- this.dreq = dreq;
60
- this.rxFIFO = new fifo_1.FIFO(8);
61
- this.txFIFO = new fifo_1.FIFO(8);
62
- // User provided callbacks
63
- this.onTransmit = () => this.completeTransmit(0);
64
- this.busy = false;
65
- this.control0 = 0;
66
- this.control1 = 0;
67
- this.dmaControl = 0;
68
- this.clockDivisor = 0;
69
- this.intRaw = 0;
70
- this.intEnable = 0;
71
- this.updateDMATx();
72
- this.updateDMARx();
73
- }
74
- get intStatus() {
75
- return this.intRaw & this.intEnable;
76
- }
77
- get enabled() {
78
- return !!(this.control1 & SSE);
79
- }
80
- /** Data size in bits: 4 to 16 bits */
81
- get dataBits() {
82
- return ((this.control0 >> DSS_SHIFT) & DSS_MASK) + 1;
83
- }
84
- get masterMode() {
85
- return !(this.control0 & MS);
86
- }
87
- get spiMode() {
88
- const cpol = this.control0 & SPO;
89
- const cpha = this.control0 & SPH;
90
- return cpol ? (cpha ? 2 : 3) : cpha ? 1 : 0;
91
- }
92
- get clockFrequency() {
93
- if (!this.clockDivisor) {
94
- return 0;
95
- }
96
- const scr = (this.control0 >> SCR_SHIFT) & SCR_MASK;
97
- return this.rp2040.clkPeri / (this.clockDivisor * (1 + scr));
98
- }
99
- updateDMATx() {
100
- if (this.txFIFO.full) {
101
- this.rp2040.dma.clearDREQ(this.dreq.tx);
102
- }
103
- else {
104
- this.rp2040.dma.setDREQ(this.dreq.tx);
105
- }
106
- }
107
- updateDMARx() {
108
- if (this.rxFIFO.empty) {
109
- this.rp2040.dma.clearDREQ(this.dreq.rx);
110
- }
111
- else {
112
- this.rp2040.dma.setDREQ(this.dreq.rx);
113
- }
114
- }
115
- doTX() {
116
- if (!this.busy && !this.txFIFO.empty) {
117
- const value = this.txFIFO.pull();
118
- this.busy = true;
119
- this.onTransmit(value);
120
- this.fifosUpdated();
121
- }
122
- }
123
- completeTransmit(rxValue) {
124
- this.busy = false;
125
- if (!this.rxFIFO.full) {
126
- this.rxFIFO.push(rxValue);
127
- }
128
- else {
129
- this.intRaw |= SSPRORINTR;
130
- }
131
- this.fifosUpdated();
132
- this.doTX();
133
- }
134
- checkInterrupts() {
135
- this.rp2040.setInterrupt(this.irq, !!this.intStatus);
136
- }
137
- fifosUpdated() {
138
- const prevStatus = this.intStatus;
139
- if (this.txFIFO.itemCount <= this.txFIFO.size / 2) {
140
- this.intRaw |= SSPTXINTR;
141
- }
142
- else {
143
- this.intRaw &= ~SSPTXINTR;
144
- }
145
- if (this.rxFIFO.itemCount >= this.rxFIFO.size / 2) {
146
- this.intRaw |= SSPRXINTR;
147
- }
148
- else {
149
- this.intRaw &= ~SSPRXINTR;
150
- }
151
- if (this.intStatus !== prevStatus) {
152
- this.checkInterrupts();
153
- }
154
- this.updateDMATx();
155
- this.updateDMARx();
156
- }
157
- readUint32(offset) {
158
- switch (offset) {
159
- case SSPCR0:
160
- return this.control0;
161
- case SSPCR1:
162
- return this.control1;
163
- case SSPDR:
164
- if (!this.rxFIFO.empty) {
165
- const value = this.rxFIFO.pull();
166
- this.fifosUpdated();
167
- return value;
168
- }
169
- return 0;
170
- case SSPSR:
171
- return ((this.busy || !this.txFIFO.empty ? BSY : 0) |
172
- (this.rxFIFO.full ? RFF : 0) |
173
- (!this.rxFIFO.empty ? RNE : 0) |
174
- (!this.txFIFO.full ? TNF : 0) |
175
- (this.txFIFO.empty ? TFE : 0));
176
- case SSPCPSR:
177
- return this.clockDivisor;
178
- case SSPIMSC:
179
- return this.intEnable;
180
- case SSPRIS:
181
- return this.intRaw;
182
- case SSPMIS:
183
- return this.intStatus;
184
- case SSPDMACR:
185
- return this.dmaControl;
186
- case SSPPERIPHID0:
187
- return 0x22;
188
- case SSPPERIPHID1:
189
- return 0x10;
190
- case SSPPERIPHID2:
191
- return 0x34;
192
- case SSPPERIPHID3:
193
- return 0x00;
194
- case SSPPCELLID0:
195
- return 0x0d;
196
- case SSPPCELLID1:
197
- return 0xf0;
198
- case SSPPCELLID2:
199
- return 0x05;
200
- case SSPPCELLID3:
201
- return 0xb1;
202
- }
203
- return super.readUint32(offset);
204
- }
205
- writeUint32(offset, value) {
206
- switch (offset) {
207
- case SSPCR0:
208
- this.control0 = value;
209
- return;
210
- case SSPCR1:
211
- this.control1 = value;
212
- return;
213
- case SSPDR:
214
- if (!this.txFIFO.full) {
215
- // decoded with respect to SSPCR0.DSS
216
- this.txFIFO.push(value & ((1 << this.dataBits) - 1));
217
- this.doTX();
218
- this.fifosUpdated();
219
- }
220
- return;
221
- case SSPCPSR:
222
- this.clockDivisor = value & CPSDVSR_MASK;
223
- return;
224
- case SSPIMSC:
225
- this.intEnable = value;
226
- this.checkInterrupts();
227
- return;
228
- case SSPDMACR:
229
- this.dmaControl = value;
230
- return;
231
- case SSPICR:
232
- this.intRaw &= ~(value & (SSPRTINTR | SSPRORINTR));
233
- this.checkInterrupts();
234
- return;
235
- default:
236
- super.writeUint32(offset, value);
237
- }
238
- }
239
- }
240
- exports.RPSPI = RPSPI;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RPSPI = void 0;
4
+ const fifo_js_1 = require("../utils/fifo.js");
5
+ const peripheral_js_1 = require("./peripheral.js");
6
+ const SSPCR0 = 0x000; // Control register 0, SSPCR0 on page 3-4
7
+ const SSPCR1 = 0x004; // Control register 1, SSPCR1 on page 3-5
8
+ const SSPDR = 0x008; // Data register, SSPDR on page 3-6
9
+ const SSPSR = 0x00c; // Status register, SSPSR on page 3-7
10
+ const SSPCPSR = 0x010; // Clock prescale register, SSPCPSR on page 3-8
11
+ const SSPIMSC = 0x014; // Interrupt mask set or clear register, SSPIMSC on page 3-9
12
+ const SSPRIS = 0x018; // Raw interrupt status register, SSPRIS on page 3-10
13
+ const SSPMIS = 0x01c; // Masked interrupt status register, SSPMIS on page 3-11
14
+ const SSPICR = 0x020; // Interrupt clear register, SSPICR on page 3-11
15
+ const SSPDMACR = 0x024; // DMA control register, SSPDMACR on page 3-12
16
+ const SSPPERIPHID0 = 0xfe0; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
17
+ const SSPPERIPHID1 = 0xfe4; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
18
+ const SSPPERIPHID2 = 0xfe8; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
19
+ const SSPPERIPHID3 = 0xfec; // Peripheral identification registers, SSPPeriphID0-3 on page 3-13
20
+ const SSPPCELLID0 = 0xff0; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
21
+ const SSPPCELLID1 = 0xff4; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
22
+ const SSPPCELLID2 = 0xff8; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
23
+ const SSPPCELLID3 = 0xffc; // PrimeCell identification registers, SSPPCellID0-3 on page 3-16
24
+ // SSPCR0 bits:
25
+ const SCR_MASK = 0xff;
26
+ const SCR_SHIFT = 8;
27
+ const SPH = 1 << 7;
28
+ const SPO = 1 << 6;
29
+ const FRF_MASK = 0x3;
30
+ const FRF_SHIFT = 4;
31
+ const DSS_MASK = 0xf;
32
+ const DSS_SHIFT = 0;
33
+ // SSPCR1 bits:
34
+ const SOD = 1 << 3;
35
+ const MS = 1 << 2;
36
+ const SSE = 1 << 1;
37
+ const LBM = 1 << 0;
38
+ // SSPSR bits:
39
+ const BSY = 1 << 4;
40
+ const RFF = 1 << 3;
41
+ const RNE = 1 << 2;
42
+ const TNF = 1 << 1;
43
+ const TFE = 1 << 0;
44
+ // SSPCPSR bits:
45
+ const CPSDVSR_MASK = 0xfe;
46
+ const CPSDVSR_SHIFT = 0;
47
+ // SSPDMACR bits:
48
+ const TXDMAE = 1 << 1;
49
+ const RXDMAE = 1 << 0;
50
+ // Interrupts:
51
+ const SSPTXINTR = 1 << 3;
52
+ const SSPRXINTR = 1 << 2;
53
+ const SSPRTINTR = 1 << 1;
54
+ const SSPRORINTR = 1 << 0;
55
+ class RPSPI extends peripheral_js_1.BasePeripheral {
56
+ get intStatus() {
57
+ return this.intRaw & this.intEnable;
58
+ }
59
+ get enabled() {
60
+ return !!(this.control1 & SSE);
61
+ }
62
+ /** Data size in bits: 4 to 16 bits */
63
+ get dataBits() {
64
+ return ((this.control0 >> DSS_SHIFT) & DSS_MASK) + 1;
65
+ }
66
+ get masterMode() {
67
+ return !(this.control0 & MS);
68
+ }
69
+ get spiMode() {
70
+ const cpol = this.control0 & SPO;
71
+ const cpha = this.control0 & SPH;
72
+ return cpol ? (cpha ? 2 : 3) : cpha ? 1 : 0;
73
+ }
74
+ get clockFrequency() {
75
+ if (!this.clockDivisor) {
76
+ return 0;
77
+ }
78
+ const scr = (this.control0 >> SCR_SHIFT) & SCR_MASK;
79
+ return this.rp2040.clkPeri / (this.clockDivisor * (1 + scr));
80
+ }
81
+ updateDMATx() {
82
+ if (this.txFIFO.full) {
83
+ this.rp2040.dma.clearDREQ(this.dreq.tx);
84
+ }
85
+ else {
86
+ this.rp2040.dma.setDREQ(this.dreq.tx);
87
+ }
88
+ }
89
+ updateDMARx() {
90
+ if (this.rxFIFO.empty) {
91
+ this.rp2040.dma.clearDREQ(this.dreq.rx);
92
+ }
93
+ else {
94
+ this.rp2040.dma.setDREQ(this.dreq.rx);
95
+ }
96
+ }
97
+ constructor(rp2040, name, irq, dreq) {
98
+ super(rp2040, name);
99
+ this.irq = irq;
100
+ this.dreq = dreq;
101
+ this.rxFIFO = new fifo_js_1.FIFO(8);
102
+ this.txFIFO = new fifo_js_1.FIFO(8);
103
+ // User provided callbacks
104
+ this.onTransmit = () => this.completeTransmit(0);
105
+ this.busy = false;
106
+ this.control0 = 0;
107
+ this.control1 = 0;
108
+ this.dmaControl = 0;
109
+ this.clockDivisor = 0;
110
+ this.intRaw = 0;
111
+ this.intEnable = 0;
112
+ this.updateDMATx();
113
+ this.updateDMARx();
114
+ }
115
+ doTX() {
116
+ if (!this.busy && !this.txFIFO.empty) {
117
+ const value = this.txFIFO.pull();
118
+ this.busy = true;
119
+ this.onTransmit(value);
120
+ this.fifosUpdated();
121
+ }
122
+ }
123
+ completeTransmit(rxValue) {
124
+ this.busy = false;
125
+ if (!this.rxFIFO.full) {
126
+ this.rxFIFO.push(rxValue);
127
+ }
128
+ else {
129
+ this.intRaw |= SSPRORINTR;
130
+ }
131
+ this.fifosUpdated();
132
+ this.doTX();
133
+ }
134
+ checkInterrupts() {
135
+ this.rp2040.setInterrupt(this.irq, !!this.intStatus);
136
+ }
137
+ fifosUpdated() {
138
+ const prevStatus = this.intStatus;
139
+ if (this.txFIFO.itemCount <= this.txFIFO.size / 2) {
140
+ this.intRaw |= SSPTXINTR;
141
+ }
142
+ else {
143
+ this.intRaw &= ~SSPTXINTR;
144
+ }
145
+ if (this.rxFIFO.itemCount >= this.rxFIFO.size / 2) {
146
+ this.intRaw |= SSPRXINTR;
147
+ }
148
+ else {
149
+ this.intRaw &= ~SSPRXINTR;
150
+ }
151
+ if (this.intStatus !== prevStatus) {
152
+ this.checkInterrupts();
153
+ }
154
+ this.updateDMATx();
155
+ this.updateDMARx();
156
+ }
157
+ readUint32(offset) {
158
+ switch (offset) {
159
+ case SSPCR0:
160
+ return this.control0;
161
+ case SSPCR1:
162
+ return this.control1;
163
+ case SSPDR:
164
+ if (!this.rxFIFO.empty) {
165
+ const value = this.rxFIFO.pull();
166
+ this.fifosUpdated();
167
+ return value;
168
+ }
169
+ return 0;
170
+ case SSPSR:
171
+ return ((this.busy || !this.txFIFO.empty ? BSY : 0) |
172
+ (this.rxFIFO.full ? RFF : 0) |
173
+ (!this.rxFIFO.empty ? RNE : 0) |
174
+ (!this.txFIFO.full ? TNF : 0) |
175
+ (this.txFIFO.empty ? TFE : 0));
176
+ case SSPCPSR:
177
+ return this.clockDivisor;
178
+ case SSPIMSC:
179
+ return this.intEnable;
180
+ case SSPRIS:
181
+ return this.intRaw;
182
+ case SSPMIS:
183
+ return this.intStatus;
184
+ case SSPDMACR:
185
+ return this.dmaControl;
186
+ case SSPPERIPHID0:
187
+ return 0x22;
188
+ case SSPPERIPHID1:
189
+ return 0x10;
190
+ case SSPPERIPHID2:
191
+ return 0x34;
192
+ case SSPPERIPHID3:
193
+ return 0x00;
194
+ case SSPPCELLID0:
195
+ return 0x0d;
196
+ case SSPPCELLID1:
197
+ return 0xf0;
198
+ case SSPPCELLID2:
199
+ return 0x05;
200
+ case SSPPCELLID3:
201
+ return 0xb1;
202
+ }
203
+ return super.readUint32(offset);
204
+ }
205
+ writeUint32(offset, value) {
206
+ switch (offset) {
207
+ case SSPCR0:
208
+ this.control0 = value;
209
+ return;
210
+ case SSPCR1:
211
+ this.control1 = value;
212
+ return;
213
+ case SSPDR:
214
+ if (!this.txFIFO.full) {
215
+ // decoded with respect to SSPCR0.DSS
216
+ this.txFIFO.push(value & ((1 << this.dataBits) - 1));
217
+ this.doTX();
218
+ this.fifosUpdated();
219
+ }
220
+ return;
221
+ case SSPCPSR:
222
+ this.clockDivisor = value & CPSDVSR_MASK;
223
+ return;
224
+ case SSPIMSC:
225
+ this.intEnable = value;
226
+ this.checkInterrupts();
227
+ return;
228
+ case SSPDMACR:
229
+ this.dmaControl = value;
230
+ return;
231
+ case SSPICR:
232
+ this.intRaw &= ~(value & (SSPRTINTR | SSPRORINTR));
233
+ this.checkInterrupts();
234
+ return;
235
+ default:
236
+ super.writeUint32(offset, value);
237
+ }
238
+ }
239
+ }
240
+ exports.RPSPI = RPSPI;
@@ -1,6 +1,6 @@
1
- import { BasePeripheral, Peripheral } from './peripheral';
2
- export declare class RPSSI extends BasePeripheral implements Peripheral {
3
- private dr0;
4
- readUint32(offset: number): number;
5
- writeUint32(offset: number, value: number): void;
6
- }
1
+ import { BasePeripheral, Peripheral } from './peripheral.js';
2
+ export declare class RPSSI extends BasePeripheral implements Peripheral {
3
+ private dr0;
4
+ readUint32(offset: number): number;
5
+ writeUint32(offset: number, value: number): void;
6
+ }
@@ -1,43 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RPSSI = void 0;
4
- const peripheral_1 = require("./peripheral");
5
- const SSI_TXFLR = 0x00000020;
6
- const SSI_RXFLR = 0x00000024;
7
- const SSI_SR = 0x00000028;
8
- const SSI_DR0 = 0x00000060;
9
- const SSI_SR_TFNF_BITS = 0x00000002;
10
- const SSI_SR_TFE_BITS = 0x00000004;
11
- const SSI_SR_RFNE_BITS = 0x00000008;
12
- const CMD_READ_STATUS = 0x05;
13
- class RPSSI extends peripheral_1.BasePeripheral {
14
- constructor() {
15
- super(...arguments);
16
- this.dr0 = 0;
17
- }
18
- readUint32(offset) {
19
- switch (offset) {
20
- case SSI_TXFLR:
21
- return 0;
22
- case SSI_RXFLR:
23
- return 0;
24
- case SSI_SR:
25
- return SSI_SR_TFE_BITS | SSI_SR_RFNE_BITS | SSI_SR_TFNF_BITS;
26
- case SSI_DR0:
27
- return this.dr0;
28
- }
29
- return super.readUint32(offset);
30
- }
31
- writeUint32(offset, value) {
32
- switch (offset) {
33
- case SSI_DR0:
34
- if (value === CMD_READ_STATUS) {
35
- this.dr0 = 0; // tell stage2 that we completed a write
36
- }
37
- return;
38
- default:
39
- super.writeUint32(offset, value);
40
- }
41
- }
42
- }
43
- exports.RPSSI = RPSSI;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RPSSI = void 0;
4
+ const peripheral_js_1 = require("./peripheral.js");
5
+ const SSI_TXFLR = 0x00000020;
6
+ const SSI_RXFLR = 0x00000024;
7
+ const SSI_SR = 0x00000028;
8
+ const SSI_DR0 = 0x00000060;
9
+ const SSI_SR_TFNF_BITS = 0x00000002;
10
+ const SSI_SR_TFE_BITS = 0x00000004;
11
+ const SSI_SR_RFNE_BITS = 0x00000008;
12
+ const CMD_READ_STATUS = 0x05;
13
+ class RPSSI extends peripheral_js_1.BasePeripheral {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.dr0 = 0;
17
+ }
18
+ readUint32(offset) {
19
+ switch (offset) {
20
+ case SSI_TXFLR:
21
+ return 0;
22
+ case SSI_RXFLR:
23
+ return 0;
24
+ case SSI_SR:
25
+ return SSI_SR_TFE_BITS | SSI_SR_RFNE_BITS | SSI_SR_TFNF_BITS;
26
+ case SSI_DR0:
27
+ return this.dr0;
28
+ }
29
+ return super.readUint32(offset);
30
+ }
31
+ writeUint32(offset, value) {
32
+ switch (offset) {
33
+ case SSI_DR0:
34
+ if (value === CMD_READ_STATUS) {
35
+ this.dr0 = 0; // tell stage2 that we completed a write
36
+ }
37
+ return;
38
+ default:
39
+ super.writeUint32(offset, value);
40
+ }
41
+ }
42
+ }
43
+ exports.RPSSI = RPSSI;
@@ -1,5 +1,5 @@
1
- import { BasePeripheral, Peripheral } from './peripheral';
2
- export declare class RP2040SysCfg extends BasePeripheral implements Peripheral {
3
- readUint32(offset: number): number;
4
- writeUint32(offset: number, value: number): void;
5
- }
1
+ import { BasePeripheral, Peripheral } from './peripheral.js';
2
+ export declare class RP2040SysCfg extends BasePeripheral implements Peripheral {
3
+ readUint32(offset: number): number;
4
+ writeUint32(offset: number, value: number): void;
5
+ }
@@ -1,26 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RP2040SysCfg = void 0;
4
- const peripheral_1 = require("./peripheral");
5
- const PROC0_NMI_MASK = 0;
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
- const PROC1_NMI_MASK = 4;
8
- class RP2040SysCfg extends peripheral_1.BasePeripheral {
9
- readUint32(offset) {
10
- switch (offset) {
11
- case PROC0_NMI_MASK:
12
- return this.rp2040.core.interruptNMIMask;
13
- }
14
- return super.readUint32(offset);
15
- }
16
- writeUint32(offset, value) {
17
- switch (offset) {
18
- case PROC0_NMI_MASK:
19
- this.rp2040.core.interruptNMIMask = value;
20
- break;
21
- default:
22
- super.writeUint32(offset, value);
23
- }
24
- }
25
- }
26
- exports.RP2040SysCfg = RP2040SysCfg;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RP2040SysCfg = void 0;
4
+ const peripheral_js_1 = require("./peripheral.js");
5
+ const PROC0_NMI_MASK = 0;
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ const PROC1_NMI_MASK = 4;
8
+ class RP2040SysCfg extends peripheral_js_1.BasePeripheral {
9
+ readUint32(offset) {
10
+ switch (offset) {
11
+ case PROC0_NMI_MASK:
12
+ return this.rp2040.core.interruptNMIMask;
13
+ }
14
+ return super.readUint32(offset);
15
+ }
16
+ writeUint32(offset, value) {
17
+ switch (offset) {
18
+ case PROC0_NMI_MASK:
19
+ this.rp2040.core.interruptNMIMask = value;
20
+ break;
21
+ default:
22
+ super.writeUint32(offset, value);
23
+ }
24
+ }
25
+ }
26
+ exports.RP2040SysCfg = RP2040SysCfg;
@@ -1,4 +1,4 @@
1
- import { BasePeripheral, Peripheral } from './peripheral';
2
- export declare class RP2040SysInfo extends BasePeripheral implements Peripheral {
3
- readUint32(offset: number): number;
4
- }
1
+ import { BasePeripheral, Peripheral } from './peripheral.js';
2
+ export declare class RP2040SysInfo extends BasePeripheral implements Peripheral {
3
+ readUint32(offset: number): number;
4
+ }