2 Copyright 2012 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
18 #include QMK_KEYBOARD_H
19 #include "protocol/serial.h"
37 static uint8_t matrix[MATRIX_ROWS];
38 #define ROW(code) ((code>>3)&0xF)
39 #define COL(code) (code&0x07)
41 static bool is_modified = false;
43 __attribute__ ((weak))
44 void matrix_init_kb(void) {
48 __attribute__ ((weak))
49 void matrix_scan_kb(void) {
53 __attribute__ ((weak))
54 void matrix_init_user(void) {
57 __attribute__ ((weak))
58 void matrix_scan_user(void) {
62 uint8_t matrix_rows(void)
68 uint8_t matrix_cols(void)
73 void matrix_init(void)
76 /* PORTD |= (1<<6); */
81 // initialize matrix state: all keys off
82 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
84 /* // wait for keyboard coming up */
85 /* // otherwise LED status update fails */
86 /* print("Reseting "); */
89 /* while (serial_recv()); */
90 /* serial_send(0x01); */
92 /* if (serial_recv() == 0xFF) { */
94 /* if (serial_recv() == 0x04) */
98 /* print(" Done\n"); */
100 /* PORTD &= ~(1<<6); */
102 matrix_init_quantum();
106 uint8_t matrix_scan(void)
109 code = serial_recv();
112 debug_hex(code); debug(" ");
115 case 0xFF: // reset success: FF 04
118 code = serial_recv();
119 xprintf("%02X\n", code);
122 led_set(host_keyboard_leds());
125 case 0xFE: // layout: FE <layout>
128 xprintf("%02X\n", serial_recv());
130 case 0x7E: // reset fail: 7E 01
131 print("reset fail: ");
133 xprintf("%02X\n", serial_recv());
137 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
143 if (matrix_is_on(ROW(code), COL(code))) {
144 matrix[ROW(code)] &= ~(1<<COL(code));
148 if (!matrix_is_on(ROW(code), COL(code))) {
149 matrix[ROW(code)] |= (1<<COL(code));
153 matrix_scan_quantum();
157 bool matrix_is_modified(void)
163 bool matrix_has_ghost(void)
169 bool matrix_is_on(uint8_t row, uint8_t col)
171 return (matrix[row] & (1<<col));
175 uint8_t matrix_get_row(uint8_t row)
180 void matrix_print(void)
182 print("\nr/c 01234567\n");
183 for (uint8_t row = 0; row < matrix_rows(); row++) {
184 phex(row); print(": ");
185 pbin_reverse(matrix_get_row(row));
190 uint8_t matrix_key_count(void)
193 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
194 count += bitpop(matrix[i]);