Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Interfaces for stepper motor controllers. More...

Modules

 Trinamic Stepper Controller Interface
 Trinamic Stepper Controller Interface.
 

Files

file  stepper.h
 Main header file for stepper driver API.
 

Macros

#define MICRO_STEP_RES_INDEX(res)   LOG2(res)
 Macro to calculate the index of the microstep resolution.
 
#define VALID_MICRO_STEP_RES(res)
 

Enumerations

enum  stepper_micro_step_resolution {
  STEPPER_MICRO_STEP_1 = 1 , STEPPER_MICRO_STEP_2 = 2 , STEPPER_MICRO_STEP_4 = 4 , STEPPER_MICRO_STEP_8 = 8 ,
  STEPPER_MICRO_STEP_16 = 16 , STEPPER_MICRO_STEP_32 = 32 , STEPPER_MICRO_STEP_64 = 64 , STEPPER_MICRO_STEP_128 = 128 ,
  STEPPER_MICRO_STEP_256 = 256
}
 Stepper Motor micro-step resolution options. More...
 
enum  stepper_direction { STEPPER_DIRECTION_NEGATIVE = 0 , STEPPER_DIRECTION_POSITIVE = 1 }
 Stepper Motor direction options. More...
 
enum  stepper_run_mode { STEPPER_RUN_MODE_HOLD = 0 , STEPPER_RUN_MODE_POSITION = 1 , STEPPER_RUN_MODE_VELOCITY = 2 }
 Stepper Motor run mode options. More...
 
enum  stepper_event {
  STEPPER_EVENT_STEPS_COMPLETED = 0 , STEPPER_EVENT_STALL_DETECTED = 1 , STEPPER_EVENT_LEFT_END_STOP_DETECTED = 2 , STEPPER_EVENT_RIGHT_END_STOP_DETECTED = 3 ,
  STEPPER_EVENT_STOPPED = 4 , STEPPER_EVENT_FAULT_DETECTED = 5
}
 Stepper Events. More...
 

Functions

int stepper_enable (const struct device *dev)
 Enable stepper driver.
 
int stepper_disable (const struct device *dev)
 Disable stepper driver.
 
int stepper_set_micro_step_res (const struct device *dev, enum stepper_micro_step_resolution resolution)
 Set the micro-step resolution in stepper driver.
 
int stepper_get_micro_step_res (const struct device *dev, enum stepper_micro_step_resolution *resolution)
 Get the micro-step resolution in stepper driver.
 
int stepper_set_reference_position (const struct device *dev, int32_t value)
 Set the reference position of the stepper.
 
int stepper_get_actual_position (const struct device *dev, int32_t *value)
 Get the actual a.k.a reference position of the stepper.
 
int stepper_set_event_callback (const struct device *dev, stepper_event_callback_t callback, void *user_data)
 Set the callback function to be called when a stepper event occurs.
 
int stepper_set_microstep_interval (const struct device *dev, uint64_t microstep_interval_ns)
 Set the time interval between steps in nanoseconds with immediate effect.
 
int stepper_move_by (const struct device *dev, int32_t micro_steps)
 Set the micro-steps to be moved from the current position i.e.
 
int stepper_move_to (const struct device *dev, int32_t micro_steps)
 Set the absolute target position of the stepper.
 
int stepper_run (const struct device *dev, enum stepper_direction direction)
 Run the stepper with a given step interval in a given direction.
 
int stepper_stop (const struct device *dev)
 Stop the stepper.
 
int stepper_is_moving (const struct device *dev, bool *is_moving)
 Check if the stepper is currently moving.
 

Detailed Description

Interfaces for stepper motor controllers.

Since
4.0
Version
0.1.0

Macro Definition Documentation

◆ MICRO_STEP_RES_INDEX

#define MICRO_STEP_RES_INDEX (   res)    LOG2(res)

#include <include/zephyr/drivers/stepper.h>

Macro to calculate the index of the microstep resolution.

Parameters
resMicrostep resolution

◆ VALID_MICRO_STEP_RES

#define VALID_MICRO_STEP_RES (   res)

#include <include/zephyr/drivers/stepper.h>

Value:
((res) == STEPPER_MICRO_STEP_1 || (res) == STEPPER_MICRO_STEP_2 || \
(res) == STEPPER_MICRO_STEP_4 || (res) == STEPPER_MICRO_STEP_8 || \
(res) == STEPPER_MICRO_STEP_16 || (res) == STEPPER_MICRO_STEP_32 || \
@ STEPPER_MICRO_STEP_64
64 micro-steps per full step
Definition stepper.h:50
@ STEPPER_MICRO_STEP_4
4 micro-steps per full step
Definition stepper.h:42
@ STEPPER_MICRO_STEP_1
Full step resolution.
Definition stepper.h:38
@ STEPPER_MICRO_STEP_2
2 micro-steps per full step
Definition stepper.h:40
@ STEPPER_MICRO_STEP_256
256 micro-steps per full step
Definition stepper.h:54
@ STEPPER_MICRO_STEP_8
8 micro-steps per full step
Definition stepper.h:44
@ STEPPER_MICRO_STEP_16
16 micro-steps per full step
Definition stepper.h:46
@ STEPPER_MICRO_STEP_32
32 micro-steps per full step
Definition stepper.h:48
@ STEPPER_MICRO_STEP_128
128 micro-steps per full step
Definition stepper.h:52

Enumeration Type Documentation

◆ stepper_direction

#include <include/zephyr/drivers/stepper.h>

Stepper Motor direction options.

Enumerator
STEPPER_DIRECTION_NEGATIVE 

Negative direction.

STEPPER_DIRECTION_POSITIVE 

Positive direction.

◆ stepper_event

#include <include/zephyr/drivers/stepper.h>

Stepper Events.

Enumerator
STEPPER_EVENT_STEPS_COMPLETED 

Steps set using move_by or move_to have been executed.

STEPPER_EVENT_STALL_DETECTED 

Stall detected.

STEPPER_EVENT_LEFT_END_STOP_DETECTED 

Left end switch status changes to pressed.

STEPPER_EVENT_RIGHT_END_STOP_DETECTED 

Right end switch status changes to pressed.

STEPPER_EVENT_STOPPED 

Stepper has stopped.

STEPPER_EVENT_FAULT_DETECTED 

Fault with the stepper controller detected.

◆ stepper_micro_step_resolution

#include <include/zephyr/drivers/stepper.h>

Stepper Motor micro-step resolution options.

Enumerator
STEPPER_MICRO_STEP_1 

Full step resolution.

STEPPER_MICRO_STEP_2 

2 micro-steps per full step

STEPPER_MICRO_STEP_4 

4 micro-steps per full step

STEPPER_MICRO_STEP_8 

8 micro-steps per full step

STEPPER_MICRO_STEP_16 

16 micro-steps per full step

STEPPER_MICRO_STEP_32 

32 micro-steps per full step

STEPPER_MICRO_STEP_64 

64 micro-steps per full step

STEPPER_MICRO_STEP_128 

128 micro-steps per full step

STEPPER_MICRO_STEP_256 

256 micro-steps per full step

◆ stepper_run_mode

#include <include/zephyr/drivers/stepper.h>

Stepper Motor run mode options.

Enumerator
STEPPER_RUN_MODE_HOLD 

Hold Mode.

STEPPER_RUN_MODE_POSITION 

Position Mode.

STEPPER_RUN_MODE_VELOCITY 

Velocity Mode.

Function Documentation

◆ stepper_disable()

int stepper_disable ( const struct device dev)

#include <include/zephyr/drivers/stepper.h>

Disable stepper driver.

Disabling the driver shall switch off the power stage and de-energize the coils. Disabling the stepper does not implicitly stop the stepper. If the motor shall not move after re-enabling the stepper than consider calling stepper_stop() before.

Parameters
devpointer to the stepper driver instance
Return values
-ENOTSUPDisabling of driver is not supported.
-EIOError during Disabling
0Success

◆ stepper_enable()

int stepper_enable ( const struct device dev)

#include <include/zephyr/drivers/stepper.h>

Enable stepper driver.

Enabling the driver shall switch on the power stage and energize the coils.

Parameters
devpointer to the stepper driver instance
Return values
-EIOError during Enabling
0Success

◆ stepper_get_actual_position()

int stepper_get_actual_position ( const struct device dev,
int32_t value 
)

#include <include/zephyr/drivers/stepper.h>

Get the actual a.k.a reference position of the stepper.

Parameters
devpointer to the stepper driver instance
valueThe actual position to get in micro-steps
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_get_micro_step_res()

int stepper_get_micro_step_res ( const struct device dev,
enum stepper_micro_step_resolution resolution 
)

#include <include/zephyr/drivers/stepper.h>

Get the micro-step resolution in stepper driver.

Parameters
devpointer to the stepper driver instance
resolutionmicro-step resolution
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_is_moving()

int stepper_is_moving ( const struct device dev,
bool is_moving 
)

#include <include/zephyr/drivers/stepper.h>

Check if the stepper is currently moving.

Parameters
devpointer to the stepper driver instance
is_movingPointer to a boolean to store the moving status of the stepper
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_move_by()

int stepper_move_by ( const struct device dev,
int32_t  micro_steps 
)

#include <include/zephyr/drivers/stepper.h>

Set the micro-steps to be moved from the current position i.e.

relative movement

The stepper will move by the given number of micro-steps from the current position. This function is non-blocking.

Parameters
devpointer to the stepper driver instance
micro_stepstarget micro-steps to be moved from the current position
Return values
-EIOGeneral input / output error
0Success

◆ stepper_move_to()

int stepper_move_to ( const struct device dev,
int32_t  micro_steps 
)

#include <include/zephyr/drivers/stepper.h>

Set the absolute target position of the stepper.

The stepper will move to the given micro-steps position from the reference position. This function is non-blocking.

Parameters
devpointer to the stepper driver instance
micro_stepstarget position to set in micro-steps
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_run()

int stepper_run ( const struct device dev,
enum stepper_direction  direction 
)

#include <include/zephyr/drivers/stepper.h>

Run the stepper with a given step interval in a given direction.

The stepper shall be set into motion and run continuously until stalled or stopped using some other command, for instance, stepper_stop(). This function is non-blocking.

Parameters
devpointer to the stepper driver instance
directionThe direction to set
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_set_event_callback()

int stepper_set_event_callback ( const struct device dev,
stepper_event_callback_t  callback,
void *  user_data 
)

#include <include/zephyr/drivers/stepper.h>

Set the callback function to be called when a stepper event occurs.

Parameters
devpointer to the stepper driver instance
callbackCallback function to be called when a stepper event occurs passing NULL will disable the callback
user_dataUser data to be passed to the callback function
Return values
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_set_micro_step_res()

int stepper_set_micro_step_res ( const struct device dev,
enum stepper_micro_step_resolution  resolution 
)

#include <include/zephyr/drivers/stepper.h>

Set the micro-step resolution in stepper driver.

Parameters
devpointer to the stepper driver instance
resolutionmicro-step resolution
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
-EINVALIf the requested resolution is invalid
-ENOTSUPIf the requested resolution is not supported
0Success

◆ stepper_set_microstep_interval()

int stepper_set_microstep_interval ( const struct device dev,
uint64_t  microstep_interval_ns 
)

#include <include/zephyr/drivers/stepper.h>

Set the time interval between steps in nanoseconds with immediate effect.

Note
Setting step interval does not set the stepper into motion, a combination of set_microstep_interval and move is required to set the stepper into motion.
Parameters
devpointer to the stepper driver instance
microstep_interval_nstime interval between steps in nanoseconds
Return values
-EIOGeneral input / output error
-EINVALIf the requested step interval is not supported
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_set_reference_position()

int stepper_set_reference_position ( const struct device dev,
int32_t  value 
)

#include <include/zephyr/drivers/stepper.h>

Set the reference position of the stepper.

Parameters
devPointer to the stepper driver instance.
valueThe reference position to set in micro-steps.
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success

◆ stepper_stop()

int stepper_stop ( const struct device dev)

#include <include/zephyr/drivers/stepper.h>

Stop the stepper.

Cancel all active movements.

Parameters
devpointer to the stepper driver instance
Return values
-EIOGeneral input / output error
-ENOSYSIf not implemented by device driver
0Success