Skip to content

Commit

Permalink
drivers: stepper: gpio: return -ECANCELED from move operations
Browse files Browse the repository at this point in the history
return -ECANCELED when move operations are called with stepper not enabled

Signed-off-by: Jilay Pandya <[email protected]>
  • Loading branch information
jilaypandya committed Dec 19, 2024
1 parent 8ea11ca commit cba78df
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/stepper/gpio_stepper_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct gpio_stepper_data {
int32_t actual_position;
uint32_t delay_in_us;
int32_t step_count;
bool is_enabled;
stepper_event_callback_t callback;
void *event_cb_user_data;
};
Expand Down Expand Up @@ -181,6 +182,11 @@ static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps)
{
struct gpio_stepper_data *data = dev->data;

if (!data->is_enabled) {
LOG_ERR("Stepper motor is not enabled");
return -ECANCELED;
}

if (data->delay_in_us == 0) {
LOG_ERR("Velocity not set or invalid velocity set");
return -EINVAL;
Expand Down Expand Up @@ -218,6 +224,11 @@ static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps)
{
struct gpio_stepper_data *data = dev->data;

if (!data->is_enabled) {
LOG_ERR("Stepper motor is not enabled");
return -ECANCELED;
}

if (data->delay_in_us == 0) {
LOG_ERR("Velocity not set or invalid velocity set");
return -EINVAL;
Expand Down Expand Up @@ -266,6 +277,11 @@ static int gpio_stepper_run(const struct device *dev, const enum stepper_directi
{
struct gpio_stepper_data *data = dev->data;

if (!data->is_enabled) {
LOG_ERR("Stepper motor is not enabled");
return -ECANCELED;
}

K_SPINLOCK(&data->lock) {
data->run_mode = STEPPER_RUN_MODE_VELOCITY;
data->direction = direction;
Expand Down Expand Up @@ -323,6 +339,9 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
struct gpio_stepper_data *data = dev->data;

K_SPINLOCK(&data->lock) {

data->is_enabled = enable;

if (enable) {
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
} else {
Expand Down

0 comments on commit cba78df

Please sign in to comment.