diff --git a/doc/hardware/peripherals/stepper.rst b/doc/hardware/peripherals/stepper.rst index 1790740cd58..be95b8a1c53 100644 --- a/doc/hardware/peripherals/stepper.rst +++ b/doc/hardware/peripherals/stepper.rst @@ -24,6 +24,7 @@ Control Stepper - Run continuously with a **constant velocity** in a specific direction until a stop is detected using :c:func:`stepper_enable_constant_velocity_mode`. - Check if the stepper is **moving** using :c:func:`stepper_is_moving`. +- Register an **event callback** using :c:func:`stepper_set_event_callback`. Device Tree =========== diff --git a/drivers/stepper/stepper_shell.c b/drivers/stepper/stepper_shell.c index 3f9d0523294..05ad2370382 100644 --- a/drivers/stepper/stepper_shell.c +++ b/drivers/stepper/stepper_shell.c @@ -203,7 +203,7 @@ static int cmd_stepper_move(const struct shell *sh, size_t argc, char **argv) return err; } - err = stepper_set_callback(dev, print_callback, (void *)sh); + err = stepper_set_event_callback(dev, print_callback, (void *)sh); if (err != 0) { shell_error(sh, "Failed to set callback: %d", err); } @@ -350,7 +350,7 @@ static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc, return err; } - err = stepper_set_callback(dev, print_callback, NULL); + err = stepper_set_event_callback(dev, print_callback, (void *)sh); if (err != 0) { shell_error(sh, "Failed to set callback: %d", err); } @@ -393,7 +393,7 @@ static int cmd_stepper_enable_constant_velocity_mode(const struct shell *sh, siz return err; } - err = stepper_set_callback(dev, print_callback, NULL); + err = stepper_set_event_callback(dev, print_callback, (void *)sh); if (err != 0) { shell_error(sh, "Failed to set callback: %d", err); } diff --git a/include/zephyr/drivers/stepper.h b/include/zephyr/drivers/stepper.h index 39171513aa8..df784840067 100644 --- a/include/zephyr/drivers/stepper.h +++ b/include/zephyr/drivers/stepper.h @@ -180,7 +180,7 @@ typedef void (*stepper_event_callback_t)(const struct device *dev, const enum st /** * @brief Set the callback function to be called when a stepper event occurs * - * @see stepper_set_callback() for details. + * @see stepper_set_event_callback() for details. */ typedef int (*stepper_set_event_callback_t)(const struct device *dev, stepper_event_callback_t callback, void *user_data); @@ -449,11 +449,12 @@ static inline int z_impl_stepper_enable_constant_velocity_mode( * @retval -ENOSYS If not implemented by device driver * @retval 0 Success */ -__syscall int stepper_set_callback(const struct device *dev, stepper_event_callback_t callback, - void *user_data); +__syscall int stepper_set_event_callback(const struct device *dev, + stepper_event_callback_t callback, void *user_data); -static inline int z_impl_stepper_set_callback(const struct device *dev, - stepper_event_callback_t callback, void *user_data) +static inline int z_impl_stepper_set_event_callback(const struct device *dev, + stepper_event_callback_t callback, + void *user_data) { const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; diff --git a/tests/drivers/stepper/stepper_api/src/main.c b/tests/drivers/stepper/stepper_api/src/main.c index 8aaf468c0e1..773578801c5 100644 --- a/tests/drivers/stepper/stepper_api/src/main.c +++ b/tests/drivers/stepper/stepper_api/src/main.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 Jilay Sandeep Pandya + * SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,7 +17,7 @@ struct k_poll_event stepper_event; void *user_data_received; static void stepper_print_event_callback(const struct device *dev, enum stepper_event event, - void *user_data) + void *user_data) { user_data_received = user_data; switch (event) { @@ -85,7 +85,7 @@ ZTEST_F(stepper, test_target_position) (void)stepper_set_max_velocity(fixture->dev, 100u); /* Pass the function name as user data */ - (void)stepper_set_callback(fixture->dev, fixture->callback, &fixture); + (void)stepper_set_event_callback(fixture->dev, fixture->callback, &fixture); (void)stepper_set_target_position(fixture->dev, pos);