# violet10b/hwstepgen architecture

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

- Interactive diagram: https://gitdiagram.com/violet10b/hwstepgen
- Repository: https://github.com/violet10b/hwstepgen

## Overview

HWStepGen is an ESP32 stepper-motor speed-control library: applications configure motors, command speed or direction, optionally ramp speed, and the LEDC peripheral generates STEP pulses independently of the CPU. It provides single-motor control, coordinated multi-motor operations, frequency/timer checks, and hardware-capability limits. The graph follows calls visible in sampled source; README-documented behavior whose internal wiring was not sampled is represented only where its owning module is clear.

Main entry points: [`src/hwsg/Stepper.cpp`](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Stepper.cpp) (Stepper control), [`src/hwsg/detail/LedcBackend.cpp`](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/LedcBackend.cpp) (LEDC backend), [`src/hwsg/Ramp.cpp`](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Ramp.cpp) (Speed ramp), [`src/hwsg/StepperBank.cpp`](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/StepperBank.cpp) (Stepper bank)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Motor API"]
  node_stepper["Stepper control<br/>[Stepper.cpp]"]
  node_types["Config and errors<br/>[Types.cpp]"]
end

subgraph group_coordination["Motion Coordination"]
  node_ramp["Speed ramp<br/>[Ramp.cpp]"]
  node_bank["Stepper bank<br/>[StepperBank.cpp]"]
end

subgraph group_hardware["Pulse Hardware"]
  node_backend["Backend selector<br/>[Backend.h]"]
  node_ledcbackend["LEDC backend<br/>[LedcBackend.cpp]"]
  node_allocator["Channel allocator<br/>[LedcBackend.cpp]"]
  node_ledccompat["LEDC compatibility<br/>[Ledc.h]"]
end

subgraph group_platform["ESP32 Platform"]
  node_soc["SoC capabilities<br/>[SocCaps.h]"]
end

node_application(("Arduino application"))
node_arduino["Arduino ESP32 core"]
node_peripheral["LEDC peripheral"]
node_gpio["ESP32 GPIO"]
node_driver["Step-dir driver"]
node_motor(("Stepper motor"))

node_application -->|"commands"| node_stepper
node_application -->|"updates"| node_ramp
node_application -->|"group commands"| node_bank
node_ramp -->|"sets speed"| node_stepper
node_bank -->|"dispatches"| node_stepper
node_stepper -->|"controls pulses"| node_backend
node_stepper -->|"sets DIR/ENABLE"| node_gpio
node_backend -->|"selects default"| node_ledcbackend
node_ledcbackend -->|"reserves timer"| node_allocator
node_ledcbackend -->|"configures output"| node_ledccompat
node_ledcbackend -->|"uses capabilities"| node_soc
node_ledccompat -->|"calls LEDC API"| node_arduino
node_arduino -->|"configures"| node_peripheral
node_stepper -->|"checks pins/ranges"| node_soc
node_peripheral -->|"emits STEP pulses"| node_driver
node_gpio -->|"drives DIR/ENABLE"| node_driver
node_driver -->|"drives coils"| node_motor

click node_stepper "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Stepper.cpp"
click node_types "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Types.cpp"
click node_ramp "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Ramp.cpp"
click node_bank "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/StepperBank.cpp"
click node_backend "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/Backend.h"
click node_ledcbackend "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/LedcBackend.cpp"
click node_allocator "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/LedcBackend.cpp"
click node_ledccompat "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/Ledc.h"
click node_soc "https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/SocCaps.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_stepper,node_types toneBlue
class node_ramp,node_bank toneAmber
class node_backend,node_ledcbackend,node_allocator,node_ledccompat toneMint
class node_soc toneRose
class node_application,node_arduino,node_peripheral,node_gpio,node_driver,node_motor toneIndigo
```

## Components

### Motor API

- [Stepper control](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Stepper.cpp): `src/hwsg/Stepper.cpp`
- [Config and errors](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Types.cpp): `src/hwsg/Types.cpp`

### Motion Coordination

- [Speed ramp](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/Ramp.cpp): `src/hwsg/Ramp.cpp`
- [Stepper bank](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/StepperBank.cpp): `src/hwsg/StepperBank.cpp`

### Pulse Hardware

- [Backend selector](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/Backend.h): `src/hwsg/detail/Backend.h`
- [LEDC backend](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/LedcBackend.cpp): `src/hwsg/detail/LedcBackend.cpp`
- [Channel allocator](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/LedcBackend.cpp): `src/hwsg/detail/LedcBackend.cpp`
- [LEDC compatibility](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/Ledc.h): `src/hwsg/detail/Ledc.h`

### ESP32 Platform

- [SoC capabilities](https://github.com/violet10b/hwstepgen/blob/main/src/hwsg/detail/SocCaps.h): `src/hwsg/detail/SocCaps.h`

### Other components

- **Arduino application**
- **Arduino ESP32 core**
- **LEDC peripheral**
- **ESP32 GPIO**
- **Step-dir driver**
- **Stepper motor**

## Connections

- Arduino application → Stepper control: commands
- Arduino application → Speed ramp: updates
- Arduino application → Stepper bank: group commands
- Speed ramp → Stepper control: sets speed
- Stepper bank → Stepper control: dispatches
- Stepper control → Backend selector: controls pulses
- Stepper control → ESP32 GPIO: sets DIR/ENABLE
- Backend selector → LEDC backend: selects default
- LEDC backend → Channel allocator: reserves timer
- LEDC backend → LEDC compatibility: configures output
- LEDC backend → SoC capabilities: uses capabilities
- LEDC compatibility → Arduino ESP32 core: calls LEDC API
- Arduino ESP32 core → LEDC peripheral: configures
- Stepper control → SoC capabilities: checks pins/ranges
- LEDC peripheral → Step-dir driver: emits STEP pulses
- ESP32 GPIO → Step-dir driver: drives DIR/ENABLE
- Step-dir driver → Stepper motor: drives coils
