Skip to content

Commit e41a6df

Browse files
committed
drivers: stepper: introduce step_dir api
introduce step_dir api which is to be implemented by the step_dir stepper drivers Add fault handling in drv84xx using a fault cb mechanism With the introduction of the step-dir api,different motion controllers to consume various step-dir drivers allowing for further upstream as well as downstream stepper motion controllers to be implemented Signed-off-by: Jilay Pandya <[email protected]>
1 parent 4cae466 commit e41a6df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1256
-1023
lines changed

drivers/stepper/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/stepper.h)
77
add_subdirectory_ifdef(CONFIG_STEPPER_ADI_TMC adi_tmc)
88
add_subdirectory_ifdef(CONFIG_STEPPER_ALLEGRO allegro)
99
add_subdirectory_ifdef(CONFIG_STEPPER_TI ti)
10+
# zephyr-keep-sorted-stop
11+
12+
# zephyr-keep-sorted-start
13+
add_subdirectory_ifdef(CONFIG_STEPPER_TIMING_SOURCES stepper_timing_sources)
1014
add_subdirectory_ifdef(CONFIG_STEP_DIR_STEPPER step_dir)
1115
# zephyr-keep-sorted-stop
1216

1317
zephyr_library()
1418
zephyr_library_property(ALLOW_EMPTY TRUE)
1519

1620
zephyr_library_sources_ifdef(CONFIG_FAKE_STEPPER fake_stepper_controller.c)
17-
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_controller.c)
21+
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_driver.c)
22+
zephyr_library_sources_ifdef(CONFIG_ZEPHYR_STEPPER_MOTION_CONTROL zephyr_stepper_motion_controller.c)
1823
zephyr_library_sources_ifdef(CONFIG_STEPPER_SHELL stepper_shell.c)

drivers/stepper/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ config STEPPER_SHELL
2727
comment "Stepper Driver Common"
2828

2929
rsource "step_dir/Kconfig"
30+
rsource "stepper_timing_sources/Kconfig"
3031

3132
comment "Stepper Drivers"
3233

3334
# zephyr-keep-sorted-start
3435
rsource "Kconfig.fake"
3536
rsource "Kconfig.gpio"
37+
rsource "Kconfig.zephyr_stepper_motion_controller"
38+
# zephyr-keep-sorted-stop
39+
40+
# zephyr-keep-sorted-start
3641
rsource "adi_tmc/Kconfig"
3742
rsource "allegro/Kconfig"
3843
rsource "ti/Kconfig"

drivers/stepper/Kconfig.gpio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
config GPIO_STEPPER
66
bool "Activate driver for gpio stepper control"
77
depends on DT_HAS_ZEPHYR_GPIO_STEPPER_ENABLED
8+
select STEP_DIR_STEPPER
89
default y
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Copyright (c) 2024 Fabian Blatz <[email protected]>
22
# SPDX-License-Identifier: Apache-2.0
33

4-
config STEPPER_$(module)_GENERATE_ISR_SAFE_EVENTS
4+
config $(module)_GENERATE_ISR_SAFE_EVENTS
55
bool "$(module-str) guarantee non ISR callbacks upon stepper events"
66
help
77
Enable the dispatch of stepper generated events via
88
a message queue to guarantee that the event handler
99
code is not run inside of an ISR. Can be disabled, but
1010
then registered stepper event callback must be ISR safe.
1111

12-
config STEPPER_$(module)_EVENT_QUEUE_LEN
12+
config $(module)_EVENT_QUEUE_LEN
1313
int "$(module-str) maximum number of pending stepper events"
1414
default 4
15-
depends on STEPPER_$(module)_GENERATE_ISR_SAFE_EVENTS
15+
depends on $(module)_GENERATE_ISR_SAFE_EVENTS
1616
help
1717
The maximum number of stepper events that can be pending before new events
1818
are dropped.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Jilay Sandeep Pandya
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ZEPHYR_STEPPER_MOTION_CONTROL
5+
bool "Zephyr CPU based Stepper motion control"
6+
depends on DT_HAS_ZEPHYR_STEPPER_MOTION_CONTROL_ENABLED
7+
select STEPPER_TIMING_SOURCES
8+
default y
9+
10+
11+
module = ZEPHYR_STEPPER_MOTION_CONTROL
12+
module-str = zephyr_stepper_motion_control
13+
14+
rsource "Kconfig.stepper_event_template"

drivers/stepper/adi_tmc/tmc22xx.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ struct tmc22xx_config {
1919
};
2020

2121
struct tmc22xx_data {
22-
struct step_dir_stepper_common_data common;
2322
enum stepper_micro_step_resolution resolution;
2423
};
2524

26-
STEP_DIR_STEPPER_STRUCT_CHECK(struct tmc22xx_config, struct tmc22xx_data);
25+
STEP_DIR_STEPPER_STRUCT_CHECK(struct tmc22xx_config);
2726

2827
static int tmc22xx_stepper_enable(const struct device *dev)
2928
{
@@ -147,18 +146,11 @@ static int tmc22xx_stepper_init(const struct device *dev)
147146
return 0;
148147
}
149148

150-
static DEVICE_API(stepper, tmc22xx_stepper_api) = {
149+
static DEVICE_API(step_dir, tmc22xx_stepper_api) = {
151150
.enable = tmc22xx_stepper_enable,
152151
.disable = tmc22xx_stepper_disable,
153-
.move_by = step_dir_stepper_common_move_by,
154-
.is_moving = step_dir_stepper_common_is_moving,
155-
.set_reference_position = step_dir_stepper_common_set_reference_position,
156-
.get_actual_position = step_dir_stepper_common_get_actual_position,
157-
.move_to = step_dir_stepper_common_move_to,
158-
.set_microstep_interval = step_dir_stepper_common_set_microstep_interval,
159-
.run = step_dir_stepper_common_run,
160-
.stop = step_dir_stepper_common_stop,
161-
.set_event_callback = step_dir_stepper_common_set_event_callback,
152+
.step = step_dir_stepper_common_step,
153+
.set_direction = step_dir_stepper_common_set_direction,
162154
.set_micro_step_res = tmc22xx_stepper_set_micro_step_res,
163155
.get_micro_step_res = tmc22xx_stepper_get_micro_step_res,
164156
};
@@ -183,7 +175,6 @@ static DEVICE_API(stepper, tmc22xx_stepper_api) = {
183175
(.msx_pins = tmc22xx_stepper_msx_pins_##inst)) \
184176
}; \
185177
static struct tmc22xx_data tmc22xx_data_##inst = { \
186-
.common = STEP_DIR_STEPPER_DT_INST_COMMON_DATA_INIT(inst), \
187178
.resolution = DT_INST_PROP(inst, micro_step_res), \
188179
}; \
189180
DEVICE_DT_INST_DEFINE(inst, tmc22xx_stepper_init, NULL, &tmc22xx_data_##inst, \

drivers/stepper/allegro/a4979.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ struct a4979_config {
2222
};
2323

2424
struct a4979_data {
25-
const struct step_dir_stepper_common_data common;
2625
enum stepper_micro_step_resolution micro_step_res;
2726
};
2827

29-
STEP_DIR_STEPPER_STRUCT_CHECK(struct a4979_config, struct a4979_data);
28+
STEP_DIR_STEPPER_STRUCT_CHECK(struct a4979_config);
3029

3130
static int a4979_set_microstep_pin(const struct device *dev, const struct gpio_dt_spec *pin,
3231
int value)
@@ -222,20 +221,13 @@ static int a4979_init(const struct device *dev)
222221
return 0;
223222
}
224223

225-
static DEVICE_API(stepper, a4979_stepper_api) = {
224+
static DEVICE_API(step_dir, a4979_stepper_api) = {
226225
.enable = a4979_stepper_enable,
227226
.disable = a4979_stepper_disable,
228-
.move_by = step_dir_stepper_common_move_by,
229-
.move_to = step_dir_stepper_common_move_to,
230-
.is_moving = step_dir_stepper_common_is_moving,
231-
.set_reference_position = step_dir_stepper_common_set_reference_position,
232-
.get_actual_position = step_dir_stepper_common_get_actual_position,
233-
.set_microstep_interval = step_dir_stepper_common_set_microstep_interval,
234-
.run = step_dir_stepper_common_run,
235-
.stop = step_dir_stepper_common_stop,
236227
.set_micro_step_res = a4979_stepper_set_micro_step_res,
237228
.get_micro_step_res = a4979_stepper_get_micro_step_res,
238-
.set_event_callback = step_dir_stepper_common_set_event_callback,
229+
.step = step_dir_stepper_common_step,
230+
.set_direction = step_dir_stepper_common_set_direction,
239231
};
240232

241233
#define A4979_DEVICE(inst) \
@@ -249,7 +241,6 @@ static DEVICE_API(stepper, a4979_stepper_api) = {
249241
}; \
250242
\
251243
static struct a4979_data a4979_data_##inst = { \
252-
.common = STEP_DIR_STEPPER_DT_INST_COMMON_DATA_INIT(inst), \
253244
.micro_step_res = DT_INST_PROP(inst, micro_step_res), \
254245
}; \
255246
\

0 commit comments

Comments
 (0)