Use KBD interrupt to detect when computer has read character sent (Arduino doesn't support flow control in other direction)

This commit is contained in:
Unknown 2017-06-01 22:37:16 +02:00
parent 972f4c3b06
commit 7e9fb543ca

View File

@ -1,7 +1,9 @@
#include <SPI.h> #include <SPI.h>
#include <MCP23S17.h> #include <MCP23S17.h>
#define debug 0 #define DEBUG 0
#define KBD_INTERRUPT_ENABLE true
#define KBD_SEND_TIMEOUT 23
#define IO_SS 10 #define IO_SS 10
@ -62,7 +64,7 @@ void debug_value(String description, byte value) {
} }
void debug_value(String description, byte value, int level) { void debug_value(String description, byte value, int level) {
if (debug < level) return; if (DEBUG < level) return;
Serial.print(description); Serial.print(description);
Serial.print(": "); Serial.print(": ");
print_hex(value); print_hex(value);
@ -99,21 +101,31 @@ void pia_send(int c) {
/* Output the actual keys as long as it's supported */ /* Output the actual keys as long as it's supported */
if (c < 96) { if (c < 96) {
bridge.writePort(IO_KBD, c | 128); bridge.writePort(IO_KBD, c | 128);
digitalWrite(KBD_STROBE, HIGH); digitalWrite(KBD_STROBE, HIGH);
/* if (KBD_INTERRUPT_ENABLE) {
while(digitalRead(KBD_READY) != LOW) { byte timeout;
Serial.print("-");
delay(1); /* Wait for KBD_READY (CA2) to go HIGH */
timeout = KBD_SEND_TIMEOUT;
while(digitalRead(KBD_READY) != HIGH) {
delay(1);
if (timeout == 0) break;
else timeout--;
}
digitalWrite(KBD_STROBE, LOW);
/* Wait for KBD_READY (CA2) to go LOW */
timeout = KBD_SEND_TIMEOUT;
while(digitalRead(KBD_READY) != LOW) {
delay(1);
if (timeout == 0) break;
else timeout--;
}
} else {
delay(KBD_SEND_TIMEOUT);
digitalWrite(KBD_STROBE, LOW);
} }
*/
delay(23);
digitalWrite(KBD_STROBE, LOW);
/*
while(digitalRead(KBD_READY) == HIGH) {
Serial.print(".");
delay(1);
}
*/
} }
} }