# cbruiz/printhor architecture

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

- Interactive diagram: https://gitdiagram.com/cbruiz/printhor
- Repository: https://github.com/cbruiz/printhor

## Overview

##### Main System Components

A. Hardware Abstraction Layer (Top Level)
- Native Simulator
- STM32 Boards (SKR Mini E3, MKS Robin Nano)
- RP2040 Boards
- Nucleo Boards

B. Core Framework Layer (Middle Level)
- Motion Control System
- Motion Planning
- Kinematics
- Trajectory Control
- Temperature Control System
- I/O Management
- Task Management
- System

C. Interface Layer (Bottom Level)
- GCode Parser/Processor
- Communication Interfaces
- User Interface Components

##### Component Relationships

A. Hardware Interface Flow:
**Hardware Boards -> Hardware Abstraction Layer (HWI) -> Core Framework**

B. Control Flow:
**GCode Input -> Parser -> Task Management -> Motion/Temperature Controllers -> Hardware**

C. Data Flow:
**Sensors -> Hardware Interface -> Controllers -> State Management -> User Interface**

##### Specific Implementation Details

Key architectural elements:

A. Hardware Abstraction:
- `hwi-boards` implementations for different targets
- Common traits and interfaces
- Peripheral abstractions (ADC, PWM, UART, etc.)

B. Control Systems:
- Motion planning system with its components:
- Trajectory Planning
- Velocity Profile Generation
- Stepper Motor Control
- Thermal control system with PID controllers

C. Task Management:
- Async task system
- Event bus architecture
- Resource sharing mechanisms

##### Technical Specifications

Technical details:

A. Supported Protocols:
- GCode command support
- Communication interfaces
- SD Card interface

B. Real-time Components:
- Motion timing
- Temperature monitoring
- Emergency stop system

##### Key Features to Highlight

Important aspects:

A. Safety Features:
- Emergency stop paths
- Temperature monitoring
- Limit switch handling

B. Performance Features:
- Async task management
- DMA utilization
- Resource sharing

C. Extensibility:
- Board support addition
- Feature modularity
- Hardware abstraction layer

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef hardware fill:#a8d1f0,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef interface fill:#FFE5B4,stroke:#333
    classDef critical fill:#FFB6C1,stroke:#333
    classDef control fill:#98FB98,stroke:#333
    
    %% Hardware Layer
    subgraph Hardware
        Native[Native Simulator]
        STM32[STM32 Boards]
        RP2040[RP2040 Boards]
        Nucleo[Nucleo Boards]
    end
    
    %% Hardware Abstraction Layer
    HAL[Hardware Abstraction Layer]
    click HAL "https://github.com/cbruiz/printhor/tree/main/hwi-boards/"
    HWDrivers[Hardware Drivers]
    click HWDrivers "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/hwa/drivers/"
    
    %% Core Framework Layer
    subgraph CoreFramework
        MotionControl[Motion Control System]
        click MotionControl "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/hwa/controllers/motion/"
        
        MotionPlanning[Motion Planning]
        click MotionPlanning "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/hwa/controllers/motion/motion_planner.rs"
        
        Kinematics[Kinematics & Trajectory]
        click Kinematics "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/hwa/controllers/motion/motion_interpolation.rs"
        
        TempControl[Temperature Control System]
        click TempControl "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/control/task_temperature.rs"
        
        TaskMgmt[Task Management]
        click TaskMgmt "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/control/"
        
        Controllers[Controller Components]
        click Controllers "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/hwa/controllers/"
    end
    
    %% Interface Layer
    subgraph InterfaceLayer
        GCodeParser[GCode Parser]
        click GCodeParser "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/control/processing/gcode_parser.rs"
        
        GCodeProc[GCode Processor]
        click GCodeProc "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/control/processing/gcode_processor.rs"
        
        CommInterface[Communication Interfaces]
        click CommInterface "https://github.com/cbruiz/printhor/blob/main/src/bin/printhor/control/processing/gcode_multiplexed_io.rs"
        
        Display[Display System]
        click Display "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/display/"
        
        UI[User Interface]
        click UI "https://github.com/cbruiz/printhor/tree/main/src/bin/printhor/display/ui/"
    end
    
    %% Connections
    Native & STM32 & RP2040 & Nucleo --> HAL
    HAL --> HWDrivers
    HWDrivers --> Controllers
    
    Controllers --> MotionControl & TempControl
    MotionControl --> MotionPlanning
    MotionPlanning --> Kinematics
    
    GCodeParser --> GCodeProc
    GCodeProc --> TaskMgmt
    TaskMgmt --> MotionControl
    TaskMgmt --> TempControl
    
    CommInterface --> GCodeParser
    Display --> UI
    
    %% Emergency/Critical Paths
    EmergencyStop[Emergency Stop System]:::critical
    TempControl --> EmergencyStop
    MotionControl --> EmergencyStop
    
    %% Apply Classes
    class Native,STM32,RP2040,Nucleo hardware
    class MotionControl,TempControl,TaskMgmt,Controllers core
    class GCodeParser,GCodeProc,CommInterface,Display,UI interface
    class EmergencyStop critical
    class MotionPlanning,Kinematics control
```
