-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: stepper: add common helper header for tmc5xxx functions #80795
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 common helper header for tmc5xxx functions #80795
Conversation
5e583c8 to
e2e6ae9
Compare
e2e6ae9 to
4966f00
Compare
4966f00 to
42ebdff
Compare
| inline void tmc5xxx_calculate_velocity_from_hz_to_fclk(const uint32_t velocity_hz, | ||
| uint32_t *velocity_fclk, | ||
| const uint32_t clock_frequency) |
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.
I would update the signature to:
static inline uint32_t tmc5xxx_calculate_velocity_from_hz_to_fclk(uint64_t velocity_hz,
uint32_t clock_frequency)
{
__ASSERT_NO_MSG(clock_frequency);
return (velocity_hz << TMC5XXX_CLOCK_FREQ_SHIFT) / clock_frequency;
}
- static inline to allow the compiler to either inline it or make it a static function, whichever is most efficient.
- since the function "can't fail", just return the result. Otherwise we would return a status, and copy out the result.
- add an assert to prevent divide by zero error
- make
velocity_hz64 bit removing the need to promote it and make it mutable (no const) to allow the compiler to work directly on the variable which is already on the stack - since we are copying the arguments entirely, const really does not help us :) const is useful when referencing a structure outside of the function, so we don't modify something we don't own, inside the function its not really helpful :)
e43b127 to
e42bb56
Compare
e42bb56 to
82eb9fb
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.
the indentation here can be helped by keeping the definition of uint32_t velocity_fclk in the header (where it should be according to MISRA), and even defining tmc5041_config->clock_frequency:
uint32_t clock_frequency = tmc5041_config->clock_frequency;
uint32_t velocity_fclk;
...
velocity_fclk = tmc5xxx_calculate_velocity_from_hz_to_fclk(velocity, clock_frequency);
the compiler will optimize the clock_frequency away :)
This commit adds a common helper header for tmc5xxx driver Signed-off-by: Jilay Pandya <[email protected]>
82eb9fb to
071be88
Compare
bjarki-andreasen
left a comment
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.
Nice :)
| #endif | ||
|
|
||
| /** Common Registers for TMC5041 and TMC51XX */ | ||
| #if defined(CONFIG_STEPPER_ADI_TMC5041) |
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.
Doesn't this rely on the correct include order? The autoconf is not pulled in otherwise.
This commit adds a common helper header for tmc5xxx driver in #80784