# yangyuanxin/qt-sensor architecture

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

- Interactive diagram: https://gitdiagram.com/yangyuanxin/qt-sensor
- Repository: https://github.com/yangyuanxin/qt-sensor

## Overview

This repository contains STM32 firmware that samples the BH750 light sensor and MQ-2 gas sensor, packages readings in the documented 0xAA sensor frame, and sends the bytes over USART1 for a host to consume. The main loop hands control to an RTOS task; that task selects sensor reads, frames each value, and transmits it. The tree also contains a Qt serial-thread module, but its behavior and connection to the firmware are not established by the available excerpts. Firmware wiring is based on the sampled entry point and application source; peripheral-driver internals were not sampled.

Main entry points: [`Mcu/APP/App.c`](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/APP/App.c) (RTOS app task), [`Mcu/McuPlatform/Core/Src/main.c`](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/McuPlatform/Core/Src/main.c) (Firmware entry), [`Mcu/Bsp/Bh750.c`](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/Bh750.c) (BH750 driver), [`Mcu/Bsp/MQ_2.c`](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/MQ_2.c) (MQ-2 driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Firmware workflow"]
  node_main["Firmware entry<br/>[main.c]"]
  node_application["RTOS app task<br/>[App.c]"]
end

subgraph group_sensing["Sensor acquisition"]
  node_bh750["BH750 driver<br/>[Bh750.c]"]
  node_mq2["MQ-2 driver<br/>[MQ_2.c]"]
end

subgraph group_transport["Serial transport"]
  node_protocol["Sensor framing<br/>[sensor_protocol.c]"]
  node_uart_config["USART1 setup<br/>[usart.c]"]
  node_serial_output["USART1 transmitter<br/>[App.c]"]
end

subgraph group_host["Host software"]
  node_qt_serial["Qt serial thread<br/>[serialthread.cpp]"]
end

node_board(("STM32 board"))
node_bh750_sensor(("BH750 sensor"))
node_mq2_sensor(("MQ-2 sensor"))
node_host(("Serial host"))

node_board -->|"boots"| node_main
node_main -->|"initializes"| node_uart_config
node_main -->|"starts"| node_application
node_application -->|"reads light"| node_bh750
node_bh750_sensor -->|"provides reading"| node_bh750
node_application -->|"reads gas"| node_mq2
node_mq2_sensor -->|"provides reading"| node_mq2
node_application -->|"packs value"| node_protocol
node_application -->|"sends frame"| node_serial_output
node_serial_output -->|"transmits bytes"| node_host

click node_main "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/McuPlatform/Core/Src/main.c"
click node_application "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/APP/App.c"
click node_bh750 "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/Bh750.c"
click node_mq2 "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/MQ_2.c"
click node_protocol "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Common/data_protocol/sensor_protocol.c"
click node_uart_config "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/McuPlatform/Core/Src/usart.c"
click node_serial_output "https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/APP/App.c"
click node_qt_serial "https://github.com/yangyuanxin/qt-sensor/blob/main/QT/SerialDriver/serialthread.cpp"

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_application toneBlue
class node_bh750,node_mq2 toneAmber
class node_protocol,node_uart_config,node_serial_output toneMint
class node_qt_serial toneRose
class node_board,node_bh750_sensor,node_mq2_sensor,node_host toneIndigo
```

## Components

### Firmware workflow

- [Firmware entry](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/McuPlatform/Core/Src/main.c): `Mcu/McuPlatform/Core/Src/main.c`
- [RTOS app task](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/APP/App.c): `Mcu/APP/App.c`

### Sensor acquisition

- [BH750 driver](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/Bh750.c): `Mcu/Bsp/Bh750.c`
- [MQ-2 driver](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Bsp/MQ_2.c): `Mcu/Bsp/MQ_2.c`

### Serial transport

- [Sensor framing](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/Common/data_protocol/sensor_protocol.c): `Mcu/Common/data_protocol/sensor_protocol.c`
- [USART1 setup](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/McuPlatform/Core/Src/usart.c): `Mcu/McuPlatform/Core/Src/usart.c`
- [USART1 transmitter](https://github.com/yangyuanxin/qt-sensor/blob/main/Mcu/APP/App.c): `Mcu/APP/App.c`

### Host software

- [Qt serial thread](https://github.com/yangyuanxin/qt-sensor/blob/main/QT/SerialDriver/serialthread.cpp): `QT/SerialDriver/serialthread.cpp`

### Other components

- **STM32 board**
- **BH750 sensor**
- **MQ-2 sensor**
- **Serial host**

## Connections

- STM32 board → Firmware entry: boots
- Firmware entry → USART1 setup: initializes
- Firmware entry → RTOS app task: starts
- RTOS app task → BH750 driver: reads light
- BH750 sensor → BH750 driver: provides reading
- RTOS app task → MQ-2 driver: reads gas
- MQ-2 sensor → MQ-2 driver: provides reading
- RTOS app task → Sensor framing: packs value
- RTOS app task → USART1 transmitter: sends frame
- USART1 transmitter → Serial host: transmits bytes
