Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
stepper_ctrl.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2025 Jilay Sandeep Pandya
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_
13#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_
14
23
24#include <zephyr/kernel.h>
25#include <zephyr/device.h>
26#include <errno.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
41
53
67
79
83typedef void (*stepper_ctrl_event_callback_t)(const struct device *dev,
84 const enum stepper_ctrl_event event, void *user_data);
85
90
96typedef int (*stepper_ctrl_set_reference_position_t)(const struct device *dev, const int32_t value);
97
103typedef int (*stepper_ctrl_get_actual_position_t)(const struct device *dev, int32_t *value);
104
110typedef int (*stepper_ctrl_set_event_cb_t)(const struct device *dev,
111 stepper_ctrl_event_callback_t callback, void *user_data);
112
118typedef int (*stepper_ctrl_set_microstep_interval_t)(const struct device *dev,
119 const uint64_t microstep_interval_ns);
120
126typedef int (*stepper_ctrl_configure_ramp_t)(const struct device *dev,
127 const struct stepper_ctrl_ramp *ramp);
128
134typedef int (*stepper_ctrl_move_by_t)(const struct device *dev, const int32_t micro_steps);
135
141typedef int (*stepper_ctrl_move_to_t)(const struct device *dev, const int32_t micro_steps);
142
148typedef int (*stepper_ctrl_run_t)(const struct device *dev,
149 const enum stepper_ctrl_direction direction);
150
156typedef int (*stepper_ctrl_stop_t)(const struct device *dev);
157
163typedef int (*stepper_ctrl_is_moving_t)(const struct device *dev, bool *is_moving);
164
210
214
225__syscall int stepper_ctrl_set_reference_position(const struct device *dev, const int32_t value);
226
227static inline int z_impl_stepper_ctrl_set_reference_position(const struct device *dev,
228 const int32_t value)
229{
230 if (DEVICE_API_GET(stepper_ctrl, dev)->set_reference_position == NULL) {
231 return -ENOSYS;
232 }
233 return DEVICE_API_GET(stepper_ctrl, dev)->set_reference_position(dev, value);
234}
235
249
250__syscall int stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value);
251
252static inline int z_impl_stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value)
253{
254 __ASSERT_NO_MSG(value != NULL);
255
256 if (DEVICE_API_GET(stepper_ctrl, dev)->get_actual_position == NULL) {
257 return -ENOSYS;
258 }
259 return DEVICE_API_GET(stepper_ctrl, dev)->get_actual_position(dev, value);
260}
261
273
274__syscall int stepper_ctrl_set_event_cb(const struct device *dev,
275 stepper_ctrl_event_callback_t callback, void *user_data);
276
277static inline int z_impl_stepper_ctrl_set_event_cb(const struct device *dev,
279 void *user_data)
280{
281 if (DEVICE_API_GET(stepper_ctrl, dev)->set_event_cb == NULL) {
282 return -ENOSYS;
283 }
284 return DEVICE_API_GET(stepper_ctrl, dev)->set_event_cb(dev, callback, user_data);
285}
286
301__syscall int stepper_ctrl_set_microstep_interval(const struct device *dev,
302 const uint64_t microstep_interval_ns);
303
304static inline int z_impl_stepper_ctrl_set_microstep_interval(const struct device *dev,
305 const uint64_t microstep_interval_ns)
306{
307 if (DEVICE_API_GET(stepper_ctrl, dev)->set_microstep_interval == NULL) {
308 return -ENOSYS;
309 }
310 return DEVICE_API_GET(stepper_ctrl, dev)->set_microstep_interval(dev,
311 microstep_interval_ns);
312}
313
324__syscall int stepper_ctrl_configure_ramp(const struct device *dev,
325 const struct stepper_ctrl_ramp *ramp);
326
327static inline int z_impl_stepper_ctrl_configure_ramp(const struct device *dev,
328 const struct stepper_ctrl_ramp *ramp)
329{
330 __ASSERT_NO_MSG(ramp != NULL);
331
332 if (DEVICE_API_GET(stepper_ctrl, dev)->configure_ramp == NULL) {
333 return -ENOSYS;
334 }
335 return DEVICE_API_GET(stepper_ctrl, dev)->configure_ramp(dev, ramp);
336}
350__syscall int stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps);
351
352static inline int z_impl_stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps)
353{
354 return DEVICE_API_GET(stepper_ctrl, dev)->move_by(dev, micro_steps);
355}
356
370__syscall int stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps);
371
372static inline int z_impl_stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps)
373{
374 return DEVICE_API_GET(stepper_ctrl, dev)->move_to(dev, micro_steps);
375}
376
392__syscall int stepper_ctrl_run(const struct device *dev,
393 const enum stepper_ctrl_direction direction);
394
395static inline int z_impl_stepper_ctrl_run(const struct device *dev,
396 const enum stepper_ctrl_direction direction)
397{
398 if (DEVICE_API_GET(stepper_ctrl, dev)->run == NULL) {
399 return -ENOSYS;
400 }
401 return DEVICE_API_GET(stepper_ctrl, dev)->run(dev, direction);
402}
403
414__syscall int stepper_ctrl_stop(const struct device *dev);
415
416static inline int z_impl_stepper_ctrl_stop(const struct device *dev)
417{
418 if (DEVICE_API_GET(stepper_ctrl, dev)->stop == NULL) {
419 return -ENOSYS;
420 }
421 return DEVICE_API_GET(stepper_ctrl, dev)->stop(dev);
422}
423
434__syscall int stepper_ctrl_is_moving(const struct device *dev, bool *is_moving);
435
436static inline int z_impl_stepper_ctrl_is_moving(const struct device *dev, bool *is_moving)
437{
438 __ASSERT_NO_MSG(is_moving != NULL);
439 if (DEVICE_API_GET(stepper_ctrl, dev)->is_moving == NULL) {
440 return -ENOSYS;
441 }
442 return DEVICE_API_GET(stepper_ctrl, dev)->is_moving(dev, is_moving);
443}
444
448
449#ifdef __cplusplus
450}
451#endif
452
453#include <zephyr/syscalls/stepper_ctrl.h>
454
455#endif /* ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
int(* stepper_ctrl_get_actual_position_t)(const struct device *dev, int32_t *value)
Get the actual a.k.a reference position of the stepper motion controller.
Definition stepper_ctrl.h:103
int(* stepper_ctrl_set_reference_position_t)(const struct device *dev, const int32_t value)
Set the reference position of the stepper motion controller.
Definition stepper_ctrl.h:96
int(* stepper_ctrl_set_event_cb_t)(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.
Definition stepper_ctrl.h:110
int(* stepper_ctrl_run_t)(const struct device *dev, const enum stepper_ctrl_direction direction)
Run the stepper with a given step interval in a given direction.
Definition stepper_ctrl.h:148
int(* stepper_ctrl_configure_ramp_t)(const struct device *dev, const struct stepper_ctrl_ramp *ramp)
Configure the ramp parameters for the stepper motion controller.
Definition stepper_ctrl.h:126
int(* stepper_ctrl_move_to_t)(const struct device *dev, const int32_t micro_steps)
Move the stepper to an absolute position in micro-steps.
Definition stepper_ctrl.h:141
int(* stepper_ctrl_move_by_t)(const struct device *dev, const int32_t micro_steps)
Move the stepper relatively by a given number of micro-steps.
Definition stepper_ctrl.h:134
int(* stepper_ctrl_set_microstep_interval_t)(const struct device *dev, const uint64_t microstep_interval_ns)
Set the time interval between steps in nanoseconds.
Definition stepper_ctrl.h:118
int(* stepper_ctrl_is_moving_t)(const struct device *dev, bool *is_moving)
Is the target position fo the stepper reached.
Definition stepper_ctrl.h:163
int(* stepper_ctrl_stop_t)(const struct device *dev)
Stop the stepper.
Definition stepper_ctrl.h:156
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
void(* stepper_ctrl_event_callback_t)(const struct device *dev, const enum stepper_ctrl_event event, void *user_data)
Callback function for stepper motion controller events.
Definition stepper_ctrl.h:83
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_configure_ramp(const struct device *dev, const struct stepper_ctrl_ramp *ramp)
Configure the ramp for the stepper motion controller.
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
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__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
<span class="mlabel">Driver Operations</span> Stepper Motion Controller driver operations
Definition stepper_ctrl.h:168
stepper_ctrl_stop_t stop
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:204
stepper_ctrl_move_by_t move_by
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper_ctrl.h:192
stepper_ctrl_set_reference_position_t set_reference_position
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:172
stepper_ctrl_is_moving_t is_moving
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:208
stepper_ctrl_set_event_cb_t set_event_cb
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:180
stepper_ctrl_set_microstep_interval_t set_microstep_interval
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:184
stepper_ctrl_run_t run
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:200
stepper_ctrl_move_to_t move_to
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper_ctrl.h:196
stepper_ctrl_configure_ramp_t configure_ramp
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:188
stepper_ctrl_get_actual_position_t get_actual_position
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition stepper_ctrl.h:176
Steper Motion Controller Ramp Parameters.
Definition stepper_ctrl.h:71
uint32_t deceleration_max
Deceleration in micro_steps/s²
Definition stepper_ctrl.h:77
uint32_t acceleration_max
Acceleration in micro_steps/s²
Definition stepper_ctrl.h:73
uint32_t speed_max
Maximum speed in micro_steps/s.
Definition stepper_ctrl.h:75