How addy771/simple-pico-vesc-display works
Project type and purpose
• This is an embedded firmware project (“Simple Pico VESC Display”) for the Raspberry Pi Pico (RP2040) that interfaces with VESC motor controllers over UART/CAN, renders a real‐time dashboard on an SSD1306 display, and logs data to microSD via FatFS.
File structure
• Top-level code files (buffer.c/h, display.cpp, packet.c/h, page_ctrl.cpp/h, log.cpp/hpp, nv_flash.cpp/hpp, hw_def.c/h, hw_config.c, crc.c/h) implement application logic, hardware abstraction, communication parsing, UI state, logging, and non-volatile storage.
• The “FatFS-SD” directory is the microSD SPI file-system module.
• The “u8g2” submodule provides the SSD1306 graphics library and drivers.
• The “bldc” directory is the VESC firmware source (GPL) included for reference or cross-compilation.
• CMakeLists.txt and pico_sdk_import.cmake orchestrate the build using the pico-sdk, often invoked via a Docker toolchain.
Extract insights from README
• Interfaces: UART or CAN to external VESC controllers.
• Outputs: SSD1306 (SPI-driven via PIO code), microSD logging.
• Build: cross-compile with pico-sdk under Docker, generate “display” binary.
Main components
a. Hardware Components
• RP2040 Microcontroller (dual-core, PIO engines)
• SSD1306 OLED Display (SPI/P0 bit-bang)
• microSD card (SPI, FatFS)
• External VESC Motor Controller(s) (UART and/or CAN bus)
• On-board QSPI flash (for nv_flash storage)
b. Software Modules (on RP2040)
• Hardware Abstraction Layer (hw_def, hw_config)
• PIO Drivers (spi_tx_9bit.pio)
• Comm Manager (UART/CAN receiver, packet.c parser)
• Data Model (datatypes.h structures for speed, voltage, etc.)
• UI Controller (page_ctrl: state machine for dashboard pages)
• Renderer (buffer.c/h, u8g2 library draws into frame buffer)
• Storage Manager (FatFS-SD drivers, nv_flash for config)
• Logging (log.cpp/hpp writes parsed data to SD via FatFS)
• Utility (crc check, buffer management, packet framing)
c. Build System
• CMake + pico-sdk
• Docker cross-compile environment
Relationships and data flow
• Data In: VESC → (UART/CAN) → Comm Manager → Packet Parser → Data Model
• Application: Data Model → Page Controller → Display Renderer → PIO SPI → SSD1306
• Logging: Data Model / Log module → FatFS → microSD
• Config/State: nv_flash module ↔ QSPI flash (stores user prefs, calibration)
• Hardware Layer: HAL provides pin mappings to Comm, PIO, SD drivers
Architectural patterns
• Layered architecture:
• HAL Layer (hw_def/config, PIO drivers)
• Driver Layer (UART/CAN, SPI, FatFS, u8g2)
• Service Layer (Comm Manager, Storage Manager, Logging)
• Application Layer (Page Controller, UI Renderer)
• State-machine pattern in page_ctrl for UI navigation.
• Producer–consumer pattern: incoming data feeds both UI and logger.