Skip to content

Commit 7060cb7

Browse files
authored
Refactor steno and add STENO_PROTOCOL = [all|txbolt|geminipr] (#17065)
* Refactor steno into STENO_ENABLE_[ALL|GEMINI|BOLT] * Update stenography documentation * STENO_ENABLE_TXBOLT → STENO_ENABLE_BOLT TXBOLT is a better name but BOLT is more consistent with the pre-existing TX Bolt related constants, which all drop the "TX " prefix * Comments * STENO_ENABLE_[GEMINI|BOLT|ALL] → STENO_PROTOCOL = [geminipr|txbolt|all] * Add note on lacking V-USB support * Clear chord at the end of the switch(mode){send_steno_chord} block * Return true if NOEVENT * update_chord_xxx → add_xxx_key_to_chord * Enable the defines for all the protocols if STENO_PROTOCOL = all * Mention how to use `steno_set_mode` * Set the default steno protocol to "all" This is done so that existing keymaps invoking `steno_set_mode` don't all suddenly break * Add data driver equivalents for stenography feature * Document format of serial steno packets (Thanks dnaq) * Add missing comma
1 parent 2239527 commit 7060cb7

File tree

9 files changed

+349
-179
lines changed

9 files changed

+349
-179
lines changed

builddefs/common_features.mk

+22-3
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,29 @@ ifeq ($(MUSIC_ENABLE), yes)
9292
SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
9393
endif
9494

95+
VALID_STENO_PROTOCOL_TYPES := geminipr txbolt all
96+
STENO_PROTOCOL ?= all
9597
ifeq ($(strip $(STENO_ENABLE)), yes)
96-
OPT_DEFS += -DSTENO_ENABLE
97-
VIRTSER_ENABLE ?= yes
98-
SRC += $(QUANTUM_DIR)/process_keycode/process_steno.c
98+
ifeq ($(filter $(STENO_PROTOCOL),$(VALID_STENO_PROTOCOL_TYPES)),)
99+
$(call CATASTROPHIC_ERROR,Invalid STENO_PROTOCOL,STENO_PROTOCOL="$(STENO_PROTOCOL)" is not a valid stenography protocol)
100+
else
101+
OPT_DEFS += -DSTENO_ENABLE
102+
VIRTSER_ENABLE ?= yes
103+
104+
ifeq ($(strip $(STENO_PROTOCOL)), geminipr)
105+
OPT_DEFS += -DSTENO_ENABLE_GEMINI
106+
endif
107+
ifeq ($(strip $(STENO_PROTOCOL)), txbolt)
108+
OPT_DEFS += -DSTENO_ENABLE_BOLT
109+
endif
110+
ifeq ($(strip $(STENO_PROTOCOL)), all)
111+
OPT_DEFS += -DSTENO_ENABLE_ALL
112+
OPT_DEFS += -DSTENO_ENABLE_GEMINI
113+
OPT_DEFS += -DSTENO_ENABLE_BOLT
114+
endif
115+
116+
SRC += $(QUANTUM_DIR)/process_keycode/process_steno.c
117+
endif
99118
endif
100119

101120
ifeq ($(strip $(VIRTSER_ENABLE)), yes)

builddefs/show_options.mk

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ OTHER_OPTION_NAMES = \
4545
LEADER_ENABLE \
4646
PRINTING_ENABLE \
4747
STENO_ENABLE \
48+
STENO_PROTOCOL \
4849
TAP_DANCE_ENABLE \
4950
VIRTSER_ENABLE \
5051
OLED_ENABLE \

data/mappings/info_rules.json

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"SPLIT_KEYBOARD": {"info_key": "split.enabled", "value_type": "bool"},
2929
"SPLIT_TRANSPORT": {"info_key": "split.transport.protocol", "to_c": false},
3030
"WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"},
31+
"STENO_ENABLE": {"info_key": "stenography.enabled", "value_type": "bool"},
32+
"STENO_PROTOCOL": {"info_key": "stenography.protocol"},
3133

3234
# Items we want flagged in lint
3335
"CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true},

data/schemas/keyboard.jsonschema

+11
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@
361361
}
362362
}
363363
},
364+
"stenography": {
365+
"type": "object",
366+
"additionalProperties": false,
367+
"properties": {
368+
"enabled": {"type": "boolean"},
369+
"protocol": {
370+
"type": "string",
371+
"enum": ["all", "geminipr", "txbolt"]
372+
}
373+
}
374+
},
364375
"split": {
365376
"type": "object",
366377
"additionalProperties": false,

docs/feature_stenography.md

+96-27
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,107 @@ The [Open Steno Project](https://www.openstenoproject.org/) has built an open-so
88

99
Plover can work with any standard QWERTY keyboard, although it is more efficient if the keyboard supports NKRO (n-key rollover) to allow Plover to see all the pressed keys at once. An example keymap for Plover can be found in `planck/keymaps/default`. Switching to the `PLOVER` layer adjusts the position of the keyboard to support the number bar.
1010

11-
To use Plover with QMK just enable NKRO and optionally adjust your layout if you have anything other than a standard layout. You may also want to purchase some steno-friendly keycaps to make it easier to hit multiple keys.
11+
To enable NKRO, add `NKRO_ENABLE = yes` in your `rules.mk` and make sure to press `NK_ON` to turn it on because `NKRO_ENABLE = yes` merely adds the possibility of switching to NKRO mode but it doesn't automatically switch to it. If you want to automatically switch, add `#define FORCE_NKRO` in your `config.h`.
12+
13+
You may also need to adjust your layout, either in QMK or in Plover, if you have anything other than a standard layout. You may also want to purchase some steno-friendly keycaps to make it easier to hit multiple keys.
1214

1315
## Plover with Steno Protocol :id=plover-with-steno-protocol
1416

15-
Plover also understands the language of several steno machines. QMK can speak a couple of these languages, TX Bolt and GeminiPR. An example layout can be found in `planck/keymaps/steno`.
17+
Plover also understands the language of several steno machines. QMK can speak a couple of these languages: TX Bolt and GeminiPR. An example layout can be found in `planck/keymaps/steno`.
18+
19+
When QMK speaks to Plover over a steno protocol, Plover will not use the keyboard as input. This means that you can switch back and forth between a standard keyboard and your steno keyboard, or even switch layers from Plover to standard and back without needing to activate/deactivate Plover.
20+
21+
In this mode, Plover expects to speak with a steno machine over a serial port so QMK will present itself to the operating system as a virtual serial port in addition to a keyboard.
1622

17-
When QMK speaks to Plover over a steno protocol Plover will not use the keyboard as input. This means that you can switch back and forth between a standard keyboard and your steno keyboard, or even switch layers from Plover to standard and back without needing to activate/deactivate Plover.
23+
> Note: Due to hardware limitations, you might not be able to run both a virtual serial port and mouse emulation at the same time.
1824
19-
In this mode Plover expects to speak with a steno machine over a serial port so QMK will present itself to the operating system as a virtual serial port in addition to a keyboard. By default QMK will speak the TX Bolt protocol but can be switched to GeminiPR; the last protocol used is stored in non-volatile memory so QMK will use the same protocol on restart.
25+
!> Serial stenography protocols are not supported on [V-USB keyboards](compatible_microcontrollers#atmel-avr).
2026

21-
> Note: Due to hardware limitations you may not be able to run both a virtual serial port and mouse emulation at the same time.
27+
To enable stenography protocols, add the following lines to your `rules.mk`:
28+
```mk
29+
STENO_ENABLE = yes
30+
```
2231

2332
### TX Bolt :id=tx-bolt
2433

25-
TX Bolt communicates the status of 24 keys over a very simple protocol in variable-sized (1-5 byte) packets.
34+
TX Bolt communicates the status of 24 keys over a simple protocol in variable-sized (1–4 bytes) packets.
2635

27-
### GeminiPR :id=geminipr
36+
To select TX Bolt, add the following lines to your `rules.mk`:
37+
```mk
38+
STENO_ENABLE = yes
39+
STENO_PROTOCOL = txbolt
40+
```
2841

29-
GeminiPR encodes 42 keys into a 6-byte packet. While TX Bolt contains everything that is necessary for standard stenography, GeminiPR opens up many more options, including supporting non-English theories.
42+
Each byte of the packet represents a different group of steno keys. Determining the group of a certain byte of the packet is done by checking the first two bits, the remaining bits are set if the corresponding steno key was pressed for the stroke. The last set of keys (as indicated by leading `11`) needs to keep track of less keys than there are bits so one of the bits is constantly 0.
3043

31-
## Configuring QMK for Steno :id=configuring-qmk-for-steno
44+
The start of a new packet can be detected by comparing the group “ID” (the two MSBs) of the current byte to that of the previously received byte. If the group “ID” of the current byte is smaller or equal to that of the previous byte, it means that the current byte is the beginning of a new packet.
3245

33-
Firstly, enable steno in your keymap's Makefile. You may also need disable mousekeys, extra keys, or another USB endpoint to prevent conflicts. The builtin USB stack for some processors only supports a certain number of USB endpoints and the virtual serial port needed for steno fills 3 of them.
46+
The format of TX Bolt packets is shown below.
47+
```
48+
00HWPKTS 01UE*OAR 10GLBPRF 110#ZDST
49+
```
50+
51+
Examples of steno strokes and the associated packet:
52+
- `EUBG` = `01110000 10101000`
53+
- `WAZ` = `00010000 01000010 11001000`
54+
- `PHAPBGS` = `00101000 01000010 10101100 11000010`
55+
56+
### GeminiPR :id=geminipr
57+
58+
GeminiPR encodes 42 keys into a 6-byte packet. While TX Bolt contains everything that is necessary for standard stenography, GeminiPR opens up many more options, including differentiating between top and bottom `S-`, and supporting non-English theories.
3459

35-
```make
60+
To select GeminiPR, add the following lines to your `rules.mk`:
61+
```mk
3662
STENO_ENABLE = yes
37-
MOUSEKEY_ENABLE = no
63+
STENO_PROTOCOL = geminipr
3864
```
3965

40-
In your keymap create a new layer for Plover. You will need to include `keymap_steno.h`. See `planck/keymaps/steno/keymap.c` for an example. Remember to create a key to switch to the layer as well as a key for exiting the layer. If you would like to switch modes on the fly you can use the keycodes `QK_STENO_BOLT` and `QK_STENO_GEMINI`. If you only want to use one of the protocols you may set it up in your initialization function:
66+
All packets in the GeminiPR protocol consist of exactly six bytes, used as bit-arrays for different groups of keys. The beginning of a packet is indicated by setting the most significant bit (MSB) to 1 while setting the MSB of the remaining five bytes to 0.
4167

42-
```c
43-
void eeconfig_init_user() {
44-
steno_set_mode(STENO_MODE_GEMINI); // or STENO_MODE_BOLT
45-
}
68+
The format of GeminiPR packets is shown below.
69+
```
70+
1 Fn #1 #2 #3 #4 #5 #6
71+
0 S1- S2- T- K- P- W- H-
72+
0 R- A- O- *1 *2 res1 res2
73+
0 pwr *3 *4 -E -U -F -R
74+
0 -P -B -L -G -T -S -D
75+
0 #7 #8 #9 #A #B #C -Z
4676
```
4777

48-
Once you have your keyboard flashed launch Plover. Click the 'Configure...' button. In the 'Machine' tab select the Stenotype Machine that corresponds to your desired protocol. Click the 'Configure...' button on this tab and enter the serial port or click 'Scan'. Baud rate is fine at 9600 (although you should be able to set as high as 115200 with no issues). Use the default settings for everything else (Data Bits: 8, Stop Bits: 1, Parity: N, no flow control).
78+
Examples of steno strokes and the associated packet:
79+
- `EUBG` = `10000000 00000000 00000000 00001100 00101000 00000000`
80+
- `WAZ` = `10000000 00000010 00100000 00000000 00000000 00000001`
81+
- `PHAPBGS` = `10000000 00000101 00100000 00000000 01101010 00000000`
4982

50-
On the display tab click 'Open stroke display'. With Plover disabled you should be able to hit keys on your keyboard and see them show up in the stroke display window. Use this to make sure you have set up your keymap correctly. You are now ready to steno!
83+
### Switching protocols on the fly :id=switching-protocols-on-the-fly
84+
85+
If you wish to switch the serial protocol used to transfer the steno chords without having to recompile your keyboard firmware every time, you can press the `QK_STENO_BOLT` and `QK_STENO_GEMINI` keycodes in order to switch protocols on the fly.
86+
87+
To enable these special keycodes, add the following lines to your `rules.mk`:
88+
```mk
89+
STENO_ENABLE = yes
90+
STENO_PROTOCOL = all
91+
```
92+
93+
If you want to switch protocols programatically, as part of a custom macro for example, don't use `tap_code(QK_STENO_*)`, as `tap_code` only supports [basic keycodes](keycodes_basic). Instead, you should use `steno_set_mode(STENO_MODE_*)`, whose valid arguments are `STENO_MODE_BOLT` and `STENO_MODE_GEMINI`.
94+
95+
The default protocol is Gemini PR but the last protocol used is stored in non-volatile memory so QMK will remember your choice between reboots of your keyboard — assuming that your keyboard features (emulated) EEPROM.
96+
97+
Naturally, this option takes the most amount of firmware space as it needs to compile the code for all the available stenography protocols. In most cases, compiling a single stenography protocol is sufficient.
98+
99+
The default value for `STENO_PROTOCOL` is `all`.
100+
101+
## Configuring QMK for Steno :id=configuring-qmk-for-steno
102+
103+
After enabling stenography and optionally selecting a protocol, you may also need disable mouse keys, extra keys, or another USB endpoint to prevent conflicts. The builtin USB stack for some processors only supports a certain number of USB endpoints and the virtual serial port needed for steno fills 3 of them.
104+
105+
!> If you had *explicitly* set `VIRSTER_ENABLE = no`, none of the serial stenography protocols (GeminiPR, TX Bolt) will work properly. You are expected to either set it to `yes`, remove the line from your `rules.mk` or send the steno chords yourself in an alternative way using the [provided interceptable hooks](#interfacing-with-the-code).
106+
107+
In your keymap, create a new layer for Plover, that you can fill in with the [steno keycodes](#keycode-reference) (you will need to include `keymap_steno.h`, see `planck/keymaps/steno/keymap.c` for an example). Remember to create a key to switch to the layer as well as a key for exiting the layer.
108+
109+
Once you have your keyboard flashed, launch Plover. Click the 'Configure...' button. In the 'Machine' tab, select the Stenotype Machine that corresponds to your desired protocol. Click the 'Configure...' button on this tab and enter the serial port or click 'Scan'. Baud rate is fine at 9600 (although you should be able to set as high as 115200 with no issues). Use the default settings for everything else (Data Bits: 8, Stop Bits: 1, Parity: N, no flow control).
110+
111+
To test your keymap, you can chord keys on your keyboard and either look at the output of the 'paper tape' (Tools > Paper Tape) or that of the 'layout display' (Tools > Layout Display). If your strokes correctly show up, you are now ready to steno!
51112

52113
## Learning Stenography :id=learning-stenography
53114

@@ -60,7 +121,7 @@ On the display tab click 'Open stroke display'. With Plover disabled you should
60121
The steno code has three interceptable hooks. If you define these functions, they will be called at certain points in processing; if they return true, processing continues, otherwise it's assumed you handled things.
61122

62123
```c
63-
bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]);
124+
bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[MAX_STROKE_SIZE]);
64125
```
65126
66127
This function is called when a chord is about to be sent. Mode will be one of `STENO_MODE_BOLT` or `STENO_MODE_GEMINI`. This represents the actual chord that would be sent via whichever protocol. You can modify the chord provided to alter what gets sent. Remember to return true if you want the regular sending process to happen.
@@ -72,15 +133,23 @@ bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
72133
This function is called when a keypress has come in, before it is processed. The keycode should be one of `QK_STENO_BOLT`, `QK_STENO_GEMINI`, or one of the `STN_*` key values.
73134

74135
```c
75-
bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed);
136+
bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[MAX_STROKE_SIZE], int8_t n_pressed_keys);
76137
```
77138
78-
This function is called after a key has been processed, but before any decision about whether or not to send a chord. If `IS_PRESSED(record->event)` is false, and `pressed` is 0 or 1, the chord will be sent shortly, but has not yet been sent. This is where to put hooks for things like, say, live displays of steno chords or keys.
139+
This function is called after a key has been processed, but before any decision about whether or not to send a chord. This is where to put hooks for things like, say, live displays of steno chords or keys.
140+
141+
If `IS_PRESSED(record->event)` is false, and `n_pressed_keys` is 0 or 1, the chord will be sent shortly, but has not yet been sent. This relieves you of the need of keeping track of where a packet ends and another begins.
142+
143+
The `chord` argument contains the packet of the current chord as specified by the protocol in use. This is *NOT* simply a list of chorded steno keys of the form `[STN_E, STN_U, STN_BR, STN_GR]`. Refer to the appropriate protocol section of this document to learn more about the format of the packets in your steno protocol/mode of choice.
79144
145+
The `n_pressed_keys` argument is the number of physical keys actually being held down.
146+
This is not always equal to the number of bits set to 1 (aka the [Hamming weight](https://en.wikipedia.org/wiki/Hamming_weight)) in `chord` because it is possible to simultaneously press down four keys, then release three of those four keys and then press yet another key while the fourth finger is still holding down its key.
147+
At the end of this scenario given as an example, `chord` would have five bits set to 1 but
148+
`n_pressed_keys` would be set to 2 because there are only two keys currently being pressed down.
80149
81150
## Keycode Reference :id=keycode-reference
82151
83-
As defined in `keymap_steno.h`.
152+
You must include `keymap_steno.h` to your `keymap.c` with `#include "keymap_steno.h"` before you can use these keycodes
84153
85154
> Note: TX Bolt does not support the full set of keys. The TX Bolt implementation in QMK will map the GeminiPR keys to the nearest TX Bolt key so that one key map will work for both.
86155
@@ -124,10 +193,10 @@ As defined in `keymap_steno.h`.
124193
|`STN_SR`|`STN_SR`| `-S`|
125194
|`STN_DR`|`STN_DR`| `-D`|
126195
|`STN_ZR`|`STN_ZR`| `-Z`|
127-
|`STN_FN`|| (GeminiPR only)|
128-
|`STN_RES1`||(GeminiPR only)|
129-
|`STN_RES2`||(GeminiPR only)|
130-
|`STN_PWR`||(GeminiPR only)|
196+
|`STN_FN`|| (Function)|
197+
|`STN_RES1`||(Reset 1)|
198+
|`STN_RES2`||(Reset 2)|
199+
|`STN_PWR`||(Power)|
131200
132201
If you do not want to hit two keys with one finger combined keycodes can be used. These are also defined in `keymap_steno.h`, and causes both keys to be reported as pressed or released. To use these keycodes define `STENO_COMBINEDMAP` in your `config.h` file.
133202

quantum/keyboard.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void keyboard_init(void) {
381381
#ifdef ENCODER_ENABLE
382382
encoder_init();
383383
#endif
384-
#ifdef STENO_ENABLE
384+
#ifdef STENO_ENABLE_ALL
385385
steno_init();
386386
#endif
387387
#ifdef POINTING_DEVICE_ENABLE

quantum/keymap_extras/keymap_steno.h

+28
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,31 @@ enum steno_combined_keycodes {
8989
STN_COMB_MAX = STN_EU,
9090
};
9191
#endif
92+
93+
#ifdef STENO_ENABLE_BOLT
94+
// TxBolt Codes
95+
# define TXB_NUL 0
96+
# define TXB_S_L 0b00000001
97+
# define TXB_T_L 0b00000010
98+
# define TXB_K_L 0b00000100
99+
# define TXB_P_L 0b00001000
100+
# define TXB_W_L 0b00010000
101+
# define TXB_H_L 0b00100000
102+
# define TXB_R_L 0b01000001
103+
# define TXB_A_L 0b01000010
104+
# define TXB_O_L 0b01000100
105+
# define TXB_STR 0b01001000
106+
# define TXB_E_R 0b01010000
107+
# define TXB_U_R 0b01100000
108+
# define TXB_F_R 0b10000001
109+
# define TXB_R_R 0b10000010
110+
# define TXB_P_R 0b10000100
111+
# define TXB_B_R 0b10001000
112+
# define TXB_L_R 0b10010000
113+
# define TXB_G_R 0b10100000
114+
# define TXB_T_R 0b11000001
115+
# define TXB_S_R 0b11000010
116+
# define TXB_D_R 0b11000100
117+
# define TXB_Z_R 0b11001000
118+
# define TXB_NUM 0b11010000
119+
#endif // STENO_ENABLE_BOLT

0 commit comments

Comments
 (0)