Zephyr API 3.6.99
Loading...
Searching...
No Matches
stepper.h
Go to the documentation of this file.
1
8/*
9 * SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
15
23#include <zephyr/kernel.h>
24#include <zephyr/device.h>
25#include <errno.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
54
64
76
84
97typedef int (*stepper_enable_t)(const struct device *dev, const bool enable);
98
104typedef int (*stepper_move_t)(const struct device *dev, const int32_t micro_steps,
105 struct k_poll_signal *async);
106
112typedef int (*stepper_set_max_velocity_t)(const struct device *dev,
113 const uint32_t micro_steps_per_second);
114
120typedef int (*stepper_set_micro_step_res_t)(const struct device *dev,
121 const enum micro_step_resolution resolution);
122
128typedef int (*stepper_get_micro_step_res_t)(const struct device *dev,
129 enum micro_step_resolution *resolution);
135typedef int (*stepper_set_actual_position_t)(const struct device *dev, const int32_t value);
136
142typedef int (*stepper_get_actual_position_t)(const struct device *dev, int32_t *value);
143
149typedef int (*stepper_set_target_position_t)(const struct device *dev, const int32_t value,
150 struct k_poll_signal *async);
151
157typedef int (*stepper_is_moving_t)(const struct device *dev, bool *is_moving);
158
164typedef int (*stepper_enable_constant_velocity_mode_t)(const struct device *dev,
165 const enum stepper_direction direction,
166 const uint32_t value);
167
171__subsystem struct stepper_driver_api {
172 stepper_enable_t enable;
173 stepper_move_t move;
174 stepper_set_max_velocity_t set_max_velocity;
175 stepper_set_micro_step_res_t set_micro_step_res;
176 stepper_get_micro_step_res_t get_micro_step_res;
177 stepper_set_actual_position_t set_actual_position;
178 stepper_get_actual_position_t get_actual_position;
179 stepper_set_target_position_t set_target_position;
180 stepper_is_moving_t is_moving;
181 stepper_enable_constant_velocity_mode_t enable_constant_velocity_mode;
182};
183
197__syscall int stepper_enable(const struct device *dev, const bool enable);
198
199static inline int z_impl_stepper_enable(const struct device *dev, const bool enable)
200{
201 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
202
203 return api->enable(dev, enable);
204}
205
219__syscall int stepper_move(const struct device *dev, int32_t micro_steps,
220 struct k_poll_signal *async);
221
222static inline int z_impl_stepper_move(const struct device *dev, const int32_t micro_steps,
223 struct k_poll_signal *async)
224{
225 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
226
227 return api->move(dev, micro_steps, async);
228}
229
246__syscall int stepper_set_max_velocity(const struct device *dev, uint32_t micro_steps_per_second);
247
248static inline int z_impl_stepper_set_max_velocity(const struct device *dev,
249 const uint32_t micro_steps_per_second)
250{
251 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
252
253 return api->set_max_velocity(dev, micro_steps_per_second);
254}
255
267__syscall int stepper_set_micro_step_res(const struct device *dev,
268 enum micro_step_resolution resolution);
269
270static inline int z_impl_stepper_set_micro_step_res(const struct device *dev,
271 enum micro_step_resolution resolution)
272{
273 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
274
275 if (api->set_micro_step_res == NULL) {
276 return -ENOSYS;
277 }
278 return api->set_micro_step_res(dev, resolution);
279}
280
291__syscall int stepper_get_micro_step_res(const struct device *dev,
292 enum micro_step_resolution *resolution);
293
294static inline int z_impl_stepper_get_micro_step_res(const struct device *dev,
295 enum micro_step_resolution *resolution)
296{
297 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
298
299 if (api->get_micro_step_res == NULL) {
300 return -ENOSYS;
301 }
302 return api->get_micro_step_res(dev, resolution);
303}
304
315__syscall int stepper_set_actual_position(const struct device *dev, int32_t value);
316
317static inline int z_impl_stepper_set_actual_position(const struct device *dev, const int32_t value)
318{
319 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
320
321 if (api->set_actual_position == NULL) {
322 return -ENOSYS;
323 }
324 return api->set_actual_position(dev, value);
325}
326
337__syscall int stepper_get_actual_position(const struct device *dev, int32_t *value);
338
339static inline int z_impl_stepper_get_actual_position(const struct device *dev, int32_t *value)
340{
341 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
342
343 if (api->get_actual_position == NULL) {
344 return -ENOSYS;
345 }
346 return api->get_actual_position(dev, value);
347}
348
363__syscall int stepper_set_target_position(const struct device *dev, int32_t value,
364 struct k_poll_signal *async);
365
366static inline int z_impl_stepper_set_target_position(const struct device *dev, const int32_t value,
367 struct k_poll_signal *async)
368{
369 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
370
371 if (api->set_target_position == NULL) {
372 return -ENOSYS;
373 }
374 return api->set_target_position(dev, value, async);
375}
376
387__syscall int stepper_is_moving(const struct device *dev, bool *is_moving);
388
389static inline int z_impl_stepper_is_moving(const struct device *dev, bool *is_moving)
390{
391 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
392
393 if (api->is_moving == NULL) {
394 return -ENOSYS;
395 }
396 return api->is_moving(dev, is_moving);
397}
398
417__syscall int stepper_enable_constant_velocity_mode(const struct device *dev,
418 enum stepper_direction direction,
419 uint32_t value);
420
421static inline int z_impl_stepper_enable_constant_velocity_mode(
422 const struct device *dev, const enum stepper_direction direction, const uint32_t value)
423{
424 const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
425
426 if (api->enable_constant_velocity_mode == NULL) {
427 return -ENOSYS;
428 }
429 return api->enable_constant_velocity_mode(dev, direction, value);
430}
431
436#ifdef __cplusplus
437}
438#endif
439
440#include <zephyr/syscalls/stepper.h>
441
442#endif /* ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_ */
System error numbers.
stepper_direction
Stepper Motor direction options.
Definition stepper.h:58
int stepper_move(const struct device *dev, int32_t micro_steps, struct k_poll_signal *async)
Set the micro_steps to be moved from the current position i.e.
int stepper_enable(const struct device *dev, const bool enable)
Enable or Disable Motor Controller.
int stepper_enable_constant_velocity_mode(const struct device *dev, enum stepper_direction direction, uint32_t value)
Enable constant velocity mode for the stepper with a given velocity.
int stepper_get_micro_step_res(const struct device *dev, enum micro_step_resolution *resolution)
Get the microstep resolution in stepper motor controller.
stepper_run_mode
Stepper Motor run mode options.
Definition stepper.h:68
int stepper_set_micro_step_res(const struct device *dev, enum micro_step_resolution resolution)
Set the microstep resolution in stepper motor controller.
int stepper_get_actual_position(const struct device *dev, int32_t *value)
Get the actual a.k.a reference position of the stepper.
stepper_signal_result
Stepper Motor signal results.
Definition stepper.h:80
int stepper_is_moving(const struct device *dev, bool *is_moving)
Check if the stepper motor is currently moving.
micro_step_resolution
Stepper Motor micro step resolution options.
Definition stepper.h:34
int stepper_set_max_velocity(const struct device *dev, uint32_t micro_steps_per_second)
Set the target velocity to be reached by the motor.
int stepper_set_target_position(const struct device *dev, int32_t value, struct k_poll_signal *async)
Set the absolute target position of the stepper.
int stepper_set_actual_position(const struct device *dev, int32_t value)
Set the actual a.k.a reference position of the stepper.
@ STEPPER_DIRECTION_POSITIVE
Positive direction.
Definition stepper.h:60
@ STEPPER_DIRECTION_NEGATIVE
Negative direction.
Definition stepper.h:62
@ STEPPER_POSITION_MODE
Position Mode.
Definition stepper.h:72
@ STEPPER_VELOCITY_MODE
Velocity Mode.
Definition stepper.h:74
@ STEPPER_HOLD_MODE
Hold Mode.
Definition stepper.h:70
@ STEPPER_SIGNAL_STEPS_COMPLETED
Steps set using move or set_target_position have been executed.
Definition stepper.h:82
@ STEPPER_MICRO_STEP_64
64 micro steps per full step
Definition stepper.h:48
@ STEPPER_MICRO_STEP_4
4 micro steps per full step
Definition stepper.h:40
@ STEPPER_MICRO_STEP_2
2 micro steps per full step
Definition stepper.h:38
@ STEPPER_MICRO_STEP_256
256 micro steps per full step
Definition stepper.h:52
@ STEPPER_MICRO_STEP_8
8 micro steps per full step
Definition stepper.h:42
@ STEPPER_MICRO_STEP_16
16 micro steps per full step
Definition stepper.h:44
@ STEPPER_FULL_STEP
Full step resolution.
Definition stepper.h:36
@ STEPPER_MICRO_STEP_32
32 micro steps per full step
Definition stepper.h:46
@ STEPPER_MICRO_STEP_128
128 micro steps per full step
Definition stepper.h:50
#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
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Definition kernel.h:5768