-
Notifications
You must be signed in to change notification settings - Fork 8.1k
drivers: stepper: introduce stepper_drv api to facilitate implementing motion controllers as device drivers #91979
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
base: main
Are you sure you want to change the base?
Conversation
0429ffb
to
5c9c369
Compare
676d5fd
to
1d51595
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small little pass, will do some in depth review later on :^)
drivers/stepper/adi_tmc/tmc22xx.c
Outdated
|
||
LOG_DBG("Enabling Stepper motor controller %s", dev->name); | ||
return gpio_pin_set_dt(&config->enable_pin, 1); | ||
return gpio_pin_set_dt(&config->enable_pin, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally you would set this to 1 and change the actual output to be active low via devicetree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense :) Thanks :^)
Ping @andre-stefanov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is exactly what i came up with in my implementation in the end. It is a bit inconvenient because the user of e.g. tmc2209 has to know this inverted EN logic during DTS definition instead of just saying "i define the pins, the driver knows which level has to be used for enable/disable". But unfortunately i could not provide gpio port/pin references without output level flag in DTS so i left it as faxe is proposing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you do #define STEPPER_GPIO_ENABLE_LEVEL DT_PROP(instance_nr, enable_level)
Then enable_level
may be defined in .yaml as an integer or boolean as a required entry.
Then one can do: return gpio_pin_set_dt(&config->enable_pin, STEPPER_GPIO_ENABLE_LEVEL);
.
I may be wrong - just my 2 cents here.
9ebf11f
to
d3c27b5
Compare
3b94e61
to
703d030
Compare
#include <zephyr/sys/__assert.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(gpio_stepper_motor_controller, CONFIG_STEPPER_LOG_LEVEL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: gpio_stepper_motor_controller
, just a bit too long :)
4a60ace
to
e4b6c2d
Compare
84392f5
to
060b707
Compare
drivers/stepper/stepper_motion_controllers/zephyr_stepper_motion_controller.c
Outdated
Show resolved
Hide resolved
drivers/stepper/stepper_motion_controllers/zephyr_stepper_motion_controller.c
Outdated
Show resolved
Hide resolved
060b707
to
e2dd143
Compare
6028fc9
to
49f5c47
Compare
Hey Everyone, I am working towards dropping the stepper_idx from the stepper_api. |
|
@jilaypandya props to you for continuing to tackle this :^) |
2a8478c
to
da93fe7
Compare
da93fe7
to
eeeece2
Compare
df91e36
to
25a3253
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the stepper subsystem by splitting driver responsibilities into two distinct APIs: stepper_drv
for low-level stepper driver operations (enable/disable, microstep resolution) and stepper
for motion controller operations (move, position, velocity control). This separation models TMC5xxx devices as MFD-like controllers with separate driver and motion controller components.
Key Changes:
- Introduced
stepper_drv
API for driver-level operations (enable/disable, microstep configuration, fault detection) - Separated TMC51xx/TMC50xx into stepper driver and motion controller components
- Refactored GPIO-based controllers (h_bridge, step_dir) to use common code library
- Removed step-dir common code in favor of gpio_stepper common library
- Updated tests to reflect new API split
Reviewed Changes
Copilot reviewed 102 out of 104 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
include/zephyr/drivers/stepper.h | Split API into stepper and stepper_drv interfaces |
drivers/stepper/ti/drv84xx.c | Converted to stepper_drv API |
drivers/stepper/allegro/a4979.c | Converted to stepper_drv API |
drivers/stepper/adi_tmc/tmc51xx/* | Split into separate driver and controller files |
drivers/stepper/gpio_stepper/* | New common library for GPIO-based controllers |
tests/* | Updated tests for new API structure |
Comments suppressed due to low confidence (1)
include/zephyr/drivers/stepper.h:1
- Missing closing brace in the ternary expression. The macro has an extra opening parenthesis before
&step_work_timing_source_api
that should be removed, or a closing parenthesis is missing at the end of line 49.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
drivers/stepper/gpio_stepper/common/include/gpio_stepper_common.h
Outdated
Show resolved
Hide resolved
drivers/stepper/gpio_stepper/common/include/gpio_stepper_common.h
Outdated
Show resolved
Hide resolved
add documentation about stepper and stepper_drv api - move stepper.rst in a dedicated stepper folder - add information about stepper_drv api and relevant functions in stepper documentation. Signed-off-by: Jilay Pandya <[email protected]>
- split stepper api into stepper and stepper_drv api - stepper api now comprises only of motion control apis - stepper_drv api comprises of apis for configuring stepper drivers Signed-off-by: Jilay Pandya <[email protected]>
drop motion control functions from all the stepper_drv drivers create a common a library for controlling stepper motors by toggling gpios via h-bridge or step-dir stepper_drivers Signed-off-by: Jilay Pandya <[email protected]>
stepper_api does not comprise of apis for configuring stepper drivers. Hence the stepper drivers and corresponding api tests have now been removed from stepper_api test suite. gpio_step_dir and h_bridge_stepper controllers are added to the stepper_api test-suite Signed-off-by: Jilay Pandya <[email protected]>
stepper_api split needs to be addressed in stepper_shell as well Signed-off-by: Jilay Pandya <[email protected]>
tmc5xxx devices are a combination of motion controller and stepper driver devices. tmc5xxx devices need to be modelled as mfds in order to address the split in stepper driver subsystem Signed-off-by: Jilay Pandya <[email protected]>
25a3253
to
961a67b
Compare
|
Update 17.10.25
split the stepper_drv_api out of stepper_api.
model tmc5xxx drivers like mfds.
This PR aims to facilitate implementation of stepper motion controllers as device drivers. Hence the low-level step-dir drivers now shall implement a stepper_drv api, effectively also signifying what the IC actually supports i.e enable/disable, setting/getting microstep resolution and in some cases fault detection.
Stepper Driver Subsystem shall now have two APIs
Side effects: