Zephyr API Documentation 4.4.0-rc1
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 __ASSERT_NO_MSG(dev != NULL);
231 if (DEVICE_API_GET(stepper_ctrl, dev)->set_reference_position == NULL) {
232 return -ENOSYS;
233 }
234 return DEVICE_API_GET(stepper_ctrl, dev)->set_reference_position(dev, value);
235}
236
250
251__syscall int stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value);
252
253static inline int z_impl_stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value)
254{
255 __ASSERT_NO_MSG(dev != NULL);
256 __ASSERT_NO_MSG(value != NULL);
257 if (DEVICE_API_GET(stepper_ctrl, dev)->get_actual_position == NULL) {
258 return -ENOSYS;
259 }
260 return DEVICE_API_GET(stepper_ctrl, dev)->get_actual_position(dev, value);
261}
262
274
275__syscall int stepper_ctrl_set_event_cb(const struct device *dev,
276 stepper_ctrl_event_callback_t callback, void *user_data);
277
278static inline int z_impl_stepper_ctrl_set_event_cb(const struct device *dev,
280 void *user_data)
281{
282 __ASSERT_NO_MSG(dev != NULL);
283 if (DEVICE_API_GET(stepper_ctrl, dev)->set_event_cb == NULL) {
284 return -ENOSYS;
285 }
286 return DEVICE_API_GET(stepper_ctrl, dev)->set_event_cb(dev, callback, user_data);
287}
288
303__syscall int stepper_ctrl_set_microstep_interval(const struct device *dev,
304 const uint64_t microstep_interval_ns);
305
306static inline int z_impl_stepper_ctrl_set_microstep_interval(const struct device *dev,
307 const uint64_t microstep_interval_ns)
308{
309 __ASSERT_NO_MSG(dev != NULL);
310 if (DEVICE_API_GET(stepper_ctrl, dev)->set_microstep_interval == NULL) {
311 return -ENOSYS;
312 }
313 return DEVICE_API_GET(stepper_ctrl, dev)->set_microstep_interval(dev,
314 microstep_interval_ns);
315}
316
327__syscall int stepper_ctrl_configure_ramp(const struct device *dev,
328 const struct stepper_ctrl_ramp *ramp);
329
330static inline int z_impl_stepper_ctrl_configure_ramp(const struct device *dev,
331 const struct stepper_ctrl_ramp *ramp)
332{
333 __ASSERT_NO_MSG(dev != NULL);
334 __ASSERT_NO_MSG(ramp != NULL);
335
336 if (DEVICE_API_GET(stepper_ctrl, dev)->configure_ramp == NULL) {
337 return -ENOSYS;
338 }
339 return DEVICE_API_GET(stepper_ctrl, dev)->configure_ramp(dev, ramp);
340}
354__syscall int stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps);
355
356static inline int z_impl_stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps)
357{
358 __ASSERT_NO_MSG(dev != NULL);
359 return DEVICE_API_GET(stepper_ctrl, dev)->move_by(dev, micro_steps);
360}
361
375__syscall int stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps);
376
377static inline int z_impl_stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps)
378{
379 __ASSERT_NO_MSG(dev != NULL);
380 return DEVICE_API_GET(stepper_ctrl, dev)->move_to(dev, micro_steps);
381}
382
398__syscall int stepper_ctrl_run(const struct device *dev,
399 const enum stepper_ctrl_direction direction);
400
401static inline int z_impl_stepper_ctrl_run(const struct device *dev,
402 const enum stepper_ctrl_direction direction)
403{
404 __ASSERT_NO_MSG(dev != NULL);
405 if (DEVICE_API_GET(stepper_ctrl, dev)->run == NULL) {
406 return -ENOSYS;
407 }
408 return DEVICE_API_GET(stepper_ctrl, dev)->run(dev, direction);
409}
410
421__syscall int stepper_ctrl_stop(const struct device *dev);
422
423static inline int z_impl_stepper_ctrl_stop(const struct device *dev)
424{
425 __ASSERT_NO_MSG(dev != NULL);
426 if (DEVICE_API_GET(stepper_ctrl, dev)->stop == NULL) {
427 return -ENOSYS;
428 }
429 return DEVICE_API_GET(stepper_ctrl, dev)->stop(dev);
430}
431
442__syscall int stepper_ctrl_is_moving(const struct device *dev, bool *is_moving);
443
444static inline int z_impl_stepper_ctrl_is_moving(const struct device *dev, bool *is_moving)
445{
446 __ASSERT_NO_MSG(dev != NULL);
447 __ASSERT_NO_MSG(is_moving != NULL);
448 if (DEVICE_API_GET(stepper_ctrl, dev)->is_moving == NULL) {
449 return -ENOSYS;
450 }
451 return DEVICE_API_GET(stepper_ctrl, dev)->is_moving(dev, is_moving);
452}
453
457
458#ifdef __cplusplus
459}
460#endif
461
462#include <zephyr/syscalls/stepper_ctrl.h>
463
464#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:1375
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
#define NULL
Definition iar_missing_defs.h:20
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