Skip to content

Commit

Permalink
Merge pull request #1 from jackhumbert/master
Browse files Browse the repository at this point in the history
Catch up with jack's master
  • Loading branch information
TerryMathews authored Jul 9, 2016
2 parents 979a0d2 + c444f4f commit 4decdd2
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 47 deletions.
4 changes: 4 additions & 0 deletions keyboards/hhkb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion keyboards/hhkb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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
Expand Down
27 changes: 27 additions & 0 deletions keyboards/hhkb/hhkb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions keyboards/hhkb/keymaps/jp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HHKB_JP=yes
58 changes: 58 additions & 0 deletions keyboards/hhkb/keymaps/jp/keymap.c
Original file line number Diff line number Diff line change
@@ -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[] = {

};
1 change: 1 addition & 0 deletions keyboards/hhkb/keymaps/rdg_jp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HHKB_JP=yes
65 changes: 65 additions & 0 deletions keyboards/hhkb/keymaps/rdg_jp/keymap.c
Original file line number Diff line number Diff line change
@@ -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[] = {

};
75 changes: 75 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tmk_core/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4decdd2

Please sign in to comment.