Special characters in tmk_keyboard firmware

anker

05 Jun 2017, 20:39

I'm in a friendly competition at work, were we aim to make our first mechanical keyboard each.

Im gonna build it from scratch, which means Im gonna make the casing do all the soldering etc., but I'm stuck on the firmware. I've read this great article
workshop-f7/how-to-build-your-very-own- ... t7177.html

And off course looked at the source code on github
https://github.com/tmk/tmk_keyboard
And searched and searched and searched and read and read and read

It seems straightforward if you are used to an american keyboard.
But I'm from Denmark so we have three extra characters Å next to the p and ÆØ next to the L. That also means that <>(),;.: etc. are placed entirely different places. How do i change the SHIFT combinations and place ÆØÅ

I like my language a lot, and am not really inclined to learning a new keyboard layout :-)
I would imagine a lot of nationalities have the same issue (Germans, Swedish people etc. etc)

Findecanor

05 Jun 2017, 21:25

You can't. The keyboard does not send letters, it sends a code for the physical key over the wire. The host computer then looks up the character depending on which keys you have pressed from a "keymap" (or whatever it is called in the OS you are using). You can see and change the keymap or "keyboard layout" in the operating system's control panel/preferences.

This allows keyboard manufacturers to not have to manufacture or program electronics differently for different markets. They just print different letters on the keys. It also means that you can type Danish with a keyboard that has other letters printed on it (as long as you don't need to watch the keyboard to type ...).

The firmware source code just uses the names for the US-ANSI (US-English) letters that are printed on the keys. Unless/until you have learned them, you would have to look up pictures of US layout and Danish layout and match symbols on the same positions.
However ... There are two physical keys that are different between US-ANSI and Danish layouts:.
1. The key between left Shift and Z is "KC_NONUS_BSLASH" (named such because there is where the backslash symbol is in British layout).
2. The key in-between Ø and Enter is equivalent to the \ key in US layout: KC_BSLASH.
(BTW, The KC_NONUS_HASH is in the USB standard and was intended for this key ... but it turned out that nobody used it. It won't be recognized by most operating systems.)

Note that TMK's firmware often uses macros for keyboard layouts that adds the "KC_" prefix so that you don't have to type them so often.

anker

05 Jun 2017, 21:47

Hmmmm I'm not really sure I understand. That means that in the american layout the : is equal to Æ

But if I can't change the layout at all, why then the keyboard matrix? I should be able to change qwerty to ytrewq if i wanted to in the keyboard matrix in tmk_keyboard.

Findecanor

05 Jun 2017, 22:02

I'm sorry if I confused you with the term "physical key". It is rather, "logical" key...
Yes, The code for the Æ key is KC_SCOLON. (semi-colon is the symbol you get in US-ANSI when not pressing Shift )

The electrical keyboard matrix is up to the individual keyboard. I suggest that you choose whatever matrix is easiest for you to wire that gets the job done.
You would need to write your own source code that maps from keyboard matrix to the KC_ - codes. The convention in TMK is to use macros for this. Do look at some of the existing examples under "tmk_keyboard/keyboard" and do what they do.

User avatar
Scarpia

05 Jun 2017, 22:10

@anker you can move keys around physically (like qwerty to ytrewq) but you can't change what an individual key does. I'm sorry if this is confusing, let me rephrase:

Når du trykker på 'æ', sender dit keyboard ikke tegnet 'æ', men derimod en keycode som vi for enkelheds skyld kan sige er et tal mellem 0 og 255 (KC_ koderne i TMK repræsenterer disse talværdier). Denne keycode oversættes af operativsystemet til tegnet æ, hvis din maskine er indstillet til dansk tastaturlayout, eller til semikolon (;) hvis den er indstillet til et US ANSI layout.

Der findes således kun et begrænset antal keycodes, som genbruges til alle tastaturlayouts, og disse layouts er så standarder som indbygges i alle styresystemer fra Windows til Mac og alle Unix/Linux-varianter.

Dit tastatur ved altså ikke hvilket sprog det har, så du kan bare kode TMK så tasterne sender keycodes som til et standard ISO layout (det er let nok, du kan bruge TMK keymap editoren), og så længe din computer er indstillet til dansk layout, så virker det som det skal.

God fornøjelse!

User avatar
Scarpia

05 Jun 2017, 22:20

A few hints:

æ = KC_SCLN
ø = KC_QUOT
å = KC_LBRC
-_ = KC_SLSH

anker

05 Jun 2017, 22:39

OK this makes more sense, but still confusing.

So according to my OS keyboard setting which i danish, then it just knows that where I have inputtet the number 8, the SHIFT +2 combination is (

And using the https://github.com/tmk/tmk_keyboard/blo ... eycode.txt
I just have to look at the american and danish keyboard to find that the ; semicolon is in the place of < and therefore KC_COMM is the correct keymap.

And a huge thanks for the danish @scarpia
Nice to know theres some interested danes around :-)

So if I understand this, I can now begin to contemplate which keyboard-size i want. I'm gonna install a keycounter and check which keys I actually use and I've already ordered the Teensy++ and a sample of cherry mx switches :-)

User avatar
obfuscated

06 Jun 2017, 21:39

The keyboard sends USB HID codes (defined here http://www.usb.org/developers/hidpage/Hut1_12v2.pdf)
Then the HID driver interprets them as the appropriate symbols.
If you want to have non default shift+Something keys you need to implement your own protocol and then write a keyboard driver that supports it.

I'm wondering if this could be handled as a community project? Implement a protocol and drivers for the major OSes which could be used by the major DIY keyboards and firmwares.

User avatar
suka
frobiac

06 Jun 2017, 23:03

But it is still just a matter of implementation how flexible HID codes and modifiers can be mapped to different or the same layers in custom firmwares.

For example, I'm using special characters that do require AltGr, Shift or no modifiers on German qwertz host OS all on one layer, but without pressing that modifier, only the layer key - In TMK, this can already be implemented via macros, IIRC.

So while this is indeed a nuisance to support for different host language layouts and requires slightly larger mapping structures, it is an OS agnostic approach that is compatible with any device that supports HID devices.

If you decide to implement direct Unicode support, however, you'll definitely want to think about custom host drivers, but good luck with all the details...

Post Reply

Return to “Keyboards”