Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
stepper.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
3 * SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/device.h>
18#include <errno.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
41
65
70#define MICRO_STEP_RES_INDEX(res) LOG2(res)
71
78#define VALID_MICRO_STEP_RES(res) \
79 ((res) == STEPPER_MICRO_STEP_1 || (res) == STEPPER_MICRO_STEP_2 || \
80 (res) == STEPPER_MICRO_STEP_4 || (res) == STEPPER_MICRO_STEP_8 || \
81 (res) == STEPPER_MICRO_STEP_16 || (res) == STEPPER_MICRO_STEP_32 || \
82 (res) == STEPPER_MICRO_STEP_64 || (res) == STEPPER_MICRO_STEP_128 || \
83 (res) == STEPPER_MICRO_STEP_256)
84
94
98typedef void (*stepper_event_cb_t)(const struct device *dev, const enum stepper_event event,
99 void *user_data);
100
105
110typedef int (*stepper_enable_t)(const struct device *dev);
111
116typedef int (*stepper_disable_t)(const struct device *dev);
117
122typedef int (*stepper_set_micro_step_res_t)(const struct device *dev,
123 const enum stepper_micro_step_resolution resolution);
124
129typedef int (*stepper_get_micro_step_res_t)(const struct device *dev,
130 enum stepper_micro_step_resolution *resolution);
131
136typedef int (*stepper_set_event_cb_t)(const struct device *dev, stepper_event_cb_t callback,
137 void *user_data);
138
164
168
179__syscall int stepper_enable(const struct device *dev);
180
181static inline int z_impl_stepper_enable(const struct device *dev)
182{
183 return DEVICE_API_GET(stepper, dev)->enable(dev);
184}
185
197__syscall int stepper_disable(const struct device *dev);
198
199static inline int z_impl_stepper_disable(const struct device *dev)
200{
201 return DEVICE_API_GET(stepper, dev)->disable(dev);
202}
203
215__syscall int stepper_set_micro_step_res(const struct device *dev,
217
218static inline int z_impl_stepper_set_micro_step_res(const struct device *dev,
220{
221 if (!VALID_MICRO_STEP_RES(res)) {
222 return -EINVAL;
223 }
224 return DEVICE_API_GET(stepper, dev)->set_micro_step_res(dev, res);
225}
226
236__syscall int stepper_get_micro_step_res(const struct device *dev,
238
239static inline int z_impl_stepper_get_micro_step_res(const struct device *dev,
241{
242 __ASSERT_NO_MSG(res != NULL);
243 return DEVICE_API_GET(stepper, dev)->get_micro_step_res(dev, res);
244}
245
257__syscall int stepper_set_event_cb(const struct device *dev, stepper_event_cb_t callback,
258 void *user_data);
259
260static inline int z_impl_stepper_set_event_cb(const struct device *dev,
261 stepper_event_cb_t cb, void *user_data)
262{
263 if (DEVICE_API_GET(stepper, dev)->set_event_cb == NULL) {
264 return -ENOSYS;
265 }
266
267 return DEVICE_API_GET(stepper, dev)->set_event_cb(dev, cb, user_data);
268}
269
273
274#ifdef __cplusplus
275}
276#endif
277
278#include <zephyr/syscalls/stepper.h>
279
280#endif /* ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
System error numbers.
int(* stepper_set_micro_step_res_t)(const struct device *dev, const enum stepper_micro_step_resolution resolution)
Callback API to set the stepper micro-step resolution.
Definition stepper.h:122
int(* stepper_disable_t)(const struct device *dev)
Callback API to disable the stepper hardware driver.
Definition stepper.h:116
int(* stepper_enable_t)(const struct device *dev)
Callback API to enable the stepper hardware driver.
Definition stepper.h:110
int(* stepper_set_event_cb_t)(const struct device *dev, stepper_event_cb_t callback, void *user_data)
Callback API to set the event callback function.
Definition stepper.h:136
int(* stepper_get_micro_step_res_t)(const struct device *dev, enum stepper_micro_step_resolution *resolution)
Callback API to get the stepper micro-step resolution.
Definition stepper.h:129
#define VALID_MICRO_STEP_RES(res)
Check whether a microstep resolution is valid.
Definition stepper.h:78
int stepper_enable(const struct device *dev)
Enable stepper hardware driver.
int stepper_set_micro_step_res(const struct device *dev, enum stepper_micro_step_resolution res)
Set the micro-step resolution in stepper hardware driver.
void(* stepper_event_cb_t)(const struct device *dev, const enum stepper_event event, void *user_data)
Callback function for stepper driver events.
Definition stepper.h:98
int stepper_get_micro_step_res(const struct device *dev, enum stepper_micro_step_resolution *res)
Get the micro-step resolution in stepper hardware driver.
stepper_event
Stepper Hardware Driver Events.
Definition stepper.h:88
int stepper_disable(const struct device *dev)
Disable stepper hardware driver.
stepper_micro_step_resolution
Stepper Motor micro-step resolution options.
Definition stepper.h:45
int stepper_set_event_cb(const struct device *dev, stepper_event_cb_t callback, void *user_data)
Set the callback function to be called when a stepper_event occurs.
@ STEPPER_EVENT_STALL_DETECTED
Stepper driver stall detected.
Definition stepper.h:90
@ STEPPER_EVENT_FAULT_DETECTED
Stepper driver fault detected.
Definition stepper.h:92
@ STEPPER_MICRO_STEP_64
64 micro-steps per full step
Definition stepper.h:59
@ STEPPER_MICRO_STEP_4
4 micro-steps per full step
Definition stepper.h:51
@ STEPPER_MICRO_STEP_1
Full step resolution.
Definition stepper.h:47
@ STEPPER_MICRO_STEP_2
2 micro-steps per full step
Definition stepper.h:49
@ STEPPER_MICRO_STEP_256
256 micro-steps per full step
Definition stepper.h:63
@ STEPPER_MICRO_STEP_8
8 micro-steps per full step
Definition stepper.h:53
@ STEPPER_MICRO_STEP_16
16 micro-steps per full step
Definition stepper.h:55
@ STEPPER_MICRO_STEP_32
32 micro-steps per full step
Definition stepper.h:57
@ STEPPER_MICRO_STEP_128
128 micro-steps per full step
Definition stepper.h:61
#define EINVAL
Invalid argument.
Definition errno.h:61
#define ENOSYS
Function not implemented.
Definition errno.h:83
Public kernel APIs.
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
<span class="mlabel">Driver Operations</span> Stepper Hardware Driver driver operations
Definition stepper.h:142
stepper_enable_t enable
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:146
stepper_disable_t disable
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:150
stepper_get_micro_step_res_t get_micro_step_res
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:158
stepper_set_micro_step_res_t set_micro_step_res
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:154
stepper_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.h:162