$ show FreeJoy-Team/FreeJoy
This repository contains the firmware for FreeJoy, a highly configurable USB game controller (joystick, HOTAS, steering wheel) based on the STM32F103 (Blue Pill). The firmware implements a composite USB device with joystick HID, custom HID (for configuration), and CDC (for SimHub telemetry). It supports a wide variety of input sensors (ADC, magnetic encoders via SPI/I2C), buttons (GPIO, shift registers), encoders, LEDs (matrix and addressable RGB), and PWM outputs. Configuration is stored in flash and managed via a companion PC tool. A separate USB HID bootloader enables firmware updates. The code is bare-metal, leveraging the deprecated STM32 Standard Peripheral Library and CMSIS 3.5.0, with SEGGER RTT/SysView for debugging. The architecture is monolithic but modular within the firmware, with clear separation between bootloader and application.
The LLM identified 5 files worth highlighting for reuse:
Implements a generic ring buffer (RB_Push, RB_Pop, RB_Size) and a SimHub command parser for CDC telemetry. The ring buffer is self-contained and reusable for any byte-stream protocol on embedded systems. The parser demonstrates a clean pattern for handling stateful serial commands.
Implements a USB HID bootloader that receives firmware in 60-byte packets, validates CRC-16, and writes to flash. This module is self-contained (separate from the application) and can be reused as a generic HID bootloader for other STM32F10x projects. It demonstrates a robust firmware update protocol with integrity checking.
Provides flash-based configuration storage with CRC-16 validation and version migration. The pattern of storing a large struct (dev_config_t) in the last flash pages and validating with CRC is reusable for any embedded project requiring persistent settings. The code carefully handles flash erase/write and config integrity checks.
Implements configurable mapping of analog axis values to digital button outputs (up to 12 buttons per axis). The module reads zone thresholds from the config struct and sets buttons accordingly. This pattern is reusable for any analog input to digital output conversion, though it is coupled to the project's config structure (which can be adapted).
Implements a state machine for various LED effects (static, rainbow, flow, SimHub-reactive). The code cleanly separates effect logic from LED hardware (WS2812B) and uses a timer-based update loop. This pattern can be extracted and adapted for other RGB LED projects.