void pc_keyboard_init(void) { u8 retries; u8 regval; enum cb_err err; if (!CONFIG_DRIVERS_PS2_KEYBOARD) return; if (acpi_is_wakeup_s3()) return; printk(BIOS_DEBUG, "Keyboard init...\n"); /* Run a keyboard controller self-test */ err = kbc_self_test(); /* Ignore iterface failure as it's non-fatal. */ if (err != CB_SUCCESS && err != CB_KBD_INTERFACE_FAILURE) return; /* Enable keyboard interface - No IRQ */ if (!kbc_input_buffer_empty()) return; outb(0x60, KBD_COMMAND); if (!kbc_input_buffer_empty()) return; outb(0x20, KBD_DATA); /* send cmd: enable keyboard */ if (!kbc_input_buffer_empty()) { printk(BIOS_INFO, "Timeout while enabling keyboard\n"); return; } /* clean up any junk that might have been in the keyboard */ if (!kbc_cleanup_buffers()) return; /* reset keyboard and self test (keyboard side) */ regval = send_keyboard(0xFF); if (regval == KBD_REPLY_RESEND) { /* keeps sending RESENDs, probably no keyboard. */ printk(BIOS_INFO, "No PS/2 keyboard detected.\n"); return; } if (regval != KBD_REPLY_ACK) { printk(BIOS_ERR, "Keyboard reset failed ACK: 0x%x\n", regval); return; } /* the reset command takes some time, so wait a little longer */ for (retries = 9; retries && !kbc_output_buffer_full(); retries--) ; if (!kbc_output_buffer_full()) { printk(BIOS_ERR, "Timeout waiting for keyboard after reset.\n"); return; } regval = inb(KBD_DATA); if (regval != 0xAA) { printk(BIOS_ERR, "Keyboard reset selftest failed: 0x%x\n", regval); return; } /* * The following set scancode stuff is what normal BIOS do. It could be * argued that coreboot shouldn't set the scan code..... */ /* disable the keyboard */ regval = send_keyboard(0xF5); if (regval != KBD_REPLY_ACK) { printk(BIOS_ERR, "Keyboard disable failed ACK: 0x%x\n", regval); return; } /* Set scancode command */ regval = send_keyboard(0xF0); if (regval != KBD_REPLY_ACK) { printk(BIOS_ERR, "Keyboard set scancode cmd failed ACK: 0x%x\n", regval); return; } /* Set scancode mode 2 */ regval = send_keyboard(0x02); if (regval != KBD_REPLY_ACK) { printk(BIOS_ERR, "Keyboard set scancode mode failed ACK: 0x%x\n", regval); return; } /* All is well - enable keyboard interface */ if (!kbc_input_buffer_empty()) return; outb(0x60, KBD_COMMAND); if (!kbc_input_buffer_empty()) return; outb(0x65, KBD_DATA); /* send cmd: enable keyboard and IRQ 1 */ if (!kbc_input_buffer_empty()) { printk(BIOS_ERR, "Timeout during keyboard enable\n"); return; } /* enable the keyboard */ regval = send_keyboard(0xF4); if (regval != KBD_REPLY_ACK) { printk(BIOS_ERR, "Keyboard enable failed ACK: 0x%x\n", regval); return; } }
void x_window_rep::key_event (string key) { send_keyboard (kbd_focus, key); }
static THD_FUNCTION(buttonThread, arg) { (void)arg; wkup_old_state = 0; while(1) { wkup_cur_state = palReadPad(BUTTON_GPIO, BUTTON_PIN); if(wkup_cur_state != wkup_old_state) { chSysLock(); if(usbGetDriverStateI(&USB_DRIVER) == USB_ACTIVE) { chSysUnlock(); /* just some test code for various reports * choose one and comment the others */ /* keyboard test, sends 'n' in nkro mode, 'm' in normal mode */ #ifdef NKRO_ENABLE if(wkup_cur_state == BUTTON_ACTIVE) { report.nkro.bits[2] |= 2; // 'n' } else { report.nkro.bits[2] &= 0b11111101; } #else report.keys[0] = ((wkup_cur_state == BUTTON_ACTIVE) ? 0x10 : 0); // 'm' #endif send_keyboard(&report); /* mouse test, moves the mouse pointer diagonally right and down */ // send_mouse(&mouse_report); /* consumer keys test, sends 'mute audio' */ // if(wkup_cur_state == BUTTON_ACTIVE) { // send_consumer(AUDIO_MUTE); // } else { // send_consumer(0); // } /* system keys test, sends 'sleep key' * on macs it takes a second or two for the system to react * I suppose it's to prevent from accidental hits of the sleep key */ // if(wkup_cur_state == BUTTON_ACTIVE) { // send_system(SYSTEM_SLEEP); // } else { // send_system(0); // } /* debug console test, sends the button state and the alphabet * - also blink, to see that the code above is not blocking */ // sendchar(((wkup_cur_state == BUTTON_ACTIVE) ? '1' : '0')); // uint8_t n; // for(n = 0; n < 26; n++) { // sendchar('A' + n); // sendchar('a' + n); // } // sendchar('\n'); // palSetPad(LED2_GPIO, LED2_PIN); // chThdSleepMilliseconds(50); // palClearPad(LED2_GPIO, LED2_PIN); } else chSysUnlock(); wkup_old_state = wkup_cur_state; } chThdSleepMilliseconds(50); } }