megi's PinePhone Development Log RSS


2021–06–14: Pinephone keyboard firmware

So I managed to write and test my USB flashing tool for Pinephone keyboard.

I've also managed to write FOSS firmware for the keyboard, that can provide 12×6 bitmap of all currently pressed keys. So any combination you'll manage to press will be properly detected, without limit.

Currently this interface is consumed using a userspace daemon that waits for H->L transition on pin PL12 (POGO interrupt pin) and reads out the current bitmap of all pressed keys.

In the future this daemon can provide a userspace implementation of Linux input device. This is a way to easily support any kind of keymap without having to touch the firmware. All the mapping could be done in userspace and can be easily modifiable by users, without any re-flashing of the firmware. Userspace input devices behave just like the ones provided by the kernel, and work everywhere incl. Linux console.

I've also investigated the charging controller inside the keyboard, and it can be controlled over I2C from the phone itself. I've demonstrated reading of battery voltage/current and status of the button on the side of the keyboard. This button is connected to the charging controller.

Here is a repository with some of the code:

And here you can see the code in action:

Hardware-wise, the prototype I have has some issues. Some keys don't react well to being pressed (all the keys on the top row), and enter also sucks. Control and C keys are merged (pressing one, presses the other one too), and Z key is stuck (+ one other row/column combination is shorted). Shorted rows/columns on my prototype are R4/C2 and R5/C4. It may be better if enter key had two membrane contacts, because it doesn't press/react well due to its size.

All in all, things look rather bright on the software/firmware front. :) I'll probably continue hacking on the keyboard's software next weekend.