Multifunctional keypad
1 Introduction
Use ch55x (ch551 / ch552 / ch554) microcontroller and use ch55xarduino to implement USB HID. It is not only fully compatible with ordinary numeric keypads, but also has more extended functions.
2 knowledge points
(1) Learn keyboard design ideas and methods;
(2) Understand the periphery of CH552;
(3) Use arduino to write programs;
(4) Learn to use Lichuang EDA to design schematic diagrams and PCB diagrams;
(5) Learn the composition of PCB boards and factory production processes;
3 Introduction to onboard resources
(1) A 16P TYPE-C interface;
(2) 17 mechanical shafts;
(3) Two LEDs to indicate the current mode;
4.1 Monolithic peripherals
There is nothing much to say about the peripherals of ch55x. It uses 5V input. Just add two decoupling capacitors at 5V and 3V3 according to the Datasheet.
The download circuit is also very simple. Pull DP low during startup to enter download mode.
4.2 Key array
In order to ensure that there is no conflict between the keys, the wiring method used is a bit expensive. There is a big guy on the open source platform who has a more subtle way to achieve 64-key full-key rollover. It is not practical here.
4.3 LED
Since there is only 1 IO left, one IO is used to control two LEDs.
As we all know, GPIO has three states, namely high and low levels and high resistance, so an NMOS is used to implement it.
- When IO is low, NMOS is turned off and LED4 lights up;
- When IO is high, NMOS is turned on and LED3 lights up;
- When IO is high resistance, both LEDs will not light up;
- The IO configuration is PWM. When the frequency is high enough, it can be approximately seen as two LEDs lighting up at the same time;

5.PCB drawing
It is not difficult to pull the wires on this board. Just pay attention that the wires between the two layers are basically vertical.
6.Welding
First put a little solder paste on the pad and put all the components on it

Turn on the air gun at 370 degrees, wind speed 2, and blow for about ten seconds.

Power on and test, insert the TYPE-C cable, it can be recognized normally (download mode)

Weld the tea shaft

7.Code
7.1 The idea of key scanning
According to the key array, we first pull down these IOs in A1-A5 in sequence. Each time an IO is pulled down, we configure A6-A9 into input pull-up mode and scan the records in sequence.

7.2 Software filtering
Taking into account possible noise, perform a filtering and key simulation


7.3 Mode switching (deleted)
The mode switching here is implemented by offsetting the array.

8. Existing problems with firmware
- It seems that ch55xarduino cannot configure the pin to a high-impedance state. The pinMode is set to INPUT, which is actually high level. It is impossible to turn off two LEDs at the same time. It does not affect the use.
Due to some problems caused by mode switching, the mode switching function has been deleted and the following BUGs have been resolved.
- Switching modes when other keys have been pressed will cause the OS to think that the key has been pressed, and it can be restored by pressing any key.
- (A1, A7) of the button matrix will be recognized as (A1, A6) after the first scan. This problem is serious. It is recommended to temporarily block this button. The reason has not been found yet.
9. Appearance


The base is glued together using another piece of board and hot melt glue.
Considering that the jp next door has a 3D printing activity for free, I may paint the shell in the future.
2021/6/15 I can’t afford to play next door, I can’t buy 3D printing for free, and the shell will not be painted.
10. Traps that have been stepped on
The ch55xrduino linux version of 0.0.9 has a path exception (or there is an omission in the packaging). The compilation error reports that avr-objcopy cannot be found. The Arch system solution is as follows
sudo pacman -S avr-gcc
vim /home/[YOUR-USER-NAME]/.arduino15/packages/CH55xDuino/hardware/mcs51/0.0.9/platform.txt
Line 41
compiler.tools.path=xxxxxxxxxxxxx
Change to
compiler.tools.path=/usr/bin
Just save and exit
The window version cannot use the built-in download tool to burn the program. It seems to be a permissions issue? Anyway, there is no solution. You can export hex and burn it with the official burning software.
The last two comments are that the feel of the black switch is really bad. Who is it that said that the black switch is suitable for gaming?
I am an old fish at level 54 in the former priest server, UID: 163114852, welcome to harass~
Note that the files in the attachment may not be updated in a timely manner