How xiaoshijourney/ydlidar_x2_tof_stm32 works
This firmware fuses YDLIDAR X2 scans and two TOF ranges on an STM32F103. The main loop decodes sensor data; a 100 ms timer path encodes a framed SPI report and applies timeout handling. README documents wall-angle fitting, OLED rendering, and optional USB CDC debugging. The TOF implementation files are not present in the supplied tree, so that subsystem is represented by its enclosing directory; relationships below follow the README and sampled main.c, not an inspection of those missing sources.
Main entry points: main.c Main loop · LIDAR.c Scan decoding · xiaoshi_func SPI frame encode · OLED.c OLED driver
Components 21
Sensor application
- Main loop
Core/Src/main.c - 100 ms handler
Core/Src/main.c - TOF decoding
xiaoshi_func - TOF buffering
xiaoshi_func - Sensor timeouts
xiaoshi_func
LIDAR processing
- Scan decoding
xiaoshi_func/LIDAR.c - Wall angle fit
xiaoshi_func/LIDAR.c - Radar rendering
xiaoshi_func/LIDAR.c
Output interfaces
- SPI frame encode
xiaoshi_func - SPI transmit
Core/Src/main.c - OLED driver
xiaoshi_func/OLED.c - USB CDC debug
USB_DEVICE/App/usbd_cdc_if.c
Board peripherals
- Peripheral setup
Core/Src/main.c - UART and DMA
Core/Src/usart.c - TIM3 setup
Core/Src/tim.c - SPI2 setup
Core/Src/spi.c
Other components
- YDLIDAR X2
- Dual TOF
- SPI host
- OLED display
- USB host
Connections 22
- YDLIDAR X2 → Scan decoding: sends scan
- Main loop → Scan decoding: calls decode
Core/Src/main.c - Scan decoding → Wall angle fit: fits wall
- Dual TOF → TOF buffering: sends ranges
- TOF decoding → TOF buffering: reads queue
- Main loop → TOF decoding: calls decode
Core/Src/main.c - Main loop → Radar rendering: optional draw
- Radar rendering → OLED driver: renders with
- OLED driver → OLED display: updates display
- 100 ms handler → SPI frame encode: calls encode
Core/Src/main.c - Scan decoding → SPI frame encode: supplies distances
- Wall angle fit → SPI frame encode: supplies yaw
- TOF decoding → SPI frame encode: supplies ranges
- 100 ms handler → Sensor timeouts: checks timeouts
Core/Src/main.c - 100 ms handler → SPI transmit: transmits frame
Core/Src/main.c - SPI transmit → SPI host: sends SPI frame
- Main loop → USB CDC debug: optional debug
- USB CDC debug → USB host: exposes serial
- Main loop → Peripheral setup: initializes board
Core/Src/main.c - Peripheral setup → UART and DMA: configures UART
- Peripheral setup → TIM3 setup: configures timer
- Peripheral setup → SPI2 setup: configures SPI