From cc5e7f68e4d58cecfea1e02a0a4181a9be16cca6 Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 19 Feb 2016 03:05:35 +0100 Subject: [PATCH] readme: added example of adding new keyboard layout --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index 679a101..55c6ae9 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ A hardware password manager, built around a Paspberry Pi Zero and [`pass`, the U This is also an entry for [Hackaday.io](https://hackaday.io)'s Pi Zero Contest. +This repo shall also provide code for your own hid-gadgets - the code is meant to be easy to change to suit your needs. + ## Hardware I am using a Raspberry Pi Zero, since it has USB-OTG support and a lot of GPIO to interface an OLED screen, a button matrix for input and maybe even an ESP8266 for WiFi. The OLED I am intending to use has an I²C interface and a screen diagonal of .96". @@ -54,3 +56,47 @@ ls /sys/class/udc > UDC The version of (pass)[https://passwordstore.org] doesn't format the output as nice, so it is easier to work with. Using the `pass-installer.sh` will automatically clone from the original repository, apply the patch and install it (make sure, `patch` and `sudo` is installed). You can then check out `hardpass-demo.sh` to see how to supply a passphrase directly from the command line (without gpg-agent). Keep in mind, that it will show up in your history file! + +## internals of this code +whenever you need to add (or remove) a new keyboard layout, the following changes have to be made: + +### adding a new keyboard layout (example) +1. in `scancodes.h` add the layout to `keysym`-struct: +this identifier does not need to be used outside of scancodes.{h,c}. +``` +struct keysym { + // ... + struct layout de_dv; //dvorak layout + // ... +}; +``` +2. the enum `kbd1` has to be ammended: +``` +enum kbdl { //keyboard layouts: + // ... + de_DV //de_AT-Dvorak +}; +``` +3. in `scancodes.c` you need to add a new column (containing more columns) to the big `keysyms[]` table: +It is suggested to explicitly name `.is_dead` and `.unicode` to avoid confusion. Also notice that `.is_dead` is part of the layout (and goes within the inner braces), while `.unicode` resides in the keysym-struct. +``` +struct keysym keysyms[] = { + //... + {"#", {0x20, 0x02}, {0x31, 0x00}, {0x31, 0x00}, {KEY, MODIFIER}}, + {"^", {0x23, 0x02}, {0x35, 0x00}, {0x35, 0x00}, {KEY, MODIFIER, .is_dead = 1}}, + {"&", {0x24, 0x02}, {0x23, 0x02}, {0x23, 0x02}, {KEY, MODIFIER}, .unicode=OxHEX}, + //... +}; +``` +4. `tolay()` needs a new case to its switch statement: +This is the only place where the `layout`-idenitfier from `keysym` needs to be used. +``` +struct layout* tolay (struct keysym* s, enum kbdl layout) { + switch (layout) { + // ... + case de_DV: return &(s->de_dv); + default: return NULL; + } +} +``` +5. finally, your code must understand the new layout, represented by the `enum kbd1`-entry, `de_DV` in this example. -- 2.39.3