From 5bc85ec07ac00013de4681cb5d268e4567709be0 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Tue, 7 Sep 2021 00:42:42 +0300 Subject: fix(gpio): CBI/SBI handling in writes to PIN register #103 fix #103 --- src/peripherals/gpio.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/peripherals/gpio.ts') diff --git a/src/peripherals/gpio.ts b/src/peripherals/gpio.ts index 6d1dae8..07667d9 100644 --- a/src/peripherals/gpio.ts +++ b/src/peripherals/gpio.ts @@ -229,11 +229,11 @@ export class AVRIOPort { this.updatePinRegister(ddrMask); return true; }; - cpu.writeHooks[portConfig.PIN] = (value: u8) => { + cpu.writeHooks[portConfig.PIN] = (value: u8, oldValue, addr, mask) => { // Writing to 1 PIN toggles PORT bits const oldPortValue = cpu.data[portConfig.PORT]; const ddrMask = cpu.data[portConfig.DDR]; - const portValue = oldPortValue ^ value; + const portValue = oldPortValue ^ (value & mask); cpu.data[portConfig.PORT] = portValue; this.writeGpio(portValue, ddrMask); this.updatePinRegister(ddrMask); -- cgit v1.2.3