Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify split_common significantly #4772

Merged
merged 21 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,32 @@ QUANTUM_SRC:= \
$(QUANTUM_DIR)/keymap_common.c \
$(QUANTUM_DIR)/keycode_config.c

ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
ifneq ($(strip $(CUSTOM_MATRIX)), yes)
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c
# Do not use $(QUANTUM_DIR)/matrix.c.
CUSTOM_MATRIX=yes
# Include the standard or split matrix code if needed
ifneq ($(strip $(CUSTOM_MATRIX)), yes)
ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c
else
QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
endif
endif

# Include the standard debounce code if needed
ifneq ($(strip $(CUSTOM_DEBOUNCE)), yes)
QUANTUM_SRC += $(QUANTUM_DIR)/debounce.c
endif

ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
OPT_DEFS += -DSPLIT_KEYBOARD

# Include files used by all split keyboards
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/split_flags.c \
$(QUANTUM_DIR)/split_common/split_util.c
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/i2c.c
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/serial.c
COMMON_VPATH += $(QUANTUM_PATH)/split_common
endif
$(QUANTUM_DIR)/split_common/split_util.c

ifneq ($(strip $(CUSTOM_MATRIX)), yes)
QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
# Determine which (if any) transport files are required
ifneq ($(strip $(SPLIT_TRANSPORT)), custom)
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/transport.c
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/i2c.c \
$(QUANTUM_DIR)/split_common/serial.c
endif
COMMON_VPATH += $(QUANTUM_PATH)/split_common
endif
11 changes: 9 additions & 2 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ If you define these options you will enable the associated feature, which may in
* Breaks any Tap Toggle functionality (`TT` or the One Shot Tap Toggle)
* `#define LEADER_TIMEOUT 300`
* how long before the leader key times out
* If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped.
* If you're having issues finishing the sequence before it times out, you may need to increase the timeout setting. Or you may want to enable the `LEADER_PER_KEY_TIMING` option, which resets the timeout after each key is tapped.
* `#define LEADER_PER_KEY_TIMING`
* sets the timer for leader key chords to run on each key press rather than overall
* `#define LEADER_KEY_STRICT_KEY_PROCESSING`
Expand Down Expand Up @@ -197,6 +197,9 @@ If you define these options you will enable the associated feature, which may in

Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk

* `SPLIT_TRANSPORT = custom`
* Allows replacing the standard split communication routines with a custom one. ARM based split keyboards must use this at present.

### Setting Handedness

One thing to remember, the side that the USB port is plugged into is always the master half. The side not plugged into USB is the slave.
Expand All @@ -208,7 +211,7 @@ There are a few different ways to set handedness for split keyboards (listed in
3. Set `MASTER_RIGHT`: Half that is plugged into the USB port is determined to be the master and right half (inverse of the default)
4. Default: The side that is plugged into the USB port is the master half and is assumed to be the left half. The slave side is the right half

* `#define SPLIT_HAND_PIN B7`
* `#define SPLIT_HAND_PIN B7`
* 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.

* `#define EE_HANDS` (only works if `SPLIT_HAND_PIN` is not defined)
Expand Down Expand Up @@ -302,6 +305,10 @@ Use these to enable or disable building certain features. The more you have enab
* Current options are AdafruitEzKey, AdafruitBLE, RN42
* `SPLIT_KEYBOARD`
* Enables split keyboard support (dual MCU like the let's split and bakingpy's boards) and includes all necessary files located at quantum/split_common
* `CUSTOM_MATRIX`
* Allows replacing the standard matrix scanning routine with a custom one.
* `CUSTOM_DEBOUNCE`
* Allows replacing the standard key debouncing routine with a custom one.
* `WAIT_FOR_USB`
* Forces the keyboard to wait for a USB connection to be established before it starts up
* `NO_USB_STARTUP_CHECK`
Expand Down
14 changes: 13 additions & 1 deletion docs/getting_started_make_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ This allows you to send Unicode characters using `UC(<code point>)` in your keym

`UNICODEMAP_ENABLE`

This allows you to send Unicode characters using `X(<map index>)` in your keymap. You will need to maintain a mapping table in your keymap file. All possible code points (up to `0x10FFFF`) are supported.
This allows you to send Unicode characters using `X(<map index>)` in your keymap. You will need to maintain a mapping table in your keymap file. All possible code points (up to `0x10FFFF`) are supported.

`UCIS_ENABLE`

Expand Down Expand Up @@ -135,6 +135,18 @@ This enables [key lock](feature_key_lock.md). This consumes an additional 260 by

This enables split keyboard support (dual MCU like the let's split and bakingpy's boards) and includes all necessary files located at quantum/split_common

`SPLIT_TRANSPORT`

As there is no standard split communication driver for ARM-based split keyboards yet, `SPLIT_TRANSPORT = custom` must be used for these. It will prevent the standard split keyboard communication code (which is AVR-specific) from being included, allowing a custom implementation to be used.

`CUSTOM_MATRIX`

Lets you replace the default matrix scanning routine with your own code. You will need to provide your own implementations of matrix_init() and matrix_scan().

`CUSTOM_DEBOUNCE`

Lets you replace the default key debouncing routine with your own code. You will need to provide your own implementation of debounce().

## Customizing Makefile Options on a Per-Keymap Basis

If your keymap directory has a file called `rules.mk` any options you set in that file will take precedence over other `rules.mk` options for your particular keyboard.
Expand Down
63 changes: 63 additions & 0 deletions keyboards/handwired/xealous/debounce.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <string.h>
#include "config.h"
#include "matrix.h"
#include "timer.h"
#include "quantum.h"

#ifndef DEBOUNCING_DELAY
# define DEBOUNCING_DELAY 5
#endif

//Debouncing counters
typedef uint8_t debounce_counter_t;
#define DEBOUNCE_COUNTER_MODULO 250
#define DEBOUNCE_COUNTER_INACTIVE 251

static debounce_counter_t *debounce_counters;

void debounce_init(uint8_t num_rows)
{
debounce_counters = malloc(num_rows*MATRIX_COLS);
memset(debounce_counters, DEBOUNCE_COUNTER_INACTIVE, num_rows*MATRIX_COLS);
}

void update_debounce_counters(uint8_t num_rows, uint8_t current_time)
{
for (uint8_t row = 0; row < num_rows; row++)
{
for (uint8_t col = 0; col < MATRIX_COLS; col++)
{
if (debounce_counters[row*MATRIX_COLS + col] != DEBOUNCE_COUNTER_INACTIVE)
{
if (TIMER_DIFF(current_time, debounce_counters[row*MATRIX_COLS + col], DEBOUNCE_COUNTER_MODULO) >= DEBOUNCING_DELAY) {
debounce_counters[row*MATRIX_COLS + col] = DEBOUNCE_COUNTER_INACTIVE;
}
}
}
}
}

void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t current_time)
{
for (uint8_t row = 0; row < num_rows; row++)
{
matrix_row_t delta = raw[row] ^ cooked[row];

for (uint8_t col = 0; col < MATRIX_COLS; col++)
{
if (debounce_counters[row*MATRIX_COLS + col] == DEBOUNCE_COUNTER_INACTIVE && (delta & (1<<col)))
{
debounce_counters[row*MATRIX_COLS + col] = current_time;
cooked[row] ^= (1 << col);
}
}
}
}

void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed)
{
uint8_t current_time = timer_read() % DEBOUNCE_COUNTER_MODULO;

update_debounce_counters(num_rows, current_time);
transfer_matrix_values(raw, cooked, num_rows, current_time);
}
10 changes: 6 additions & 4 deletions keyboards/handwired/xealous/rules.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SRC += matrix_scanrate.c matrix.c
#SRC += matrix_scanrate.c matrix.c
SRC += debounce.c

# MCU name
MCU = atmega32u4
Expand Down Expand Up @@ -37,7 +38,7 @@ F_USB = $(F_CPU)

# Bootloader
# This definition is optional, and if your keyboard supports multiple bootloaders of
# different sizes, comment this out, and the correct address will be loaded
# different sizes, comment this out, and the correct address will be loaded
# automatically (+60). See bootloader.mk for all options.
BOOTLOADER = caterina

Expand All @@ -59,14 +60,15 @@ MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight.
RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight.
SPLIT_KEYBOARD = yes # Use shared split_common code
SUBPROJECT_rev1 = yes

# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend

CUSTOM_MATRIX = yes
CUSTOM_MATRIX = no
CUSTOM_DEBOUNCE = yes

LAYOUTS = split60

Expand Down
9 changes: 9 additions & 0 deletions keyboards/lets_split/sockets/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION

#ifdef USE_Link_Time_Optimization
// LTO has issues with macros (action_get_macro) and "functions" (fn_actions),
// so just disable them
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION

#define DISABLE_LEADER
#endif // USE_Link_Time_Optimization
2 changes: 2 additions & 0 deletions keyboards/lets_split/sockets/rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BACKLIGHT_ENABLE = no
AUDIO_ENABLE = yes
RGBLIGHT_ENABLE = yes #Don't enable this along with I2C

EXTRAFLAGS += -flto -DUSE_Link_Time_Optimization
5 changes: 2 additions & 3 deletions keyboards/miniaxe/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// #define MATRIX_ROW_PINS { D0, D5 }
// #define MATRIX_COL_PINS { F1, F0, B0 }
#define NO_PIN 0xFF
#define MATRIX_ROW_COL_PINS { \
#define DIRECT_PINS { \
{ F1, E6, B0, B2, B3 }, \
{ F5, F0, B1, B7, D2 }, \
{ F6, F7, C7, D5, D3 }, \
Expand All @@ -54,7 +53,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define UNUSED_PINS

/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
#define DIODE_DIRECTION CUSTOM_MATRIX
//#define DIODE_DIRECTION CUSTOM_MATRIX

// #define BACKLIGHT_PIN B7
// #define BACKLIGHT_BREATHING
Expand Down
Loading