aboutsummaryrefslogtreecommitdiff
path: root/src/twi.ts
diff options
context:
space:
mode:
authorUri Shaked2020-02-03 22:34:30 +0200
committerUri Shaked2020-02-03 22:34:30 +0200
commit13a112968c5527b10b974489d3a2ec19c98736d9 (patch)
tree1c0d9819541d4d3e43846c1971ce3418581e763e /src/twi.ts
parenttest(twi): add master TWI receive test #10 (diff)
downloadavr8js-13a112968c5527b10b974489d3a2ec19c98736d9.tar.gz
avr8js-13a112968c5527b10b974489d3a2ec19c98736d9.tar.bz2
avr8js-13a112968c5527b10b974489d3a2ec19c98736d9.zip
feat(twi): proper interrupt support #10
Diffstat (limited to 'src/twi.ts')
-rw-r--r--src/twi.ts14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/twi.ts b/src/twi.ts
index 027061f..fd0645b 100644
--- a/src/twi.ts
+++ b/src/twi.ts
@@ -1,6 +1,6 @@
-import { u8 } from './types';
import { CPU } from './cpu';
import { avrInterrupt } from './interrupt';
+import { u8 } from './types';
export interface TWIEventHandler {
start(repeated: boolean): void;
@@ -133,6 +133,13 @@ export class AVRTWI {
this.nextTick();
this.nextTick = null;
}
+ if (this.cpu.interruptsEnabled) {
+ const { TWCR, twiInterrupt } = this.config;
+ if (this.cpu.data[TWCR] & TWCR_TWIE && this.cpu.data[TWCR] & TWCR_TWINT) {
+ avrInterrupt(this.cpu, twiInterrupt);
+ this.cpu.data[TWCR] &= ~TWCR_TWINT;
+ }
+ }
}
get prescaler() {
@@ -186,11 +193,8 @@ export class AVRTWI {
}
private updateStatus(value: u8) {
- const { TWCR, TWSR, twiInterrupt } = this.config;
+ const { TWCR, TWSR } = this.config;
this.cpu.data[TWSR] = (this.cpu.data[TWSR] & ~TWSR_TWS_MASK) | value;
this.cpu.data[TWCR] |= TWCR_TWINT;
- if (this.cpu.interruptsEnabled && this.cpu.data[TWCR] & TWCR_TWIE) {
- avrInterrupt(this.cpu, twiInterrupt);
- }
}
}