diff options
Diffstat (limited to 'keyboards/lily58/rev1/split_util.c')
| -rwxr-xr-x | keyboards/lily58/rev1/split_util.c | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/keyboards/lily58/rev1/split_util.c b/keyboards/lily58/rev1/split_util.c deleted file mode 100755 index 316c1c389..000000000 --- a/keyboards/lily58/rev1/split_util.c +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | #include <avr/io.h> | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | #include <avr/power.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/delay.h> | ||
| 6 | #include <avr/eeprom.h> | ||
| 7 | #include "split_util.h" | ||
| 8 | #include "matrix.h" | ||
| 9 | #include "keyboard.h" | ||
| 10 | #include "wait.h" | ||
| 11 | |||
| 12 | #ifdef USE_MATRIX_I2C | ||
| 13 | # include "i2c.h" | ||
| 14 | #else | ||
| 15 | # include "split_scomm.h" | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifndef SPLIT_USB_TIMEOUT | ||
| 19 | # define SPLIT_USB_TIMEOUT 2500 | ||
| 20 | #endif | ||
| 21 | |||
| 22 | volatile bool isLeftHand = true; | ||
| 23 | |||
| 24 | bool waitForUsb(void) { | ||
| 25 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) { | ||
| 26 | // This will return true of a USB connection has been established | ||
| 27 | if (UDADDR & _BV(ADDEN)) { | ||
| 28 | return true; | ||
| 29 | } | ||
| 30 | wait_ms(100); | ||
| 31 | } | ||
| 32 | |||
| 33 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow | ||
| 34 | (USBCON &= ~(_BV(USBE) | _BV(OTGPADE))); | ||
| 35 | |||
| 36 | return false; | ||
| 37 | } | ||
| 38 | |||
| 39 | __attribute__((weak)) bool is_keyboard_left(void) { | ||
| 40 | #if defined(SPLIT_HAND_PIN) | ||
| 41 | // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand | ||
| 42 | setPinInput(SPLIT_HAND_PIN); | ||
| 43 | return readPin(SPLIT_HAND_PIN); | ||
| 44 | #elif defined(EE_HANDS) | ||
| 45 | return eeconfig_read_handedness(); | ||
| 46 | #elif defined(MASTER_RIGHT) | ||
| 47 | return !has_usb(); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | return has_usb(); | ||
| 51 | } | ||
| 52 | |||
| 53 | __attribute__((weak)) bool has_usb(void) { | ||
| 54 | static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN; | ||
| 55 | |||
| 56 | // only check once, as this is called often | ||
| 57 | if (usbstate == UNKNOWN) { | ||
| 58 | #if defined(SPLIT_USB_DETECT) | ||
| 59 | usbstate = waitForUsb() ? MASTER : SLAVE; | ||
| 60 | #elif defined(__AVR__) | ||
| 61 | USBCON |= (1 << OTGPADE); // enables VBUS pad | ||
| 62 | wait_us(5); | ||
| 63 | |||
| 64 | usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS | ||
| 65 | #else | ||
| 66 | usbstate = MASTER; | ||
| 67 | #endif | ||
| 68 | } | ||
| 69 | |||
| 70 | return (usbstate == MASTER); | ||
| 71 | } | ||
| 72 | |||
| 73 | static void keyboard_master_setup(void) { | ||
| 74 | |||
| 75 | #ifdef USE_MATRIX_I2C | ||
| 76 | i2c_master_init(); | ||
| 77 | #else | ||
| 78 | serial_master_init(); | ||
| 79 | #endif | ||
| 80 | } | ||
| 81 | |||
| 82 | static void keyboard_slave_setup(void) { | ||
| 83 | |||
| 84 | #ifdef USE_MATRIX_I2C | ||
| 85 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
| 86 | #else | ||
| 87 | serial_slave_init(); | ||
| 88 | #endif | ||
| 89 | } | ||
| 90 | |||
| 91 | void split_keyboard_setup(void) { | ||
| 92 | isLeftHand = is_keyboard_left(); | ||
| 93 | |||
| 94 | if (has_usb()) { | ||
| 95 | keyboard_master_setup(); | ||
| 96 | } else { | ||
| 97 | keyboard_slave_setup(); | ||
| 98 | } | ||
| 99 | sei(); | ||
| 100 | } | ||
