Skip to content

Commit 2aca0d3

Browse files
jilaypandyakartben
authored andcommitted
drivers: stepper: remove stop function wrapped in disable
Removing stop functionality wrapped in stepper_disable since there is a dedicated function for it. Signed-off-by: Jilay Pandya <[email protected]>
1 parent 5918ddc commit 2aca0d3

File tree

5 files changed

+22
-252
lines changed

5 files changed

+22
-252
lines changed

drivers/stepper/allegro/a4979.c

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct a4979_config {
2424
struct a4979_data {
2525
const struct step_dir_stepper_common_data common;
2626
enum stepper_micro_step_resolution micro_step_res;
27-
bool enabled;
2827
};
2928

3029
STEP_DIR_STEPPER_STRUCT_CHECK(struct a4979_config, struct a4979_data);
@@ -54,7 +53,6 @@ static int a4979_stepper_enable(const struct device *dev)
5453
{
5554
int ret;
5655
const struct a4979_config *config = dev->config;
57-
struct a4979_data *data = dev->data;
5856
bool has_enable_pin = config->en_pin.port != NULL;
5957

6058
/* Check availability of enable pin, as it might be hardwired. */
@@ -69,16 +67,13 @@ static int a4979_stepper_enable(const struct device *dev)
6967
return ret;
7068
}
7169

72-
data->enabled = true;
73-
7470
return 0;
7571
}
7672

7773
static int a4979_stepper_disable(const struct device *dev)
7874
{
7975
int ret;
8076
const struct a4979_config *config = dev->config;
81-
struct a4979_data *data = dev->data;
8277
bool has_enable_pin = config->en_pin.port != NULL;
8378

8479
/* Check availability of enable pin, as it might be hardwired. */
@@ -93,9 +88,6 @@ static int a4979_stepper_disable(const struct device *dev)
9388
return ret;
9489
}
9590

96-
config->common.timing_source->stop(dev);
97-
data->enabled = false;
98-
9991
return 0;
10092
}
10193

@@ -153,42 +145,6 @@ static int a4979_stepper_get_micro_step_res(const struct device *dev,
153145
return 0;
154146
}
155147

156-
static int a4979_move_to(const struct device *dev, int32_t target)
157-
{
158-
struct a4979_data *data = dev->data;
159-
160-
if (!data->enabled) {
161-
LOG_ERR("Failed to move to target position, device is not enabled");
162-
return -ECANCELED;
163-
}
164-
165-
return step_dir_stepper_common_move_to(dev, target);
166-
}
167-
168-
static int a4979_stepper_move_by(const struct device *dev, const int32_t micro_steps)
169-
{
170-
struct a4979_data *data = dev->data;
171-
172-
if (!data->enabled) {
173-
LOG_ERR("Failed to move by delta, device is not enabled");
174-
return -ECANCELED;
175-
}
176-
177-
return step_dir_stepper_common_move_by(dev, micro_steps);
178-
}
179-
180-
static int a4979_run(const struct device *dev, enum stepper_direction direction)
181-
{
182-
struct a4979_data *data = dev->data;
183-
184-
if (!data->enabled) {
185-
LOG_ERR("Failed to run stepper, device is not enabled");
186-
return -ECANCELED;
187-
}
188-
189-
return step_dir_stepper_common_run(dev, direction);
190-
}
191-
192148
static int a4979_init(const struct device *dev)
193149
{
194150
const struct a4979_config *config = dev->config;
@@ -269,13 +225,13 @@ static int a4979_init(const struct device *dev)
269225
static DEVICE_API(stepper, a4979_stepper_api) = {
270226
.enable = a4979_stepper_enable,
271227
.disable = a4979_stepper_disable,
272-
.move_by = a4979_stepper_move_by,
273-
.move_to = a4979_move_to,
228+
.move_by = step_dir_stepper_common_move_by,
229+
.move_to = step_dir_stepper_common_move_to,
274230
.is_moving = step_dir_stepper_common_is_moving,
275231
.set_reference_position = step_dir_stepper_common_set_reference_position,
276232
.get_actual_position = step_dir_stepper_common_get_actual_position,
277233
.set_microstep_interval = step_dir_stepper_common_set_microstep_interval,
278-
.run = a4979_run,
234+
.run = step_dir_stepper_common_run,
279235
.stop = step_dir_stepper_common_stop,
280236
.set_micro_step_res = a4979_stepper_set_micro_step_res,
281237
.get_micro_step_res = a4979_stepper_get_micro_step_res,

drivers/stepper/gpio_stepper_controller.c

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static const uint8_t
2424
{0u, 0u, 1u, 1u}, {0u, 0u, 0u, 1u}, {1u, 0u, 0u, 1u}, {1u, 0u, 0u, 0u}};
2525

2626
struct gpio_stepper_config {
27+
const struct gpio_dt_spec en_pin;
2728
const struct gpio_dt_spec *control_pins;
2829
bool invert_direction;
2930
};
@@ -39,7 +40,6 @@ struct gpio_stepper_data {
3940
int32_t actual_position;
4041
uint64_t delay_in_ns;
4142
int32_t step_count;
42-
bool is_enabled;
4343
stepper_event_callback_t callback;
4444
void *event_cb_user_data;
4545
};
@@ -183,11 +183,6 @@ static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps)
183183
{
184184
struct gpio_stepper_data *data = dev->data;
185185

186-
if (!data->is_enabled) {
187-
LOG_ERR("Stepper motor is not enabled");
188-
return -ECANCELED;
189-
}
190-
191186
if (data->delay_in_ns == 0) {
192187
LOG_ERR("Step interval not set or invalid step interval set");
193188
return -EINVAL;
@@ -262,11 +257,6 @@ static int gpio_stepper_run(const struct device *dev, const enum stepper_directi
262257
{
263258
struct gpio_stepper_data *data = dev->data;
264259

265-
if (!data->is_enabled) {
266-
LOG_ERR("Stepper motor is not enabled");
267-
return -ECANCELED;
268-
}
269-
270260
K_SPINLOCK(&data->lock) {
271261
data->run_mode = STEPPER_RUN_MODE_VELOCITY;
272262
data->direction = direction;
@@ -317,33 +307,35 @@ static int gpio_stepper_set_event_callback(const struct device *dev,
317307

318308
static int gpio_stepper_enable(const struct device *dev)
319309
{
310+
const struct gpio_stepper_config *config = dev->config;
320311
struct gpio_stepper_data *data = dev->data;
321312
int err;
322313

323-
if (data->is_enabled) {
324-
LOG_WRN("Stepper motor is already enabled");
325-
return 0;
326-
}
327-
328314
K_SPINLOCK(&data->lock) {
329-
err = energize_coils(dev, true);
330-
if (err == 0) {
331-
data->is_enabled = true;
315+
if (config->en_pin.port != NULL) {
316+
err = gpio_pin_set_dt(&config->en_pin, 1);
317+
} else {
318+
LOG_DBG("No en_pin detected");
319+
err = -ENOTSUP;
332320
}
333321
}
334322
return err;
335323
}
336324

337325
static int gpio_stepper_disable(const struct device *dev)
338326
{
327+
const struct gpio_stepper_config *config = dev->config;
339328
struct gpio_stepper_data *data = dev->data;
340329
int err;
341330

342331
K_SPINLOCK(&data->lock) {
343-
(void)k_work_cancel_delayable(&data->stepper_dwork);
344-
err = energize_coils(dev, false);
345-
if (err == 0) {
346-
data->is_enabled = false;
332+
(void)energize_coils(dev, false);
333+
if (config->en_pin.port != NULL) {
334+
err = gpio_pin_set_dt(&config->en_pin, 0);
335+
} else {
336+
LOG_DBG("No en_pin detected, power stages will not be turned off if "
337+
"stepper is in motion");
338+
err = -ENOTSUP;
347339
}
348340
}
349341
return err;

drivers/stepper/ti/drv84xx.c

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct drv84xx_pin_states {
4949
struct drv84xx_data {
5050
const struct step_dir_stepper_common_data common;
5151
const struct device *dev;
52-
bool enabled;
5352
struct drv84xx_pin_states pin_states;
5453
enum stepper_micro_step_resolution ustep_res;
5554
struct gpio_callback fault_cb_data;
@@ -220,8 +219,6 @@ static int drv84xx_enable(const struct device *dev)
220219
}
221220
}
222221

223-
data->enabled = true;
224-
225222
return ret;
226223
}
227224

@@ -255,10 +252,6 @@ static int drv84xx_disable(const struct device *dev)
255252
}
256253
}
257254

258-
config->common.timing_source->stop(dev);
259-
260-
data->enabled = false;
261-
262255
return ret;
263256
}
264257

@@ -351,42 +344,6 @@ static int drv84xx_get_micro_step_res(const struct device *dev,
351344
return 0;
352345
}
353346

354-
static int drv84xx_move_to(const struct device *dev, int32_t target)
355-
{
356-
struct drv84xx_data *data = dev->data;
357-
358-
if (!data->enabled) {
359-
LOG_ERR("Failed to move to target position, device is not enabled");
360-
return -ECANCELED;
361-
}
362-
363-
return step_dir_stepper_common_move_to(dev, target);
364-
}
365-
366-
static int drv84xx_move_by(const struct device *dev, int32_t steps)
367-
{
368-
struct drv84xx_data *data = dev->data;
369-
370-
if (!data->enabled) {
371-
LOG_ERR("Failed to move by delta, device is not enabled");
372-
return -ECANCELED;
373-
}
374-
375-
return step_dir_stepper_common_move_by(dev, steps);
376-
}
377-
378-
static int drv84xx_run(const struct device *dev, enum stepper_direction direction)
379-
{
380-
struct drv84xx_data *data = dev->data;
381-
382-
if (!data->enabled) {
383-
LOG_ERR("Failed to run stepper, device is not enabled");
384-
return -ECANCELED;
385-
}
386-
387-
return step_dir_stepper_common_run(dev, direction);
388-
}
389-
390347
void fault_event(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
391348
{
392349
struct drv84xx_data *data = CONTAINER_OF(cb, struct drv84xx_data, fault_cb_data);
@@ -478,13 +435,13 @@ static int drv84xx_init(const struct device *dev)
478435
static DEVICE_API(stepper, drv84xx_stepper_api) = {
479436
.enable = drv84xx_enable,
480437
.disable = drv84xx_disable,
481-
.move_by = drv84xx_move_by,
482-
.move_to = drv84xx_move_to,
438+
.move_by = step_dir_stepper_common_move_by,
439+
.move_to = step_dir_stepper_common_move_to,
483440
.is_moving = step_dir_stepper_common_is_moving,
484441
.set_reference_position = step_dir_stepper_common_set_reference_position,
485442
.get_actual_position = step_dir_stepper_common_get_actual_position,
486443
.set_microstep_interval = step_dir_stepper_common_set_microstep_interval,
487-
.run = drv84xx_run,
444+
.run = step_dir_stepper_common_run,
488445
.stop = step_dir_stepper_common_stop,
489446
.set_micro_step_res = drv84xx_set_micro_step_res,
490447
.get_micro_step_res = drv84xx_get_micro_step_res,

include/zephyr/drivers/stepper.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ static inline int z_impl_stepper_enable(const struct device *dev)
262262
*
263263
* @param dev pointer to the stepper driver instance
264264
*
265+
* @retval -ENOTSUP Disabling of driver is not supported.
265266
* @retval -EIO Error during Disabling
266267
* @retval 0 Success
267268
*/
@@ -436,7 +437,6 @@ static inline int z_impl_stepper_set_microstep_interval(const struct device *dev
436437
* @param dev pointer to the stepper driver instance
437438
* @param micro_steps target micro-steps to be moved from the current position
438439
*
439-
* @retval -ECANCELED If the stepper is disabled
440440
* @retval -EIO General input / output error
441441
* @retval 0 Success
442442
*/
@@ -458,7 +458,6 @@ static inline int z_impl_stepper_move_by(const struct device *dev, const int32_t
458458
* @param dev pointer to the stepper driver instance
459459
* @param micro_steps target position to set in micro-steps
460460
*
461-
* @retval -ECANCELED If the stepper is disabled
462461
* @retval -EIO General input / output error
463462
* @retval -ENOSYS If not implemented by device driver
464463
* @retval 0 Success
@@ -485,7 +484,6 @@ static inline int z_impl_stepper_move_to(const struct device *dev, const int32_t
485484
* @param dev pointer to the stepper driver instance
486485
* @param direction The direction to set
487486
*
488-
* @retval -ECANCELED If the stepper is disabled
489487
* @retval -EIO General input / output error
490488
* @retval -ENOSYS If not implemented by device driver
491489
* @retval 0 Success

0 commit comments

Comments
 (0)