1 #include "split_util.h"
6 #include "split_flags.h"
11 # include "tmk_core/common/eeprom.h"
12 # include "eeconfig.h"
15 volatile bool isLeftHand = true;
18 bool is_keyboard_left(void) {
20 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
21 setPinInput(SPLIT_HAND_PIN);
22 return readPin(SPLIT_HAND_PIN);
25 return eeprom_read_byte(EECONFIG_HANDEDNESS);
28 return !is_keyboard_master();
30 return is_keyboard_master();
36 bool is_keyboard_master(void)
39 static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
41 // only check once, as this is called often
42 if (usbstate == UNKNOWN)
44 USBCON |= (1 << OTGPADE); // enables VBUS pad
47 usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
50 return (usbstate == MASTER);
56 static void keyboard_master_setup(void) {
57 #if defined(USE_I2C) || defined(EH)
59 matrix_master_OLED_init ();
62 transport_master_init();
64 // For master the Backlight info needs to be sent on startup
65 // Otherwise the salve won't start with the proper info until an update
69 static void keyboard_slave_setup(void)
71 transport_slave_init();
74 // this code runs before the usb and keyboard is initialized
75 void matrix_setup(void)
77 isLeftHand = is_keyboard_left();
79 if (is_keyboard_master())
81 keyboard_master_setup();
85 keyboard_slave_setup();