@@ -39,6 +39,7 @@ struct gpio_stepper_data {
39
39
int32_t actual_position ;
40
40
uint32_t delay_in_us ;
41
41
int32_t step_count ;
42
+ bool is_enabled ;
42
43
stepper_event_callback_t callback ;
43
44
void * event_cb_user_data ;
44
45
};
@@ -181,6 +182,11 @@ static int gpio_stepper_move_by(const struct device *dev, int32_t micro_steps)
181
182
{
182
183
struct gpio_stepper_data * data = dev -> data ;
183
184
185
+ if (!data -> is_enabled ) {
186
+ LOG_ERR ("Stepper motor is not enabled" );
187
+ return - ECANCELED ;
188
+ }
189
+
184
190
if (data -> delay_in_us == 0 ) {
185
191
LOG_ERR ("Velocity not set or invalid velocity set" );
186
192
return - EINVAL ;
@@ -218,6 +224,11 @@ static int gpio_stepper_move_to(const struct device *dev, int32_t micro_steps)
218
224
{
219
225
struct gpio_stepper_data * data = dev -> data ;
220
226
227
+ if (!data -> is_enabled ) {
228
+ LOG_ERR ("Stepper motor is not enabled" );
229
+ return - ECANCELED ;
230
+ }
231
+
221
232
if (data -> delay_in_us == 0 ) {
222
233
LOG_ERR ("Velocity not set or invalid velocity set" );
223
234
return - EINVAL ;
@@ -266,6 +277,11 @@ static int gpio_stepper_run(const struct device *dev, const enum stepper_directi
266
277
{
267
278
struct gpio_stepper_data * data = dev -> data ;
268
279
280
+ if (!data -> is_enabled ) {
281
+ LOG_ERR ("Stepper motor is not enabled" );
282
+ return - ECANCELED ;
283
+ }
284
+
269
285
K_SPINLOCK (& data -> lock ) {
270
286
data -> run_mode = STEPPER_RUN_MODE_VELOCITY ;
271
287
data -> direction = direction ;
@@ -323,6 +339,9 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
323
339
struct gpio_stepper_data * data = dev -> data ;
324
340
325
341
K_SPINLOCK (& data -> lock ) {
342
+
343
+ data -> is_enabled = enable ;
344
+
326
345
if (enable ) {
327
346
(void )k_work_reschedule (& data -> stepper_dwork , K_NO_WAIT );
328
347
} else {
0 commit comments