# adam97-1/colorsorterc architecture

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

- Interactive diagram: https://gitdiagram.com/adam97-1/colorsorterc
- Repository: https://github.com/adam97-1/colorsorterc

## Overview

This is STM32F446 firmware for a sensor-guided robot. The main workflow initializes the board and periodic task loop, samples color and IR sensors, maps detected colors to selector-motor positions, and regulates two motors using encoder feedback. The graph also retains the clock/tick, task scheduling, MCU register definitions, and CMSIS support layers. Several implementation files were not sampled; where their behavior is only suggested by the source index, links are marked unverified rather than asserted.

Main entry points: [`Src/main.c`](https://github.com/adam97-1/colorsorterc/blob/master/Src/main.c) (Application entry), [`Src/MotorSel/MotorSel.c`](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSel.c) (Selector motor), [`Src/TaskMenager.c`](https://github.com/adam97-1/colorsorterc/blob/master/Src/TaskMenager.c) (Task manager), [`Src/MotorDriv/MotorDriv.c`](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/MotorDriv.c) (Drive motor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Firmware workflow"]
  node_app["Application entry<br/>[main.c]"]
  node_tasks["Task manager<br/>[TaskMenager.c]"]
end

subgraph group_sensing["Sensors and detection"]
  node_ircol["Color IR detector<br/>[IrDetectorCol.c]"]
  node_irsel["Selector IR detector<br/>[IrDetectorSel.c]"]
  node_color["Color sampling<br/>[ColorDetector.c]"]
end

subgraph group_motion["Motion control"]
  node_drive["Drive motor<br/>[MotorDriv.c]"]
  node_driveenc["Drive encoder<br/>[EncoderDriv.c]"]
  node_drivereg["Drive speed regulator"]
  node_selector["Selector motor<br/>[MotorSel.c]"]
  node_selenc["Selector encoder<br/>[EncoderSel.c]"]
  node_selpos["Position regulator"]
  node_selreg["Selector speed regulator"]
  node_functions["Motion utilities<br/>[Functions.c]"]
end

subgraph group_platform["MCU platform"]
  node_clock["Clock setup<br/>[Clock.c]"]
  node_systick["SysTick<br/>[SysTick.c]"]
  node_device["STM32F446 registers<br/>[stm32f446xx.h]"]
  node_cmsis["CMSIS core support"]
end

node_power(("Power-on"))

node_power -->|"starts"| node_app
node_app -->|"initializes"| node_clock
node_app -->|"initializes"| node_systick
node_app -->|"initializes"| node_tasks
node_app -->|"initializes"| node_ircol
node_app -->|"initializes"| node_irsel
node_app -->|"initializes"| node_color
node_app -->|"initializes"| node_drive
node_app -->|"initializes"| node_selector
node_app -->|"runs"| node_tasks
node_app -->|"registers callback"| node_ircol
node_app -->|"registers callback"| node_irsel
node_app -->|"registers callback"| node_color
node_ircol -->|"requests sample"| node_color
node_color -.->|"delivers color"| node_app
node_irsel -.->|"signals edge"| node_app
node_app -->|"sets position"| node_selector
node_drive -.->|"registers loop"| node_tasks
node_selector -->|"registers loop"| node_tasks
node_selector -->|"calculates target speed"| node_selpos
node_selector -->|"calculates output"| node_selreg
node_selector -->|"reads feedback"| node_selenc
node_selector -->|"writes PWM"| node_device
node_selector -->|"initializes"| node_selenc
node_selector -->|"initializes"| node_selpos
node_selector -->|"initializes"| node_selreg
node_drive -.->|"uses feedback"| node_driveenc
node_drive -.->|"uses regulator"| node_drivereg
node_driveenc -->|"registers sampling"| node_tasks
node_driveenc -->|"uses distance helper"| node_functions
node_selenc -.->|"registers sampling"| node_tasks
node_selpos -.->|"uses helper"| node_functions
node_selreg -.->|"uses helper"| node_functions
node_device -.->|"uses core definitions"| node_cmsis

click node_app "https://github.com/adam97-1/colorsorterc/blob/master/Src/main.c"
click node_tasks "https://github.com/adam97-1/colorsorterc/blob/master/Src/TaskMenager.c"
click node_clock "https://github.com/adam97-1/colorsorterc/blob/master/Src/Clock.c"
click node_systick "https://github.com/adam97-1/colorsorterc/blob/master/Src/SysTick.c"
click node_ircol "https://github.com/adam97-1/colorsorterc/blob/master/Src/IrDetectorCol.c"
click node_irsel "https://github.com/adam97-1/colorsorterc/blob/master/Src/IrDetectorSel.c"
click node_color "https://github.com/adam97-1/colorsorterc/blob/master/Src/ColorDetector.c"
click node_drive "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/MotorDriv.c"
click node_driveenc "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/EncoderDriv.c"
click node_drivereg "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/MotorDrivSpeedRegulator.c"
click node_selector "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSel.c"
click node_selenc "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/EncoderSel.c"
click node_selpos "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSelPositionRegulator.c"
click node_selreg "https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSelSpeedRegulator.c"
click node_functions "https://github.com/adam97-1/colorsorterc/blob/master/Src/Functions.c"
click node_device "https://github.com/adam97-1/colorsorterc/blob/master/Device/ST/STM32F4xx/Include/stm32f446xx.h"
click node_cmsis "https://github.com/adam97-1/colorsorterc/tree/master/Core/Include"

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_app,node_tasks toneBlue
class node_ircol,node_irsel,node_color toneAmber
class node_drive,node_driveenc,node_drivereg,node_selector,node_selenc,node_selpos,node_selreg,node_functions toneMint
class node_clock,node_systick,node_device,node_cmsis toneRose
class node_power toneIndigo
```

## Components

### Firmware workflow

- [Application entry](https://github.com/adam97-1/colorsorterc/blob/master/Src/main.c): `Src/main.c`
- [Task manager](https://github.com/adam97-1/colorsorterc/blob/master/Src/TaskMenager.c): `Src/TaskMenager.c`

### Sensors and detection

- [Color IR detector](https://github.com/adam97-1/colorsorterc/blob/master/Src/IrDetectorCol.c): `Src/IrDetectorCol.c`
- [Selector IR detector](https://github.com/adam97-1/colorsorterc/blob/master/Src/IrDetectorSel.c): `Src/IrDetectorSel.c`
- [Color sampling](https://github.com/adam97-1/colorsorterc/blob/master/Src/ColorDetector.c): `Src/ColorDetector.c`

### Motion control

- [Drive motor](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/MotorDriv.c): `Src/MotorDriv/MotorDriv.c`
- [Drive encoder](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/EncoderDriv.c): `Src/MotorDriv/EncoderDriv.c`
- [Drive speed regulator](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorDriv/MotorDrivSpeedRegulator.c): `Src/MotorDriv/MotorDrivSpeedRegulator.c`
- [Selector motor](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSel.c): `Src/MotorSel/MotorSel.c`
- [Selector encoder](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/EncoderSel.c): `Src/MotorSel/EncoderSel.c`
- [Position regulator](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSelPositionRegulator.c): `Src/MotorSel/MotorSelPositionRegulator.c`
- [Selector speed regulator](https://github.com/adam97-1/colorsorterc/blob/master/Src/MotorSel/MotorSelSpeedRegulator.c): `Src/MotorSel/MotorSelSpeedRegulator.c`
- [Motion utilities](https://github.com/adam97-1/colorsorterc/blob/master/Src/Functions.c): `Src/Functions.c`

### MCU platform

- [Clock setup](https://github.com/adam97-1/colorsorterc/blob/master/Src/Clock.c): `Src/Clock.c`
- [SysTick](https://github.com/adam97-1/colorsorterc/blob/master/Src/SysTick.c): `Src/SysTick.c`
- [STM32F446 registers](https://github.com/adam97-1/colorsorterc/blob/master/Device/ST/STM32F4xx/Include/stm32f446xx.h): `Device/ST/STM32F4xx/Include/stm32f446xx.h`
- [CMSIS core support](https://github.com/adam97-1/colorsorterc/tree/master/Core/Include): `Core/Include`

### Other components

- **Power-on**

## Connections

- Power-on → Application entry: starts (evidence: `Src/main.c`)
- Application entry → Clock setup: initializes (evidence: `Src/main.c`)
- Application entry → SysTick: initializes (evidence: `Src/main.c`)
- Application entry → Task manager: initializes (evidence: `Src/main.c`)
- Application entry → Color IR detector: initializes (evidence: `Src/main.c`)
- Application entry → Selector IR detector: initializes (evidence: `Src/main.c`)
- Application entry → Color sampling: initializes (evidence: `Src/main.c`)
- Application entry → Drive motor: initializes (evidence: `Src/main.c`)
- Application entry → Selector motor: initializes (evidence: `Src/main.c`)
- Application entry → Task manager: runs (evidence: `Src/main.c`)
- Application entry → Color IR detector: registers callback (evidence: `Src/main.c`)
- Application entry → Selector IR detector: registers callback (evidence: `Src/main.c`)
- Application entry → Color sampling: registers callback (evidence: `Src/main.c`)
- Color IR detector → Color sampling: requests sample
- Color sampling → Application entry: delivers color
- Selector IR detector → Application entry: signals edge
- Application entry → Selector motor: sets position (evidence: `Src/main.c`)
- Drive motor → Task manager: registers loop
- Selector motor → Task manager: registers loop (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Position regulator: calculates target speed (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Selector speed regulator: calculates output (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Selector encoder: reads feedback (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → STM32F446 registers: writes PWM (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Selector encoder: initializes (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Position regulator: initializes (evidence: `Src/MotorSel/MotorSel.c`)
- Selector motor → Selector speed regulator: initializes (evidence: `Src/MotorSel/MotorSel.c`)
- Drive motor → Drive encoder: uses feedback
- Drive motor → Drive speed regulator: uses regulator
- Drive encoder → Task manager: registers sampling (evidence: `Src/MotorDriv/EncoderDriv.c`)
- Drive encoder → Motion utilities: uses distance helper (evidence: `Src/MotorDriv/EncoderDriv.c`)
- Selector encoder → Task manager: registers sampling
- Position regulator → Motion utilities: uses helper
- Selector speed regulator → Motion utilities: uses helper
- STM32F446 registers → CMSIS core support: uses core definitions
