Skip to content

Commit 31a15da

Browse files
committed
drivers: stepper_control: stepper motion control driver
This commit integrates timing source from by refactoring it out from step_dir lib Refactor motion control related function from gpio_stepper_controller to zephyr stepper control driver Signed-off-by: Andre Stefanov <[email protected]> Signed-off-by: Jilay Pandya <[email protected]>
1 parent 20db5bd commit 31a15da

28 files changed

+875
-1055
lines changed

drivers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ add_subdirectory_ifdef(CONFIG_SERIAL serial)
8585
add_subdirectory_ifdef(CONFIG_SMBUS smbus)
8686
add_subdirectory_ifdef(CONFIG_SPI spi)
8787
add_subdirectory_ifdef(CONFIG_STEPPER stepper)
88+
add_subdirectory_ifdef(CONFIG_STEPPER_CONTROL stepper_control)
8889
add_subdirectory_ifdef(CONFIG_SYSCON syscon)
8990
add_subdirectory_ifdef(CONFIG_SYS_CLOCK_EXISTS timer)
9091
add_subdirectory_ifdef(CONFIG_TEE tee)

drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ source "drivers/sip_svc/Kconfig"
8383
source "drivers/smbus/Kconfig"
8484
source "drivers/spi/Kconfig"
8585
source "drivers/stepper/Kconfig"
86+
source "drivers/stepper_control/Kconfig"
8687
source "drivers/syscon/Kconfig"
8788
source "drivers/timer/Kconfig"
8889
source "drivers/usb/Kconfig"

drivers/stepper/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ zephyr_library()
1414
zephyr_library_property(ALLOW_EMPTY TRUE)
1515

1616
zephyr_library_sources_ifdef(CONFIG_FAKE_STEPPER fake_stepper_controller.c)
17-
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_controller.c)
17+
zephyr_library_sources_ifdef(CONFIG_GPIO_STEPPER gpio_stepper_driver.c)
1818
zephyr_library_sources_ifdef(CONFIG_STEPPER_SHELL stepper_shell.c)

drivers/stepper/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
menuconfig STEPPER
5-
bool "Stepper Controller"
5+
bool "Stepper Driver"
66
help
7-
Enable stepper controller
7+
Enable stepper driver
88

99
if STEPPER
1010

drivers/stepper/adi_tmc/tmc22xx.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,8 @@ static int tmc22xx_stepper_init(const struct device *dev)
150150
static DEVICE_API(stepper, tmc22xx_stepper_api) = {
151151
.enable = tmc22xx_stepper_enable,
152152
.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,
153+
.step = step_dir_stepper_common_step,
154+
.set_direction = step_dir_stepper_common_set_direction,
162155
.set_micro_step_res = tmc22xx_stepper_set_micro_step_res,
163156
.get_micro_step_res = tmc22xx_stepper_get_micro_step_res,
164157
};

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;
@@ -152,42 +151,6 @@ static int a4979_stepper_get_micro_step_res(const struct device *dev,
152151
return 0;
153152
}
154153

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

284240
#define A4979_DEVICE(inst) \

0 commit comments

Comments
 (0)