# liren197968/sweeprobot architecture

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

- Interactive diagram: https://gitdiagram.com/liren197968/sweeprobot
- Repository: https://github.com/liren197968/sweeprobot

## Overview

##### Project type and purpose
- This is an embedded-firmware project for a “SweepRobot” (a vacuum-cleaning robot) running primarily on an STM32F4 microcontroller.
- There is also a Cortex-A53 directory (likely Linux or higher-level code) and a smaller “JoystickProject” that demonstrates USB-host joystick support on STM32F4.

##### File structure
- Top-level:
- CortexA53 – higher-level code (Linux? analysis tools)
- Stm32F4 – two subprojects: JoystickProject and RobotProject
- Document – design docs, schematics, PCA9685 spec
- RobotProject layers:
- Drivers – CMSIS core + DSP libraries, STM32 HAL driver, RTOS template, USB-host middleware
- Middlewares – ST USB-Host stack (HID class)
- Robot – application modules (control algorithms, DH math)
- RobotDriver – sensor and actuator drivers (IMU, gas sensor, LoRa, motors, servos, OLED, beeper, battery monitor, Bluetooth, EEPROM, etc.)
- Src/Inc – board-specific initialization, peripheral wrappers (GPIO, I2C, SPI, ADC, DMA, TIM, USART, USB host)
- .ioc, MDK-ARM – CubeMX and Keil project configurations

##### README.md
- Confirms this is the open-source code for a sweep-robot.

##### Final advice
- Be very detailed: capture each bus, driver module, and external device as its own block.
- Explicitly separate layers and show how data flows from sensor inputs through drivers into the control algorithm, and back out as motor commands.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Cortex-A53 Subsystem
    CortexA53["Cortex-A53 Subsystem"]:::external
    click CortexA53 "https://github.com/liren197968/sweeprobot/tree/master/CortexA53/"

    %% Joystick Demo
    JoystickDemo["JoystickProject (USB-Host Demo)"]:::external
    click JoystickDemo "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/JoystickProject/"

    %% Robot Project
    subgraph "RobotProject (SweepRobot Firmware)"
        direction TB
        subgraph "STM32F4 MCU"
            direction TB

            %% Board Support Layer
            subgraph "Board Support Package" 
                direction TB
                CMSIS["CMSIS Core & DSP"]:::hal
                click CMSIS "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Drivers/CMSIS/"
                HAL["STM32 HAL Drivers"]:::hal
                click HAL "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Drivers/STM32F4xx_HAL_Driver/"
                RTOS["RTOS Template"]:::hal
                click RTOS "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Drivers/CMSIS/RTOS/Template/"
            end

            %% Middleware Layer
            subgraph "USB-Host Middleware"
                USBHostML["ST USB-Host Library"]:::middleware
                click USBHostML "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Middlewares/ST/STM32_USB_Host_Library/"
            end

            %% HAL Wrappers (Hardware Abstraction)
            subgraph "HAL Wrappers"
                Inc["Includes (gpio,i2c,spi,adc,dma,tim,usart,usb)"]:::hal
                click Inc "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Inc/"
                Src["Sources (msp init, system, peripheral drivers)"]:::hal
                click Src "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Src/"
            end

            %% Application Layer
            subgraph "Application"
                direction TB
                Control["Control & Navigation"]:::app
                click Control "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotControl/"
                subgraph "RocRobotDriver Modules"
                    direction TB
                    IMU["IMU (MPU6050)"]:::app
                    click IMU "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocImu/RocMpu6050/"
                    Gas["Gas Sensor (Zmod4410)"]:::app
                    click Gas "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Zmod4410/"
                    Battery["Battery Monitor"]:::app
                    click Battery "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocBattery/"
                    Beeper["Beeper"]:::app
                    click Beeper "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocBeeper/"
                    Bluetooth["Bluetooth UART"]:::app
                    click Bluetooth "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocBluetooth/"
                    EEPROM["EEPROM (AT24C02)"]:::app
                    click EEPROM "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocEeprom/"
                    LEDs["LEDs"]:::app
                    click LEDs "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocLed/"
                    LoRa["LoRa Radio (SX1276)"]:::app
                    click LoRa "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocLoRa/"
                    Motors["Motors (PWM)"]:::app
                    click Motors "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocMotor/"
                    Servos["Servos (PCA9685)"]:::app
                    click Servos "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocPca9685/"
                    OLED["OLED Display"]:::app
                    click OLED "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocOled/"
                    Relay["Relay"]:::app
                    click Relay "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocRelay/"
                    USBHID["USB-HID Gamepad"]:::app
                    click USBHID "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/Robot/RocRobotDriver/RocUsb/"
                end
            end
        end

        %% Board Config Files
        CubeMX["CubeMX Config (.ioc)"]:::hardware
        click CubeMX "https://github.com/liren197968/sweeprobot/blob/master/Stm32F4/RobotProject/SweepRobot.ioc"
        Keil["Keil MDK-ARM Project"]:::hardware
        click Keil "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/MDK-ARM/"

        %% External USB-Host Utilities
        USBHostUtil["USBHost Utilities"]:::hardware
        click USBHostUtil "https://github.com/liren197968/sweeprobot/tree/master/Stm32F4/RobotProject/USB/USBHost/"
    end

    %% Hardware Buses
    subgraph "Hardware Buses"
        I2C["I2C Bus"]:::hardware
        SPI["SPI Bus"]:::hardware
        UART["UART"]:::hardware
        USB["USB-Host Port"]:::hardware
        PWM["PWM Timers"]:::hardware
        ADC["ADC"]:::hardware
    end

    %% External Devices
    subgraph "External Sensors & Actuators"
        direction TB
        IMUDev["IMU (MPU6050)"]:::external
        GasDev["Gas Sensor (Zmod4410)"]:::external
        EEPROMDev["EEPROM"]:::external
        ServosDev["Servos (PCA9685)"]:::external
        LoRaDev["LoRa Module (SX1276)"]:::external
        BluetoothDev["Bluetooth Module"]:::external
        USBGamepad["USB-HID Gamepad"]:::external
        MotorsDev["Wheel & Vacuum Motors"]:::external
        LEDsDev["LEDs & Beeper"]:::external
        BatteryDev["Battery Monitor"]:::external
        OLEDDev["OLED Display"]:::external
        RelayDev["Relay"]:::external
    end

    %% Connections: MCU layers
    CMSIS --> HAL --> USBHostML --> Control
    Control --> IMU
    Control --> Gas
    Control --> Motors
    Control --> Servos

    %% Connections: Buses to MCU
    I2C --> Inc
    SPI --> Inc
    UART --> Inc
    USB --> USBHostML
    PWM --> Inc
    ADC --> Inc

    %% Connections: Buses to external
    I2C --> IMUDev
    I2C --> EEPROMDev
    I2C --> GasDev
    I2C --> ServosDev
    SPI --> LoRaDev
    UART --> BluetoothDev
    USB --> USBGamepad
    PWM --> MotorsDev
    PWM --> LEDsDev
    ADC --> BatteryDev

    %% Data flow arrows
    IMUDev --> IMU
    GasDev --> Gas
    EEPROMDev --> EEPROM
    LoRaDev --> LoRa
    BluetoothDev --> Bluetooth
    USBGamepad --> USBHID
    MotorsDev --> Motors
    ServosDev --> Servos
    LEDsDev --> LEDs
    BatteryDev --> Battery
    OLEDDev --> OLED
    RelayDev --> Relay

    %% Document links
    PCA9685Doc["PCA9685 Datasheet"]:::external
    click PCA9685Doc "https://github.com/liren197968/sweeprobot/blob/master/Document/PCA9685.pdf"
    Schematics["Electrical Schematics"]:::external
    click Schematics "https://github.com/liren197968/sweeprobot/blob/master/Document/电路原理图V1.0.pdf"
    Docs["Design Docs"]:::external
    click Docs "https://github.com/liren197968/sweeprobot/blob/master/Document/文档说明.txt"

    classDef hal fill:#D0E6F6,stroke:#4A90E2
    classDef middleware fill:#D0F6D8,stroke:#27AE60
    classDef app fill:#F6E2D0,stroke:#E67E22
    classDef hardware fill:#ECECEC,stroke:#7F8C8D
    classDef external fill:#F5F5F5,stroke:#95A5A6
```
