summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoakim Tufvegren <jocke@barbanet.com>2021-07-20 03:54:32 +0200
committerGitHub <noreply@github.com>2021-07-19 18:54:32 -0700
commit1414e9736d441f4cefbdd2f88157419066f96f71 (patch)
tree927b51b9a42698ad9b297ac55a9870fc21b535d3
parent85621311db62a3a2a264cb7c9edefb7cab731e4c (diff)
Switch Ergodox Infinity over to split_common (#13481)
-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 275d4e1dcf..e0208ba4d3 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/>.
/* key matrix size */
#define MATRIX_ROWS 18
#define MATRIX_COLS 5
-#define LOCAL_MATRIX_ROWS 9
+
+// For some reason, the rows are colums in the schematic, and vice versa
+#define MATRIX_ROW_PINS { B2, B3, B18, B19, C0, C9, C10, C11, D0 }
+#define MATRIX_COL_PINS { D1, D4, D5, D6, D7 }
+#define UNUSED_PINS
+
+/* COL2ROW, ROW2COL */
+#define DIODE_DIRECTION ROW2COL
+
+/* Serial config (for communication between halves) */
+#define SERIAL_USART_DRIVER SD1 // Only true for the master half
+#define SERIAL_USART_CONFIG { (SERIAL_USART_SPEED), } // Only field is speed
+#define SERIAL_USART_FULL_DUPLEX
+#define SERIAL_USART_TIMEOUT 50
/* number of backlight levels */
#define BACKLIGHT_LEVELS 3
@@ -103,10 +116,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Set 0 if debouncing isn't needed */
#define DEBOUNCE 5
-#define SERIAL_LINK_BAUD 562500
-#define SERIAL_LINK_THREAD_PRIORITY (NORMALPRIO - 1)
-
#define VISUALIZER_USER_DATA_SIZE 16
+
/*
* Feature disable options
* 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 b802bf014e..76cbca07f8 100644
--- a/keyboards/ergodox_infinity/ergodox_infinity.c
+++ b/keyboards/ergodox_infinity/ergodox_infinity.c
@@ -8,47 +8,6 @@
# include "lcd_backlight.h"
#endif
-#if (defined(LED_MATRIX_ENABLE) || defined(WPM_ENABLE))
-# include "serial_link/protocol/transport.h"
-
-# ifdef LED_MATRIX_ENABLE
-MASTER_TO_ALL_SLAVES_OBJECT(led_matrix, led_eeconfig_t);
-MASTER_TO_ALL_SLAVES_OBJECT(led_suspend_state, bool);
-static led_eeconfig_t last_sent_led_matrix;
-static uint16_t led_matrix_sent_timer = 0;
-
-void send_led_suspend_state(void) {
- if (is_serial_link_master()) {
- *begin_write_led_suspend_state() = led_matrix_get_suspend_state();
- end_write_led_suspend_state();
- }
-}
-# endif
-
-# ifdef WPM_ENABLE
-# include "wpm.h"
-MASTER_TO_ALL_SLAVES_OBJECT(current_wpm, uint8_t);
-static uint8_t last_sent_wpm = 0;
-# endif
-
-static remote_object_t *remote_objects[] = {
-# ifdef LED_MATRIX_ENABLE
- REMOTE_OBJECT(led_matrix),
- REMOTE_OBJECT(led_suspend_state),
-# endif
-# ifdef WPM_ENABLE
- REMOTE_OBJECT(current_wpm),
-# endif
-};
-#endif
-
-void init_serial_link_hal(void) {
- PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
- PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
- PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
- PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
-}
-
#define RED_PIN 1
#define GREEN_PIN 2
#define BLUE_PIN 3
@@ -176,70 +135,15 @@ void matrix_init_kb(void) {
#endif
matrix_init_user();
-#if (defined(LED_MATRIX_ENABLE) || defined(WPM_ENABLE))
- add_remote_objects(remote_objects, sizeof(remote_objects) / sizeof(remote_object_t *));
-#endif
}
void matrix_scan_kb(void) {
// put your looping keyboard code here
// runs every cycle (a lot)
-#ifdef LED_MATRIX_ENABLE
- if (is_serial_link_master()) {
- if (!led_matrix_get_suspend_state()) {
- if (timer_elapsed(led_matrix_sent_timer) >= 5000 || memcmp((void *)&last_sent_led_matrix, (void *)&led_matrix_eeconfig, sizeof(last_sent_led_matrix))) {
- led_matrix_sent_timer = timer_read();
- memcpy((void *)&last_sent_led_matrix, (void *)&led_matrix_eeconfig, sizeof(last_sent_led_matrix));
- *begin_write_led_matrix() = last_sent_led_matrix;
- end_write_led_matrix();
- }
- }
- } else if (is_serial_link_connected()) {
- bool *new_led_suspend_state = read_led_suspend_state();
- if (new_led_suspend_state) {
- led_matrix_set_suspend_state(*new_led_suspend_state);
- }
- if (!led_matrix_get_suspend_state()) {
- led_eeconfig_t *new_led_matrix = read_led_matrix();
- if (new_led_matrix) {
- memcpy((void *)&led_matrix_eeconfig, (void *)new_led_matrix, sizeof(last_sent_led_matrix));
- }
- }
- }
-#endif
-
-#ifdef WPM_ENABLE
- if (is_serial_link_master()) {
- uint8_t current_wpm = get_current_wpm();
- if (current_wpm != last_sent_wpm) {
- *begin_write_current_wpm() = current_wpm;
- end_write_current_wpm();
- last_sent_wpm = current_wpm;
- }
- } else if (is_serial_link_connected()) {
- uint8_t *new_wpm = read_current_wpm();
- if (new_wpm) {
- set_current_wpm(*new_wpm);
- }
- }
-#endif
-
matrix_scan_user();
}
-bool is_keyboard_master(void) { return is_serial_link_master(); }
-
-bool is_keyboard_left(void) {
-#if defined(EE_HANDS)
- return eeconfig_read_handedness();
-#elif defined(MASTER_IS_ON_RIGHT)
- return !is_keyboard_master();
-#else
- return is_keyboard_master();
-#endif
-}
-
__attribute__ ((weak)) void ergodox_board_led_on(void) {}
__attribute__ ((weak)) void ergodox_right_led_1_on(void) {}
@@ -262,20 +166,6 @@ __attribute__ ((weak)) void ergodox_right_led_2_set(uint8_t n) {}
__attribute__ ((weak)) void ergodox_right_led_3_set(uint8_t n) {}
-void suspend_power_down_kb(void) {
-#ifdef LED_MATRIX_ENABLE
- send_led_suspend_state();
-#endif
- suspend_power_down_user();
-}
-
-void suspend_wakeup_init_kb(void) {
-#ifdef LED_MATRIX_ENABLE
- send_led_suspend_state();
-#endif
- suspend_wakeup_init_user();
-}
-
#ifdef SWAP_HANDS_ENABLE
__attribute__ ((weak))
const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
@@ -472,3 +362,19 @@ __attribute__((weak)) void st7565_task_user(void) {
}
}
#endif
+
+#if defined(SPLIT_KEYBOARD)
+void usart_master_init(SerialDriver **driver) {
+ PORTA->PCR[1] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(2);
+ PORTA->PCR[2] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(2);
+
+ // driver is set to SD1 in config.h
+}
+
+void usart_slave_init(SerialDriver **driver) {
+ PORTE->PCR[0] = PORTx_PCRn_PE | PORTx_PCRn_PS | PORTx_PCRn_PFE | PORTx_PCRn_MUX(3);
+ PORTE->PCR[1] = PORTx_PCRn_DSE | PORTx_PCRn_SRE | PORTx_PCRn_MUX(3);
+
+ *driver = &SD2;
+}
+#endif
diff --git a/keyboards/ergodox_infinity/led.c b/keyboards/ergodox_infinity/led.c
deleted file mode 100644
index 0b50247d7a..0000000000
--- a/keyboards/ergodox_infinity/led.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-Copyright 2012 Jun Wako <wakojun@gmail.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <hal.h>
-
-#include "led.h"
-
-
-void led_set(uint8_t usb_led) {
- //TODO: Add led emulation if there's no customized visualization
- (void)usb_led;
-}
diff --git a/keyboards/ergodox_infinity/matrix.c b/keyboards/ergodox_infinity/matrix.c
deleted file mode 100644
index 0fca56a979..0000000000
--- a/keyboards/ergodox_infinity/matrix.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
-Copyright 2016 Fred Sundvik <fsundvik@gmail.com>
-Jun Wako <wakojun@gmail.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-#include <hal.h>
-#include "timer.h"
-#include "wait.h"
-#include "print.h"
-#include "debug.h"
-#include "matrix.h"
-#include "keyboard.h"
-#include "serial_link/system/serial_link.h"
-
-
-/*
- * Infinity ErgoDox Pinusage:
- * Column pins are input with internal pull-down. Row pins are output and strobe with high.
- * Key is high or 1 when it turns on.
- *
- * col: { PTD1, PTD4, PTD5, PTD6, PTD7 }
- * row: { PTB2, PTB3, PTB18, PTB19, PTC0, PTC9, PTC10, PTC11, PTD0 }
- */
-/* matrix state(1:on, 0:off) */
-static matrix_row_t matrix[MATRIX_ROWS];
-static matrix_row_t matrix_debouncing[LOCAL_MATRIX_ROWS];
-static bool debouncing = false;
-static uint16_t debouncing_time = 0;
-
-
-void matrix_init(void)
-{
- /* Row(sense) */
- palSetPadMode(GPIOD, 1, PAL_MODE_INPUT_PULLDOWN);
- palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLDOWN);
- palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLDOWN);
- palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLDOWN);
- palSetPadMode(GPIOD, 7, PAL_MODE_INPUT_PULLDOWN);
-
- /* Column(strobe) */
- palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOB, 18, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOB, 19, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 10, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL);
- palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
-
- memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
- memset(matrix_debouncing, 0, LOCAL_MATRIX_ROWS * sizeof(matrix_row_t));
-
- matrix_init_quantum();
-}
-
-uint8_t matrix_scan(void)
-{
- for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
- matrix_row_t data = 0;
-
- // strobe row
- switch (row) {
- case 0: palSetPad(GPIOB, 2); break;
- case 1: palSetPad(GPIOB, 3); break;
- case 2: palSetPad(GPIOB, 18); break;
- case 3: palSetPad(GPIOB, 19); break;
- case 4: palSetPad(GPIOC, 0); break;
- case 5: palSetPad(GPIOC, 9); break;
- case 6: palSetPad(GPIOC, 10); break;
- case 7: palSetPad(GPIOC, 11); break;
- case 8: palSetPad(GPIOD, 0); break;
- }
-
- // need wait to settle pin state
- // if you wait too short, or have a too high update rate
- // the keyboard might freeze, or there might not be enough
- // processing power to update the LCD screen properly.
- // 20us, or two ticks at 100000Hz seems to be OK
- wait_us(20);
-
- // read col data: { PTD1, PTD4, PTD5, PTD6, PTD7 }
- data = ((palReadPort(GPIOD) & 0xF0) >> 3) |
- ((palReadPort(GPIOD) & 0x02) >> 1);
-
- // un-strobe row
- switch (row) {
- case 0: palClearPad(GPIOB, 2); break;
- case 1: palClearPad(GPIOB, 3); break;
- case 2: palClearPad(GPIOB, 18); break;
- case 3: palClearPad(GPIOB, 19); break;
- case 4: palClearPad(GPIOC, 0); break;
- case 5: palClearPad(GPIOC, 9); break;
- case 6: palClearPad(GPIOC, 10); break;
- case 7: palClearPad(GPIOC, 11); break;
- case 8: palClearPad(GPIOD, 0); break;
- }
-
- if (matrix_debouncing[row] != data) {
- matrix_debouncing[row] = data;
- debouncing = true;
- debouncing_time = timer_read();
- }
- }
-
- uint8_t offset = 0;
- if (is_serial_link_master() && !is_keyboard_left()) {
- offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS;
- }
-
- if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
- for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
- matrix[offset + row] = matrix_debouncing[row];
- }
- debouncing = false;
- }
- matrix_scan_quantum();
- return 1;
-}
-
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
- return (matrix[row] & (1<<col));
-}
-
-matrix_row_t matrix_get_row(uint8_t row)
-{
- return matrix[row];
-}
-
-void matrix_print(void)
-{
- xprintf("\nr/c 01234567\n");
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- xprintf("%X0: ", row);
- matrix_row_t data = matrix_get_row(row);
- for (int col = 0; col < MATRIX_COLS; col++) {
- if (data & (1<<col))
- xprintf("1");
- else
- xprintf("0");
- }
- xprintf("\n");
- }
-}
-
-void matrix_set_remote(matrix_row_t* rows, uint8_t index) {
- uint8_t offset = 0;
- if (is_keyboard_left()) {
- offset = LOCAL_MATRIX_ROWS * (index + 1);
- } else {
- offset = MATRIX_ROWS - LOCAL_MATRIX_ROWS * (index + 2);
- }
- for (int row = 0; row < LOCAL_MATRIX_ROWS; row++) {
- matrix[offset + row] = rows[row];
- }
-}
diff --git a/keyboards/ergodox_infinity/rules.mk b/keyboards/ergodox_infinity/rules.mk
index c7ff07d4ea..fbd52cd257 100644
--- a/keyboards/ergodox_infinity/rules.mk
+++ b/keyboards/ergodox_infinity/rules.mk
@@ -12,18 +12,17 @@ MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
COMMAND_ENABLE = yes # Commands for debug and configuration
-CUSTOM_MATRIX = yes # Custom matrix file for the ErgoDox EZ
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
UNICODE_ENABLE = yes # Unicode
SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard
-CUSTOM_MATRIX = yes # Custom matrix file
-SERIAL_LINK_ENABLE = yes
-
MIDI_ENABLE = no
RGBLIGHT_ENABLE = no
+SPLIT_KEYBOARD = yes
+SERIAL_DRIVER = usart
+
ST7565_ENABLE = yes
LED_MATRIX_ENABLE = yes
@@ -36,8 +35,4 @@ LCD_DRIVER = st7565
LCD_WIDTH = 128
LCD_HEIGHT = 32
-# project specific files
-SRC = matrix.c \
- led.c
-
LAYOUTS = ergodox
diff --git a/keyboards/ergodox_infinity/visualizer.c b/keyboards/ergodox_infinity/visualizer.c
index 4b16021abc..1ea891e830 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/>.
#include "visualizer_keyframes.h"
#include "lcd_keyframes.h"
#include "lcd_backlight_keyframes.h"
-#include "system/serial_link.h"
#include "default_animations.h"
static 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_
uint8_t new_index;
uint8_t old_index;
- if (is_serial_link_master()) {
+ if (is_keyboard_master()) {
new_index = get_led_index_master(user_data_new);
old_index = get_led_index_master(user_data_old);
}
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index fe7f1f0394..bcf258b260 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -459,7 +459,7 @@ void led_matrix_init(void) {
void led_matrix_set_suspend_state(bool state) {
#ifdef LED_DISABLE_WHEN_USB_SUSPENDED
- if (state) {
+ if (state && is_keyboard_master()) {
led_matrix_set_value_all(0); // turn off all LEDs when suspending
}
suspend_state = state;