aboutsummaryrefslogtreecommitdiff
path: root/keyboards/planck
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/planck')
-rw-r--r--keyboards/planck/keymaps/default/keymap.c2
-rw-r--r--keyboards/planck/rev6/config.h15
-rw-r--r--keyboards/planck/rev6/matrix.c176
-rw-r--r--keyboards/planck/rev6/rev6.c10
-rw-r--r--keyboards/planck/rev6/rules.mk3
5 files changed, 22 insertions, 184 deletions
diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c
index 901977198..44bc7db7f 100644
--- a/keyboards/planck/keymaps/default/keymap.c
+++ b/keyboards/planck/keymaps/default/keymap.c
@@ -289,7 +289,7 @@ void encoder_update(bool clockwise) {
289 } 289 }
290} 290}
291 291
292void dip_update(uint8_t index, bool active) { 292void dip_switch_update_user(uint8_t index, bool active) {
293 switch (index) { 293 switch (index) {
294 case 0: 294 case 0:
295 if (active) { 295 if (active) {
diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h
index 3354c3f80..d8c9d86ae 100644
--- a/keyboards/planck/rev6/config.h
+++ b/keyboards/planck/rev6/config.h
@@ -37,15 +37,20 @@
37 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) 37 * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
38 * 38 *
39*/ 39*/
40/* Note: These are not used for arm boards. They're here purely as documentation. 40/* Note: These are not used for arm boards. They're here purely as documentation. */
41 * #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 } 41#undef MATRIX_ROW_PINS
42 * #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } 42#undef MATRIX_COL_PINS
43 * #define UNUSED_PINS 43
44 */ 44#define MATRIX_ROW_PINS { A10, A9, A8, B15, C13, C14, C15, A2 }
45#define MATRIX_COL_PINS { B11, B10, B2, B1, A7, B0 }
46
47#define UNUSED_PINS
45 48
46#define ENCODERS_PAD_A { B12 } 49#define ENCODERS_PAD_A { B12 }
47#define ENCODERS_PAD_B { B13 } 50#define ENCODERS_PAD_B { B13 }
48 51
52#define DIP_SWITCH_PINS { B14, A15, A0, B9 }
53
49#define MUSIC_MAP 54#define MUSIC_MAP
50#undef AUDIO_VOICES 55#undef AUDIO_VOICES
51#undef C6_AUDIO 56#undef C6_AUDIO
diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c
deleted file mode 100644
index 2df588cef..000000000
--- a/keyboards/planck/rev6/matrix.c
+++ /dev/null
@@ -1,176 +0,0 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <string.h>
4#include "hal.h"
5#include "timer.h"
6#include "wait.h"
7#include "printf.h"
8#include "backlight.h"
9#include "matrix.h"
10#include "action.h"
11#include "keycode.h"
12#include <string.h>
13
14/*
15 * col: { B11, B10, B2, B1, A7, B0 }
16 * row: { A10, A9, A8, B15, C13, C14, C15, A2 }
17 */
18/* matrix state(1:on, 0:off) */
19static matrix_row_t matrix[MATRIX_ROWS];
20static matrix_row_t matrix_debouncing[MATRIX_COLS];
21static bool debouncing = false;
22static uint16_t debouncing_time = 0;
23
24static bool dip_switch[4] = {0, 0, 0, 0};
25
26__attribute__ ((weak))
27void matrix_init_user(void) {}
28
29__attribute__ ((weak))
30void matrix_scan_user(void) {}
31
32__attribute__ ((weak))
33void matrix_init_kb(void) {
34 matrix_init_user();
35}
36
37__attribute__ ((weak))
38void matrix_scan_kb(void) {
39 matrix_scan_user();
40}
41
42void matrix_init(void) {
43 printf("matrix init\n");
44 //debug_matrix = true;
45
46 // dip switch setup
47 palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP);
48 palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLUP);
49 palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLUP);
50 palSetPadMode(GPIOB, 9, PAL_MODE_INPUT_PULLUP);
51
52 // actual matrix setup
53 palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL);
54 palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL);
55 palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
56 palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL);
57 palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL);
58 palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
59
60 palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN);
61 palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN);
62 palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN);
63 palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLDOWN);
64 palSetPadMode(GPIOC, 13, PAL_MODE_INPUT_PULLDOWN);
65 palSetPadMode(GPIOC, 14, PAL_MODE_INPUT_PULLDOWN);
66 palSetPadMode(GPIOC, 15, PAL_MODE_INPUT_PULLDOWN);
67 palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLDOWN);
68
69
70 memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
71 memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t));
72
73
74 matrix_init_quantum();
75}
76
77__attribute__ ((weak))
78void dip_update(uint8_t index, bool active) { }
79
80bool last_dip_switch[4] = {0};
81
82uint8_t matrix_scan(void) {
83 // dip switch
84 dip_switch[0] = !palReadPad(GPIOB, 14);
85 dip_switch[1] = !palReadPad(GPIOA, 15);
86 dip_switch[2] = !palReadPad(GPIOA, 10);
87 dip_switch[3] = !palReadPad(GPIOB, 9);
88 for (uint8_t i = 0; i < 4; i++) {
89 if (last_dip_switch[i] ^ dip_switch[i])
90 dip_update(i, dip_switch[i]);
91 }
92 memcpy(last_dip_switch, dip_switch, sizeof(&dip_switch));
93
94 // actual matrix
95 for (int col = 0; col < MATRIX_COLS; col++) {
96 matrix_row_t data = 0;
97
98 // strobe col { B11, B10, B2, B1, A7, B0 }
99 switch (col) {
100 case 0: palSetPad(GPIOB, 11); break;
101 case 1: palSetPad(GPIOB, 10); break;
102 case 2: palSetPad(GPIOB, 2); break;
103 case 3: palSetPad(GPIOB, 1); break;
104 case 4: palSetPad(GPIOA, 7); break;
105 case 5: palSetPad(GPIOB, 0); break;
106 }
107
108 // need wait to settle pin state
109 wait_us(20);
110
111 // read row data { A10, A9, A8, B15, C13, C14, C15, A2 }
112 data = (
113 (palReadPad(GPIOA, 10) << 0 ) |
114 (palReadPad(GPIOA, 9) << 1 ) |
115 (palReadPad(GPIOA, 8) << 2 ) |
116 (palReadPad(GPIOB, 15) << 3 ) |
117 (palReadPad(GPIOC, 13) << 4 ) |
118 (palReadPad(GPIOC, 14) << 5 ) |
119 (palReadPad(GPIOC, 15) << 6 ) |
120 (palReadPad(GPIOA, 2) << 7 )
121 );
122
123 // unstrobe col { B11, B10, B2, B1, A7, B0 }
124 switch (col) {
125 case 0: palClearPad(GPIOB, 11); break;
126 case 1: palClearPad(GPIOB, 10); break;
127 case 2: palClearPad(GPIOB, 2); break;
128 case 3: palClearPad(GPIOB, 1); break;
129 case 4: palClearPad(GPIOA, 7); break;
130 case 5: palClearPad(GPIOB, 0); break;
131 }
132
133 if (matrix_debouncing[col] != data) {
134 matrix_debouncing[col] = data;
135 debouncing = true;
136 debouncing_time = timer_read();
137 }
138 }
139
140 if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
141 for (int row = 0; row < MATRIX_ROWS; row++) {
142 matrix[row] = 0;
143 for (int col = 0; col < MATRIX_COLS; col++) {
144 matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col);
145 }
146 }
147 debouncing = false;
148 }
149
150 matrix_scan_quantum();
151
152 return 1;
153}
154
155bool matrix_is_on(uint8_t row, uint8_t col) {
156 return (matrix[row] & (1<<col));
157}
158
159matrix_row_t matrix_get_row(uint8_t row) {
160 return matrix[row];
161}
162
163void matrix_print(void) {
164 printf("\nr/c 01234567\n");
165 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
166 printf("%X0: ", row);
167 matrix_row_t data = matrix_get_row(row);
168 for (int col = 0; col < MATRIX_COLS; col++) {
169 if (data & (1<<col))
170 printf("1");
171 else
172 printf("0");
173 }
174 printf("\n");
175 }
176}
diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c
index 650e1a194..8f4d168bf 100644
--- a/keyboards/planck/rev6/rev6.c
+++ b/keyboards/planck/rev6/rev6.c
@@ -22,3 +22,13 @@ void matrix_init_kb(void) {
22void matrix_scan_kb(void) { 22void matrix_scan_kb(void) {
23 matrix_scan_user(); 23 matrix_scan_user();
24} 24}
25
26#ifdef DIP_SWITCH_ENABLE
27__attribute__((weak))
28void dip_update(uint8_t index, bool active) {}
29
30__attribute__((weak))
31void dip_switch_update_user(uint8_t index, bool active) {
32 dip_update(index, active);
33}
34#endif
diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk
index c58275002..ea53c8f91 100644
--- a/keyboards/planck/rev6/rules.mk
+++ b/keyboards/planck/rev6/rules.mk
@@ -1,5 +1,4 @@
1# project specific files 1# project specific files
2SRC = matrix.c
3LAYOUTS += ortho_4x12 2LAYOUTS += ortho_4x12
4 3
5# Cortex version 4# Cortex version
@@ -31,9 +30,9 @@ API_SYSEX_ENABLE = no
31SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 30SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
32#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 31#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
33 32
34CUSTOM_MATRIX = yes # Custom matrix file
35# SERIAL_LINK_ENABLE = yes 33# SERIAL_LINK_ENABLE = yes
36ENCODER_ENABLE = yes 34ENCODER_ENABLE = yes
35DIP_SWITCH_ENABLE = yes
37 36
38LAYOUTS = ortho_4x12 planck_mit 37LAYOUTS = ortho_4x12 planck_mit
39LAYOUTS_HAS_RGB = no 38LAYOUTS_HAS_RGB = no