$ show gin66/FastAccelStepper
FastAccelStepper is a high-performance stepper motor control library for Arduino/ESP-IDF, supporting AVR, ESP32, SAM, SAMD51, and RP2040 platforms. It provides precise trapezoidal (optionally cubic) acceleration ramps with tick-exact step generation through a queue-based command execution model. The library abstracts hardware pulse generation behind a platform driver pattern (AVR timers, ESP32 RMT/MCPWM/PCNT/I2S, RP2040 PIO, SAM/SAMD51 timers) and avoids floating-point arithmetic by using a custom fixed-point log2 representation for speed calculations. It includes extensive automated testing (simulated AVR with VCD traces, PC-based unit tests, ESP32 hardware-in-the-loop) and CI matrices covering 50+ environment combinations. The library is production-ready, published on Arduino Library Manager and PlatformIO, with a detailed changelog from v0.8.0 to v1.3.3. It is used in real robotic and motion control systems, evidenced by issue reproductions for direction-change miscounts. Though the codebase is actively maintained, it suffers from conditional compilation proliferation across multiple ESP-IDF versions (4/5/6) and chip variants, and some platforms (SAM) have known bugs with no CI coverage. A major refactoring of direction-change handling is proposed but not yet merged. A companion web-based demo application (Esp32StepperDemo) is under design but incomplete. Highlights include the log2 fixed-point math component, a lock-free ring buffer queue, a portable platform abstraction layer, and an I2S mux driver capable of driving 32 steppers from one I2S transmitter. The extensive test harnesses and build-matrix generation scripts provide a solid foundation for regression testing across diverse hardware.
The LLM identified 5 files worth highlighting for reuse:
Self-contained 16-bit fixed-point logarithm representation enabling fast multiply, divide, and square-root operations without floating-point hardware. Used for ramp calculations; can be extracted into any embedded project requiring efficient math, with no external dependencies beyond standard integer types.
Compact header providing macros for platform-specific operations (interrupt enable/disable, GPIO output, NOP wait). Follows a simple 'supply-a-macro-per-platform' pattern that can be adapted to any new embedded target, enabling the core library to remain platform-agnostic.
Implements a lock-free circular command queue for stepper instructions. The queue structure and operations (push/pop/peek) are generic and could be reused in other embedded command-processing contexts (e.g., motor controllers, sensor samplers) with minimal changes to the element type and size.
Manages an I2S peripheral to generate precise step pulses for up to 32 steppers using DMA double-buffering. Demonstrates a non-trivial pattern for generating arbitrary digital waveforms from a serial sample stream; could be extracted as a generic bit-bang output generator for parallel control signals.
Computes acceleration/deceleration profiles using log2 fixed-point math to avoid floating-point overhead. The algorithm solves the equations of motion for stepping motors (distance = 0.5 * accel * t^2) via table lookups. This pattern is directly reusable in any motion control system requiring efficient ramp generation.