Skip to content

Commit af68d97

Browse files
jilaypandyakartben
authored andcommitted
drivers: stepper: api: rename enable_constant_velocity_mode to run
rename enable_constant_velocity_mode to run in following files: - include/zephyr/drivers/stepper.h - include/zephyr/drivers/stepper/stepper_fake.h - 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 - tests/drivers/stepper/shell/src/main.c Signed-off-by: Jilay Pandya <[email protected]>
1 parent 401f784 commit af68d97

File tree

9 files changed

+49
-59
lines changed

9 files changed

+49
-59
lines changed

doc/hardware/peripherals/stepper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Control Stepper
2222
- **Move to** a specific position also known as **absolute movement**
2323
using :c:func:`stepper_set_target_position`.
2424
- Run continuously with a **constant velocity** in a specific direction until
25-
a stop is detected using :c:func:`stepper_enable_constant_velocity_mode`.
25+
a stop is detected using :c:func:`stepper_run`.
2626
- Check if the stepper is **moving** using :c:func:`stepper_is_moving`.
2727
- Register an **event callback** using :c:func:`stepper_set_event_callback`.
2828

doc/releases/migration-guide-4.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Stepper
163163

164164
* Renamed the ``compatible`` from ``zephyr,gpio-steppers`` to :dtcompatible:`zephyr,gpio-stepper`.
165165
* Renamed the ``stepper_set_actual_position`` function to :c:func:`stepper_set_reference_position`.
166+
* Renamed the ``stepper_enable_constant_velocity_mode`` function to :c:func:`stepper_run`.
166167

167168
SPI
168169
===

drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,10 @@ static int tmc5041_stepper_set_target_position(const struct device *dev, const i
477477
return 0;
478478
}
479479

480-
static int tmc5041_stepper_enable_constant_velocity_mode(const struct device *dev,
481-
const enum stepper_direction direction,
482-
const uint32_t velocity)
480+
static int tmc5041_stepper_run(const struct device *dev, const enum stepper_direction direction,
481+
const uint32_t velocity)
483482
{
484-
LOG_DBG("Stepper motor controller %s enable constant velocity mode", dev->name);
483+
LOG_DBG("Stepper motor controller %s run with velocity %d", dev->name, velocity);
485484
const struct tmc5041_stepper_config *config = dev->config;
486485
const struct tmc5041_config *tmc5041_config = config->controller->config;
487486
struct tmc5041_stepper_data *data = dev->data;
@@ -731,7 +730,7 @@ static int tmc5041_stepper_init(const struct device *dev)
731730
.set_reference_position = tmc5041_stepper_set_reference_position, \
732731
.get_actual_position = tmc5041_stepper_get_actual_position, \
733732
.set_target_position = tmc5041_stepper_set_target_position, \
734-
.enable_constant_velocity_mode = tmc5041_stepper_enable_constant_velocity_mode, \
733+
.run = tmc5041_stepper_run, \
735734
.set_event_callback = tmc5041_stepper_set_event_callback, };
736735

737736
#define TMC5041_STEPPER_DEFINE(child) \

drivers/stepper/fake_stepper_controller.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_get_actual_position, const struct devic
3939

4040
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct device *, int32_t);
4141

42-
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_enable_constant_velocity_mode, const struct device *,
43-
enum stepper_direction, uint32_t);
42+
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction,
43+
uint32_t);
4444

4545
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_event_callback, const struct device *,
4646
stepper_event_callback_t, void *);
@@ -98,7 +98,7 @@ static void fake_stepper_reset_rule_before(const struct ztest_unit_test *test, v
9898
RESET_FAKE(fake_stepper_set_reference_position);
9999
RESET_FAKE(fake_stepper_get_actual_position);
100100
RESET_FAKE(fake_stepper_set_target_position);
101-
RESET_FAKE(fake_stepper_enable_constant_velocity_mode);
101+
RESET_FAKE(fake_stepper_run);
102102

103103
/* Install custom fakes for the setter and getter functions */
104104
fake_stepper_set_micro_step_res_fake.custom_fake = fake_stepper_set_micro_step_res_delegate;
@@ -134,7 +134,7 @@ static DEVICE_API(stepper, fake_stepper_driver_api) = {
134134
.set_reference_position = fake_stepper_set_reference_position,
135135
.get_actual_position = fake_stepper_get_actual_position,
136136
.set_target_position = fake_stepper_set_target_position,
137-
.enable_constant_velocity_mode = fake_stepper_enable_constant_velocity_mode,
137+
.run = fake_stepper_run,
138138
.set_event_callback = fake_stepper_set_event_callback,
139139
};
140140

drivers/stepper/gpio_stepper_controller.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,16 @@ static int gpio_stepper_set_max_velocity(const struct device *dev, uint32_t velo
261261
return 0;
262262
}
263263

264-
static int gpio_stepper_enable_constant_velocity_mode(const struct device *dev,
265-
const enum stepper_direction direction,
266-
const uint32_t value)
264+
static int gpio_stepper_run(const struct device *dev, const enum stepper_direction direction,
265+
const uint32_t velocity)
267266
{
268267
struct gpio_stepper_data *data = dev->data;
269268

270269
K_SPINLOCK(&data->lock) {
271270
data->run_mode = STEPPER_RUN_MODE_VELOCITY;
272271
data->direction = direction;
273-
if (value != 0) {
274-
data->delay_in_us = USEC_PER_SEC / value;
272+
if (velocity != 0) {
273+
data->delay_in_us = USEC_PER_SEC / velocity;
275274
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
276275
} else {
277276
(void)k_work_cancel_delayable(&data->stepper_dwork);
@@ -360,7 +359,7 @@ static DEVICE_API(stepper, gpio_stepper_api) = {
360359
.get_actual_position = gpio_stepper_get_actual_position,
361360
.set_target_position = gpio_stepper_set_target_position,
362361
.set_max_velocity = gpio_stepper_set_max_velocity,
363-
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode,
362+
.run = gpio_stepper_run,
364363
.set_micro_step_res = gpio_stepper_set_micro_step_res,
365364
.get_micro_step_res = gpio_stepper_get_micro_step_res,
366365
.set_event_callback = gpio_stepper_set_event_callback,

drivers/stepper/stepper_shell.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ static int cmd_stepper_set_target_position(const struct shell *sh, size_t argc,
366366
return err;
367367
}
368368

369-
static int cmd_stepper_enable_constant_velocity_mode(const struct shell *sh, size_t argc,
370-
char **argv)
369+
static int cmd_stepper_run(const struct shell *sh, size_t argc, char **argv)
371370
{
372371
const struct device *dev;
373372
int err = -EINVAL;
@@ -401,7 +400,7 @@ static int cmd_stepper_enable_constant_velocity_mode(const struct shell *sh, siz
401400
shell_error(sh, "Failed to set callback: %d", err);
402401
}
403402

404-
err = stepper_enable_constant_velocity_mode(dev, direction, velocity);
403+
err = stepper_run(dev, direction, velocity);
405404
if (err) {
406405
shell_error(sh, "Error: %d", err);
407406
return err;
@@ -468,9 +467,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
468467
cmd_stepper_get_actual_position, 2, 0),
469468
SHELL_CMD_ARG(set_target_position, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
470469
cmd_stepper_set_target_position, 3, 0),
471-
SHELL_CMD_ARG(enable_constant_velocity_mode, &dsub_pos_stepper_motor_name_dir,
472-
"<device> <direction> <velocity>", cmd_stepper_enable_constant_velocity_mode,
473-
4, 0),
470+
SHELL_CMD_ARG(run, &dsub_pos_stepper_motor_name_dir, "<device> <direction> <velocity>",
471+
cmd_stepper_run, 4, 0),
474472
SHELL_CMD_ARG(info, &dsub_pos_stepper_motor_name, "<device>", cmd_stepper_info, 2, 0),
475473
SHELL_SUBCMD_SET_END);
476474

include/zephyr/drivers/stepper.h

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,12 @@ typedef int (*stepper_set_target_position_t)(const struct device *dev, const int
164164
typedef int (*stepper_is_moving_t)(const struct device *dev, bool *is_moving);
165165

166166
/**
167-
* @brief Enable constant velocity mode for the stepper with a given velocity
167+
* @brief Run the stepper with a given velocity in a given direction
168168
*
169-
* @see stepper_enable_constant_velocity_mode() for details.
169+
* @see stepper_run() for details.
170170
*/
171-
typedef int (*stepper_enable_constant_velocity_mode_t)(const struct device *dev,
172-
const enum stepper_direction direction,
173-
const uint32_t value);
171+
typedef int (*stepper_run_t)(const struct device *dev, const enum stepper_direction direction,
172+
const uint32_t value);
174173

175174
/**
176175
* @brief Callback function for stepper events
@@ -199,7 +198,7 @@ __subsystem struct stepper_driver_api {
199198
stepper_get_actual_position_t get_actual_position;
200199
stepper_set_target_position_t set_target_position;
201200
stepper_is_moving_t is_moving;
202-
stepper_enable_constant_velocity_mode_t enable_constant_velocity_mode;
201+
stepper_run_t run;
203202
stepper_set_event_callback_t set_event_callback;
204203
};
205204

@@ -408,36 +407,34 @@ static inline int z_impl_stepper_is_moving(const struct device *dev, bool *is_mo
408407
}
409408

410409
/**
411-
* @brief Enable constant velocity mode for the stepper with a given velocity
410+
* @brief Run the stepper with a given velocity in a given direction
412411
*
413-
* @details activate constant velocity mode with the given velocity in micro_steps_per_second.
414-
* If velocity > 0, motor shall be set into motion and run incessantly until and unless stalled or
415-
* stopped using some other command, for instance, motor_enable(false).
412+
* @details If velocity > 0, motor shall be set into motion and run incessantly until and unless
413+
* stalled or stopped using some other command, for instance, motor_enable(false).
416414
*
417415
* @param dev pointer to the stepper motor controller instance
418416
* @param direction The direction to set
419-
* @param value The velocity to set in steps per second where one step is dependent on the current
420-
* microstepping resolution:
421-
* > 0: Enable constant velocity mode with the given velocity in a given direction
422-
* 0: Disable constant velocity mode
417+
* @param velocity The velocity to set in microsteps per second
418+
* - > 0: Run the stepper with the given velocity in a given direction
419+
* - 0: Stop the stepper
423420
*
424421
* @retval -EIO General input / output error
425422
* @retval -ENOSYS If not implemented by device driver
426423
* @retval 0 Success
427424
*/
428-
__syscall int stepper_enable_constant_velocity_mode(const struct device *dev,
429-
enum stepper_direction direction,
430-
uint32_t value);
425+
__syscall int stepper_run(const struct device *dev, enum stepper_direction direction,
426+
uint32_t velocity);
431427

432-
static inline int z_impl_stepper_enable_constant_velocity_mode(
433-
const struct device *dev, const enum stepper_direction direction, const uint32_t value)
428+
static inline int z_impl_stepper_run(const struct device *dev,
429+
const enum stepper_direction direction,
430+
const uint32_t velocity)
434431
{
435432
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
436433

437-
if (api->enable_constant_velocity_mode == NULL) {
434+
if (api->run == NULL) {
438435
return -ENOSYS;
439436
}
440-
return api->enable_constant_velocity_mode(dev, direction, value);
437+
return api->run(dev, direction, velocity);
441438
}
442439

443440
/**

include/zephyr/drivers/stepper/stepper_fake.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_target_position, const struct devi
3434

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

37-
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_enable_constant_velocity_mode, const struct device *,
38-
enum stepper_direction, uint32_t);
37+
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_run, const struct device *, enum stepper_direction,
38+
uint32_t);
3939

4040
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_event_callback, const struct device *,
4141
stepper_event_callback_t, void *);

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,23 @@ ZTEST(stepper_shell, test_stepper_set_target_position)
127127
"wrong target position value");
128128
}
129129

130-
ZTEST(stepper_shell, test_stepper_enable_constant_velocity_mode)
130+
ZTEST(stepper_shell, test_stepper_run)
131131
{
132132
const struct shell *sh = shell_backend_dummy_get_ptr();
133-
int err = shell_execute_cmd(sh, "stepper enable_constant_velocity_mode " FAKE_STEPPER_NAME
134-
" positive 200");
135-
136-
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_enable_constant_velocity_mode_fake, err);
137-
zassert_equal(fake_stepper_enable_constant_velocity_mode_fake.arg1_val,
138-
STEPPER_DIRECTION_POSITIVE, "wrong direction value");
139-
zassert_equal(fake_stepper_enable_constant_velocity_mode_fake.arg2_val, 200,
140-
"wrong velocity value");
133+
int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " positive 200");
134+
135+
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_run_fake, err);
136+
zassert_equal(fake_stepper_run_fake.arg1_val, STEPPER_DIRECTION_POSITIVE,
137+
"wrong direction value");
138+
zassert_equal(fake_stepper_run_fake.arg2_val, 200, "wrong velocity value");
141139
}
142140

143-
ZTEST(stepper_shell, test_stepper_enable_constant_velocity_mode_invalid_direction)
141+
ZTEST(stepper_shell, test_stepper_run_invalid_direction)
144142
{
145143
const struct shell *sh = shell_backend_dummy_get_ptr();
146-
int err = shell_execute_cmd(sh, "stepper enable_constant_velocity_mode " FAKE_STEPPER_NAME
147-
" foo 200");
144+
int err = shell_execute_cmd(sh, "stepper run " FAKE_STEPPER_NAME " foo 200");
148145

149-
zassert_not_equal(err, 0,
150-
" executed enable_constant_velocity_mode with invalid direction value");
146+
zassert_not_equal(err, 0, " executed run with invalid direction value");
151147
}
152148

153149
ZTEST(stepper_shell, test_stepper_info)

0 commit comments

Comments
 (0)