# team-resurgent/modxo architecture

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

- Interactive diagram: https://gitdiagram.com/team-resurgent/modxo
- Repository: https://github.com/team-resurgent/modxo

## Overview

#### Purpose and runtime
Modxo is bare-metal C firmware that makes RP2040/RP2350 boards behave as an Original Xbox LPC peripheral. It serves BIOS data and exposes optional LPC-addressable peripherals. The firmware runs on Raspberry Pi Pico SDK targets, with board-selected GPIO pinouts and UF2 firmware output.

Paths: `src/main.c`, `modxo/modxo.c`, `external/pico-sdk`

#### Build and board specialization
The root CMake project imports the Pico SDK and composes the core firmware plus modular peripherals. Board CMake definitions select supported physical pin mappings, including Pico, Pico 2, RP2040 Zero/Tiny, XIAO, and other variants. Generated pinout headers isolate board wiring from protocol logic.

Paths: `CMakeLists.txt`, `pico_sdk_import.cmake`, `boards/modxo_pinout.h.in`

#### Firmware entry and core coordination
`src/main.c` is the application entry point. The core Modxo layer owns initialization and shared firmware-facing definitions, while its queue provides deferred/event-style coordination between timing-sensitive LPC activity and higher-level module work.

Paths: `src/main.c`, `modxo/modxo.c`, `modxo/modxo_queue.c`

#### LPC transport boundary
The LPC subsystem is the hardware/protocol boundary to the Xbox. It implements the LPC interface, register-level protocol handling, and transaction logging. Its CMake input template indicates generated/compiled LPC communication configuration. This layer converts bus activity into normalized requests for feature modules.

Paths: `modxo/lpc/lpc_interface.c`, `modxo/lpc/lpc_regs.c`, `modxo/lpc/lpc_log.c`

#### LPC request routing and emulated devices
`lpc_mapper` is the central dispatch layer for LPC-visible address/function mappings. Handlers implement BIOS flash access, expansion I²C, heap/PSRAM or internal RAM mappings, random data, SD-card access/configuration, and echo behavior. This is the main extensibility boundary: new Xbox-visible services belong as mapper handlers rather than in LPC transport.

Paths: `modxo_modules/lpc_mapper/lpc_mapper.c`, `modxo_modules/lpc_mapper/handlers/flash.c`, `modxo_modules/lpc_mapper/handlers/sdcard.c`

#### Persistent BIOS/configuration storage
The flash-ROM module provides the BIOS-image-facing storage service exposed through the mapper. Separately, configuration NVM persists firmware configuration, allowing runtime state to remain independent of the flashed executable and LPC transaction engine.

Paths: `modxo_modules/flashrom/flashrom.c`, `modxo/config/config_nvm.c`, `modxo/include/modxo/config_nvm.h`

#### Peripheral integrations
Optional hardware services include an I²C expansion interface, HD44780-style legacy display support, WS2812 LEDs, serial IRQ, and an LPC Super I/O implementation with 16550 UART support. These modules bridge LPC-side software expectations to RP2040 peripherals and PIO programs where timing requires it.

Paths: `modxo/expansion_i2c/expansion_i2c.c`, `modxo_modules/superio/LPC47M152.c`, `modxo_modules/serirq/serirq.pio.in`

#### SD-card stack and delivery infrastructure
An embedded SD/FAT stack supports SPI and RP2040 SDIO card transports, DMA, and FatFs-backed file access; it is consumed through the mapper rather than being the firmware entry path. Docker and GitHub Actions provide build/bundle automation, though the primary SDK dependency is the Pico SDK submodule.

Paths: `modxo/sdcard/src/sd_driver/sd_card.c`, `modxo/sdcard/src/ff15/source/ff.c`, `Dockerfile`

Main entry points: [`modxo/lpc/lpc_interface.c`](https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_interface.c) (LPC interface), [`modxo_modules/lpc_mapper/lpc_mapper.c`](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/lpc_mapper.c) (LPC mapper), [`modxo/modxo.c`](https://github.com/team-resurgent/modxo/blob/main/modxo/modxo.c) (Modxo core), [`CMakeLists.txt`](https://github.com/team-resurgent/modxo/blob/main/CMakeLists.txt) (CMake build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Boards"]
  node_cmake["CMake build<br/>[CMakeLists.txt]"]
  node_pico_sdk["Pico SDK<br/>SDK dependency"]
  node_pinouts["Generated pinouts<br/>board wiring<br/>[modxo_pinout.h.in]"]
  node_docker["Container build<br/>delivery automation"]
end

subgraph group_runtime["Firmware Runtime"]
  node_entry["Firmware entry<br/>application entry<br/>[main.c]"]
  node_core["Modxo core<br/>firmware coordinator<br/>[modxo.c]"]
  node_queue["Deferred work queue<br/>event queue<br/>[modxo_queue.c]"]
end

subgraph group_lpc["LPC Boundary"]
  node_lpc_interface["LPC interface<br/>hardware transport<br/>[lpc_interface.c]"]
  node_lpc_regs["LPC registers<br/>protocol handling<br/>[lpc_regs.c]"]
  node_lpc_log["LPC transaction log<br/>diagnostics<br/>[lpc_log.c]"]
end

subgraph group_services["LPC Services"]
  node_mapper["LPC mapper<br/>request dispatcher<br/>[lpc_mapper.c]"]
  node_flash_handler["Flash handler<br/>mapper handler<br/>[flash.c]"]
  node_sd_handler["SD-card handler<br/>mapper handler<br/>[sdcard.c]"]
  node_expansion_i2c["Expansion I²C<br/>optional peripheral<br/>[expansion_i2c.c]"]
  node_superio["Super I/O / UART<br/>optional peripheral<br/>[LPC47M152.c]"]
  node_serirq["Serial IRQ PIO<br/>PIO peripheral<br/>[serirq.pio.in]"]
end

subgraph group_storage["Storage"]
  node_flashrom[("BIOS flash ROM<br/>BIOS storage service<br/>[flashrom.c]")]
  node_config_nvm[("Configuration NVM<br/>persistent configuration<br/>[config_nvm.c]")]
  node_sd_driver["SD transport<br/>SPI/SDIO driver<br/>[sd_card.c]"]
  node_fatfs["FatFs<br/>filesystem<br/>[ff.c]"]
end

node_cmake -->|"imports"| node_pico_sdk
node_cmake -->|"generates"| node_pinouts
node_cmake -->|"builds"| node_entry
node_docker -.->|"automates build"| node_cmake
node_entry -->|"initializes"| node_core
node_core -->|"coordinates via"| node_queue
node_core -->|"starts"| node_lpc_interface
node_pinouts -->|"supplies GPIO mapping"| node_lpc_interface
node_lpc_interface -->|"handles protocol registers"| node_lpc_regs
node_lpc_interface -.->|"records transactions"| node_lpc_log
node_lpc_interface -->|"normalizes requests"| node_mapper
node_lpc_interface -->|"defers work"| node_queue
node_mapper -->|"dispatches"| node_flash_handler
node_mapper -->|"dispatches"| node_sd_handler
node_flash_handler -->|"accesses BIOS data"| node_flashrom
node_sd_handler -->|"accesses card"| node_sd_driver
node_sd_driver -->|"provides block transport"| node_fatfs
node_mapper -->|"exposes"| node_expansion_i2c
node_mapper -->|"exposes"| node_superio
node_superio -->|"uses IRQ signaling"| node_serirq
node_core -->|"loads and persists config"| node_config_nvm

click node_cmake "https://github.com/team-resurgent/modxo/blob/main/CMakeLists.txt"
click node_pico_sdk "https://github.com/team-resurgent/modxo/tree/main/external/pico-sdk"
click node_pinouts "https://github.com/team-resurgent/modxo/blob/main/boards/modxo_pinout.h.in"
click node_entry "https://github.com/team-resurgent/modxo/blob/main/src/main.c"
click node_core "https://github.com/team-resurgent/modxo/blob/main/modxo/modxo.c"
click node_queue "https://github.com/team-resurgent/modxo/blob/main/modxo/modxo_queue.c"
click node_lpc_interface "https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_interface.c"
click node_lpc_regs "https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_regs.c"
click node_lpc_log "https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_log.c"
click node_mapper "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/lpc_mapper.c"
click node_flash_handler "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/handlers/flash.c"
click node_sd_handler "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/handlers/sdcard.c"
click node_flashrom "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/flashrom/flashrom.c"
click node_config_nvm "https://github.com/team-resurgent/modxo/blob/main/modxo/config/config_nvm.c"
click node_sd_driver "https://github.com/team-resurgent/modxo/blob/main/modxo/sdcard/src/sd_driver/sd_card.c"
click node_fatfs "https://github.com/team-resurgent/modxo/blob/main/modxo/sdcard/src/ff15/source/ff.c"
click node_expansion_i2c "https://github.com/team-resurgent/modxo/blob/main/modxo/expansion_i2c/expansion_i2c.c"
click node_superio "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/superio/LPC47M152.c"
click node_serirq "https://github.com/team-resurgent/modxo/blob/main/modxo_modules/serirq/serirq.pio.in"
click node_docker "https://github.com/team-resurgent/modxo/blob/main/Dockerfile"

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_cmake,node_pico_sdk,node_pinouts,node_docker toneBlue
class node_entry,node_core,node_queue toneAmber
class node_lpc_interface,node_lpc_regs,node_lpc_log toneMint
class node_mapper,node_flash_handler,node_sd_handler,node_expansion_i2c,node_superio,node_serirq toneRose
class node_flashrom,node_config_nvm,node_sd_driver,node_fatfs toneIndigo
```

## Components

### Build & Boards

- [CMake build](https://github.com/team-resurgent/modxo/blob/main/CMakeLists.txt): build · Composes firmware modules and UF2 targets. · `CMakeLists.txt`
- [Pico SDK](https://github.com/team-resurgent/modxo/tree/main/external/pico-sdk): SDK dependency · `external/pico-sdk`
- [Generated pinouts](https://github.com/team-resurgent/modxo/blob/main/boards/modxo_pinout.h.in): board wiring · Board-specific GPIO mappings are generated separately from protocol logic. · `boards/modxo_pinout.h.in`
- [Container build](https://github.com/team-resurgent/modxo/blob/main/Dockerfile): delivery automation · `Dockerfile`

### Firmware Runtime

- [Firmware entry](https://github.com/team-resurgent/modxo/blob/main/src/main.c): application entry · `src/main.c`
- [Modxo core](https://github.com/team-resurgent/modxo/blob/main/modxo/modxo.c): firmware coordinator · Owns shared initialization and firmware-facing definitions. · `modxo/modxo.c`
- [Deferred work queue](https://github.com/team-resurgent/modxo/blob/main/modxo/modxo_queue.c): event queue · Decouples timing-sensitive LPC work from higher-level modules. · `modxo/modxo_queue.c`

### LPC Boundary

- [LPC interface](https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_interface.c): hardware transport · Xbox LPC hardware and protocol boundary. · `modxo/lpc/lpc_interface.c`
- [LPC registers](https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_regs.c): protocol handling · `modxo/lpc/lpc_regs.c`
- [LPC transaction log](https://github.com/team-resurgent/modxo/blob/main/modxo/lpc/lpc_log.c): diagnostics · `modxo/lpc/lpc_log.c`

### LPC Services

- [LPC mapper](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/lpc_mapper.c): request dispatcher · Central extensibility boundary for Xbox-visible mappings. · `modxo_modules/lpc_mapper/lpc_mapper.c`
- [Flash handler](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/handlers/flash.c): mapper handler · `modxo_modules/lpc_mapper/handlers/flash.c`
- [SD-card handler](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/lpc_mapper/handlers/sdcard.c): mapper handler · `modxo_modules/lpc_mapper/handlers/sdcard.c`
- [Expansion I²C](https://github.com/team-resurgent/modxo/blob/main/modxo/expansion_i2c/expansion_i2c.c): optional peripheral · `modxo/expansion_i2c/expansion_i2c.c`
- [Super I/O / UART](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/superio/LPC47M152.c): optional peripheral · LPC Super I/O implementation with 16550 UART support. · `modxo_modules/superio/LPC47M152.c`
- [Serial IRQ PIO](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/serirq/serirq.pio.in): PIO peripheral · `modxo_modules/serirq/serirq.pio.in`

### Storage

- [BIOS flash ROM](https://github.com/team-resurgent/modxo/blob/main/modxo_modules/flashrom/flashrom.c): BIOS storage service · `modxo_modules/flashrom/flashrom.c`
- [Configuration NVM](https://github.com/team-resurgent/modxo/blob/main/modxo/config/config_nvm.c): persistent configuration · Persists firmware state independently of executable and LPC engine. · `modxo/config/config_nvm.c`
- [SD transport](https://github.com/team-resurgent/modxo/blob/main/modxo/sdcard/src/sd_driver/sd_card.c): SPI/SDIO driver · `modxo/sdcard/src/sd_driver/sd_card.c`
- [FatFs](https://github.com/team-resurgent/modxo/blob/main/modxo/sdcard/src/ff15/source/ff.c): filesystem · `modxo/sdcard/src/ff15/source/ff.c`

## Connections

- CMake build → Pico SDK: imports
- CMake build → Generated pinouts: generates
- CMake build → Firmware entry: builds
- Container build → CMake build: automates build
- Firmware entry → Modxo core: initializes
- Modxo core → Deferred work queue: coordinates via
- Modxo core → LPC interface: starts
- Generated pinouts → LPC interface: supplies GPIO mapping
- LPC interface → LPC registers: handles protocol registers
- LPC interface → LPC transaction log: records transactions
- LPC interface → LPC mapper: normalizes requests
- LPC interface → Deferred work queue: defers work
- LPC mapper → Flash handler: dispatches
- LPC mapper → SD-card handler: dispatches
- Flash handler → BIOS flash ROM: accesses BIOS data
- SD-card handler → SD transport: accesses card
- SD transport → FatFs: provides block transport
- LPC mapper → Expansion I²C: exposes
- LPC mapper → Super I/O / UART: exposes
- Super I/O / UART → Serial IRQ PIO: uses IRQ signaling
- Modxo core → Configuration NVM: loads and persists config
