# wagiminator/attiny814-usb-pd-adapter architecture

> Architecture diagram of the GitHub repository wagiminator/attiny814-usb-pd-adapter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wagiminator/attiny814-usb-pd-adapter
- Repository: https://github.com/wagiminator/attiny814-usb-pd-adapter

## Overview

#### 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: [`hardware/USB_PD_Adapter_schematic.pdf`](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf) (CH224K PD receiver), [`software/USB_PD_Adapter.ino`](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/USB_PD_Adapter.ino) (Control and UI loop), [`software/usb_pd_adapter.hex`](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/usb_pd_adapter.hex) (Prebuilt firmware image), [`software/makefile`](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/makefile) (AVR build rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_hardware["Device Hardware"]
  node_usb_c_source{{"USB-C PD source<br/>external power source"}}
  node_ch224k["CH224K PD receiver<br/>PD negotiation IC"]
  node_power_output{{"Output terminal &amp; load<br/>power output"}}
  node_shunt["10 mΩ shunt<br/>current sense"]
  node_ina219["INA219 monitor<br/>power monitor"]
  node_buttons["SET / RESET buttons<br/>local input"]
  node_oled["SSD1306 OLED<br/>local display"]
  node_pcb_artifacts["PCB manufacturing artifacts<br/>schematic, Gerbers, BOM"]
end

subgraph group_firmware["Embedded Firmware"]
  node_attiny{{"tinyAVR controller<br/>ATtiny 0/1-series MCU"}}
  node_control_loop["Control and UI loop<br/>Arduino sketch<br/>[USB_PD_Adapter.ino]"]
  node_firmware_image["Prebuilt firmware image<br/>AVR HEX<br/>[usb_pd_adapter.hex]"]
end

subgraph group_provisioning["Build &amp; Provisioning"]
  node_make_build["AVR build rules<br/>Makefile / avr-gcc"]
  node_vendored_headers["Vendored AVR headers<br/>device headers"]
  node_pymcuprog["Bundled pymcuprog<br/>programming tool<br/>[prog.py]"]
  node_avrdude_config["AVRDUDE configuration<br/>alternate programmer config<br/>[avrdude.conf]"]
  node_updi_programmer{{"External UPDI programmer<br/>3.3 V programmer"}}
end

node_usb_c_source -->|"USB-C PD"| node_ch224k
node_ch224k -->|"negotiated output"| node_power_output
node_power_output -->|"load current"| node_shunt
node_shunt -->|"bus and shunt sense"| node_ina219
node_buttons -->|"SET / RESET"| node_attiny
node_attiny -->|"CFG voltage request"| node_ch224k
node_ch224k -->|"PG status"| node_attiny
node_ina219 -->|"I²C telemetry"| node_attiny
node_attiny -->|"shared serial display data"| node_oled
node_control_loop -->|"executes on"| node_attiny
node_control_loop -.->|"negotiation policy"| node_ch224k
node_control_loop -.->|"power and energy calculation"| node_ina219
node_make_build -->|"builds"| node_firmware_image
node_vendored_headers -->|"target definitions"| node_make_build
node_firmware_image -->|"flash image"| node_updi_programmer
node_pymcuprog -->|"serial UPDI"| node_updi_programmer
node_avrdude_config -.->|"alternate programming"| node_updi_programmer
node_updi_programmer -->|"programs and sets fuses"| node_attiny
node_pcb_artifacts -.->|"board implementation"| node_ch224k

click node_ch224k "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_power_output "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_shunt "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_ina219 "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_buttons "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_oled "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf"
click node_pcb_artifacts "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_gerber.zip"
click node_control_loop "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/USB_PD_Adapter.ino"
click node_firmware_image "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/usb_pd_adapter.hex"
click node_make_build "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/makefile"
click node_pymcuprog "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/tools/pymcuprog/prog.py"
click node_avrdude_config "https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/tools/avrdude/avrdude.conf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_usb_c_source,node_ch224k,node_power_output,node_shunt,node_ina219,node_buttons,node_oled,node_pcb_artifacts toneBlue
class node_attiny,node_control_loop,node_firmware_image toneAmber
class node_make_build,node_vendored_headers,node_pymcuprog,node_avrdude_config,node_updi_programmer toneMint
```

## Components

### Device Hardware

PCB power, sensing, and local controls.

- **USB-C PD source**: external power source
- [CH224K PD receiver](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): PD negotiation IC · Negotiates one of the selectable USB-PD voltages. · `hardware/USB_PD_Adapter_schematic.pdf`
- [Output terminal & load](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): power output · `hardware/USB_PD_Adapter_schematic.pdf`
- [10 mΩ shunt](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): current sense · `hardware/USB_PD_Adapter_schematic.pdf`
- [INA219 monitor](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): power monitor · Measures output bus voltage and shunt current. · `hardware/USB_PD_Adapter_schematic.pdf`
- [SET / RESET buttons](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): local input · `hardware/USB_PD_Adapter_schematic.pdf`
- [SSD1306 OLED](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_schematic.pdf): local display · `hardware/USB_PD_Adapter_schematic.pdf`
- [PCB manufacturing artifacts](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/hardware/USB_PD_Adapter_gerber.zip): schematic, Gerbers, BOM · Defines board connectivity and production components. · `hardware/USB_PD_Adapter_gerber.zip`

### Embedded Firmware

ATtiny control and measurement runtime.

- **tinyAVR controller**: ATtiny 0/1-series MCU · Runs at 1 MHz to reduce regulator heating and demand.
- [Control and UI loop](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/USB_PD_Adapter.ino): Arduino sketch · Applies requests, waits for PG, calculates energy, and renders status. · `software/USB_PD_Adapter.ino`
- [Prebuilt firmware image](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/usb_pd_adapter.hex): AVR HEX · `software/usb_pd_adapter.hex`

### Build & Provisioning

AVR build and UPDI flashing support.

- [AVR build rules](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/makefile): Makefile / avr-gcc · Selects device, programmer, port, fuses, and firmware build. · `software/makefile`
- **Vendored AVR headers**: device headers
- [Bundled pymcuprog](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/tools/pymcuprog/prog.py): programming tool · Provides serial-UPDI transport and device metadata. · `software/tools/pymcuprog/prog.py`
- [AVRDUDE configuration](https://github.com/wagiminator/attiny814-usb-pd-adapter/blob/main/software/tools/avrdude/avrdude.conf): alternate programmer config · `software/tools/avrdude/avrdude.conf`
- **External UPDI programmer**: 3.3 V programmer

## Connections

- 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
