diff options
| -rw-r--r-- | keyboards/helix/rev2/matrix.c | 5 | ||||
| -rw-r--r-- | keyboards/helix/rev2/split_util.c | 80 |
2 files changed, 60 insertions, 25 deletions
diff --git a/keyboards/helix/rev2/matrix.c b/keyboards/helix/rev2/matrix.c index 322959dbb..70a6cb0a5 100644 --- a/keyboards/helix/rev2/matrix.c +++ b/keyboards/helix/rev2/matrix.c | |||
| @@ -95,9 +95,8 @@ uint8_t matrix_cols(void) | |||
| 95 | 95 | ||
| 96 | void matrix_init(void) | 96 | void matrix_init(void) |
| 97 | { | 97 | { |
| 98 | debug_enable = true; | 98 | split_keyboard_setup(); |
| 99 | debug_matrix = true; | 99 | |
| 100 | debug_mouse = true; | ||
| 101 | // initialize row and col | 100 | // initialize row and col |
| 102 | unselect_rows(); | 101 | unselect_rows(); |
| 103 | init_cols(); | 102 | init_cols(); |
diff --git a/keyboards/helix/rev2/split_util.c b/keyboards/helix/rev2/split_util.c index e1ff8b437..89df43e27 100644 --- a/keyboards/helix/rev2/split_util.c +++ b/keyboards/helix/rev2/split_util.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "split_util.h" | 7 | #include "split_util.h" |
| 8 | #include "matrix.h" | 8 | #include "matrix.h" |
| 9 | #include "keyboard.h" | 9 | #include "keyboard.h" |
| 10 | #include "wait.h" | ||
| 10 | 11 | ||
| 11 | #ifdef USE_MATRIX_I2C | 12 | #ifdef USE_MATRIX_I2C |
| 12 | # include "i2c.h" | 13 | # include "i2c.h" |
| @@ -14,19 +15,64 @@ | |||
| 14 | # include "split_scomm.h" | 15 | # include "split_scomm.h" |
| 15 | #endif | 16 | #endif |
| 16 | 17 | ||
| 18 | #ifdef EE_HANDS | ||
| 19 | # include "eeconfig.h" | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifndef SPLIT_USB_TIMEOUT | ||
| 23 | #define SPLIT_USB_TIMEOUT 2500 | ||
| 24 | #endif | ||
| 25 | |||
| 17 | volatile bool isLeftHand = true; | 26 | volatile bool isLeftHand = true; |
| 18 | 27 | ||
| 19 | static void setup_handedness(void) { | 28 | bool waitForUsb(void) { |
| 20 | #ifdef EE_HANDS | 29 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) { |
| 21 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | 30 | // This will return true of a USB connection has been established |
| 22 | #else | 31 | if (UDADDR & _BV(ADDEN)) { |
| 23 | // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c | 32 | return true; |
| 24 | #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) | 33 | } |
| 25 | isLeftHand = !has_usb(); | 34 | wait_ms(100); |
| 26 | #else | 35 | } |
| 27 | isLeftHand = has_usb(); | 36 | |
| 28 | #endif | 37 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow |
| 29 | #endif | 38 | (USBCON &= ~(_BV(USBE) | _BV(OTGPADE))); |
| 39 | |||
| 40 | return false; | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | __attribute__((weak)) bool is_keyboard_left(void) { | ||
| 45 | #if defined(SPLIT_HAND_PIN) | ||
| 46 | // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand | ||
| 47 | setPinInput(SPLIT_HAND_PIN); | ||
| 48 | return readPin(SPLIT_HAND_PIN); | ||
| 49 | #elif defined(EE_HANDS) | ||
| 50 | return eeconfig_read_handedness(); | ||
| 51 | #elif defined(MASTER_RIGHT) | ||
| 52 | return !has_usb(); | ||
| 53 | #endif | ||
| 54 | |||
| 55 | return has_usb(); | ||
| 56 | } | ||
| 57 | |||
| 58 | __attribute__((weak)) bool has_usb(void) { | ||
| 59 | static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN; | ||
| 60 | |||
| 61 | // only check once, as this is called often | ||
| 62 | if (usbstate == UNKNOWN) { | ||
| 63 | #if defined(SPLIT_USB_DETECT) | ||
| 64 | usbstate = waitForUsb() ? MASTER : SLAVE; | ||
| 65 | #elif defined(__AVR__) | ||
| 66 | USBCON |= (1 << OTGPADE); // enables VBUS pad | ||
| 67 | wait_us(5); | ||
| 68 | |||
| 69 | usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS | ||
| 70 | #else | ||
| 71 | usbstate = MASTER; | ||
| 72 | #endif | ||
| 73 | } | ||
| 74 | |||
| 75 | return (usbstate == MASTER); | ||
| 30 | } | 76 | } |
| 31 | 77 | ||
| 32 | static void keyboard_master_setup(void) { | 78 | static void keyboard_master_setup(void) { |
| @@ -47,14 +93,8 @@ static void keyboard_slave_setup(void) { | |||
| 47 | #endif | 93 | #endif |
| 48 | } | 94 | } |
| 49 | 95 | ||
| 50 | bool has_usb(void) { | ||
| 51 | USBCON |= (1 << OTGPADE); //enables VBUS pad | ||
| 52 | _delay_us(5); | ||
| 53 | return (USBSTA & (1<<VBUS)); //checks state of VBUS | ||
| 54 | } | ||
| 55 | |||
| 56 | void split_keyboard_setup(void) { | 96 | void split_keyboard_setup(void) { |
| 57 | setup_handedness(); | 97 | isLeftHand = is_keyboard_left(); |
| 58 | 98 | ||
| 59 | if (has_usb()) { | 99 | if (has_usb()) { |
| 60 | keyboard_master_setup(); | 100 | keyboard_master_setup(); |
| @@ -64,7 +104,3 @@ void split_keyboard_setup(void) { | |||
| 64 | sei(); | 104 | sei(); |
| 65 | } | 105 | } |
| 66 | 106 | ||
| 67 | // this code runs before the usb and keyboard is initialized | ||
| 68 | void matrix_setup(void) { | ||
| 69 | split_keyboard_setup(); | ||
| 70 | } | ||
