1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024 Fabian Blatz <fabianblatz@gmail.com>
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_TIMING_SOURCE_H_
7 #define ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_TIMING_SOURCE_H_
8 
9 #include <zephyr/device.h>
10 
11 /**
12  * @brief Initialize the stepper timing source.
13  *
14  * @param dev Pointer to the device structure.
15  * @return 0 on success, or a negative error code on failure.
16  */
17 typedef int (*stepper_timing_source_init)(const struct device *dev);
18 
19 /**
20  * @brief Update the stepper timing source.
21  *
22  * @param dev Pointer to the device structure.
23  * @param velocity Velocity in microsteps per second.
24  * @return 0 on success, or a negative error code on failure.
25  */
26 typedef int (*stepper_timing_source_update)(const struct device *dev, uint32_t velocity);
27 
28 /**
29  * @brief Start the stepper timing source.
30  *
31  * @param dev Pointer to the device structure.
32  * @return 0 on success, or a negative error code on failure.
33  */
34 typedef int (*stepper_timing_source_start)(const struct device *dev);
35 
36 /**
37  * @brief Whether the stepper timing source requires rescheduling (keeps running
38  *        after the initial start).
39  *
40  * @param dev Pointer to the device structure.
41  * @return true if the timing source requires rescheduling, false otherwise.
42  */
43 typedef bool (*stepper_timing_sources_requires_reschedule)(const struct device *dev);
44 
45 /**
46  * @brief Stop the stepper timing source.
47  *
48  * @param dev Pointer to the device structure.
49  * @return 0 on success, or a negative error code on failure.
50  */
51 typedef int (*stepper_timing_source_stop)(const struct device *dev);
52 
53 /**
54  * @brief Check if the stepper timing source is running.
55  *
56  * @param dev Pointer to the device structure.
57  * @return true if the timing source is running, false otherwise.
58  */
59 typedef bool (*stepper_timing_source_is_running)(const struct device *dev);
60 
61 /**
62  * @brief Stepper timing source API.
63  */
64 struct stepper_timing_source_api {
65 	stepper_timing_source_init init;
66 	stepper_timing_source_update update;
67 	stepper_timing_source_start start;
68 	stepper_timing_sources_requires_reschedule needs_reschedule;
69 	stepper_timing_source_stop stop;
70 	stepper_timing_source_is_running is_running;
71 };
72 
73 extern const struct stepper_timing_source_api step_work_timing_source_api;
74 #ifdef CONFIG_STEP_DIR_STEPPER_COUNTER_TIMING
75 extern const struct stepper_timing_source_api step_counter_timing_source_api;
76 #endif /* CONFIG_STEP_DIR_STEPPER_COUNTER_TIMING */
77 
78 #endif /* ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_TIMING_SOURCE_H_ */
79