13#ifndef ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
14#define ZEPHYR_INCLUDE_DRIVERS_STEPPER_H_
65#define MICRO_STEP_RES_INDEX(res) LOG2(res)
73#define VALID_MICRO_STEP_RES(res) \
74 ((res) == STEPPER_MICRO_STEP_1 || (res) == STEPPER_MICRO_STEP_2 || \
75 (res) == STEPPER_MICRO_STEP_4 || (res) == STEPPER_MICRO_STEP_8 || \
76 (res) == STEPPER_MICRO_STEP_16 || (res) == STEPPER_MICRO_STEP_32 || \
77 (res) == STEPPER_MICRO_STEP_64 || (res) == STEPPER_MICRO_STEP_128 || \
78 (res) == STEPPER_MICRO_STEP_256)
176static inline int z_impl_stepper_enable(
const struct device *dev)
194static inline int z_impl_stepper_disable(
const struct device *dev)
213static inline int z_impl_stepper_set_micro_step_res(
const struct device *dev,
219 return DEVICE_API_GET(stepper, dev)->set_micro_step_res(dev, res);
234static inline int z_impl_stepper_get_micro_step_res(
const struct device *dev,
237 __ASSERT_NO_MSG(res != NULL);
238 return DEVICE_API_GET(stepper, dev)->get_micro_step_res(dev, res);
255static inline int z_impl_stepper_set_event_cb(
const struct device *dev,
262 return DEVICE_API_GET(stepper, dev)->set_event_cb(dev, cb, user_data);
273#include <zephyr/syscalls/stepper.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
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:117
int(* stepper_disable_t)(const struct device *dev)
Callback API to disable the stepper hardware driver.
Definition stepper.h:111
int(* stepper_enable_t)(const struct device *dev)
Callback API to enable the stepper hardware driver.
Definition stepper.h:105
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:131
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:124
#define VALID_MICRO_STEP_RES(res)
Check whether a microstep resolution is valid.
Definition stepper.h:73
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:93
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:83
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:85
@ STEPPER_EVENT_FAULT_DETECTED
Stepper driver fault detected.
Definition stepper.h:87
@ 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
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:137
stepper_enable_t enable
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:141
stepper_disable_t disable
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition stepper.h:145
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:153
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:149
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:157