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 microstep_interval_ns Step interval in nanoseconds. 24 * @return 0 on success, or a negative error code on failure. 25 */ 26 typedef int (*stepper_timing_source_update)(const struct device *dev, 27 uint64_t microstep_interval_ns); 28 29 /** 30 * @brief Start the stepper timing source. 31 * 32 * @param dev Pointer to the device structure. 33 * @return 0 on success, or a negative error code on failure. 34 */ 35 typedef int (*stepper_timing_source_start)(const struct device *dev); 36 37 /** 38 * @brief Whether the stepper timing source requires rescheduling (keeps running 39 * after the initial start). 40 * 41 * @param dev Pointer to the device structure. 42 * @return true if the timing source requires rescheduling, false otherwise. 43 */ 44 typedef bool (*stepper_timing_sources_requires_reschedule)(const struct device *dev); 45 46 /** 47 * @brief Stop the stepper timing source. 48 * 49 * @param dev Pointer to the device structure. 50 * @return 0 on success, or a negative error code on failure. 51 */ 52 typedef int (*stepper_timing_source_stop)(const struct device *dev); 53 54 /** 55 * @brief Check if the stepper timing source is running. 56 * 57 * @param dev Pointer to the device structure. 58 * @return true if the timing source is running, false otherwise. 59 */ 60 typedef bool (*stepper_timing_source_is_running)(const struct device *dev); 61 62 /** 63 * @brief Stepper timing source API. 64 */ 65 struct stepper_timing_source_api { 66 stepper_timing_source_init init; 67 stepper_timing_source_update update; 68 stepper_timing_source_start start; 69 stepper_timing_sources_requires_reschedule needs_reschedule; 70 stepper_timing_source_stop stop; 71 stepper_timing_source_is_running is_running; 72 }; 73 74 extern const struct stepper_timing_source_api step_work_timing_source_api; 75 #ifdef CONFIG_STEP_DIR_STEPPER_COUNTER_TIMING 76 extern const struct stepper_timing_source_api step_counter_timing_source_api; 77 #endif /* CONFIG_STEP_DIR_STEPPER_COUNTER_TIMING */ 78 79 #endif /* ZEPHYR_DRIVER_STEPPER_STEP_DIR_STEPPER_TIMING_SOURCE_H_ */ 80