How to build a keyboard
Step 1: Keyboard without keys
First let us make a USB keyboard that issues X characters (once per second), the Arduino Micro development board is a nice choice for this goal because it features ATMEGA32U4MICROCONTROLLER (AVR MicroCrontroller) and the same processor is UHK Brain.
Speaking of USB-Capable AVR MicroControllers, a lightweight USB framework for AVR (Lufa) is the selection of libraries. It makes these processors become "brains" of printers, MIDI devices, keyboards, or any other USB device type.
When the device is inserted into the USB port, the device passes some special data structure called the USB descriptor. These descriptors inform the host the type and nature of the device connected and represent it by a tree structure. More than one function can be implemented, but multiple. This makes things more complicated. Let's take a look at the structure of the UHK descriptor:
Device Descriptor
Configuration Descriptor
Interface Descriptor 0: GENENRICHDI
Endpoint Descriptor
Interface Descriptor 1: KEYBOARD
Endpoint Descriptor
Interface Descriptor 2: Mouse
Endpoint Descriptor
Most keyboards only expose a single keyboard interface descriptor, which is reasonable. However, UHK will also expose the mouse interface descriptor because the user can instruct the keyboard to control the mouse pointer, so the keyboard can be used as a mouse. The generichi interface service is equivalent to a communication channel for exchange configuration information for all feature keyboards.
Now we have created a descriptor. The following code demonstrates its first time to send X characters per second:
USB is a query protocol that means that the host regular interval (usually 125 / s) query devices to find out if there is any new data transmission. The callback associated with this is a callback_hid_device_createHidReport () function, and the ISSecondelapsed variable is one-to-host scan code, which is set to 1 on the basis per second, and set to 0 when the callback is set.
Step 2: Four keys Keyboard
At this point, our keyboard is not very useful, if we make a practical category on this, it will be good. To do this, we need some keys that need to be placed in a keyboard matrix. A full-size 104 key keyboard can have 18 columns 6 lines, and we must simplify it into 2x2 keyboard matrix, this is a schematic:
It is rendered in the development board:
Suppose the ROW1 connection PINA0, ROW2 connection PINA1, COL1 connection portb0 and COL2 connection portb1, then the scan code will be like this:
The code scans one column once and read the status of the personal key switch, and then saves this status to an array, and the relevant scan code will send these array-based states through the Callback_HID_DEVICE_CREATEHIDREPORT () function described above.
Step 3: Two parts of a keyboard
So far, we have built a normal keyboard. But our goal is advanced ergonomics. In view of both people have two hands, we'd better add another half keyboard.
The other half of the keyboard will have another keyboard matrix, repeat the steps before. The exciting is the communication between the two-part keyboard, here there are three most popular electronic equipment interconnect protocols: SPI, I2C and UART. In practice, we will use the UART in this case:
UART needs to use the same baud rate, data bits, and stop bit. Now the left button is sent to the right-click on the UART to press the button or the release button, and the right-click on these information is half-processed and the state of the full keyboard matrix array array is operated. .
Send information on the left button:
The right-click acceptance information is as follows:
The KeyboardRxCallback () interrupt handler is triggered when a byte is received by UART, taking into account the interrupt handler should be executed as soon as possible, so the received information will be placed behind a ring-shaped buffer left processing. The ring buffer will eventually be processed by the primary loop, and the keyboard matrix will be updated based on information.
What is mentioned above is the easiest way to achieve this point, but the final agreement is more complicated. You need to consider processing of multi-byte information, and personal information should also check their integrity through CRC-CCITT checks.
At this point, our experimental board model may make you impressive:
Step 4: Meet the LED display
This is to allow users to define multiple application-specific key maps to increase production efficiency. Users need to realize some ways that are being used for key maps, an integrated LED display is built into the keyboard, and the figure below shows this model:
The LED display is implemented by an 8x6 matrix:
Each two lines of red LED symbols represent the segmentation of the 14-Segment LED, and the white LED symbol represents additional three status indicators.
The current is driven by the LED and lit it, the corresponding column is high voltage, and the corresponding range is low voltage. A interesting result of the system is that only one column can be enabled at any given time, while other columns are disabled. Some people may think that this system cannot work throughout the LED, but in reality, the column and line updates are too fast to see obvious flicker with the human naked eye.
The LED matrix is driven by two integrated circuits (ICs), a drive line, a driver column, and the source IC of the drive column is the PCA9634 I2C LED driver:
The drive line is TPIC6C595:
Let us see the relevant code:
Ledmatrix_updateNeXTROW () will be called at speeds per millisecond, and the LED matrix is updated, and the LEDMatrix array stores the state of a single LED light, and the status information is derived from the Press / Release button event through the UART.
Overall situation
Here we have gradually established all the necessary components for your keyboard. Now you need to start from the global, just like a microcomputer network: a large number of nodes are connected to each other. The difference is that the distance between the measurement nodes is not rice or kilometers, but cm, and the node is not a mature computer, but a miniature integrated circuit.
But most of them say the details of the keyboard device, and there are not many UHK agents. The UHK agent is a configurer application that meets the user's custom demand through the keyboard. Can be seen in the following code:
Create prototype
There is a CAD design before everything is manufactured:
3D printing keyboard will look like this:
Design of printed circuit board based on mechanical design and principle. The PCB of the right half in Kicad will be like this:
The PCB surface mount assembly must be manually solder:
Finally, after 3D printing, polishing, assembly, we will get such a prototype:
Related Reading:
Give nostalgic game ashes flour: Homemade a Raspberry Division
Teach you to make an open source PCB printer
A thinner speaker, bright your eyes!
35 $ buying computer, running Windows10 Toronto
Raspberry Part 2: 6 times Performance + 1GB Memory
Google Project ARA module mobile phone can guide the future
Our other product: