Skip to content

Commit 7939d6c

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 Remove unnecessary `data` parameter from `STEP_DIR_STEPPER_STRUCT_CHECK` macro, simplifying its usage. Adjust `tmc22xx_data` struct and initialization to reflect the change, removing redundant `.common` field. Correct the GPIO pin states for enabling and disabling the stepper motor controller. The enable logic was accidentally inverted, causing improper activation and deactivation of the device. This change ensures proper functionality as per the intended design. Signed-off-by: Andre Stefanov <[email protected]> Signed-off-by: Jilay Pandya <[email protected]>
1 parent 0548cca commit 7939d6c

28 files changed

+892
-1065
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: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,25 @@ 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
{
3029
const struct tmc22xx_config *config = dev->config;
3130

3231
LOG_DBG("Enabling Stepper motor controller %s", dev->name);
33-
return gpio_pin_set_dt(&config->enable_pin, 1);
32+
return gpio_pin_set_dt(&config->enable_pin, 0);
3433
}
3534

3635
static int tmc22xx_stepper_disable(const struct device *dev)
3736
{
3837
const struct tmc22xx_config *config = dev->config;
3938

4039
LOG_DBG("Disabling Stepper motor controller %s", dev->name);
41-
return gpio_pin_set_dt(&config->enable_pin, 0);
40+
return gpio_pin_set_dt(&config->enable_pin, 1);
4241
}
4342

4443
static int tmc22xx_stepper_set_micro_step_res(const struct device *dev,
@@ -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;
@@ -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)