From afb08462085132acf7a1962522952f7dbf064519 Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 8 Jun 2012 00:37:46 +0900 Subject: Made directories for keyboard and converter projects. --- converter/adb_usb/matrix.c | 241 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 converter/adb_usb/matrix.c (limited to 'converter/adb_usb/matrix.c') diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c new file mode 100644 index 000000000..a2367af56 --- /dev/null +++ b/converter/adb_usb/matrix.c @@ -0,0 +1,241 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "util.h" +#include "debug.h" +#include "host.h" +#include "led.h" +#include "adb.h" +#include "matrix.h" + + +#if (MATRIX_COLS > 16) +# error "MATRIX_COLS must not exceed 16" +#endif +#if (MATRIX_ROWS > 255) +# error "MATRIX_ROWS must not exceed 255" +#endif + +#define CAPS 0x39 +#define CAPS_UP (CAPS | 0x80) +#define ROW(key) ((key)>>3&0x0F) +#define COL(key) ((key)&0x07) + + +static bool _matrix_is_modified = false; + +// matrix state buffer(1:on, 0:off) +#if (MATRIX_COLS <= 8) +static uint8_t *matrix; +static uint8_t _matrix0[MATRIX_ROWS]; +#else +static uint16_t *matrix; +static uint16_t _matrix0[MATRIX_ROWS]; +#endif + +#ifdef MATRIX_HAS_GHOST +static bool matrix_has_ghost_in_row(uint8_t row); +#endif +static void _register_key(uint8_t key); + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + adb_host_init(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; + matrix = _matrix0; + + print_enable = true; + debug_enable = true; + debug_matrix = true; + debug_keyboard = true; + debug_mouse = true; + print("debug enabled.\n"); + return; +} + +uint8_t matrix_scan(void) +{ + uint16_t codes; + uint8_t key0, key1; + + _matrix_is_modified = false; + codes = adb_host_kbd_recv(); + key0 = codes>>8; + key1 = codes&0xFF; + +#ifdef MATRIX_HAS_LOCKING_CAPS + // Send Caps key up event + if (matrix_is_on(ROW(CAPS), COL(CAPS))) { + _matrix_is_modified = true; + _register_key(CAPS_UP); + } +#endif + if (codes == 0) { // no keys + return 0; + } else if (key0 == 0xFF && key1 != 0xFF) { // error + return codes&0xFF; + } else { +#ifdef MATRIX_HAS_LOCKING_CAPS + if (host_keyboard_leds() & (1<>3)&0x0F; + if (key&0x80) { + matrix[row] &= ~(1<