Skip to content

Commit 843625a

Browse files
jilaypandyanashif
authored andcommitted
drivers: stepper: change gpio-stepper dt-compatible
This commit changes compatible of gpio-stepper in driver Signed-off-by: Jilay Pandya <[email protected]>
1 parent df3b76b commit 843625a

File tree

13 files changed

+75
-106
lines changed

13 files changed

+75
-106
lines changed

doc/hardware/peripherals/stepper.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ be used in a boards devicetree to configure a stepper driver to its initial stat
3636

3737
See examples in:
3838

39+
- :dtcompatible:`zephyr,gpio-stepper`
3940
- :dtcompatible:`adi,tmc5041`
4041

4142
Discord

drivers/stepper/Kconfig.gpio

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ menu "GPIO stepper driver"
66

77
config GPIO_STEPPER
88
bool "Activate driver for gpio stepper control"
9-
depends on DT_HAS_ZEPHYR_GPIO_STEPPERS_ENABLED
9+
depends on DT_HAS_ZEPHYR_GPIO_STEPPER_ENABLED
1010
default y
1111
help
1212
GPIO Stepper driver for stepper motor control with darlington arrays or dual H-bridge.

drivers/stepper/gpio_stepper_controller.c

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#define DT_DRV_COMPAT zephyr_gpio_steppers
7+
#define DT_DRV_COMPAT zephyr_gpio_stepper
88

99
#include <zephyr/drivers/gpio.h>
1010
#include <zephyr/kernel.h>
@@ -338,62 +338,50 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
338338
return 0;
339339
}
340340

341-
static int gpio_stepper_motor_controller_init(const struct device *dev)
341+
static int gpio_stepper_init(const struct device *dev)
342342
{
343343
struct gpio_stepper_data *data = dev->data;
344344
const struct gpio_stepper_config *config = dev->config;
345345

346346
data->dev = dev;
347-
LOG_DBG("Initializing %s gpio_stepper_motor_controller with %d pin", dev->name,
348-
NUM_CONTROL_PINS);
347+
LOG_DBG("Initializing %s gpio_stepper with %d pin", dev->name, NUM_CONTROL_PINS);
349348
for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) {
350349
(void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE);
351350
}
352351
k_work_init_delayable(&data->stepper_dwork, stepper_work_step_handler);
353352
return 0;
354353
}
355354

356-
#define GPIO_STEPPER_DEVICE_DATA_DEFINE(child) \
357-
static struct gpio_stepper_data gpio_stepper_data_##child = { \
358-
.step_gap = MAX_MICRO_STEP_RES >> (DT_PROP(child, micro_step_res) - 1), \
359-
}; \
360-
BUILD_ASSERT(DT_PROP(child, micro_step_res) <= STEPPER_MICRO_STEP_2, \
361-
"gpio_stepper_controller driver supports up to 2 micro steps");
362-
363-
#define GPIO_STEPPER_DEVICE_CONFIG_DEFINE(child) \
364-
static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##child[] = { \
365-
DT_FOREACH_PROP_ELEM_SEP(child, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \
366-
}; \
367-
BUILD_ASSERT( \
368-
ARRAY_SIZE(gpio_stepper_motor_control_pins_##child) == 4, \
369-
"gpio_stepper_controller driver currently supports only 4 wire configuration"); \
370-
static const struct gpio_stepper_config gpio_stepper_config_##child = { \
371-
.invert_direction = DT_PROP(child, invert_direction), \
372-
.control_pins = gpio_stepper_motor_control_pins_##child};
373-
374-
#define GPIO_STEPPER_API_DEFINE(child) \
375-
static const struct stepper_driver_api gpio_stepper_api_##child = { \
376-
.enable = gpio_stepper_enable, \
377-
.move = gpio_stepper_move, \
378-
.is_moving = gpio_stepper_is_moving, \
379-
.set_actual_position = gpio_stepper_set_actual_position, \
380-
.get_actual_position = gpio_stepper_get_actual_position, \
381-
.set_target_position = gpio_stepper_set_target_position, \
382-
.set_max_velocity = gpio_stepper_set_max_velocity, \
383-
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode, \
384-
.set_micro_step_res = gpio_stepper_set_micro_step_res, \
385-
.get_micro_step_res = gpio_stepper_get_micro_step_res, \
386-
.set_event_callback = gpio_stepper_set_event_callback, };
387-
388-
#define GPIO_STEPPER_DEVICE_DEFINE(child) \
389-
DEVICE_DT_DEFINE(child, gpio_stepper_motor_controller_init, NULL, \
390-
&gpio_stepper_data_##child, &gpio_stepper_config_##child, POST_KERNEL, \
391-
CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api_##child);
392-
393-
#define GPIO_STEPPER_CONTROLLER_DEFINE(inst) \
394-
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_CONFIG_DEFINE); \
395-
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DATA_DEFINE); \
396-
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_API_DEFINE); \
397-
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DEFINE);
398-
399-
DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_CONTROLLER_DEFINE)
355+
static const struct stepper_driver_api gpio_stepper_api = {
356+
.enable = gpio_stepper_enable,
357+
.move = gpio_stepper_move,
358+
.is_moving = gpio_stepper_is_moving,
359+
.set_actual_position = gpio_stepper_set_actual_position,
360+
.get_actual_position = gpio_stepper_get_actual_position,
361+
.set_target_position = gpio_stepper_set_target_position,
362+
.set_max_velocity = gpio_stepper_set_max_velocity,
363+
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode,
364+
.set_micro_step_res = gpio_stepper_set_micro_step_res,
365+
.get_micro_step_res = gpio_stepper_get_micro_step_res,
366+
.set_event_callback = gpio_stepper_set_event_callback,
367+
};
368+
369+
#define GPIO_STEPPER_DEFINE(inst) \
370+
static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##inst[] = { \
371+
DT_INST_FOREACH_PROP_ELEM_SEP(inst, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \
372+
}; \
373+
BUILD_ASSERT(ARRAY_SIZE(gpio_stepper_motor_control_pins_##inst) == 4, \
374+
"gpio_stepper_controller driver currently supports only 4 wire configuration"); \
375+
static const struct gpio_stepper_config gpio_stepper_config_##inst = { \
376+
.invert_direction = DT_INST_PROP(inst, invert_direction), \
377+
.control_pins = gpio_stepper_motor_control_pins_##inst}; \
378+
static struct gpio_stepper_data gpio_stepper_data_##inst = { \
379+
.step_gap = MAX_MICRO_STEP_RES >> (DT_INST_PROP(inst, micro_step_res) - 1), \
380+
}; \
381+
BUILD_ASSERT(DT_INST_PROP(inst, micro_step_res) <= STEPPER_MICRO_STEP_2, \
382+
"gpio_stepper_controller driver supports up to 2 micro steps"); \
383+
DEVICE_DT_INST_DEFINE(inst, gpio_stepper_init, NULL, &gpio_stepper_data_##inst, \
384+
&gpio_stepper_config_##inst, POST_KERNEL, \
385+
CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api);
386+
387+
DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_DEFINE)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,10 @@ properties:
8989
9090
child-binding:
9191
include:
92+
- name: stepper-controller.yaml
9293
- name: base.yaml
9394
property-allowlist:
9495
- reg
95-
- name: stepper-controller.yaml
96-
property-allowlist:
97-
- invert-direction
98-
- micro-step-res
9996
- name: adi,trinamic-ramp-generator.yaml
10097
property-allowlist:
10198
- vstart

dts/bindings/stepper/stepper-controller.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
description: Stepper Controller
55

6-
include: base.yaml
7-
86
properties:
97
invert-direction:
108
type: boolean

dts/bindings/stepper/zephyr,gpio-stepper.yaml

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,25 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
description: |
6-
GPIO Stepper Controller cluster for darlington transistor arrays or dual H-bridge
6+
GPIO Stepper Controller for darlington transistor arrays or dual H-bridge
77
88
Example:
99
/* Lead A is connected Lead C and Lead B is connected to Lead D*/
10-
stepper {
11-
compatible = "zephyr,gpio-steppers";
12-
motor: motor {
13-
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>, /* Lead A1/A */
14-
<&gpioc 7 GPIO_ACTIVE_HIGH>, /* Lead B1/B */
15-
<&gpiob 0 GPIO_ACTIVE_HIGH>, /* Lead A2/C */
16-
<&gpioa 7 GPIO_ACTIVE_HIGH>; /* Lead B2/D */
17-
};
10+
stepper: stepper {
11+
compatible = "zephyr,gpio-stepper";
12+
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>, /* Lead A1/A */
13+
<&gpioc 7 GPIO_ACTIVE_HIGH>, /* Lead B1/B */
14+
<&gpiob 0 GPIO_ACTIVE_HIGH>, /* Lead A2/C */
15+
<&gpioa 7 GPIO_ACTIVE_HIGH>; /* Lead B2/D */
1816
};
1917
20-
compatible: "zephyr,gpio-steppers"
18+
compatible: "zephyr,gpio-stepper"
2119

22-
child-binding:
23-
description: GPIO Controller for stepper motor
24-
include:
25-
- name: stepper-controller.yaml
26-
property-allowlist:
27-
- micro-step-res
28-
- invert-direction
20+
include: stepper-controller.yaml
2921

30-
properties:
31-
gpios:
32-
type: phandle-array
33-
required: true
34-
description: |
35-
The gpio pin array on which the stepper inputs are to be connected
22+
properties:
23+
gpios:
24+
type: phandle-array
25+
required: true
26+
description: |
27+
The gpio pin array on which the stepper inputs are to be connected
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# Copyright (c) 2024 Jilay Sandeep Pandya
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
22
# SPDX-License-Identifier: Apache-2.0
33

44
cmake_minimum_required(VERSION 3.20.0)
5-
65
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
76
project(stepper_api)
8-
target_sources(app PRIVATE
9-
src/main.c
10-
)
7+
8+
target_sources(app PRIVATE src/main.c)

tests/drivers/stepper/stepper_api/boards/nucleo_g071rb.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Jilay Sandeep Pandya
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
22
# SPDX-License-Identifier: Apache-2.0
33

44
CONFIG_GPIO=y

tests/drivers/stepper/stepper_api/boards/nucleo_g071rb.overlay

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
*/
55

66
/ {
7-
uln2003_motor: uln2003_1 {
8-
compatible = "zephyr,gpio-steppers";
7+
motor_1: motor_1 {
8+
compatible = "zephyr,gpio-stepper";
99
status = "okay";
10-
motor_1: motor_1 {
11-
micro-step-res = <1>;
12-
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>,
13-
<&gpioc 7 GPIO_ACTIVE_HIGH>,
14-
<&gpiob 0 GPIO_ACTIVE_HIGH>,
15-
<&gpioa 7 GPIO_ACTIVE_HIGH>;
16-
};
10+
micro-step-res = <1>;
11+
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>,
12+
<&gpioc 7 GPIO_ACTIVE_HIGH>,
13+
<&gpiob 0 GPIO_ACTIVE_HIGH>,
14+
<&gpioa 7 GPIO_ACTIVE_HIGH>;
1715
};
1816
};

tests/drivers/stepper/stepper_api/boards/qemu_x86_64.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Jilay Sandeep Pandya
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
22
# SPDX-License-Identifier: Apache-2.0
33

44
CONFIG_GPIO=y

0 commit comments

Comments
 (0)