ZeroPhone keypad controller
ZeroPhone uses a microcontroller to offload some tasks and to get some peripherals that Pi Zero doesn't have.
An ATMega328P is used. The pinout is as follows:
TODO: add pinout
The ATMega is connected to Pi Zero through I2C (shared with MCP23017 and expansion headers), and it also has an interrupt line to avoid having to poll the key state all the time.
Parts involved and substitutes
- ATMega328P/168P in TQFP package
- 16MHz/8MHz crystal, one of these:
- CSCTE crystal (small footprint, SMD, 3 pads under the crystal)
- HC-49 through-hole crystal + 2x 18pF capacitors
Sourcing the parts
There are two ways to get the parts necessary:
- Buy them separately from Digikey/Mouser/eBay/etc.
- Get an Arduino Pro Mini clone board and transplant the necessary components with a heat gun
Second way is the preferred way, since you get the ATMega with the right bootloader already flashed and it's going to be cheaper. However, you do need access to a heat gun (or to be skilled enough to desolder TQFP with a soldering iron). Also, you do need to make sure that the Pro Mini board has the TQFP ATMega, though you should be able to see the chip on the photos provided by seller.
Flashing the firmware
Current firmware is Arduino-based, so Arduino IDE can be used to compile and flash the firmware. As for the USB-UART part - the 6-pin ATMega programming header has the same pinout as Arduino Pro Mini, so you can use either general-purpose USB-UARTs or the "FTDI header" (GND-GND-VCC-TX-RX-RST) adapters (like Arduino Serial Light or some Chinese USB-UARTs).
- You can use 5V-only ATMega programming adapters, such as Arduino Serial Light. However, you need to make sure that, when a 5V adapter is connected to the ATMega328P programming header, front board is not connected to the Pi Zero and the back board
- Do not connect the adapter in wrong polarity (the other way around), as that will likely destroy the ATMega.
Current state of firmware
- Scanning keys and sending key values, enabling the interrupt line on each received key
- Vibromotor control
- VIN voltage reading
- Keypad backlight control
- Screen backlight control (will only be necessary if TFT screens will be used with ZeroPhone)
- User-accessible ADC and GPIO control
- Allowing ATMega UART usage for some other things (custom sensors, RFID, POGSAC etc.) (needs some way of bridging I2C to UART in firmware)
Fixed in 0ec32f79 of firmware
- When an LED is connected to Pin 13, certain keys misbehave.
- KEY_LEFT is interpreted as KEY_ANSWER
- KEY_VOLUMEUP is interpreted as KEY_VOLUMEDOWN
- KEY_F3 (KEY_PAGEUP) is interpreted as KEY_1
- KEY_8 is interpreted as KEY_4
- KEY_* is interpreted as KEY_PROG1
- KEY_0 is interpreted as KEY_F5
To avoid this, you can desolder the resistor in series with the LED (as it's much easier to desolder than the LED).
- Connecting a USB serial adapter in reverse polarity appears to burn the ATMega328P (confirmed with 5V Arduino Serial Light - happens almost instantaneously). For now, be very careful about that.