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);
39 // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c
40 #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
41 isLeftHand = !has_usb();
43 isLeftHand = has_usb();
49 static void keyboard_master_setup(void) {
50 #if defined(USE_I2C) || defined(EH)
53 matrix_master_OLED_init ();
59 // For master the Backlight info needs to be sent on startup
60 // Otherwise the salve won't start with the proper info until an update
64 static void keyboard_slave_setup(void) {
66 #if defined(USE_I2C) || defined(EH)
67 i2c_slave_init(SLAVE_I2C_ADDRESS);
74 USBCON |= (1 << OTGPADE); //enables VBUS pad
76 return (USBSTA & (1<<VBUS)); //checks state of VBUS
79 void split_keyboard_setup(void) {
83 keyboard_master_setup();
85 keyboard_slave_setup();
90 void keyboard_slave_loop(void) {
94 #ifdef RGBLIGHT_ENABLE
102 // Read Backlight Info
103 #ifdef BACKLIGHT_ENABLE
106 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
107 BACKLIT_DIRTY = false;
110 backlight_set(serial_m2s_buffer.backlight_level);
114 #ifdef RGBLIGHT_ENABLE
117 // Disable interupts (RGB data is big)
119 // Create new DWORD for RGB data
122 // Fill the new DWORD with the data that was sent over
123 uint8_t *dword_dat = (uint8_t *)(&dword);
124 for (int i = 0; i < 4; i++) {
125 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START+i];
128 // Update the RGB now with the new data and set RGB_DIRTY to false
129 rgblight_update_dword(dword);
131 // Re-enable interupts now that RGB is set
135 #ifdef RGBLIGHT_SPLIT
136 // Add serial implementation for RGB here
143 // this code runs before the usb and keyboard is initialized
144 void matrix_setup(void) {
145 split_keyboard_setup();
149 keyboard_slave_loop();