示例#1
0
文件: kbd.c 项目: gluke77/meto-avr
void do_kbd(void)
{
	static uint8_t kbd_timeout = KBD_TIMEOUT;
	
	if (!kbd_timeout--)
	{
		kbd_timeout = KBD_TIMEOUT;
		kbd_scan();
	}
}
示例#2
0
static void
kbd_server(cyg_addrword_t p)
{
    int col, bit, key, event, timeout;
    diag_printf("KBD server here\n");
    while (TRUE) {
        cyg_semaphore_wait(&kbd_sem);
        // As long as keys are pressed, scan and update
        timeout = 0;
        while (TRUE) {
            // Wait for 20ms - time to debounce keyboard
            cyg_thread_delay(2);
            // Scan keyboard
            kbd_scan();
            // Reset state
            for (key = 0;  key < sizeof(kbd_new_state);  key++) {
                kbd_new_state[key] = 0;
            }
            // Check state of all keys and send events for those that change
            for (col = 0;  col < 8;  col++) {
                for (bit = 0;  bit < 8;  bit++) {
                    if (col_state[col] & (1<<bit)) {
                        key = kbd_map[col][bit];
                        if (key != KBD_Empty) {
                            kbd_new_state[key] = 1;
                        }
                    }
                    if (ext_state[col] & (1<<bit)) {
                        key = kbd_map[col][bit+8];
                        if (key != KBD_Empty) {
                            kbd_new_state[key] = 1;
                        }
                    }
                }
            }
            // Compare new and old (known) states, generate events for changes
            // Send events for modifier keys first.
            for (key = 0;  key < sizeof(kbd_new_state);  key++) {
                if (kbd_state[key] != kbd_new_state[key]) {
                    event = 0xFF;
                    switch (key) {
                    case KBD_LeftShift:
                    case KBD_RightShift:
                    case KBD_Ctrl:
                    case KBD_LeftAlt:
                    case KBD_RightAlt:
                    case KBD_Function:
                    case KBD_CapsLock:
                        if (kbd_state[key]) {
                            // Key going up
                            event = key;
                        } else {
                            // Key going down
                            event = key + KBD_Press;
                        }
                        kbd_state[key] = kbd_new_state[key];
                    }
                    if (event != 0xFF) {
                        if (!cyg_mbox_tryput(kbd_events_mbox_handle, (void *)event)) {
                            diag_printf("KBD event lost: %x\n", event);
                        }
                    }
                }
            }
            // First key up events
            for (key = 0;  key < sizeof(kbd_new_state);  key++) {
                if (kbd_state[key] != kbd_new_state[key]) {
                    if (kbd_state[key]) {
                        // Key going up
                        event = key;
                    } else {
                        // Key going down
                        event = key + KBD_Press;
                    }
                    if (!cyg_mbox_tryput(kbd_events_mbox_handle, (void *)event)) {
                        diag_printf("KBD event lost: %x\n", event);
                    }
                }
                kbd_state[key] = kbd_new_state[key];
            }
            // Clear interrupt (true when keys are pressed)
            cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_KBDINT);
#if 0
            if (*(volatile cyg_uint32 *)INTSR2 & INTSR2_KBDINT) {
                timeout = 0;
            } else if (++timeout == 5) {
                // No keys for 100ms
                break;
            }
#endif
        }
        // Allow interrupts to happen again
        cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_KBDINT);
        cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_KBDINT);
    }
}
示例#3
0
int kbd_test_scan(unsigned short ass) {
		kbd_scan(ass);
	//else kbd_scan_ass;
}