aboutsummaryrefslogtreecommitdiff
path: root/keyboards/helix/pico/split_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/helix/pico/split_util.c')
-rw-r--r--keyboards/helix/pico/split_util.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/keyboards/helix/pico/split_util.c b/keyboards/helix/pico/split_util.c
deleted file mode 100644
index c77e63f33..000000000
--- a/keyboards/helix/pico/split_util.c
+++ /dev/null
@@ -1,104 +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 "serial.h"
16#endif
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
26volatile bool isLeftHand = true;
27
28bool waitForUsb(void) {
29 for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) {
30 // This will return true of a USB connection has been established
31 if (UDADDR & _BV(ADDEN)) {
32 return true;
33 }
34 wait_ms(100);
35 }
36
37 // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
38 (USBCON &= ~(_BV(USBE) | _BV(OTGPADE)));
39
40 return false;
41}
42
43bool is_keyboard_left(void) {
44#if defined(SPLIT_HAND_PIN)
45 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
46 setPinInput(SPLIT_HAND_PIN);
47 return readPin(SPLIT_HAND_PIN);
48#elif defined(EE_HANDS)
49 return eeconfig_read_handedness();
50#elif defined(MASTER_RIGHT)
51 return !is_helix_master();
52#endif
53
54 return is_helix_master();
55}
56
57bool is_helix_master(void) {
58 static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
59
60 // only check once, as this is called often
61 if (usbstate == UNKNOWN) {
62#if defined(SPLIT_USB_DETECT)
63 usbstate = waitForUsb() ? MASTER : SLAVE;
64#elif defined(__AVR__)
65 USBCON |= (1 << OTGPADE); // enables VBUS pad
66 wait_us(5);
67
68 usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
69#else
70 usbstate = MASTER;
71#endif
72 }
73
74 return (usbstate == MASTER);
75 }
76
77static void keyboard_master_setup(void) {
78
79#ifdef USE_MATRIX_I2C
80 i2c_master_init();
81#else
82 serial_master_init();
83#endif
84}
85
86static void keyboard_slave_setup(void) {
87
88#ifdef USE_MATRIX_I2C
89 i2c_slave_init(SLAVE_I2C_ADDRESS);
90#else
91 serial_slave_init();
92#endif
93}
94
95void split_keyboard_setup(void) {
96 isLeftHand = is_keyboard_left();
97
98 if (is_helix_master()) {
99 keyboard_master_setup();
100 } else {
101 keyboard_slave_setup();
102 }
103 sei();
104}