aboutsummaryrefslogtreecommitdiff
path: root/src/gpio.spec.ts
diff options
context:
space:
mode:
authorUri Shaked2020-01-11 02:58:50 +0200
committerUri Shaked2020-01-11 02:58:50 +0200
commitdd18276e5ddc17fe6156e46428e34652537ba2c4 (patch)
treea1c0cdefc018da75af62293bb2413d1b07415201 /src/gpio.spec.ts
parentchore: release 0.5.1 (diff)
downloadavr8js-dd18276e5ddc17fe6156e46428e34652537ba2c4.tar.gz
avr8js-dd18276e5ddc17fe6156e46428e34652537ba2c4.tar.bz2
avr8js-dd18276e5ddc17fe6156e46428e34652537ba2c4.zip
fix(gpio): pinState() value incorrect in GPIO listeners
fix #9
Diffstat (limited to '')
-rw-r--r--src/gpio.spec.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gpio.spec.ts b/src/gpio.spec.ts
index e0ab7a1..2fa866d 100644
--- a/src/gpio.spec.ts
+++ b/src/gpio.spec.ts
@@ -68,5 +68,19 @@ describe('GPIO', () => {
cpu.writeData(0x25, 0x2); // PORTB <- 0x2
expect(port.pinState(1)).toEqual(PinState.InputPullUp);
});
+
+ it('should reflect the current port state when called inside a listener', () => {
+ // Related issue: https://github.com/wokwi/avr8js/issues/9
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ const listener = jest.fn(() => {
+ expect(port.pinState(0)).toBe(PinState.High);
+ });
+ port.addListener(listener);
+ expect(port.pinState(0)).toBe(PinState.Input);
+ cpu.writeData(0x24, 0x01); // DDRB <- 0x01
+ cpu.writeData(0x25, 0x01); // PORTB <- 0x01
+ expect(listener).toHaveBeenCalled();
+ });
});
});