int kbdtest(void) { int i; printf("keyboard test\n"); printf("check keyboard..."); if(kbd_initialize()) { printf("failed\n"); } else { printf("ok\n"); printf("test kbd leds\n"); printf("num Lock off"); for(i=0;i<3;i++) { printf("\b\b\b on"); pckbd_leds(2); delay1(1000); pckbd_leds(0); printf("\b\b\boff"); delay1(1000); } printf("\ncaps Lock off"); for(i=0;i<3;i++) { printf("\b\b\b on"); pckbd_leds(4); delay1(1000); pckbd_leds(0); printf("\b\b\boff"); delay1(1000); } printf("\nscroll Lock off"); for(i=0;i<3;i++) { printf("\b\b\b on"); pckbd_leds(1); delay1(1000); pckbd_leds(0); printf("\b\b\boff"); delay1(1000); } printf("\n"); printf("press key test,wait 10s to quit\n"); while(1) { kbd_test=1; kbd_test_hit=0; delay1(10000); if(!kbd_test_hit){ kbd_test=0; break; } } } return 0; }
void handle_scancode(unsigned char scancode) { unsigned char keycode; /* Convert scancode to keycode */ PRINTF("scancode %x\n",scancode); if(scancode==0xe0) { e0=1; /* special charakters */ return; } if(e0==1) { e0=0; /* delete flag */ if(!( ((scancode&0x7F)==0x38)|| /* the right ctrl key */ ((scancode&0x7F)==0x1D)|| /* the right alt key */ ((scancode&0x7F)==0x35)|| /* the right '/' key */ ((scancode&0x7F)==0x1C) )) /* the right enter key */ /* we swallow unknown e0 codes */ return; } /* special cntrl keys */ switch(scancode) { case 0x2A: case 0x36: /* shift pressed */ shift=1; return; /* do nothing else */ case 0xAA: case 0xB6: /* shift released */ shift=0; return; /* do nothing else */ case 0x38: /* alt pressed */ alt=1; return; /* do nothing else */ case 0xB8: /* alt released */ alt=0; return; /* do nothing else */ case 0x1d: /* ctrl pressed */ ctrl=1; return; /* do nothing else */ case 0x9d: /* ctrl released */ ctrl=0; return; /* do nothing else */ case 0x46: /* scrollock pressed */ scroll_lock=~scroll_lock; if(scroll_lock==0) leds&=~LED_SCR; /* switch LED off */ else leds|=LED_SCR; /* switch on LED */ pckbd_leds(leds); return; /* do nothing else */ case 0x3A: /* capslock pressed */ caps_lock=~caps_lock; if(caps_lock==0) leds&=~LED_CAP; /* switch caps_lock off */ else leds|=LED_CAP; /* switch on LED */ pckbd_leds(leds); return; case 0x45: /* numlock pressed */ num_lock=~num_lock; if(num_lock==0) leds&=~LED_NUM; /* switch LED off */ else leds|=LED_NUM; /* switch on LED */ pckbd_leds(leds); return; case 0xC6: /* scroll lock released */ case 0xC5: /* num lock released */ case 0xBA: /* caps lock released */ return; /* just swallow */ } #if 1 if((scancode&0x80)==0x80) /* key released */ return; #else if((scancode&0x80)==0x00) /* key pressed */ return; scancode &= ~0x80; #endif /* now, decide which table we need */ if(scancode > (sizeof(kbd_plain_xlate)/sizeof(kbd_plain_xlate[0]))) { /* scancode not in list */ PRINTF("unkown scancode %X\n",scancode); return; /* swallow it */ } /* setup plain code first */ keycode=kbd_plain_xlate[scancode]; if(caps_lock==1) { /* caps_lock is pressed, overwrite plain code */ if(scancode > (sizeof(kbd_shift_xlate)/sizeof(kbd_shift_xlate[0]))) { /* scancode not in list */ PRINTF("unkown caps-locked scancode %X\n",scancode); return; /* swallow it */ } keycode=kbd_shift_xlate[scancode]; if(keycode<'A') { /* we only want the alphas capital */ keycode=kbd_plain_xlate[scancode]; } } if(shift==1) { /* shift overwrites caps_lock */ if(scancode > (sizeof(kbd_shift_xlate)/sizeof(kbd_shift_xlate[0]))) { /* scancode not in list */ PRINTF("unkown shifted scancode %X\n",scancode); return; /* swallow it */ } keycode=kbd_shift_xlate[scancode]; } if(ctrl==1) { /* ctrl overwrites caps_lock and shift */ if(scancode > (sizeof(kbd_ctrl_xlate)/sizeof(kbd_ctrl_xlate[0]))) { /* scancode not in list */ PRINTF("unkown ctrl scancode %X\n",scancode); return; /* swallow it */ } keycode=kbd_ctrl_xlate[scancode]; } /* check if valid keycode */ if(keycode==0xff) { PRINTF("unkown scancode %X\n",scancode); return; /* swallow unknown codes */ } kbd_put_queue(keycode); PRINTF("%x\n",keycode); }