How wagiminator/attiny814-usb-pd-adapter works
Purpose and Entry Points
This repository delivers a complete USB-C Power Delivery trigger/monitor: PCB manufacturing artifacts plus AVR firmware. The runtime entry point is the Arduino/megaTinyCore sketch at software/USB_PD_Adapter.ino; a prebuilt image is software/usb_pd_adapter.hex. Hardware implementation sources are distributed as hardware/USB_PD_Adapter_schematic.pdf, hardware/USB_PD_Adapter_gerber.zip, and hardware/USB_PD_Adapter_BOM.tsv.
Hardware Power and PD Boundary
A USB-C PD supply is negotiated by the CH224K receiver, which supports selectable 5/9/12/15/20 V output. The ATtiny drives the chip’s three CFG lines to request a voltage and reads its open-drain PG status to determine whether negotiation succeeded. This separates USB-PD protocol handling (CH224K hardware) from firmware policy/UI. Board connectivity and components are defined in hardware/USB_PD_Adapter_schematic.pdf and hardware/USB_PD_Adapter_BOM.tsv.
Embedded Control Firmware
software/USB_PD_Adapter.ino coordinates the device’s stateful control loop:
• reads SET and RESET user inputs;
• advances the selected PD voltage;
• writes CH224K configuration pins and waits for PG;
• reads output telemetry;
• calculates/display voltage, current, power, and accumulated energy.
It targets several tinyAVR 0/1-series chips (including ATtiny204/214/404/414/804/814/1604/1614) and runs at 1 MHz to limit regulator heating/current demand.
Measurement and Display Data Path
Output power traverses a 10 mΩ shunt monitored by INA219. The MCU obtains bus voltage and current over I²C, derives power and energy, then renders values and negotiation feedback to the SSD1306 128×32 OLED over the shared serial peripheral interface. The measurement/UI logic is consolidated in software/USB_PD_Adapter.ino; the electrical integration is captured by hardware/USB_PD_Adapter_schematic.pdf.
User-Facing Device Flow
Physical control is local, not networked: USB-C source → negotiated high-voltage output terminal → attached load. SET selects and applies a request; the display indicates pending/success status; RESET clears the energy accumulator. There is no server, database, cloud service, or host runtime in normal operation. The ATtiny, CH224K, INA219, OLED, buttons, 3.3 V regulator, and output terminal form the material deployment boundary.
Build, Targeting, and Flashing
Firmware can be built/uploaded through Arduino IDE with megaTinyCore or through software/makefile using avr-gcc. The Makefile selects a DEVICE, programmer, and serial port, produces AVR firmware, configures fuses, and programs through UPDI. Device-specific AVR headers and link artifacts are vendored under software/include/avr/ and software/include/dev/.
Programming Toolchain Boundary
The repository vendors flashing support rather than relying solely on a system programmer: software/tools/pymcuprog/prog.py fronts bundled pymcuprog libraries, including serial-UPDI transport and device metadata such as software/tools/pymcuprog/libs/pymcuprog/deviceinfo/devices/attiny814.py. software/tools/avrdude/avrdude.conf provides an alternate AVR programmer configuration. These tools interact with an external 3.3 V-compatible UPDI programmer; they are provisioning infrastructure, not device firmware behavior.
Main entry points: USB_PD_Adapter_schematic.pdf CH224K PD receiver · USB_PD_Adapter.ino Control and UI loop · usb_pd_adapter.hex Prebuilt firmware image · makefile AVR build rules
Components 16
Device Hardware
PCB power, sensing, and local controls.
- USB-C PD source
- CH224K PD receiver · Negotiates one of the selectable USB-PD voltages.
hardware/USB_PD_Adapter_schematic.pdf - Output terminal & load
hardware/USB_PD_Adapter_schematic.pdf - 10 mΩ shunt
hardware/USB_PD_Adapter_schematic.pdf - INA219 monitor · Measures output bus voltage and shunt current.
hardware/USB_PD_Adapter_schematic.pdf - SET / RESET buttons
hardware/USB_PD_Adapter_schematic.pdf - SSD1306 OLED
hardware/USB_PD_Adapter_schematic.pdf - PCB manufacturing artifacts · Defines board connectivity and production components.
hardware/USB_PD_Adapter_gerber.zip
Embedded Firmware
ATtiny control and measurement runtime.
- tinyAVR controller · Runs at 1 MHz to reduce regulator heating and demand.
- Control and UI loop · Applies requests, waits for PG, calculates energy, and renders status.
software/USB_PD_Adapter.ino - Prebuilt firmware image
software/usb_pd_adapter.hex
Build & Provisioning
AVR build and UPDI flashing support.
- AVR build rules · Selects device, programmer, port, fuses, and firmware build.
software/makefile - Vendored AVR headers
- Bundled pymcuprog · Provides serial-UPDI transport and device metadata.
software/tools/pymcuprog/prog.py - AVRDUDE configuration
software/tools/avrdude/avrdude.conf - External UPDI programmer
Connections 19
- USB-C PD source → CH224K PD receiver: USB-C PD
- CH224K PD receiver → Output terminal & load: negotiated output
- Output terminal & load → 10 mΩ shunt: load current
- 10 mΩ shunt → INA219 monitor: bus and shunt sense
- SET / RESET buttons → tinyAVR controller: SET / RESET
- tinyAVR controller → CH224K PD receiver: CFG voltage request
- CH224K PD receiver → tinyAVR controller: PG status
- INA219 monitor → tinyAVR controller: I²C telemetry
- tinyAVR controller → SSD1306 OLED: shared serial display data
- Control and UI loop → tinyAVR controller: executes on
- Control and UI loop → CH224K PD receiver: negotiation policy
- Control and UI loop → INA219 monitor: power and energy calculation
- AVR build rules → Prebuilt firmware image: builds
- Vendored AVR headers → AVR build rules: target definitions
- Prebuilt firmware image → External UPDI programmer: flash image
- Bundled pymcuprog → External UPDI programmer: serial UPDI
- AVRDUDE configuration → External UPDI programmer: alternate programming
- External UPDI programmer → tinyAVR controller: programs and sets fuses
- PCB manufacturing artifacts → CH224K PD receiver: board implementation