Skip to content

Commit 7f0a89c

Browse files
committed
feat(usart): add immediate parameter to writeByte()
The value will be available immediately to the user program instead of waiting one symbol time before making it available.
1 parent ba80f53 commit 7f0a89c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/peripherals/usart.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,23 @@ export class AVRUSART {
193193
return this.rxBusyValue;
194194
}
195195

196-
writeByte(value: number) {
197-
const { cpu, config } = this;
198-
if (this.rxBusyValue || !(cpu.data[config.UCSRB] & UCSRB_RXEN)) {
196+
writeByte(value: number, immediate = false) {
197+
const { cpu } = this;
198+
if (this.rxBusyValue || !this.rxEnable) {
199199
return false;
200200
}
201-
this.rxBusyValue = true;
202-
cpu.addClockEvent(() => {
201+
if (immediate) {
203202
this.rxByte = value;
204-
this.rxBusyValue = false;
205203
cpu.setInterruptFlag(this.RXC);
206204
this.onRxComplete?.();
207-
}, this.cyclesPerChar);
208-
return true;
205+
} else {
206+
this.rxBusyValue = true;
207+
cpu.addClockEvent(() => {
208+
this.rxBusyValue = false;
209+
this.writeByte(value, true);
210+
}, this.cyclesPerChar);
211+
return true;
212+
}
209213
}
210214

211215
private get cyclesPerChar() {

0 commit comments

Comments
 (0)