# twotoz/triversity architecture

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

- Interactive diagram: https://gitdiagram.com/twotoz/triversity
- Repository: https://github.com/twotoz/triversity

## Overview

Triversity is an experimental FPV diversity receiver: three ESP32-C5 units stream raw IQ to a Tang Nano FPGA, which combines before demodulation and produces live colour video and optional HQ DVR recordings. The graph preserves the documented receiver, display, menu, and recording stages, plus the firmware controls and host-side signal models. Several FPGA runtime implementations are absent from the supplied tree, so those subsystems use supported directory paths; their links reflect README descriptions rather than inspected RTL.

Main entry points: [`c5/main/receiver.c`](https://github.com/twotoz/triversity/blob/main/c5/main/receiver.c) (Receiver control), [`c5/main/rf.c`](https://github.com/twotoz/triversity/blob/main/c5/main/rf.c) (RF and PHY), [`fpga`](https://github.com/twotoz/triversity/tree/main/fpga) (FM demodulation), [`web/app.js`](https://github.com/twotoz/triversity/blob/main/web/app.js) (Flasher interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rf["RF receivers"]
  node_boot["Firmware startup<br/>[main.c]"]
  node_receiver["Receiver control<br/>[receiver.c]"]
  node_rf_front["RF and PHY<br/>[rf.c]"]
  node_calibration["Calibration<br/>[calibration.c]"]
  node_gain["Gain control<br/>[gain.c]"]
  node_transport["IQ transport<br/>[transport.c]"]
end

subgraph group_fpga["FPGA video"]
  node_fpga_rx["IQ alignment and fusion"]
  node_demod["FM demodulation"]
  node_colour["Colour video"]
  node_osd["Menu and OSD"]
end

subgraph group_record["Recording"]
  node_field_buffer[("Field buffer")]
  node_hqdvr["HQ DVR JPEG"]
end

subgraph group_tools["Host models"]
  node_mrc_models["IQ fusion models<br/>[mrc3_model.py]"]
  node_eval_models["Receiver evaluation<br/>[eval3.py]"]
  node_chroma_model["Colour model<br/>[chroma_model.py]"]
  node_fade_study["Fading study<br/>[fade_study.py]"]
end

subgraph group_flash["Web flasher"]
  node_flasher_ui["Flasher interface<br/>[app.js]"]
  node_esp_loader["ESP flashing<br/>[esptool.js]"]
  node_fpga_loader["FPGA flashing<br/>[fpga.js]"]
end

node_video_tx(("FPV transmitter"))
node_antennas(("Three antennas"))
node_display(("LCD or HDMI"))
node_tf_card[("TF card")]
node_operator(("Operator"))
node_c5_boards(("C5 boards"))
node_tang(("Tang FPGA"))

node_video_tx -->|"transmits to"| node_antennas
node_antennas -->|"receive signal"| node_rf_front
node_boot -->|"starts"| node_receiver
node_boot -->|"starts radio"| node_rf_front
node_receiver -->|"controls"| node_rf_front
node_receiver -->|"manages gain"| node_gain
node_calibration -->|"calibrates"| node_receiver
node_rf_front -->|"streams IQ"| node_transport
node_transport -->|"sends IQ"| node_fpga_rx
node_fpga_rx -->|"feeds fused IQ"| node_demod
node_demod -->|"demodulates video"| node_colour
node_colour -->|"drives picture"| node_display
node_osd -->|"overlays menu"| node_display
node_operator -->|"controls menu"| node_osd
node_demod -->|"buffers fields"| node_field_buffer
node_field_buffer -->|"provides fields"| node_hqdvr
node_hqdvr -->|"writes JPEGs"| node_tf_card
node_mrc_models -->|"evaluated by"| node_eval_models
node_eval_models -->|"compared with"| node_chroma_model
node_fade_study -->|"studies fusion"| node_mrc_models
node_operator -->|"selects firmware"| node_flasher_ui
node_flasher_ui -->|"flashes C5"| node_esp_loader
node_flasher_ui -->|"loads bitstream"| node_fpga_loader
node_esp_loader -->|"programs"| node_c5_boards
node_fpga_loader -->|"programs"| node_tang

click node_boot "https://github.com/twotoz/triversity/blob/main/c5/main/main.c"
click node_receiver "https://github.com/twotoz/triversity/blob/main/c5/main/receiver.c"
click node_rf_front "https://github.com/twotoz/triversity/blob/main/c5/main/rf.c"
click node_calibration "https://github.com/twotoz/triversity/blob/main/c5/main/calibration.c"
click node_gain "https://github.com/twotoz/triversity/blob/main/c5/main/gain.c"
click node_transport "https://github.com/twotoz/triversity/blob/main/c5/main/transport.c"
click node_fpga_rx "https://github.com/twotoz/triversity/tree/main/fpga"
click node_demod "https://github.com/twotoz/triversity/tree/main/fpga"
click node_colour "https://github.com/twotoz/triversity/tree/main/fpga"
click node_osd "https://github.com/twotoz/triversity/tree/main/fpga"
click node_field_buffer "https://github.com/twotoz/triversity/tree/main/fpga"
click node_hqdvr "https://github.com/twotoz/triversity/tree/main/fpga"
click node_mrc_models "https://github.com/twotoz/triversity/blob/main/fpga/model/mrc3_model.py"
click node_eval_models "https://github.com/twotoz/triversity/blob/main/fpga/model/eval3.py"
click node_chroma_model "https://github.com/twotoz/triversity/blob/main/fpga/model/chroma_model.py"
click node_fade_study "https://github.com/twotoz/triversity/blob/main/fpga/sim/fading/fade_study.py"
click node_flasher_ui "https://github.com/twotoz/triversity/blob/main/web/app.js"
click node_esp_loader "https://github.com/twotoz/triversity/blob/main/web/esptool.js"
click node_fpga_loader "https://github.com/twotoz/triversity/blob/main/web/fpga.js"

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_boot,node_receiver,node_rf_front,node_calibration,node_gain,node_transport toneBlue
class node_fpga_rx,node_demod,node_colour,node_osd,node_tf_card toneAmber
class node_field_buffer,node_hqdvr toneMint
class node_mrc_models,node_eval_models,node_chroma_model,node_fade_study toneRose
class node_flasher_ui,node_esp_loader,node_fpga_loader,node_video_tx,node_antennas,node_display,node_operator,node_c5_boards,node_tang toneIndigo
```

## Components

### RF receivers

- [Firmware startup](https://github.com/twotoz/triversity/blob/main/c5/main/main.c): `c5/main/main.c`
- [Receiver control](https://github.com/twotoz/triversity/blob/main/c5/main/receiver.c): `c5/main/receiver.c`
- [RF and PHY](https://github.com/twotoz/triversity/blob/main/c5/main/rf.c): `c5/main/rf.c`
- [Calibration](https://github.com/twotoz/triversity/blob/main/c5/main/calibration.c): `c5/main/calibration.c`
- [Gain control](https://github.com/twotoz/triversity/blob/main/c5/main/gain.c): `c5/main/gain.c`
- [IQ transport](https://github.com/twotoz/triversity/blob/main/c5/main/transport.c): `c5/main/transport.c`

### FPGA video

- [IQ alignment and fusion](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`
- [FM demodulation](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`
- [Colour video](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`
- [Menu and OSD](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`

### Recording

- [Field buffer](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`
- [HQ DVR JPEG](https://github.com/twotoz/triversity/tree/main/fpga): `fpga`

### Host models

- [IQ fusion models](https://github.com/twotoz/triversity/blob/main/fpga/model/mrc3_model.py): `fpga/model/mrc3_model.py`
- [Receiver evaluation](https://github.com/twotoz/triversity/blob/main/fpga/model/eval3.py): `fpga/model/eval3.py`
- [Colour model](https://github.com/twotoz/triversity/blob/main/fpga/model/chroma_model.py): `fpga/model/chroma_model.py`
- [Fading study](https://github.com/twotoz/triversity/blob/main/fpga/sim/fading/fade_study.py): `fpga/sim/fading/fade_study.py`

### Web flasher

- [Flasher interface](https://github.com/twotoz/triversity/blob/main/web/app.js): `web/app.js`
- [ESP flashing](https://github.com/twotoz/triversity/blob/main/web/esptool.js): `web/esptool.js`
- [FPGA flashing](https://github.com/twotoz/triversity/blob/main/web/fpga.js): `web/fpga.js`

### Other components

- **FPV transmitter**
- **Three antennas**
- **LCD or HDMI**
- **TF card**
- **Operator**
- **C5 boards**
- **Tang FPGA**

## Connections

- FPV transmitter → Three antennas: transmits to
- Three antennas → RF and PHY: receive signal
- Firmware startup → Receiver control: starts (evidence: `c5/main/main.c`)
- Firmware startup → RF and PHY: starts radio (evidence: `c5/main/main.c`)
- Receiver control → RF and PHY: controls (evidence: `c5/main/receiver.c`)
- Receiver control → Gain control: manages gain (evidence: `c5/main/receiver.c`)
- Calibration → Receiver control: calibrates
- RF and PHY → IQ transport: streams IQ
- IQ transport → IQ alignment and fusion: sends IQ
- IQ alignment and fusion → FM demodulation: feeds fused IQ
- FM demodulation → Colour video: demodulates video
- Colour video → LCD or HDMI: drives picture
- Menu and OSD → LCD or HDMI: overlays menu
- Operator → Menu and OSD: controls menu
- FM demodulation → Field buffer: buffers fields
- Field buffer → HQ DVR JPEG: provides fields
- HQ DVR JPEG → TF card: writes JPEGs
- IQ fusion models → Receiver evaluation: evaluated by (evidence: `fpga/model/eval3.py`)
- Receiver evaluation → Colour model: compared with (evidence: `fpga/model/chroma_model.py`)
- Fading study → IQ fusion models: studies fusion (evidence: `fpga/sim/fading/fade_study.py`)
- Operator → Flasher interface: selects firmware (evidence: `web/app.js`)
- Flasher interface → ESP flashing: flashes C5 (evidence: `web/app.js`)
- Flasher interface → FPGA flashing: loads bitstream (evidence: `web/app.js`)
- ESP flashing → C5 boards: programs
- FPGA flashing → Tang FPGA: programs
