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,52 +1,52 @@
1
- import { RP2040 } from '../rp2040';
2
- import { FIFO } from '../utils/fifo';
3
- import { DREQChannel } from './dma';
4
- import { BasePeripheral, Peripheral } from './peripheral';
5
- export declare class RPADC extends BasePeripheral implements Peripheral {
6
- readonly numChannels = 5;
7
- /** ADC resolution (in bits) */
8
- readonly resolution = 12;
9
- /** Time to read a single sample, in microseconds */
10
- readonly sampleTime = 2;
11
- /**
12
- * ADC Channel values. Channels 0...3 are connected to GPIO 26...29, and channel 4 is connected to the built-in
13
- * temperature sensor: T=27-(ADC_voltage-0.706)/0.001721.
14
- *
15
- * Changing the values will change the ADC reading, unless you override onADCRead() with a custom implementation.
16
- */
17
- readonly channelValues: number[];
18
- /**
19
- * Invoked whenever the emulated code performs an ADC read.
20
- *
21
- * The default implementation reads the result from the `channelValues` array, and then calls
22
- * completeADCRead() after `sampleTime` milliseconds.
23
- *
24
- * If you override the default implementation, make sure to call `completeADCRead()` after
25
- * `sampleTime` milliseconds (or else the ADC read will never complete).
26
- */
27
- onADCRead: (channel: number) => void;
28
- readonly fifo: FIFO;
29
- readonly dreq = DREQChannel.DREQ_ADC;
30
- cs: number;
31
- fcs: number;
32
- clockDiv: number;
33
- intEnable: number;
34
- intForce: number;
35
- result: number;
36
- busy: boolean;
37
- err: boolean;
38
- get temperatueEnable(): number;
39
- get enabled(): number;
40
- get divider(): number;
41
- get intRaw(): number;
42
- get intStatus(): number;
43
- private get activeChannel();
44
- private set activeChannel(value);
45
- constructor(rp2040: RP2040, name: string);
46
- checkInterrupts(): void;
47
- startADCRead(): void;
48
- private updateDMA;
49
- completeADCRead(value: number, error: boolean): void;
50
- readUint32(offset: number): number;
51
- writeUint32(offset: number, value: number): void;
52
- }
1
+ import { RP2040 } from '../rp2040.js';
2
+ import { FIFO } from '../utils/fifo.js';
3
+ import { DREQChannel } from './dma.js';
4
+ import { BasePeripheral, Peripheral } from './peripheral.js';
5
+ export declare class RPADC extends BasePeripheral implements Peripheral {
6
+ readonly numChannels = 5;
7
+ /** ADC resolution (in bits) */
8
+ readonly resolution = 12;
9
+ /** Time to read a single sample, in microseconds */
10
+ readonly sampleTime = 2;
11
+ /**
12
+ * ADC Channel values. Channels 0...3 are connected to GPIO 26...29, and channel 4 is connected to the built-in
13
+ * temperature sensor: T=27-(ADC_voltage-0.706)/0.001721.
14
+ *
15
+ * Changing the values will change the ADC reading, unless you override onADCRead() with a custom implementation.
16
+ */
17
+ readonly channelValues: number[];
18
+ /**
19
+ * Invoked whenever the emulated code performs an ADC read.
20
+ *
21
+ * The default implementation reads the result from the `channelValues` array, and then calls
22
+ * completeADCRead() after `sampleTime` milliseconds.
23
+ *
24
+ * If you override the default implementation, make sure to call `completeADCRead()` after
25
+ * `sampleTime` milliseconds (or else the ADC read will never complete).
26
+ */
27
+ onADCRead: (channel: number) => void;
28
+ readonly fifo: FIFO;
29
+ readonly dreq = DREQChannel.DREQ_ADC;
30
+ cs: number;
31
+ fcs: number;
32
+ clockDiv: number;
33
+ intEnable: number;
34
+ intForce: number;
35
+ result: number;
36
+ busy: boolean;
37
+ err: boolean;
38
+ get temperatueEnable(): number;
39
+ get enabled(): number;
40
+ get divider(): number;
41
+ get intRaw(): number;
42
+ get intStatus(): number;
43
+ private get activeChannel();
44
+ private set activeChannel(value);
45
+ constructor(rp2040: RP2040, name: string);
46
+ checkInterrupts(): void;
47
+ startADCRead(): void;
48
+ private updateDMA;
49
+ completeADCRead(value: number, error: boolean): void;
50
+ readUint32(offset: number): number;
51
+ writeUint32(offset: number, value: number): void;
52
+ }
@@ -1,261 +1,261 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RPADC = void 0;
4
- const irq_1 = require("../irq");
5
- const fifo_1 = require("../utils/fifo");
6
- const dma_1 = require("./dma");
7
- const peripheral_1 = require("./peripheral");
8
- const CS = 0x00; // ADC Control and Status
9
- const RESULT = 0x04; // Result of most recent ADC conversion
10
- const FCS = 0x08; // FIFO control and status
11
- const FIFO_REG = 0x0c; // Conversion result FIFO
12
- const DIV = 0x10; // Clock divider.0x14 INTR Raw Interrupts
13
- const INTR = 0x14; // Raw Interrupts
14
- const INTE = 0x18; // Interrupt Enable
15
- const INTF = 0x1c; // Interrupt Force
16
- const INTS = 0x20; // Interrupt status after masking & forcing
17
- // CS bits
18
- const CS_RROBIN_MASK = 0x1f;
19
- const CS_RROBIN_SHIFT = 16;
20
- const CS_AINSEL_MASK = 0x7;
21
- const CS_AINSEL_SHIFT = 12;
22
- const CS_ERR_STICKY = 1 << 10;
23
- const CS_ERR = 1 << 9;
24
- const CS_READY = 1 << 8;
25
- const CS_START_MANY = 1 << 3;
26
- const CS_START_ONE = 1 << 2;
27
- const CS_TS_EN = 1 << 1;
28
- const CS_EN = 1 << 0;
29
- const CS_WRITE_MASK = (CS_RROBIN_MASK << CS_RROBIN_SHIFT) |
30
- (CS_AINSEL_MASK << CS_AINSEL_SHIFT) |
31
- CS_START_MANY |
32
- CS_START_ONE |
33
- CS_TS_EN |
34
- CS_EN;
35
- // FCS bits
36
- const FCS_THRES_MASK = 0xf;
37
- const FCS_THRESH_SHIFT = 24;
38
- const FCS_LEVEL_MASK = 0xf;
39
- const FCS_LEVEL_SHIFT = 16;
40
- const FCS_OVER = 1 << 11;
41
- const FCS_UNDER = 1 << 10;
42
- const FCS_FULL = 1 << 9;
43
- const FCS_EMPTY = 1 << 8;
44
- const FCS_DREQ_EN = 1 << 3;
45
- const FCS_ERR = 1 << 2;
46
- const FCS_SHIFT = 1 << 1;
47
- const FCS_EN = 1 << 0;
48
- const FCS_WRITE_MASK = (FCS_THRES_MASK << FCS_THRESH_SHIFT) | FCS_DREQ_EN | FCS_ERR | FCS_SHIFT | FCS_EN;
49
- // FIFO_REG bits
50
- const FIFO_ERR = 1 << 15;
51
- // DIV bits
52
- const DIV_INT_MASK = 0xffff;
53
- const DIV_INT_SHIFT = 8;
54
- const DIV_FRAC_MASK = 0xff;
55
- const DIV_FRAC_SHIFT = 0;
56
- // Interrupt bits
57
- const FIFO_INT = 1 << 0;
58
- class RPADC extends peripheral_1.BasePeripheral {
59
- constructor(rp2040, name) {
60
- super(rp2040, name);
61
- /* Number of ADC channels */
62
- this.numChannels = 5;
63
- /** ADC resolution (in bits) */
64
- this.resolution = 12;
65
- /** Time to read a single sample, in microseconds */
66
- this.sampleTime = 2;
67
- /**
68
- * ADC Channel values. Channels 0...3 are connected to GPIO 26...29, and channel 4 is connected to the built-in
69
- * temperature sensor: T=27-(ADC_voltage-0.706)/0.001721.
70
- *
71
- * Changing the values will change the ADC reading, unless you override onADCRead() with a custom implementation.
72
- */
73
- this.channelValues = [0, 0, 0, 0, 0];
74
- /**
75
- * Invoked whenever the emulated code performs an ADC read.
76
- *
77
- * The default implementation reads the result from the `channelValues` array, and then calls
78
- * completeADCRead() after `sampleTime` milliseconds.
79
- *
80
- * If you override the default implementation, make sure to call `completeADCRead()` after
81
- * `sampleTime` milliseconds (or else the ADC read will never complete).
82
- */
83
- this.onADCRead = (channel) => {
84
- // Default implementation
85
- this.rp2040.clock.createTimer(this.sampleTime, () => this.completeADCRead(this.channelValues[channel], false));
86
- };
87
- this.fifo = new fifo_1.FIFO(4);
88
- this.dreq = dma_1.DREQChannel.DREQ_ADC;
89
- // Registers
90
- this.cs = 0;
91
- this.fcs = 0;
92
- this.clockDiv = 0;
93
- this.intEnable = 0;
94
- this.intForce = 0;
95
- this.result = 0;
96
- // Status
97
- this.busy = false;
98
- this.err = false;
99
- }
100
- get temperatueEnable() {
101
- return this.cs & CS_TS_EN;
102
- }
103
- get enabled() {
104
- return this.cs & CS_EN;
105
- }
106
- get divider() {
107
- return (1 +
108
- ((this.clockDiv >> DIV_INT_SHIFT) & DIV_INT_MASK) +
109
- ((this.clockDiv >> DIV_FRAC_SHIFT) & DIV_FRAC_MASK) / 256);
110
- }
111
- get intRaw() {
112
- const thres = (this.fcs >> FCS_THRESH_SHIFT) & FCS_THRES_MASK;
113
- return this.fifo.itemCount >= thres ? FIFO_INT : 0;
114
- }
115
- get intStatus() {
116
- return (this.intRaw & this.intEnable) | this.intForce;
117
- }
118
- get activeChannel() {
119
- return (this.cs >> CS_AINSEL_SHIFT) & CS_AINSEL_MASK;
120
- }
121
- set activeChannel(channel) {
122
- this.cs &= ~(CS_AINSEL_MASK << CS_AINSEL_SHIFT);
123
- this.cs |= (channel & CS_AINSEL_SHIFT) << CS_AINSEL_SHIFT;
124
- }
125
- checkInterrupts() {
126
- this.rp2040.setInterrupt(irq_1.IRQ.ADC_FIFO, !!this.intStatus);
127
- }
128
- startADCRead() {
129
- this.busy = true;
130
- this.onADCRead(this.activeChannel);
131
- }
132
- updateDMA() {
133
- if (this.fcs & FCS_DREQ_EN) {
134
- const thres = (this.fcs >> FCS_THRESH_SHIFT) & FCS_THRES_MASK;
135
- if (this.fifo.itemCount >= thres) {
136
- this.rp2040.dma.setDREQ(this.dreq);
137
- }
138
- else {
139
- this.rp2040.dma.clearDREQ(this.dreq);
140
- }
141
- }
142
- }
143
- completeADCRead(value, error) {
144
- this.busy = false;
145
- this.result = value;
146
- if (error) {
147
- this.cs |= CS_ERR_STICKY | CS_ERR;
148
- }
149
- else {
150
- this.cs &= ~CS_ERR;
151
- }
152
- // FIFO
153
- if (this.fcs & FCS_EN) {
154
- if (this.fifo.full) {
155
- this.fcs |= FCS_OVER;
156
- }
157
- else {
158
- value &= 0xfff; // 12 bits
159
- if (this.fcs & FCS_SHIFT) {
160
- value >>= 4;
161
- }
162
- if (error && this.fcs & FCS_ERR) {
163
- value |= FIFO_ERR;
164
- }
165
- this.fifo.push(value);
166
- this.updateDMA();
167
- this.checkInterrupts();
168
- }
169
- }
170
- // Round-robin
171
- const round = (this.cs >> CS_RROBIN_SHIFT) & CS_RROBIN_MASK;
172
- if (round) {
173
- let channel = this.activeChannel + 1;
174
- while (!(round & (1 << channel))) {
175
- channel = (channel + 1) % this.numChannels;
176
- }
177
- this.activeChannel = channel;
178
- }
179
- // Multi-shot conversions
180
- if (this.cs & CS_START_MANY) {
181
- const clockMHZ = 48;
182
- const sampleTicks = clockMHZ * this.sampleTime;
183
- if (this.divider > sampleTicks) {
184
- // clock runs at 48MHz, subtract 2uS
185
- const micros = (this.divider - sampleTicks) / clockMHZ;
186
- this.rp2040.clock.createTimer(micros, () => {
187
- if (this.cs & CS_START_MANY) {
188
- this.startADCRead();
189
- }
190
- });
191
- }
192
- else {
193
- this.startADCRead();
194
- }
195
- }
196
- }
197
- readUint32(offset) {
198
- switch (offset) {
199
- case CS:
200
- return this.cs | (this.err ? CS_ERR : 0) | (this.busy ? 0 : CS_READY);
201
- case RESULT:
202
- return this.result;
203
- case FCS:
204
- return (this.fcs |
205
- ((this.fifo.itemCount & FCS_LEVEL_MASK) << FCS_LEVEL_SHIFT) |
206
- (this.fifo.full ? FCS_FULL : 0) |
207
- (this.fifo.empty ? FCS_EMPTY : 0));
208
- case FIFO_REG:
209
- if (this.fifo.empty) {
210
- this.fcs |= FCS_UNDER;
211
- return 0;
212
- }
213
- else {
214
- const value = this.fifo.pull();
215
- this.updateDMA();
216
- return value;
217
- }
218
- case DIV:
219
- return this.clockDiv;
220
- case INTR:
221
- return this.intRaw;
222
- case INTE:
223
- return this.intEnable;
224
- case INTF:
225
- return this.intForce;
226
- case INTS:
227
- return this.intStatus;
228
- }
229
- return super.readUint32(offset);
230
- }
231
- writeUint32(offset, value) {
232
- switch (offset) {
233
- case CS:
234
- this.fcs &= ~(value & CS_ERR_STICKY); // Write-clear bits
235
- this.cs = (this.cs & ~CS_WRITE_MASK) | (value & CS_WRITE_MASK);
236
- if (value & CS_EN && !this.busy && (value & CS_START_ONE || value & CS_START_MANY)) {
237
- this.startADCRead();
238
- }
239
- break;
240
- case FCS:
241
- this.fcs &= ~(value & (FCS_OVER | FCS_UNDER)); // Write-clear bits
242
- this.fcs = (this.fcs & ~FCS_WRITE_MASK) | (value & FCS_WRITE_MASK);
243
- this.checkInterrupts();
244
- break;
245
- case DIV:
246
- this.clockDiv = value;
247
- break;
248
- case INTE:
249
- this.intEnable = value & FIFO_INT;
250
- this.checkInterrupts();
251
- break;
252
- case INTF:
253
- this.intForce = value & FIFO_INT;
254
- this.checkInterrupts();
255
- break;
256
- default:
257
- super.writeUint32(offset, value);
258
- }
259
- }
260
- }
261
- exports.RPADC = RPADC;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RPADC = void 0;
4
+ const irq_js_1 = require("../irq.js");
5
+ const fifo_js_1 = require("../utils/fifo.js");
6
+ const dma_js_1 = require("./dma.js");
7
+ const peripheral_js_1 = require("./peripheral.js");
8
+ const CS = 0x00; // ADC Control and Status
9
+ const RESULT = 0x04; // Result of most recent ADC conversion
10
+ const FCS = 0x08; // FIFO control and status
11
+ const FIFO_REG = 0x0c; // Conversion result FIFO
12
+ const DIV = 0x10; // Clock divider.0x14 INTR Raw Interrupts
13
+ const INTR = 0x14; // Raw Interrupts
14
+ const INTE = 0x18; // Interrupt Enable
15
+ const INTF = 0x1c; // Interrupt Force
16
+ const INTS = 0x20; // Interrupt status after masking & forcing
17
+ // CS bits
18
+ const CS_RROBIN_MASK = 0x1f;
19
+ const CS_RROBIN_SHIFT = 16;
20
+ const CS_AINSEL_MASK = 0x7;
21
+ const CS_AINSEL_SHIFT = 12;
22
+ const CS_ERR_STICKY = 1 << 10;
23
+ const CS_ERR = 1 << 9;
24
+ const CS_READY = 1 << 8;
25
+ const CS_START_MANY = 1 << 3;
26
+ const CS_START_ONE = 1 << 2;
27
+ const CS_TS_EN = 1 << 1;
28
+ const CS_EN = 1 << 0;
29
+ const CS_WRITE_MASK = (CS_RROBIN_MASK << CS_RROBIN_SHIFT) |
30
+ (CS_AINSEL_MASK << CS_AINSEL_SHIFT) |
31
+ CS_START_MANY |
32
+ CS_START_ONE |
33
+ CS_TS_EN |
34
+ CS_EN;
35
+ // FCS bits
36
+ const FCS_THRES_MASK = 0xf;
37
+ const FCS_THRESH_SHIFT = 24;
38
+ const FCS_LEVEL_MASK = 0xf;
39
+ const FCS_LEVEL_SHIFT = 16;
40
+ const FCS_OVER = 1 << 11;
41
+ const FCS_UNDER = 1 << 10;
42
+ const FCS_FULL = 1 << 9;
43
+ const FCS_EMPTY = 1 << 8;
44
+ const FCS_DREQ_EN = 1 << 3;
45
+ const FCS_ERR = 1 << 2;
46
+ const FCS_SHIFT = 1 << 1;
47
+ const FCS_EN = 1 << 0;
48
+ const FCS_WRITE_MASK = (FCS_THRES_MASK << FCS_THRESH_SHIFT) | FCS_DREQ_EN | FCS_ERR | FCS_SHIFT | FCS_EN;
49
+ // FIFO_REG bits
50
+ const FIFO_ERR = 1 << 15;
51
+ // DIV bits
52
+ const DIV_INT_MASK = 0xffff;
53
+ const DIV_INT_SHIFT = 8;
54
+ const DIV_FRAC_MASK = 0xff;
55
+ const DIV_FRAC_SHIFT = 0;
56
+ // Interrupt bits
57
+ const FIFO_INT = 1 << 0;
58
+ class RPADC extends peripheral_js_1.BasePeripheral {
59
+ get temperatueEnable() {
60
+ return this.cs & CS_TS_EN;
61
+ }
62
+ get enabled() {
63
+ return this.cs & CS_EN;
64
+ }
65
+ get divider() {
66
+ return (1 +
67
+ ((this.clockDiv >> DIV_INT_SHIFT) & DIV_INT_MASK) +
68
+ ((this.clockDiv >> DIV_FRAC_SHIFT) & DIV_FRAC_MASK) / 256);
69
+ }
70
+ get intRaw() {
71
+ const thres = (this.fcs >> FCS_THRESH_SHIFT) & FCS_THRES_MASK;
72
+ return this.fifo.itemCount >= thres ? FIFO_INT : 0;
73
+ }
74
+ get intStatus() {
75
+ return (this.intRaw & this.intEnable) | this.intForce;
76
+ }
77
+ get activeChannel() {
78
+ return (this.cs >> CS_AINSEL_SHIFT) & CS_AINSEL_MASK;
79
+ }
80
+ set activeChannel(channel) {
81
+ this.cs &= ~(CS_AINSEL_MASK << CS_AINSEL_SHIFT);
82
+ this.cs |= (channel & CS_AINSEL_SHIFT) << CS_AINSEL_SHIFT;
83
+ }
84
+ constructor(rp2040, name) {
85
+ super(rp2040, name);
86
+ /* Number of ADC channels */
87
+ this.numChannels = 5;
88
+ /** ADC resolution (in bits) */
89
+ this.resolution = 12;
90
+ /** Time to read a single sample, in microseconds */
91
+ this.sampleTime = 2;
92
+ /**
93
+ * ADC Channel values. Channels 0...3 are connected to GPIO 26...29, and channel 4 is connected to the built-in
94
+ * temperature sensor: T=27-(ADC_voltage-0.706)/0.001721.
95
+ *
96
+ * Changing the values will change the ADC reading, unless you override onADCRead() with a custom implementation.
97
+ */
98
+ this.channelValues = [0, 0, 0, 0, 0];
99
+ /**
100
+ * Invoked whenever the emulated code performs an ADC read.
101
+ *
102
+ * The default implementation reads the result from the `channelValues` array, and then calls
103
+ * completeADCRead() after `sampleTime` milliseconds.
104
+ *
105
+ * If you override the default implementation, make sure to call `completeADCRead()` after
106
+ * `sampleTime` milliseconds (or else the ADC read will never complete).
107
+ */
108
+ this.onADCRead = (channel) => {
109
+ // Default implementation
110
+ this.rp2040.clock.createTimer(this.sampleTime, () => this.completeADCRead(this.channelValues[channel], false));
111
+ };
112
+ this.fifo = new fifo_js_1.FIFO(4);
113
+ this.dreq = dma_js_1.DREQChannel.DREQ_ADC;
114
+ // Registers
115
+ this.cs = 0;
116
+ this.fcs = 0;
117
+ this.clockDiv = 0;
118
+ this.intEnable = 0;
119
+ this.intForce = 0;
120
+ this.result = 0;
121
+ // Status
122
+ this.busy = false;
123
+ this.err = false;
124
+ }
125
+ checkInterrupts() {
126
+ this.rp2040.setInterrupt(irq_js_1.IRQ.ADC_FIFO, !!this.intStatus);
127
+ }
128
+ startADCRead() {
129
+ this.busy = true;
130
+ this.onADCRead(this.activeChannel);
131
+ }
132
+ updateDMA() {
133
+ if (this.fcs & FCS_DREQ_EN) {
134
+ const thres = (this.fcs >> FCS_THRESH_SHIFT) & FCS_THRES_MASK;
135
+ if (this.fifo.itemCount >= thres) {
136
+ this.rp2040.dma.setDREQ(this.dreq);
137
+ }
138
+ else {
139
+ this.rp2040.dma.clearDREQ(this.dreq);
140
+ }
141
+ }
142
+ }
143
+ completeADCRead(value, error) {
144
+ this.busy = false;
145
+ this.result = value;
146
+ if (error) {
147
+ this.cs |= CS_ERR_STICKY | CS_ERR;
148
+ }
149
+ else {
150
+ this.cs &= ~CS_ERR;
151
+ }
152
+ // FIFO
153
+ if (this.fcs & FCS_EN) {
154
+ if (this.fifo.full) {
155
+ this.fcs |= FCS_OVER;
156
+ }
157
+ else {
158
+ value &= 0xfff; // 12 bits
159
+ if (this.fcs & FCS_SHIFT) {
160
+ value >>= 4;
161
+ }
162
+ if (error && this.fcs & FCS_ERR) {
163
+ value |= FIFO_ERR;
164
+ }
165
+ this.fifo.push(value);
166
+ this.updateDMA();
167
+ this.checkInterrupts();
168
+ }
169
+ }
170
+ // Round-robin
171
+ const round = (this.cs >> CS_RROBIN_SHIFT) & CS_RROBIN_MASK;
172
+ if (round) {
173
+ let channel = this.activeChannel + 1;
174
+ while (!(round & (1 << channel))) {
175
+ channel = (channel + 1) % this.numChannels;
176
+ }
177
+ this.activeChannel = channel;
178
+ }
179
+ // Multi-shot conversions
180
+ if (this.cs & CS_START_MANY) {
181
+ const clockMHZ = 48;
182
+ const sampleTicks = clockMHZ * this.sampleTime;
183
+ if (this.divider > sampleTicks) {
184
+ // clock runs at 48MHz, subtract 2uS
185
+ const micros = (this.divider - sampleTicks) / clockMHZ;
186
+ this.rp2040.clock.createTimer(micros, () => {
187
+ if (this.cs & CS_START_MANY) {
188
+ this.startADCRead();
189
+ }
190
+ });
191
+ }
192
+ else {
193
+ this.startADCRead();
194
+ }
195
+ }
196
+ }
197
+ readUint32(offset) {
198
+ switch (offset) {
199
+ case CS:
200
+ return this.cs | (this.err ? CS_ERR : 0) | (this.busy ? 0 : CS_READY);
201
+ case RESULT:
202
+ return this.result;
203
+ case FCS:
204
+ return (this.fcs |
205
+ ((this.fifo.itemCount & FCS_LEVEL_MASK) << FCS_LEVEL_SHIFT) |
206
+ (this.fifo.full ? FCS_FULL : 0) |
207
+ (this.fifo.empty ? FCS_EMPTY : 0));
208
+ case FIFO_REG:
209
+ if (this.fifo.empty) {
210
+ this.fcs |= FCS_UNDER;
211
+ return 0;
212
+ }
213
+ else {
214
+ const value = this.fifo.pull();
215
+ this.updateDMA();
216
+ return value;
217
+ }
218
+ case DIV:
219
+ return this.clockDiv;
220
+ case INTR:
221
+ return this.intRaw;
222
+ case INTE:
223
+ return this.intEnable;
224
+ case INTF:
225
+ return this.intForce;
226
+ case INTS:
227
+ return this.intStatus;
228
+ }
229
+ return super.readUint32(offset);
230
+ }
231
+ writeUint32(offset, value) {
232
+ switch (offset) {
233
+ case CS:
234
+ this.fcs &= ~(value & CS_ERR_STICKY); // Write-clear bits
235
+ this.cs = (this.cs & ~CS_WRITE_MASK) | (value & CS_WRITE_MASK);
236
+ if (value & CS_EN && !this.busy && (value & CS_START_ONE || value & CS_START_MANY)) {
237
+ this.startADCRead();
238
+ }
239
+ break;
240
+ case FCS:
241
+ this.fcs &= ~(value & (FCS_OVER | FCS_UNDER)); // Write-clear bits
242
+ this.fcs = (this.fcs & ~FCS_WRITE_MASK) | (value & FCS_WRITE_MASK);
243
+ this.checkInterrupts();
244
+ break;
245
+ case DIV:
246
+ this.clockDiv = value;
247
+ break;
248
+ case INTE:
249
+ this.intEnable = value & FIFO_INT;
250
+ this.checkInterrupts();
251
+ break;
252
+ case INTF:
253
+ this.intForce = value & FIFO_INT;
254
+ this.checkInterrupts();
255
+ break;
256
+ default:
257
+ super.writeUint32(offset, value);
258
+ }
259
+ }
260
+ }
261
+ exports.RPADC = RPADC;
@@ -1,10 +1,10 @@
1
- import { RP2040 } from '../rp2040';
2
- import { BasePeripheral, Peripheral } from './peripheral';
3
- export declare class RPBUSCTRL extends BasePeripheral implements Peripheral {
4
- voltageSelect: number;
5
- readonly perfCtr: number[];
6
- readonly perfSel: number[];
7
- constructor(rp2040: RP2040, name: string);
8
- readUint32(offset: number): number;
9
- writeUint32(offset: number, value: number): void;
10
- }
1
+ import { RP2040 } from '../rp2040.js';
2
+ import { BasePeripheral, Peripheral } from './peripheral.js';
3
+ export declare class RPBUSCTRL extends BasePeripheral implements Peripheral {
4
+ voltageSelect: number;
5
+ readonly perfCtr: number[];
6
+ readonly perfSel: number[];
7
+ constructor(rp2040: RP2040, name: string);
8
+ readUint32(offset: number): number;
9
+ writeUint32(offset: number, value: number): void;
10
+ }