12#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_
13#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_
80typedef int (*stepper_ctrl_set_reference_position_t)(
const struct device *dev,
const int32_t value);
87typedef int (*stepper_ctrl_get_actual_position_t)(
const struct device *dev,
int32_t *value);
92typedef void (*stepper_ctrl_event_callback_t)(
const struct device *dev,
100typedef int (*stepper_ctrl_set_event_cb_t)(
const struct device *dev,
101 stepper_ctrl_event_callback_t callback,
void *user_data);
108typedef int (*stepper_ctrl_set_microstep_interval_t)(
const struct device *dev,
109 const uint64_t microstep_interval_ns);
115typedef int (*stepper_ctrl_move_by_t)(
const struct device *dev,
const int32_t micro_steps);
122typedef int (*stepper_ctrl_move_to_t)(
const struct device *dev,
const int32_t micro_steps);
129typedef int (*stepper_ctrl_run_t)(
const struct device *dev,
137typedef int (*stepper_ctrl_stop_t)(
const struct device *dev);
144typedef int (*stepper_ctrl_is_moving_t)(
const struct device *dev,
bool *is_moving);
149__subsystem
struct stepper_ctrl_driver_api {
150 stepper_ctrl_set_reference_position_t set_reference_position;
151 stepper_ctrl_get_actual_position_t get_actual_position;
152 stepper_ctrl_set_event_cb_t set_event_cb;
153 stepper_ctrl_set_microstep_interval_t set_microstep_interval;
154 stepper_ctrl_move_by_t move_by;
155 stepper_ctrl_move_to_t move_to;
156 stepper_ctrl_run_t run;
157 stepper_ctrl_stop_t stop;
158 stepper_ctrl_is_moving_t is_moving;
177static inline int z_impl_stepper_ctrl_set_reference_position(
const struct device *dev,
180 __ASSERT_NO_MSG(dev !=
NULL);
181 const struct stepper_ctrl_driver_api *api = dev->
api;
183 if (api->set_reference_position ==
NULL) {
186 return api->set_reference_position(dev, value);
205static inline int z_impl_stepper_ctrl_get_actual_position(
const struct device *dev,
int32_t *value)
207 __ASSERT_NO_MSG(dev !=
NULL);
208 __ASSERT_NO_MSG(value !=
NULL);
209 const struct stepper_ctrl_driver_api *api = dev->
api;
211 if (api->get_actual_position ==
NULL) {
214 return api->get_actual_position(dev, value);
230 stepper_ctrl_event_callback_t callback,
void *user_data);
232static inline int z_impl_stepper_ctrl_set_event_cb(
const struct device *dev,
233 stepper_ctrl_event_callback_t callback,
236 __ASSERT_NO_MSG(dev !=
NULL);
237 const struct stepper_ctrl_driver_api *api = dev->
api;
239 if (api->set_event_cb ==
NULL) {
242 return api->set_event_cb(dev, callback, user_data);
260 const uint64_t microstep_interval_ns);
262static inline int z_impl_stepper_ctrl_set_microstep_interval(
const struct device *dev,
263 const uint64_t microstep_interval_ns)
265 __ASSERT_NO_MSG(dev !=
NULL);
266 const struct stepper_ctrl_driver_api *api = dev->
api;
268 if (api->set_microstep_interval ==
NULL) {
271 return api->set_microstep_interval(dev, microstep_interval_ns);
289static inline int z_impl_stepper_ctrl_move_by(
const struct device *dev,
const int32_t micro_steps)
291 __ASSERT_NO_MSG(dev !=
NULL);
292 const struct stepper_ctrl_driver_api *api = dev->
api;
294 return api->move_by(dev, micro_steps);
312static inline int z_impl_stepper_ctrl_move_to(
const struct device *dev,
const int32_t micro_steps)
314 __ASSERT_NO_MSG(dev !=
NULL);
315 const struct stepper_ctrl_driver_api *api = dev->
api;
317 return api->move_to(dev, micro_steps);
338static inline int z_impl_stepper_ctrl_run(
const struct device *dev,
341 __ASSERT_NO_MSG(dev !=
NULL);
342 const struct stepper_ctrl_driver_api *api = dev->
api;
344 if (api->run ==
NULL) {
347 return api->run(dev, direction);
362static inline int z_impl_stepper_ctrl_stop(
const struct device *dev)
364 __ASSERT_NO_MSG(dev !=
NULL);
365 const struct stepper_ctrl_driver_api *api = dev->
api;
367 if (api->stop ==
NULL) {
370 return api->stop(dev);
385static inline int z_impl_stepper_ctrl_is_moving(
const struct device *dev,
bool *is_moving)
387 __ASSERT_NO_MSG(dev !=
NULL);
388 __ASSERT_NO_MSG(is_moving !=
NULL);
389 const struct stepper_ctrl_driver_api *api = dev->
api;
391 if (api->is_moving ==
NULL) {
394 return api->is_moving(dev, is_moving);
405#include <zephyr/syscalls/stepper_ctrl.h>
stepper_ctrl_direction
Stepper Motion Controller direction options.
Definition stepper_ctrl.h:35
int stepper_ctrl_set_microstep_interval(const struct device *dev, const uint64_t microstep_interval_ns)
Set the time interval between steps in nanoseconds with immediate effect.
int stepper_ctrl_run(const struct device *dev, const enum stepper_ctrl_direction direction)
Run the stepper with a given step interval in a given direction.
stepper_ctrl_event
Stepper Motion Controller Events.
Definition stepper_ctrl.h:57
int stepper_ctrl_stop(const struct device *dev)
Stop the stepper.
stepper_ctrl_run_mode
Stepper Motion Controller run mode options.
Definition stepper_ctrl.h:45
int stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps)
Set the micro-steps to be moved from the current position i.e.
int stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps)
Set the absolute target position of the stepper.
int stepper_ctrl_set_event_cb(const struct device *dev, stepper_ctrl_event_callback_t callback, void *user_data)
Set the callback function to be called when a stepper motion controller event occurs.
int stepper_ctrl_set_reference_position(const struct device *dev, const int32_t value)
Set the reference position.
int stepper_ctrl_is_moving(const struct device *dev, bool *is_moving)
Check if the stepper is currently moving.
int stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value)
Get the actual step count.
@ STEPPER_CTRL_DIRECTION_POSITIVE
Positive direction.
Definition stepper_ctrl.h:39
@ STEPPER_CTRL_DIRECTION_NEGATIVE
Negative direction.
Definition stepper_ctrl.h:37
@ STEPPER_CTRL_EVENT_RIGHT_END_STOP_DETECTED
Right end switch status changes to pressed.
Definition stepper_ctrl.h:63
@ STEPPER_CTRL_EVENT_LEFT_END_STOP_DETECTED
Left end switch status changes to pressed.
Definition stepper_ctrl.h:61
@ STEPPER_CTRL_EVENT_STEPS_COMPLETED
Steps set using move_by or move_to have been executed.
Definition stepper_ctrl.h:59
@ STEPPER_CTRL_EVENT_STOPPED
Stepper has stopped.
Definition stepper_ctrl.h:65
@ STEPPER_CTRL_RUN_MODE_HOLD
Hold Mode.
Definition stepper_ctrl.h:47
@ STEPPER_CTRL_RUN_MODE_POSITION
Position Mode.
Definition stepper_ctrl.h:49
@ STEPPER_CTRL_RUN_MODE_VELOCITY
Velocity Mode.
Definition stepper_ctrl.h:51
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519