-
KeyboardWhiz hardware background
06/11/2022 at 22:00 • 0 commentsLaptop keyboard FPCs can have up to 32 pins - and "keyboard+other things" connectors, on like Thinkpad or Framework keyboard modules, can even have up to 50 pins. It's hard to find a cheap USB-capable microcontroller with so many pins.
A typical keyboard uses 24 pins for the actual keys and 3-4 pins for the LEDs. The keyboard FPCs often have 30-32 pins, however - a portion of them NC. This doesn't work.
An Arduino Pro Micro has 18 GPIOs, which is nowhere near enough. Microcontrollers like Teensy tend to be of more help - Teensy 2.0 has 26 GPIOs available, which even allows for two LEDs. Bigger Teensies have more pins, but they're way too expensive for this project's goals. A Pi Pico has 26 GPIOs available too, and is cheaper. Plus, the RP2040 chip itself has 30, so it should be possible to add more features if you make a custom board with the RP2040.
However, in order for 24 pins to be sufficient, you still need to know which pins are used and which aren't - if you don't know that, you still need 32 pins; and for an universal keyboard RE adapter, the assumption is that you don't know which pins are which.
Because of this 32 GPIO requirement, I use GPIO expanders in the KeyboardWhiz. Two 16-bit or four 8-bit GPIO expanders can provide 32 IO pins - leaving the microcontroller with quite a few extra GPIOs. For instance, you can control many extra keys, PWM the backlight control circuit, or even interface to a touchpad over I2C. I use I2C expanders, but it's possible to use SPI expanders, too.
The original KeyboardWhiz only had I2C expanders and connectors on it - so you'd have to connect it to a Raspberry Pi or a HDMI-I2C breakout of some sort, and run Python code communicating with these expanders. As such, it couldn't work as a USB keyboard controller, either. The next KeyboardWhiz version will have a RP2040 in addition to expanders, so you can take control of way more features.
-
Theory
06/07/2022 at 04:07 • 0 commentsA laptop keyboard is a diode-less key matrix. Its keys are distributed in a way that you can press the most important key combinations at once, despite the lack of diodes - to the point where some rows only contain one or two keys.
Often, there's also LEDs for functions like WiFi status, CapsLock and NumLock inside the keyboard, connected to the same FPC connectors. If there's backlight inside the keyboard, it's typically connected separately, however. Sometimes, there's a power button on the keyboard - then, it's also available on the same FPC.
Laptop keyboards typically use 0.8mm pitch FPC connectors, and 1mm connectors were typically used in older laptops. For small and modern laptops, it's not unheard of to use 0.5mm connectors. At times, keyboards use proprietary connectors, sometimes exposing all the signals through them (i.e. Framework or Thinkpad) and sometimes using a separate keyboard controller chip on a sub-board, which uses some kind of low-pin-count interface to talk to the EC (i.e. Dell Latitude E7470).
Typically, there's 8 rows and 16 columns in a keyboard matrix - this helps the EC scan the keyboard, since 8 and 16 are multiples of 8, and it's a bit easier to write code that operates with these. Numpad-equipped laptop keyboards tend to have 18 columns. There's no real difference between "rows" and "columns" - it's just a matrix of keys, either of the two sides can be called by either term, theoretically. For consistency, I use "columns" for the side which uses more GPIOs (so, typically the 16-pin side), since that somewhat represents how keyboards actually look physically - they have few rows and many columns.
As implied in the first paragraph, the key arrangement in the matrix doesn't represent the physical arrangement of the keys on the keyboard. In fact, it's quite a bit different. For a laptop keyboard, you need to be able to press certain keys simultaneously, i.e. Shift/Ctrl/Alt+KEY combos, and Ctrl+Alt+Delete. Laptop keyboards don't use diodes, however - they compensate by dedicating entire columns to certain keys. This explains why a typical keyboard can technically have 128 or 144 spots for keys (8x16 or 8x18), but has way less keys available, typically, from 80 to 100.
[TODO: image]
While scanning the matrix, some GPIOs have to be set as outputs, and some have to be set as inputs. It's quicker to scan through 8 pins than it is to scan through 16 pins. So, "row" pins are typically referred to as KSI (Keyboard Scanning Input, 8 pins that are set as outputs on the EC), and "column" pins are typically referred to as KSO (Keyboard Scanning Output, 16-18 pins set as inputs on the EC). Again, some keyboards might use a different terminology, I haven't checked that - I chose this convention because it makes sense physically.