A project to implement a console using the Mbed using VGA for video output and a PS/2 keyboard for the input. The eventual goal is to also include tools for managing SD cards, and a semi-self-hosting programming environment.

Dependencies:   PS2_MbedConsole fastlib SDFileSystem vga640x480g_mbedconsole lightvm mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers keyboard.h Source File

keyboard.h

00001 /*
00002 <Copyright Header>
00003 Copyright (c) 2012 Jordan "Earlz" Earls  <http://lastyearswishes.com>
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions
00008 are met:
00009 
00010 1. Redistributions of source code must retain the above copyright
00011    notice, this list of conditions and the following disclaimer.
00012 2. Redistributions in binary form must reproduce the above copyright
00013    notice, this list of conditions and the following disclaimer in the
00014    documentation and/or other materials provided with the distribution.
00015 3. The name of the author may not be used to endorse or promote products
00016    derived from this software without specific prior written permission.
00017    
00018 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
00019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00020 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
00021 THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00022 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00023 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00024 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00025 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00026 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00027 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 
00029 This file is part of the MbedConsole project
00030 */
00031 
00032 #ifndef KEYBOARD_H
00033 #define KEYBOARD_H
00034 
00035 #include "stdint.h"
00036 /**This is basically a straight rip off of my x86 OS project AlloyOS. I just ported the keyboard driver from it cause it always treated me well**/
00037 
00038 
00039 #define KEYBOARD_DATAPIN p21
00040 #define KEYBOARD_CLOCKPIN p22
00041 
00042 //how many keys the buffer can hold
00043 #define KBD_BUFFER_SIZE 128 
00044 
00045 //key defines
00046 #define LSHIFT_KEY 0x12
00047 #define RSHIFT_KEY 0x59
00048 
00049 #define CTRL_KEY 0xF3
00050 #define ALT_KEY 0xF4
00051 #define CAPS_KEY 0x58
00052 #define NUM_KEY 0x77
00053 #define SCROLL_KEY 0xF7
00054 //#define F_BASE_KEY 0xFF //59 is F1, 60 is F2, and so on until F10
00055 #define HOME_KEY 0xFF
00056 #define UP_KEY 0xFF
00057 #define PAGE_UP_KEY 0xFF
00058 #define LEFT_KEY 0xFF
00059 #define RIGHT_KEY 0xFF
00060 #define END_KEY 0xFF
00061 #define DOWN_KEY 0xFF
00062 #define PAGE_DOWN_KEY 0xFF
00063 #define INSERT_KEY 0xFF
00064 #define DEL_KEY 0xFF
00065 #define F11_KEY 0xFF
00066 #define F12_KEY 0xFF
00067 
00068 #define SCROLL_LED 1
00069 #define NUM_LED 2
00070 #define CAPS_LED 4
00071 
00072 
00073 extern const char kbdus[0x84];
00074 extern const char kbdus_caps[0x84];
00075 
00076 typedef struct {
00077     unsigned char caps;
00078     unsigned char shift;
00079     unsigned char scroll;
00080     unsigned char num;
00081     unsigned char ctrl;
00082     unsigned char alt;
00083 }
00084 shift_locks; /*for simplicity and speed*/
00085 
00086 extern volatile shift_locks kbd_shifts;
00087 
00088 typedef struct {
00089     uint16_t scancode;
00090     uint8_t asci;
00091 }kbd_key;
00092 
00093 void keyboard_callback(PS2KB kb, uint8_t val);
00094 void keyboard_init();
00095 
00096 int kbd_PutBuffer(uint16_t scan,uint8_t asci);
00097 
00098 kbd_key kbd_PopBuffer();
00099 uint8_t kbd_GetKey();
00100 void kbd_update_leds(uint8_t status);
00101 int kbd_DoShifts(uint8_t scan);
00102 int kbd_DoUnshifts(uint8_t scan);
00103 void keyboard_callback(PS2KB kb, uint8_t val);
00104 
00105 
00106 
00107 #endif