From 253905cbf952978df10d6e60dc599176ed593977 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Tue, 17 May 2022 12:37:27 +0300 Subject: feat(usi): ATtiny85 USI implementation --- src/peripherals/gpio.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/peripherals/gpio.ts') diff --git a/src/peripherals/gpio.ts b/src/peripherals/gpio.ts index 07667d9..9d84307 100644 --- a/src/peripherals/gpio.ts +++ b/src/peripherals/gpio.ts @@ -210,6 +210,7 @@ export class AVRIOPort { private lastValue: u8 = 0; private lastDdr: u8 = 0; private lastPin: u8 = 0; + openCollector: u8 = 0; constructor(private cpu: CPU, readonly portConfig: Readonly) { cpu.gpioPorts.add(this); @@ -317,10 +318,12 @@ export class AVRIOPort { const ddr = this.cpu.data[this.portConfig.DDR]; const port = this.cpu.data[this.portConfig.PORT]; const bitMask = 1 << index; + const openState = port & bitMask ? PinState.InputPullUp : PinState.Input; + const highValue = this.openCollector & bitMask ? openState : PinState.High; if (ddr & bitMask) { - return this.lastValue & bitMask ? PinState.High : PinState.Low; + return this.lastValue & bitMask ? highValue : PinState.Low; } else { - return port & bitMask ? PinState.InputPullUp : PinState.Input; + return openState; } } -- cgit v1.2.3