1 #include "split_util.h"
6 #include "split_flags.h"
9 #ifdef BACKLIGHT_ENABLE
10 # include "backlight.h"
13 #if defined(USE_I2C) || defined(EH)
17 volatile bool isLeftHand = true;
19 volatile uint8_t setTries = 0;
21 static void setup_handedness(void) {
23 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
24 setPinInput(SPLIT_HAND_PIN);
25 isLeftHand = readPin(SPLIT_HAND_PIN);
28 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
31 isLeftHand = !has_usb();
33 isLeftHand = has_usb();
39 static void keyboard_master_setup(void) {
40 #if defined(USE_I2C) || defined(EH)
43 matrix_master_OLED_init ();
49 // For master the Backlight info needs to be sent on startup
50 // Otherwise the salve won't start with the proper info until an update
54 static void keyboard_slave_setup(void) {
56 #if defined(USE_I2C) || defined(EH)
57 i2c_slave_init(SLAVE_I2C_ADDRESS);
64 USBCON |= (1 << OTGPADE); //enables VBUS pad
66 return (USBSTA & (1<<VBUS)); //checks state of VBUS
69 void split_keyboard_setup(void) {
73 keyboard_master_setup();
75 keyboard_slave_setup();
80 void keyboard_slave_loop(void) {
84 #ifdef RGBLIGHT_ENABLE
92 // Read Backlight Info
93 #ifdef BACKLIGHT_ENABLE
96 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
97 BACKLIT_DIRTY = false;
100 backlight_set(serial_m2s_buffer.backlight_level);
104 #ifdef RGBLIGHT_ENABLE
107 // Disable interupts (RGB data is big)
109 // Create new DWORD for RGB data
112 // Fill the new DWORD with the data that was sent over
113 uint8_t *dword_dat = (uint8_t *)(&dword);
114 for (int i = 0; i < 4; i++) {
115 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START+i];
118 // Update the RGB now with the new data and set RGB_DIRTY to false
119 rgblight_update_dword(dword);
121 // Re-enable interupts now that RGB is set
125 #ifdef RGBLIGHT_SPLIT
126 // Add serial implementation for RGB here
133 // this code runs before the usb and keyboard is initialized
134 void matrix_setup(void) {
135 split_keyboard_setup();
139 keyboard_slave_loop();