]> git.gir.st - tmk_keyboard.git/blob - converter/m0110_usb/matrix.c
adb_usb/matrix.c : changed size of handler_id from uint16_t to uint8_t
[tmk_keyboard.git] / converter / m0110_usb / matrix.c
1 /*
2 Copyright 2011,2012 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * scan matrix
20 */
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <avr/io.h>
24 #include <util/delay.h>
25 #include "print.h"
26 #include "util.h"
27 #include "debug.h"
28 #include "host.h"
29 #include "led.h"
30 #include "m0110.h"
31 #include "matrix.h"
32
33
34 #define CAPS 0x39
35 #define CAPS_BREAK (CAPS | 0x80)
36 #define ROW(key) ((key)>>3&0x0F)
37 #define COL(key) ((key)&0x07)
38
39
40 static bool is_modified = false;
41
42 // matrix state buffer(1:on, 0:off)
43 static uint8_t *matrix;
44 static uint8_t _matrix0[MATRIX_ROWS];
45
46 static void register_key(uint8_t key);
47
48
49 void matrix_init(void)
50 {
51 m0110_init();
52 // initialize matrix state: all keys off
53 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
54 matrix = _matrix0;
55
56 // LED flash
57 DDRD |= (1<<6); PORTD |= (1<<6);
58 _delay_ms(500);
59 DDRD |= (1<<6); PORTD &= ~(1<<6);
60
61 return;
62 }
63
64 uint8_t matrix_scan(void)
65 {
66 uint8_t key;
67
68 is_modified = false;
69 key = m0110_recv_key();
70
71 if (key == M0110_NULL) {
72 return 0;
73 } else if (key == M0110_ERROR) {
74 return 0;
75 } else {
76 is_modified = true;
77 register_key(key);
78 }
79
80 if (debug_enable) {
81 print("["); phex(key); print("]\n");
82 }
83 return 1;
84 }
85
86 inline
87 uint8_t matrix_get_row(uint8_t row)
88 {
89 return matrix[row];
90 }
91
92 inline
93 static void register_key(uint8_t key)
94 {
95 if (key&0x80) {
96 matrix[ROW(key)] &= ~(1<<COL(key));
97 } else {
98 matrix[ROW(key)] |= (1<<COL(key));
99 }
100 }
Imprint / Impressum