aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/ergodox_infinity/config.h19
-rw-r--r--keyboards/ergodox_infinity/ergodox_infinity.c126
-rw-r--r--keyboards/ergodox_infinity/led.c26
-rw-r--r--keyboards/ergodox_infinity/matrix.c172
-rw-r--r--keyboards/ergodox_infinity/rules.mk11
-rw-r--r--keyboards/ergodox_infinity/visualizer.c3
-rw-r--r--quantum/led_matrix/led_matrix.c2
7 files changed, 36 insertions, 323 deletions
diff --git a/keyboards/ergodox_infinity/config.h b/keyboards/ergodox_infinity/config.h
index 275d4e1dc..e0208ba4d 100644
--- a/keyboards/ergodox_infinity/config.h
+++ b/keyboards/ergodox_infinity/config.h
@@ -54,7 +54,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
54/* key matrix size */ 54/* key matrix size */
55#define MATRIX_ROWS 18 55#define MATRIX_ROWS 18
56#define MATRIX_COLS 5 56#define MATRIX_COLS 5
57#define LOCAL_MATRIX_ROWS 9 57
58// For some reason, the rows are colums in the schematic, and vice versa
59#define MATRIX_ROW_PINS { B2, B3, B18, B19, C0, C9, C10, C11, D0 }
60#define MATRIX_COL_PINS { D1, D4, D5, D6, D7 }
61#define UNUSED_PINS
62
63/* COL2ROW, ROW2COL */
64#define DIODE_DIRECTION ROW2COL
65
66/* Serial config (for communication between halves) */
67#define SERIAL_USART_DRIVER SD1 // Only true for the master half
68#define SERIAL_USART_CONFIG { (SERIAL_USART_SPEED), } // Only field is speed
69#define SERIAL_USART_FULL_DUPLEX
70#define SERIAL_USART_TIMEOUT 50
58 71
59/* number of backlight levels */ 72/* number of backlight levels */
60#define BACKLIGHT_LEVELS 3 73#define BACKLIGHT_LEVELS 3
@@ -103,10 +116,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
103/* Set 0 if debouncing isn't needed */ 116/* Set 0 if debouncing isn't needed */
104#define DEBOUNCE 5 117#define DEBOUNCE 5
105 118
106#define SERIAL_LINK_BAUD 562500
107#define SERIAL_LINK_THREAD_PRIORITY (NORMALPRIO - 1)
108
109#define VISUALIZER_USER_DATA_SIZE 16 119#define VISUALIZER_USER_DATA_SIZE 16
120
110/* 121/*
111 * Feature disable options 122 * Feature disable options
112 * These options are also useful to firmware size reduction. 123 * These options are also useful to firmware size reduction.
diff --git a/keyboards/ergodox_infinity/ergodox_infinity.c b/keyboards/ergodox_infinity/ergodox_infinity.c
index b802bf014..76cbca07f 100644
--- a/keyboards/ergodox_infinity/ergodox_infinity.c
+++ b/keyboards/ergodox_infinity/ergodox_infinity.c
@@ -8,47 +8,6 @@
8# include "lcd_backlight.h" 8# include "lcd_backlight.h"
9#endif 9#endif
10 10
11#if (defined(LED_MATRIX_ENABLE) || defined(WPM_ENABLE))
12# include "serial_link/protocol/transport.h"
13
14# ifdef LED_MATRIX_ENABLE
15MASTER_TO_ALL_SLAVES_OBJECT(led_matrix, led_eeconfig_t);
16MASTER_TO_ALL_SLAVES_OBJECT(led_suspend_state, bool);
17static led_eeconfig_t last_sent_led_matrix;
18static uint16_t led_matrix_sent_timer = 0;
19
20void send_led_suspend_state(void) {
21 if (is_serial_link_master()) {
22 *begin_write_led_suspend_state() = led_matrix_get_suspend_state();
23 end_write_led_suspend_state();
24 }
25}
26# endif
27
28# ifdef WPM_ENABLE
29# include "wpm.h"
30MASTER_TO_ALL_SLAVES_OBJECT(current_wpm, uint8_t);
31static uint8_t last_sent_wpm = 0;
32# endif
33
34static remote_object_t *remote_objects[] = {
35# ifdef LED_MATRIX_ENABLE
36 REMOTE_OBJECT(led_matrix),
37 REMOTE_OBJECT(led_suspend_state),
38# endif
39# ifdef WPM_ENABLE
40 REMOTE_OBJECT(current_wpm),
41# endif
42};
43#endif
44
45void init_serial_link_hal(void) {
46 PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
47 PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
48 PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
49 PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
50}
51
52#define RED_PIN 1 11#define RED_PIN 1
53#define GREEN_PIN 2 12#define GREEN_PIN 2
54#define BLUE_PIN 3 13#define BLUE_PIN 3
@@ -176,70 +135,15 @@ void matrix_init_kb(void) {
176#endif 135#endif
177 136
178 matrix_init_user(); 137 matrix_init_user();
179#if (defined(LED_MATRIX_ENABLE) || defined(WPM_ENABLE))
180 add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t *));
181#endif
182} 138}
183 139
184void matrix_scan_kb(void) { 140void matrix_scan_kb(void) {
185 // put your looping keyboard code here 141 // put your looping keyboard code here
186 // runs every cycle (a lot) 142 // runs every cycle (a lot)
187 143
188#ifdef LED_MATRIX_ENABLE
189 if (is_serial_link_master()) {
190 if (!led_matrix_get_suspend_state()) {
191 if (timer_elapsed(led_matrix_sent_timer) >= 5000 || memcmp((void *)&last_sent_led_matrix, (void *)&led_matrix_eeconfig, sizeof(last_sent_led_matrix))) {
192 led_matrix_sent_timer = timer_read();
193 memcpy((void *)&last_sent_led_matrix, (void *)&led_matrix_eeconfig, sizeof(last_sent_led_matrix));
194 *begin_write_led_matrix() = last_sent_led_matrix;
195 end_write_led_matrix();
196 }
197 }
198 } else if (is_serial_link_connected()) {
199 bool *new_led_suspend_state = read_led_suspend_state();
200 if (new_led_suspend_state) {
201 led_matrix_set_suspend_state(*new_led_suspend_state);
202 }
203 if (!led_matrix_get_suspend_state()) {
204 led_eeconfig_t *new_led_matrix = read_led_matrix();
205 if (new_led_matrix) {
206 memcpy((void *)&led_matrix_eeconfig, (void *)new_led_matrix, sizeof(last_sent_led_matrix));
207 }
208 }
209 }
210#endif
211
212#ifdef WPM_ENABLE
213 if (is_serial_link_master()) {
214 uint8_t current_wpm = get_current_wpm();
215 if (current_wpm != last_sent_wpm) {
216 *begin_write_current_wpm() = current_wpm;
217 end_write_current_wpm();
218 last_sent_wpm = current_wpm;
219 }
220 } else if (is_serial_link_connected()) {
221 uint8_t *new_wpm = read_current_wpm();
222 if (new_wpm) {
223 set_current_wpm(*new_wpm);
224 }
225 }
226#endif
227
228 matrix_scan_user(); 144 matrix_scan_user();
229} 145}
230 146
231bool is_keyboard_master(void) { return is_serial_link_master(); }
232
233bool is_keyboard_left(void) {
234#if defined(EE_HANDS)
235 return eeconfig_read_handedness();
236#elif defined(MASTER_IS_ON_RIGHT)
237 return !is_keyboard_master();
238#else
239 return is_keyboard_master();
240#endif
241}
242
243__attribute__ ((weak)) void ergodox_board_led_on(void) {} 147__attribute__ ((weak)) void ergodox_board_led_on(void) {}
244 148
245__attribute__ ((weak)) void ergodox_right_led_1_on(void) {} 149__attribute__ ((weak)) void ergodox_right_led_1_on(void) {}
@@ -262,20 +166,6 @@ __attribute__ ((weak)) void ergodox_right_led_2_set(uint8_t n) {}
262 166
263__attribute__ ((weak)) void ergodox_right_led_3_set(uint8_t n) {} 167__attribute__ ((weak)) void ergodox_right_led_3_set(uint8_t n) {}
264 168
265void suspend_power_down_kb(void) {
266#ifdef LED_MATRIX_ENABLE
267 send_led_suspend_state();
268#endif
269 suspend_power_down_user();
270}
271
272void suspend_wakeup_init_kb(void) {
273#ifdef LED_MATRIX_ENABLE
274 send_led_suspend_state();
275#endif
276 suspend_wakeup_init_user();
277}
278
279#ifdef SWAP_HANDS_ENABLE 169#ifdef SWAP_HANDS_ENABLE
280__attribute__ ((weak)) 170__attribute__ ((weak))
281const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { 171const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
@@ -472,3 +362,19 @@ __attribute__((weak)) void st7565_task_user(void) {
472 } 362 }
473} 363}
474#endif 364#endif
365
366#if defined(SPLIT_KEYBOARD)
367void usart_master_init(SerialDriver **driver) {
368 PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
369 PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
370
371 // driver is set to SD1 in config.h
372}
373
374void usart_slave_init(SerialDriver **driver) {
375 PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
376 PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
377
378 *driver = &SD2;
379}
380#endif
diff --git a/keyboards/ergodox_infinity/led.c b/keyboards/ergodox_infinity/led.c
deleted file mode 100644
index 0b50247d7..000000000
--- a/keyboards/ergodox_infinity/led.c
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2Copyright 2012 Jun Wako <wakojun@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 <hal.h>
19
20#include "led.h"
21
22
23void led_set(uint8_t usb_led) {
24 //TODO: Add led emulation if there's no customized visualization
25 (void)usb_led;
26}
diff --git a/keyboards/ergodox_infinity/matrix.c b/keyboards/ergodox_infinity/matrix.c
deleted file mode 100644
index 0fca56a97..000000000
--- a/keyboards/ergodox_infinity/matrix.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2Copyright 2016 Fred Sundvik <fsundvik@gmail.com>
3Jun Wako <wakojun@gmail.com>
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include <stdint.h>
19#include <stdbool.h>
20#include <string.h>
21#include <hal.h>
22#include "timer.h"
23#include "wait.h"
24#include "print.h"
25#include "debug.h"
26#include "matrix.h"
27#include "keyboard.h"
28#include "serial_link/system/serial_link.h"
29
30
31/*
32 * Infinity ErgoDox Pinusage:
33 * Column pins are input with internal pull-down. Row pins are output and strobe with high.
34 * Key is high or 1 when it turns on.
35 *
36 * col: { PTD1, PTD4, PTD5, PTD6, PTD7 }
37 * row: { PTB2, PTB3, PTB18, PTB19, PTC0, PTC9, PTC10, PTC11, PTD0 }
38 */
39/* matrix state(1:on, 0:off) */
40static matrix_row_t matrix[MATRIX_ROWS];
41static matrix_row_t matrix_debouncing[LOCAL_MATRIX_ROWS];
42static bool debouncing = false;
43static uint16_t debouncing_time = 0;
44
45
46void matrix_init(void)
47{
48 /* Row(sense) */
49 palSetPadMode(GPIOD, 1, PAL_MODE_INPUT_PULLDOWN);
50 palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLDOWN);
51 palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLDOWN);
52 palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLDOWN);
53 palSetPadMode(GPIOD, 7, PAL_MODE_INPUT_PULLDOWN);
54
55 /* Column(strobe) */
56 palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
57 palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL);
58 palSetPadMode(GPIOB, 18, PAL_MODE_OUTPUT_PUSHPULL);
59 palSetPadMode(GPIOB, 19, PAL_MODE_OUTPUT_PUSHPULL);
60 palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL);
61 palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL);
62 palSetPadMode(GPIOC, 10, PAL_MODE_OUTPUT_PUSHPULL);
63 palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL);
64 palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
65
66 memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
67 memset(matrix_debouncing, 0, LOCAL_MATRIX_ROWS * sizeof(matrix_row_t));
68
69 matrix_init_quantum();
70}
71
72uint8_t matrix_scan(void)
73{
74 for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
75 matrix_row_t data = 0;
76
77 // strobe row
78 switch (row) {
79 case 0: palSetPad(GPIOB, 2); break;
80 case 1: palSetPad(GPIOB, 3); break;
81 case 2: palSetPad(GPIOB, 18); break;
82 case 3: palSetPad(GPIOB, 19); break;
83 case 4: palSetPad(GPIOC, 0); break;
84 case 5: palSetPad(GPIOC, 9); break;
85 case 6: palSetPad(GPIOC, 10); break;
86 case 7: palSetPad(GPIOC, 11); break;
87 case 8: palSetPad(GPIOD, 0); break;
88 }
89
90 // need wait to settle pin state
91 // if you wait too short, or have a too high update rate
92 // the keyboard might freeze, or there might not be enough
93 // processing power to update the LCD screen properly.
94 // 20us, or two ticks at 100000Hz seems to be OK
95 wait_us(20);
96
97 // read col data: { PTD1, PTD4, PTD5, PTD6, PTD7 }
98 data = ((palReadPort(GPIOD) & 0xF0) >> 3) |
99 ((palReadPort(GPIOD) & 0x02) >> 1);
100
101 // un-strobe row
102 switch (row) {
103 case 0: palClearPad(GPIOB, 2); break;
104 case 1: palClearPad(GPIOB, 3); break;
105 case 2: palClearPad(GPIOB, 18); break;
106 case 3: palClearPad(GPIOB, 19); break;
107 case 4: palClearPad(GPIOC, 0); break;
108 case 5: palClearPad(GPIOC, 9); break;
109 case 6: palClearPad(GPIOC, 10); break;
110 case 7: palClearPad(GPIOC, 11); break;
111 case 8: palClearPad(GPIOD, 0); break;
112 }
113
114 if (matrix_debouncing[row] != data) {
115 matrix_debouncing[row] = data;
116 debouncing = true;
117 debouncing_time = timer_read();
118 }
119 }
120
121 uint8_t offset = 0;
122 if (is_serial_link_master() && !is_keyboard_left()) {
123 offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS;
124 }
125
126 if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
127 for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
128 matrix[offset + row] = matrix_debouncing[row];
129 }
130 debouncing = false;
131 }
132 matrix_scan_quantum();
133 return 1;
134}
135
136bool matrix_is_on(uint8_t row, uint8_t col)
137{
138 return (matrix[row] & (1<<col));
139}
140
141matrix_row_t matrix_get_row(uint8_t row)
142{
143 return matrix[row];
144}
145
146void matrix_print(void)
147{
148 xprintf("\nr/c 01234567\n");
149 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
150 xprintf("%X0: ", row);
151 matrix_row_t data = matrix_get_row(row);
152 for (int col = 0; col < MATRIX_COLS; col++) {
153 if (data & (1<<col))
154 xprintf("1");
155 else
156 xprintf("0");
157 }
158 xprintf("\n");
159 }
160}
161
162void matrix_set_remote(matrix_row_t* rows, uint8_t index) {
163 uint8_t offset = 0;
164 if (is_keyboard_left()) {
165 offset = LOCAL_MATRIX_ROWS * (index + 1);
166 } else {
167 offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS * (index + 2);
168 }
169 for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
170 matrix[offset + row] = rows[row];
171 }
172}
diff --git a/keyboards/ergodox_infinity/rules.mk b/keyboards/ergodox_infinity/rules.mk
index c7ff07d4e..fbd52cd25 100644
--- a/keyboards/ergodox_infinity/rules.mk
+++ b/keyboards/ergodox_infinity/rules.mk
@@ -12,18 +12,17 @@ MOUSEKEY_ENABLE = yes # Mouse keys
12EXTRAKEY_ENABLE = yes # Audio control and System control 12EXTRAKEY_ENABLE = yes # Audio control and System control
13CONSOLE_ENABLE = no # Console for debug 13CONSOLE_ENABLE = no # Console for debug
14COMMAND_ENABLE = yes # Commands for debug and configuration 14COMMAND_ENABLE = yes # Commands for debug and configuration
15CUSTOM_MATRIX = yes # Custom matrix file for the ErgoDox EZ
16SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 15SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
17NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 16NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
18UNICODE_ENABLE = yes # Unicode 17UNICODE_ENABLE = yes # Unicode
19SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard 18SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard
20 19
21CUSTOM_MATRIX = yes # Custom matrix file
22SERIAL_LINK_ENABLE = yes
23
24MIDI_ENABLE = no 20MIDI_ENABLE = no
25RGBLIGHT_ENABLE = no 21RGBLIGHT_ENABLE = no
26 22
23SPLIT_KEYBOARD = yes
24SERIAL_DRIVER = usart
25
27ST7565_ENABLE = yes 26ST7565_ENABLE = yes
28 27
29LED_MATRIX_ENABLE = yes 28LED_MATRIX_ENABLE = yes
@@ -36,8 +35,4 @@ LCD_DRIVER = st7565
36LCD_WIDTH = 128 35LCD_WIDTH = 128
37LCD_HEIGHT = 32 36LCD_HEIGHT = 32
38 37
39# project specific files
40SRC = matrix.c \
41 led.c
42
43LAYOUTS = ergodox 38LAYOUTS = ergodox
diff --git a/keyboards/ergodox_infinity/visualizer.c b/keyboards/ergodox_infinity/visualizer.c
index 4b16021ab..1ea891e83 100644
--- a/keyboards/ergodox_infinity/visualizer.c
+++ b/keyboards/ergodox_infinity/visualizer.c
@@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30#include "visualizer_keyframes.h" 30#include "visualizer_keyframes.h"
31#include "lcd_keyframes.h" 31#include "lcd_keyframes.h"
32#include "lcd_backlight_keyframes.h" 32#include "lcd_backlight_keyframes.h"
33#include "system/serial_link.h"
34#include "default_animations.h" 33#include "default_animations.h"
35 34
36static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); 35static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF);
@@ -177,7 +176,7 @@ static void update_emulated_leds(visualizer_state_t* state, visualizer_keyboard_
177 uint8_t new_index; 176 uint8_t new_index;
178 uint8_t old_index; 177 uint8_t old_index;
179 178
180 if (is_serial_link_master()) { 179 if (is_keyboard_master()) {
181 new_index = get_led_index_master(user_data_new); 180 new_index = get_led_index_master(user_data_new);
182 old_index = get_led_index_master(user_data_old); 181 old_index = get_led_index_master(user_data_old);
183 } 182 }
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index fe7f1f039..bcf258b26 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -459,7 +459,7 @@ void led_matrix_init(void) {
459 459
460void led_matrix_set_suspend_state(bool state) { 460void led_matrix_set_suspend_state(bool state) {
461#ifdef LED_DISABLE_WHEN_USB_SUSPENDED 461#ifdef LED_DISABLE_WHEN_USB_SUSPENDED
462 if (state) { 462 if (state && is_keyboard_master()) {
463 led_matrix_set_value_all(0); // turn off all LEDs when suspending 463 led_matrix_set_value_all(0); // turn off all LEDs when suspending
464 } 464 }
465 suspend_state = state; 465 suspend_state = state;