Skip to content

Commit 2382d23

Browse files
jilaypandyakartben
authored andcommitted
drivers: stepper: gpio: return -ECANCELED from move operations
return -ECANCELED when move operations are called with stepper not enabled Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
1 parent 24914d7 commit 2382d23

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

drivers/stepper/gpio_stepper_controller.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct gpio_stepper_data {
3939
int32_t actual_position;
4040
uint32_t delay_in_us;
4141
int32_t step_count;
42+
bool is_enabled;
4243
stepper_event_callback_t callback;
4344
void *event_cb_user_data;
4445
};
@@ -181,6 +182,11 @@ static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps)
181182
{
182183
struct gpio_stepper_data *data = dev->data;
183184

185+
if (!data->is_enabled) {
186+
LOG_ERR("Stepper motor is not enabled");
187+
return -ECANCELED;
188+
}
189+
184190
if (data->delay_in_us == 0) {
185191
LOG_ERR("Velocity not set or invalid velocity set");
186192
return -EINVAL;
@@ -218,6 +224,11 @@ static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps)
218224
{
219225
struct gpio_stepper_data *data = dev->data;
220226

227+
if (!data->is_enabled) {
228+
LOG_ERR("Stepper motor is not enabled");
229+
return -ECANCELED;
230+
}
231+
221232
if (data->delay_in_us == 0) {
222233
LOG_ERR("Velocity not set or invalid velocity set");
223234
return -EINVAL;
@@ -266,6 +277,11 @@ static int gpio_stepper_run(const struct device *dev, const enum stepper_directi
266277
{
267278
struct gpio_stepper_data *data = dev->data;
268279

280+
if (!data->is_enabled) {
281+
LOG_ERR("Stepper motor is not enabled");
282+
return -ECANCELED;
283+
}
284+
269285
K_SPINLOCK(&data->lock) {
270286
data->run_mode = STEPPER_RUN_MODE_VELOCITY;
271287
data->direction = direction;
@@ -323,6 +339,9 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
323339
struct gpio_stepper_data *data = dev->data;
324340

325341
K_SPINLOCK(&data->lock) {
342+
343+
data->is_enabled = enable;
344+
326345
if (enable) {
327346
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
328347
} else {

0 commit comments

Comments
 (0)