Added KeyMap

This commit is contained in:
Graeme Harker 2022-01-23 19:03:56 +00:00
parent bbb796662d
commit b942e4b29b
3 changed files with 50 additions and 48 deletions

View File

@ -2,5 +2,5 @@
"board": "arduino:avr:uno",
"programmer": "arduino:avrispmkii",
"sketch": "SmartyKit 1 basic drivers/SmartyKit1_KeyboardDriverBasic/SmartyKit1_KeyboardDriverBasic.ino",
"port": "/dev/cu.usbmodem2101"
"port": "/dev/cu.usbserial-FTBXSR3D"
}

View File

@ -19,6 +19,7 @@
"/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino",
"/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard",
"/Users/gharker/Documents/Arduino/libraries/PS2KeyAdvanced/src",
"/Users/gharker/Documents/Arduino/libraries/PS2KeyMap/src",
"/Applications/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/7.3.0/include",
"/Applications/Arduino.app/Contents/Java/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed",
"/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include"

View File

@ -16,6 +16,7 @@
*/
#include <PS2KeyAdvanced.h>
#include <PS2KeyMap.h>
// Keyboard Driver pins connections:
// D0 & D1 reserved for Serial connection
@ -33,18 +34,19 @@
#define KEYBOARD_BIT7_PIN 5
const int KeyboardPort[8] = {6, 7, 8, 9, 10, 11, 12, 13};
static boolean BIT7flag = false;
static boolean autoMode = false; //run pre-set command or wait for user input from PS/2 keyboard
static boolean autoCommandSent = false; // run pre-set command only once after reboot of Keyboard controller
//low-rate clock for tests on A4-A5
#define LORATE_CLOCK_PIN A4
#define LORATE_CLOCK_LED_PIN A5
#define LORATE_CLOCK_PIN A4
#define LORATE_CLOCK_LED_PIN A5
//10 milliseconds = 100 times per second (100 Hz)
#define LORATE_CLOCK_PERIOD_MILLIS 100
PS2KeyAdvanced keyboard;
PS2KeyMap keymap;
void setup()
{
@ -57,7 +59,7 @@ void setup()
pinMode(KeyboardPort[bit], OUTPUT);
}
pinMode(KEYBOARD_BIT7_PIN, OUTPUT);
ClearKeyboardBIT7();
digitalWrite(KEYBOARD_BIT7_PIN, LOW);
Serial.begin(9600);
Serial.println("SmartyKit 1 PS2 Keyboard is ready...");
@ -70,7 +72,7 @@ void setup()
keyboard.begin(PS2KEYBOARD_DATA_PIN, PS2KEYBOARDCLOCK_PIN);
keyboard.echo();
delay( 6 );
uint16_t scan_code = keyboard.read( );
uint16_t scan_code = keyboard.read();
if( (scan_code & 0xff) == PS2_KEY_ECHO || (scan_code & 0xff) == PS2_KEY_BAT || (scan_code & 0xff) == 0xe8 )
Serial.println( "Keyboard OK.." ); // Response was Echo or power up
@ -81,45 +83,37 @@ void setup()
}
else
{
Serial.print( "Invalid Code received of " );
Serial.print( "Invalid Code received of 0x" );
Serial.println(scan_code, HEX);
}
keyboard.setNoBreak(1);
keyboard.setNoRepeat(1);
keymap.selectMap((char *)"UK");
attachInterrupt(digitalPinToInterrupt(KEYBOARD_RD_PIN), cpuReadsKeyboard, FALLING);
}
void cpuReadsKeyboard(void)
{
ClearKeyboardBIT7();
}
void SetKeyboardBIT7()
{
digitalWrite(KEYBOARD_BIT7_PIN, HIGH);
BIT7flag = true;
}
void ClearKeyboardBIT7()
{
digitalWrite(KEYBOARD_BIT7_PIN, LOW);
BIT7flag = false;
}
void sendCharToKeyboardPort(char c)
{
Serial.print(c);
if (c == '\r')
Serial.println();
if (c == '\r')
Serial.println();
else
Serial.print(c);
for (int bit = 0; bit < 8 ; bit++)
{
if (c & (1 << (bit)))
digitalWrite(KeyboardPort[bit], HIGH);
else
digitalWrite(KeyboardPort[bit], LOW);
if (c & (1 << (bit)))
digitalWrite(KeyboardPort[bit], HIGH);
else
digitalWrite(KeyboardPort[bit], LOW);
}
digitalWrite(KeyboardPort[7], HIGH);
SetKeyboardBIT7();
digitalWrite(KEYBOARD_BIT7_PIN, HIGH);
}
void loop()
@ -133,32 +127,39 @@ void loop()
}
//check PS2 input
if (!BIT7flag && keyboard.available())
if (!digitalRead(KEYBOARD_BIT7_PIN) && keyboard.available())
{
uint16_t scan_code = keyboard.read();
if (!( scan_code & PS2_BREAK ))
uint16_t scan_code = keymap.remapKey(keyboard.read());
char c = scan_code & 0xff;
Serial.print(":0x");
Serial.print(scan_code, HEX);
Serial.print(":");
//process Backspace, Left Arrow, Delete as Apple I backspace '_'
switch (c)
{
char c = scan_code & 0xff;
if (c == PS2_KEY_TAB)
case PS2_KEY_TAB:
runCommand();
//process Backspace, Left Arrow, Delete as Apple I backspace '_'
if (c == PS2_KEY_BACK) {
break;
case PS2_KEY_BS:
case PS2_KEY_DELETE:
case PS2_KEY_L_ARROW:
c = '_';
} else if (c == PS2_KEY_L_ARROW) {
c = '_';
} else if (c == PS2_KEY_DELETE) {
c = '_';
}
//make all symbols uppercase (from 'a' (ASCII code 0x61) to 'z' (ASCII code 0x7A))
//as in original Apple-1
c = toupper(c);
//print c to Keyboard Port to be read by CPU
sendCharToKeyboardPort(c);
break;
case PS2_KEY_ENTER:
c = '\r';
break;
case PS2_KEY_SPACE:
c = ' ';
break;
}
//make all symbols uppercase (from 'a' (ASCII code 0x61) to 'z' (ASCII code 0x7A))
//as in original Apple-1
c = toupper(c);
//print c to Keyboard Port to be read by CPU
sendCharToKeyboardPort(c);
}
//low-rate clock