Skip to content

Commit b3d88eb

Browse files
committed
drivers: stepper: unify msx-gpios
currently there are two different ways how microstepping gpios are handled in step/dir drivers. This PR aims to unify the two different approaches. Signed-off-by: Jilay Pandya <[email protected]>
1 parent f922014 commit b3d88eb

File tree

5 files changed

+28
-33
lines changed

5 files changed

+28
-33
lines changed

drivers/stepper/allegro/a4979.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ struct a4979_config {
1717
const struct step_dir_stepper_common_config common;
1818
const struct gpio_dt_spec en_pin;
1919
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;
2221
};
2322

2423
struct a4979_data {
@@ -130,11 +129,11 @@ static int a4979_stepper_set_micro_step_res(const struct device *dev,
130129
return -ENOTSUP;
131130
}
132131

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);
134133
if (ret != 0) {
135134
return ret;
136135
}
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);
138137
if (ret != 0) {
139138
return ret;
140139
}
@@ -228,22 +227,22 @@ static int a4979_init(const struct device *dev)
228227
}
229228

230229
/* Configure microstep pin 0 */
231-
if (!gpio_is_ready_dt(&config->m0_pin)) {
230+
if (!gpio_is_ready_dt(&config->msx_pins[0])) {
232231
LOG_ERR("m0 Pin is not ready");
233232
return -ENODEV;
234233
}
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);
236235
if (ret != 0) {
237236
LOG_ERR("%s: Failed to configure m0_pin (error: %d)", dev->name, ret);
238237
return ret;
239238
}
240239

241240
/* Configure microstep pin 1 */
242-
if (!gpio_is_ready_dt(&config->m1_pin)) {
241+
if (!gpio_is_ready_dt(&config->msx_pins[1])) {
243242
LOG_ERR("m1 Pin is not ready");
244243
return -ENODEV;
245244
}
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);
247246
if (ret != 0) {
248247
LOG_ERR("%s: Failed to configure m1_pin (error: %d)", dev->name, ret);
249248
return ret;
@@ -282,13 +281,18 @@ static DEVICE_API(stepper, a4979_stepper_api) = {
282281
};
283282

284283
#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+
}; \
286290
static const struct a4979_config a4979_config_##inst = { \
287291
.common = STEP_DIR_STEPPER_DT_INST_COMMON_CONFIG_INIT(inst), \
288292
.en_pin = GPIO_DT_SPEC_INST_GET_OR(inst, en_gpios, {0}), \
289293
.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)) \
292296
}; \
293297
\
294298
static struct a4979_data a4979_data_##inst = { \

dts/bindings/stepper/adi/adi,tmc2209.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ include:
2121
- name: stepper-controller.yaml
2222

2323
properties:
24-
msx-gpios:
25-
type: phandle-array
26-
description: |
27-
An array of GPIO pins for configuring the microstep resolution of the driver.
28-
The pins should be listed in the following order:
29-
- MS1
30-
- MS2
31-
3224
dual-edge-step:
3325
type: boolean
3426
description: |

dts/bindings/stepper/allegro/allegro,a4979.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ description: |
1616
dir-gpios = <&gpiod 14 GPIO_ACTIVE_HIGH>;
1717
step-gpios = <&gpiod 15 GPIO_ACTIVE_HIGH>;
1818
en-gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
19-
m0-gpios = <&gpiod 13 0>;
20-
m1-gpios = <&gpiod 12 0>;
19+
msx-gpios = <&gpiod 13 0>,
20+
<&gpiod 12 0>;
2121
counter = <&counter5>;
2222
};
2323
@@ -27,16 +27,6 @@ include:
2727
- name: stepper-controller.yaml
2828

2929
properties:
30-
m0-gpios:
31-
required: true
32-
type: phandle-array
33-
description: Microstep configuration pin 0.
34-
35-
m1-gpios:
36-
required: true
37-
type: phandle-array
38-
description: Microstep configuration pin 1.
39-
4030
reset-gpios:
4131
type: phandle-array
4232
required: true

dts/bindings/stepper/stepper-controller.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ properties:
4141
The GPIO pins used to send direction signals to the stepper motor.
4242
Pin will be driven high for forward direction and low for reverse direction.
4343
44+
msx-gpios:
45+
type: phandle-array
46+
description: |
47+
An array of GPIO pins for configuring the microstep resolution of the driver.
48+
The pins should be listed in the following order:
49+
- MS1
50+
- MS2
51+
- MS3
52+
4453
counter:
4554
type: phandle
4655
description: Counter used for generating step-accurate pulse signals.

tests/drivers/build_all/stepper/gpio.dtsi

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ allegro_a4979: allegro_a4979 {
2727
dir-gpios = <&test_gpio 0 0>;
2828
step-gpios = <&test_gpio 0 0>;
2929
en-gpios = <&test_gpio 0 0>;
30-
m0-gpios = <&test_gpio 0 0>;
31-
m1-gpios = <&test_gpio 0 0>;
30+
msx-gpios = <&test_gpio 0 0>,
31+
<&test_gpio 0 0>;
3232
counter = <&counter0>;
3333
};
3434

0 commit comments

Comments
 (0)