13#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
65#define MICRO_STEP_RES_INDEX(res) LOG2(res)
67#define VALID_MICRO_STEP_RES(res) \
68 ((res) == STEPPER_MICRO_STEP_1 || (res) == STEPPER_MICRO_STEP_2 || \
69 (res) == STEPPER_MICRO_STEP_4 || (res) == STEPPER_MICRO_STEP_8 || \
70 (res) == STEPPER_MICRO_STEP_16 || (res) == STEPPER_MICRO_STEP_32 || \
71 (res) == STEPPER_MICRO_STEP_64 || (res) == STEPPER_MICRO_STEP_128 || \
72 (res) == STEPPER_MICRO_STEP_256)
96typedef int (*stepper_enable_t)(
const struct device *dev);
103typedef int (*stepper_disable_t)(
const struct device *dev);
110typedef int (*stepper_set_micro_step_res_t)(
118typedef int (*stepper_get_micro_step_res_t)(
const struct device *dev,
124typedef void (*stepper_event_cb_t)(
const struct device *dev,
const enum stepper_event event,
132typedef int (*stepper_set_event_cb_t)(
const struct device *dev,
133 stepper_event_cb_t callback,
void *user_data);
138__subsystem
struct stepper_driver_api {
139 stepper_enable_t enable;
140 stepper_disable_t disable;
141 stepper_set_micro_step_res_t set_micro_step_res;
142 stepper_get_micro_step_res_t get_micro_step_res;
143 stepper_set_event_cb_t set_event_cb;
162static inline int z_impl_stepper_enable(
const struct device *dev)
164 __ASSERT_NO_MSG(dev !=
NULL);
165 const struct stepper_driver_api *api = (
const struct stepper_driver_api *)dev->
api;
167 return api->enable(dev);
183static inline int z_impl_stepper_disable(
const struct device *dev)
185 __ASSERT_NO_MSG(dev !=
NULL);
186 const struct stepper_driver_api *api = (
const struct stepper_driver_api *)dev->
api;
188 return api->disable(dev);
205static inline int z_impl_stepper_set_micro_step_res(
const struct device *dev,
208 __ASSERT_NO_MSG(dev !=
NULL);
209 const struct stepper_driver_api *api = (
const struct stepper_driver_api *)dev->
api;
214 return api->set_micro_step_res(dev, res);
229static inline int z_impl_stepper_get_micro_step_res(
const struct device *dev,
232 __ASSERT_NO_MSG(dev !=
NULL);
233 __ASSERT_NO_MSG(res !=
NULL);
234 const struct stepper_driver_api *api = (
const struct stepper_driver_api *)dev->
api;
236 return api->get_micro_step_res(dev, res);
253static inline int z_impl_stepper_set_event_cb(
const struct device *dev,
254 stepper_event_cb_t cb,
void *user_data)
256 __ASSERT_NO_MSG(dev !=
NULL);
257 const struct stepper_driver_api *api = (
const struct stepper_driver_api *)dev->
api;
259 if (api->set_event_cb ==
NULL) {
263 return api->set_event_cb(dev, cb, user_data);
274#include <zephyr/syscalls/stepper.h>
#define VALID_MICRO_STEP_RES(res)
Definition stepper.h:67
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.
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:77
int stepper_disable(const struct device *dev)
Disable stepper hardware driver.
stepper_micro_step_resolution
Stepper Motor micro-step resolution options.
Definition stepper.h:40
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:79
@ STEPPER_EVENT_FAULT_DETECTED
Stepper driver fault detected.
Definition stepper.h:81
@ STEPPER_MICRO_STEP_64
64 micro-steps per full step
Definition stepper.h:54
@ STEPPER_MICRO_STEP_4
4 micro-steps per full step
Definition stepper.h:46
@ STEPPER_MICRO_STEP_1
Full step resolution.
Definition stepper.h:42
@ STEPPER_MICRO_STEP_2
2 micro-steps per full step
Definition stepper.h:44
@ STEPPER_MICRO_STEP_256
256 micro-steps per full step
Definition stepper.h:58
@ STEPPER_MICRO_STEP_8
8 micro-steps per full step
Definition stepper.h:48
@ STEPPER_MICRO_STEP_16
16 micro-steps per full step
Definition stepper.h:50
@ STEPPER_MICRO_STEP_32
32 micro-steps per full step
Definition stepper.h:52
@ STEPPER_MICRO_STEP_128
128 micro-steps per full step
Definition stepper.h:56
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
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