Goal

During the Hackaday tiny game console, I wanted to create the smallest possible gaming console for two people. two buttons, two pixels was the minimum I found to be actually funny.

Games

You can select the game you want by pressing the select button (then LEDs are illuminated with the game color), then press the OK button : the leds blink a few times then the game begins.
![big game in action !](pics/2p2p.svg)

RED game: Tennis / Pong

In this game the ball is illumination: when your LED is blue the ball is on your side. Hit it by pressing your buttons, the your LED will get less and less illuminated and your opponents more and more. When the LED of you opponent illuminated enough, s/he can press the button and send it back to you. If course, if you press too late or too soon, you miss and loose the game. Besides, the more you press your ball late, the fastest it goes to the opponent (but the closer you are missing it !)

YELLOW game: mash it!

This game is simpler : when the game begins, you have a few seconds to mash it as much as possible. The player that press the most their button won.

GREEN game: duel

All is calm and quiet for a (random) moment ... until both LEDs illuminate : then player who is the first to shoot (press their button) when the light goes on wins !
CYAN game: same color

Both lights lighten with a given color. Try to remember your color, then both LEDs go red. When you press the button you change the hue of your LED : the player who has the color closest to the original color wins !

BLUE game: sync it

LEDs are cycling randomly between colors. When both colors are the same, press the button : the player who pressed first wins the game.

Hardware conception

The hardware itself is very minimalist : one STM32F030F4 (50cts genuine part, 16k Flash, 4k RAM microcontroller - it's great !). This was the cheapest chip I could find that I had a programmer ready. The board itself has two buttons directly plugged on GPIO, 2 ws2812 RGB LEDs and a reset button with 4 passive components, no crystal or voltage regulator is needed : chip uses its internal oscillator, and the 3.7v delivered by a battery is enough to run the ws2812 and low enough to suit the microcontroller.

The PCB itself is 40x13 mm (that's ~1.6x0.5 inches) and can be used as a keychain. Routing so few components was simple on a 2 layers board and manufacturing 5 boards quite quick.

Software

Software is written in C and is tiny, not in that the resulting binary is absolutely small (it's 3kB so it's *relatively* small), but is interesting in that it's 2 250-lines files: one for the hardware support (`stm32f030.c`) and one for the games logic (shockingly named `games.c`), for a grand total of around 500 lines. Two files means there is no extra library or hardware abstraction layers besides CMSIS (which is a set of header definition files to designate ports, bits and addresses by name instead of just numbers). All code is under your eyes, from the first cycle to the last.

To flash the binary I used the open [stlink](https://github.com/stlink-org/stlink) opensource utility on linux and a $5 st-link clone probe to flash the chip.

To build it you don't need any download besides gcc for arm embedded and make : no IDE, no special package besides `make`, a terminal and an arm32-flavored gcc compiler.

You CAN debug the program on-chip by installing gcc-multiarch.

There is also a SDL "hardware" file used to "emulate" the console using SDL on linux by example. It's also one file.

Simply, a board definition provides one function : `uint8_t frame(struct Color *leds)` : you send it two RGB colors, it sets the LEDs with those colors, waits a bit and read buttons then send it back to you. Simple. The hardware also takes care of initializing the board and calls you game starting function, `game_main()`. That's it !