XT keyboard reader for embedded systems --------------------------------------- XT reference: http://www.cs.cmu.edu/afs/cs/usr/jmcm/www/info/key2.txt Reading an XT keyboard requires two input pins, a clock pin and a data pin. The clock pin should be bound to an external interrupt, triggered on the falling edge of the clock pulse. The idle state for the clock is high, and the idle state for the data pin is low. During the clock interrupt, the program should read the data pin and push the bit read into the XT context using the xt_read function. When a full byte has been read from the data pin the clock pin should be held low to pause the keyboard until the program has has handled the scancode. The main program loop should call xt_handle function to process scancodes, passing a callback function that will handle keyboard events when they occur. When the function returns a nonzero value, the clock pin should be release to allow data input from the keyboard again. See the header file for a complete list of key constants. Example abstract program: #include xt_ctx_t *ctx; void xt_event_handler() { if (event->phase XT_KEY_PRESS && event->modifiers & (XT_SHIFT | XT_CONTROL) && event->symbol == XT_A) { do_something(); } } void xt_clock_interrupt() { int bit = read_data_pin(); if (xt_read(ctx, bit)) { hold_clock_pin_low(); if (xt_handle(ctx, xt_event_handler)) release_clock_pin(); } } int main(void) { setup_interrupt_handler_for_xt_clock_interrupt(); ctx = xt_init_ctx(); while (1) { rest_of_the_program(); } }