$ show grblHAL/core
grblHAL/core is an embedded firmware for real-time CNC motion control, derived from the original grbl 1.1f project. It interprets G-code (RS274/NGC) and executes motion planning with acceleration/jerk profiles, driving stepper motors via a hardware abstraction layer (HAL) that supports many 32-bit MCUs (ESP32, STM32, RP2040, i.MX RT, etc.). The architecture is modular: a plugin system allows adding spindles, I/O expanders, kinematics (CoreXY, delta, polar, wall plotter), networking, and custom M-codes. Key subsystems include a G-code parser, motion planner with look-ahead, stepper ISR with Bresenham and AMASS, state machine, settings registry with NVS persistence, virtual file system, and cooperative task scheduler. Communication streams (serial, TCP, WebSocket, Modbus) are multiplexed. The codebase is highly optimized for real-time constraints, uses extensive conditional compilation for configurability, and provides reusable patterns such as function-pointer-based HAL, callback chaining, and abstracted I/O. While some internal coupling exists, many modules (crc, regex, utf8, string utilities, PID, expression evaluator, task scheduler) are self-contained and extractable.
The LLM identified 8 files worth highlighting for reuse:
A minimal, self-contained regular expression matcher by Rob Pike implementing grep-like patterns (literal, ., ^, $, *, and character classes). Single C file with no external dependencies, easily reusable in any embedded or systems project needing lightweight pattern matching.
Implements CRC-8 (grbl CRC), Modbus CRC-16, and CCITT CRC-16. Each function is small, table-driven, and standalone. Useful for any embedded project requiring CRC computation for communication or storage integrity.
UTF-32 to UTF-8 byte sequence encoding, self-contained and dependency-free. Converts a single Unicode code point into 1-4 byte UTF-8 sequence. Suitable for any system needing to output UTF-8 strings without full Unicode library.
String utility functions including case-insensitive search, tokenization, line counting, datetime parsing, and human-readable byte formatting. Standalone, no dependencies beyond standard C. Useful in any C project needing robust string helpers.
A PID controller implementation with configurable Kp, Ki, Kd, output limits, integral windup prevention, and optional derivative filtering. Self-contained, header provides a PID state struct. Easily reusable for spindle speed control, temperature regulation, or any closed-loop system.
An expression evaluator conforming to NIST RS274NGC standard. Supports binary/unary operators, named parameters, functions (e.g., EXISTS), and arithmetic precedence. Standalone (depends only on ngc_expr.h and standard libs). Reusable in any context needing a compact, embeddable arithmetic expression evaluator.
A lightweight cooperative task scheduler supporting delayed, immediate, and systick-interval tasks. Task list is a linked list of `delayed_task_t` structures. Self-contained, no external dependencies. Reusable in embedded firmware for debouncing, polling, and deferred execution.
Emulates non-volatile storage in RAM with periodic synchronous writes to physical storage. Manages a buffer with CRC validation, dirty flag, and configurable sync interval. Self-contained (requires only basic HAL abstraction for storage write). Reusable in projects that need EEPROM emulation on MCUs without hardware NVS.