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: pwm: add functions for capturing pwm pulse width and period #26025

Merged
merged 6 commits into from Jan 12, 2021

Conversation

@henrikbrixandersen
Copy link
Member

@henrikbrixandersen henrikbrixandersen commented Jun 6, 2020

Extend the PWM API with optional functions for capturing the PWM pulse width and period time.

Fixes #26026.

Signed-off-by: Henrik Brix Andersen hebad@vestas.com

Copy link
Collaborator

@pabigot pabigot left a comment

Suggestion to make the API extension conditional on a Kconfig enabling it. Example is in 48dc2fd ("drivers: flash: add API to access SFDP region of serial flash devices") of #25851 where CONFIG_FLASH_JESD216_API enables the special case.

There're actually design considerations on how that should be implemented. In that approach the API functions are only defined if the feature is enabled. An alternative would be to always define them, but have them return -ENOTSUP if the feature is not enabled (that actually makes more sense at the moment).

@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch from 444b114 to 122307a Jul 9, 2020
@henrikbrixandersen
Copy link
Member Author

@henrikbrixandersen henrikbrixandersen commented Jul 9, 2020

Suggestion to make the API extension conditional on a Kconfig enabling it. Example is in 48dc2fd ("drivers: flash: add API to access SFDP region of serial flash devices") of #25851 where CONFIG_FLASH_JESD216_API enables the special case.

Thank you. I have added a Kconfig option for enabling this. Example implementation still pending.

@henrikbrixandersen henrikbrixandersen requested a review from pabigot Jul 9, 2020
Copy link
Collaborator

@pabigot pabigot left a comment

I see this is still draft, but since I was looking at it here're the initial comments. Will check again when there's an implementation.

include/drivers/pwm.h Outdated Show resolved Hide resolved
include/drivers/pwm.h Outdated Show resolved Hide resolved
@github-actions
Copy link

@github-actions github-actions bot commented Sep 26, 2020

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 26, 2020
@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch 2 times, most recently from 2962d5e to af63d9b Oct 7, 2020
@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch 3 times, most recently from 49c163c to 6a2f6c6 Nov 21, 2020
Copy link
Collaborator

@pabigot pabigot left a comment

It doesn't seem quite right to have both a synchronous and an asynchronous API implementation. Seems like that would produce duplication. How about just the async as the implemented API, and have the sync wrapper use a stack signal structure and k_poll()?

include/drivers/pwm.h Outdated Show resolved Hide resolved
@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch from 6a2f6c6 to 4378451 Nov 21, 2020
@coderkalyan
Copy link
Contributor

@coderkalyan coderkalyan commented Dec 8, 2020

@henrikbrixandersen What is the state of this? Does the API need any more work? Or is the wait because implementations haven't been finished yet?

@henrikbrixandersen
Copy link
Member Author

@henrikbrixandersen henrikbrixandersen commented Dec 10, 2020

@henrikbrixandersen What is the state of this? Does the API need any more work? Or is the wait because implementations haven't been finished yet?

I have had to rework the proposed API to meet real-life application needs (support for continuous capture and filtering through a callback mechanism). I have a couple of implementations almost ready. I will update this PR once the final issues have been worked out.

@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch from 4378451 to 022fe12 Jan 2, 2021
@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch 2 times, most recently from 9262ffe to 9d775c6 Jan 7, 2021
@MaureenHelm
Copy link
Member

@MaureenHelm MaureenHelm commented Jan 7, 2021

@henrikbrixandersen By any chance are you planning to write an implementation for STM32 devices? I would really like to use this API on an STM32 device to replace my current GPIO interrupt "stopwatch" implementation, but I don't know very much at all about the low level STM32 HALs in order to be able to implement this driver ☹️

@coderkalyan Sorry, no. I have no plans for adding PWM capture support on STM32. Others can submit PRs for that, though, once this PR (hopefully) goes in.

@erwango can you take a look?

@erwango
Copy link
Member

@erwango erwango commented Jan 7, 2021

@henrikbrixandersen By any chance are you planning to write an implementation for STM32 devices? I would really like to use this API on an STM32 device to replace my current GPIO interrupt "stopwatch" implementation, but I don't know very much at all about the low level STM32 HALs in order to be able to implement this driver frowning_face

@coderkalyan Sorry, no. I have no plans for adding PWM capture support on STM32. Others can submit PRs for that, though, once this PR (hopefully) goes in.

@erwango can you take a look?

No plans on our side for now, @gmarull maybe?

@henrikbrixandersen
Copy link
Member Author

@henrikbrixandersen henrikbrixandersen commented Jan 7, 2021

To demonstrate the PWM capture API on more hardware, I have added another driver implementation in #31165. I will not add it here since it currently has a few dependencies on other PRs to be merged.

@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch from 9d775c6 to 687477f Jan 7, 2021
@coderkalyan
Copy link
Contributor

@coderkalyan coderkalyan commented Jan 8, 2021

Ah, I guess I'll have to learn the LL framework and implement the driver myself 😢 😂 In the meantime, if anyone is kind enough to do it, it would be very much appreciated by me!

@henrikbrixandersen
Copy link
Member Author

@henrikbrixandersen henrikbrixandersen commented Jan 12, 2021

@MaureenHelm Could you please re-approve? @zephyrbot cancelled your approval 👎

Extend the PWM API with optional API functions for capturing PWM pulse
width and period cycles.

Fixes #26026.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Take ownership of the PWM capture helper functions.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add myself as collaborator on the PWM code.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add PWM capture support to the NXP MCUX FlexTimer driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Enable FlexTimer 0 (FTM0) as PWM and setup PTC1 as FTM0 channel 0 for
use in PWM loopback test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add test cases for the PWM capture API using PWM signal loopback.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
@henrikbrixandersen henrikbrixandersen force-pushed the vestas-wind-systems:pwm_capture branch from 7e39c15 to c673eeb Jan 12, 2021
@henrikbrixandersen henrikbrixandersen requested a review from Thalley Jan 12, 2021
@henrikbrixandersen
Copy link
Member Author

@henrikbrixandersen henrikbrixandersen commented Jan 12, 2021

@anangl Please re-review.

@anangl
anangl approved these changes Jan 12, 2021
@carlescufi carlescufi merged commit 90825a8 into zephyrproject-rtos:master Jan 12, 2021
6 checks passed
6 checks passed
@github-actions
Run compliance checks on patch series (PR)
Details
@github-actions
Documentation Build
Details
@github-actions
Manifest
Details
@github-actions
Pull Request Labeler
Details
@github-actions
Scan code for licenses
Details
buildkite/zephyr Build #17725 passed (35 minutes, 51 seconds)
Details
API review/cleanup/rework automation moved this from In Progress to Done Jan 12, 2021
@henrikbrixandersen henrikbrixandersen deleted the vestas-wind-systems:pwm_capture branch Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment