# gab-k/rp2040-decoder architecture

> Architecture diagram of the GitHub repository gab-k/rp2040-decoder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gab-k/rp2040-decoder
- Repository: https://github.com/gab-k/rp2040-decoder

## Overview

RP2040-Decoder is an open-source dual-core DCC locomotive decoder, with USB and Legacy board revisions. Its principal workflow receives DCC commands, interprets speed and configuration instructions on Core 0, and controls motor speed on Core 1 using PWM and back-EMF feedback. Core 0 also handles CV programming and persistent configuration; shared state supports coordination. The README documents auxiliary outputs and flexible GPIO, though their implementation was not sampled. Firmware relationships below follow the README and source index; unsampled details are left unconnected.

Main entry points: [`Software/core0.c`](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c) (Core 0 processing), [`Software/core1.c`](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c) (Motor controller), [`Software/shared.c`](https://github.com/gab-k/rp2040-decoder/blob/main/Software/shared.c) (Shared core state), [`Software/CV.h`](https://github.com/gab-k/rp2040-decoder/blob/main/Software/CV.h) (CV defaults)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Decoder firmware"]
  node_core0["Core 0 processing<br/>[core0.c]"]
  node_dcc_decode["Packet decoding<br/>[core0.c]"]
  node_cv_programming["CV programming<br/>[core0.c]"]
  node_cv_defaults["CV defaults<br/>[CV.h]"]
  node_cv_flash[("Persistent CVs<br/>[core0.c]")]
  node_shared["Shared core state<br/>[shared.c]"]
  node_core1["Core 1 control<br/>[core1.c]"]
  node_motor_control["Motor controller<br/>[core1.c]"]
  node_back_emf["Back-EMF feedback<br/>[core1.c]"]
  node_aux_io["Auxiliary I/O"]
end

subgraph group_hardware["Board designs"]
  node_usb_board["USB revision"]
  node_legacy_board["Legacy revision"]
end

node_dcc(("DCC signal"))
node_motor["Motor outputs"]

node_dcc -->|"supplies signal"| node_dcc_decode
node_core0 -->|"decodes packets"| node_dcc_decode
node_core0 -->|"handles programming"| node_cv_programming
node_cv_programming -->|"persists configuration"| node_cv_flash
node_cv_defaults -->|"defines defaults"| node_cv_programming
node_core0 -.->|"coordinates through"| node_shared
node_core1 -.->|"coordinates through"| node_shared
node_core1 -->|"runs control"| node_motor_control
node_motor_control -->|"uses feedback"| node_back_emf
node_motor_control -->|"drives PWM"| node_motor
node_core0 -->|"separate core tasks"| node_core1
node_core0 -.->|"manages outputs"| node_aux_io
node_usb_board -.->|"hosts firmware"| node_core0
node_legacy_board -.->|"hosts firmware"| node_core0

click node_core0 "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c"
click node_dcc_decode "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c"
click node_cv_programming "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c"
click node_cv_defaults "https://github.com/gab-k/rp2040-decoder/blob/main/Software/CV.h"
click node_cv_flash "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c"
click node_shared "https://github.com/gab-k/rp2040-decoder/blob/main/Software/shared.c"
click node_core1 "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c"
click node_motor_control "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c"
click node_back_emf "https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c"
click node_aux_io "https://github.com/gab-k/rp2040-decoder/blob/main/Software/RP2040-Decoder-board-USB.h"
click node_usb_board "https://github.com/gab-k/rp2040-decoder/blob/main/KiCad/USB/RP2040-Decoder.kicad_sch"
click node_legacy_board "https://github.com/gab-k/rp2040-decoder/blob/main/KiCad/Legacy/RP2040-Decoder.kicad_sch"

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_core0,node_dcc_decode,node_cv_programming,node_cv_defaults,node_cv_flash,node_shared,node_core1,node_motor_control,node_back_emf,node_aux_io toneBlue
class node_usb_board,node_legacy_board toneAmber
class node_dcc,node_motor toneIndigo
```

## Components

### Decoder firmware

- [Core 0 processing](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c): `Software/core0.c`
- [Packet decoding](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c): `Software/core0.c`
- [CV programming](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c): `Software/core0.c`
- [CV defaults](https://github.com/gab-k/rp2040-decoder/blob/main/Software/CV.h): `Software/CV.h`
- [Persistent CVs](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core0.c): `Software/core0.c`
- [Shared core state](https://github.com/gab-k/rp2040-decoder/blob/main/Software/shared.c): `Software/shared.c`
- [Core 1 control](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c): `Software/core1.c`
- [Motor controller](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c): `Software/core1.c`
- [Back-EMF feedback](https://github.com/gab-k/rp2040-decoder/blob/main/Software/core1.c): `Software/core1.c`
- [Auxiliary I/O](https://github.com/gab-k/rp2040-decoder/blob/main/Software/RP2040-Decoder-board-USB.h): `Software/RP2040-Decoder-board-USB.h`

### Board designs

- [USB revision](https://github.com/gab-k/rp2040-decoder/blob/main/KiCad/USB/RP2040-Decoder.kicad_sch): `KiCad/USB/RP2040-Decoder.kicad_sch`
- [Legacy revision](https://github.com/gab-k/rp2040-decoder/blob/main/KiCad/Legacy/RP2040-Decoder.kicad_sch): `KiCad/Legacy/RP2040-Decoder.kicad_sch`

### Other components

- **DCC signal**
- **Motor outputs**

## Connections

- DCC signal → Packet decoding: supplies signal (evidence: `README.md`)
- Core 0 processing → Packet decoding: decodes packets (evidence: `README.md`)
- Core 0 processing → CV programming: handles programming (evidence: `README.md`)
- CV programming → Persistent CVs: persists configuration (evidence: `README.md`)
- CV defaults → CV programming: defines defaults
- Core 0 processing → Shared core state: coordinates through
- Core 1 control → Shared core state: coordinates through
- Core 1 control → Motor controller: runs control (evidence: `README.md`)
- Motor controller → Back-EMF feedback: uses feedback (evidence: `README.md`)
- Motor controller → Motor outputs: drives PWM (evidence: `README.md`)
- Core 0 processing → Core 1 control: separate core tasks (evidence: `README.md`)
- Core 0 processing → Auxiliary I/O: manages outputs
- USB revision → Core 0 processing: hosts firmware
- Legacy revision → Core 0 processing: hosts firmware
