rp2040js 0.17.17 → 0.18.1
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.
- package/dist/cjs/clock/clock.d.ts +11 -11
- package/dist/cjs/clock/clock.js +2 -2
- package/dist/cjs/clock/mock-clock.d.ts +17 -17
- package/dist/cjs/clock/mock-clock.js +52 -52
- package/dist/cjs/clock/realtime-clock.d.ts +23 -23
- package/dist/cjs/clock/realtime-clock.js +73 -73
- package/dist/cjs/cortex-m0-core.d.ts +87 -87
- package/dist/cjs/cortex-m0-core.js +1251 -1251
- package/dist/cjs/gdb/gdb-connection.d.ts +11 -11
- package/dist/cjs/gdb/gdb-connection.js +57 -57
- package/dist/cjs/gdb/gdb-server.d.ts +23 -23
- package/dist/cjs/gdb/gdb-server.js +232 -232
- package/dist/cjs/gdb/gdb-tcp-server.d.ts +10 -10
- package/dist/cjs/gdb/gdb-tcp-server.js +34 -34
- package/dist/cjs/gdb/gdb-utils.d.ts +9 -9
- package/dist/cjs/gdb/gdb-utils.js +48 -48
- package/dist/cjs/gpio-pin.d.ts +56 -56
- package/dist/cjs/gpio-pin.js +216 -216
- package/dist/cjs/index.d.ts +11 -11
- package/dist/cjs/index.js +36 -36
- package/dist/cjs/interpolator.d.ts +36 -36
- package/dist/cjs/interpolator.js +150 -150
- package/dist/cjs/irq.d.ts +29 -29
- package/dist/cjs/irq.js +33 -33
- package/dist/cjs/peripherals/adc.d.ts +52 -52
- package/dist/cjs/peripherals/adc.js +261 -261
- package/dist/cjs/peripherals/busctrl.d.ts +10 -10
- package/dist/cjs/peripherals/busctrl.js +84 -84
- package/dist/cjs/peripherals/clocks.d.ts +9 -9
- package/dist/cjs/peripherals/clocks.js +42 -42
- package/dist/cjs/peripherals/dma.d.ts +109 -109
- package/dist/cjs/peripherals/dma.js +520 -520
- package/dist/cjs/peripherals/i2c.d.ts +54 -54
- package/dist/cjs/peripherals/i2c.js +458 -458
- package/dist/cjs/peripherals/io.d.ts +11 -11
- package/dist/cjs/peripherals/io.js +100 -100
- package/dist/cjs/peripherals/pads.d.ts +13 -13
- package/dist/cjs/peripherals/pads.js +58 -58
- package/dist/cjs/peripherals/peripheral.d.ts +22 -22
- package/dist/cjs/peripherals/peripheral.js +61 -61
- package/dist/cjs/peripherals/pio.d.ts +120 -120
- package/dist/cjs/peripherals/pio.js +1086 -1086
- package/dist/cjs/peripherals/ppb.d.ts +25 -25
- package/dist/cjs/peripherals/ppb.js +229 -229
- package/dist/cjs/peripherals/pwm.d.ts +65 -65
- package/dist/cjs/peripherals/pwm.js +372 -372
- package/dist/cjs/peripherals/reset.d.ts +8 -8
- package/dist/cjs/peripherals/reset.js +40 -40
- package/dist/cjs/peripherals/rtc.d.ts +10 -10
- package/dist/cjs/peripherals/rtc.js +74 -74
- package/dist/cjs/peripherals/spi.d.ts +38 -38
- package/dist/cjs/peripherals/spi.js +240 -240
- package/dist/cjs/peripherals/ssi.d.ts +6 -6
- package/dist/cjs/peripherals/ssi.js +43 -43
- package/dist/cjs/peripherals/syscfg.d.ts +5 -5
- package/dist/cjs/peripherals/syscfg.js +26 -26
- package/dist/cjs/peripherals/sysinfo.d.ts +4 -4
- package/dist/cjs/peripherals/sysinfo.js +22 -22
- package/dist/cjs/peripherals/tbman.d.ts +4 -4
- package/dist/cjs/peripherals/tbman.js +17 -17
- package/dist/cjs/peripherals/timer.d.ts +18 -18
- package/dist/cjs/peripherals/timer.js +156 -156
- package/dist/cjs/peripherals/uart.d.ts +31 -31
- package/dist/cjs/peripherals/uart.js +132 -132
- package/dist/cjs/peripherals/usb.d.ts +29 -29
- package/dist/cjs/peripherals/usb.js +309 -309
- package/dist/cjs/rp2040.d.ts +71 -71
- package/dist/cjs/rp2040.js +361 -361
- package/dist/cjs/sio.d.ts +21 -21
- package/dist/cjs/sio.js +425 -425
- package/dist/cjs/usb/cdc.d.ts +20 -20
- package/dist/cjs/usb/cdc.js +126 -126
- package/dist/cjs/usb/interfaces.d.ts +47 -47
- package/dist/cjs/usb/interfaces.js +46 -46
- package/dist/cjs/usb/setup.d.ts +5 -5
- package/dist/cjs/usb/setup.js +53 -53
- package/dist/cjs/utils/assembler.d.ts +79 -79
- package/dist/cjs/utils/assembler.js +328 -328
- package/dist/cjs/utils/bit.d.ts +3 -3
- package/dist/cjs/utils/bit.js +15 -15
- package/dist/cjs/utils/fifo.d.ts +15 -15
- package/dist/cjs/utils/fifo.js +56 -56
- package/dist/cjs/utils/logging.d.ts +23 -23
- package/dist/cjs/utils/logging.js +48 -48
- package/dist/cjs/utils/pio-assembler.d.ts +45 -45
- package/dist/cjs/utils/pio-assembler.js +87 -87
- package/dist/cjs/utils/time.d.ts +2 -2
- package/dist/cjs/utils/time.js +32 -32
- package/dist/cjs/utils/timer32.d.ts +57 -57
- package/dist/cjs/utils/timer32.js +208 -208
- package/dist/esm/clock/clock.d.ts +11 -11
- package/dist/esm/clock/clock.js +1 -1
- package/dist/esm/clock/mock-clock.d.ts +17 -17
- package/dist/esm/clock/mock-clock.js +47 -47
- package/dist/esm/clock/realtime-clock.d.ts +23 -23
- package/dist/esm/clock/realtime-clock.js +68 -68
- package/dist/esm/cortex-m0-core.d.ts +87 -87
- package/dist/esm/cortex-m0-core.js +1247 -1247
- package/dist/esm/gdb/gdb-connection.d.ts +11 -11
- package/dist/esm/gdb/gdb-connection.js +53 -53
- package/dist/esm/gdb/gdb-server.d.ts +23 -23
- package/dist/esm/gdb/gdb-server.js +228 -228
- package/dist/esm/gdb/gdb-tcp-server.d.ts +10 -10
- package/dist/esm/gdb/gdb-tcp-server.js +30 -30
- package/dist/esm/gdb/gdb-utils.d.ts +9 -9
- package/dist/esm/gdb/gdb-utils.js +36 -36
- package/dist/esm/gpio-pin.d.ts +56 -56
- package/dist/esm/gpio-pin.js +212 -212
- package/dist/esm/index.d.ts +11 -11
- package/dist/esm/index.js +11 -11
- package/dist/esm/interpolator.d.ts +36 -36
- package/dist/esm/interpolator.js +145 -145
- package/dist/esm/irq.d.ts +29 -29
- package/dist/esm/irq.js +30 -30
- package/dist/esm/peripherals/adc.d.ts +52 -52
- package/dist/esm/peripherals/adc.js +257 -257
- package/dist/esm/peripherals/busctrl.d.ts +10 -10
- package/dist/esm/peripherals/busctrl.js +80 -80
- package/dist/esm/peripherals/clocks.d.ts +9 -9
- package/dist/esm/peripherals/clocks.js +38 -38
- package/dist/esm/peripherals/dma.d.ts +109 -109
- package/dist/esm/peripherals/dma.js +515 -515
- package/dist/esm/peripherals/i2c.d.ts +54 -54
- package/dist/esm/peripherals/i2c.js +454 -454
- package/dist/esm/peripherals/io.d.ts +11 -11
- package/dist/esm/peripherals/io.js +96 -96
- package/dist/esm/peripherals/pads.d.ts +13 -13
- package/dist/esm/peripherals/pads.js +54 -54
- package/dist/esm/peripherals/peripheral.d.ts +22 -22
- package/dist/esm/peripherals/peripheral.js +55 -55
- package/dist/esm/peripherals/pio.d.ts +120 -120
- package/dist/esm/peripherals/pio.js +1081 -1081
- package/dist/esm/peripherals/ppb.d.ts +25 -25
- package/dist/esm/peripherals/ppb.js +225 -225
- package/dist/esm/peripherals/pwm.d.ts +65 -65
- package/dist/esm/peripherals/pwm.js +368 -368
- package/dist/esm/peripherals/reset.d.ts +8 -8
- package/dist/esm/peripherals/reset.js +36 -36
- package/dist/esm/peripherals/rtc.d.ts +10 -10
- package/dist/esm/peripherals/rtc.js +70 -70
- package/dist/esm/peripherals/spi.d.ts +38 -38
- package/dist/esm/peripherals/spi.js +236 -236
- package/dist/esm/peripherals/ssi.d.ts +6 -6
- package/dist/esm/peripherals/ssi.js +39 -39
- package/dist/esm/peripherals/syscfg.d.ts +5 -5
- package/dist/esm/peripherals/syscfg.js +22 -22
- package/dist/esm/peripherals/sysinfo.d.ts +4 -4
- package/dist/esm/peripherals/sysinfo.js +18 -18
- package/dist/esm/peripherals/tbman.d.ts +4 -4
- package/dist/esm/peripherals/tbman.js +13 -13
- package/dist/esm/peripherals/timer.d.ts +18 -18
- package/dist/esm/peripherals/timer.js +152 -152
- package/dist/esm/peripherals/uart.d.ts +31 -31
- package/dist/esm/peripherals/uart.js +128 -128
- package/dist/esm/peripherals/usb.d.ts +29 -29
- package/dist/esm/peripherals/usb.js +305 -305
- package/dist/esm/rp2040.d.ts +71 -71
- package/dist/esm/rp2040.js +357 -357
- package/dist/esm/sio.d.ts +21 -21
- package/dist/esm/sio.js +421 -421
- package/dist/esm/usb/cdc.d.ts +20 -20
- package/dist/esm/usb/cdc.js +121 -121
- package/dist/esm/usb/interfaces.d.ts +47 -47
- package/dist/esm/usb/interfaces.js +43 -43
- package/dist/esm/usb/setup.d.ts +5 -5
- package/dist/esm/usb/setup.js +46 -46
- package/dist/esm/utils/assembler.d.ts +79 -79
- package/dist/esm/utils/assembler.js +245 -245
- package/dist/esm/utils/bit.d.ts +3 -3
- package/dist/esm/utils/bit.js +9 -9
- package/dist/esm/utils/fifo.d.ts +15 -15
- package/dist/esm/utils/fifo.js +52 -52
- package/dist/esm/utils/logging.d.ts +23 -23
- package/dist/esm/utils/logging.js +44 -44
- package/dist/esm/utils/pio-assembler.d.ts +45 -45
- package/dist/esm/utils/pio-assembler.js +75 -75
- package/dist/esm/utils/time.d.ts +2 -2
- package/dist/esm/utils/time.js +27 -27
- package/dist/esm/utils/timer32.d.ts +57 -57
- package/dist/esm/utils/timer32.js +203 -203
- package/package.json +38 -27
- package/dist/esm/package.json +0 -1
package/dist/cjs/utils/time.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatTime = exports.getCurrentMicroseconds = void 0;
|
|
4
|
-
function getCurrentMicroseconds() {
|
|
5
|
-
if (typeof performance != 'undefined') {
|
|
6
|
-
return Math.floor(performance.now() * 1000);
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
return Math.floor(eval('require')('perf_hooks').performance.now() * 1000);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.getCurrentMicroseconds = getCurrentMicroseconds;
|
|
13
|
-
function leftPad(value, minLength, padChar = ' ') {
|
|
14
|
-
if (value.length < minLength) {
|
|
15
|
-
value = padChar + value;
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
function rightPad(value, minLength, padChar = ' ') {
|
|
20
|
-
if (value.length < minLength) {
|
|
21
|
-
value += padChar;
|
|
22
|
-
}
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
function formatTime(date) {
|
|
26
|
-
const hours = leftPad(date.getHours().toString(), 2, '0');
|
|
27
|
-
const minutes = leftPad(date.getMinutes().toString(), 2, '0');
|
|
28
|
-
const seconds = leftPad(date.getSeconds().toString(), 2, '0');
|
|
29
|
-
const milliseconds = rightPad(date.getMilliseconds().toString(), 3);
|
|
30
|
-
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
31
|
-
}
|
|
32
|
-
exports.formatTime = formatTime;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTime = exports.getCurrentMicroseconds = void 0;
|
|
4
|
+
function getCurrentMicroseconds() {
|
|
5
|
+
if (typeof performance != 'undefined') {
|
|
6
|
+
return Math.floor(performance.now() * 1000);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return Math.floor(eval('require')('perf_hooks').performance.now() * 1000);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.getCurrentMicroseconds = getCurrentMicroseconds;
|
|
13
|
+
function leftPad(value, minLength, padChar = ' ') {
|
|
14
|
+
if (value.length < minLength) {
|
|
15
|
+
value = padChar + value;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function rightPad(value, minLength, padChar = ' ') {
|
|
20
|
+
if (value.length < minLength) {
|
|
21
|
+
value += padChar;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function formatTime(date) {
|
|
26
|
+
const hours = leftPad(date.getHours().toString(), 2, '0');
|
|
27
|
+
const minutes = leftPad(date.getMinutes().toString(), 2, '0');
|
|
28
|
+
const seconds = leftPad(date.getSeconds().toString(), 2, '0');
|
|
29
|
+
const milliseconds = rightPad(date.getMilliseconds().toString(), 3);
|
|
30
|
+
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
31
|
+
}
|
|
32
|
+
exports.formatTime = formatTime;
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { IClock } from '../clock/clock';
|
|
2
|
-
export declare enum TimerMode {
|
|
3
|
-
Increment = 0,
|
|
4
|
-
Decrement = 1,
|
|
5
|
-
ZigZag = 2
|
|
6
|
-
}
|
|
7
|
-
export declare class Timer32 {
|
|
8
|
-
readonly clock: IClock;
|
|
9
|
-
private baseFreq;
|
|
10
|
-
private baseValue;
|
|
11
|
-
private baseMicros;
|
|
12
|
-
private topValue;
|
|
13
|
-
private prescalerValue;
|
|
14
|
-
private timerMode;
|
|
15
|
-
private enabled;
|
|
16
|
-
readonly listeners: (() => void)[];
|
|
17
|
-
constructor(clock: IClock, baseFreq: number);
|
|
18
|
-
reset(): void;
|
|
19
|
-
set(value: number, zigZagDown?: boolean): void;
|
|
20
|
-
/**
|
|
21
|
-
* Advances the counter by the given amount. Note that this will
|
|
22
|
-
* decrease the counter if the timer is running in Decrement mode.
|
|
23
|
-
*
|
|
24
|
-
* @param delta The value to add to the counter. Can be negative.
|
|
25
|
-
*/
|
|
26
|
-
advance(delta: number): void;
|
|
27
|
-
get rawCounter(): number;
|
|
28
|
-
get counter(): number;
|
|
29
|
-
get top(): number;
|
|
30
|
-
set top(value: number);
|
|
31
|
-
get frequency(): number;
|
|
32
|
-
set frequency(value: number);
|
|
33
|
-
get prescaler(): number;
|
|
34
|
-
set prescaler(value: number);
|
|
35
|
-
toMicros(cycles: number): number;
|
|
36
|
-
get enable(): boolean;
|
|
37
|
-
set enable(value: boolean);
|
|
38
|
-
get mode(): TimerMode;
|
|
39
|
-
set mode(value: TimerMode);
|
|
40
|
-
private updated;
|
|
41
|
-
}
|
|
42
|
-
export declare class Timer32PeriodicAlarm {
|
|
43
|
-
readonly timer: Timer32;
|
|
44
|
-
readonly callback: () => void;
|
|
45
|
-
private targetValue;
|
|
46
|
-
private enabled;
|
|
47
|
-
private clockTimer?;
|
|
48
|
-
constructor(timer: Timer32, callback: () => void);
|
|
49
|
-
get enable(): boolean;
|
|
50
|
-
set enable(value: boolean);
|
|
51
|
-
get target(): number;
|
|
52
|
-
set target(value: number);
|
|
53
|
-
handleAlarm: () => void;
|
|
54
|
-
update: () => void;
|
|
55
|
-
private schedule;
|
|
56
|
-
private cancel;
|
|
57
|
-
}
|
|
1
|
+
import { IClock } from '../clock/clock.js';
|
|
2
|
+
export declare enum TimerMode {
|
|
3
|
+
Increment = 0,
|
|
4
|
+
Decrement = 1,
|
|
5
|
+
ZigZag = 2
|
|
6
|
+
}
|
|
7
|
+
export declare class Timer32 {
|
|
8
|
+
readonly clock: IClock;
|
|
9
|
+
private baseFreq;
|
|
10
|
+
private baseValue;
|
|
11
|
+
private baseMicros;
|
|
12
|
+
private topValue;
|
|
13
|
+
private prescalerValue;
|
|
14
|
+
private timerMode;
|
|
15
|
+
private enabled;
|
|
16
|
+
readonly listeners: (() => void)[];
|
|
17
|
+
constructor(clock: IClock, baseFreq: number);
|
|
18
|
+
reset(): void;
|
|
19
|
+
set(value: number, zigZagDown?: boolean): void;
|
|
20
|
+
/**
|
|
21
|
+
* Advances the counter by the given amount. Note that this will
|
|
22
|
+
* decrease the counter if the timer is running in Decrement mode.
|
|
23
|
+
*
|
|
24
|
+
* @param delta The value to add to the counter. Can be negative.
|
|
25
|
+
*/
|
|
26
|
+
advance(delta: number): void;
|
|
27
|
+
get rawCounter(): number;
|
|
28
|
+
get counter(): number;
|
|
29
|
+
get top(): number;
|
|
30
|
+
set top(value: number);
|
|
31
|
+
get frequency(): number;
|
|
32
|
+
set frequency(value: number);
|
|
33
|
+
get prescaler(): number;
|
|
34
|
+
set prescaler(value: number);
|
|
35
|
+
toMicros(cycles: number): number;
|
|
36
|
+
get enable(): boolean;
|
|
37
|
+
set enable(value: boolean);
|
|
38
|
+
get mode(): TimerMode;
|
|
39
|
+
set mode(value: TimerMode);
|
|
40
|
+
private updated;
|
|
41
|
+
}
|
|
42
|
+
export declare class Timer32PeriodicAlarm {
|
|
43
|
+
readonly timer: Timer32;
|
|
44
|
+
readonly callback: () => void;
|
|
45
|
+
private targetValue;
|
|
46
|
+
private enabled;
|
|
47
|
+
private clockTimer?;
|
|
48
|
+
constructor(timer: Timer32, callback: () => void);
|
|
49
|
+
get enable(): boolean;
|
|
50
|
+
set enable(value: boolean);
|
|
51
|
+
get target(): number;
|
|
52
|
+
set target(value: number);
|
|
53
|
+
handleAlarm: () => void;
|
|
54
|
+
update: () => void;
|
|
55
|
+
private schedule;
|
|
56
|
+
private cancel;
|
|
57
|
+
}
|
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Timer32PeriodicAlarm = exports.Timer32 = exports.TimerMode = void 0;
|
|
4
|
-
var TimerMode;
|
|
5
|
-
(function (TimerMode) {
|
|
6
|
-
TimerMode[TimerMode["Increment"] = 0] = "Increment";
|
|
7
|
-
TimerMode[TimerMode["Decrement"] = 1] = "Decrement";
|
|
8
|
-
TimerMode[TimerMode["ZigZag"] = 2] = "ZigZag";
|
|
9
|
-
})(TimerMode
|
|
10
|
-
class Timer32 {
|
|
11
|
-
constructor(clock, baseFreq) {
|
|
12
|
-
this.clock = clock;
|
|
13
|
-
this.baseFreq = baseFreq;
|
|
14
|
-
this.baseValue = 0;
|
|
15
|
-
this.baseMicros = 0;
|
|
16
|
-
this.topValue = 0xffffffff;
|
|
17
|
-
this.prescalerValue = 1;
|
|
18
|
-
this.timerMode = TimerMode.Increment;
|
|
19
|
-
this.enabled = true;
|
|
20
|
-
this.listeners = [];
|
|
21
|
-
}
|
|
22
|
-
reset() {
|
|
23
|
-
this.baseMicros = this.clock.micros;
|
|
24
|
-
this.baseValue = 0;
|
|
25
|
-
this.updated();
|
|
26
|
-
}
|
|
27
|
-
set(value, zigZagDown = false) {
|
|
28
|
-
this.baseValue = zigZagDown ? this.topValue * 2 - value : value;
|
|
29
|
-
this.baseMicros = this.clock.micros;
|
|
30
|
-
this.updated();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Advances the counter by the given amount. Note that this will
|
|
34
|
-
* decrease the counter if the timer is running in Decrement mode.
|
|
35
|
-
*
|
|
36
|
-
* @param delta The value to add to the counter. Can be negative.
|
|
37
|
-
*/
|
|
38
|
-
advance(delta) {
|
|
39
|
-
this.baseValue += delta;
|
|
40
|
-
}
|
|
41
|
-
get rawCounter() {
|
|
42
|
-
const { baseFreq, prescalerValue, baseMicros, baseValue, enabled, timerMode } = this;
|
|
43
|
-
if (!baseFreq || !prescalerValue || !enabled) {
|
|
44
|
-
return this.baseValue;
|
|
45
|
-
}
|
|
46
|
-
const zigzag = timerMode == TimerMode.ZigZag;
|
|
47
|
-
const ticks = ((this.clock.micros - baseMicros) / 1e6) * (baseFreq / prescalerValue);
|
|
48
|
-
const topModulo = zigzag ? this.topValue * 2 : this.topValue + 1;
|
|
49
|
-
const delta = timerMode == TimerMode.Decrement ? topModulo - (ticks % topModulo) : ticks;
|
|
50
|
-
let currentValue = Math.round(baseValue + delta);
|
|
51
|
-
if (this.topValue != 0xffffffff) {
|
|
52
|
-
currentValue %= topModulo;
|
|
53
|
-
}
|
|
54
|
-
return currentValue;
|
|
55
|
-
}
|
|
56
|
-
get counter() {
|
|
57
|
-
let currentValue = this.rawCounter;
|
|
58
|
-
if (this.timerMode == TimerMode.ZigZag && currentValue > this.topValue) {
|
|
59
|
-
currentValue = this.topValue * 2 - currentValue;
|
|
60
|
-
}
|
|
61
|
-
return currentValue >>> 0;
|
|
62
|
-
}
|
|
63
|
-
get top() {
|
|
64
|
-
return this.topValue;
|
|
65
|
-
}
|
|
66
|
-
set top(value) {
|
|
67
|
-
const { counter } = this;
|
|
68
|
-
this.topValue = value;
|
|
69
|
-
this.set(counter <= this.topValue ? counter : 0);
|
|
70
|
-
}
|
|
71
|
-
get frequency() {
|
|
72
|
-
return this.baseFreq;
|
|
73
|
-
}
|
|
74
|
-
set frequency(value) {
|
|
75
|
-
this.baseValue = this.counter;
|
|
76
|
-
this.baseMicros = this.clock.micros;
|
|
77
|
-
this.baseFreq = value;
|
|
78
|
-
this.updated();
|
|
79
|
-
}
|
|
80
|
-
get prescaler() {
|
|
81
|
-
return this.prescalerValue;
|
|
82
|
-
}
|
|
83
|
-
set prescaler(value) {
|
|
84
|
-
this.baseValue = this.counter;
|
|
85
|
-
this.baseMicros = this.clock.micros;
|
|
86
|
-
this.enabled = this.prescalerValue !== 0;
|
|
87
|
-
this.prescalerValue = value;
|
|
88
|
-
this.updated();
|
|
89
|
-
}
|
|
90
|
-
toMicros(cycles) {
|
|
91
|
-
const { baseFreq, prescalerValue } = this;
|
|
92
|
-
return (cycles * 1e6) / (baseFreq / prescalerValue);
|
|
93
|
-
}
|
|
94
|
-
get enable() {
|
|
95
|
-
return this.enabled;
|
|
96
|
-
}
|
|
97
|
-
set enable(value) {
|
|
98
|
-
if (value !== this.enabled) {
|
|
99
|
-
if (value) {
|
|
100
|
-
this.baseMicros = this.clock.micros;
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
this.baseValue = this.counter;
|
|
104
|
-
}
|
|
105
|
-
this.enabled = value;
|
|
106
|
-
this.updated();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
get mode() {
|
|
110
|
-
return this.timerMode;
|
|
111
|
-
}
|
|
112
|
-
set mode(value) {
|
|
113
|
-
if (this.timerMode !== value) {
|
|
114
|
-
const { counter } = this;
|
|
115
|
-
this.timerMode = value;
|
|
116
|
-
this.set(counter);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
updated() {
|
|
120
|
-
for (const listener of this.listeners) {
|
|
121
|
-
listener();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
exports.Timer32 = Timer32;
|
|
126
|
-
class Timer32PeriodicAlarm {
|
|
127
|
-
constructor(timer, callback) {
|
|
128
|
-
this.timer = timer;
|
|
129
|
-
this.callback = callback;
|
|
130
|
-
this.targetValue = 0;
|
|
131
|
-
this.enabled = false;
|
|
132
|
-
this.handleAlarm = () => {
|
|
133
|
-
this.callback();
|
|
134
|
-
if (this.enabled && this.timer.enable) {
|
|
135
|
-
this.schedule();
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
this.update = () => {
|
|
139
|
-
this.cancel();
|
|
140
|
-
if (this.enabled && this.timer.enable) {
|
|
141
|
-
this.schedule();
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
timer.listeners.push(this.update);
|
|
145
|
-
}
|
|
146
|
-
get enable() {
|
|
147
|
-
return this.enabled;
|
|
148
|
-
}
|
|
149
|
-
set enable(value) {
|
|
150
|
-
if (value !== this.enabled) {
|
|
151
|
-
this.enabled = value;
|
|
152
|
-
if (value && this.timer.enable) {
|
|
153
|
-
this.schedule();
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
this.cancel();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
get target() {
|
|
161
|
-
return this.targetValue;
|
|
162
|
-
}
|
|
163
|
-
set target(value) {
|
|
164
|
-
if (value === this.targetValue) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
this.targetValue = value;
|
|
168
|
-
if (this.enabled && this.timer.enable) {
|
|
169
|
-
this.cancel();
|
|
170
|
-
this.schedule();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
schedule() {
|
|
174
|
-
const { timer, targetValue } = this;
|
|
175
|
-
const { top, mode, rawCounter } = timer;
|
|
176
|
-
let cycleDelta = targetValue - rawCounter;
|
|
177
|
-
if (mode === TimerMode.ZigZag && cycleDelta < 0) {
|
|
178
|
-
if (cycleDelta < -top) {
|
|
179
|
-
cycleDelta += 2 * top;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
cycleDelta = top * 2 - targetValue - rawCounter;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (top != 0xffffffff) {
|
|
186
|
-
if (cycleDelta < 0) {
|
|
187
|
-
cycleDelta += top + 1;
|
|
188
|
-
}
|
|
189
|
-
if (targetValue > top) {
|
|
190
|
-
// Skip alarm
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (mode === TimerMode.Decrement) {
|
|
195
|
-
cycleDelta = top + 1 - cycleDelta;
|
|
196
|
-
}
|
|
197
|
-
const cyclesToAlarm = cycleDelta >>> 0;
|
|
198
|
-
const microsToAlarm = timer.toMicros(cyclesToAlarm);
|
|
199
|
-
this.clockTimer = this.timer.clock.createTimer(microsToAlarm, this.handleAlarm);
|
|
200
|
-
}
|
|
201
|
-
cancel() {
|
|
202
|
-
if (this.clockTimer) {
|
|
203
|
-
this.timer.clock.deleteTimer(this.clockTimer);
|
|
204
|
-
this.clockTimer = undefined;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
exports.Timer32PeriodicAlarm = Timer32PeriodicAlarm;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Timer32PeriodicAlarm = exports.Timer32 = exports.TimerMode = void 0;
|
|
4
|
+
var TimerMode;
|
|
5
|
+
(function (TimerMode) {
|
|
6
|
+
TimerMode[TimerMode["Increment"] = 0] = "Increment";
|
|
7
|
+
TimerMode[TimerMode["Decrement"] = 1] = "Decrement";
|
|
8
|
+
TimerMode[TimerMode["ZigZag"] = 2] = "ZigZag";
|
|
9
|
+
})(TimerMode || (exports.TimerMode = TimerMode = {}));
|
|
10
|
+
class Timer32 {
|
|
11
|
+
constructor(clock, baseFreq) {
|
|
12
|
+
this.clock = clock;
|
|
13
|
+
this.baseFreq = baseFreq;
|
|
14
|
+
this.baseValue = 0;
|
|
15
|
+
this.baseMicros = 0;
|
|
16
|
+
this.topValue = 0xffffffff;
|
|
17
|
+
this.prescalerValue = 1;
|
|
18
|
+
this.timerMode = TimerMode.Increment;
|
|
19
|
+
this.enabled = true;
|
|
20
|
+
this.listeners = [];
|
|
21
|
+
}
|
|
22
|
+
reset() {
|
|
23
|
+
this.baseMicros = this.clock.micros;
|
|
24
|
+
this.baseValue = 0;
|
|
25
|
+
this.updated();
|
|
26
|
+
}
|
|
27
|
+
set(value, zigZagDown = false) {
|
|
28
|
+
this.baseValue = zigZagDown ? this.topValue * 2 - value : value;
|
|
29
|
+
this.baseMicros = this.clock.micros;
|
|
30
|
+
this.updated();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Advances the counter by the given amount. Note that this will
|
|
34
|
+
* decrease the counter if the timer is running in Decrement mode.
|
|
35
|
+
*
|
|
36
|
+
* @param delta The value to add to the counter. Can be negative.
|
|
37
|
+
*/
|
|
38
|
+
advance(delta) {
|
|
39
|
+
this.baseValue += delta;
|
|
40
|
+
}
|
|
41
|
+
get rawCounter() {
|
|
42
|
+
const { baseFreq, prescalerValue, baseMicros, baseValue, enabled, timerMode } = this;
|
|
43
|
+
if (!baseFreq || !prescalerValue || !enabled) {
|
|
44
|
+
return this.baseValue;
|
|
45
|
+
}
|
|
46
|
+
const zigzag = timerMode == TimerMode.ZigZag;
|
|
47
|
+
const ticks = ((this.clock.micros - baseMicros) / 1e6) * (baseFreq / prescalerValue);
|
|
48
|
+
const topModulo = zigzag ? this.topValue * 2 : this.topValue + 1;
|
|
49
|
+
const delta = timerMode == TimerMode.Decrement ? topModulo - (ticks % topModulo) : ticks;
|
|
50
|
+
let currentValue = Math.round(baseValue + delta);
|
|
51
|
+
if (this.topValue != 0xffffffff) {
|
|
52
|
+
currentValue %= topModulo;
|
|
53
|
+
}
|
|
54
|
+
return currentValue;
|
|
55
|
+
}
|
|
56
|
+
get counter() {
|
|
57
|
+
let currentValue = this.rawCounter;
|
|
58
|
+
if (this.timerMode == TimerMode.ZigZag && currentValue > this.topValue) {
|
|
59
|
+
currentValue = this.topValue * 2 - currentValue;
|
|
60
|
+
}
|
|
61
|
+
return currentValue >>> 0;
|
|
62
|
+
}
|
|
63
|
+
get top() {
|
|
64
|
+
return this.topValue;
|
|
65
|
+
}
|
|
66
|
+
set top(value) {
|
|
67
|
+
const { counter } = this;
|
|
68
|
+
this.topValue = value;
|
|
69
|
+
this.set(counter <= this.topValue ? counter : 0);
|
|
70
|
+
}
|
|
71
|
+
get frequency() {
|
|
72
|
+
return this.baseFreq;
|
|
73
|
+
}
|
|
74
|
+
set frequency(value) {
|
|
75
|
+
this.baseValue = this.counter;
|
|
76
|
+
this.baseMicros = this.clock.micros;
|
|
77
|
+
this.baseFreq = value;
|
|
78
|
+
this.updated();
|
|
79
|
+
}
|
|
80
|
+
get prescaler() {
|
|
81
|
+
return this.prescalerValue;
|
|
82
|
+
}
|
|
83
|
+
set prescaler(value) {
|
|
84
|
+
this.baseValue = this.counter;
|
|
85
|
+
this.baseMicros = this.clock.micros;
|
|
86
|
+
this.enabled = this.prescalerValue !== 0;
|
|
87
|
+
this.prescalerValue = value;
|
|
88
|
+
this.updated();
|
|
89
|
+
}
|
|
90
|
+
toMicros(cycles) {
|
|
91
|
+
const { baseFreq, prescalerValue } = this;
|
|
92
|
+
return (cycles * 1e6) / (baseFreq / prescalerValue);
|
|
93
|
+
}
|
|
94
|
+
get enable() {
|
|
95
|
+
return this.enabled;
|
|
96
|
+
}
|
|
97
|
+
set enable(value) {
|
|
98
|
+
if (value !== this.enabled) {
|
|
99
|
+
if (value) {
|
|
100
|
+
this.baseMicros = this.clock.micros;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.baseValue = this.counter;
|
|
104
|
+
}
|
|
105
|
+
this.enabled = value;
|
|
106
|
+
this.updated();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
get mode() {
|
|
110
|
+
return this.timerMode;
|
|
111
|
+
}
|
|
112
|
+
set mode(value) {
|
|
113
|
+
if (this.timerMode !== value) {
|
|
114
|
+
const { counter } = this;
|
|
115
|
+
this.timerMode = value;
|
|
116
|
+
this.set(counter);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
updated() {
|
|
120
|
+
for (const listener of this.listeners) {
|
|
121
|
+
listener();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Timer32 = Timer32;
|
|
126
|
+
class Timer32PeriodicAlarm {
|
|
127
|
+
constructor(timer, callback) {
|
|
128
|
+
this.timer = timer;
|
|
129
|
+
this.callback = callback;
|
|
130
|
+
this.targetValue = 0;
|
|
131
|
+
this.enabled = false;
|
|
132
|
+
this.handleAlarm = () => {
|
|
133
|
+
this.callback();
|
|
134
|
+
if (this.enabled && this.timer.enable) {
|
|
135
|
+
this.schedule();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
this.update = () => {
|
|
139
|
+
this.cancel();
|
|
140
|
+
if (this.enabled && this.timer.enable) {
|
|
141
|
+
this.schedule();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
timer.listeners.push(this.update);
|
|
145
|
+
}
|
|
146
|
+
get enable() {
|
|
147
|
+
return this.enabled;
|
|
148
|
+
}
|
|
149
|
+
set enable(value) {
|
|
150
|
+
if (value !== this.enabled) {
|
|
151
|
+
this.enabled = value;
|
|
152
|
+
if (value && this.timer.enable) {
|
|
153
|
+
this.schedule();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.cancel();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
get target() {
|
|
161
|
+
return this.targetValue;
|
|
162
|
+
}
|
|
163
|
+
set target(value) {
|
|
164
|
+
if (value === this.targetValue) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.targetValue = value;
|
|
168
|
+
if (this.enabled && this.timer.enable) {
|
|
169
|
+
this.cancel();
|
|
170
|
+
this.schedule();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
schedule() {
|
|
174
|
+
const { timer, targetValue } = this;
|
|
175
|
+
const { top, mode, rawCounter } = timer;
|
|
176
|
+
let cycleDelta = targetValue - rawCounter;
|
|
177
|
+
if (mode === TimerMode.ZigZag && cycleDelta < 0) {
|
|
178
|
+
if (cycleDelta < -top) {
|
|
179
|
+
cycleDelta += 2 * top;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
cycleDelta = top * 2 - targetValue - rawCounter;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (top != 0xffffffff) {
|
|
186
|
+
if (cycleDelta < 0) {
|
|
187
|
+
cycleDelta += top + 1;
|
|
188
|
+
}
|
|
189
|
+
if (targetValue > top) {
|
|
190
|
+
// Skip alarm
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (mode === TimerMode.Decrement) {
|
|
195
|
+
cycleDelta = top + 1 - cycleDelta;
|
|
196
|
+
}
|
|
197
|
+
const cyclesToAlarm = cycleDelta >>> 0;
|
|
198
|
+
const microsToAlarm = timer.toMicros(cyclesToAlarm);
|
|
199
|
+
this.clockTimer = this.timer.clock.createTimer(microsToAlarm, this.handleAlarm);
|
|
200
|
+
}
|
|
201
|
+
cancel() {
|
|
202
|
+
if (this.clockTimer) {
|
|
203
|
+
this.timer.clock.deleteTimer(this.clockTimer);
|
|
204
|
+
this.clockTimer = undefined;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.Timer32PeriodicAlarm = Timer32PeriodicAlarm;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface IClockTimer {
|
|
2
|
-
pause(currentMicros: number): void;
|
|
3
|
-
resume(currentMicros: number): void;
|
|
4
|
-
}
|
|
5
|
-
export interface IClock {
|
|
6
|
-
readonly micros: number;
|
|
7
|
-
pause(): void;
|
|
8
|
-
resume(): void;
|
|
9
|
-
createTimer(deltaMicros: number, callback: () => void): IClockTimer;
|
|
10
|
-
deleteTimer(timer: IClockTimer): void;
|
|
11
|
-
}
|
|
1
|
+
export interface IClockTimer {
|
|
2
|
+
pause(currentMicros: number): void;
|
|
3
|
+
resume(currentMicros: number): void;
|
|
4
|
+
}
|
|
5
|
+
export interface IClock {
|
|
6
|
+
readonly micros: number;
|
|
7
|
+
pause(): void;
|
|
8
|
+
resume(): void;
|
|
9
|
+
createTimer(deltaMicros: number, callback: () => void): IClockTimer;
|
|
10
|
+
deleteTimer(timer: IClockTimer): void;
|
|
11
|
+
}
|
package/dist/esm/clock/clock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { IClock, IClockTimer } from './clock';
|
|
2
|
-
export declare class MockClockTimer implements IClockTimer {
|
|
3
|
-
readonly micros: number;
|
|
4
|
-
readonly callback: () => void;
|
|
5
|
-
constructor(micros: number, callback: () => void);
|
|
6
|
-
pause(): void;
|
|
7
|
-
resume(): void;
|
|
8
|
-
}
|
|
9
|
-
export declare class MockClock implements IClock {
|
|
10
|
-
micros: number;
|
|
11
|
-
readonly timers: MockClockTimer[];
|
|
12
|
-
pause(): void;
|
|
13
|
-
resume(): void;
|
|
14
|
-
advance(deltaMicros: number): void;
|
|
15
|
-
createTimer(deltaMicros: number, callback: () => void): MockClockTimer;
|
|
16
|
-
deleteTimer(timer: IClockTimer): void;
|
|
17
|
-
}
|
|
1
|
+
import { IClock, IClockTimer } from './clock.js';
|
|
2
|
+
export declare class MockClockTimer implements IClockTimer {
|
|
3
|
+
readonly micros: number;
|
|
4
|
+
readonly callback: () => void;
|
|
5
|
+
constructor(micros: number, callback: () => void);
|
|
6
|
+
pause(): void;
|
|
7
|
+
resume(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class MockClock implements IClock {
|
|
10
|
+
micros: number;
|
|
11
|
+
readonly timers: MockClockTimer[];
|
|
12
|
+
pause(): void;
|
|
13
|
+
resume(): void;
|
|
14
|
+
advance(deltaMicros: number): void;
|
|
15
|
+
createTimer(deltaMicros: number, callback: () => void): MockClockTimer;
|
|
16
|
+
deleteTimer(timer: IClockTimer): void;
|
|
17
|
+
}
|