Just for fun, I designed a cheap USB gamepad using CH551G. The design files are at
EasyEDA, and are in Public Domain.
I'm not familiar with the CH551G yet, and I'm not particularly happy about how the wiring turned out, so all comments and suggestions are welcome!
Schematic:
Top layer:
Bottom layer:
The core idea is that the gamepad is usable with just the basic parts. Ordering five PCBs from JLCPCB (it's 98mm by 48mm) and the parts from LCSC, the total for five gamepads should be on the order of USD $10 plus shipping (although I didn't check the button caps; the 12mm buttons have the standard square 3.8mm, and the smaller are 6mm tactile switches without caps). The bottom two buttons don't have to be populated, they're for reset and programming. (I probably should add pads that one could short with a paperclip or something if the buttons are not populated. Opinions?)
(I also think that adding through holes for the USB +5V, D+, D-, and GND might be a good idea: that way, one could simply scavenge a cheap USB cable, and solder the other end directly to the board. It is only 12 Mbit/s HID stuff, so this should not affect the signal integrity too much, but I'm not sure. Anyone know?)
However, the gamepad can be paired with a second board with the same shape, and holes for the buttons, and a small OLED display. (I haven't done this board yet, but it basically has a 3V regulator, a buffer to convert the 5V SCK and DO to 3V, bypass capacitors, and the passives needed for the OLED panel itself – the idea is to use raw panels with flat flex cable, not modules, from BuyDisplay or similar. Not affiliated, just happy with their documentation.)
The locations for support struts are marked with silkscreened circles on both sides of the board, in case one needs to drill a small hole.
This does increase the price a bit, but allows the display to show the current keys being produced – the gamepad should be usable with online/HTML games, you see, not just stuff that supports gamepads. Also, I'm thinking of having a simple HID interface for Python or similar to change the display. For example, you could have a Python program running, and showing current time, and perhaps number of unread emails if any. The pad has 12 buttons, so a couple of them could be reserved for configuration/OLED display use.
The current board has four holes, and silkscreen circles where additional struts can be added. The idea is that one can easily design and 3D print the "enclosure" in two parts, sandwiching the board itself; or, as I already said, use two PCBs, or with just a single PCB: modular.
Software-wise, it'll probably be a combined keyboard-gamepad device. The user should be able to choose the keypresses/buttons the pad produces, either from preprogrammed sets in flash, or via HID using a simple program (although that will lose the settings whenever the pad is disconnected).
I'm not sure if I'll use C or 8051 assembly for this yet; both are quite acceptable for me.
Electrically, the buttons are in a 3×4 matrix. There are four outputs, and three inputs. Each button has a Schottky diode (half of a BAT54C). Each input has a 10kOhm current-limiting resistor, and a 100k pull-down resistor to ground. Only one of the four outputs is high at any time, and selects the set of three buttons being read.
All buttons are 4-pin, with only two diagonal pins connected, to ensure one can use generic switches (as long as the size is roughly correct).
As I understand it, the pins on CH551G are high at bootup. This way, no matter if some of the buttons are pressed and all seven I/O lines are output-high or output-low, there is no problem: the diodes protect the outputs, and the resistors the inputs, in all cases.
Again, all comments and suggestions are welcome, especially if you see something in the schematic or boards that looks suspicious or wrong!