aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/config_options.md8
-rw-r--r--docs/feature_split_keyboard.md12
-rw-r--r--quantum/split_common/matrix.c4
-rw-r--r--quantum/split_common/split_util.c33
-rw-r--r--quantum/split_common/split_util.h1
5 files changed, 49 insertions, 9 deletions
diff --git a/docs/config_options.md b/docs/config_options.md
index 9e43f47c2..ec3d1a1c8 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -267,6 +267,14 @@ There are a few different ways to set handedness for split keyboards (listed in
267 * 4: about 26kbps 267 * 4: about 26kbps
268 * 5: about 20kbps 268 * 5: about 20kbps
269 269
270* `#define SPLIT_USB_DETECT`
271 * Detect (with timeout) USB connection when delegating master/slave
272 * Default behavior for ARM
273 * Required for AVR Teensy
274
275* `#define SPLIT_USB_TIMEOUT 2500`
276 * Maximum timeout when detecting master/slave when using `SPLIT_USB_DETECT`
277
270# The `rules.mk` File 278# The `rules.mk` File
271 279
272This is a [make](https://www.gnu.org/software/make/manual/make.html) file that is included by the top-level `Makefile`. It is used to set some information about the MCU that we will be compiling for as well as enabling and disabling certain features. 280This is a [make](https://www.gnu.org/software/make/manual/make.html) file that is included by the top-level `Makefile`. It is used to set some information about the MCU that we will be compiling for as well as enabling and disabling certain features.
diff --git a/docs/feature_split_keyboard.md b/docs/feature_split_keyboard.md
index 42dd838d0..efc65a4c7 100644
--- a/docs/feature_split_keyboard.md
+++ b/docs/feature_split_keyboard.md
@@ -190,6 +190,18 @@ This sets how many LEDs are directly connected to each controller. The first nu
190?> This setting implies that `RGBLIGHT_SPLIT` is enabled, and will forcibly enable it, if it's not. 190?> This setting implies that `RGBLIGHT_SPLIT` is enabled, and will forcibly enable it, if it's not.
191 191
192 192
193```c
194#define SPLIT_USB_DETECT
195```
196This option changes the startup behavior to detect an active USB connection when delegating master/slave. If this operation times out, then the half is assume to be a slave. This is the default behavior for ARM, and required for AVR Teensy boards (due to hardware limitations).
197
198?> This setting will stop the ability to demo using battery packs.
199
200```c
201#define SPLIT_USB_TIMEOUT 2500
202```
203This sets the maximum timeout when detecting master/slave when using `SPLIT_USB_DETECT`.
204
193## Additional Resources 205## Additional Resources
194 206
195Nicinabox has a [very nice and detailed guide](https://github.com/nicinabox/lets-split-guide) for the Let's Split keyboard, that covers most everything you need to know, including troubleshooting information. 207Nicinabox has a [very nice and detailed guide](https://github.com/nicinabox/lets-split-guide) for the Let's Split keyboard, that covers most everything you need to know, including troubleshooting information.
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 313f7830b..7176d0cc4 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -246,9 +246,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
246#endif 246#endif
247 247
248void matrix_init(void) { 248void matrix_init(void) {
249 debug_enable = true; 249 keyboard_split_setup();
250 debug_matrix = true;
251 debug_mouse = true;
252 250
253 // Set pinout for right half if pinout for that half is defined 251 // Set pinout for right half if pinout for that half is defined
254 if (!isLeftHand) { 252 if (!isLeftHand) {
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index d16a98977..8983861bc 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -14,8 +14,27 @@
14# include "rgblight.h" 14# include "rgblight.h"
15#endif 15#endif
16 16
17#ifndef SPLIT_USB_TIMEOUT
18# define SPLIT_USB_TIMEOUT 2500
19#endif
20
17volatile bool isLeftHand = true; 21volatile bool isLeftHand = true;
18 22
23bool waitForUsb(void) {
24 for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) {
25 // This will return true of a USB connection has been established
26#if defined(__AVR__)
27 if (UDADDR & _BV(ADDEN)) {
28#else
29 if (usbGetDriverStateI(&USBD1) == USB_ACTIVE) {
30#endif
31 return true;
32 }
33 wait_ms(100);
34 }
35 return false;
36}
37
19__attribute__((weak)) bool is_keyboard_left(void) { 38__attribute__((weak)) bool is_keyboard_left(void) {
20#if defined(SPLIT_HAND_PIN) 39#if defined(SPLIT_HAND_PIN)
21 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand 40 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
@@ -31,21 +50,23 @@ __attribute__((weak)) bool is_keyboard_left(void) {
31} 50}
32 51
33__attribute__((weak)) bool is_keyboard_master(void) { 52__attribute__((weak)) bool is_keyboard_master(void) {
34#ifdef __AVR__
35 static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN; 53 static enum { UNKNOWN, MASTER, SLAVE } usbstate = UNKNOWN;
36 54
37 // only check once, as this is called often 55 // only check once, as this is called often
38 if (usbstate == UNKNOWN) { 56 if (usbstate == UNKNOWN) {
57#if defined(SPLIT_USB_DETECT) || defined(PROTOCOL_CHIBIOS)
58 usbstate = waitForUsb() ? MASTER : SLAVE;
59#elif defined(__AVR__)
39 USBCON |= (1 << OTGPADE); // enables VBUS pad 60 USBCON |= (1 << OTGPADE); // enables VBUS pad
40 wait_us(5); 61 wait_us(5);
41 62
42 usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS 63 usbstate = (USBSTA & (1 << VBUS)) ? MASTER : SLAVE; // checks state of VBUS
64#else
65 usbstate = MASTER;
66#endif
43 } 67 }
44 68
45 return (usbstate == MASTER); 69 return (usbstate == MASTER);
46#else
47 return true;
48#endif
49} 70}
50 71
51static void keyboard_master_setup(void) { 72static void keyboard_master_setup(void) {
@@ -59,8 +80,8 @@ static void keyboard_master_setup(void) {
59 80
60static void keyboard_slave_setup(void) { transport_slave_init(); } 81static void keyboard_slave_setup(void) { transport_slave_init(); }
61 82
62// this code runs before the usb and keyboard is initialized 83// this code runs before the keyboard is fully initialized
63void matrix_setup(void) { 84void keyboard_split_setup(void) {
64 isLeftHand = is_keyboard_left(); 85 isLeftHand = is_keyboard_left();
65 86
66#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT) 87#if defined(RGBLIGHT_ENABLE) && defined(RGBLED_SPLIT)
diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h
index f41c77605..5d9c52340 100644
--- a/quantum/split_common/split_util.h
+++ b/quantum/split_common/split_util.h
@@ -8,3 +8,4 @@
8extern volatile bool isLeftHand; 8extern volatile bool isLeftHand;
9 9
10void matrix_master_OLED_init(void); 10void matrix_master_OLED_init(void);
11void keyboard_split_setup(void);