diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-22 23:32:24 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-22 23:32:24 +0200 |
| commit | 50f8b0c3f3a4309091f0c576dc8e35060a43b8c3 (patch) | |
| tree | 685662080560a6cc2ef6d0845fcd462e6113b772 | |
| parent | 3c33d36759a316b8c118b77b3eed040425db8e0a (diff) | |
added numeric input and capsed alpha to kb driver
| -rw-r--r-- | kernel/kernel.c | 4 | ||||
| -rw-r--r-- | kernel/keyboard.c | 98 |
2 files changed, 90 insertions, 12 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c index 701d33f..23246e1 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -100,6 +100,7 @@ void kernel_main(uint32_t initial_stack, int mp) log_log(); + // // Print initial address of the esp stack pointer // @@ -116,8 +117,9 @@ void kernel_main(uint32_t initial_stack, int mp) // timer_init(); - // mouse driver init (before interrupts) + // mouse and kb driver init (before interrupts) mouse_init(); + keyboard_init(); // // Setup Interrupts (code segment: 0x08) diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 083e553..746dc3a 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -5,14 +5,25 @@ #include "console.h" #include "../lib/logger/log.h" // logger facilities +#include "../lib/bool/bool.h" /// keyboard driver //// +// http://www.computer-engineering.org/ps2keyboard/scancodes1.html + +static bool shift_l; +static bool shift_r; +static bool capslock; + +void keyboard_init() +{ + shift_l=shift_r=capslock=false; //!! +} void keyboard_handle(uint8_t in) { - uint8_t make_codes[]={ + uint8_t make_alpha[]={ 0x1e, // A 0x30, // B 0x2e, // C @@ -70,36 +81,101 @@ void keyboard_handle(uint8_t in) 0xac, // Z }; + uint8_t break_num[]={ + + 0x8b, //0 + 0x82, + 0x83, + 0x84, + 0x85, + 0x86, + 0x87, + 0x88, + 0x89, + 0x8a, // 9 + + }; + + + + + uint8_t break_key_enter=0x9c; uint8_t break_key_space=0xb9; uint8_t break_key_backspace=0x8e; + uint8_t make_key_shift_l=0x2a; + uint8_t break_key_shift_l=0xaa; + + uint8_t make_key_shift_r=0x36; + uint8_t break_key_shift_r=0xb6; + + uint8_t break_caps_lock=0xba; + + if(make_key_shift_l==in)shift_l=true; + if(break_key_shift_l==in)shift_l=false;; + + if(make_key_shift_r==in)shift_r=true; + if(break_key_shift_r==in)shift_r=false;; + + if(break_caps_lock==in)capslock=!capslock; + + char ascii; + bool match=false; // optimize this! - if(break_key_space==in)ascii=' '; - else if(break_key_backspace==in)ascii='x'; - else if(break_key_enter==in)ascii='\n'; + if(break_key_space==in) + { + ascii=' '; + match=true; + } + + else if(break_key_backspace==in) + { + ascii='x'; + match=true; + } + + else if(break_key_enter==in) + { + ascii='\n'; + match=true; + } else for(int i=0;i<26;i++) { if(break_alpha[i]==in) { - ascii=('A'+i); + ascii=('a'+i); + + if(shift_l||shift_r||capslock) // capslock makes trouble :( + { + ascii=('A'+i); + } + match=true; break; } - if(i==25) + } + + for(int i=0;i<10;i++) + { + if(break_num[i]==in) { - return; + ascii=('0'+i); + match=true; + break; } } - PutConsoleChar(ascii,0b1111100000011111); - + if(match) + { + PutConsoleChar(ascii,0b1111100000011111); - if(!ringbuffer_put(ascii)) - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full.."); + if(!ringbuffer_put(ascii)) + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full.."); + } } |
