aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUri Shaked2020-10-07 12:42:23 +0300
committerUri Shaked2020-10-07 12:42:23 +0300
commitcb71d87c2831b842e72bb6152ac5d8144b9bbd03 (patch)
treea879f8b2b2e34045fefea64d695e322e2c9d9d43
parent0.11.3 (diff)
downloadavr8js-cb71d87c2831b842e72bb6152ac5d8144b9bbd03.tar.gz
avr8js-cb71d87c2831b842e72bb6152ac5d8144b9bbd03.tar.bz2
avr8js-cb71d87c2831b842e72bb6152ac5d8144b9bbd03.zip
fix(gpio): Changing pinMode from `INPUT` to `INPUT_PULLUP` doesn't trigger listeners
close #62
-rw-r--r--src/peripherals/gpio.spec.ts15
-rw-r--r--src/peripherals/gpio.ts2
2 files changed, 13 insertions, 4 deletions
diff --git a/src/peripherals/gpio.spec.ts b/src/peripherals/gpio.spec.ts
index 44232f4..820aa52 100644
--- a/src/peripherals/gpio.spec.ts
+++ b/src/peripherals/gpio.spec.ts
@@ -9,7 +9,7 @@ describe('GPIO', () => {
cpu.writeData(0x24, 0x0f); // DDRB <- 0x0f
port.addListener(listener);
cpu.writeData(0x25, 0x55); // PORTB <- 0x55
- expect(listener).toHaveBeenCalledWith(0x05, 0);
+ expect(listener).toHaveBeenCalledWith(0x55, 0);
expect(cpu.data[0x23]).toEqual(0x5); // PINB should return port value
});
@@ -20,7 +20,16 @@ describe('GPIO', () => {
cpu.writeData(0x25, 0x55); // PORTB <- 0x55
port.addListener(listener);
cpu.writeData(0x24, 0xf0); // DDRB <- 0xf0
- expect(listener).toHaveBeenCalledWith(0x50, 0);
+ expect(listener).toHaveBeenCalledWith(0x55, 0x55);
+ });
+
+ it('should invoke the listeners when pullup register enabled (issue #62)', () => {
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ const listener = jest.fn();
+ port.addListener(listener);
+ cpu.writeData(0x25, 0x55); // PORTB <- 0x55
+ expect(listener).toHaveBeenCalledWith(0x55, 0);
});
it('should toggle the pin when writing to the PIN register', () => {
@@ -31,7 +40,7 @@ describe('GPIO', () => {
cpu.writeData(0x24, 0x0f); // DDRB <- 0x0f
cpu.writeData(0x25, 0x55); // PORTB <- 0x55
cpu.writeData(0x23, 0x01); // PINB <- 0x0f
- expect(listener).toHaveBeenCalledWith(0x04, 0x5);
+ expect(listener).toHaveBeenCalledWith(0x54, 0x55);
expect(cpu.data[0x23]).toEqual(0x4); // PINB should return port value
});
diff --git a/src/peripherals/gpio.ts b/src/peripherals/gpio.ts
index e0861d7..4130c82 100644
--- a/src/peripherals/gpio.ts
+++ b/src/peripherals/gpio.ts
@@ -204,7 +204,7 @@ export class AVRIOPort {
}
private writeGpio(value: u8, ddr: u8) {
- const newValue = ((value & this.overrideMask) | this.overrideValue) & ddr;
+ const newValue = (((value & this.overrideMask) | this.overrideValue) & ddr) | (value & ~ddr);
const prevValue = this.lastValue;
if (newValue !== prevValue || ddr !== this.lastDdr) {
this.lastValue = newValue;
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.