]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/sol/rev1/split_util.c
Keyboard: Add new keyboard "Sol" from RGBKB (#4497)
[qmk_firmware.git] / keyboards / sol / rev1 / split_util.c
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 "serial.h"
11
12 volatile bool isLeftHand = true;
13
14 static void setup_handedness(void) {
15   #ifdef EE_HANDS
16     isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
17   #else
18     #if defined(MASTER_RIGHT)
19       isLeftHand = !has_usb();
20     #else
21       isLeftHand = has_usb();
22     #endif
23   #endif
24 }
25
26 static void keyboard_master_setup(void) {
27     serial_master_init();
28 }
29
30 static void keyboard_slave_setup(void) {
31     serial_slave_init();
32 }
33
34 bool has_usb(void) {
35    USBCON |= (1 << OTGPADE); //enables VBUS pad
36    _delay_us(5);
37    return (USBSTA & (1<<VBUS));  //checks state of VBUS
38 }
39
40 void split_keyboard_setup(void) {
41    setup_handedness();
42
43    if (has_usb()) {
44       keyboard_master_setup();
45    } else {
46       keyboard_slave_setup();
47    }
48    sei();
49 }
50
51 // this code runs before the usb and keyboard is initialized
52 void matrix_setup(void) {
53     split_keyboard_setup();
54 }