@@ -17,8 +17,7 @@ struct a4979_config {
17
17
const struct step_dir_stepper_common_config common ;
18
18
const struct gpio_dt_spec en_pin ;
19
19
const struct gpio_dt_spec reset_pin ;
20
- const struct gpio_dt_spec m0_pin ;
21
- const struct gpio_dt_spec m1_pin ;
20
+ const struct gpio_dt_spec * msx_pins ;
22
21
};
23
22
24
23
struct a4979_data {
@@ -130,11 +129,11 @@ static int a4979_stepper_set_micro_step_res(const struct device *dev,
130
129
return - ENOTSUP ;
131
130
}
132
131
133
- ret = a4979_set_microstep_pin (dev , & config -> m0_pin , m0_value );
132
+ ret = a4979_set_microstep_pin (dev , & config -> msx_pins [ 0 ] , m0_value );
134
133
if (ret != 0 ) {
135
134
return ret ;
136
135
}
137
- ret = a4979_set_microstep_pin (dev , & config -> m1_pin , m1_value );
136
+ ret = a4979_set_microstep_pin (dev , & config -> msx_pins [ 1 ] , m1_value );
138
137
if (ret != 0 ) {
139
138
return ret ;
140
139
}
@@ -228,22 +227,22 @@ static int a4979_init(const struct device *dev)
228
227
}
229
228
230
229
/* Configure microstep pin 0 */
231
- if (!gpio_is_ready_dt (& config -> m0_pin )) {
230
+ if (!gpio_is_ready_dt (& config -> msx_pins [ 0 ] )) {
232
231
LOG_ERR ("m0 Pin is not ready" );
233
232
return - ENODEV ;
234
233
}
235
- ret = gpio_pin_configure_dt (& config -> m0_pin , GPIO_OUTPUT_INACTIVE );
234
+ ret = gpio_pin_configure_dt (& config -> msx_pins [ 0 ] , GPIO_OUTPUT_INACTIVE );
236
235
if (ret != 0 ) {
237
236
LOG_ERR ("%s: Failed to configure m0_pin (error: %d)" , dev -> name , ret );
238
237
return ret ;
239
238
}
240
239
241
240
/* Configure microstep pin 1 */
242
- if (!gpio_is_ready_dt (& config -> m1_pin )) {
241
+ if (!gpio_is_ready_dt (& config -> msx_pins [ 1 ] )) {
243
242
LOG_ERR ("m1 Pin is not ready" );
244
243
return - ENODEV ;
245
244
}
246
- ret = gpio_pin_configure_dt (& config -> m1_pin , GPIO_OUTPUT_INACTIVE );
245
+ ret = gpio_pin_configure_dt (& config -> msx_pins [ 1 ] , GPIO_OUTPUT_INACTIVE );
247
246
if (ret != 0 ) {
248
247
LOG_ERR ("%s: Failed to configure m1_pin (error: %d)" , dev -> name , ret );
249
248
return ret ;
@@ -282,13 +281,18 @@ static DEVICE_API(stepper, a4979_stepper_api) = {
282
281
};
283
282
284
283
#define A4979_DEVICE (inst ) \
285
- \
284
+ IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, msx_gpios), ( \
285
+ static const struct gpio_dt_spec a4979_stepper_msx_pins_##inst[] = { \
286
+ DT_INST_FOREACH_PROP_ELEM_SEP( \
287
+ inst, msx_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,) \
288
+ ), \
289
+ }; \
286
290
static const struct a4979_config a4979_config_##inst = { \
287
291
.common = STEP_DIR_STEPPER_DT_INST_COMMON_CONFIG_INIT(inst), \
288
292
.en_pin = GPIO_DT_SPEC_INST_GET_OR(inst, en_gpios, {0}), \
289
293
.reset_pin = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
290
- .m0_pin = GPIO_DT_SPEC_INST_GET( inst, m0_gpios), \
291
- .m1_pin = GPIO_DT_SPEC_INST_GET( inst, m1_gpios), \
294
+ IF_ENABLED(DT_INST_NODE_HAS_PROP( inst, msx_gpios), \
295
+ (.msx_pins = a4979_stepper_msx_pins_## inst)) \
292
296
}; \
293
297
\
294
298
static struct a4979_data a4979_data_##inst = { \
0 commit comments