Skip to content

Commit 703d030

Browse files
committed
drivers: stepper: api: introduce step-dir functions
With the introduction of these two functions, now motion controllers can be directly implemented on the device driver level. This allows different motion controllers to consume various stepper drivers allowing for further upstream as well as downstream stepper motion controllers to be implemented Signed-off-by: Jilay Pandya <[email protected]>
1 parent e92468c commit 703d030

Some content is hidden

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

55 files changed

+1024
-1996
lines changed

drivers/stepper/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ 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)
1010
add_subdirectory_ifdef(CONFIG_STEP_DIR_STEPPER step_dir)
11+
add_subdirectory_ifdef(CONFIG_ZEPHYR_STEPPER_MOTION_CONTROL stepper_motion_controllers)
1112
# zephyr-keep-sorted-stop
1213

1314
zephyr_library()
1415
zephyr_library_property(ALLOW_EMPTY TRUE)
1516

1617
zephyr_library_sources_ifdef(CONFIG_FAKE_STEPPER fake_stepper_controller.c)
17-
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_controller.c)
18+
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_driver.c)
1819
zephyr_library_sources_ifdef(CONFIG_STEPPER_SHELL stepper_shell.c)

drivers/stepper/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ config STEPPER_SHELL
2727
comment "Stepper Driver Common"
2828

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

3132
comment "Stepper Drivers"
3233

drivers/stepper/adi_tmc/tmc22xx.c

Lines changed: 3 additions & 12 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
{
@@ -150,15 +149,8 @@ static int tmc22xx_stepper_init(const struct device *dev)
150149
static DEVICE_API(stepper, 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: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ static int a4979_stepper_disable(const struct device *dev)
9393
return ret;
9494
}
9595

96-
config->common.timing_source->stop(dev);
9796
data->enabled = false;
9897

9998
return 0;
@@ -153,42 +152,6 @@ static int a4979_stepper_get_micro_step_res(const struct device *dev,
153152
return 0;
154153
}
155154

156-
static int a4979_move_to(const struct device *dev, int32_t target)
157-
{
158-
struct a4979_data *data = dev->data;
159-
160-
if (!data->enabled) {
161-
LOG_ERR("Failed to move to target position, device is not enabled");
162-
return -ECANCELED;
163-
}
164-
165-
return step_dir_stepper_common_move_to(dev, target);
166-
}
167-
168-
static int a4979_stepper_move_by(const struct device *dev, const int32_t micro_steps)
169-
{
170-
struct a4979_data *data = dev->data;
171-
172-
if (!data->enabled) {
173-
LOG_ERR("Failed to move by delta, device is not enabled");
174-
return -ECANCELED;
175-
}
176-
177-
return step_dir_stepper_common_move_by(dev, micro_steps);
178-
}
179-
180-
static int a4979_run(const struct device *dev, enum stepper_direction direction)
181-
{
182-
struct a4979_data *data = dev->data;
183-
184-
if (!data->enabled) {
185-
LOG_ERR("Failed to run stepper, device is not enabled");
186-
return -ECANCELED;
187-
}
188-
189-
return step_dir_stepper_common_run(dev, direction);
190-
}
191-
192155
static int a4979_init(const struct device *dev)
193156
{
194157
const struct a4979_config *config = dev->config;
@@ -269,17 +232,10 @@ static int a4979_init(const struct device *dev)
269232
static DEVICE_API(stepper, a4979_stepper_api) = {
270233
.enable = a4979_stepper_enable,
271234
.disable = a4979_stepper_disable,
272-
.move_by = a4979_stepper_move_by,
273-
.move_to = a4979_move_to,
274-
.is_moving = step_dir_stepper_common_is_moving,
275-
.set_reference_position = step_dir_stepper_common_set_reference_position,
276-
.get_actual_position = step_dir_stepper_common_get_actual_position,
277-
.set_microstep_interval = step_dir_stepper_common_set_microstep_interval,
278-
.run = a4979_run,
279-
.stop = step_dir_stepper_common_stop,
280235
.set_micro_step_res = a4979_stepper_set_micro_step_res,
281236
.get_micro_step_res = a4979_stepper_get_micro_step_res,
282-
.set_event_callback = step_dir_stepper_common_set_event_callback,
237+
.step = step_dir_stepper_common_step,
238+
.set_direction = step_dir_stepper_common_set_direction,
283239
};
284240

285241
#define A4979_DEVICE(inst) \

0 commit comments

Comments
 (0)