Skip to content

Commit 0304448

Browse files
jilaypandyakartben
authored andcommitted
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>
1 parent 05e94ed commit 0304448

File tree

10 files changed

+34
-31
lines changed

10 files changed

+34
-31
lines changed

doc/hardware/peripherals/stepper.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ Control Stepper
1919
===============
2020

2121
- **Move by** +/- micro-steps also known as **relative movement** using :c:func:`stepper_move_by`.
22-
- **Move to** a specific position also known as **absolute movement**
23-
using :c:func:`stepper_set_target_position`.
22+
- **Move to** a specific position also known as **absolute movement** using :c:func:`stepper_move_to`.
2423
- Run continuously with a **constant velocity** in a specific direction until
2524
a stop is detected using :c:func:`stepper_run`.
2625
- Check if the stepper is **moving** using :c:func:`stepper_is_moving`.

doc/releases/migration-guide-4.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Stepper
181181
* Renamed the ``stepper_set_actual_position`` function to :c:func:`stepper_set_reference_position`.
182182
* Renamed the ``stepper_enable_constant_velocity_mode`` function to :c:func:`stepper_run`.
183183
* Renamed the ``stepper_move`` function to :c:func:`stepper_move_by`.
184+
* Renamed the ``stepper_set_target_position`` function to :c:func:`stepper_move_to`.
184185

185186
SPI
186187
===

drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ static int tmc5041_stepper_get_actual_position(const struct device *dev, int32_t
442442
return 0;
443443
}
444444

445-
static int tmc5041_stepper_set_target_position(const struct device *dev, const int32_t position)
445+
static int tmc5041_stepper_move_to(const struct device *dev, const int32_t micro_steps)
446446
{
447-
LOG_DBG("Stepper motor controller %s set target position to %d", dev->name, position);
447+
LOG_DBG("Stepper motor controller %s set target position to %d", dev->name, micro_steps);
448448
const struct tmc5041_stepper_config *config = dev->config;
449449
struct tmc5041_stepper_data *data = dev->data;
450450
int err;
@@ -458,7 +458,7 @@ static int tmc5041_stepper_set_target_position(const struct device *dev, const i
458458
if (err != 0) {
459459
return -EIO;
460460
}
461-
err = tmc5041_write(config->controller, TMC5041_XTARGET(config->index), position);
461+
err = tmc5041_write(config->controller, TMC5041_XTARGET(config->index), micro_steps);
462462
if (err != 0) {
463463
return -EIO;
464464
}
@@ -729,7 +729,7 @@ static int tmc5041_stepper_init(const struct device *dev)
729729
.get_micro_step_res = tmc5041_stepper_get_micro_step_res, \
730730
.set_reference_position = tmc5041_stepper_set_reference_position, \
731731
.get_actual_position = tmc5041_stepper_get_actual_position, \
732-
.set_target_position = tmc5041_stepper_set_target_position, \
732+
.move_to = tmc5041_stepper_move_to, \
733733
.run = tmc5041_stepper_run, \
734734
.set_event_callback = tmc5041_stepper_set_event_callback, };
735735

drivers/stepper/fake_stepper_controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_reference_position, const struct de
3737

3838
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *);
3939

40-
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct device *, int32_t);
40+
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_move_to, const struct device *, int32_t);
4141

4242
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction,
4343
uint32_t);
@@ -97,7 +97,7 @@ static void fake_stepper_reset_rule_before(const struct ztest_unit_test *test, v
9797
RESET_FAKE(fake_stepper_get_micro_step_res);
9898
RESET_FAKE(fake_stepper_set_reference_position);
9999
RESET_FAKE(fake_stepper_get_actual_position);
100-
RESET_FAKE(fake_stepper_set_target_position);
100+
RESET_FAKE(fake_stepper_move_to);
101101
RESET_FAKE(fake_stepper_run);
102102

103103
/* Install custom fakes for the setter and getter functions */
@@ -133,7 +133,7 @@ static DEVICE_API(stepper, fake_stepper_driver_api) = {
133133
.get_micro_step_res = fake_stepper_get_micro_step_res,
134134
.set_reference_position = fake_stepper_set_reference_position,
135135
.get_actual_position = fake_stepper_get_actual_position,
136-
.set_target_position = fake_stepper_set_target_position,
136+
.move_to = fake_stepper_move_to,
137137
.run = fake_stepper_run,
138138
.set_event_callback = fake_stepper_set_event_callback,
139139
};

drivers/stepper/gpio_stepper_controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static int gpio_stepper_get_actual_position(const struct device *dev, int32_t *p
214214
return 0;
215215
}
216216

217-
static int gpio_stepper_set_target_position(const struct device *dev, int32_t position)
217+
static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps)
218218
{
219219
struct gpio_stepper_data *data = dev->data;
220220

@@ -224,7 +224,7 @@ static int gpio_stepper_set_target_position(const struct device *dev, int32_t po
224224
}
225225
K_SPINLOCK(&data->lock) {
226226
data->run_mode = STEPPER_RUN_MODE_POSITION;
227-
data->step_count = position - data->actual_position;
227+
data->step_count = micro_steps - data->actual_position;
228228
update_direction_from_step_count(dev);
229229
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
230230
}
@@ -357,7 +357,7 @@ static DEVICE_API(stepper, gpio_stepper_api) = {
357357
.is_moving = gpio_stepper_is_moving,
358358
.set_reference_position = gpio_stepper_set_reference_position,
359359
.get_actual_position = gpio_stepper_get_actual_position,
360-
.set_target_position = gpio_stepper_set_target_position,
360+
.move_to = gpio_stepper_move_to,
361361
.set_max_velocity = gpio_stepper_set_max_velocity,
362362
.run = gpio_stepper_run,
363363
.set_micro_step_res = gpio_stepper_set_micro_step_res,

drivers/stepper/stepper_shell.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static int cmd_stepper_get_actual_position(const struct shell *sh, size_t argc,
338338
return err;
339339
}
340340

341-
static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc, char **argv)
341+
static int cmd_stepper_move_to(const struct shell *sh, size_t argc, char **argv)
342342
{
343343
const struct device *dev;
344344
int err = 0;
@@ -358,7 +358,7 @@ static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc,
358358
shell_error(sh, "Failed to set callback: %d", err);
359359
}
360360

361-
err = stepper_set_target_position(dev, position);
361+
err = stepper_move_to(dev, position);
362362
if (err) {
363363
shell_error(sh, "Error: %d", err);
364364
}
@@ -465,8 +465,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
465465
cmd_stepper_set_reference_position, 3, 0),
466466
SHELL_CMD_ARG(get_actual_position, &dsub_pos_stepper_motor_name, "<device>",
467467
cmd_stepper_get_actual_position, 2, 0),
468-
SHELL_CMD_ARG(set_target_position, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
469-
cmd_stepper_set_target_position, 3, 0),
468+
SHELL_CMD_ARG(move_to, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
469+
cmd_stepper_move_to, 3, 0),
470470
SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, "<device> <direction> <velocity>",
471471
cmd_stepper_run, 4, 0),
472472
SHELL_CMD_ARG(info, &dsub_pos_stepper_motor_name, "<device>", cmd_stepper_info, 2, 0),

include/zephyr/drivers/stepper.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ typedef int (*stepper_set_reference_position_t)(const struct device *dev, const
150150
typedef int (*stepper_get_actual_position_t)(const struct device *dev, int32_t *value);
151151

152152
/**
153-
* @brief Set the absolute target position of the stepper
153+
* @brief Move the stepper motor absolutely by a given number of micro_steps.
154154
*
155-
* @see stepper_set_target_position() for details.
155+
* @see stepper_move_to() for details.
156156
*/
157-
typedef int (*stepper_set_target_position_t)(const struct device *dev, const int32_t value);
157+
typedef int (*stepper_move_to_t)(const struct device *dev, const int32_t micro_steps);
158158

159159
/**
160160
* @brief Is the target position fo the stepper reached
@@ -196,7 +196,7 @@ __subsystem struct stepper_driver_api {
196196
stepper_get_micro_step_res_t get_micro_step_res;
197197
stepper_set_reference_position_t set_reference_position;
198198
stepper_get_actual_position_t get_actual_position;
199-
stepper_set_target_position_t set_target_position;
199+
stepper_move_to_t move_to;
200200
stepper_is_moving_t is_moving;
201201
stepper_run_t run;
202202
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
368368
/**
369369
* @brief Set the absolute target position of the stepper
370370
*
371+
* @details The motor will move to the given micro_steps position from the reference position.
372+
* This function is non-blocking.
373+
*
371374
* @param dev pointer to the stepper motor controller instance
372-
* @param value target position to set in micro_steps
375+
* @param micro_steps target position to set in micro_steps
373376
*
374377
* @retval -EIO General input / output error
375378
* @retval -ENOSYS If not implemented by device driver
376379
* @retval 0 Success
377380
*/
378-
__syscall int stepper_set_target_position(const struct device *dev, int32_t value);
381+
__syscall int stepper_move_to(const struct device *dev, int32_t micro_steps);
379382

380-
static inline int z_impl_stepper_set_target_position(const struct device *dev, const int32_t value)
383+
static inline int z_impl_stepper_move_to(const struct device *dev, const int32_t micro_steps)
381384
{
382385
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
383386

384-
if (api->set_target_position == NULL) {
387+
if (api->move_to == NULL) {
385388
return -ENOSYS;
386389
}
387-
return api->set_target_position(dev, value);
390+
return api->move_to(dev, micro_steps);
388391
}
389392

390393
/**

include/zephyr/drivers/stepper/stepper_fake.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_reference_position, const struct d
3030

3131
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct device *, int32_t *);
3232

33-
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct device *, int32_t);
33+
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move_to, const struct device *, int32_t);
3434

3535
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool *);
3636

tests/drivers/stepper/shell/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ ZTEST(stepper_shell, test_stepper_get_actual_position)
117117
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_get_actual_position_fake, err);
118118
}
119119

120-
ZTEST(stepper_shell, test_stepper_set_target_position)
120+
ZTEST(stepper_shell, test_stepper_move_to)
121121
{
122122
const struct shell *sh = shell_backend_dummy_get_ptr();
123-
int err = shell_execute_cmd(sh, "stepper set_target_position " FAKE_STEPPER_NAME " 200");
123+
int err = shell_execute_cmd(sh, "stepper move_to " FAKE_STEPPER_NAME " 200");
124124

125-
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_set_target_position_fake, err);
126-
zassert_equal(fake_stepper_set_target_position_fake.arg1_val, 200,
125+
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_move_to_fake, err);
126+
zassert_equal(fake_stepper_move_to_fake.arg1_val, 200,
127127
"wrong target position value");
128128
}
129129

tests/drivers/stepper/stepper_api/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ZTEST_F(stepper, test_target_position)
8787
/* Pass the function name as user data */
8888
(void)stepper_set_event_callback(fixture->dev, fixture->callback, &fixture);
8989

90-
(void)stepper_set_target_position(fixture->dev, pos);
90+
(void)stepper_move_to(fixture->dev, pos);
9191

9292
(void)k_poll(&stepper_event, 1, K_SECONDS(5));
9393
unsigned int signaled;

0 commit comments

Comments
 (0)