@@ -30,8 +30,6 @@ struct drv84xx_config {
30
30
struct step_dir_stepper_common_config common ;
31
31
struct gpio_dt_spec sleep_pin ;
32
32
struct gpio_dt_spec en_pin ;
33
- struct gpio_dt_spec m0_pin ;
34
- struct gpio_dt_spec m1_pin ;
35
33
struct gpio_dt_spec fault_pin ;
36
34
};
37
35
@@ -106,14 +104,14 @@ int drv84xx_microstep_recovery(const struct device *dev)
106
104
uint8_t m0_value = data -> pin_states .m0 ;
107
105
uint8_t m1_value = data -> pin_states .m1 ;
108
106
109
- ret = drv84xx_set_microstep_pin (dev , & config -> m0_pin , m0_value );
107
+ ret = drv84xx_set_microstep_pin (dev , & config -> common . msx_pins [ 0 ] , m0_value );
110
108
if (ret != 0 ) {
111
109
LOG_ERR ("%s: Failed to restore microstep configuration (error: %d)" , dev -> name ,
112
110
ret );
113
111
return ret ;
114
112
}
115
113
116
- ret = drv84xx_set_microstep_pin (dev , & config -> m1_pin , m1_value );
114
+ ret = drv84xx_set_microstep_pin (dev , & config -> common . msx_pins [ 1 ] , m1_value );
117
115
if (ret != 0 ) {
118
116
LOG_ERR ("%s: Failed to restore microstep configuration (error: %d)" , dev -> name ,
119
117
ret );
@@ -272,7 +270,7 @@ static int drv84xx_set_micro_step_res(const struct device *dev,
272
270
uint8_t m0_value = 0 ;
273
271
uint8_t m1_value = 0 ;
274
272
275
- if ((config -> m0_pin . port == NULL ) || (config -> m1_pin .port == NULL )) {
273
+ if ((config -> common . msx_pins [ 0 ]. port == NULL ) || (config -> common . msx_pins [ 1 ] .port == NULL )) {
276
274
277
275
LOG_ERR ("%s: Failed to set microstep resolution: microstep pins are not defined "
278
276
"(error: %d)" ,
@@ -326,12 +324,12 @@ static int drv84xx_set_micro_step_res(const struct device *dev,
326
324
return - ENOTSUP ;
327
325
};
328
326
329
- ret = drv84xx_set_microstep_pin (dev , & config -> m0_pin , m0_value );
327
+ ret = drv84xx_set_microstep_pin (dev , & config -> common . msx_pins [ 0 ] , m0_value );
330
328
if (ret != 0 ) {
331
329
return ret ;
332
330
}
333
331
334
- ret = drv84xx_set_microstep_pin (dev , & config -> m1_pin , m1_value );
332
+ ret = drv84xx_set_microstep_pin (dev , & config -> common . msx_pins [ 1 ] , m1_value );
335
333
if (ret != 0 ) {
336
334
return ret ;
337
335
}
@@ -421,8 +419,8 @@ static int drv84xx_init(const struct device *dev)
421
419
}
422
420
423
421
/* Configure microstep pin 0 if it is available */
424
- if (config -> m0_pin .port != NULL ) {
425
- ret = gpio_pin_configure_dt (& config -> m0_pin , GPIO_OUTPUT_INACTIVE );
422
+ if (config -> common . msx_pins [ 0 ] .port != NULL ) {
423
+ ret = gpio_pin_configure_dt (& config -> common . msx_pins [ 0 ] , GPIO_OUTPUT_INACTIVE );
426
424
if (ret != 0 ) {
427
425
LOG_ERR ("%s: Failed to configure m0_pin (error: %d)" , dev -> name , ret );
428
426
return ret ;
@@ -431,16 +429,16 @@ static int drv84xx_init(const struct device *dev)
431
429
}
432
430
433
431
/* Configure microstep pin 1 if it is available */
434
- if (config -> m1_pin .port != NULL ) {
435
- ret = gpio_pin_configure_dt (& config -> m1_pin , GPIO_OUTPUT_INACTIVE );
432
+ if (config -> common . msx_pins [ 1 ] .port != NULL ) {
433
+ ret = gpio_pin_configure_dt (& config -> common . msx_pins [ 1 ] , GPIO_OUTPUT_INACTIVE );
436
434
if (ret != 0 ) {
437
435
LOG_ERR ("%s: Failed to configure m1_pin (error: %d)" , dev -> name , ret );
438
436
return ret ;
439
437
}
440
438
data -> pin_states .m1 = 0U ;
441
439
}
442
440
443
- if ((config -> m0_pin . port != NULL ) && (config -> m1_pin .port != NULL )) {
441
+ if ((config -> common . msx_pins [ 0 ]. port != NULL ) && (config -> common . msx_pins [ 1 ] .port != NULL )) {
444
442
ret = drv84xx_set_micro_step_res (dev , data -> ustep_res );
445
443
if (ret != 0 ) {
446
444
return ret ;
@@ -492,13 +490,21 @@ static DEVICE_API(stepper, drv84xx_stepper_api) = {
492
490
};
493
491
494
492
#define DRV84XX_DEVICE (inst ) \
495
- \
496
- static const struct drv84xx_config drv84xx_config_##inst = { \
497
- .common = STEP_DIR_STEPPER_DT_INST_COMMON_CONFIG_INIT(inst), \
493
+ IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, msx_gpios), ( \
494
+ static const struct gpio_dt_spec drv84xx_stepper_msx_pins_##inst[] = { \
495
+ DT_INST_FOREACH_PROP_ELEM_SEP( \
496
+ inst, msx_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,) \
497
+ ), \
498
+ }; \
499
+ BUILD_ASSERT( \
500
+ ARRAY_SIZE(drv84xx_stepper_msx_pins_##inst) == 2, \
501
+ "Two microstep config pins needed"); \
502
+ )) \
503
+ static const struct drv84xx_config drv84xx_config_##inst = { \
504
+ .common = STEP_DIR_STEPPER_DT_INST_COMMON_CONFIG_INIT( \
505
+ inst, drv84xx_stepper_msx_pins_##inst), \
498
506
.sleep_pin = GPIO_DT_SPEC_INST_GET_OR(inst, sleep_gpios, {0}), \
499
507
.en_pin = GPIO_DT_SPEC_INST_GET_OR(inst, en_gpios, {0}), \
500
- .m0_pin = GPIO_DT_SPEC_INST_GET_OR(inst, m0_gpios, {0}), \
501
- .m1_pin = GPIO_DT_SPEC_INST_GET_OR(inst, m1_gpios, {0}), \
502
508
.fault_pin = GPIO_DT_SPEC_INST_GET_OR(inst, fault_gpios, {0}), \
503
509
}; \
504
510
\
0 commit comments