drivers: stepper: change gpio-stepper dt-compatible

This commit changes compatible of gpio-stepper in driver

Signed-off-by: Jilay Pandya <jilay.pandya@outlook.com>
This commit is contained in:
Jilay Pandya 2024-11-05 21:05:54 +01:00 committed by Anas Nashif
commit 843625a29b
13 changed files with 73 additions and 104 deletions

View file

@ -36,6 +36,7 @@ be used in a boards devicetree to configure a stepper driver to its initial stat
See examples in: See examples in:
- :dtcompatible:`zephyr,gpio-stepper`
- :dtcompatible:`adi,tmc5041` - :dtcompatible:`adi,tmc5041`
Discord Discord

View file

@ -6,7 +6,7 @@ menu "GPIO stepper driver"
config GPIO_STEPPER config GPIO_STEPPER
bool "Activate driver for gpio stepper control" bool "Activate driver for gpio stepper control"
depends on DT_HAS_ZEPHYR_GPIO_STEPPERS_ENABLED depends on DT_HAS_ZEPHYR_GPIO_STEPPER_ENABLED
default y default y
help help
GPIO Stepper driver for stepper motor control with darlington arrays or dual H-bridge. GPIO Stepper driver for stepper motor control with darlington arrays or dual H-bridge.

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#define DT_DRV_COMPAT zephyr_gpio_steppers #define DT_DRV_COMPAT zephyr_gpio_stepper
#include <zephyr/drivers/gpio.h> #include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
@ -338,14 +338,13 @@ static int gpio_stepper_enable(const struct device *dev, bool enable)
return 0; return 0;
} }
static int gpio_stepper_motor_controller_init(const struct device *dev) static int gpio_stepper_init(const struct device *dev)
{ {
struct gpio_stepper_data *data = dev->data; struct gpio_stepper_data *data = dev->data;
const struct gpio_stepper_config *config = dev->config; const struct gpio_stepper_config *config = dev->config;
data->dev = dev; data->dev = dev;
LOG_DBG("Initializing %s gpio_stepper_motor_controller with %d pin", dev->name, LOG_DBG("Initializing %s gpio_stepper with %d pin", dev->name, NUM_CONTROL_PINS);
NUM_CONTROL_PINS);
for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) { for (uint8_t n_pin = 0; n_pin < NUM_CONTROL_PINS; n_pin++) {
(void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE); (void)gpio_pin_configure_dt(&config->control_pins[n_pin], GPIO_OUTPUT_INACTIVE);
} }
@ -353,47 +352,36 @@ static int gpio_stepper_motor_controller_init(const struct device *dev)
return 0; return 0;
} }
#define GPIO_STEPPER_DEVICE_DATA_DEFINE(child) \ static const struct stepper_driver_api gpio_stepper_api = {
static struct gpio_stepper_data gpio_stepper_data_##child = { \ .enable = gpio_stepper_enable,
.step_gap = MAX_MICRO_STEP_RES >> (DT_PROP(child, micro_step_res) - 1), \ .move = gpio_stepper_move,
}; \ .is_moving = gpio_stepper_is_moving,
BUILD_ASSERT(DT_PROP(child, micro_step_res) <= STEPPER_MICRO_STEP_2, \ .set_actual_position = gpio_stepper_set_actual_position,
"gpio_stepper_controller driver supports up to 2 micro steps"); .get_actual_position = gpio_stepper_get_actual_position,
.set_target_position = gpio_stepper_set_target_position,
.set_max_velocity = gpio_stepper_set_max_velocity,
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode,
.set_micro_step_res = gpio_stepper_set_micro_step_res,
.get_micro_step_res = gpio_stepper_get_micro_step_res,
.set_event_callback = gpio_stepper_set_event_callback,
};
#define GPIO_STEPPER_DEVICE_CONFIG_DEFINE(child) \ #define GPIO_STEPPER_DEFINE(inst) \
static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##child[] = { \ static const struct gpio_dt_spec gpio_stepper_motor_control_pins_##inst[] = { \
DT_FOREACH_PROP_ELEM_SEP(child, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \ DT_INST_FOREACH_PROP_ELEM_SEP(inst, gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)), \
}; \ }; \
BUILD_ASSERT( \ BUILD_ASSERT(ARRAY_SIZE(gpio_stepper_motor_control_pins_##inst) == 4, \
ARRAY_SIZE(gpio_stepper_motor_control_pins_##child) == 4, \
"gpio_stepper_controller driver currently supports only 4 wire configuration"); \ "gpio_stepper_controller driver currently supports only 4 wire configuration"); \
static const struct gpio_stepper_config gpio_stepper_config_##child = { \ static const struct gpio_stepper_config gpio_stepper_config_##inst = { \
.invert_direction = DT_PROP(child, invert_direction), \ .invert_direction = DT_INST_PROP(inst, invert_direction), \
.control_pins = gpio_stepper_motor_control_pins_##child}; .control_pins = gpio_stepper_motor_control_pins_##inst}; \
static struct gpio_stepper_data gpio_stepper_data_##inst = { \
.step_gap = MAX_MICRO_STEP_RES >> (DT_INST_PROP(inst, micro_step_res) - 1), \
}; \
BUILD_ASSERT(DT_INST_PROP(inst, micro_step_res) <= STEPPER_MICRO_STEP_2, \
"gpio_stepper_controller driver supports up to 2 micro steps"); \
DEVICE_DT_INST_DEFINE(inst, gpio_stepper_init, NULL, &gpio_stepper_data_##inst, \
&gpio_stepper_config_##inst, POST_KERNEL, \
CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api);
#define GPIO_STEPPER_API_DEFINE(child) \ DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_DEFINE)
static const struct stepper_driver_api gpio_stepper_api_##child = { \
.enable = gpio_stepper_enable, \
.move = gpio_stepper_move, \
.is_moving = gpio_stepper_is_moving, \
.set_actual_position = gpio_stepper_set_actual_position, \
.get_actual_position = gpio_stepper_get_actual_position, \
.set_target_position = gpio_stepper_set_target_position, \
.set_max_velocity = gpio_stepper_set_max_velocity, \
.enable_constant_velocity_mode = gpio_stepper_enable_constant_velocity_mode, \
.set_micro_step_res = gpio_stepper_set_micro_step_res, \
.get_micro_step_res = gpio_stepper_get_micro_step_res, \
.set_event_callback = gpio_stepper_set_event_callback, };
#define GPIO_STEPPER_DEVICE_DEFINE(child) \
DEVICE_DT_DEFINE(child, gpio_stepper_motor_controller_init, NULL, \
&gpio_stepper_data_##child, &gpio_stepper_config_##child, POST_KERNEL, \
CONFIG_STEPPER_INIT_PRIORITY, &gpio_stepper_api_##child);
#define GPIO_STEPPER_CONTROLLER_DEFINE(inst) \
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_CONFIG_DEFINE); \
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DATA_DEFINE); \
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_API_DEFINE); \
DT_INST_FOREACH_CHILD(inst, GPIO_STEPPER_DEVICE_DEFINE);
DT_INST_FOREACH_STATUS_OKAY(GPIO_STEPPER_CONTROLLER_DEFINE)

View file

@ -89,13 +89,10 @@ properties:
child-binding: child-binding:
include: include:
- name: stepper-controller.yaml
- name: base.yaml - name: base.yaml
property-allowlist: property-allowlist:
- reg - reg
- name: stepper-controller.yaml
property-allowlist:
- invert-direction
- micro-step-res
- name: adi,trinamic-ramp-generator.yaml - name: adi,trinamic-ramp-generator.yaml
property-allowlist: property-allowlist:
- vstart - vstart

View file

@ -3,8 +3,6 @@
description: Stepper Controller description: Stepper Controller
include: base.yaml
properties: properties:
invert-direction: invert-direction:
type: boolean type: boolean

View file

@ -3,31 +3,23 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
description: | description: |
GPIO Stepper Controller cluster for darlington transistor arrays or dual H-bridge GPIO Stepper Controller for darlington transistor arrays or dual H-bridge
Example: Example:
/* Lead A is connected Lead C and Lead B is connected to Lead D*/ /* Lead A is connected Lead C and Lead B is connected to Lead D*/
stepper { stepper: stepper {
compatible = "zephyr,gpio-steppers"; compatible = "zephyr,gpio-stepper";
motor: motor {
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>, /* Lead A1/A */ gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>, /* Lead A1/A */
<&gpioc 7 GPIO_ACTIVE_HIGH>, /* Lead B1/B */ <&gpioc 7 GPIO_ACTIVE_HIGH>, /* Lead B1/B */
<&gpiob 0 GPIO_ACTIVE_HIGH>, /* Lead A2/C */ <&gpiob 0 GPIO_ACTIVE_HIGH>, /* Lead A2/C */
<&gpioa 7 GPIO_ACTIVE_HIGH>; /* Lead B2/D */ <&gpioa 7 GPIO_ACTIVE_HIGH>; /* Lead B2/D */
}; };
};
compatible: "zephyr,gpio-steppers" compatible: "zephyr,gpio-stepper"
child-binding: include: stepper-controller.yaml
description: GPIO Controller for stepper motor
include:
- name: stepper-controller.yaml
property-allowlist:
- micro-step-res
- invert-direction
properties: properties:
gpios: gpios:
type: phandle-array type: phandle-array
required: true required: true

View file

@ -1,10 +1,8 @@
# Copyright (c) 2024 Jilay Sandeep Pandya # SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0) cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(stepper_api) project(stepper_api)
target_sources(app PRIVATE
src/main.c target_sources(app PRIVATE src/main.c)
)

View file

@ -1,4 +1,4 @@
# Copyright (c) 2024 Jilay Sandeep Pandya # SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
CONFIG_GPIO=y CONFIG_GPIO=y

View file

@ -4,15 +4,13 @@
*/ */
/ { / {
uln2003_motor: uln2003_1 {
compatible = "zephyr,gpio-steppers";
status = "okay";
motor_1: motor_1 { motor_1: motor_1 {
compatible = "zephyr,gpio-stepper";
status = "okay";
micro-step-res = <1>; micro-step-res = <1>;
gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>, gpios = <&gpioa 9 GPIO_ACTIVE_HIGH>,
<&gpioc 7 GPIO_ACTIVE_HIGH>, <&gpioc 7 GPIO_ACTIVE_HIGH>,
<&gpiob 0 GPIO_ACTIVE_HIGH>, <&gpiob 0 GPIO_ACTIVE_HIGH>,
<&gpioa 7 GPIO_ACTIVE_HIGH>; <&gpioa 7 GPIO_ACTIVE_HIGH>;
}; };
};
}; };

View file

@ -1,4 +1,4 @@
# Copyright (c) 2024 Jilay Sandeep Pandya # SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
CONFIG_GPIO=y CONFIG_GPIO=y

View file

@ -19,16 +19,13 @@
}; };
/ { / {
test_uln2003_motor_cluster: uln2003_motor_cluster {
compatible = "zephyr,gpio-steppers";
status = "okay";
motor_1: motor_1 { motor_1: motor_1 {
compatible = "zephyr,gpio-stepper";
status = "okay";
micro-step-res = <1>; micro-step-res = <1>;
gpios = <&test_gpio 0 0>, gpios = <&test_gpio 0 0>,
<&test_gpio 0 0>, <&test_gpio 0 0>,
<&test_gpio 0 0>, <&test_gpio 0 0>,
<&test_gpio 0 0>; <&test_gpio 0 0>;
}; };
};
}; };

View file

@ -1,4 +1,4 @@
# Copyright (c) 2024 Jilay Sandeep Pandya # SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
CONFIG_ZTEST=y CONFIG_ZTEST=y

View file

@ -1,4 +1,4 @@
# Copyright (c) 2024 Jilay Sandeep Pandya # SPDX-FileCopyrightText: Copyright (c) 2024 Jilay Sandeep Pandya
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
tests: tests: