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 RGBLIGHT_ENABLE
15 # include "rgblight.h"
17 #ifdef BACKLIGHT_ENABLE
18 # include "backlight.h"
22 # include "pincontrol.h"
25 #if defined(USE_I2C) || defined(EH)
31 volatile bool isLeftHand = true;
33 volatile uint8_t setTries = 0;
35 static void setup_handedness(void) {
37 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
38 pinMode(SPLIT_HAND_PIN, PinDirectionInput);
39 isLeftHand = digitalRead(SPLIT_HAND_PIN);
42 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
44 // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c
45 #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
46 isLeftHand = !has_usb();
48 isLeftHand = has_usb();
54 static void keyboard_master_setup(void) {
55 #if defined(USE_I2C) || defined(EH)
58 matrix_master_OLED_init ();
64 // For master the Backlight info needs to be sent on startup
65 // Otherwise the salve won't start with the proper info until an update
69 static void keyboard_slave_setup(void) {
71 #if defined(USE_I2C) || defined(EH)
72 i2c_slave_init(SLAVE_I2C_ADDRESS);
79 USBCON |= (1 << OTGPADE); //enables VBUS pad
81 return (USBSTA & (1<<VBUS)); //checks state of VBUS
84 void split_keyboard_setup(void) {
88 keyboard_master_setup();
90 keyboard_slave_setup();
95 void keyboard_slave_loop(void) {
99 #ifdef RGBLIGHT_ENABLE
107 // Read Backlight Info
108 #ifdef BACKLIGHT_ENABLE
111 backlight_set(i2c_slave_buffer[I2C_BACKLIT_START]);
112 BACKLIT_DIRTY = false;
115 backlight_set(serial_master_buffer[SERIAL_BACKLIT_START]);
119 #ifdef RGBLIGHT_ENABLE
122 // Disable interupts (RGB data is big)
124 // Create new DWORD for RGB data
127 // Fill the new DWORD with the data that was sent over
128 uint8_t *dword_dat = (uint8_t *)(&dword);
129 for (int i = 0; i < 4; i++) {
130 dword_dat[i] = i2c_slave_buffer[I2C_RGB_START+i];
133 // Update the RGB now with the new data and set RGB_DIRTY to false
134 rgblight_update_dword(dword);
136 // Re-enable interupts now that RGB is set
140 // Add serial implementation for RGB here
146 // this code runs before the usb and keyboard is initialized
147 void matrix_setup(void) {
148 split_keyboard_setup();
152 keyboard_slave_loop();