3 Note for ErgoDox EZ customizers: Here be dragons!
4 This is not a file you want to be messing with.
5 All of the interesting stuff for you is under keymaps/ :)
8 Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include <util/delay.h>
31 #include "action_layer.h"
39 /* matrix state(1:on, 0:off) */
40 static matrix_row_t matrix[MATRIX_ROWS];
41 static matrix_row_t matrix_stage[MATRIX_ROWS];
42 static matrix_row_t matrix_debouncing[MATRIX_ROWS];
44 static uint16_t debouncing_time;
45 static bool debouncing = false;
47 __attribute__ ((weak))
48 void matrix_init_kb(void) {
52 __attribute__ ((weak))
53 void matrix_scan_kb(void) {
57 __attribute__ ((weak))
58 void matrix_init_user(void) {
61 __attribute__ ((weak))
62 void matrix_scan_user(void) {
66 uint8_t matrix_rows(void)
72 uint8_t matrix_cols(void)
77 void matrix_init(void)
80 DDRF &= ~(1<<4 | 1<<5 | 1<<6 | 1<<7);
81 PORTF |= (1<<4 | 1<<5 | 1<<6 | 1<<7);
84 DDRD &= ~(1<<0 | 1<<1 | 1<<4);
85 PORTD |= (1<<0 | 1<<1 | 1<<4);
87 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
89 matrix_debouncing[i] = 0;
93 matrix_init_quantum();
97 uint8_t matrix_scan(void)
100 (PINF&(1<<4) ? 0 : (1<<0)) |
101 (PINF&(1<<5) ? 0 : (1<<1)) |
102 (PINF&(1<<6) ? 0 : (1<<2)) |
103 (PINF&(1<<7) ? 0 : (1<<3));
105 (PIND&(1<<1) ? 0 : (1<<0)) |
106 (PIND&(1<<0) ? 0 : (1<<1)) |
107 (PIND&(1<<4) ? 0 : (1<<2)) |
108 (PINC&(1<<6) ? 0 : (1<<3));
110 if (memcmp(matrix_debouncing, matrix_stage, sizeof(matrix)) != 0) {
112 debouncing_time = timer_read();
115 matrix_debouncing[0] = matrix_stage[0];
116 matrix_debouncing[1] = matrix_stage[1];
118 if (debouncing && (timer_elapsed(debouncing_time) > 20)) {
119 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
120 matrix[i] = matrix_debouncing[i];
125 matrix_scan_quantum();
130 bool matrix_is_modified(void)
136 bool matrix_is_on(uint8_t row, uint8_t col)
138 return (matrix[row] & ((matrix_row_t)1<<col));
142 matrix_row_t matrix_get_row(uint8_t row)
147 void matrix_print(void)
151 uint8_t matrix_key_count(void)
154 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
155 count += bitpop16(matrix[i]);