# tghan98/surearly-multi architecture

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

- Interactive diagram: https://gitdiagram.com/tghan98/surearly-multi
- Repository: https://github.com/tghan98/surearly-multi

## Overview

This is embedded firmware for an STM8L15x optical stick-testing device. The main loop initializes hardware and repeatedly runs a test sequence: check insertion and usage, acquire optical measurements, evaluate the sample, and present status on the LCD. Supporting branches handle stored scan counts, hardware access, and timer/ADC/serial interrupts. The README is empty; relationships below are limited to calls and references shown in the supplied excerpts and SOURCE INDEX, so peripheral-level wiring is not expanded.

Main entry points: [`USER/App/DM_Main_Sq_App.c`](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Main_Sq_App.c) (Test sequence), [`USER/App/DM_Optic_Handle_App.c`](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Optic_Handle_App.c) (Optical sensing), [`USER/User_Main.c`](https://github.com/tghan98/surearly-multi/blob/main/USER/User_Main.c) (User runtime), [`USER/Drive/DM_HW_Drv.c`](https://github.com/tghan98/surearly-multi/blob/main/USER/Drive/DM_HW_Drv.c) (Hardware driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_main["Entry point<br/>[main.c]"]
  node_user["User runtime<br/>[User_Main.c]"]
  node_interrupts["Interrupt handlers<br/>[stm8l15x_it.c]"]
end

subgraph group_workflow["Test workflow"]
  node_sequence["Test sequence<br/>[DM_Main_Sq_App.c]"]
  node_optical["Optical sensing"]
  node_lcd["LCD and stick status"]
  node_rom[("Usage data<br/>[DM_Rom_Handl_App.c]")]
  node_parameters["Test parameters<br/>[Parameter_define.h]"]
end

subgraph group_hardware["Hardware access"]
  node_hardware_driver["Hardware driver<br/>[DM_HW_Drv.c]"]
  node_utilities["Calculation utilities<br/>[DM_Utill.c]"]
end

subgraph group_platform["MCU platform"]
  node_peripherals["STM8 peripheral library"]
  node_device_registers["Device definitions<br/>[stm8l15x.h]"]
  node_peripheral_config["Peripheral configuration<br/>[stm8l15x_conf.h]"]
end

node_stick(("Test stick"))

node_main -->|"initializes and runs"| node_user
node_user -->|"initializes hardware"| node_hardware_driver
node_user -->|"processes sequence"| node_sequence
node_user -.->|"handles interrupts"| node_interrupts
node_sequence -->|"measures stick"| node_optical
node_sequence -->|"reads and updates counts"| node_rom
node_sequence -->|"sets display steps"| node_lcd
node_sequence -->|"sleeps"| node_hardware_driver
node_sequence -->|"uses calculations"| node_utilities
node_optical -->|"reads sensors"| node_hardware_driver
node_optical -->|"uses stored data"| node_rom
node_lcd -->|"checks stick presence"| node_optical
node_rom -->|"accesses storage"| node_hardware_driver
node_sequence -->|"uses thresholds"| node_parameters
node_stick -.->|"reflects light"| node_optical
node_peripheral_config -->|"includes definitions"| node_device_registers

click node_main "https://github.com/tghan98/surearly-multi/blob/main/Core/main/main.c"
click node_user "https://github.com/tghan98/surearly-multi/blob/main/USER/User_Main.c"
click node_interrupts "https://github.com/tghan98/surearly-multi/blob/main/Core/main/stm8l15x_it.c"
click node_sequence "https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Main_Sq_App.c"
click node_optical "https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Optic_Handle_App.c"
click node_lcd "https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_LCD_Stick_Check_App.c"
click node_rom "https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Rom_Handl_App.c"
click node_parameters "https://github.com/tghan98/surearly-multi/blob/main/USER/Parameter_define.h"
click node_hardware_driver "https://github.com/tghan98/surearly-multi/blob/main/USER/Drive/DM_HW_Drv.c"
click node_utilities "https://github.com/tghan98/surearly-multi/blob/main/USER/Utill/DM_Utill.c"
click node_peripherals "https://github.com/tghan98/surearly-multi/tree/main/Core/STM8L15x_StdPeriph_Driver/src"
click node_device_registers "https://github.com/tghan98/surearly-multi/blob/main/Core/STM8L15x_StdPeriph_Driver/inc/stm8l15x.h"
click node_peripheral_config "https://github.com/tghan98/surearly-multi/blob/main/Core/main/stm8l15x_conf.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_main,node_user,node_interrupts toneBlue
class node_sequence,node_optical,node_lcd,node_rom,node_parameters toneAmber
class node_hardware_driver,node_utilities toneMint
class node_peripherals,node_device_registers,node_peripheral_config toneRose
class node_stick toneIndigo
```

## Components

### Firmware runtime

- [Entry point](https://github.com/tghan98/surearly-multi/blob/main/Core/main/main.c): `Core/main/main.c`
- [User runtime](https://github.com/tghan98/surearly-multi/blob/main/USER/User_Main.c): `USER/User_Main.c`
- [Interrupt handlers](https://github.com/tghan98/surearly-multi/blob/main/Core/main/stm8l15x_it.c): `Core/main/stm8l15x_it.c`

### Test workflow

- [Test sequence](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Main_Sq_App.c): `USER/App/DM_Main_Sq_App.c`
- [Optical sensing](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Optic_Handle_App.c): `USER/App/DM_Optic_Handle_App.c`
- [LCD and stick status](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_LCD_Stick_Check_App.c): `USER/App/DM_LCD_Stick_Check_App.c`
- [Usage data](https://github.com/tghan98/surearly-multi/blob/main/USER/App/DM_Rom_Handl_App.c): `USER/App/DM_Rom_Handl_App.c`
- [Test parameters](https://github.com/tghan98/surearly-multi/blob/main/USER/Parameter_define.h): `USER/Parameter_define.h`

### Hardware access

- [Hardware driver](https://github.com/tghan98/surearly-multi/blob/main/USER/Drive/DM_HW_Drv.c): `USER/Drive/DM_HW_Drv.c`
- [Calculation utilities](https://github.com/tghan98/surearly-multi/blob/main/USER/Utill/DM_Utill.c): `USER/Utill/DM_Utill.c`

### MCU platform

- [STM8 peripheral library](https://github.com/tghan98/surearly-multi/tree/main/Core/STM8L15x_StdPeriph_Driver/src): `Core/STM8L15x_StdPeriph_Driver/src`
- [Device definitions](https://github.com/tghan98/surearly-multi/blob/main/Core/STM8L15x_StdPeriph_Driver/inc/stm8l15x.h): `Core/STM8L15x_StdPeriph_Driver/inc/stm8l15x.h`
- [Peripheral configuration](https://github.com/tghan98/surearly-multi/blob/main/Core/main/stm8l15x_conf.h): `Core/main/stm8l15x_conf.h`

### Other components

- **Test stick**

## Connections

- Entry point → User runtime: initializes and runs (evidence: `Core/main/main.c`)
- User runtime → Hardware driver: initializes hardware (evidence: `USER/User_Main.c`)
- User runtime → Test sequence: processes sequence (evidence: `USER/User_Main.c`)
- User runtime → Interrupt handlers: handles interrupts
- Test sequence → Optical sensing: measures stick (evidence: `USER/App/DM_Main_Sq_App.c`)
- Test sequence → Usage data: reads and updates counts (evidence: `USER/App/DM_Main_Sq_App.c`)
- Test sequence → LCD and stick status: sets display steps (evidence: `USER/App/DM_Main_Sq_App.c`)
- Test sequence → Hardware driver: sleeps (evidence: `USER/App/DM_Main_Sq_App.c`)
- Test sequence → Calculation utilities: uses calculations (evidence: `USER/App/DM_Main_Sq_App.c`)
- Optical sensing → Hardware driver: reads sensors (evidence: `USER/App/DM_Optic_Handle_App.c`)
- Optical sensing → Usage data: uses stored data (evidence: `USER/App/DM_Optic_Handle_App.c`)
- LCD and stick status → Optical sensing: checks stick presence (evidence: `USER/App/DM_LCD_Stick_Check_App.c`)
- Usage data → Hardware driver: accesses storage (evidence: `USER/App/DM_Rom_Handl_App.c`)
- Test sequence → Test parameters: uses thresholds (evidence: `USER/App/DM_Main_Sq_App.c`)
- Test stick → Optical sensing: reflects light
- Peripheral configuration → Device definitions: includes definitions (evidence: `Core/main/stm8l15x_conf.h`)
