/* * Send two-byte command to the device on a primary port. */ int i8042_kbd_command (int cmd, int param) { int count; unsigned char ack; /* Send command and wait for an ack response. */ /*debug_printf ("keyboard: command %02x-%02x\n", cmd, param);*/ i8042_kbd_write (cmd); if (! i8042_read (&ack) || ack != KBDR_ACK) { /*debug_printf ("keyboard: no ACK after command\n");*/ return 0; } /* Send a parameter and wait for an ack response. */ i8042_kbd_write (param); for (count=0; count<100; ++count) { if (! i8042_read (&ack)) continue; if (ack == KBDR_ACK) { return 1; } /*debug_printf ("keyboard: %02x (%d)\n", ack, count);*/ } /*debug_printf ("keyboard: no ACK\n", cmd, param);*/ return 0; }
/* * Look to see if we can find a device on the aux port. */ int i8042_aux_probe () { int count; unsigned char ack; /* Send a reset and wait for an ack response. */ i8042_aux_write (KBDK_RESET); if (! i8042_read (&ack) || ack != KBDR_ACK) { /*debug_printf ("mouse: probe: no ACK after reset\n");*/ return 0; } /* Ensure that we see a basic assurance test response. */ for (count=0; count<1000; ++count) { if (! i8042_read (&ack)) continue; /*debug_printf ("mouse: probe: %02x (%d)\n", ack, count);*/ if (ack == KBDR_TEST_OK) { /* Check that we get a pointing device ID back */ if (! i8042_read (&ack) || ack != 0) { /*debug_printf ("mouse: probe: no ACK after BAT\n");*/ return 0; } return 1; } } /*debug_printf ("mouse: probe: no BAT after reset\n");*/ return 0; }
/** Handle data requests. * * @param fun ddf_fun_t function. * @param id callid * @param call IPC request. * */ void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call) { const sysarg_t method = IPC_GET_IMETHOD(*call); const size_t size = IPC_GET_ARG1(*call); switch (method) { case IPC_CHAR_READ: if (size <= 4 * sizeof(sysarg_t)) { sysarg_t message[4] = {}; i8042_read(fun, (char *) message, size); async_answer_4(id, size, message[0], message[1], message[2], message[3]); } else async_answer_0(id, ELIMIT); break; case IPC_CHAR_WRITE: if (size <= 3 * sizeof(sysarg_t)) { const sysarg_t message[3] = { IPC_GET_ARG2(*call), IPC_GET_ARG3(*call), IPC_GET_ARG4(*call) }; i8042_write(fun, (char *) message, size); async_answer_0(id, size); } else async_answer_0(id, ELIMIT); default: async_answer_0(id, EINVAL); } }
/* init keyboard 'module' */ static int i8042_init (uint flags, void *kernel_callback_function, device_t *d) { buf_first = buf_last = buf_size = 0; spec_keys_down = (int32) 0; keyb_flags = flags; /* empty hardware buffer */ while ( i8042_read () > 0 ) ; kernel_interrupt_callback_function = kernel_callback_function; return 0; }
/*! Keyboard interrupt handler - read new keystrokes and process them */ static void i8042_interrupt_handler ( int irq_num, void *device ) { int32 c; int new_keystrokes = FALSE; while ( ( c = i8042_read () ) >= 0 ) { new_keystrokes |= i8042_insert_keystroke ( c ); if ( ASCII_KEY ( c ) && ( keyb_flags & ECHO_ON ) ) kprint ( "%c", ASCII_KEY ( c ) ); } /* halt on Ctrl+p */ //if ( ASCII_KEY(c) == 'p' && (spec_keys_down & LCTRL) ) // halt (); if ( new_keystrokes && kernel_interrupt_callback_function ) kernel_interrupt_callback_function (); }