How hjd1964/onstepx works
Project Type and Purpose
• This is an embedded firmware project (OnStep) for controlling telescope mounts and accessories.
• It provides a hardware-agnostic control core with support for multiple MCUs (Arduino M0, Mega2560/328, ESP32/8266, STM32, Teensy, RP2040, etc.).
• Key features include motion control (axes, motors, step/servo), mount functions (goto, guide, park, PEC), auxiliary devices (dew heater, intervalometer), communications (serial, Ethernet, Wi-Fi, Bluetooth, CAN), and plugin extensibility.
File Structure and Architectural Layers
– Top Level
• OnStepX.ino, Config.h, Extended.config.h: sketch entry points and configuration overrides.
• src/ folder: all source code.
– HAL Layer (src/HAL)
• Common HAL interface (HAL.h) and per-MCU header implementations.
• Abstracts timers, GPIO, serial, I²C, SPI, PWM, interrupts.
– Core Libraries (src/lib)
• Drivers for encoders, motors (stepDir, servo), 1-wire, CAN, calendars, tasks scheduler (OnTask), watchdog, NV storage, etc.
• Communications sub-modules: serial (local, IP over Ethernet/Wi-Fi), web/cmd servers, Bluetooth.
– Application Layer (src/libApp, src/telescope)
• libApp: high-level command processing, temperature & weather modules.
• telescope: mount, focuser, rotator, auxiliary feature implementations with command handlers.
– Configuration & Pinmaps (src/pinmaps)
• MCU/board-specific pin definitions.
– Plugins (src/plugins)
• Sample plugin interface and stub for third-party feature extensions.
Architectural Patterns and Key Components
• Layered architecture:
– Hardware Abstraction Layer → Core Drivers & Services → Application Modules → Plugins
• Modular motor control: axis library uses pluggable motor drivers (oDrive, kTech, DC, TMC SPI/UART).
• Task scheduler (OnTask) creates pseudo-RTOS for timed operations.
• Communication stack: uniform “Serial” API multiplexed over physical UART, Ethernet, Wi-Fi or Bluetooth.
a. Main Components
– Hardware: MCU (choose one), power, sensors, actuators, communications peripherals.
– HAL Module: timer, GPIO, serial, I²C, SPI, PWM interfaces.
– Core Services: OnTask scheduler, NV storage, watchdog, debug/log.
– Driver Libraries: motor drivers, encoder interfaces, temperature/clock modules, CAN, calendars.
– Application Modules: mount controller, focuser, rotator, auxiliary (dew heater, intervalometer), command processor.
– Communication Interfaces: Serial, Ethernet, Wi-Fi, Bluetooth, Web/CMD servers.
– Plugin Layer.
b. Relationships & Data Flow
• MCU peripherals → HAL layer → core services & drivers → application modules → external devices (motors, encoders, heaters).
• Command inputs (serial, network) → command processor → application modules → driver APIs → actuators.
• Sensor data (temperature, encoders) → driver libraries → application logic → telemetry over comms.
c. Patterns
• Layer separation: physical vs. HAL vs. services vs. logic.
• Pluggable drivers and plugins.
• Single scheduler coordinating tasks.
d. Technologies
• C++ classes for HAL, drivers, modules.
• OnTask scheduler.
• Network stacks (EthernetManager, WifiManager).
• Motor protocols (StepDir, servo, TMC, oDrive).