diff --git a/doc/hardware/peripherals/stepper.rst b/doc/hardware/peripherals/stepper.rst index 3b24198a4610eb..9bc78daea5f6b8 100644 --- a/doc/hardware/peripherals/stepper.rst +++ b/doc/hardware/peripherals/stepper.rst @@ -12,7 +12,7 @@ Configure Stepper Driver and :c:func:`stepper_get_micro_step_res`. - Configure **reference position** in microsteps using :c:func:`stepper_set_reference_position` and :c:func:`stepper_get_actual_position`. -- Set **max velocity** in micro-steps per second using :c:func:`stepper_set_max_velocity` +- Set **step interval** in microseconds between steps using :c:func:`stepper_set_step_interval` - **Enable** the stepper driver using :c:func:`stepper_enable`. Control Stepper @@ -20,7 +20,7 @@ Control Stepper - **Move by** +/- micro-steps also known as **relative movement** using :c:func:`stepper_move_by`. - **Move to** a specific position also known as **absolute movement** using :c:func:`stepper_move_to`. -- Run continuously with a **constant velocity** in a specific direction until +- Run continuously with a **constant step interval** in a specific direction until a stop is detected using :c:func:`stepper_run`. - Check if the stepper is **moving** using :c:func:`stepper_is_moving`. - Register an **event callback** using :c:func:`stepper_set_event_callback`. diff --git a/doc/releases/migration-guide-4.1.rst b/doc/releases/migration-guide-4.1.rst index 29805486d9caa1..a66668c260cd8f 100644 --- a/doc/releases/migration-guide-4.1.rst +++ b/doc/releases/migration-guide-4.1.rst @@ -237,8 +237,13 @@ Stepper * Renamed the ``compatible`` from ``zephyr,gpio-steppers`` to :dtcompatible:`zephyr,gpio-stepper`. * Renamed the ``stepper_set_actual_position`` function to :c:func:`stepper_set_reference_position`. * Renamed the ``stepper_enable_constant_velocity_mode`` function to :c:func:`stepper_run`. + The function does not take a velocity parameter anymore. Set the desired speed using the + :c:func:`stepper_set_step_interval` function beforehand. * Renamed the ``stepper_move`` function to :c:func:`stepper_move_by`. * Renamed the ``stepper_set_target_position`` function to :c:func:`stepper_move_to`. + * Renamed the ``stepper_set_max_velocity`` function to :c:func:`stepper_set_step_interval`. + The function now takes the step interval in microseconds. This allows for a more precise control. + * Changed the :c:func:`stepper_run` to take the step interval in microseconds instead of velocity. * The :kconfig:option:`STEPPER_ADI_TMC_RAMP_GEN` is now deprecated and is replaced with the new :kconfig:option:`STEPPER_ADI_TMC5041_RAMP_GEN` option. diff --git a/drivers/stepper/adi_tmc/adi_tmc22xx_stepper_controller.c b/drivers/stepper/adi_tmc/adi_tmc22xx_stepper_controller.c index f93cb6efd180b9..c3f234f09d6931 100644 --- a/drivers/stepper/adi_tmc/adi_tmc22xx_stepper_controller.c +++ b/drivers/stepper/adi_tmc/adi_tmc22xx_stepper_controller.c @@ -150,7 +150,7 @@ static DEVICE_API(stepper, tmc22xx_stepper_api) = { .set_reference_position = step_dir_stepper_common_set_reference_position, .get_actual_position = step_dir_stepper_common_get_actual_position, .move_to = step_dir_stepper_common_move_to, - .set_max_velocity = step_dir_stepper_common_set_max_velocity, + .set_step_interval = step_dir_stepper_common_set_step_interval, .run = step_dir_stepper_common_run, .set_event_callback = step_dir_stepper_common_set_event_callback, .set_micro_step_res = tmc22xx_stepper_set_micro_step_res, diff --git a/drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c b/drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c index fd89e99c0c2f81..131173a71b5e2b 100644 --- a/drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c +++ b/drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c @@ -348,7 +348,7 @@ static int tmc5041_stepper_move_by(const struct device *dev, const int32_t micro return 0; } -static int tmc5041_stepper_set_max_velocity(const struct device *dev, uint32_t velocity) +static int tmc5041_stepper_set_step_interval(const struct device *dev, uint64_t step_interval_us) { const struct tmc5041_stepper_config *config = dev->config; const struct tmc5041_config *tmc5041_config = config->controller->config; @@ -356,7 +356,18 @@ static int tmc5041_stepper_set_max_velocity(const struct device *dev, uint32_t v uint32_t velocity_fclk; int err; - velocity_fclk = tmc5xxx_calculate_velocity_from_hz_to_fclk(velocity, clock_frequency); + if (step_interval_us == 0) { + err = tmc5041_write(config->controller, TMC5041_RAMPMODE(config->index), + TMC5XXX_RAMPMODE_HOLD_MODE); + if (err != 0) { + LOG_ERR("%s: Failed to stop motor", dev->name); + return -EIO; + } + return 0; + } + + velocity_fclk = tmc5xxx_calculate_velocity_fclk_from_step_interval(step_interval_us, + clock_frequency); err = tmc5041_write(config->controller, TMC5041_VMAX(config->index), velocity_fclk); if (err != 0) { @@ -477,19 +488,13 @@ static int tmc5041_stepper_move_to(const struct device *dev, const int32_t micro return 0; } -static int tmc5041_stepper_run(const struct device *dev, const enum stepper_direction direction, - const uint32_t velocity) +static int tmc5041_stepper_run(const struct device *dev, const enum stepper_direction direction) { - LOG_DBG("Stepper motor controller %s run with velocity %d", dev->name, velocity); + LOG_DBG("Stepper motor controller %s run", dev->name); const struct tmc5041_stepper_config *config = dev->config; - const struct tmc5041_config *tmc5041_config = config->controller->config; struct tmc5041_stepper_data *data = dev->data; - const uint32_t clock_frequency = tmc5041_config->clock_frequency; - uint32_t velocity_fclk; int err; - velocity_fclk = tmc5xxx_calculate_velocity_from_hz_to_fclk(velocity, clock_frequency); - if (config->is_sg_enabled) { err = stallguard_enable(dev, false); if (err != 0) { @@ -504,10 +509,6 @@ static int tmc5041_stepper_run(const struct device *dev, const enum stepper_dire if (err != 0) { return -EIO; } - err = tmc5041_write(config->controller, TMC5041_VMAX(config->index), velocity_fclk); - if (err != 0) { - return -EIO; - } break; case STEPPER_DIRECTION_NEGATIVE: @@ -516,10 +517,6 @@ static int tmc5041_stepper_run(const struct device *dev, const enum stepper_dire if (err != 0) { return -EIO; } - err = tmc5041_write(config->controller, TMC5041_VMAX(config->index), velocity_fclk); - if (err != 0) { - return -EIO; - } break; } @@ -724,7 +721,7 @@ static int tmc5041_stepper_init(const struct device *dev) .enable = tmc5041_stepper_enable, \ .is_moving = tmc5041_stepper_is_moving, \ .move_by = tmc5041_stepper_move_by, \ - .set_max_velocity = tmc5041_stepper_set_max_velocity, \ + .set_step_interval = tmc5041_stepper_set_step_interval, \ .set_micro_step_res = tmc5041_stepper_set_micro_step_res, \ .get_micro_step_res = tmc5041_stepper_get_micro_step_res, \ .set_reference_position = tmc5041_stepper_set_reference_position, \ diff --git a/drivers/stepper/adi_tmc/adi_tmc5xxx_common.h b/drivers/stepper/adi_tmc/adi_tmc5xxx_common.h index 7eafe62326eb89..1b320108167a14 100644 --- a/drivers/stepper/adi_tmc/adi_tmc5xxx_common.h +++ b/drivers/stepper/adi_tmc/adi_tmc5xxx_common.h @@ -26,17 +26,21 @@ extern "C" { */ /** - * @brief Calculate the velocity in full clock cycles from the velocity in Hz + * @brief Calculate the velocity in full clock cycles from the given step interval * - * @param velocity_hz Velocity in Hz + * @param step_interval_us Step interval in microseconds * @param clock_frequency Clock frequency in Hz * * @return Calculated velocity in full clock cycles */ -static inline uint32_t tmc5xxx_calculate_velocity_from_hz_to_fclk(uint64_t velocity_hz, - uint32_t clock_frequency) +static inline uint32_t tmc5xxx_calculate_velocity_fclk_from_step_interval(uint64_t step_interval_us, + uint32_t clock_frequency) { __ASSERT_NO_MSG(clock_frequency); + __ASSERT_NO_MSG(step_interval_us); + + uint32_t velocity_hz = 1e6 / step_interval_us; + return (velocity_hz << TMC5XXX_CLOCK_FREQ_SHIFT) / clock_frequency; } diff --git a/drivers/stepper/fake_stepper_controller.c b/drivers/stepper/fake_stepper_controller.c index 519c8dd2c670a3..fec9f3197fa00b 100644 --- a/drivers/stepper/fake_stepper_controller.c +++ b/drivers/stepper/fake_stepper_controller.c @@ -25,7 +25,7 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_move_by, const struct device *, int32_t); -DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_max_velocity, const struct device *, uint32_t); +DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_step_interval, const struct device *, uint64_t); DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_micro_step_res, const struct device *, enum stepper_micro_step_resolution); @@ -39,8 +39,7 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct devic DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_move_to, const struct device *, int32_t); -DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction, - uint32_t); +DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction); DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_event_callback, const struct device *, stepper_event_callback_t, void *); @@ -92,7 +91,7 @@ static void fake_stepper_reset_rule_before(const struct ztest_unit_test *test, v RESET_FAKE(fake_stepper_enable); RESET_FAKE(fake_stepper_move_by); RESET_FAKE(fake_stepper_is_moving); - RESET_FAKE(fake_stepper_set_max_velocity); + RESET_FAKE(fake_stepper_set_step_interval); RESET_FAKE(fake_stepper_set_micro_step_res); RESET_FAKE(fake_stepper_get_micro_step_res); RESET_FAKE(fake_stepper_set_reference_position); @@ -128,7 +127,7 @@ static DEVICE_API(stepper, fake_stepper_driver_api) = { .enable = fake_stepper_enable, .move_by = fake_stepper_move_by, .is_moving = fake_stepper_is_moving, - .set_max_velocity = fake_stepper_set_max_velocity, + .set_step_interval = fake_stepper_set_step_interval, .set_micro_step_res = fake_stepper_set_micro_step_res, .get_micro_step_res = fake_stepper_get_micro_step_res, .set_reference_position = fake_stepper_set_reference_position, diff --git a/drivers/stepper/gpio_stepper_controller.c b/drivers/stepper/gpio_stepper_controller.c index aa5d706f67f817..594c4b9b748be8 100644 --- a/drivers/stepper/gpio_stepper_controller.c +++ b/drivers/stepper/gpio_stepper_controller.c @@ -37,7 +37,7 @@ struct gpio_stepper_data { uint8_t coil_charge; struct k_work_delayable stepper_dwork; int32_t actual_position; - uint32_t delay_in_us; + uint64_t delay_in_us; int32_t step_count; bool is_enabled; stepper_event_callback_t callback; @@ -188,7 +188,7 @@ static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps) } if (data->delay_in_us == 0) { - LOG_ERR("Velocity not set or invalid velocity set"); + LOG_ERR("Step interval not set or invalid step interval set"); return -EINVAL; } K_SPINLOCK(&data->lock) { @@ -230,7 +230,7 @@ static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps) } if (data->delay_in_us == 0) { - LOG_ERR("Velocity not set or invalid velocity set"); + LOG_ERR("Step interval not set or invalid step interval set"); return -EINVAL; } K_SPINLOCK(&data->lock) { @@ -251,29 +251,23 @@ static int gpio_stepper_is_moving(const struct device *dev, bool *is_moving) return 0; } -static int gpio_stepper_set_max_velocity(const struct device *dev, uint32_t velocity) +static int gpio_stepper_set_step_interval(const struct device *dev, uint64_t step_interval_us) { struct gpio_stepper_data *data = dev->data; - if (velocity == 0) { - LOG_ERR("Velocity cannot be zero"); - return -EINVAL; - } - - if (velocity > USEC_PER_SEC) { - LOG_ERR("Velocity cannot be greater than %d micro_steps_per_second", USEC_PER_SEC); + if (step_interval_us == 0) { + LOG_ERR("Step interval is invalid."); return -EINVAL; } K_SPINLOCK(&data->lock) { - data->delay_in_us = USEC_PER_SEC / velocity; + data->delay_in_us = step_interval_us; } - LOG_DBG("Setting Motor Speed to %d", velocity); + LOG_DBG("Setting Motor step interval to %llu", step_interval_us); return 0; } -static int gpio_stepper_run(const struct device *dev, const enum stepper_direction direction, - const uint32_t velocity) +static int gpio_stepper_run(const struct device *dev, const enum stepper_direction direction) { struct gpio_stepper_data *data = dev->data; @@ -285,12 +279,7 @@ static int gpio_stepper_run(const struct device *dev, const enum stepper_directi K_SPINLOCK(&data->lock) { data->run_mode = STEPPER_RUN_MODE_VELOCITY; data->direction = direction; - if (velocity != 0) { - data->delay_in_us = USEC_PER_SEC / velocity; - (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); - } else { - (void)k_work_cancel_delayable(&data->stepper_dwork); - } + (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); } return 0; } @@ -377,7 +366,7 @@ static DEVICE_API(stepper, gpio_stepper_api) = { .set_reference_position = gpio_stepper_set_reference_position, .get_actual_position = gpio_stepper_get_actual_position, .move_to = gpio_stepper_move_to, - .set_max_velocity = gpio_stepper_set_max_velocity, + .set_step_interval = gpio_stepper_set_step_interval, .run = gpio_stepper_run, .set_micro_step_res = gpio_stepper_set_micro_step_res, .get_micro_step_res = gpio_stepper_get_micro_step_res, diff --git a/drivers/stepper/step_dir/step_dir_stepper_common.c b/drivers/stepper/step_dir/step_dir_stepper_common.c index 86be8d5d3c39c4..95caa2daecc159 100644 --- a/drivers/stepper/step_dir/step_dir_stepper_common.c +++ b/drivers/stepper/step_dir/step_dir_stepper_common.c @@ -228,15 +228,15 @@ int step_dir_stepper_common_move_by(const struct device *dev, const int32_t micr struct step_dir_stepper_common_data *data = dev->data; const struct step_dir_stepper_common_config *config = dev->config; - if (data->max_velocity == 0) { - LOG_ERR("Velocity not set or invalid velocity set"); + if (data->step_interval_us == 0) { + LOG_ERR("Step interval not set or invalid step interval set"); return -EINVAL; } K_SPINLOCK(&data->lock) { data->run_mode = STEPPER_RUN_MODE_POSITION; data->step_count = micro_steps; - config->timing_source->update(dev, data->max_velocity); + config->timing_source->update(dev, data->step_interval_us); update_direction_from_step_count(dev); config->timing_source->start(dev); } @@ -244,24 +244,20 @@ int step_dir_stepper_common_move_by(const struct device *dev, const int32_t micr return 0; } -int step_dir_stepper_common_set_max_velocity(const struct device *dev, const uint32_t velocity) +int step_dir_stepper_common_set_step_interval(const struct device *dev, + const uint64_t step_interval_us) { struct step_dir_stepper_common_data *data = dev->data; const struct step_dir_stepper_common_config *config = dev->config; - if (velocity == 0) { - LOG_ERR("Velocity cannot be zero"); - return -EINVAL; - } - - if (velocity > USEC_PER_SEC) { - LOG_ERR("Velocity cannot be greater than %d micro steps per second", USEC_PER_SEC); + if (step_interval_us == 0) { + LOG_ERR("Step interval cannot be zero"); return -EINVAL; } K_SPINLOCK(&data->lock) { - data->max_velocity = velocity; - config->timing_source->update(dev, velocity); + data->step_interval_us = step_interval_us; + config->timing_source->update(dev, step_interval_us); } return 0; @@ -294,15 +290,15 @@ int step_dir_stepper_common_move_to(const struct device *dev, const int32_t valu struct step_dir_stepper_common_data *data = dev->data; const struct step_dir_stepper_common_config *config = dev->config; - if (data->max_velocity == 0) { - LOG_ERR("Velocity not set or invalid velocity set"); + if (data->step_interval_us == 0) { + LOG_ERR("Step interval not set or invalid step interval set"); return -EINVAL; } K_SPINLOCK(&data->lock) { data->run_mode = STEPPER_RUN_MODE_POSITION; data->step_count = value - data->actual_position; - config->timing_source->update(dev, data->max_velocity); + config->timing_source->update(dev, data->step_interval_us); update_direction_from_step_count(dev); config->timing_source->start(dev); } @@ -318,8 +314,7 @@ int step_dir_stepper_common_is_moving(const struct device *dev, bool *is_moving) return 0; } -int step_dir_stepper_common_run(const struct device *dev, const enum stepper_direction direction, - const uint32_t velocity) +int step_dir_stepper_common_run(const struct device *dev, const enum stepper_direction direction) { struct step_dir_stepper_common_data *data = dev->data; const struct step_dir_stepper_common_config *config = dev->config; @@ -327,13 +322,8 @@ int step_dir_stepper_common_run(const struct device *dev, const enum stepper_dir K_SPINLOCK(&data->lock) { data->run_mode = STEPPER_RUN_MODE_VELOCITY; data->direction = direction; - data->max_velocity = velocity; - config->timing_source->update(dev, velocity); - if (velocity != 0) { - config->timing_source->start(dev); - } else { - config->timing_source->stop(dev); - } + config->timing_source->update(dev, data->step_interval_us); + config->timing_source->start(dev); } return 0; diff --git a/drivers/stepper/step_dir/step_dir_stepper_common.h b/drivers/stepper/step_dir/step_dir_stepper_common.h index a6fe92476c1bdb..a40467021c4847 100644 --- a/drivers/stepper/step_dir/step_dir_stepper_common.h +++ b/drivers/stepper/step_dir/step_dir_stepper_common.h @@ -70,7 +70,7 @@ struct step_dir_stepper_common_data { enum stepper_direction direction; enum stepper_run_mode run_mode; int32_t actual_position; - uint32_t max_velocity; + uint64_t step_interval_us; int32_t step_count; stepper_event_callback_t callback; void *event_cb_user_data; @@ -141,13 +141,14 @@ int step_dir_stepper_common_init(const struct device *dev); int step_dir_stepper_common_move_by(const struct device *dev, const int32_t micro_steps); /** - * @brief Set the maximum velocity in micro_steps per second. + * @brief Set the step interval of the stepper motor. * * @param dev Pointer to the device structure. - * @param velocity Maximum velocity in micro_steps per second. + * @param step_interval_us The step interval in microseconds. * @return 0 on success, or a negative error code on failure. */ -int step_dir_stepper_common_set_max_velocity(const struct device *dev, const uint32_t velocity); +int step_dir_stepper_common_set_step_interval(const struct device *dev, + const uint64_t step_interval_us); /** * @brief Set the reference position of the stepper motor. @@ -186,15 +187,13 @@ int step_dir_stepper_common_move_to(const struct device *dev, const int32_t valu int step_dir_stepper_common_is_moving(const struct device *dev, bool *is_moving); /** - * @brief Run the stepper with a given velocity in a given direction. + * @brief Run the stepper with a given direction and step interval. * * @param dev Pointer to the device structure. * @param direction The direction of movement (positive or negative). - * @param velocity The velocity in micro_steps per second. * @return 0 on success, or a negative error code on failure. */ -int step_dir_stepper_common_run(const struct device *dev, const enum stepper_direction direction, - const uint32_t velocity); +int step_dir_stepper_common_run(const struct device *dev, const enum stepper_direction direction); /** * @brief Set a callback function for stepper motor events. diff --git a/drivers/stepper/step_dir/step_dir_stepper_counter_timing.c b/drivers/stepper/step_dir/step_dir_stepper_counter_timing.c index 6a99b434632bab..85fcb8a239771e 100644 --- a/drivers/stepper/step_dir/step_dir_stepper_counter_timing.c +++ b/drivers/stepper/step_dir/step_dir_stepper_counter_timing.c @@ -17,18 +17,17 @@ static void step_counter_top_interrupt(const struct device *dev, void *user_data stepper_handle_timing_signal(data->dev); } -int step_counter_timing_source_update(const struct device *dev, const uint32_t velocity) +int step_counter_timing_source_update(const struct device *dev, const uint64_t step_interval_us) { const struct step_dir_stepper_common_config *config = dev->config; struct step_dir_stepper_common_data *data = dev->data; int ret; - if (velocity == 0) { + if (step_interval_us == 0) { return -EINVAL; } - data->counter_top_cfg.ticks = - DIV_ROUND_UP(counter_us_to_ticks(config->counter, USEC_PER_SEC), velocity); + data->counter_top_cfg.ticks = counter_us_to_ticks(config->counter, step_interval_us); /* Lock interrupts while modifying counter settings */ int key = irq_lock(); diff --git a/drivers/stepper/step_dir/step_dir_stepper_timing_source.h b/drivers/stepper/step_dir/step_dir_stepper_timing_source.h index b2d369f968c6ab..2659a12b17fcb3 100644 --- a/drivers/stepper/step_dir/step_dir_stepper_timing_source.h +++ b/drivers/stepper/step_dir/step_dir_stepper_timing_source.h @@ -20,10 +20,10 @@ typedef int (*stepper_timing_source_init)(const struct device *dev); * @brief Update the stepper timing source. * * @param dev Pointer to the device structure. - * @param velocity Velocity in microsteps per second. + * @param step_interval_us Step interval in microseconds. * @return 0 on success, or a negative error code on failure. */ -typedef int (*stepper_timing_source_update)(const struct device *dev, uint32_t velocity); +typedef int (*stepper_timing_source_update)(const struct device *dev, uint64_t step_interval_us); /** * @brief Start the stepper timing source. diff --git a/drivers/stepper/step_dir/step_dir_stepper_work_timing.c b/drivers/stepper/step_dir/step_dir_stepper_work_timing.c index 8d3bc8614142f5..67c5a2e35b2818 100644 --- a/drivers/stepper/step_dir/step_dir_stepper_work_timing.c +++ b/drivers/stepper/step_dir/step_dir_stepper_work_timing.c @@ -10,11 +10,11 @@ static k_timeout_t stepper_movement_delay(const struct device *dev) { const struct step_dir_stepper_common_data *data = dev->data; - if (data->max_velocity == 0) { + if (data->step_interval_us == 0) { return K_FOREVER; } - return K_USEC(USEC_PER_SEC / data->max_velocity); + return K_USEC(data->step_interval_us); } static void stepper_work_step_handler(struct k_work *work) @@ -35,10 +35,10 @@ int step_work_timing_source_init(const struct device *dev) return 0; } -int step_work_timing_source_update(const struct device *dev, const uint32_t velocity) +int step_work_timing_source_update(const struct device *dev, const uint64_t step_interval_us) { ARG_UNUSED(dev); - ARG_UNUSED(velocity); + ARG_UNUSED(step_interval_us); return 0; } diff --git a/drivers/stepper/stepper_shell.c b/drivers/stepper/stepper_shell.c index 97f05c99e04aec..e1007924b8086f 100644 --- a/drivers/stepper/stepper_shell.c +++ b/drivers/stepper/stepper_shell.c @@ -224,11 +224,11 @@ static int cmd_stepper_move_by(const struct shell *sh, size_t argc, char **argv) return err; } -static int cmd_stepper_set_max_velocity(const struct shell *sh, size_t argc, char **argv) +static int cmd_stepper_set_step_interval(const struct shell *sh, size_t argc, char **argv) { const struct device *dev; int err = 0; - uint32_t velocity = shell_strtoul(argv[ARG_IDX_PARAM], 10, &err); + uint64_t step_interval = shell_strtoull(argv[ARG_IDX_PARAM], 10, &err); if (err < 0) { return err; @@ -239,7 +239,7 @@ static int cmd_stepper_set_max_velocity(const struct shell *sh, size_t argc, cha return err; } - err = stepper_set_max_velocity(dev, velocity); + err = stepper_set_step_interval(dev, step_interval); if (err) { shell_error(sh, "Error: %d", err); } @@ -389,12 +389,6 @@ static int cmd_stepper_run(const struct shell *sh, size_t argc, char **argv) return err; } - uint32_t velocity = shell_strtoul(argv[ARG_IDX_VALUE], 10, &err); - - if (err < 0) { - return err; - } - err = parse_device_arg(sh, argv, &dev); if (err < 0) { return err; @@ -405,7 +399,7 @@ static int cmd_stepper_run(const struct shell *sh, size_t argc, char **argv) shell_error(sh, "Failed to set callback: %d", err); } - err = stepper_run(dev, direction, velocity); + err = stepper_run(dev, direction); if (err) { shell_error(sh, "Error: %d", err); return err; @@ -460,8 +454,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE( 3, 0), SHELL_CMD_ARG(move_by, &dsub_pos_stepper_motor_name, " ", cmd_stepper_move_by, 3, 0), - SHELL_CMD_ARG(set_max_velocity, &dsub_pos_stepper_motor_name, " ", - cmd_stepper_set_max_velocity, 3, 0), + SHELL_CMD_ARG(set_step_interval, &dsub_pos_stepper_motor_name, + " ", cmd_stepper_set_step_interval, 3, 0), SHELL_CMD_ARG(set_micro_step_res, &dsub_pos_stepper_motor_name_microstep, " ", cmd_stepper_set_micro_step_res, 3, 0), SHELL_CMD_ARG(get_micro_step_res, &dsub_pos_stepper_motor_name, "", @@ -472,8 +466,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE( cmd_stepper_get_actual_position, 2, 0), SHELL_CMD_ARG(move_to, &dsub_pos_stepper_motor_name, " ", cmd_stepper_move_to, 3, 0), - SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, " ", - cmd_stepper_run, 4, 0), + SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, " ", + cmd_stepper_run, 3, 0), SHELL_CMD_ARG(info, &dsub_pos_stepper_motor_name, "", cmd_stepper_info, 2, 0), SHELL_SUBCMD_SET_END); diff --git a/drivers/stepper/ti/drv8424.c b/drivers/stepper/ti/drv8424.c index 57aa64f9ff4c86..1086460615f3f0 100644 --- a/drivers/stepper/ti/drv8424.c +++ b/drivers/stepper/ti/drv8424.c @@ -264,8 +264,7 @@ static int drv8424_move_by(const struct device *dev, int32_t steps) return step_dir_stepper_common_move_by(dev, steps); } -static int drv8424_run(const struct device *dev, enum stepper_direction direction, - uint32_t velocity) +static int drv8424_run(const struct device *dev, enum stepper_direction direction) { struct drv8424_data *data = dev->data; @@ -274,7 +273,7 @@ static int drv8424_run(const struct device *dev, enum stepper_direction directio return -ECANCELED; } - return step_dir_stepper_common_run(dev, direction, velocity); + return step_dir_stepper_common_run(dev, direction); } static int drv8424_init(const struct device *dev) @@ -340,7 +339,7 @@ static DEVICE_API(stepper, drv8424_stepper_api) = { .is_moving = step_dir_stepper_common_is_moving, .set_reference_position = step_dir_stepper_common_set_reference_position, .get_actual_position = step_dir_stepper_common_get_actual_position, - .set_max_velocity = step_dir_stepper_common_set_max_velocity, + .set_step_interval = step_dir_stepper_common_set_step_interval, .run = drv8424_run, .set_micro_step_res = drv8424_set_micro_step_res, .get_micro_step_res = drv8424_get_micro_step_res, diff --git a/include/zephyr/drivers/stepper.h b/include/zephyr/drivers/stepper.h index 31200cd0302f2b..fe4216f9da1205 100644 --- a/include/zephyr/drivers/stepper.h +++ b/include/zephyr/drivers/stepper.h @@ -117,12 +117,12 @@ typedef int (*stepper_enable_t)(const struct device *dev, const bool enable); typedef int (*stepper_move_by_t)(const struct device *dev, const int32_t micro_steps); /** - * @brief Set the max velocity in microsteps per seconds. + * @brief Set the time interval between steps in microseconds. * - * @see stepper_set_max_velocity() for details. + * @see stepper_set_step_interval() for details. */ -typedef int (*stepper_set_max_velocity_t)(const struct device *dev, - const uint32_t micro_steps_per_second); +typedef int (*stepper_set_step_interval_t)(const struct device *dev, + const uint64_t step_interval_us); /** * @brief Set the micro-step resolution @@ -168,12 +168,11 @@ typedef int (*stepper_move_to_t)(const struct device *dev, const int32_t micro_s typedef int (*stepper_is_moving_t)(const struct device *dev, bool *is_moving); /** - * @brief Run the stepper with a given velocity in a given direction + * @brief Run the stepper with a given step interval in a given direction * * @see stepper_run() for details. */ -typedef int (*stepper_run_t)(const struct device *dev, const enum stepper_direction direction, - const uint32_t value); +typedef int (*stepper_run_t)(const struct device *dev, const enum stepper_direction direction); /** * @brief Callback function for stepper events @@ -195,7 +194,7 @@ typedef int (*stepper_set_event_callback_t)(const struct device *dev, __subsystem struct stepper_driver_api { stepper_enable_t enable; stepper_move_by_t move_by; - stepper_set_max_velocity_t set_max_velocity; + stepper_set_step_interval_t set_step_interval; stepper_set_micro_step_res_t set_micro_step_res; stepper_get_micro_step_res_t get_micro_step_res; stepper_set_reference_position_t set_reference_position; @@ -251,29 +250,29 @@ static inline int z_impl_stepper_move_by(const struct device *dev, const int32_t } /** - * @brief Set the target velocity to be reached by the motor + * @brief Set the time interval between steps in microseconds * * @details For controllers such as DRV8825 where you * toggle the STEP Pin, the pulse_length would have to be calculated based on this parameter in the - * driver. For controllers where velocity can be set, this parameter corresponds to max_velocity - * @note Setting max velocity does not set the motor into motion, a combination of set_max_velocity - * and move is required to set the motor into motion. + * driver. + * @note Setting step interval does not set the motor into motion, a combination of + * set_step_interval and move is required to set the motor into motion. * * @param dev pointer to the stepper motor controller instance - * @param micro_steps_per_second speed in microsteps per second + * @param step_interval_us time interval between steps in microseconds * * @retval -EIO General input / output error - * @retval -EINVAL If the requested velocity is not supported + * @retval -EINVAL If the requested step interval is not supported * @retval 0 Success */ -__syscall int stepper_set_max_velocity(const struct device *dev, uint32_t micro_steps_per_second); +__syscall int stepper_set_step_interval(const struct device *dev, uint64_t step_interval_us); -static inline int z_impl_stepper_set_max_velocity(const struct device *dev, - const uint32_t micro_steps_per_second) +static inline int z_impl_stepper_set_step_interval(const struct device *dev, + const uint64_t step_interval_us) { const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; - return api->set_max_velocity(dev, micro_steps_per_second); + return api->set_step_interval(dev, step_interval_us); } /** @@ -419,36 +418,31 @@ static inline int z_impl_stepper_is_moving(const struct device *dev, bool *is_mo } /** - * @brief Run the stepper with a given velocity in a given direction + * @brief Run the stepper with a given step interval in a given direction * - * @details If velocity > 0, motor shall be set into motion and run incessantly until and unless - * stalled or stopped using some other command, for instance, motor_enable(false). - * This function is non-blocking. + * @details The motor shall be set into motion and run continuously until + * stalled or stopped using some other command, for instance, motor_enable(false). This + * function is non-blocking. * * @param dev pointer to the stepper motor controller instance * @param direction The direction to set - * @param velocity The velocity to set in microsteps per second - * - > 0: Run the stepper with the given velocity in a given direction - * - 0: Stop the stepper * * @retval -ECANCELED If the stepper is disabled * @retval -EIO General input / output error * @retval -ENOSYS If not implemented by device driver * @retval 0 Success */ -__syscall int stepper_run(const struct device *dev, enum stepper_direction direction, - uint32_t velocity); +__syscall int stepper_run(const struct device *dev, enum stepper_direction direction); static inline int z_impl_stepper_run(const struct device *dev, - const enum stepper_direction direction, - const uint32_t velocity) + const enum stepper_direction direction) { const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; if (api->run == NULL) { return -ENOSYS; } - return api->run(dev, direction, velocity); + return api->run(dev, direction); } /** diff --git a/include/zephyr/drivers/stepper/stepper_fake.h b/include/zephyr/drivers/stepper/stepper_fake.h index 292fdbc0e807be..95cfad2ee9fbed 100644 --- a/include/zephyr/drivers/stepper/stepper_fake.h +++ b/include/zephyr/drivers/stepper/stepper_fake.h @@ -18,7 +18,7 @@ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_enable, const struct device *, bool); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move_by, const struct device *, int32_t); -DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_max_velocity, const struct device *, uint32_t); +DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_step_interval, const struct device *, uint64_t); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_micro_step_res, const struct device *, enum stepper_micro_step_resolution); @@ -34,8 +34,7 @@ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move_to, const struct device *, int32_ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool *); -DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction, - uint32_t); +DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_event_callback, const struct device *, stepper_event_callback_t, void *); diff --git a/tests/drivers/stepper/drv8424/api/src/main.c b/tests/drivers/stepper/drv8424/api/src/main.c index 1af5902a5a4b87..03f2a0d7480e57 100644 --- a/tests/drivers/stepper/drv8424/api/src/main.c +++ b/tests/drivers/stepper/drv8424/api/src/main.c @@ -67,7 +67,7 @@ static void drv8424_api_before(void *f) static void drv8424_api_after(void *f) { struct drv8424_api_fixture *fixture = f; - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, 0); + (void)stepper_enable(fixture->dev, false); } ZTEST_F(drv8424_api, test_micro_step_res_set) @@ -102,7 +102,7 @@ ZTEST_F(drv8424_api, test_is_not_moving_when_disabled) bool moving = true; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_move_by(fixture->dev, steps); (void)stepper_enable(fixture->dev, false); (void)stepper_is_moving(fixture->dev, &moving); @@ -116,7 +116,7 @@ ZTEST_F(drv8424_api, test_position_not_updating_when_disabled) int32_t position_2 = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_move_by(fixture->dev, steps); (void)stepper_enable(fixture->dev, false); (void)stepper_get_actual_position(fixture->dev, &position_1); @@ -133,7 +133,7 @@ ZTEST_F(drv8424_api, test_is_not_moving_when_reenabled_after_movement) bool moving = true; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_move_by(fixture->dev, steps); (void)stepper_enable(fixture->dev, false); (void)k_msleep(100); @@ -149,7 +149,7 @@ ZTEST_F(drv8424_api, test_position_not_updating_when_reenabled_after_movement) int32_t position_2 = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_move_by(fixture->dev, steps); (void)stepper_enable(fixture->dev, false); (void)stepper_get_actual_position(fixture->dev, &position_1); @@ -167,7 +167,7 @@ ZTEST_F(drv8424_api, test_move_to_positive_direction_movement) int32_t pos = 50; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_to(fixture->dev, pos); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -187,7 +187,7 @@ ZTEST_F(drv8424_api, test_move_to_negative_direction_movement) int32_t pos = -50; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_to(fixture->dev, pos); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -207,7 +207,7 @@ ZTEST_F(drv8424_api, test_move_to_identical_current_and_target_position) int32_t pos = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_to(fixture->dev, pos); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -222,13 +222,12 @@ ZTEST_F(drv8424_api, test_move_to_identical_current_and_target_position) zassert_equal(pos, 0, "Target position should not have changed from %d but is %d", 0, pos); } -ZTEST_F(drv8424_api, test_move_to_zero_velocity) +ZTEST_F(drv8424_api, test_move_to_zero_step_interval) { int32_t pos = 100; int32_t ret = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 0u); ret = stepper_move_to(fixture->dev, pos); zassert_not_equal(ret, 0, "Command should fail with an error code, but returned 0"); @@ -243,7 +242,7 @@ ZTEST_F(drv8424_api, test_move_to_is_moving_true_while_moving) bool moving = false; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_to(fixture->dev, pos); (void)stepper_is_moving(fixture->dev, &moving); @@ -256,7 +255,7 @@ ZTEST_F(drv8424_api, test_move_to_is_moving_false_when_completed) bool moving = false; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_to(fixture->dev, pos); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -277,7 +276,7 @@ ZTEST_F(drv8424_api, test_move_to_no_movement_when_disabled) int32_t curr_pos = 50; int32_t ret = 0; - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_enable(fixture->dev, false); ret = stepper_move_to(fixture->dev, pos); @@ -293,7 +292,7 @@ ZTEST_F(drv8424_api, test_move_by_positive_step_count) int32_t steps = 50; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_by(fixture->dev, steps); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -313,7 +312,7 @@ ZTEST_F(drv8424_api, test_move_by_negative_step_count) int32_t steps = -50; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_by(fixture->dev, steps); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -333,7 +332,7 @@ ZTEST_F(drv8424_api, test_move_by_zero_steps_no_movement) int32_t steps = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_by(fixture->dev, steps); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -348,14 +347,14 @@ ZTEST_F(drv8424_api, test_move_by_zero_steps_no_movement) zassert_equal(steps, 0, "Target position should be %d but is %d", 0, steps); } -ZTEST_F(drv8424_api, test_move_by_zero_velocity) +ZTEST_F(drv8424_api, test_move_by_zero_step_interval) { int32_t steps = 100; int32_t ret = 0; int32_t pos = 100; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 0u); + (void)stepper_enable(fixture->dev, false); ret = stepper_move_by(fixture->dev, steps); zassert_not_equal(ret, 0, "Command should fail with an error code, but returned 0"); @@ -370,7 +369,7 @@ ZTEST_F(drv8424_api, test_move_by_is_moving_true_while_moving) bool moving = false; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_by(fixture->dev, steps); (void)stepper_is_moving(fixture->dev, &moving); @@ -383,7 +382,7 @@ ZTEST_F(drv8424_api, test_move_by_is_moving_false_when_completed) bool moving = true; (void)stepper_enable(fixture->dev, true); - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_set_event_callback(fixture->dev, fixture->callback, NULL); (void)stepper_move_by(fixture->dev, steps); (void)k_poll(&stepper_event, 1, K_SECONDS(5)); @@ -404,7 +403,7 @@ ZTEST_F(drv8424_api, test_move_by_no_movement_when_disabled) int32_t curr_pos = 100; int32_t ret = 0; - (void)stepper_set_max_velocity(fixture->dev, 50u); + (void)stepper_set_step_interval(fixture->dev, 20000); (void)stepper_enable(fixture->dev, false); ret = stepper_move_by(fixture->dev, steps); @@ -417,11 +416,12 @@ ZTEST_F(drv8424_api, test_move_by_no_movement_when_disabled) ZTEST_F(drv8424_api, test_run_positive_direction_correct_position) { - int32_t velocity = 50; + uint64_t step_interval = 20000; int32_t steps = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, velocity); + (void)stepper_set_step_interval(fixture->dev, step_interval); + (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE); k_busy_wait(110000); (void)stepper_get_actual_position(fixture->dev, &steps); @@ -431,11 +431,12 @@ ZTEST_F(drv8424_api, test_run_positive_direction_correct_position) ZTEST_F(drv8424_api, test_run_negative_direction_correct_position) { - int32_t velocity = 50; + uint64_t step_interval = 20000; int32_t steps = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_NEGATIVE, velocity); + (void)stepper_set_step_interval(fixture->dev, step_interval); + (void)stepper_run(fixture->dev, STEPPER_DIRECTION_NEGATIVE); k_busy_wait(110000); (void)stepper_get_actual_position(fixture->dev, &steps); @@ -443,52 +444,43 @@ ZTEST_F(drv8424_api, test_run_negative_direction_correct_position) "Current position should be between -6 and -4 but is %d", steps); } -ZTEST_F(drv8424_api, test_run_zero_velocity_correct_position) +ZTEST_F(drv8424_api, test_run_zero_step_interval_correct_position) { - int32_t velocity = 0; + uint64_t step_interval = 0; int32_t steps = 0; (void)stepper_enable(fixture->dev, true); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, velocity); + (void)stepper_set_step_interval(fixture->dev, step_interval); + (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE); k_msleep(100); zassert_equal(steps, 0, "Current position should not have changed from %d but is %d", 0, steps); } -ZTEST_F(drv8424_api, test_run_is_moving_true_when_velocity_greater_zero) +ZTEST_F(drv8424_api, test_run_is_moving_true_when_step_interval_greater_zero) { - int32_t velocity = 50; + uint64_t step_interval = 20000; bool moving = false; (void)stepper_enable(fixture->dev, true); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, velocity); + (void)stepper_set_step_interval(fixture->dev, step_interval); + (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE); (void)stepper_is_moving(fixture->dev, &moving); zassert_true(moving, "Driver should be in state is_moving"); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, 0); -} - -ZTEST_F(drv8424_api, test_run_is_moving_false_when_velocity_zero) -{ - int32_t velocity = 50; - bool moving = true; - - (void)stepper_enable(fixture->dev, true); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, velocity); - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, 0); - (void)stepper_is_moving(fixture->dev, &moving); - zassert_false(moving, "Driver should not be in state is_moving when velocity is 0"); + (void)stepper_enable(fixture->dev, false); } ZTEST_F(drv8424_api, test_run_no_movement_when_disabled) { - int32_t velocity = 50; + uint64_t step_interval = 20000; int32_t steps = 50; int32_t ret = 0; (void)stepper_enable(fixture->dev, false); + (void)stepper_set_step_interval(fixture->dev, step_interval); - ret = stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, velocity); + ret = stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE); zassert_equal(ret, -ECANCELED, "Run should fail with error code %d but returned %d", -ECANCELED, ret); (void)stepper_get_actual_position(fixture->dev, &steps); diff --git a/tests/drivers/stepper/drv8424/emul/src/main.c b/tests/drivers/stepper/drv8424/emul/src/main.c index 411b8d00bcc0b3..79615a20d0c5ca 100644 --- a/tests/drivers/stepper/drv8424/emul/src/main.c +++ b/tests/drivers/stepper/drv8424/emul/src/main.c @@ -40,7 +40,7 @@ static void drv8424_emul_before(void *f) static void drv8424_emul_after(void *f) { struct drv8424_emul_fixture *fixture = f; - (void)stepper_run(fixture->dev, STEPPER_DIRECTION_POSITIVE, 0); + (void)stepper_enable(fixture->dev, false); } ZTEST_F(drv8424_emul, test_enable_on_gpio_pins) diff --git a/tests/drivers/stepper/shell/src/main.c b/tests/drivers/stepper/shell/src/main.c index 8b2a2cc3b5b6fb..160a7b25ae06e5 100644 --- a/tests/drivers/stepper/shell/src/main.c +++ b/tests/drivers/stepper/shell/src/main.c @@ -64,13 +64,14 @@ ZTEST(stepper_shell, test_stepper_move_by) zassert_equal(fake_stepper_move_by_fake.arg1_val, 1000, "wrong microsteps value"); } -ZTEST(stepper_shell, test_stepper_set_max_velocity) +ZTEST(stepper_shell, test_stepper_set_step_interval) { const struct shell *sh = shell_backend_dummy_get_ptr(); - int err = shell_execute_cmd(sh, "stepper set_max_velocity " FAKE_STEPPER_NAME " 200"); + int err = shell_execute_cmd(sh, "stepper set_step_interval " FAKE_STEPPER_NAME " 200"); - ASSERT_STEPPER_FUNC_CALLED(fake_stepper_set_max_velocity_fake, err); - zassert_equal(fake_stepper_set_max_velocity_fake.arg1_val, 200, "wrong velocity value"); + ASSERT_STEPPER_FUNC_CALLED(fake_stepper_set_step_interval_fake, err); + zassert_equal(fake_stepper_set_step_interval_fake.arg1_val, 200, + "wrong step_interval value"); } ZTEST(stepper_shell, test_stepper_set_micro_step_res) @@ -123,25 +124,23 @@ ZTEST(stepper_shell, test_stepper_move_to) int err = shell_execute_cmd(sh, "stepper move_to " FAKE_STEPPER_NAME " 200"); ASSERT_STEPPER_FUNC_CALLED(fake_stepper_move_to_fake, err); - zassert_equal(fake_stepper_move_to_fake.arg1_val, 200, - "wrong target position value"); + zassert_equal(fake_stepper_move_to_fake.arg1_val, 200, "wrong target position value"); } ZTEST(stepper_shell, test_stepper_run) { const struct shell *sh = shell_backend_dummy_get_ptr(); - int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " positive 200"); + int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " positive"); ASSERT_STEPPER_FUNC_CALLED(fake_stepper_run_fake, err); zassert_equal(fake_stepper_run_fake.arg1_val, STEPPER_DIRECTION_POSITIVE, "wrong direction value"); - zassert_equal(fake_stepper_run_fake.arg2_val, 200, "wrong velocity value"); } ZTEST(stepper_shell, test_stepper_run_invalid_direction) { const struct shell *sh = shell_backend_dummy_get_ptr(); - int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " foo 200"); + int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " foo"); zassert_not_equal(err, 0, " executed run with invalid direction value"); } diff --git a/tests/drivers/stepper/stepper_api/src/main.c b/tests/drivers/stepper/stepper_api/src/main.c index 864957ae363add..6bc900947245f6 100644 --- a/tests/drivers/stepper/stepper_api/src/main.c +++ b/tests/drivers/stepper/stepper_api/src/main.c @@ -83,7 +83,7 @@ ZTEST_F(stepper, test_target_position) { int32_t pos = 100u; - (void)stepper_set_max_velocity(fixture->dev, 100u); + (void)stepper_set_step_interval(fixture->dev, 10000); /* Pass the function name as user data */ (void)stepper_set_event_callback(fixture->dev, fixture->callback, &fixture);