Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Ergodox Infinity over to split_common #13481

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions keyboards/ergodox_infinity/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably because it's based on the ergodox (OG), which has it's matrix rotated 90 degrees. So it's probably the same here.

That said... if that's the case, it may be worth using the eager per row debounce algo for the board, if each row can only be used by one finger at a time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I referred to here was the fact that the rows (as taken from the old custom matrix.c) are named columns in the schematic, and vice versa. I left it in this state to avoid having to rewrite all the LAYOUT defines.

I've actually tried using the eager_pr debounce algo in the past (I did some work last year to move over the Infinity to the common debounce handling, but ended up not submitting it), mostly for parity with the EZ I use at work, and actually got quite a lot of bouncing keys with that, so I went back to defer_g (which is the main reason I never submitted a PR, it didn't really add any value).

I'm currently using the defer_pk algo on my Infinity, for no particular reason other than having lots of RAM to spare. 😎

#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
Expand Down Expand Up @@ -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.
Expand Down
126 changes: 16 additions & 110 deletions keyboards/ergodox_infinity/ergodox_infinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {}
Expand All @@ -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] = {
Expand Down Expand Up @@ -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
172 changes: 0 additions & 172 deletions keyboards/ergodox_infinity/matrix.c

This file was deleted.

10 changes: 4 additions & 6 deletions keyboards/ergodox_infinity/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +36,6 @@ LCD_WIDTH = 128
LCD_HEIGHT = 32

# project specific files
SRC = matrix.c \
led.c
SRC = led.c
firetech marked this conversation as resolved.
Show resolved Hide resolved

LAYOUTS = ergodox
Loading