From 8ed06f78e44e7faab1d460223770c5b4ec6fdbf0 Mon Sep 17 00:00:00 2001 From: Daniele Verducci su MatissePenguin Date: Fri, 12 Feb 2021 12:19:19 +0100 Subject: [PATCH] ps/2 debugger --- .../composite-pal-adapter-test.ino | 41 +++++++++++++++++++ .../ps2-keyb-controller-test.ino | 35 ++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 prototiping-with-arduino/composite-pal-adapter-test/composite-pal-adapter-test.ino create mode 100644 prototiping-with-arduino/ps2-keyb-controller-test/ps2-keyb-controller-test.ino diff --git a/prototiping-with-arduino/composite-pal-adapter-test/composite-pal-adapter-test.ino b/prototiping-with-arduino/composite-pal-adapter-test/composite-pal-adapter-test.ino new file mode 100644 index 0000000..2a26e3a --- /dev/null +++ b/prototiping-with-arduino/composite-pal-adapter-test/composite-pal-adapter-test.ino @@ -0,0 +1,41 @@ +/** + * Composite pal adapter test. + * This sketch makes an Arduino send test data to tha Pat80 composite video pal adapter. + * Connect the video adapter directly to Arduino + */ + +const byte CLK = 11; // output active low +const byte RS = 12; // output low = DATA register, high = COMMAND register +const byte BUSY = 13; // Input, Active low +// DATA BUS (Output, active high): 3, 4, 5, 6, 7, 8, 9, 10; + +void setup() { + DDRD = DDRD | B11111000; // Port D (arduino pins 3 to 7) is output. In or to preserve serial pins and interrupt pin + DDRB = B00000111; // Port B (0,1,2) = pins 8,9,10 output + pinMode(CLK, OUTPUT); + pinMode(RS, OUTPUT); + pinMode(BUSY, INPUT); + + digitalWrite(CLK, HIGH); // Inactive clock +} + +void loop() { + delay(1000); + send(); +} + +void send() { + // Random char + char c = random(32, 126); + // Wait for BUSY to become inactive (HIGH) + //while(digitalRead(BUSY) == LOW) {} + + // Split byte to two parts and write to ports + PORTD = c << 3; + PORTB = c >> 5; + + // Clock pulse + digitalWrite(CLK, LOW); + delay(100); + digitalWrite(CLK, HIGH); +} diff --git a/prototiping-with-arduino/ps2-keyb-controller-test/ps2-keyb-controller-test.ino b/prototiping-with-arduino/ps2-keyb-controller-test/ps2-keyb-controller-test.ino new file mode 100644 index 0000000..bc4754f --- /dev/null +++ b/prototiping-with-arduino/ps2-keyb-controller-test/ps2-keyb-controller-test.ino @@ -0,0 +1,35 @@ +/* PS/2 Keyboard controller debugger */ + +#define EN 2 +const byte DATA_BUS[] = {10, 9, 8, 7, 6, 5, 4, 3}; + +void setup() { + pinMode(EN, INPUT); + for(int pin=0; pin < 8; pin++) { + pinMode(DATA_BUS[pin], INPUT); + } + + Serial.begin(57600); + Serial.println("PS/2 keyboard controller debugger"); + Serial.println("DATA BUS HEX EN"); + + attachInterrupt(digitalPinToInterrupt(EN), onClk, FALLING); +} + +void loop() {} + +void onClk() { + unsigned int data = 0; + for(int pin=0; pin < 8; pin++) { + byte b = digitalRead(DATA_BUS[pin]) ? 1 : 0; + Serial.print(b); + data = (data << 1) + b; // Shifta di 1 e aggiunge il bit corrente. Serve per ricostruire il numero da binario + } + + char output[50] = {}; + sprintf(output, " 0x%02x %c", + data, + digitalRead(EN) ? 'D' : 'I' + ); + Serial.println(output); +}