drivers: stepper: api: rename stepper_set_target_pos to stepper_move_to

rename stepper_set_target_position to stepper_move_to in following files:
- doc/hardware/peripherals/stepper.rst
- doc/releases/migration-guide-4.1.rst
- drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c
- drivers/stepper/fake_stepper_controller.c
- drivers/stepper/gpio_stepper_controller.c
- drivers/stepper/stepper_shell.c
- include/zephyr/drivers/stepper.h
- include/zephyr/drivers/stepper/stepper_fake.h
- tests/drivers/stepper/shell/src/main.c
- tests/drivers/stepper/stepper_api/src/main.c

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
This commit is contained in:
Jilay Pandya 2024-12-04 21:36:37 +01:00 committed by Benjamin Cabé
commit 030444822e
10 changed files with 34 additions and 31 deletions

View file

@ -19,8 +19,7 @@ Control Stepper
=============== ===============
- **Move by** +/- micro-steps also known as **relative movement** using :c:func:`stepper_move_by`. - **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** - **Move to** a specific position also known as **absolute movement** using :c:func:`stepper_move_to`.
using :c:func:`stepper_set_target_position`.
- Run continuously with a **constant velocity** in a specific direction until - Run continuously with a **constant velocity** in a specific direction until
a stop is detected using :c:func:`stepper_run`. a stop is detected using :c:func:`stepper_run`.
- Check if the stepper is **moving** using :c:func:`stepper_is_moving`. - Check if the stepper is **moving** using :c:func:`stepper_is_moving`.

View file

@ -181,6 +181,7 @@ Stepper
* Renamed the ``stepper_set_actual_position`` function to :c:func:`stepper_set_reference_position`. * 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`. * Renamed the ``stepper_enable_constant_velocity_mode`` function to :c:func:`stepper_run`.
* Renamed the ``stepper_move`` function to :c:func:`stepper_move_by`. * Renamed the ``stepper_move`` function to :c:func:`stepper_move_by`.
* Renamed the ``stepper_set_target_position`` function to :c:func:`stepper_move_to`.
SPI SPI
=== ===

View file

@ -442,9 +442,9 @@ static int tmc5041_stepper_get_actual_position(const struct device *dev, int32_t
return 0; return 0;
} }
static int tmc5041_stepper_set_target_position(const struct device *dev, const int32_t position) static int tmc5041_stepper_move_to(const struct device *dev, const int32_t micro_steps)
{ {
LOG_DBG("Stepper motor controller %s set target position to %d", dev->name, position); LOG_DBG("Stepper motor controller %s set target position to %d", dev->name, micro_steps);
const struct tmc5041_stepper_config *config = dev->config; const struct tmc5041_stepper_config *config = dev->config;
struct tmc5041_stepper_data *data = dev->data; struct tmc5041_stepper_data *data = dev->data;
int err; int err;
@ -458,7 +458,7 @@ static int tmc5041_stepper_set_target_position(const struct device *dev, const i
if (err != 0) { if (err != 0) {
return -EIO; return -EIO;
} }
err = tmc5041_write(config->controller, TMC5041_XTARGET(config->index), position); err = tmc5041_write(config->controller, TMC5041_XTARGET(config->index), micro_steps);
if (err != 0) { if (err != 0) {
return -EIO; return -EIO;
} }
@ -729,7 +729,7 @@ static int tmc5041_stepper_init(const struct device *dev)
.get_micro_step_res = tmc5041_stepper_get_micro_step_res, \ .get_micro_step_res = tmc5041_stepper_get_micro_step_res, \
.set_reference_position = tmc5041_stepper_set_reference_position, \ .set_reference_position = tmc5041_stepper_set_reference_position, \
.get_actual_position = tmc5041_stepper_get_actual_position, \ .get_actual_position = tmc5041_stepper_get_actual_position, \
.set_target_position = tmc5041_stepper_set_target_position, \ .move_to = tmc5041_stepper_move_to, \
.run = tmc5041_stepper_run, \ .run = tmc5041_stepper_run, \
.set_event_callback = tmc5041_stepper_set_event_callback, }; .set_event_callback = tmc5041_stepper_set_event_callback, };

View file

@ -37,7 +37,7 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_reference_position, const struct de
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *); DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *);
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct device *, int32_t); 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, DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction,
uint32_t); uint32_t);
@ -97,7 +97,7 @@ static void fake_stepper_reset_rule_before(const struct ztest_unit_test *test, v
RESET_FAKE(fake_stepper_get_micro_step_res); RESET_FAKE(fake_stepper_get_micro_step_res);
RESET_FAKE(fake_stepper_set_reference_position); RESET_FAKE(fake_stepper_set_reference_position);
RESET_FAKE(fake_stepper_get_actual_position); RESET_FAKE(fake_stepper_get_actual_position);
RESET_FAKE(fake_stepper_set_target_position); RESET_FAKE(fake_stepper_move_to);
RESET_FAKE(fake_stepper_run); RESET_FAKE(fake_stepper_run);
/* Install custom fakes for the setter and getter functions */ /* Install custom fakes for the setter and getter functions */
@ -133,7 +133,7 @@ static DEVICE_API(stepper, fake_stepper_driver_api) = {
.get_micro_step_res = fake_stepper_get_micro_step_res, .get_micro_step_res = fake_stepper_get_micro_step_res,
.set_reference_position = fake_stepper_set_reference_position, .set_reference_position = fake_stepper_set_reference_position,
.get_actual_position = fake_stepper_get_actual_position, .get_actual_position = fake_stepper_get_actual_position,
.set_target_position = fake_stepper_set_target_position, .move_to = fake_stepper_move_to,
.run = fake_stepper_run, .run = fake_stepper_run,
.set_event_callback = fake_stepper_set_event_callback, .set_event_callback = fake_stepper_set_event_callback,
}; };

View file

@ -214,7 +214,7 @@ static int gpio_stepper_get_actual_position(const struct device *dev, int32_t *p
return 0; return 0;
} }
static int gpio_stepper_set_target_position(const struct device *dev, int32_t position) static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps)
{ {
struct gpio_stepper_data *data = dev->data; struct gpio_stepper_data *data = dev->data;
@ -224,7 +224,7 @@ static int gpio_stepper_set_target_position(const struct device *dev, int32_t po
} }
K_SPINLOCK(&data->lock) { K_SPINLOCK(&data->lock) {
data->run_mode = STEPPER_RUN_MODE_POSITION; data->run_mode = STEPPER_RUN_MODE_POSITION;
data->step_count = position - data->actual_position; data->step_count = micro_steps - data->actual_position;
update_direction_from_step_count(dev); update_direction_from_step_count(dev);
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT); (void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
} }
@ -357,7 +357,7 @@ static DEVICE_API(stepper, gpio_stepper_api) = {
.is_moving = gpio_stepper_is_moving, .is_moving = gpio_stepper_is_moving,
.set_reference_position = gpio_stepper_set_reference_position, .set_reference_position = gpio_stepper_set_reference_position,
.get_actual_position = gpio_stepper_get_actual_position, .get_actual_position = gpio_stepper_get_actual_position,
.set_target_position = gpio_stepper_set_target_position, .move_to = gpio_stepper_move_to,
.set_max_velocity = gpio_stepper_set_max_velocity, .set_max_velocity = gpio_stepper_set_max_velocity,
.run = gpio_stepper_run, .run = gpio_stepper_run,
.set_micro_step_res = gpio_stepper_set_micro_step_res, .set_micro_step_res = gpio_stepper_set_micro_step_res,

View file

@ -338,7 +338,7 @@ static int cmd_stepper_get_actual_position(const struct shell *sh, size_t argc,
return err; return err;
} }
static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc, char **argv) static int cmd_stepper_move_to(const struct shell *sh, size_t argc, char **argv)
{ {
const struct device *dev; const struct device *dev;
int err = 0; int err = 0;
@ -358,7 +358,7 @@ static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc,
shell_error(sh, "Failed to set callback: %d", err); shell_error(sh, "Failed to set callback: %d", err);
} }
err = stepper_set_target_position(dev, position); err = stepper_move_to(dev, position);
if (err) { if (err) {
shell_error(sh, "Error: %d", err); shell_error(sh, "Error: %d", err);
} }
@ -465,8 +465,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
cmd_stepper_set_reference_position, 3, 0), cmd_stepper_set_reference_position, 3, 0),
SHELL_CMD_ARG(get_actual_position, &dsub_pos_stepper_motor_name, "<device>", SHELL_CMD_ARG(get_actual_position, &dsub_pos_stepper_motor_name, "<device>",
cmd_stepper_get_actual_position, 2, 0), cmd_stepper_get_actual_position, 2, 0),
SHELL_CMD_ARG(set_target_position, &dsub_pos_stepper_motor_name, "<device> <micro_steps>", SHELL_CMD_ARG(move_to, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
cmd_stepper_set_target_position, 3, 0), cmd_stepper_move_to, 3, 0),
SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, "<device> <direction> <velocity>", SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, "<device> <direction> <velocity>",
cmd_stepper_run, 4, 0), cmd_stepper_run, 4, 0),
SHELL_CMD_ARG(info, &dsub_pos_stepper_motor_name, "<device>", cmd_stepper_info, 2, 0), SHELL_CMD_ARG(info, &dsub_pos_stepper_motor_name, "<device>", cmd_stepper_info, 2, 0),

View file

@ -150,11 +150,11 @@ typedef int (*stepper_set_reference_position_t)(const struct device *dev, const
typedef int (*stepper_get_actual_position_t)(const struct device *dev, int32_t *value); typedef int (*stepper_get_actual_position_t)(const struct device *dev, int32_t *value);
/** /**
* @brief Set the absolute target position of the stepper * @brief Move the stepper motor absolutely by a given number of micro_steps.
* *
* @see stepper_set_target_position() for details. * @see stepper_move_to() for details.
*/ */
typedef int (*stepper_set_target_position_t)(const struct device *dev, const int32_t value); typedef int (*stepper_move_to_t)(const struct device *dev, const int32_t micro_steps);
/** /**
* @brief Is the target position fo the stepper reached * @brief Is the target position fo the stepper reached
@ -196,7 +196,7 @@ __subsystem struct stepper_driver_api {
stepper_get_micro_step_res_t get_micro_step_res; stepper_get_micro_step_res_t get_micro_step_res;
stepper_set_reference_position_t set_reference_position; stepper_set_reference_position_t set_reference_position;
stepper_get_actual_position_t get_actual_position; stepper_get_actual_position_t get_actual_position;
stepper_set_target_position_t set_target_position; stepper_move_to_t move_to;
stepper_is_moving_t is_moving; stepper_is_moving_t is_moving;
stepper_run_t run; stepper_run_t run;
stepper_set_event_callback_t set_event_callback; stepper_set_event_callback_t set_event_callback;
@ -368,23 +368,26 @@ static inline int z_impl_stepper_get_actual_position(const struct device *dev, i
/** /**
* @brief Set the absolute target position of the stepper * @brief Set the absolute target position of the stepper
* *
* @details The motor will move to the given micro_steps position from the reference position.
* This function is non-blocking.
*
* @param dev pointer to the stepper motor controller instance * @param dev pointer to the stepper motor controller instance
* @param value target position to set in micro_steps * @param micro_steps target position to set in micro_steps
* *
* @retval -EIO General input / output error * @retval -EIO General input / output error
* @retval -ENOSYS If not implemented by device driver * @retval -ENOSYS If not implemented by device driver
* @retval 0 Success * @retval 0 Success
*/ */
__syscall int stepper_set_target_position(const struct device *dev, int32_t value); __syscall int stepper_move_to(const struct device *dev, int32_t micro_steps);
static inline int z_impl_stepper_set_target_position(const struct device *dev, const int32_t value) static inline int z_impl_stepper_move_to(const struct device *dev, const int32_t micro_steps)
{ {
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api; const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
if (api->set_target_position == NULL) { if (api->move_to == NULL) {
return -ENOSYS; return -ENOSYS;
} }
return api->set_target_position(dev, value); return api->move_to(dev, micro_steps);
} }
/** /**

View file

@ -30,7 +30,7 @@ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_reference_position, const struct d
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *);
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct device *, int32_t); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move_to, const struct device *, int32_t);
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool *); DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool *);

View file

@ -117,13 +117,13 @@ ZTEST(stepper_shell, test_stepper_get_actual_position)
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_get_actual_position_fake, err); ASSERT_STEPPER_FUNC_CALLED(fake_stepper_get_actual_position_fake, err);
} }
ZTEST(stepper_shell, test_stepper_set_target_position) ZTEST(stepper_shell, test_stepper_move_to)
{ {
const struct shell *sh = shell_backend_dummy_get_ptr(); const struct shell *sh = shell_backend_dummy_get_ptr();
int err = shell_execute_cmd(sh, "stepper set_target_position " FAKE_STEPPER_NAME " 200"); int err = shell_execute_cmd(sh, "stepper move_to " FAKE_STEPPER_NAME " 200");
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_set_target_position_fake, err); ASSERT_STEPPER_FUNC_CALLED(fake_stepper_move_to_fake, err);
zassert_equal(fake_stepper_set_target_position_fake.arg1_val, 200, zassert_equal(fake_stepper_move_to_fake.arg1_val, 200,
"wrong target position value"); "wrong target position value");
} }

View file

@ -87,7 +87,7 @@ ZTEST_F(stepper, test_target_position)
/* Pass the function name as user data */ /* Pass the function name as user data */
(void)stepper_set_event_callback(fixture->dev, fixture->callback, &fixture); (void)stepper_set_event_callback(fixture->dev, fixture->callback, &fixture);
(void)stepper_set_target_position(fixture->dev, pos); (void)stepper_move_to(fixture->dev, pos);
(void)k_poll(&stepper_event, 1, K_SECONDS(5)); (void)k_poll(&stepper_event, 1, K_SECONDS(5));
unsigned int signaled; unsigned int signaled;