diff options
Diffstat (limited to 'keyboards/mechmini')
-rw-r--r-- | keyboards/mechmini/v1/config.h | 7 | ||||
-rw-r--r-- | keyboards/mechmini/v1/matrix.c | 112 | ||||
-rw-r--r-- | keyboards/mechmini/v1/rules.mk | 4 | ||||
-rw-r--r-- | keyboards/mechmini/v1/v1.c | 10 | ||||
-rw-r--r-- | keyboards/mechmini/v1/v1.h | 24 |
5 files changed, 13 insertions, 144 deletions
diff --git a/keyboards/mechmini/v1/config.h b/keyboards/mechmini/v1/config.h index 9355a6dc3..eb15a368a 100644 --- a/keyboards/mechmini/v1/config.h +++ b/keyboards/mechmini/v1/config.h | |||
@@ -30,8 +30,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
30 | #define DESCRIPTION 40% modular keyboard | 30 | #define DESCRIPTION 40% modular keyboard |
31 | 31 | ||
32 | /* matrix size */ | 32 | /* matrix size */ |
33 | #define MATRIX_ROWS 8 | 33 | #define MATRIX_ROWS 4 |
34 | #define MATRIX_COLS 15 | 34 | #define MATRIX_COLS 12 |
35 | #define MATRIX_ROW_PINS { B0, B1, B2, B3 } | ||
36 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4 } | ||
37 | #define DIODE_DIRECTION COL2ROW | ||
35 | 38 | ||
36 | #define NO_UART 1 | 39 | #define NO_UART 1 |
37 | 40 | ||
diff --git a/keyboards/mechmini/v1/matrix.c b/keyboards/mechmini/v1/matrix.c deleted file mode 100644 index 245813dfd..000000000 --- a/keyboards/mechmini/v1/matrix.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2017 Luiz Ribeiro <luizribeiro@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 | #include <avr/io.h> | ||
19 | #include <util/delay.h> | ||
20 | |||
21 | #include "matrix.h" | ||
22 | |||
23 | #ifndef DEBOUNCE | ||
24 | # define DEBOUNCE 5 | ||
25 | #endif | ||
26 | |||
27 | static uint8_t debouncing = DEBOUNCE; | ||
28 | |||
29 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
30 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
31 | |||
32 | void matrix_set_row_status(uint8_t row); | ||
33 | uint8_t bit_reverse(uint8_t x); | ||
34 | |||
35 | void matrix_init(void) { | ||
36 | // all outputs for rows high | ||
37 | DDRB = 0xFF; | ||
38 | PORTB = 0xFF; | ||
39 | // all inputs for columns | ||
40 | DDRA = 0x00; | ||
41 | DDRC &= ~(0x111111<<2); | ||
42 | DDRD &= ~(1<<PIND7); | ||
43 | // all columns are pulled-up | ||
44 | PORTA = 0xFF; | ||
45 | PORTC |= (0b111111<<2); | ||
46 | PORTD |= (1<<PIND7); | ||
47 | |||
48 | // initialize matrix state: all keys off | ||
49 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
50 | matrix[row] = 0x00; | ||
51 | matrix_debouncing[row] = 0x00; | ||
52 | } | ||
53 | |||
54 | matrix_init_quantum(); | ||
55 | } | ||
56 | |||
57 | uint8_t matrix_scan(void) { | ||
58 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
59 | matrix_set_row_status(row); | ||
60 | _delay_us(5); | ||
61 | |||
62 | matrix_row_t cols = ( | ||
63 | // cols 0..7, PORTA 0 -> 7 | ||
64 | (~PINA) & 0xFF | ||
65 | ) | ( | ||
66 | // cols 8..13, PORTC 7 -> 0 | ||
67 | bit_reverse((~PINC) & 0xFF) << 8 | ||
68 | ) | ( | ||
69 | // col 14, PORTD 7 | ||
70 | ((~PIND) & (1 << PIND7)) << 7 | ||
71 | ); | ||
72 | |||
73 | if (matrix_debouncing[row] != cols) { | ||
74 | matrix_debouncing[row] = cols; | ||
75 | debouncing = DEBOUNCE; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | if (debouncing) { | ||
80 | if (--debouncing) { | ||
81 | _delay_ms(1); | ||
82 | } else { | ||
83 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
84 | matrix[i] = matrix_debouncing[i]; | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | matrix_scan_quantum(); | ||
90 | |||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | // declarations | ||
95 | void matrix_set_row_status(uint8_t row) { | ||
96 | DDRB = (1 << row); | ||
97 | PORTB = ~(1 << row); | ||
98 | } | ||
99 | |||
100 | uint8_t bit_reverse(uint8_t x) { | ||
101 | x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); | ||
102 | x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); | ||
103 | x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); | ||
104 | return x; | ||
105 | } | ||
106 | |||
107 | inline matrix_row_t matrix_get_row(uint8_t row) { | ||
108 | return matrix[row]; | ||
109 | } | ||
110 | |||
111 | void matrix_print(void) { | ||
112 | } | ||
diff --git a/keyboards/mechmini/v1/rules.mk b/keyboards/mechmini/v1/rules.mk index ee023b43b..1c6252c59 100644 --- a/keyboards/mechmini/v1/rules.mk +++ b/keyboards/mechmini/v1/rules.mk | |||
@@ -22,7 +22,3 @@ RGBLIGHT_ENABLE = yes | |||
22 | WS2812_DRIVER = i2c | 22 | WS2812_DRIVER = i2c |
23 | 23 | ||
24 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
25 | |||
26 | # custom matrix setup | ||
27 | CUSTOM_MATRIX = yes | ||
28 | SRC = matrix.c | ||
diff --git a/keyboards/mechmini/v1/v1.c b/keyboards/mechmini/v1/v1.c index 2c910d965..ba0e09520 100644 --- a/keyboards/mechmini/v1/v1.c +++ b/keyboards/mechmini/v1/v1.c | |||
@@ -16,13 +16,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "v1.h" | 18 | #include "v1.h" |
19 | |||
20 | void matrix_init_kb(void) { matrix_init_user(); } | ||
21 | |||
22 | __attribute__ ((weak)) | ||
23 | void matrix_init_user(void) {} | ||
24 | |||
25 | void matrix_scan_kb(void) { matrix_scan_user(); } | ||
26 | |||
27 | __attribute__ ((weak)) | ||
28 | void matrix_scan_user(void) {} | ||
diff --git a/keyboards/mechmini/v1/v1.h b/keyboards/mechmini/v1/v1.h index 1e392b353..acdad5c6d 100644 --- a/keyboards/mechmini/v1/v1.h +++ b/keyboards/mechmini/v1/v1.h | |||
@@ -30,14 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
30 | K00, K10, K20, K56, K57, KB0, KC0, K66 \ | 30 | K00, K10, K20, K56, K57, KB0, KC0, K66 \ |
31 | ) \ | 31 | ) \ |
32 | { \ | 32 | { \ |
33 | { K00, K10, K20, K56, KC_NO, K57, KC_NO, KC_NO, KB0, KC0, K66, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 33 | { K00, K10, K20, K56, KC_NO, K57, KC_NO, KC_NO, KB0, KC0, K66, KC_NO }, \ |
34 | { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 34 | { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO }, \ |
35 | { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 35 | { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO }, \ |
36 | { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC_NO, KC_NO, KC_NO }, \ | 36 | { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3 } \ |
37 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
38 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
39 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
40 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \ | ||
41 | } | 37 | } |
42 | 38 | ||
43 | #define LAYOUT_split_space( \ | 39 | #define LAYOUT_split_space( \ |
@@ -47,14 +43,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
47 | K00, K10, K20, K56, K57, KB0, KC0, K66 \ | 43 | K00, K10, K20, K56, K57, KB0, KC0, K66 \ |
48 | ) \ | 44 | ) \ |
49 | { \ | 45 | { \ |
50 | { K00, K10, K20, K56, KC_NO, KC_NO, K57, KC_NO, KB0, KC0, K66, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 46 | { K00, K10, K20, K56, KC_NO, KC_NO, K57, KC_NO, KB0, KC0, K66, KC_NO }, \ |
51 | { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 47 | { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO }, \ |
52 | { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 48 | { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO }, \ |
53 | { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC_NO, KC_NO, KC_NO }, \ | 49 | { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3 } \ |
54 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
55 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
56 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | ||
57 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \ | ||
58 | } | 50 | } |
59 | 51 | ||
60 | #endif | 52 | #endif |