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: Add timing source API #83342

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

faxe1008
Copy link
Collaborator

Adds a timing source API for the common step dir stepper code. This can also be used to simplify the ti drv8424 driver.

help
Enable library used for step direction stepper drivers.

config STEP_DIR_STEPPER_GENERATE_ISR_SAFE_EVENTS
Copy link
Contributor

@jilaypandya jilaypandya Dec 23, 2024

Choose a reason for hiding this comment

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

I think this feature could be used by other drivers as well, hence could be probably refactored out to Kconfig.stepper_event_template

The maximum number of stepper events that can be pending before new events
are dropped.

config STEP_DIR_STEPPER_COUNTER_TIMING
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the idea was to go via device tree instead of Kconfig, in order to be able to select on per instance basis. #82843 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I added the Kconfig to remove the source file from compilation if you are sure you only need the delayed work.

int step_counter_timing_source_start(const struct device *dev);
bool step_counter_timing_source_needs_reschedule(const struct device *dev);
int step_counter_timing_source_stop(const struct device *dev);
bool step_counter_timing_source_is_running(const struct device *dev);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these functions need to be exposed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, they do not need to be exposed. Removed the headers :^)

stepper_timing_source_stop stop;
stepper_timing_source_is_running is_running;
};

Copy link
Contributor

@jilaypandya jilaypandya Dec 23, 2024

Choose a reason for hiding this comment

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

#if CONFIG_STEP_DIR_STEPPER_COUNTER_TIMING
extern const struct stepper_timing_source_api step_counter_timing_source_api;
#endif
extern const struct stepper_timing_source_api step_work_timing_source_api;

I think then drivers/stepper/step_dir/step_dir_stepper_counter_timing.h and drivers/stepper/step_dir/step_dir_stepper_work_timing.h could be dropped.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Adds a timing source api which is used by the step-dir stepper common code.
This allows the reusable common code to configure different timing sources,
since the initial delayable work implementation was inacurate for higher
maximum velocities.

Signed-off-by: Fabian Blatz <[email protected]>
Enables use of the counter dts property which allows to configure a counter
device as the timing source for the stepping.

Signed-off-by: Fabian Blatz <[email protected]>
Adds the counter property to the tmc2209 node to ensure counter dependant
step-dir code is build by CI.

Signed-off-by: Fabian Blatz <[email protected]>
Copy link
Member

@fabiobaltieri fabiobaltieri left a comment

Choose a reason for hiding this comment

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

just few coding style comments, great to see the subsystem growing on common functionalities and code deduplication

*
* @param node_id The devicetree node identifier.
*/
#define STEP_DIR_STEPPER_DT_COMMON_CONFIG_INIT(node_id) \
{ \
.step_pin = GPIO_DT_SPEC_GET(node_id, step_gpios), \
.dir_pin = GPIO_DT_SPEC_GET(node_id, dir_gpios), \
.dir_pin = GPIO_DT_SPEC_GET(node_id, dir_gpios), \
.dual_edge = DT_PROP_OR(node_id, dual_edge_step, false), \
Copy link
Member

Choose a reason for hiding this comment

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

sorry just caught this: booleans are implicitly "false" if not set, this can just be DT_PROP(node_id, dual_edge_step), wanna change it while you are at it?

.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), \
(&step_work_timing_source_api)), \
Copy link
Member

Choose a reason for hiding this comment

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

nit: tailing tab alignment is off

# SPDX-License-Identifier: Apache-2.0

zephyr_library()
zephyr_library_property(ALLOW_EMPTY TRUE)
Copy link
Member

Choose a reason for hiding this comment

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

this is probably not needed since there's some files enabled unconditionally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants