Skip to content

File syn_stepper.c

FileList > motor > syn_stepper.c

Go to the source code of this file

Stepper motor driver implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_stepper.h"
  • #include <string.h>

Public Functions

Type Name
void syn_stepper_enable (const SYN_Stepper * s, bool enable)
Enable or disable the motor driver.
void syn_stepper_init (SYN_Stepper * s, SYN_GPIO_Pin step_pin, SYN_GPIO_Pin dir_pin)
Initialize stepper motor driver.
void syn_stepper_move (SYN_Stepper * s, int32_t steps)
Start a relative move.
void syn_stepper_move_to (SYN_Stepper * s, int32_t position)
Start a move to an absolute position.
SYN_MotorOutput syn_stepper_output (SYN_Stepper * stepper)
Create a SYN_MotorOutput interface for this stepper.
void syn_stepper_set_enable_pin (SYN_Stepper * s, SYN_GPIO_Pin pin, bool active_low)
Set optional enable pin.
void syn_stepper_set_speed (SYN_Stepper * s, uint32_t max_sps, uint32_t accel_sps2)
Set maximum speed and acceleration.
void syn_stepper_stop (SYN_Stepper * s)
Emergency stop — immediately halt with no deceleration.
void syn_stepper_tick (SYN_Stepper * s)
Advance the stepper state machine by one tick.

Public Static Functions

Type Name
void set_direction (const SYN_Stepper * s, bool forward)
Set stepper direction pin.
void stepper_output_brake (void * ctx)
Brake adapter for SYN_MotorOutput .
void stepper_output_coast (void * ctx)
Coast adapter for SYN_MotorOutput .
void stepper_output_set (void * ctx, int32_t output)
Set output adapter for SYN_MotorOutput (ticks the stepper).

Public Functions Documentation

function syn_stepper_enable

Enable or disable the motor driver.

void syn_stepper_enable (
    const SYN_Stepper * s,
    bool enable
) 

Parameters:

  • s Stepper instance.
  • enable true to enable, false to disable.

function syn_stepper_init

Initialize stepper motor driver.

void syn_stepper_init (
    SYN_Stepper * s,
    SYN_GPIO_Pin step_pin,
    SYN_GPIO_Pin dir_pin
) 

Parameters:

  • s Stepper instance.
  • step_pin Step pulse GPIO.
  • dir_pin Direction GPIO.

function syn_stepper_move

Start a relative move.

void syn_stepper_move (
    SYN_Stepper * s,
    int32_t steps
) 

Parameters:

  • s Stepper handle.
  • steps Number of steps (positive = forward, negative = reverse).

function syn_stepper_move_to

Start a move to an absolute position.

void syn_stepper_move_to (
    SYN_Stepper * s,
    int32_t position
) 

Parameters:

  • s Stepper.
  • position Target absolute position in steps.

function syn_stepper_output

Create a SYN_MotorOutput interface for this stepper.

SYN_MotorOutput syn_stepper_output (
    SYN_Stepper * stepper
) 

The set_output callback calls syn_stepper_tick(), coast/brake both call syn_stepper_stop(). The motor controller's output value is not used directly — stepper motion is driven by the stepper's own move/move_to commands.

Parameters:

  • stepper Stepper instance (must outlive the returned output).

Returns:

Motor output interface.


function syn_stepper_set_enable_pin

Set optional enable pin.

void syn_stepper_set_enable_pin (
    SYN_Stepper * s,
    SYN_GPIO_Pin pin,
    bool active_low
) 

Parameters:

  • s Stepper instance.
  • pin Enable signal GPIO pin.
  • active_low True if enabling requires driving pin LOW.

function syn_stepper_set_speed

Set maximum speed and acceleration.

void syn_stepper_set_speed (
    SYN_Stepper * s,
    uint32_t max_sps,
    uint32_t accel_sps2
) 

Parameters:

  • s Stepper.
  • max_sps Maximum speed in steps per second.
  • accel_sps2 Acceleration in steps per second².

function syn_stepper_stop

Emergency stop — immediately halt with no deceleration.

void syn_stepper_stop (
    SYN_Stepper * s
) 

Parameters:

  • s Stepper instance.

function syn_stepper_tick

Advance the stepper state machine by one tick.

void syn_stepper_tick (
    SYN_Stepper * s
) 

Call from a timer ISR or high-frequency loop. The tick rate should be at least 2× the maximum step rate for proper pulse generation.

Parameters:

  • s Stepper instance.

Public Static Functions Documentation

function set_direction

Set stepper direction pin.

static void set_direction (
    const SYN_Stepper * s,
    bool forward
) 

Parameters:

  • s Stepper instance.
  • forward true for forward, false for reverse.

function stepper_output_brake

Brake adapter for SYN_MotorOutput .

static void stepper_output_brake (
    void * ctx
) 

Parameters:

  • ctx Stepper instance (SYN_Stepper*).

function stepper_output_coast

Coast adapter for SYN_MotorOutput .

static void stepper_output_coast (
    void * ctx
) 

Parameters:

  • ctx Stepper instance (SYN_Stepper*).

function stepper_output_set

Set output adapter for SYN_MotorOutput (ticks the stepper).

static void stepper_output_set (
    void * ctx,
    int32_t output
) 

Parameters:

  • ctx Stepper instance (SYN_Stepper*).
  • output Unused — stepper motion is driven by its own commands.


The documentation for this class was generated from the following file src/syntropic/motor/syn_stepper.c