aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/gpio.ts
diff options
context:
space:
mode:
authorUri Shaked2022-05-17 12:37:27 +0300
committerUri Shaked2022-05-17 12:37:27 +0300
commit253905cbf952978df10d6e60dc599176ed593977 (patch)
treeff1aed37d7ad50067b88a21c60b351ed290ca15d /src/peripherals/gpio.ts
parent0.18.11 (diff)
downloadavr8js-253905cbf952978df10d6e60dc599176ed593977.tar.gz
avr8js-253905cbf952978df10d6e60dc599176ed593977.tar.bz2
avr8js-253905cbf952978df10d6e60dc599176ed593977.zip
feat(usi): ATtiny85 USI implementation
Diffstat (limited to '')
-rw-r--r--src/peripherals/gpio.ts7
1 files changed, 5 insertions, 2 deletions
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<AVRPortConfig>) {
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;
}
}