aboutsummaryrefslogtreecommitdiff
path: root/keyboards/converter/m0110_usb/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/converter/m0110_usb/matrix.c')
-rw-r--r--keyboards/converter/m0110_usb/matrix.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/keyboards/converter/m0110_usb/matrix.c b/keyboards/converter/m0110_usb/matrix.c
new file mode 100644
index 000000000..daba7a138
--- /dev/null
+++ b/keyboards/converter/m0110_usb/matrix.c
@@ -0,0 +1,121 @@
1/*
2Copyright 2011,2012 Jun Wako <[email protected]>
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
19Ported to QMK by Techsock <[email protected]>
20*/
21
22#include <stdint.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 "m0110.h"
30#include "matrix.h"
31#include "report.h"
32#include "timer.h"
33
34
35#define CAPS 0x39
36#define CAPS_BREAK (CAPS | 0x80)
37#define ROW(key) ((key)>>3&0x0F)
38#define COL(key) ((key)&0x07)
39
40
41static bool is_modified = false;
42
43// matrix state buffer(1:on, 0:off)
44static uint8_t *matrix;
45static uint8_t _matrix0[MATRIX_ROWS];
46
47static void register_key(uint8_t key);
48
49
50__attribute__ ((weak))
51void matrix_init_kb(void) {
52 matrix_init_user();
53}
54
55__attribute__ ((weak))
56void matrix_scan_kb(void) {
57 matrix_scan_user();
58}
59
60__attribute__ ((weak))
61void matrix_init_user(void) {
62}
63
64__attribute__ ((weak))
65void matrix_scan_user(void) {
66}
67
68void matrix_init(void)
69{
70 m0110_init();
71 // initialize matrix state: all keys off
72 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
73 matrix = _matrix0;
74
75 matrix_init_quantum();
76 return;
77}
78
79uint8_t matrix_scan(void)
80{
81 uint8_t key;
82
83 is_modified = false;
84 key = m0110_recv_key();
85
86 if (key == M0110_NULL) {
87 return 0;
88 } else if (key == M0110_ERROR) {
89 return 0;
90 } else {
91 is_modified = true;
92 register_key(key);
93 }
94
95 if (debug_enable) {
96 print("["); print_hex8(key); print("]\n");
97 }
98
99 matrix_scan_quantum();
100 return 1;
101}
102
103void matrix_print(void){
104
105}
106
107inline
108uint8_t matrix_get_row(uint8_t row)
109{
110 return matrix[row];
111}
112
113inline
114static void register_key(uint8_t key)
115{
116 if (key&0x80) {
117 matrix[ROW(key)] &= ~(1<<COL(key));
118 } else {
119 matrix[ROW(key)] |= (1<<COL(key));
120 }
121} \ No newline at end of file