aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/config_options.md5
-rw-r--r--docs/feature_split_keyboard.md18
-rw-r--r--quantum/split_common/split_util.c24
3 files changed, 46 insertions, 1 deletions
diff --git a/docs/config_options.md b/docs/config_options.md
index ab26fd46c..21c9972e0 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -250,7 +250,10 @@ There are a few different ways to set handedness for split keyboards (listed in
250* `#define SPLIT_HAND_PIN B7` 250* `#define SPLIT_HAND_PIN B7`
251 * For using high/low pin to determine handedness, low = right hand, high = left hand. Replace `B7` with the pin you are using. This is optional, and if you leave `SPLIT_HAND_PIN` undefined, then you can still use the EE_HANDS method or MASTER_LEFT / MASTER_RIGHT defines like the stock Let's Split uses. 251 * For using high/low pin to determine handedness, low = right hand, high = left hand. Replace `B7` with the pin you are using. This is optional, and if you leave `SPLIT_HAND_PIN` undefined, then you can still use the EE_HANDS method or MASTER_LEFT / MASTER_RIGHT defines like the stock Let's Split uses.
252 252
253* `#define EE_HANDS` (only works if `SPLIT_HAND_PIN` is not defined) 253* `#define SPLIT_HAND_MATRIX_GRID <out_pin>,<in_pin>`
254 * The handedness is determined by using the intersection of the keyswitches in the key matrix, which does not exist. Normally, when this intersection is shorted (level low), it is considered left. If you define `#define SPLIT_HAND_MATRIX_GRID_LOW_IS_RIGHT`, it is determined to be right when the level is low.
255
256* `#define EE_HANDS` (only works if `SPLIT_HAND_PIN` and `SPLIT_HAND_MATRIX_GRID` are not defined)
254 * Reads the handedness value stored in the EEPROM after `eeprom-lefthand.eep`/`eeprom-righthand.eep` has been flashed to their respective halves. 257 * Reads the handedness value stored in the EEPROM after `eeprom-lefthand.eep`/`eeprom-righthand.eep` has been flashed to their respective halves.
255 258
256* `#define MASTER_RIGHT` 259* `#define MASTER_RIGHT`
diff --git a/docs/feature_split_keyboard.md b/docs/feature_split_keyboard.md
index 63374a804..ce470b996 100644
--- a/docs/feature_split_keyboard.md
+++ b/docs/feature_split_keyboard.md
@@ -90,6 +90,24 @@ You can configure the firmware to read a pin on the controller to determine hand
90 90
91This will read the specified pin. If it's high, then the controller assumes it is the left hand, and if it's low, it's assumed to be the right side. 91This will read the specified pin. If it's high, then the controller assumes it is the left hand, and if it's low, it's assumed to be the right side.
92 92
93#### Handedness by Matrix Pin
94
95You can configure the firmware to read key matrix pins on the controller to determine handedness. To do this, add the following to your `config.h` file:
96
97```c
98#define SPLIT_HAND_MATRIX_GRID D0, F1
99```
100
101The first pin is the output pin and the second is the input pin.
102
103Some keyboards have unused intersections in the key matrix. This setting uses one of these unused intersections to determine the handness.
104
105Normally, when a diode is connected to an intersection, it is judged to be left. If you add the following definition, it will be judged to be right.
106
107```c
108#define SPLIT_HAND_MATRIX_GRID_LOW_IS_RIGHT
109```
110
93#### Handedness by EEPROM 111#### Handedness by EEPROM
94 112
95This method sets the keyboard's handedness by setting a flag in the persistent storage (`EEPROM`). This is checked when the controller first starts up, and determines what half the keyboard is, and how to orient the keyboard layout. 113This method sets the keyboard's handedness by setting a flag in the persistent storage (`EEPROM`). This is checked when the controller first starts up, and determines what half the keyboard is, and how to orient the keyboard layout.
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index afcd9d2aa..90735eda4 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -5,6 +5,7 @@
5#include "timer.h" 5#include "timer.h"
6#include "transport.h" 6#include "transport.h"
7#include "quantum.h" 7#include "quantum.h"
8#include "wait.h"
8 9
9#ifdef PROTOCOL_LUFA 10#ifdef PROTOCOL_LUFA
10# include <LUFA/Drivers/USB/USB.h> 11# include <LUFA/Drivers/USB/USB.h>
@@ -82,11 +83,34 @@ static inline bool usbIsActive(void) {
82static inline bool usbIsActive(void) { return true; } 83static inline bool usbIsActive(void) { return true; }
83#endif 84#endif
84 85
86#ifdef SPLIT_HAND_MATRIX_GRID
87void matrix_io_delay(void);
88
89static uint8_t peek_matrix_intersection(pin_t out_pin, pin_t in_pin) {
90 setPinInputHigh(in_pin);
91 setPinOutput(out_pin);
92 writePinLow(out_pin);
93 // It's almost unnecessary, but wait until it's down to low, just in case.
94 wait_us(1);
95 uint8_t pin_state = readPin(in_pin);
96 // Set out_pin to a setting that is less susceptible to noise.
97 setPinInputHigh(out_pin);
98 matrix_io_delay(); // Wait for the pull-up to go HIGH.
99 return pin_state;
100}
101#endif
102
85__attribute__((weak)) bool is_keyboard_left(void) { 103__attribute__((weak)) bool is_keyboard_left(void) {
86#if defined(SPLIT_HAND_PIN) 104#if defined(SPLIT_HAND_PIN)
87 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand 105 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
88 setPinInput(SPLIT_HAND_PIN); 106 setPinInput(SPLIT_HAND_PIN);
89 return readPin(SPLIT_HAND_PIN); 107 return readPin(SPLIT_HAND_PIN);
108#elif defined(SPLIT_HAND_MATRIX_GRID)
109# ifdef SPLIT_HAND_MATRIX_GRID_LOW_IS_RIGHT
110 return peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID);
111# else
112 return !peek_matrix_intersection(SPLIT_HAND_MATRIX_GRID);
113# endif
90#elif defined(EE_HANDS) 114#elif defined(EE_HANDS)
91 return eeconfig_read_handedness(); 115 return eeconfig_read_handedness();
92#elif defined(MASTER_RIGHT) 116#elif defined(MASTER_RIGHT)