From 66ffb1cb3a21c670719263f187e3470fd888f42a Mon Sep 17 00:00:00 2001 From: Robbie Gill Date: Thu, 7 Jul 2016 21:03:20 -0700 Subject: [PATCH 1/7] port missing support for hhkb-jp from tmk --- keyboards/hhkb/Makefile | 4 ++ keyboards/hhkb/config.h | 6 ++- keyboards/hhkb/hhkb.h | 27 +++++++++++ keyboards/hhkb/keymaps/jp/Makefile | 1 + keyboards/hhkb/keymaps/jp/keymap.c | 58 +++++++++++++++++++++++ keyboards/hhkb/keymaps/rdg_jp/Makefile | 1 + keyboards/hhkb/keymaps/rdg_jp/keymap.c | 65 ++++++++++++++++++++++++++ 7 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 keyboards/hhkb/keymaps/jp/Makefile create mode 100644 keyboards/hhkb/keymaps/jp/keymap.c create mode 100644 keyboards/hhkb/keymaps/rdg_jp/Makefile create mode 100644 keyboards/hhkb/keymaps/rdg_jp/keymap.c diff --git a/keyboards/hhkb/Makefile b/keyboards/hhkb/Makefile index 53eece3969..6fe973e1eb 100644 --- a/keyboards/hhkb/Makefile +++ b/keyboards/hhkb/Makefile @@ -78,6 +78,10 @@ ifndef QUANTUM_DIR include ../../Makefile endif +ifneq (, $(findstring yes, $(HHKB_JP))) + OPT_DEFS += -DHHKB_JP +endif + debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION debug-on: all diff --git a/keyboards/hhkb/config.h b/keyboards/hhkb/config.h index ee66e44571..3f0528b4b9 100644 --- a/keyboards/hhkb/config.h +++ b/keyboards/hhkb/config.h @@ -29,7 +29,11 @@ along with this program. If not, see . #define DESCRIPTION q.m.k keyboard firmware for HHKB /* key matrix size */ -#define MATRIX_ROWS 8 +#ifdef HHKB_JP +# define MATRIX_ROWS 16 +#else +# define MATRIX_ROWS 8 +#endif #define MATRIX_COLS 8 #define TAPPING_TERM 200 diff --git a/keyboards/hhkb/hhkb.h b/keyboards/hhkb/hhkb.h index cc756c4565..e95125efcb 100644 --- a/keyboards/hhkb/hhkb.h +++ b/keyboards/hhkb/hhkb.h @@ -21,4 +21,31 @@ { K70, K71, K72, K73, K74, K75, K76, KC_NO } \ } + +#define KEYMAP_JP( \ + K02, K32, K62, K22, K12, K52, K72, KA2, K92, K82, KB2, KE2, KF2, KD2, KC2, \ + K03, K63, K23, K13, K53, K73, KA3, K93, K83, KB3, KE3, KF3, KD3, \ + K06, K66, K26, K16, K56, K76, KA6, K96, K86, KB6, KE6, KF6, KD6, KC6, \ + K05, K65, K25, K15, K55, K75, KA5, K95, K85, KB5, KE5, KF5, KD5, KC5, \ + K04, K34, K64, K24, K14, K74, K94, K84, KB4, KE4, KF4, KD4, KC4) \ +{ \ + { KC_NO, KC_NO, K02, K03, K04, K05, K06, KC_NO }, \ + { KC_NO, KC_NO, K12, K13, K14, K15, K16, KC_NO }, \ + { KC_NO, KC_NO, K22, K23, K24, K25, K26, KC_NO }, \ + { KC_NO, KC_NO, K32, KC_NO, K34, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, K52, K53, KC_NO, K55, K56, KC_NO }, \ + { KC_NO, KC_NO, K62, K63, K64, K65, K66, KC_NO }, \ + { KC_NO, KC_NO, K72, K73, K74, K75, K76, KC_NO }, \ + { KC_NO, KC_NO, K82, K83, K84, K85, K86, KC_NO }, \ + { KC_NO, KC_NO, K92, K93, K94, K95, K96, KC_NO }, \ + { KC_NO, KC_NO, KA2, KA3, KC_NO, KA5, KA6, KC_NO }, \ + { KC_NO, KC_NO, KB2, KB3, KB4, KB5, KB6, KC_NO }, \ + { KC_NO, KC_NO, KC2, KC_NO, KC4, KC5, KC6, KC_NO }, \ + { KC_NO, KC_NO, KD2, KD3, KD4, KD5, KD6, KC_NO }, \ + { KC_NO, KC_NO, KE2, KE3, KE4, KE5, KE6, KC_NO }, \ + { KC_NO, KC_NO, KF2, KF3, KF4, KF5, KF6, KC_NO } \ +} + + #endif diff --git a/keyboards/hhkb/keymaps/jp/Makefile b/keyboards/hhkb/keymaps/jp/Makefile new file mode 100644 index 0000000000..92986292a2 --- /dev/null +++ b/keyboards/hhkb/keymaps/jp/Makefile @@ -0,0 +1 @@ +HHKB_JP=yes diff --git a/keyboards/hhkb/keymaps/jp/keymap.c b/keyboards/hhkb/keymaps/jp/keymap.c new file mode 100644 index 0000000000..8525adce59 --- /dev/null +++ b/keyboards/hhkb/keymaps/jp/keymap.c @@ -0,0 +1,58 @@ +#include "hhkb.h" + +#define _______ KC_TRNS + + +/* Layer 0: HHKB JP + * ,-----------------------------------------------------------. + * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| -| =|Yen|Bsp| + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | + * |------------------------------------------------------` Ent| + * |Ctrl | A| S| D| F| G| H| J| K| L| ;| '| `| | + * |-----------------------------------------------------------| + * |Shft | Z| X| C| V| B| N| M| ,| .| /| \| Up|Sft| + * |-----------------------------------------------------------| + * | ||Ctl|Alt|Cmd| | Spc |Bsp| | | ||Lft|Dwn|Rgh| + * `-----------------------------------------------------------' + */ + +/* Layer 1: HHKB mode (HHKB Fn) + * ,-----------------------------------------------------------. + * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del| + * |-----------------------------------------------------------| + * |Caps | | | | | | | |Psc|Slk|Pus|Up | | | + * |------------------------------------------------------` | + * | |VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig| | | + * |-----------------------------------------------------------| + * | | | | | | | +| -|End|PgD|Dow| | | | + * |-----------------------------------------------------------| + * | || | | | | | | | | || | | | + * `-----------------------------------------------------------' + */ + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = KEYMAP_JP( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_JYEN, KC_BSPC, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, + KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_BSLS, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RO, KC_UP, KC_RSFT, + MO(1), KC_ZKHK, KC_LGUI, KC_LALT, KC_MHEN, KC_SPC, KC_HENK, KC_KANA, KC_RALT, MO(1), KC_LEFT, KC_DOWN, KC_RGHT + ), + + [1] = KEYMAP_JP( + KC_PWR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, + KC_CAPS, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, _______, + _______, KC_VOLD, KC_VOLU, KC_MUTE, KC_PWR, _______, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, _______, KC_PENT, + _______, _______, _______, _______, _______, _______, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, _______ + ) +}; + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t macro_id, uint8_t opt) { + return MACRO_NONE; +} + +const uint16_t PROGMEM fn_actions[] = { + +}; diff --git a/keyboards/hhkb/keymaps/rdg_jp/Makefile b/keyboards/hhkb/keymaps/rdg_jp/Makefile new file mode 100644 index 0000000000..92986292a2 --- /dev/null +++ b/keyboards/hhkb/keymaps/rdg_jp/Makefile @@ -0,0 +1 @@ +HHKB_JP=yes diff --git a/keyboards/hhkb/keymaps/rdg_jp/keymap.c b/keyboards/hhkb/keymaps/rdg_jp/keymap.c new file mode 100644 index 0000000000..700ba3a0b7 --- /dev/null +++ b/keyboards/hhkb/keymaps/rdg_jp/keymap.c @@ -0,0 +1,65 @@ +#include "hhkb.h" + +#define _______ KC_TRNS + +enum { + ZER, + HDN, + OSY +}; + + +#define CTL_ESC CTL_T(KC_ESC) +#define SFT_BSP SFT_T(KC_BSPC) + +#define SCRNS3 LGUI(LCTL(LSFT(KC_3))) +#define SCRNS4 LGUI(LCTL(LSFT(KC_4))) + + +/* hhkb jp ~ layout + * ,-----------------------------------------------------------. + * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| -| =|Yen|Bsp| + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | + * |------------------------------------------------------` Ent| + * |Ctrl | A| S| D| F| G| H| J| K| L| ;| '| `| | + * |-----------------------------------------------------------| + * |Shft | Z| X| C| V| B| N| M| ,| .| /| \| Up|Sft| + * |-----------------------------------------------------------| + * | ||Ctl|Alt|Cmd| | Spc |Bsp| | | ||Lft|Dwn|Rgh| + * `-----------------------------------------------------------' + */ + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [ZER] = KEYMAP_JP( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_INS, KC_BSPC, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, + CTL_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_GRV, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_BSLS, KC_UP, KC_RSFT, + MO(HDN), KC_LCTL, KC_LALT, KC_LGUI, MO(HDN), KC_SPC, SFT_BSP, MO(HDN), MO(OSY), KC_NO, KC_LEFT, KC_DOWN, KC_RGHT + ), + + [HDN] = KEYMAP_JP( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_DEL, + _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, _______, + _______, KC_TILD, KC_GRV, KC_BSLS, KC_PIPE, KC_MINS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_TILD, KC_GRV, _______, _______, + _______, KC_VOLD, KC_VOLU, KC_MUTE, KC_PWR, _______, _______, KC_ENT, _______, _______, _______, _______, KC_PGUP, _______, + _______, _______, _______, _______, _______, KC_UNDS , KC_DEL, _______, _______, _______, KC_HOME, KC_PGDN, KC_END + ), + + [OSY] = KEYMAP_JP( + _______, _______, _______, SCRNS3, SCRNS4, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, _______ + ) +}; + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t macro_id, uint8_t opt) { + return MACRO_NONE; +} + +const uint16_t PROGMEM fn_actions[] = { + +}; From b86b0480d530c9d5f40bbe835f120b1c1b563e47 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 17:20:37 +0300 Subject: [PATCH 2/7] Speed up compilation by not using recusive make The cleaning is done outside the targets, by checking the requested target name. --- tmk_core/rules.mk | 59 +++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 352e9314b6..a518fc0c3f 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -271,23 +271,10 @@ ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) # Default target. -all: - @$(MAKE) begin - @$(MAKE) gccversion - @$(MAKE) sizebefore - @$(MAKE) clean_list # force clean each time - @$(MAKE) build - @$(MAKE) sizeafter - @$(MAKE) end +all: build sizeafter # Quick make that doesn't clean -quick: - @$(MAKE) begin - @$(MAKE) gccversion - @$(MAKE) sizebefore - @$(MAKE) build - @$(MAKE) sizeafter - @$(MAKE) end +quick: build sizeafter # Change the build target to build a HEX file or a library. build: elf hex @@ -303,13 +290,7 @@ sym: $(BUILD_DIR)/$(TARGET).sym LIBNAME=lib$(TARGET).a lib: $(LIBNAME) - - -# Eye candy. -# AVR Studio 3.x does not check make's exit code but relies on -# the following magic strings to be generated by the compile job. -begin: - @$(SECHO) $(MSG_BEGIN) +check_submodule: git submodule status --recursive | \ while IFS= read -r x; do \ case "$$x" in \ @@ -318,10 +299,6 @@ begin: esac \ done -end: - @$(SECHO) $(MSG_END) - - # Display size of file. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex #ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf @@ -331,7 +308,7 @@ sizebefore: @if test -f $(TARGET).hex; then $(SECHO) $(MSG_SIZE_BEFORE); $(SILENT) || $(HEXSIZE); \ 2>/dev/null; $(SECHO); fi -sizeafter: +sizeafter: $(BUILD_DIR)/$(TARGET).hex @if test -f $(TARGET).hex; then $(SECHO); $(SECHO) $(MSG_SIZE_AFTER); $(SILENT) || $(HEXSIZE); \ 2>/dev/null; $(SECHO); fi # test file sizes eventually @@ -386,9 +363,9 @@ gccversion : # Link: create ELF output file from object files. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf .PRECIOUS : $(OBJ) -%.elf: $(OBJ) +%.elf: gccversion sizebefore check_submodule $(OBJ) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. @@ -429,14 +406,7 @@ $(OBJDIR)/%.o : %.S $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ # Target: clean project. -clean: begin clean_list end - -clean_list : - @$(REMOVE) -r $(BUILD_DIR) - @$(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR) - @$(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR) - @if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi - @$(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR) +clean: show_path: @echo VPATH=$(VPATH) @@ -496,6 +466,19 @@ all-keymaps-%: all-keymaps: all-keymaps-all +GOAL=$(MAKECMDGOALS) +ifeq ($(MAKECMDGOALS),) +GOAL = all +endif +CLEANING_GOALS=clean clean_list all +ifneq ($(findstring $(GOAL),$(CLEANING_GOALS)),) +$(shell $(REMOVE) -r $(BUILD_DIR) 2>/dev/null) +$(shell $(REMOVE) -r $(TOP_DIR)/$(BUILD_DIR)) +$(shell $(REMOVE) -r $(KEYBOARD_PATH)/$(BUILD_DIR)) +$(shell if $$SUBPROJECT; then $(REMOVE) -r $(SUBPROJECT_PATH)/$(BUILD_DIR); fi) +$(shell $(REMOVE) -r $(KEYMAP_PATH)/$(BUILD_DIR)) +endif + # Create build directory $(shell mkdir $(BUILD_DIR) 2>/dev/null) @@ -508,7 +491,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) # Listing of phony targets. -.PHONY : all quick begin finish end sizebefore sizeafter gccversion \ +.PHONY : all quick finish sizebefore sizeafter gccversion \ build elf hex eep lss sym coff extcoff \ clean clean_list debug gdb-config show_path \ program teensy dfu flip dfu-ee flip-ee dfu-start \ From ccebceeb6f24aeee102f6ef3180f4f563ca025a8 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 17:44:41 +0300 Subject: [PATCH 3/7] Don't run git describe for ever file that is built --- tmk_core/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 5bae0d762f..aa05b9491d 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -107,7 +107,7 @@ endif # Version string -OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null) +OPT_DEFS += -DVERSION=$(GIT_VERSION) # Bootloader address ifdef STM32_BOOTLOADER_ADDRESS From 1e3db59097f8c396d69179fdd66ef0131a6ba80d Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 18:18:33 +0300 Subject: [PATCH 4/7] Fix the link target --- tmk_core/rules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index a518fc0c3f..543d3da8a0 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -365,7 +365,7 @@ gccversion : .PRECIOUS : $(OBJ) %.elf: gccversion sizebefore check_submodule $(OBJ) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out gccversion sizebefore check_submodule,$^) --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. From e8e300d5c4dd05b806869b648b93feeff1f8a7dc Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 22:59:09 +0300 Subject: [PATCH 5/7] Fix name of makefile dep files The files can't start with a .dot, as the wildcard function wont find them. So this is fixed by removing the BUILD_DIR from the name. --- tmk_core/rules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 543d3da8a0..8d843cc983 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -260,7 +260,7 @@ LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst # Compiler flags to generate dependency files. #GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d -GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d +GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$(subst $(BUILD_DIR)/,,$@)).d # Combine all necessary flags and optional flags. From 6911ead027202da981862c9259ff4d962d51a519 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 8 Jul 2016 23:19:48 +0300 Subject: [PATCH 6/7] Use order only prerequisites to avoid re-linking The prerequisites at the start of the build process are order-only so that the trget don't link again. Also added as a dependency to the compilation to force the messages to be printed at the start --- tmk_core/rules.mk | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index 8d843cc983..f13351ea19 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk @@ -360,49 +360,51 @@ gccversion : $(eval CMD=$(AR) $@ $(OBJ) ) @$(BUILD_CMD) +BEGIN = gccversion check_submodule sizebefore + # Link: create ELF output file from object files. .SECONDARY : $(BUILD_DIR)/$(TARGET).elf .PRECIOUS : $(OBJ) -%.elf: gccversion sizebefore check_submodule $(OBJ) +%.elf: $(OBJ) | $(BEGIN) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=$(CC) $(ALL_CFLAGS) $(filter-out gccversion sizebefore check_submodule,$^) --output $@ $(LDFLAGS)) + $(eval CMD=$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)) @$(BUILD_CMD) # Compile: create object files from C source files. -$(OBJDIR)/%.o : %.c +$(OBJDIR)/%.o : %.c | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_COMPILING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_CFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create object files from C++ source files. -$(OBJDIR)/%.o : %.cpp +$(OBJDIR)/%.o : %.cpp | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_COMPILING_CPP) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_CPPFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create assembler files from C source files. -%.s : %.c +%.s : %.c | $(BEGIN) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -S $(ALL_CFLAGS) $< -o $@) @$(BUILD_CMD) # Compile: create assembler files from C++ source files. -%.s : %.cpp +%.s : %.cpp | $(BEGIN) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -S $(ALL_CPPFLAGS) $< -o $@) @$(BUILD_CMD) # Assemble: create object files from assembler source files. -$(OBJDIR)/%.o : %.S +$(OBJDIR)/%.o : %.S | $(BEGIN) @mkdir -p $(@D) @$(SILENT) || printf "$(MSG_ASSEMBLING) $<" | $(AWK_CMD) $(eval CMD=$(CC) -c $(ALL_ASFLAGS) $< -o $@) @$(BUILD_CMD) # Create preprocessed source for use in sending a bug report. -%.i : %.c +%.i : %.c | $(BEGIN) $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ # Target: clean project. @@ -492,7 +494,7 @@ $(shell mkdir $(OBJDIR) 2>/dev/null) # Listing of phony targets. .PHONY : all quick finish sizebefore sizeafter gccversion \ -build elf hex eep lss sym coff extcoff \ +build elf hex eep lss sym coff extcoff check_submodule \ clean clean_list debug gdb-config show_path \ program teensy dfu flip dfu-ee flip-ee dfu-start \ all-keyboards-defaults all-keyboards all-keymaps \ From c444f4f702739633b11e548575cdbe8369d0a98b Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Fri, 8 Jul 2016 21:40:57 -0400 Subject: [PATCH 7/7] Documents tap dance --- readme.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/readme.md b/readme.md index e874812515..3657d2c15a 100644 --- a/readme.md +++ b/readme.md @@ -353,6 +353,81 @@ void matrix_scan_user(void) { As you can see, you have three function. you can use - `SEQ_ONE_KEY` for single-key sequences (Leader followed by just one key), and `SEQ_TWO_KEYS` and `SEQ_THREE_KEYS` for longer sequences. Each of these accepts one or more keycodes as arguments. This is an important point: You can use keycodes from **any layer on your keyboard**. That layer would need to be active for the leader macro to fire, obviously. +### Tap Dance: A single key can do 3, 5, or 100 different things + +Hit the semicolon key once, send a semicolon. Hit it twice, rapidly -- send a colon. Hit it three times, and your keyboard's LEDs do a wild dance. That's just one example of what Tap Dance can do. It's one of the nicest community-contributed features in the firmware, conceived and created by [algernon](https://github.com/algernon) in [#451](https://github.com/jackhumbert/qmk_firmware/pull/451). Here's how Algernon describes the feature: + +With this feature one can specify keys that behave differently, based on the amount of times they have been tapped, and when interrupted, they get handled before the interrupter. + +To make it clear how this is different from `ACTION_FUNCTION_TAP`, lets explore a certain setup! We want one key to send `Space` on single tap, but `Enter` on double-tap. + +With `ACTION_FUNCTION_TAP`, it is quite a rain-dance to set this up, and has the problem that when the sequence is interrupted, the interrupting key will be send first. Thus, `SPC a` will result in `a SPC` being sent, if they are typed within `TAPPING_TERM`. With the tap dance feature, that'll come out as `SPC a`, correctly. + +The implementation hooks into two parts of the system, to achieve this: into `process_record_quantum()`, and the matrix scan. We need the latter to be able to time out a tap sequence even when a key is not being pressed, so `SPC` alone will time out and register after `TAPPING_TERM` time. + +But lets start with how to use it, first! + +First, you will need `TAP_DANCE_ENABLE=yes` in your `Makefile`, because the feature is disabled by default. This adds a little less than 1k to the firmware size. Next, you will want to define some tap-dance keys, which is easiest to do with the `TD()` macro, that - similar to `F()`, takes a number, which will later be used as an index into the `tap_dance_actions` array. + +This array specifies what actions shall be taken when a tap-dance key is in action. Currently, there are two possible options: + +* `ACTION_TAP_DANCE_DOUBLE(kc1, kc2)`: Sends the `kc1` keycode when tapped once, `kc2` otherwise. +* `ACTION_TAP_DANCE_FN(fn)`: Calls the specified function - defined in the user keymap - with the current state of the tap-dance action. + +The first option is enough for a lot of cases, that just want dual roles. For example, `ACTION_TAP_DANCE(KC_SPC, KC_ENT)` will result in `Space` being sent on single-tap, `Enter` otherwise. + +And that's the bulk of it! + +Do note, however, that this implementation does have some consequences: keys do not register until either they reach the tapping ceiling, or they time out. This means that if you hold the key, nothing happens, no repeat, no nothing. It is possible to detect held state, and register an action then too, but that's not implemented yet. Keys also unregister immediately after being registered, so you can't even hold the second tap. This is intentional, to be consistent. + +And now, on to the explanation of how it works! + +The main entry point is `process_tap_dance()`, called from `process_record_quantum()`, which is run for every keypress, and our handler gets to run early. This function checks whether the key pressed is a tap-dance key. If it is not, and a tap-dance was in action, we handle that first, and enqueue the newly pressed key. If it is a tap-dance key, then we check if it is the same as the already active one (if there's one active, that is). If it is not, we fire off the old one first, then register the new one. If it was the same, we increment the counter and the timer. + +This means that you have `TAPPING_TERM` time to tap the key again, you do not have to input all the taps within that timeframe. This allows for longer tap counts, with minimal impact on responsiveness. + +Our next stop is `matrix_scan_tap_dance()`. This handles the timeout of tap-dance keys. + +For the sake of flexibility, tap-dance actions can be either a pair of keycodes, or a user function. The latter allows one to handle higher tap counts, or do extra things, like blink the LEDs, fiddle with the backlighting, and so on. This is accomplished by using an union, and some clever macros. + +In the end, let's see a full example! + +```c +enum { + CT_SE = 0, + CT_CLN, + CT_EGG +}; + +/* Have the above three on the keymap, TD(CT_SE), etc... */ + +void dance_cln (qk_tap_dance_state_t *state) { + if (state->count == 1) { + register_code (KC_RSFT); + register_code (KC_SCLN); + unregister_code (KC_SCLN); + unregister_code (KC_RSFT); + } else { + register_code (KC_SCLN); + unregister_code (KC_SCLN); + reset_tap_dance (state); + } +} + +void dance_egg (qk_tap_dance_state_t *state) { + if (state->count >= 100) { + SEND_STRING ("Safety dance!"); + reset_tap_dance (state); + } +} + +const qk_tap_dance_action_t tap_dance_actions[] = { + [CT_SE] = ACTION_TAP_DANCE_DOUBLE (KC_SPC, KC_ENT) + ,[CT_CLN] = ACTION_TAP_DANCE_FN (dance_cln) + ,[CT_EGG] = ACTION_TAP_DANCE_FN (dance_egg) +}; +``` + ### Temporarily setting the default layer `DF(layer)` - sets default layer to *layer*. The default layer is the one at the "bottom" of the layer stack - the ultimate fallback layer. This currently does not persist over power loss. When you plug the keyboard back in, layer 0 will always be the default. It is theoretically possible to work around that, but that's not what `DF` does.