# pimoroni/badger2040 architecture

> Architecture diagram of the GitHub repository pimoroni/badger2040, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pimoroni/badger2040
- Repository: https://github.com/pimoroni/badger2040

## Overview

##### Main Components
- Hardware Layer – Represent the two physical devices: Badger 2040 and Badger 2040 W. Emphasize that these rely on the RP2040 microcontroller and have minor hardware differences (e.g., the Pico W module on the Badger 2040 W).
- Module and Library Components – Include the firmware submodules (present under “firmware/PIMORONI_BADGER2040”, “firmware/PIMORONI_BADGER2040W” and “firmware/modules/wakeup”) which include board definitions, CMake scripts, patches, and C/C++ modules that extend the MicroPython runtime.
- CI/CD and Documentation – Represent the integration of workflow automation (GitHub workflows under .github/workflows for MicroPython builds and linting) and documentation resources (docs folder with overview, porting guide, and reference information).

##### Relationships and Interactions
- Next, illustrate how the firmware incorporates MicroPython along with critical libraries (provided via the firmware and modules directories) which enable the OS layer functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        a1["Badger 2040 (RP2040)"]:::hardware
        a2["Badger 2040 W (RP2040 Pico W)"]:::hardware
    end

    %% Firmware Layer
    subgraph "Firmware Layer"
        subgraph "Firmware Builds"
            b1["Badger 2040 Firmware Build"]:::firmware
            b2["Badger 2040 W Firmware Build"]:::firmware
        end
        f1["MicroPython Runtime & UF2 Files"]:::firmware
        subgraph "Additional Firmware Assets"
            c1["Additional Patches & Startup Scripts"]:::firmware
            c2["Supplementary Import Script"]:::firmware
        end
        subgraph "Firmware Modules"
            m1["Wakeup Module"]:::module
            m2["Board Libraries"]:::module
        end
    end

    %% Badger OS Layer
    subgraph "Badger OS Layer"
        o1["Badger OS Core"]:::os
        o2["Assets & Examples"]:::os
    end

    %% CI/CD & Documentation
    subgraph "CI/CD & Documentation"
        d1["CI/CD Automation"]:::ci
        d2["Documentation Resources"]:::docs
    end

    %% Connections from Hardware to Firmware Builds
    a1 -->|"flashes firmware"| b1
    a2 -->|"flashes firmware"| b2

    %% Connections within Firmware Layer
    b1 -->|"integrates"| f1
    b2 -->|"integrates"| f1

    b1 -->|"applies"| c1
    b2 -->|"applies"| c1
    b1 -->|"uses"| c2
    b2 -->|"uses"| c2

    b1 -->|"extends"| m2
    b2 -->|"extends"| m2
    b1 -->|"supports"| m1
    b2 -->|"supports"| m1

    %% Connection from Firmware to OS Layer
    f1 -->|"boots"| o1

    %% OS Layer internal connections
    o1 -->|"manages"| o2

    %% CI/CD and Documentation influence
    d1 ---|"triggers build"| b1
    d1 ---|"triggers build"| b2
    d2 ---|"guides development"| o1

    %% Click Events
    click a1 "https://github.com/pimoroni/badger2040/blob/main/firmware/PIMORONI_BADGER2040/board.json"
    click a2 "https://github.com/pimoroni/badger2040/blob/main/firmware/PIMORONI_BADGER2040W/board.json"
    click b1 "https://github.com/pimoroni/badger2040/tree/main/firmware/PIMORONI_BADGER2040"
    click b2 "https://github.com/pimoroni/badger2040/tree/main/firmware/PIMORONI_BADGER2040W"
    click c1 "https://github.com/pimoroni/badger2040/blob/main/firmware/932f76c6ba64c5a3e68de3324556d9979f09303b.patch"
    click c2 "https://github.com/pimoroni/badger2040/blob/main/firmware/pimoroni_pico_import.cmake"
    click o1 "https://github.com/pimoroni/badger2040/tree/main/badger_os"
    click o2 "https://github.com/pimoroni/badger2040/tree/main/badger_os/examples"
    click m1 "https://github.com/pimoroni/badger2040/tree/main/firmware/modules/wakeup"
    click m2 "https://github.com/pimoroni/badger2040/tree/main/firmware/PIMORONI_BADGER2040/lib"
    click d1 "https://github.com/pimoroni/badger2040/tree/main/.github/workflows"
    click d2 "https://github.com/pimoroni/badger2040/tree/main/docs"

    %% Styles
    classDef hardware fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef firmware fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef os fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef module fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef ci fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef docs fill:#CCE5FF,stroke:#004085,stroke-width:2px;

    class a1,a2 hardware;
    class b1,b2,f1,c1,c2 firmware;
    class o1,o2 os;
    class m1,m2 module;
    class d1 ci;
    class d2 docs;
```
