summaryrefslogtreecommitdiff
path: root/keyboards/crkbd/split_util.c
diff options
context:
space:
mode:
authorKosuke Adachi2018-06-09 07:28:28 +0900
committerDrashna Jaelre2018-06-08 15:28:28 -0700
commit710937e4ef1e14d82261fc439aa6fcfcdbd64bf5 (patch)
tree6226a1d3027634af4b4508dce101ff938f356782 /keyboards/crkbd/split_util.c
parent300cf977c93b9b37a57643ddbfa8d0bd13b29e18 (diff)
Add corne keyboard (#3119)
* Fork from helix * Move rev2 to rev1 * Remove unused settings * Move split_util to outof rev * Setup KEYMAP for crkbd * Remove old image * Move keymaps directory and glcdfont.c * Remove AUDIO in keymap * Show keylog * Show keylogs * Show time log * Remove EISU/KANA * Use KEYMAP_kc * Remove iota_gfx_record_user wrapping * Remove unused settings for layer * Add keylogger.c * Fix uppercase letters to lower * Add timelogger.c * Default RGBLED_NUM = 27 * Remove unused setting * Add mode icon reader * Add matrix_write_ln * Add layer_state_reader * Move to lib directory * Rename functions * Add host_led_state_reader * Add logo_reader * Cleaning of iota_gfx_task * Fix bugs and add key defines * Remove unnecessary comments * Update crkbd readme * Move libs to lib directories * Rename KEYMAP to LAYOUT
Diffstat (limited to 'keyboards/crkbd/split_util.c')
-rw-r--r--keyboards/crkbd/split_util.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/keyboards/crkbd/split_util.c b/keyboards/crkbd/split_util.c
new file mode 100644
index 000000000..8bc064174
--- /dev/null
+++ b/keyboards/crkbd/split_util.c
@@ -0,0 +1,71 @@
+#include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/power.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/eeprom.h>
+#include "split_util.h"
+#include "matrix.h"
+#include "keyboard.h"
+#include "config.h"
+
+#ifdef USE_MATRIX_I2C
+# include "i2c.h"
+#else
+# include "serial.h"
+#endif
+
+volatile bool isLeftHand = true;
+
+static void setup_handedness(void) {
+ #ifdef EE_HANDS
+ isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);
+ #else
+ // I2C_MASTER_RIGHT is deprecated, use MASTER_RIGHT instead, since this works for both serial and i2c
+ #if defined(I2C_MASTER_RIGHT) || defined(MASTER_RIGHT)
+ isLeftHand = !has_usb();
+ #else
+ isLeftHand = has_usb();
+ #endif
+ #endif
+}
+
+static void keyboard_master_setup(void) {
+
+#ifdef USE_MATRIX_I2C
+ i2c_master_init();
+#else
+ serial_master_init();
+#endif
+}
+
+static void keyboard_slave_setup(void) {
+
+#ifdef USE_MATRIX_I2C
+ i2c_slave_init(SLAVE_I2C_ADDRESS);
+#else
+ serial_slave_init();
+#endif
+}
+
+bool has_usb(void) {
+ USBCON |= (1 << OTGPADE); //enables VBUS pad
+ _delay_us(5);
+ return (USBSTA & (1<<VBUS)); //checks state of VBUS
+}
+
+void split_keyboard_setup(void) {
+ setup_handedness();
+
+ if (has_usb()) {
+ keyboard_master_setup();
+ } else {
+ keyboard_slave_setup();
+ }
+ sei();
+}
+
+// this code runs before the usb and keyboard is initialized
+void matrix_setup(void) {
+ split_keyboard_setup();
+}