aboutsummaryrefslogtreecommitdiff
path: root/keyboards/winkeyless
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/winkeyless')
-rw-r--r--keyboards/winkeyless/bface/config.h2
-rw-r--r--keyboards/winkeyless/bmini/bmini.c3
-rw-r--r--keyboards/winkeyless/bmini/config.h3
-rw-r--r--keyboards/winkeyless/bmini/matrix.c106
-rw-r--r--keyboards/winkeyless/bmini/rules.mk4
-rw-r--r--keyboards/winkeyless/bminiex/config.h3
-rw-r--r--keyboards/winkeyless/bminiex/matrix.c122
-rw-r--r--keyboards/winkeyless/bminiex/rules.mk4
8 files changed, 9 insertions, 238 deletions
diff --git a/keyboards/winkeyless/bface/config.h b/keyboards/winkeyless/bface/config.h
index 9d90e16a3..95d44557a 100644
--- a/keyboards/winkeyless/bface/config.h
+++ b/keyboards/winkeyless/bface/config.h
@@ -35,6 +35,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
35#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7} 35#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7}
36#define UNUSED_PINS 36#define UNUSED_PINS
37 37
38#define DIODE_DIRECTION COL2ROW
39
38#define RGBLED_NUM 16 40#define RGBLED_NUM 16
39#define RGBLIGHT_ANIMATIONS 41#define RGBLIGHT_ANIMATIONS
40 42
diff --git a/keyboards/winkeyless/bmini/bmini.c b/keyboards/winkeyless/bmini/bmini.c
index 87a31d052..f44fd36a8 100644
--- a/keyboards/winkeyless/bmini/bmini.c
+++ b/keyboards/winkeyless/bmini/bmini.c
@@ -16,6 +16,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "bmini.h" 18#include "bmini.h"
19
20__attribute__ ((weak))
21void matrix_scan_user(void) {}
diff --git a/keyboards/winkeyless/bmini/config.h b/keyboards/winkeyless/bmini/config.h
index 37df80f80..f8a26e4f0 100644
--- a/keyboards/winkeyless/bmini/config.h
+++ b/keyboards/winkeyless/bmini/config.h
@@ -31,6 +31,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31/* matrix size */ 31/* matrix size */
32#define MATRIX_ROWS 8 32#define MATRIX_ROWS 8
33#define MATRIX_COLS 15 33#define MATRIX_COLS 15
34#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
35#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
36#define DIODE_DIRECTION COL2ROW
34 37
35#define RGBLIGHT_ANIMATIONS 38#define RGBLIGHT_ANIMATIONS
36 39
diff --git a/keyboards/winkeyless/bmini/matrix.c b/keyboards/winkeyless/bmini/matrix.c
deleted file mode 100644
index 57aa36b5f..000000000
--- a/keyboards/winkeyless/bmini/matrix.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
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#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
27static uint8_t debouncing = DEBOUNCE;
28
29static matrix_row_t matrix[MATRIX_ROWS];
30static matrix_row_t matrix_debouncing[MATRIX_ROWS];
31
32void matrix_init(void) {
33 // all outputs for rows high
34 DDRB = 0xFF;
35 PORTB = 0xFF;
36 // all inputs for columns
37 DDRA = 0x00;
38 DDRC &= ~(0x111111<<2);
39 DDRD &= ~(1<<PIND7);
40 // all columns are pulled-up
41 PORTA = 0xFF;
42 PORTC |= (0b111111<<2);
43 PORTD |= (1<<PIND7);
44
45 // initialize matrix state: all keys off
46 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
47 matrix[row] = 0x00;
48 matrix_debouncing[row] = 0x00;
49 }
50}
51
52void matrix_set_row_status(uint8_t row) {
53 DDRB = (1 << row);
54 PORTB = ~(1 << row);
55}
56
57uint8_t bit_reverse(uint8_t x) {
58 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
59 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
60 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
61 return x;
62}
63
64uint8_t matrix_scan(void) {
65 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
66 matrix_set_row_status(row);
67 _delay_us(5);
68
69 matrix_row_t cols = (
70 // cols 0..7, PORTA 0 -> 7
71 (~PINA) & 0xFF
72 ) | (
73 // cols 8..13, PORTC 7 -> 0
74 bit_reverse((~PINC) & 0xFF) << 8
75 ) | (
76 // col 14, PORTD 7
77 ((~PIND) & (1 << PIND7)) << 7
78 );
79
80 if (matrix_debouncing[row] != cols) {
81 matrix_debouncing[row] = cols;
82 debouncing = DEBOUNCE;
83 }
84 }
85
86 if (debouncing) {
87 if (--debouncing) {
88 _delay_ms(1);
89 } else {
90 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
91 matrix[i] = matrix_debouncing[i];
92 }
93 }
94 }
95
96 matrix_scan_user();
97
98 return 1;
99}
100
101inline matrix_row_t matrix_get_row(uint8_t row) {
102 return matrix[row];
103}
104
105void matrix_print(void) {
106}
diff --git a/keyboards/winkeyless/bmini/rules.mk b/keyboards/winkeyless/bmini/rules.mk
index 7822bd830..530e8ea32 100644
--- a/keyboards/winkeyless/bmini/rules.mk
+++ b/keyboards/winkeyless/bmini/rules.mk
@@ -22,7 +22,3 @@ RGBLIGHT_ENABLE = yes
22WS2812_DRIVER = i2c 22WS2812_DRIVER = i2c
23 23
24OPT_DEFS = -DDEBUG_LEVEL=0 24OPT_DEFS = -DDEBUG_LEVEL=0
25
26# custom matrix setup
27CUSTOM_MATRIX = yes
28SRC = matrix.c
diff --git a/keyboards/winkeyless/bminiex/config.h b/keyboards/winkeyless/bminiex/config.h
index 35c8ce933..037ca0028 100644
--- a/keyboards/winkeyless/bminiex/config.h
+++ b/keyboards/winkeyless/bminiex/config.h
@@ -30,6 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30/* matrix size */ 30/* matrix size */
31#define MATRIX_ROWS 8 31#define MATRIX_ROWS 8
32#define MATRIX_COLS 15 32#define MATRIX_COLS 15
33#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
34#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
35#define DIODE_DIRECTION COL2ROW
33 36
34#define RGBLIGHT_ANIMATIONS 37#define RGBLIGHT_ANIMATIONS
35 38
diff --git a/keyboards/winkeyless/bminiex/matrix.c b/keyboards/winkeyless/bminiex/matrix.c
deleted file mode 100644
index 8faaed8ac..000000000
--- a/keyboards/winkeyless/bminiex/matrix.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
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#include <avr/io.h>
19#include <util/delay.h>
20
21#include "matrix.h"
22#include "backlight.h"
23
24#ifndef DEBOUNCE
25#define DEBOUNCE 5
26#endif
27
28static uint8_t debouncing = DEBOUNCE;
29
30static matrix_row_t matrix[MATRIX_ROWS];
31static matrix_row_t matrix_debouncing[MATRIX_ROWS];
32
33__attribute__ ((weak))
34void matrix_init_user(void) {}
35__attribute__ ((weak))
36void matrix_scan_user(void) {}
37__attribute__ ((weak))
38void matrix_init_kb(void) {
39 matrix_init_user();
40}
41__attribute__ ((weak))
42void matrix_scan_kb(void) {
43 matrix_scan_user();
44}
45
46void matrix_init(void) {
47 // all outputs for rows high
48 DDRB = 0xFF;
49 PORTB = 0xFF;
50 // all inputs for columns
51 DDRA = 0x00;
52 DDRC &= ~(0x111111<<2);
53 DDRD &= ~(1<<PIND7);
54 // all columns are pulled-up
55 PORTA = 0xFF;
56 PORTC |= (0b111111<<2);
57 PORTD |= (1<<PIND7);
58
59 // initialize matrix state: all keys off
60 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
61 matrix[row] = 0x00;
62 matrix_debouncing[row] = 0x00;
63 }
64
65 matrix_init_quantum();
66}
67
68void matrix_set_row_status(uint8_t row) {
69 DDRB = (1 << row);
70 PORTB = ~(1 << row);
71}
72
73uint8_t bit_reverse(uint8_t x) {
74 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
75 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
76 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
77 return x;
78}
79
80uint8_t matrix_scan(void) {
81 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
82 matrix_set_row_status(row);
83 _delay_us(5);
84
85 matrix_row_t cols = (
86 // cols 0..7, PORTA 0 -> 7
87 (~PINA) & 0xFF
88 ) | (
89 // cols 8..13, PORTC 7 -> 0
90 bit_reverse((~PINC) & 0xFF) << 8
91 ) | (
92 // col 14, PORTD 7
93 ((~PIND) & (1 << PIND7)) << 7
94 );
95
96 if (matrix_debouncing[row] != cols) {
97 matrix_debouncing[row] = cols;
98 debouncing = DEBOUNCE;
99 }
100 }
101
102 if (debouncing) {
103 if (--debouncing) {
104 _delay_ms(1);
105 } else {
106 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
107 matrix[i] = matrix_debouncing[i];
108 }
109 }
110 }
111
112 matrix_scan_quantum();
113
114 return 1;
115}
116
117inline matrix_row_t matrix_get_row(uint8_t row) {
118 return matrix[row];
119}
120
121void matrix_print(void) {
122}
diff --git a/keyboards/winkeyless/bminiex/rules.mk b/keyboards/winkeyless/bminiex/rules.mk
index 39a77bda1..2c999dcbf 100644
--- a/keyboards/winkeyless/bminiex/rules.mk
+++ b/keyboards/winkeyless/bminiex/rules.mk
@@ -29,6 +29,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
29 29
30OPT_DEFS = -DDEBUG_LEVEL=0 30OPT_DEFS = -DDEBUG_LEVEL=0
31 31
32# custom matrix setup 32SRC += backlight.c
33CUSTOM_MATRIX = yes
34SRC = matrix.c backlight.c