From 3c2d1690df9d4b993f6b0129cf9b41023f2fca38 Mon Sep 17 00:00:00 2001 From: leviport Date: Wed, 24 Jun 2020 20:14:29 -0600 Subject: [PATCH 1/5] Add my layout, enable media next/prev hotkeys, and start doc --- doc/keyboard-layout-customization.md | 1 + src/board/system76/lemp9/keymap/levi.c | 24 ++++++++++++++++++++++++ src/common/include/common/keymap.h | 3 +++ 3 files changed, 28 insertions(+) create mode 100644 doc/keyboard-layout-customization.md create mode 100644 src/board/system76/lemp9/keymap/levi.c diff --git a/doc/keyboard-layout-customization.md b/doc/keyboard-layout-customization.md new file mode 100644 index 0000000..f0d5b95 --- /dev/null +++ b/doc/keyboard-layout-customization.md @@ -0,0 +1 @@ +# How to customize your keyboard layout with System76 EC diff --git a/src/board/system76/lemp9/keymap/levi.c b/src/board/system76/lemp9/keymap/levi.c new file mode 100644 index 0000000..4802632 --- /dev/null +++ b/src/board/system76/lemp9/keymap/levi.c @@ -0,0 +1,24 @@ +// Default layout + +#include + +uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN] = { +LAYOUT( + K_ESC, K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10, K_F11, K_F12, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, + K_TICK, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_BRACE_OPEN, K_BRACE_CLOSE, K_BKSP, + K_TAB, K_QUOTE, K_COMMA, K_PERIOD, K_P, K_Y, K_F, K_G, K_C, K_R, K_L, K_SLASH, K_EQUALS, K_BACKSLASH, + K_LEFT_CTRL, K_A, K_O, K_E, K_U, K_I, K_D, K_H, K_T, K_N, K_S, K_MINUS, K_ENTER, + K_LEFT_SHIFT, K_SEMICOLON, K_Q, K_J, K_K, K_X, K_B, K_M, K_W, K_V, K_Z, K_RIGHT_SHIFT, + KT_FN, K_Z, K_LEFT_ALT, K_LEFT_SUPER, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_PGUP, K_UP, K_PGDN, + K_LEFT, K_DOWN, K_RIGHT +), +LAYOUT( + K_ESC, K_TOUCHPAD, KT_SCI | SCI_DISPLAY_TOGGLE, K_MUTE, KT_SCI_EXTRA | SCI_EXTRA_KBD_BKL, K_VOLUME_DOWN, K_VOLUME_UP, K_DISPLAY_MODE, KT_SCI | SCI_BRIGHTNESS_DOWN, KT_SCI | SCI_BRIGHTNESS_UP, KT_SCI | SCI_CAMERA_TOGGLE, KT_SCI | SCI_AIRPLANE_MODE, KT_SCI | SCI_SUSPEND, K_HOME, K_END, K_PRINT_SCREEN, K_DEL, + K_PLAY_PAUSE, K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9, K_0, K_MINUS, K_EQUALS, K_BKSP, + K_TAB, K_HOME, K_UP, K_END, K_PGUP, K_Y, K_PGUP, K_HOME, K_UP, K_END, K_L, K_SLASH, K_EQUALS, K_BACKSLASH, + K_LEFT_CTRL, K_LEFT, K_DOWN, K_RIGHT, K_PGDN, K_I, K_PGDN, K_LEFT, K_DOWN, K_RIGHT, K_S, K_MINUS, K_ENTER, + K_LEFT_SHIFT, K_PLAY_PAUSE, K_MEDIA_PREV, K_MEDIA_NEXT, K_VOLUME_DOWN, K_VOLUME_UP, K_MUTE, K_M, K_W, K_V, K_Z, K_RIGHT_SHIFT, + KT_FN, K_Z, K_LEFT_ALT, K_LEFT_SUPER, K_SPACE, K_RIGHT_ALT, K_RIGHT_CTRL, K_PGUP, K_UP, K_PGDN, + K_LEFT, K_DOWN, K_RIGHT +) +}; diff --git a/src/common/include/common/keymap.h b/src/common/include/common/keymap.h index a153634..7605455 100644 --- a/src/common/include/common/keymap.h +++ b/src/common/include/common/keymap.h @@ -54,6 +54,9 @@ uint16_t keymap_translate(uint16_t key); #define K_MUTE (K_E0 | 0x23) #define K_VOLUME_DOWN (K_E0 | 0x21) #define K_VOLUME_UP (K_E0 | 0x32) +// More media keys +#define K_MEDIA_NEXT (K_E0 | 0x4D) +#define K_MEDIA_PREV (K_E0 | 0x15) // Custom scancode #define K_TOUCHPAD (K_E0 | 0x63) From 43b5e3a451b1504c6dcc5995c5b0b25d29c70083 Mon Sep 17 00:00:00 2001 From: leviport Date: Wed, 24 Jun 2020 20:49:38 -0600 Subject: [PATCH 2/5] Add more to the keyboard customization doc (still a WIP) --- doc/keyboard-layout-customization.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/keyboard-layout-customization.md b/doc/keyboard-layout-customization.md index f0d5b95..0c42f3d 100644 --- a/doc/keyboard-layout-customization.md +++ b/doc/keyboard-layout-customization.md @@ -1 +1,28 @@ # How to customize your keyboard layout with System76 EC + +## Dependencies +* Install [sdcc](http://sdcc.sourceforge.net/): `sudo apt install sdcc` +* Install rust nightly + - Install [rustup](https://rustup.rs/) + - Reboot + - Run `rustup install nightly`) + +## Adding your layout +* In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. I named mine `levi.c`. +* In `src/common/include/common/keymap.h` you will find the key definitions. +TODO: elaborate on this + +## Point EC at your keymap +* In `ec/src/board/system76/{model}/board.mk` change `KEYMAP?=default` to the name of your layout. +TODO: There's probably a better way to do this + +## Test build your EC +* From the `ec` directory, run `make BOARD=system76/{your-model}` to make sure it builds correctly. + +## Flash your EC +* If the test build went well, you should be ready to flash your EC: + - Close all running applications. + - Unplug everything from your laptop except the charger. + - Flash with `make BOARD=system76/{your-model} flash_internal` + - When it says, "Waiting 5 seconds for all keys to be released", it is important to not touch the keyboard or trackpad until it turns itself off. + - Once it shuts down, you can power it back on, and your keymap will be active. From 7d558479a341d402e2ae3b0180388a7876395a28 Mon Sep 17 00:00:00 2001 From: leviport Date: Fri, 26 Jun 2020 16:37:34 -0600 Subject: [PATCH 3/5] Improve keyboard layout customization doc --- doc/keyboard-layout-customization.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/doc/keyboard-layout-customization.md b/doc/keyboard-layout-customization.md index 0c42f3d..a153a68 100644 --- a/doc/keyboard-layout-customization.md +++ b/doc/keyboard-layout-customization.md @@ -8,21 +8,26 @@ - Run `rustup install nightly`) ## Adding your layout -* In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. I named mine `levi.c`. -* In `src/common/include/common/keymap.h` you will find the key definitions. -TODO: elaborate on this +* In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. There are two examples to reference in the `lemp9` directory: `jeremy.c` and `levi.c`. +* In `src/common/include/common/keymap.h` you will find a list of the key definitions.h +* You will notice two sets of keys in these layout files. The top one is the standard mapping. The bottom one is the Fn layer, meaning it is active when the Fn key is being held. If you look at the Fn layer in the `levi.c` layout, you will see that there are arrow keys at WASD, media and volume keys on the bottom row, etc. +* I find it easiest to change one key at a time, referencing the key code I am deleting for keeping myself positioned correctly in the list of keycodes. -## Point EC at your keymap -* In `ec/src/board/system76/{model}/board.mk` change `KEYMAP?=default` to the name of your layout. -TODO: There's probably a better way to do this +## Configure your EC to build with your layout +* Create a file it the project's root directory called `config.mk` and add your board and keyboard layout to it. For example, if I want to build lemp9 firmware with Jeremy's layout (which is at ec/src/board/system76/lemp9/keymap/jeremy.c): +``` +BOARD?=system76/lemp9 +KEYMAP?=jeremy +``` ## Test build your EC -* From the `ec` directory, run `make BOARD=system76/{your-model}` to make sure it builds correctly. +* From the `ec` directory, run `make` to make sure it builds correctly. ## Flash your EC * If the test build went well, you should be ready to flash your EC: - Close all running applications. - Unplug everything from your laptop except the charger. - - Flash with `make BOARD=system76/{your-model} flash_internal` - - When it says, "Waiting 5 seconds for all keys to be released", it is important to not touch the keyboard or trackpad until it turns itself off. + - Flash with `make flash_internal` + - When it says, "Waiting 5 seconds for all keys to be released", it is important to not touch the keyboard or trackpad until it finishes writing the new EC and turns itself off. - Once it shuts down, you can power it back on, and your keymap will be active. + - If you changed your layout in such a way that you can't easily type, just plug in a USB keyboard and fix the layout. The USB keyboard's layout will be unaffected. From 0e20b71702d5594e779f8584fb20052d9d6e9268 Mon Sep 17 00:00:00 2001 From: leviport Date: Mon, 29 Jun 2020 07:53:55 -0600 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Jacob Floyd --- doc/keyboard-layout-customization.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/keyboard-layout-customization.md b/doc/keyboard-layout-customization.md index a153a68..6081eb6 100644 --- a/doc/keyboard-layout-customization.md +++ b/doc/keyboard-layout-customization.md @@ -11,10 +11,10 @@ * In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. There are two examples to reference in the `lemp9` directory: `jeremy.c` and `levi.c`. * In `src/common/include/common/keymap.h` you will find a list of the key definitions.h * You will notice two sets of keys in these layout files. The top one is the standard mapping. The bottom one is the Fn layer, meaning it is active when the Fn key is being held. If you look at the Fn layer in the `levi.c` layout, you will see that there are arrow keys at WASD, media and volume keys on the bottom row, etc. -* I find it easiest to change one key at a time, referencing the key code I am deleting for keeping myself positioned correctly in the list of keycodes. +* Hint: To avoid losing your place change one key at a time, referencing the key code you are deleting to keep yourself positioned correctly in the list of keycodes. ## Configure your EC to build with your layout -* Create a file it the project's root directory called `config.mk` and add your board and keyboard layout to it. For example, if I want to build lemp9 firmware with Jeremy's layout (which is at ec/src/board/system76/lemp9/keymap/jeremy.c): +* Create a file in the project's root directory called `config.mk` and add your board and keyboard layout to it. For example, if you want to build lemp9 firmware with Jeremy's layout (which is at `ec/src/board/system76/lemp9/keymap/jeremy.c`): ``` BOARD?=system76/lemp9 KEYMAP?=jeremy From aa69bd693931796e405b56adb24213ff830cca01 Mon Sep 17 00:00:00 2001 From: leviport Date: Mon, 29 Jun 2020 14:10:55 -0600 Subject: [PATCH 5/5] Update keyboard layout doc with suggested changes --- doc/keyboard-layout-customization.md | 43 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/doc/keyboard-layout-customization.md b/doc/keyboard-layout-customization.md index 6081eb6..55fa5fd 100644 --- a/doc/keyboard-layout-customization.md +++ b/doc/keyboard-layout-customization.md @@ -1,20 +1,28 @@ -# How to customize your keyboard layout with System76 EC +# Keyboard layout customization ## Dependencies -* Install [sdcc](http://sdcc.sourceforge.net/): `sudo apt install sdcc` -* Install rust nightly - - Install [rustup](https://rustup.rs/) - - Reboot - - Run `rustup install nightly`) - +* Dependencies are listed in the README file for the EC project. + ## Adding your layout -* In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. There are two examples to reference in the `lemp9` directory: `jeremy.c` and `levi.c`. -* In `src/common/include/common/keymap.h` you will find a list of the key definitions.h -* You will notice two sets of keys in these layout files. The top one is the standard mapping. The bottom one is the Fn layer, meaning it is active when the Fn key is being held. If you look at the Fn layer in the `levi.c` layout, you will see that there are arrow keys at WASD, media and volume keys on the bottom row, etc. -* Hint: To avoid losing your place change one key at a time, referencing the key code you are deleting to keep yourself positioned correctly in the list of keycodes. +* In `src/board/system76/{your-model}/keymap/`, copy `default.c` and rename it. + There are two examples to reference in the `lemp9` directory: `jeremy.c` and + `levi.c`. +* In `src/common/include/common/keymap.h` you will find a list of the key + definitions. +* You will notice two sets of keys in these layout files. The top one is the + standard mapping. The bottom one is the Fn layer, meaning it is active when + the Fn key is being held. If you look at the Fn layer in the `levi.c` layout, + you will see that there are arrow keys at WASD, media and volume keys on the + bottom row, etc. +* Hint: To avoid losing your place change one key at a time, referencing the key + code you are deleting to keep yourself positioned correctly in the list of + keycodes. ## Configure your EC to build with your layout -* Create a file in the project's root directory called `config.mk` and add your board and keyboard layout to it. For example, if you want to build lemp9 firmware with Jeremy's layout (which is at `ec/src/board/system76/lemp9/keymap/jeremy.c`): +* Create a file in the project's root directory called `config.mk` and add your + board and keyboard layout to it. For example, if you want to build lemp9 + firmware with Jeremy's layout (which is at + `ec/src/board/system76/lemp9/keymap/jeremy.c`): ``` BOARD?=system76/lemp9 KEYMAP?=jeremy @@ -28,6 +36,11 @@ KEYMAP?=jeremy - Close all running applications. - Unplug everything from your laptop except the charger. - Flash with `make flash_internal` - - When it says, "Waiting 5 seconds for all keys to be released", it is important to not touch the keyboard or trackpad until it finishes writing the new EC and turns itself off. - - Once it shuts down, you can power it back on, and your keymap will be active. - - If you changed your layout in such a way that you can't easily type, just plug in a USB keyboard and fix the layout. The USB keyboard's layout will be unaffected. + - When it says, "Waiting 5 seconds for all keys to be released", it is + important to not touch the keyboard or trackpad until it finishes writing + the new EC and turns itself off. + - Once it shuts down, you can power it back on, and your keymap will be + active. + - If you changed your layout in such a way that you can't easily type, just + plug in a USB keyboard and re-flash to the default layout until you can + fix. The USB keyboard's layout will be unaffected.