diff options
Diffstat (limited to 'keyboards/helix/pico/split_util.c')
-rw-r--r-- | keyboards/helix/pico/split_util.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/keyboards/helix/pico/split_util.c b/keyboards/helix/pico/split_util.c new file mode 100644 index 000000000..beb39fa00 --- /dev/null +++ b/keyboards/helix/pico/split_util.c | |||
@@ -0,0 +1,70 @@ | |||
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 | |||
11 | #ifdef USE_MATRIX_I2C | ||
12 | # include "i2c.h" | ||
13 | #else | ||
14 | # include "serial.h" | ||
15 | #endif | ||
16 | |||
17 | volatile bool isLeftHand = true; | ||
18 | |||
19 | static void setup_handedness(void) { | ||
20 | #ifdef EE_HANDS | ||
21 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | ||
22 | #else | ||
23 | // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c | ||
24 | #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT) | ||
25 | isLeftHand = !has_usb(); | ||
26 | #else | ||
27 | isLeftHand = has_usb(); | ||
28 | #endif | ||
29 | #endif | ||
30 | } | ||
31 | |||
32 | static void keyboard_master_setup(void) { | ||
33 | |||
34 | #ifdef USE_MATRIX_I2C | ||
35 | i2c_master_init(); | ||
36 | #else | ||
37 | serial_master_init(); | ||
38 | #endif | ||
39 | } | ||
40 | |||
41 | static void keyboard_slave_setup(void) { | ||
42 | |||
43 | #ifdef USE_MATRIX_I2C | ||
44 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
45 | #else | ||
46 | serial_slave_init(); | ||
47 | #endif | ||
48 | } | ||
49 | |||
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) { | ||
57 | setup_handedness(); | ||
58 | |||
59 | if (has_usb()) { | ||
60 | keyboard_master_setup(); | ||
61 | } else { | ||
62 | keyboard_slave_setup(); | ||
63 | } | ||
64 | sei(); | ||
65 | } | ||
66 | |||
67 | // this code runs before the usb and keyboard is initialized | ||
68 | void matrix_setup(void) { | ||
69 | split_keyboard_setup(); | ||
70 | } | ||