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/m0110_usb/matrix.c | 169 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 converter/m0110_usb/matrix.c (limited to 'converter/m0110_usb/matrix.c') diff --git a/converter/m0110_usb/matrix.c b/converter/m0110_usb/matrix.c new file mode 100644 index 000000000..1ca6894c4 --- /dev/null +++ b/converter/m0110_usb/matrix.c @@ -0,0 +1,169 @@ +/* +Copyright 2011,2012 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 "m0110.h" +#include "matrix.h" + + +#define CAPS 0x39 +#define CAPS_BREAK (CAPS | 0x80) +#define ROW(key) ((key)>>3&0x0F) +#define COL(key) ((key)&0x07) + + +static bool is_modified = false; + +// matrix state buffer(1:on, 0:off) +static uint8_t *matrix; +static uint8_t _matrix0[MATRIX_ROWS]; + +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) +{ + print_enable = true; + debug_enable = true; + debug_matrix = false; + debug_keyboard = false; + debug_mouse = false; + print("debug enabled.\n"); + + m0110_init(); + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; + matrix = _matrix0; + return; +} + +uint8_t matrix_scan(void) +{ + uint8_t key; + + is_modified = false; + key = m0110_recv_key(); + +#ifdef MATRIX_HAS_LOCKING_CAPS + // Send Caps key up event + if (matrix_is_on(ROW(CAPS), COL(CAPS))) { + is_modified = true; + register_key(CAPS_BREAK); + } +#endif + if (key == M0110_NULL) { + return 0; + } else if (key == M0110_ERROR) { + return 0; + } else { +#ifdef MATRIX_HAS_LOCKING_CAPS + if (host_keyboard_leds() & (1<