4 #include <avr/interrupt.h>
5 #include <util/delay.h>
6 #include <avr/eeprom.h>
7 #include "split_util.h"
12 #include "split_flags.h"
14 #ifdef BACKLIGHT_ENABLE
15 # include "backlight.h"
19 # include "pincontrol.h"
22 #if defined(USE_I2C) || defined(EH)
26 volatile bool isLeftHand = true;
28 volatile uint8_t setTries = 0;
30 static void setup_handedness(void) {
32 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
33 pinMode(SPLIT_HAND_PIN, PinDirectionInput);
34 isLeftHand = digitalRead(SPLIT_HAND_PIN);
37 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
40 isLeftHand = !has_usb();
42 isLeftHand = has_usb();
48 static void keyboard_master_setup(void) {
49 #if defined(USE_I2C) || defined(EH)
52 matrix_master_OLED_init ();
58 // For master the Backlight info needs to be sent on startup
59 // Otherwise the salve won't start with the proper info until an update
63 static void keyboard_slave_setup(void) {
65 #if defined(USE_I2C) || defined(EH)
66 i2c_slave_init(SLAVE_I2C_ADDRESS);
73 USBCON |= (1 << OTGPADE); //enables VBUS pad
75 return (USBSTA & (1<<VBUS)); //checks state of VBUS
78 void split_keyboard_setup(void) {
82 keyboard_master_setup();
84 keyboard_slave_setup();
89 void keyboard_slave_loop(void) {
93 #ifdef RGBLIGHT_ENABLE
101 // Read Backlight Info
102 #ifdef BACKLIGHT_ENABLE
105 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
106 BACKLIT_DIRTY = false;
109 backlight_set(serial_m2s_buffer.backlight_level);
113 #ifdef RGBLIGHT_ENABLE
116 // Disable interupts (RGB data is big)
118 // Create new DWORD for RGB data
121 // Fill the new DWORD with the data that was sent over
122 uint8_t *dword_dat = (uint8_t *)(&dword);
123 for (int i = 0; i < 4; i++) {
124 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START+i];
127 // Update the RGB now with the new data and set RGB_DIRTY to false
128 rgblight_update_dword(dword);
130 // Re-enable interupts now that RGB is set
134 #ifdef RGBLIGHT_SPLIT
135 // Add serial implementation for RGB here
142 // this code runs before the usb and keyboard is initialized
143 void matrix_setup(void) {
144 split_keyboard_setup();
148 keyboard_slave_loop();