]> git.gir.st - tmk_keyboard.git/blame_incremental - converter/x68k_usb/matrix.c
Fix matrix.c to use new default impl.
[tmk_keyboard.git] / converter / x68k_usb / matrix.c
... / ...
CommitLineData
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <stdbool.h>
20#include <avr/io.h>
21#include <util/delay.h>
22#include "print.h"
23#include "util.h"
24#include "serial.h"
25#include "matrix.h"
26#include "debug.h"
27
28
29/*
30 * Matrix Array usage:
31 *
32 * ROW: 16(4bits)
33 * COL: 8(3bits)
34 *
35 * 8bit wide
36 * +---------+
37 * 0|00 ... 07|
38 * 1|08 ... 0F|
39 * :| ... |
40 * :| ... |
41 * E|70 ... 77|
42 * F|78 ... 7F|
43 * +---------+
44 *
45 */
46static uint8_t matrix[MATRIX_ROWS];
47#define ROW(code) ((code>>3)&0xF)
48#define COL(code) (code&0x07)
49
50static bool is_modified = false;
51
52
53void matrix_init(void)
54{
55 serial_init();
56
57 // initialize matrix state: all keys off
58 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
59
60 return;
61}
62
63uint8_t matrix_scan(void)
64{
65 is_modified = false;
66
67 uint16_t code;
68 code = serial_recv2();
69 if (code == -1) {
70 return 0;
71 }
72
73 dprintf("%02X\n", code);
74 if (code&0x80) {
75 // break code
76 if (matrix_is_on(ROW(code), COL(code))) {
77 matrix[ROW(code)] &= ~(1<<COL(code));
78 is_modified = true;
79 }
80 } else {
81 // make code
82 if (!matrix_is_on(ROW(code), COL(code))) {
83 matrix[ROW(code)] |= (1<<COL(code));
84 is_modified = true;
85 }
86 }
87 return code;
88}
89
90inline
91uint8_t matrix_get_row(uint8_t row)
92{
93 return matrix[row];
94}
Imprint / Impressum