Skip to content

Commit 05e94ed

Browse files
jilaypandyakartben
authored andcommitted
drivers: stepper: api: rename stepper_move to stepper_move_by
rename stepper_move to stepper_move_by 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 <jilay.pandya@outlook.com>
1 parent 220c4ff commit 05e94ed

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

doc/hardware/peripherals/stepper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Configure Stepper Driver
1818
Control Stepper
1919
===============
2020

21-
- **Move by** +/- micro-steps also known as **relative movement** using :c:func:`stepper_move`.
21+
- **Move by** +/- micro-steps also known as **relative movement** using :c:func:`stepper_move_by`.
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

doc/releases/migration-guide-4.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Stepper
180180
* Renamed the ``compatible`` from ``zephyr,gpio-steppers`` to :dtcompatible:`zephyr,gpio-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`.
183+
* Renamed the ``stepper_move`` function to :c:func:`stepper_move_by`.
183184

184185
SPI
185186
===

drivers/stepper/adi_tmc/adi_tmc5041_stepper_controller.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static int tmc5041_stepper_is_moving(const struct device *dev, bool *is_moving)
301301
return 0;
302302
}
303303

304-
static int tmc5041_stepper_move(const struct device *dev, const int32_t steps)
304+
static int tmc5041_stepper_move_by(const struct device *dev, const int32_t micro_steps)
305305
{
306306
const struct tmc5041_stepper_config *config = dev->config;
307307
struct tmc5041_stepper_data *data = dev->data;
@@ -320,15 +320,15 @@ static int tmc5041_stepper_move(const struct device *dev, const int32_t steps)
320320
if (err != 0) {
321321
return -EIO;
322322
}
323-
int32_t target_position = position + steps;
323+
int32_t target_position = position + micro_steps;
324324

325325
err = tmc5041_write(config->controller, TMC5041_RAMPMODE(config->index),
326326
TMC5XXX_RAMPMODE_POSITIONING_MODE);
327327
if (err != 0) {
328328
return -EIO;
329329
}
330330
LOG_DBG("Stepper motor controller %s moved to %d by steps: %d", dev->name, target_position,
331-
steps);
331+
micro_steps);
332332
err = tmc5041_write(config->controller, TMC5041_XTARGET(config->index), target_position);
333333
if (err != 0) {
334334
return -EIO;
@@ -723,7 +723,7 @@ static int tmc5041_stepper_init(const struct device *dev)
723723
static DEVICE_API(stepper, tmc5041_stepper_api_##child) = { \
724724
.enable = tmc5041_stepper_enable, \
725725
.is_moving = tmc5041_stepper_is_moving, \
726-
.move = tmc5041_stepper_move, \
726+
.move_by = tmc5041_stepper_move_by, \
727727
.set_max_velocity = tmc5041_stepper_set_max_velocity, \
728728
.set_micro_step_res = tmc5041_stepper_set_micro_step_res, \
729729
.get_micro_step_res = tmc5041_stepper_get_micro_step_res, \

drivers/stepper/fake_stepper_controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_enable, const struct device *, bool);
2323

2424
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_is_moving, const struct device *, bool *);
2525

26-
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_move, const struct device *, int32_t);
26+
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_move_by, const struct device *, int32_t);
2727

2828
DEFINE_FAKE_VALUE_FUNC(int, fake_stepper_set_max_velocity, const struct device *, uint32_t);
2929

@@ -90,7 +90,7 @@ static void fake_stepper_reset_rule_before(const struct ztest_unit_test *test, v
9090
ARG_UNUSED(fixture);
9191

9292
RESET_FAKE(fake_stepper_enable);
93-
RESET_FAKE(fake_stepper_move);
93+
RESET_FAKE(fake_stepper_move_by);
9494
RESET_FAKE(fake_stepper_is_moving);
9595
RESET_FAKE(fake_stepper_set_max_velocity);
9696
RESET_FAKE(fake_stepper_set_micro_step_res);
@@ -126,7 +126,7 @@ static int fake_stepper_init(const struct device *dev)
126126

127127
static DEVICE_API(stepper, fake_stepper_driver_api) = {
128128
.enable = fake_stepper_enable,
129-
.move = fake_stepper_move,
129+
.move_by = fake_stepper_move_by,
130130
.is_moving = fake_stepper_is_moving,
131131
.set_max_velocity = fake_stepper_set_max_velocity,
132132
.set_micro_step_res = fake_stepper_set_micro_step_res,

drivers/stepper/gpio_stepper_controller.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void stepper_work_step_handler(struct k_work *work)
177177
}
178178
}
179179

180-
static int gpio_stepper_move(const struct device *dev, int32_t micro_steps)
180+
static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps)
181181
{
182182
struct gpio_stepper_data *data = dev->data;
183183

@@ -353,7 +353,7 @@ static int gpio_stepper_init(const struct device *dev)
353353

354354
static DEVICE_API(stepper, gpio_stepper_api) = {
355355
.enable = gpio_stepper_enable,
356-
.move = gpio_stepper_move,
356+
.move_by = gpio_stepper_move_by,
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,

drivers/stepper/stepper_shell.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int cmd_stepper_enable(const struct shell *sh, size_t argc, char **argv)
190190
return err;
191191
}
192192

193-
static int cmd_stepper_move(const struct shell *sh, size_t argc, char **argv)
193+
static int cmd_stepper_move_by(const struct shell *sh, size_t argc, char **argv)
194194
{
195195
const struct device *dev;
196196
int err = 0;
@@ -211,7 +211,7 @@ static int cmd_stepper_move(const struct shell *sh, size_t argc, char **argv)
211211
shell_error(sh, "Failed to set callback: %d", err);
212212
}
213213

214-
err = stepper_move(dev, micro_steps);
214+
err = stepper_move_by(dev, micro_steps);
215215
if (err) {
216216
shell_error(sh, "Error: %d", err);
217217
}
@@ -453,8 +453,8 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
453453
stepper_cmds,
454454
SHELL_CMD_ARG(enable, &dsub_pos_stepper_motor_name, "<device> <on/off>", cmd_stepper_enable,
455455
3, 0),
456-
SHELL_CMD_ARG(move, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
457-
cmd_stepper_move, 3, 0),
456+
SHELL_CMD_ARG(move_by, &dsub_pos_stepper_motor_name, "<device> <micro_steps>",
457+
cmd_stepper_move_by, 3, 0),
458458
SHELL_CMD_ARG(set_max_velocity, &dsub_pos_stepper_motor_name, "<device> <velocity>",
459459
cmd_stepper_set_max_velocity, 3, 0),
460460
SHELL_CMD_ARG(set_micro_step_res, &dsub_pos_stepper_motor_name_microstep,

include/zephyr/drivers/stepper.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ enum stepper_event {
106106
typedef int (*stepper_enable_t)(const struct device *dev, const bool enable);
107107

108108
/**
109-
* @brief Move the stepper motor by a given number of micro_steps.
109+
* @brief Move the stepper motor relatively by a given number of micro_steps.
110110
*
111-
* @see stepper_move() for details.
111+
* @see stepper_move_by() for details.
112112
*/
113-
typedef int (*stepper_move_t)(const struct device *dev, const int32_t micro_steps);
113+
typedef int (*stepper_move_by_t)(const struct device *dev, const int32_t micro_steps);
114114

115115
/**
116116
* @brief Set the max velocity in micro_steps per seconds.
@@ -190,7 +190,7 @@ typedef int (*stepper_set_event_callback_t)(const struct device *dev,
190190
*/
191191
__subsystem struct stepper_driver_api {
192192
stepper_enable_t enable;
193-
stepper_move_t move;
193+
stepper_move_by_t move_by;
194194
stepper_set_max_velocity_t set_max_velocity;
195195
stepper_set_micro_step_res_t set_micro_step_res;
196196
stepper_get_micro_step_res_t get_micro_step_res;
@@ -227,19 +227,22 @@ static inline int z_impl_stepper_enable(const struct device *dev, const bool ena
227227
/**
228228
* @brief Set the micro_steps to be moved from the current position i.e. relative movement
229229
*
230+
* @details The motor will move by the given number of micro_steps from the current position.
231+
* This function is non-blocking.
232+
*
230233
* @param dev pointer to the stepper motor controller instance
231234
* @param micro_steps target micro_steps to be moved from the current position
232235
*
233236
* @retval -EIO General input / output error
234237
* @retval 0 Success
235238
*/
236-
__syscall int stepper_move(const struct device *dev, int32_t micro_steps);
239+
__syscall int stepper_move_by(const struct device *dev, int32_t micro_steps);
237240

238-
static inline int z_impl_stepper_move(const struct device *dev, const int32_t micro_steps)
241+
static inline int z_impl_stepper_move_by(const struct device *dev, const int32_t micro_steps)
239242
{
240243
const struct stepper_driver_api *api = (const struct stepper_driver_api *)dev->api;
241244

242-
return api->move(dev, micro_steps);
245+
return api->move_by(dev, micro_steps);
243246
}
244247

245248
/**
@@ -411,6 +414,7 @@ static inline int z_impl_stepper_is_moving(const struct device *dev, bool *is_mo
411414
*
412415
* @details If velocity > 0, motor shall be set into motion and run incessantly until and unless
413416
* stalled or stopped using some other command, for instance, motor_enable(false).
417+
* This function is non-blocking.
414418
*
415419
* @param dev pointer to the stepper motor controller instance
416420
* @param direction The direction to set

include/zephyr/drivers/stepper/stepper_fake.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C" {
1616

1717
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_enable, const struct device *, bool);
1818

19-
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move, const struct device *, int32_t);
19+
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_move_by, const struct device *, int32_t);
2020

2121
DECLARE_FAKE_VALUE_FUNC(int, fake_stepper_set_max_velocity, const struct device *, uint32_t);
2222

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ ZTEST(stepper_shell, test_stepper_enable)
5555
zassert_equal(fake_stepper_enable_fake.arg1_val, false, "wrong enable value");
5656
}
5757

58-
ZTEST(stepper_shell, test_stepper_move)
58+
ZTEST(stepper_shell, test_stepper_move_by)
5959
{
6060
const struct shell *sh = shell_backend_dummy_get_ptr();
61-
int err = shell_execute_cmd(sh, "stepper move " FAKE_STEPPER_NAME " 1000");
61+
int err = shell_execute_cmd(sh, "stepper move_by " FAKE_STEPPER_NAME " 1000");
6262

63-
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_move_fake, err);
64-
zassert_equal(fake_stepper_move_fake.arg1_val, 1000, "wrong microsteps value");
63+
ASSERT_STEPPER_FUNC_CALLED(fake_stepper_move_by_fake, err);
64+
zassert_equal(fake_stepper_move_by_fake.arg1_val, 1000, "wrong microsteps value");
6565
}
6666

6767
ZTEST(stepper_shell, test_stepper_set_max_velocity)

0 commit comments

Comments
 (0)