ZeroPhone uses a microcontroller to offload some tasks and to get some peripherals that Pi Zero doesn't have.
An ATMega328P is used, in a TQFP-32 package. 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. The pinout is as follows:
|Keypad matrix pins|
|Pi Zero-connected pins|
|Pin Number||ATMega pin||Arduino pin||Function||Used for||Firmware support|
|7||PB6||XTAL1||16MHz crystal connection|
|8||PB7||XTAL2||16MHz crystal connection|
|14||PB2||10||DISPLAY_BL||Display backlight (i.e. TFT)||No|
|26||PC3||A3||KEYPAD_INT||Pi Zero communication||Yes|
|27||PC4||A4||SDA||Pi Zero communication||Yes|
|28||PC5||A5||SCL||Pi Zero communication||Yes|
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.
Compiling the firmware
Current firmware is Arduino-based, so Arduino IDE can be used to compile and flash the firmware. You need to add the Keypad library in the library manager, as pictured in the two pictures on the left.
Flashing the firmware
You can use the 6-pin header and a USB-UART- 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)
- 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). This might be solved in Delta revisions, but the solution wasn't tested. For now, be very careful about connecting the serial programmer in the wrong way.