1 #include "split_util.h"
10 # include "tmk_core/common/eeprom.h"
11 # include "eeconfig.h"
14 #if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
18 volatile bool isLeftHand = true;
21 bool is_keyboard_left(void) {
22 #if defined(SPLIT_HAND_PIN)
23 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
24 setPinInput(SPLIT_HAND_PIN);
25 return readPin(SPLIT_HAND_PIN);
26 #elif defined(EE_HANDS)
27 return eeprom_read_byte(EECONFIG_HANDEDNESS);
28 #elif defined(MASTER_RIGHT)
29 return !is_keyboard_master();
32 return is_keyboard_master();
35 bool is_keyboard_master(void)
38 static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
40 // only check once, as this is called often
41 if (usbstate == UNKNOWN)
43 USBCON |= (1 << OTGPADE); // enables VBUS pad
46 usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
49 return (usbstate == MASTER);
55 static void keyboard_master_setup(void) {
56 #if defined(USE_I2C) || defined(EH)
58 matrix_master_OLED_init ();
61 transport_master_init();
64 static void keyboard_slave_setup(void)
66 transport_slave_init();
69 // this code runs before the usb and keyboard is initialized
70 void matrix_setup(void)
72 isLeftHand = is_keyboard_left();
74 #if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
75 uint8_t num_rgb_leds_split[2] = RGBLED_SPLIT;
77 rgblight_set_clipping_range(0, num_rgb_leds_split[0]);
80 rgblight_set_clipping_range(num_rgb_leds_split[0], num_rgb_leds_split[1]);
84 if (is_keyboard_master())
86 keyboard_master_setup();
90 keyboard_slave_setup();