Skip to content

Commit df3b76b

Browse files
jilaypandyanashif
authored andcommitted
drivers: stepper: gpio: introduce power down coils function
power down coils when gpio stepper is disabled Signed-off-by: Jilay Pandya <[email protected]>
1 parent 9e7d182 commit df3b76b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/stepper/gpio_stepper_controller.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ static void decrement_coil_charge(const struct device *dev)
7777
}
7878
}
7979

80+
static int power_down_coils(const struct device *dev)
81+
{
82+
const struct gpio_stepper_config *config = dev->config;
83+
84+
for (int i = 0; i < NUM_CONTROL_PINS; i++) {
85+
const int err = gpio_pin_set_dt(&config->control_pins[i], 0u);
86+
87+
if (err != 0) {
88+
LOG_ERR("Failed to power down coil %d", i);
89+
return err;
90+
}
91+
}
92+
return 0;
93+
}
94+
8095
static void update_coil_charge(const struct device *dev)
8196
{
8297
const struct gpio_stepper_config *config = dev->config;
@@ -313,6 +328,11 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
313328
(void)k_work_reschedule(&data->stepper_dwork, K_NO_WAIT);
314329
} else {
315330
(void)k_work_cancel_delayable(&data->stepper_dwork);
331+
const int err = power_down_coils(dev);
332+
333+
if (err != 0) {
334+
return -EIO;
335+
}
316336
}
317337
}
318338
return 0;

0 commit comments

Comments
 (0)