Zephyr API Documentation 4.3.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
74
80typedef int (*stepper_ctrl_set_reference_position_t)(const struct device *dev, const int32_t value);
81
87typedef int (*stepper_ctrl_get_actual_position_t)(const struct device *dev, int32_t *value);
88
92typedef void (*stepper_ctrl_event_callback_t)(const struct device *dev,
93 const enum stepper_ctrl_event event, void *user_data);
94
100typedef int (*stepper_ctrl_set_event_cb_t)(const struct device *dev,
101 stepper_ctrl_event_callback_t callback, void *user_data);
102
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);
116
122typedef int (*stepper_ctrl_move_to_t)(const struct device *dev, const int32_t micro_steps);
123
129typedef int (*stepper_ctrl_run_t)(const struct device *dev,
130 const enum stepper_ctrl_direction direction);
131
137typedef int (*stepper_ctrl_stop_t)(const struct device *dev);
138
144typedef int (*stepper_ctrl_is_moving_t)(const struct device *dev, bool *is_moving);
145
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;
159};
160
164
175__syscall int stepper_ctrl_set_reference_position(const struct device *dev, const int32_t value);
176
177static inline int z_impl_stepper_ctrl_set_reference_position(const struct device *dev,
178 const int32_t value)
179{
180 __ASSERT_NO_MSG(dev != NULL);
181 const struct stepper_ctrl_driver_api *api = dev->api;
182
183 if (api->set_reference_position == NULL) {
184 return -ENOSYS;
185 }
186 return api->set_reference_position(dev, value);
187}
188
202
203__syscall int stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value);
204
205static inline int z_impl_stepper_ctrl_get_actual_position(const struct device *dev, int32_t *value)
206{
207 __ASSERT_NO_MSG(dev != NULL);
208 __ASSERT_NO_MSG(value != NULL);
209 const struct stepper_ctrl_driver_api *api = dev->api;
210
211 if (api->get_actual_position == NULL) {
212 return -ENOSYS;
213 }
214 return api->get_actual_position(dev, value);
215}
216
228
229__syscall int stepper_ctrl_set_event_cb(const struct device *dev,
230 stepper_ctrl_event_callback_t callback, void *user_data);
231
232static inline int z_impl_stepper_ctrl_set_event_cb(const struct device *dev,
233 stepper_ctrl_event_callback_t callback,
234 void *user_data)
235{
236 __ASSERT_NO_MSG(dev != NULL);
237 const struct stepper_ctrl_driver_api *api = dev->api;
238
239 if (api->set_event_cb == NULL) {
240 return -ENOSYS;
241 }
242 return api->set_event_cb(dev, callback, user_data);
243}
244
259__syscall int stepper_ctrl_set_microstep_interval(const struct device *dev,
260 const uint64_t microstep_interval_ns);
261
262static inline int z_impl_stepper_ctrl_set_microstep_interval(const struct device *dev,
263 const uint64_t microstep_interval_ns)
264{
265 __ASSERT_NO_MSG(dev != NULL);
266 const struct stepper_ctrl_driver_api *api = dev->api;
267
268 if (api->set_microstep_interval == NULL) {
269 return -ENOSYS;
270 }
271 return api->set_microstep_interval(dev, microstep_interval_ns);
272}
273
287__syscall int stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps);
288
289static inline int z_impl_stepper_ctrl_move_by(const struct device *dev, const int32_t micro_steps)
290{
291 __ASSERT_NO_MSG(dev != NULL);
292 const struct stepper_ctrl_driver_api *api = dev->api;
293
294 return api->move_by(dev, micro_steps);
295}
296
310__syscall int stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps);
311
312static inline int z_impl_stepper_ctrl_move_to(const struct device *dev, const int32_t micro_steps)
313{
314 __ASSERT_NO_MSG(dev != NULL);
315 const struct stepper_ctrl_driver_api *api = dev->api;
316
317 return api->move_to(dev, micro_steps);
318}
319
335__syscall int stepper_ctrl_run(const struct device *dev,
336 const enum stepper_ctrl_direction direction);
337
338static inline int z_impl_stepper_ctrl_run(const struct device *dev,
339 const enum stepper_ctrl_direction direction)
340{
341 __ASSERT_NO_MSG(dev != NULL);
342 const struct stepper_ctrl_driver_api *api = dev->api;
343
344 if (api->run == NULL) {
345 return -ENOSYS;
346 }
347 return api->run(dev, direction);
348}
349
360__syscall int stepper_ctrl_stop(const struct device *dev);
361
362static inline int z_impl_stepper_ctrl_stop(const struct device *dev)
363{
364 __ASSERT_NO_MSG(dev != NULL);
365 const struct stepper_ctrl_driver_api *api = dev->api;
366
367 if (api->stop == NULL) {
368 return -ENOSYS;
369 }
370 return api->stop(dev);
371}
372
383__syscall int stepper_ctrl_is_moving(const struct device *dev, bool *is_moving);
384
385static inline int z_impl_stepper_ctrl_is_moving(const struct device *dev, bool *is_moving)
386{
387 __ASSERT_NO_MSG(dev != NULL);
388 __ASSERT_NO_MSG(is_moving != NULL);
389 const struct stepper_ctrl_driver_api *api = dev->api;
390
391 if (api->is_moving == NULL) {
392 return -ENOSYS;
393 }
394 return api->is_moving(dev, is_moving);
395}
396
400
401#ifdef __cplusplus
402}
403#endif
404
405#include <zephyr/syscalls/stepper_ctrl.h>
406
407#endif /* ZEPHYR_INCLUDE_DRIVERS_STEPPER_CTRL_H_ */
System error numbers.
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
Public kernel APIs.
__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