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();
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();
65 static void keyboard_slave_setup(void)
67 transport_slave_init();
70 // this code runs before the usb and keyboard is initialized
71 void matrix_setup(void)
73 isLeftHand = is_keyboard_left();
75 #if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
76 uint8_t num_rgb_leds_split[2] = RGBLED_SPLIT;
78 rgblight_set_clipping_range(0, num_rgb_leds_split[0]);
81 rgblight_set_clipping_range(num_rgb_leds_split[0], num_rgb_leds_split[1]);
85 if (is_keyboard_master())
87 keyboard_master_setup();
91 keyboard_slave_setup();