mirror of https://github.com/smartykit/apple1.git
Added KeyMap
This commit is contained in:
parent
bbb796662d
commit
b942e4b29b
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include <PS2KeyAdvanced.h>
|
||||
#include <PS2KeyMap.h>
|
||||
|
||||
// Keyboard Driver pins connections:
|
||||
// D0 & D1 – reserved for Serial connection
|
||||
|
@ -33,7 +34,7 @@
|
|||
#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
|
||||
|
||||
|
@ -45,6 +46,7 @@ static boolean autoCommandSent = false; // run pre-set command only once after r
|
|||
#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...");
|
||||
|
@ -81,35 +83,27 @@ 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();
|
||||
else
|
||||
Serial.print(c);
|
||||
|
||||
for (int bit = 0; bit < 8 ; bit++)
|
||||
{
|
||||
|
@ -119,7 +113,7 @@ void sendCharToKeyboardPort(char c)
|
|||
digitalWrite(KeyboardPort[bit], LOW);
|
||||
}
|
||||
digitalWrite(KeyboardPort[7], HIGH);
|
||||
SetKeyboardBIT7();
|
||||
digitalWrite(KEYBOARD_BIT7_PIN, HIGH);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -133,24 +127,32 @@ void loop()
|
|||
}
|
||||
|
||||
//check PS2 input
|
||||
if (!BIT7flag && keyboard.available())
|
||||
{
|
||||
uint16_t scan_code = keyboard.read();
|
||||
|
||||
if (!( scan_code & PS2_BREAK ))
|
||||
if (!digitalRead(KEYBOARD_BIT7_PIN) && keyboard.available())
|
||||
{
|
||||
uint16_t scan_code = keymap.remapKey(keyboard.read());
|
||||
char c = scan_code & 0xff;
|
||||
|
||||
if (c == PS2_KEY_TAB)
|
||||
runCommand();
|
||||
Serial.print(":0x");
|
||||
Serial.print(scan_code, HEX);
|
||||
Serial.print(":");
|
||||
|
||||
//process Backspace, Left Arrow, Delete as Apple I backspace '_'
|
||||
if (c == PS2_KEY_BACK) {
|
||||
c = '_';
|
||||
} else if (c == PS2_KEY_L_ARROW) {
|
||||
c = '_';
|
||||
} else if (c == PS2_KEY_DELETE) {
|
||||
switch (c)
|
||||
{
|
||||
case PS2_KEY_TAB:
|
||||
runCommand();
|
||||
break;
|
||||
case PS2_KEY_BS:
|
||||
case PS2_KEY_DELETE:
|
||||
case PS2_KEY_L_ARROW:
|
||||
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))
|
||||
|
@ -159,7 +161,6 @@ void loop()
|
|||
//print c to Keyboard Port to be read by CPU
|
||||
sendCharToKeyboardPort(c);
|
||||
}
|
||||
}
|
||||
|
||||
//low-rate clock
|
||||
digitalWrite(LORATE_CLOCK_PIN, HIGH);
|
||||
|
|
Loading…
Reference in New Issue