1 #include "split_util.h"
6 #include "split_flags.h"
10 # include "tmk_core/common/eeprom.h"
13 #ifdef BACKLIGHT_ENABLE
14 # include "backlight.h"
17 #if defined(USE_I2C) || defined(EH)
21 volatile bool isLeftHand = true;
23 volatile uint8_t setTries = 0;
25 static void setup_handedness(void) {
27 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
28 setPinInput(SPLIT_HAND_PIN);
29 isLeftHand = readPin(SPLIT_HAND_PIN);
32 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
35 isLeftHand = !has_usb();
37 isLeftHand = has_usb();
43 static void keyboard_master_setup(void) {
44 #if defined(USE_I2C) || defined(EH)
47 matrix_master_OLED_init ();
53 // For master the Backlight info needs to be sent on startup
54 // Otherwise the salve won't start with the proper info until an update
58 static void keyboard_slave_setup(void) {
60 #if defined(USE_I2C) || defined(EH)
61 i2c_slave_init(SLAVE_I2C_ADDRESS);
68 USBCON |= (1 << OTGPADE); //enables VBUS pad
70 return (USBSTA & (1<<VBUS)); //checks state of VBUS
73 void split_keyboard_setup(void) {
77 keyboard_master_setup();
79 keyboard_slave_setup();
84 void keyboard_slave_loop(void) {
88 #ifdef RGBLIGHT_ENABLE
96 // Read Backlight Info
97 #ifdef BACKLIGHT_ENABLE
100 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
101 BACKLIT_DIRTY = false;
104 backlight_set(serial_m2s_buffer.backlight_level);
108 #ifdef RGBLIGHT_ENABLE
111 // Disable interupts (RGB data is big)
113 // Create new DWORD for RGB data
116 // Fill the new DWORD with the data that was sent over
117 uint8_t *dword_dat = (uint8_t *)(&dword);
118 for (int i = 0; i < 4; i++) {
119 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START+i];
122 // Update the RGB now with the new data and set RGB_DIRTY to false
123 rgblight_update_dword(dword);
125 // Re-enable interupts now that RGB is set
129 #ifdef RGBLIGHT_SPLIT
130 // Add serial implementation for RGB here
137 // this code runs before the usb and keyboard is initialized
138 void matrix_setup(void) {
139 split_keyboard_setup();
143 keyboard_slave_loop();