X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=quantum%2Fsplit_common%2Fsplit_util.c;h=d7ed6989f63f6c356e5b7cebd2748064d6293d5f;hb=05990c9bda0ddbc0e622f12e88bec271958c864e;hp=13b09d5b815a774d936e1cf4d82d650507969b8b;hpb=a012113d636e3f23841c23343ae3f1d5b7452701;p=qmk_firmware.git diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 13b09d5b8..d7ed6989f 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -1,154 +1,93 @@ -#include -#include -#include -#include -#include -#include #include "split_util.h" #include "matrix.h" #include "keyboard.h" #include "config.h" #include "timer.h" -#include "split_flags.h" +#include "transport.h" +#include "quantum.h" -#ifdef RGBLIGHT_ENABLE -# include "rgblight.h" -#endif -#ifdef BACKLIGHT_ENABLE -# include "backlight.h" +#ifdef EE_HANDS +# include "tmk_core/common/eeprom.h" +# include "eeconfig.h" #endif -#ifdef SPLIT_HAND_PIN -# include "pincontrol.h" -#endif - -#if defined(USE_I2C) || defined(EH) -# include "i2c.h" -#else -# include "serial.h" +#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT) +#include "rgblight.h" #endif volatile bool isLeftHand = true; -volatile uint8_t setTries = 0; - -static void setup_handedness(void) { - #ifdef SPLIT_HAND_PIN +__attribute__((weak)) +bool is_keyboard_left(void) { + #if defined(SPLIT_HAND_PIN) // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand - pinMode(SPLIT_HAND_PIN, PinDirectionInput); - isLeftHand = digitalRead(SPLIT_HAND_PIN); - #else - #ifdef EE_HANDS - isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); - #else - // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c - #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) - isLeftHand = !has_usb(); - #else - isLeftHand = has_usb(); - #endif - #endif + setPinInput(SPLIT_HAND_PIN); + return readPin(SPLIT_HAND_PIN); + #elif defined(EE_HANDS) + return eeprom_read_byte(EECONFIG_HANDEDNESS); + #elif defined(MASTER_RIGHT) + return !is_keyboard_master(); #endif + + return is_keyboard_master(); } -static void keyboard_master_setup(void) { -#if defined(USE_I2C) || defined(EH) - i2c_master_init(); - #ifdef SSD1306OLED - matrix_master_OLED_init (); - #endif -#else - serial_master_init(); -#endif +__attribute__((weak)) +bool is_keyboard_master(void) +{ +#ifdef __AVR__ + static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN; - // For master the Backlight info needs to be sent on startup - // Otherwise the salve won't start with the proper info until an update - BACKLIT_DIRTY = true; -} + // only check once, as this is called often + if (usbstate == UNKNOWN) + { + USBCON |= (1 << OTGPADE); // enables VBUS pad + wait_us(5); -static void keyboard_slave_setup(void) { - timer_init(); -#if defined(USE_I2C) || defined(EH) - i2c_slave_init(SLAVE_I2C_ADDRESS); + usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS + } + + return (usbstate == MASTER); #else - serial_slave_init(); + return true; #endif } -bool has_usb(void) { - USBCON |= (1 << OTGPADE); //enables VBUS pad - _delay_us(5); - return (USBSTA & (1<