diff --git a/docs/porting_to_kmk.md b/docs/porting_to_kmk.md index 10ef375..d7390bb 100644 --- a/docs/porting_to_kmk.md +++ b/docs/porting_to_kmk.md @@ -63,6 +63,48 @@ coord_mapping = [ ] ``` +Note: Not all numbers are necessarily used ! The keyboard assumes +`number of line * number of rows` keys. Some of the possible keys might not be +used. For example a keyboard with 60 keys might have 8 rows, 8 cols, allowing +64 total combinations -- hence 64 keys. 4 numbers will then not be used for keys +in the `coord_mapping` (might be anyone of them depending of the wiring). + +### Find your coord mapping +The following code will help you setup your `coord_mapping` by having every key +send its corresponding number. Use it after your pins and module definition +to define both `keyboard.coord_mapping` and `keyboard.keymap`. + +```python +from kmk.handlers.sequences import simple_key_sequence +from kmk.keys import KC + +# *2 for split keyboards, which will typically manage twice the number of keys +# of one side. Having this N too large will have no impact (maybe slower boot..) +N = len(keyboard.col_pins) * len(keyboard.row_pins) * 2 + +keyboard.coord_mapping = list(range(N)) + +layer = [] + +for i in range(N): + c, r = divmod(i, 100) + d, u = divmod(r, 10) + layer.append( + simple_key_sequence( + ( + getattr(KC, 'N' + str(c)), + getattr(KC, 'N' + str(d)), + getattr(KC, 'N' + str(u)), + KC.SPC, + ) + ) + ) +keyboard.keymap = [layer] + +if __name__ == '__main__': + keyboard.go() +``` + ## Keymaps Keymaps are organized as a list of lists. Keycodes are added for every key on each layer. See [keycodes](keycodes.md) for more details on what keycodes are