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