Skip to content

Commit

Permalink
Switch Ergodox Infinity over to split_common (qmk#13481)
Browse files Browse the repository at this point in the history
  • Loading branch information
firetech authored and nhongooi committed Dec 5, 2021
1 parent 6bd37bf commit e06fde6
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 323 deletions.
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
#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
26 changes: 0 additions & 26 deletions keyboards/ergodox_infinity/led.c

This file was deleted.

172 changes: 0 additions & 172 deletions keyboards/ergodox_infinity/matrix.c

This file was deleted.

Loading

0 comments on commit e06fde6

Please sign in to comment.