Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: stepper: drv8424 use step_dir common code #83430

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions drivers/stepper/step_dir/step_dir_stepper_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ static inline int step_dir_stepper_perform_step(const struct device *dev)
}
}

if (data->direction == STEPPER_DIRECTION_POSITIVE) {
data->actual_position++;
} else {
data->actual_position--;
}

return 0;
}

Expand Down Expand Up @@ -105,12 +111,15 @@ static void stepper_work_event_handler(struct k_work *work)

static void update_remaining_steps(struct step_dir_stepper_common_data *data)
{
const struct step_dir_stepper_common_config *config = data->dev->config;

if (data->step_count > 0) {
data->step_count--;
} else if (data->step_count < 0) {
data->step_count++;
} else {
stepper_trigger_callback(data->dev, STEPPER_EVENT_STEPS_COMPLETED);
config->timing_source->stop(data->dev);
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/stepper/step_dir/step_dir_stepper_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct step_dir_stepper_common_config {
{ \
.step_pin = GPIO_DT_SPEC_GET(node_id, step_gpios), \
.dir_pin = GPIO_DT_SPEC_GET(node_id, dir_gpios), \
.dual_edge = DT_PROP(node_id, dual_edge_step), \
.dual_edge = DT_PROP_OR(node_id, dual_edge_step, false), \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is not required, i suppose :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed otherwise the dual-edge-step property needs to be part of either the driver dts or the stepper-controller dts binding. You might not want to do this if the IC does not support this setting. But if the property is not present in dts compilation with just DT_PROP will fail.

This way only drivers that have that setting can declare it in their own dts, otherwise its just false.

.counter = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, counter)), \
.timing_source = COND_CODE_1(DT_NODE_HAS_PROP(node_id, counter), \
(&step_counter_timing_source_api), \
Expand Down
14 changes: 2 additions & 12 deletions drivers/stepper/ti/Kconfig.drv8424
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ config DRV8424
bool "TI DRV8424 stepper motor driver"
default y
depends on DT_HAS_TI_DRV8424_ENABLED
select COUNTER
select STEP_DIR_STEPPER
select STEPPER_STEP_DIR_GENERATE_ISR_SAFE_EVENTS
help
Enable driver for TI DRV8424 stepper motor driver.

if DRV8424

config DRV8424_EVENT_QUEUE_LEN
int "Maximum number of pending stepper events"
default 4
help
The maximum number of stepper events that can be pending before new events
are dropped.

endif # DRV8424
Loading
Loading