# bitluni/ch570composite architecture

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

- Interactive diagram: https://gitdiagram.com/bitluni/ch570composite
- Repository: https://github.com/bitluni/ch570composite

## Overview

CH570 Composite is embedded firmware that presents a USB CDC serial interface and turns received text into a PAL video signal. The main loop services USB, transfers received bytes into a bounded buffer, and prints them into the video text buffer; the timer/PWM renderer generates the raster output. The README also documents ^L screen clearing. Source excerpts support the main loop and rendering calls, but do not show the CDC receive-dispatch implementation, so that connection is marked unverified. The SPI video implementation is present but not selected by main.

Main entry points: [`code/src/main.cpp`](https://github.com/bitluni/ch570composite/blob/master/code/src/main.cpp) (Main loop), [`code/src/video/CompositeVideoTimerPWM.cpp`](https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoTimerPWM.cpp) (PAL raster renderer), [`code/src/cdc/cdc.cpp`](https://github.com/bitluni/ch570composite/blob/master/code/src/cdc/cdc.cpp) (USB CDC), [`code/src/video/CompositeVideoSPI.cpp`](https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoSPI.cpp) (SPI video alternative)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_application["Firmware workflow"]
  node_main_loop["Main loop<br/>[main.cpp]"]
  node_cdc["USB CDC<br/>[cdc.cpp]"]
  node_receive_buffer[("Text input buffer<br/>[main.cpp]")]
end

subgraph group_video["Video generation"]
  node_text_terminal["Text terminal"]
  node_font["Character font<br/>[font.h]"]
  node_raster_renderer["PAL raster renderer"]
  node_rick_asset["RLE video asset<br/>[rick.h]"]
  node_spi_video["SPI video alternative"]
end

subgraph group_platform["CH570 platform"]
  node_peripheral_drivers["Peripheral drivers<br/>[CH57x_i2c.c]"]
  node_common_definitions["CH57x definitions<br/>[CH57x_common.h]"]
end

node_serial_host(("Serial host"))
node_video_output(("PAL display"))

node_serial_host -->|"sends serial"| node_cdc
node_main_loop -->|"initializes and services"| node_cdc
node_main_loop -->|"appends received bytes"| node_receive_buffer
node_cdc -.->|"dispatches received data"| node_main_loop
node_main_loop -->|"prints characters"| node_text_terminal
node_main_loop -->|"updates video"| node_raster_renderer
node_text_terminal -->|"reads glyphs"| node_font
node_raster_renderer -->|"drives PAL signal"| node_video_output
node_raster_renderer -->|"references animation data"| node_rick_asset
node_spi_video -->|"drives SPI output"| node_video_output
node_peripheral_drivers -->|"uses definitions"| node_common_definitions

click node_main_loop "https://github.com/bitluni/ch570composite/blob/master/code/src/main.cpp"
click node_cdc "https://github.com/bitluni/ch570composite/blob/master/code/src/cdc/cdc.cpp"
click node_receive_buffer "https://github.com/bitluni/ch570composite/blob/master/code/src/main.cpp"
click node_text_terminal "https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoTimerPWM.cpp"
click node_font "https://github.com/bitluni/ch570composite/blob/master/code/src/video/font.h"
click node_raster_renderer "https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoTimerPWM.cpp"
click node_rick_asset "https://github.com/bitluni/ch570composite/blob/master/code/src/video/rick.h"
click node_spi_video "https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoSPI.cpp"
click node_peripheral_drivers "https://github.com/bitluni/ch570composite/blob/master/code/lib/StdPeriphDriver/CH57x_i2c.c"
click node_common_definitions "https://github.com/bitluni/ch570composite/blob/master/code/lib/StdPeriphDriver/inc/CH57x_common.h"

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_main_loop,node_cdc,node_receive_buffer toneBlue
class node_text_terminal,node_font,node_raster_renderer,node_rick_asset,node_spi_video toneAmber
class node_peripheral_drivers,node_common_definitions toneMint
class node_serial_host,node_video_output toneIndigo
```

## Components

### Firmware workflow

- [Main loop](https://github.com/bitluni/ch570composite/blob/master/code/src/main.cpp): `code/src/main.cpp`
- [USB CDC](https://github.com/bitluni/ch570composite/blob/master/code/src/cdc/cdc.cpp): `code/src/cdc/cdc.cpp`
- [Text input buffer](https://github.com/bitluni/ch570composite/blob/master/code/src/main.cpp): `code/src/main.cpp`

### Video generation

- [Text terminal](https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoTimerPWM.cpp): `code/src/video/CompositeVideoTimerPWM.cpp`
- [Character font](https://github.com/bitluni/ch570composite/blob/master/code/src/video/font.h): `code/src/video/font.h`
- [PAL raster renderer](https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoTimerPWM.cpp): `code/src/video/CompositeVideoTimerPWM.cpp`
- [RLE video asset](https://github.com/bitluni/ch570composite/blob/master/code/src/video/rick.h): `code/src/video/rick.h`
- [SPI video alternative](https://github.com/bitluni/ch570composite/blob/master/code/src/video/CompositeVideoSPI.cpp): `code/src/video/CompositeVideoSPI.cpp`

### CH570 platform

- [Peripheral drivers](https://github.com/bitluni/ch570composite/blob/master/code/lib/StdPeriphDriver/CH57x_i2c.c): `code/lib/StdPeriphDriver/CH57x_i2c.c`
- [CH57x definitions](https://github.com/bitluni/ch570composite/blob/master/code/lib/StdPeriphDriver/inc/CH57x_common.h): `code/lib/StdPeriphDriver/inc/CH57x_common.h`

### Other components

- **Serial host**
- **PAL display**

## Connections

- Serial host → USB CDC: sends serial
- Main loop → USB CDC: initializes and services (evidence: `code/src/main.cpp`)
- Main loop → Text input buffer: appends received bytes (evidence: `code/src/main.cpp`)
- USB CDC → Main loop: dispatches received data
- Main loop → Text terminal: prints characters (evidence: `code/src/main.cpp`)
- Main loop → PAL raster renderer: updates video (evidence: `code/src/main.cpp`)
- Text terminal → Character font: reads glyphs (evidence: `code/src/video/CompositeVideoTimerPWM.cpp`)
- PAL raster renderer → PAL display: drives PAL signal (evidence: `code/src/video/CompositeVideoTimerPWM.cpp`)
- PAL raster renderer → RLE video asset: references animation data (evidence: `code/src/video/CompositeVideoTimerPWM.cpp`)
- SPI video alternative → PAL display: drives SPI output (evidence: `code/src/video/CompositeVideoSPI.cpp`)
- Peripheral drivers → CH57x definitions: uses definitions (evidence: `code/lib/StdPeriphDriver/CH57x_i2c.c`)
