counter: add input-capture feature-flag #71618
jlh-makeen
started this conversation in
RFC
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to propose an request for improvement on the driver counter API to add the input capture feature.
The feature would work as a selector flag passed to the counter_set_channel_alarm function and therefore doesn't add new functions to the API.
Why this would make sense ?
The counter callback structure is already thought to pass the tick value together with the channel id and user_data.
When setting up an alarm as input-capture, the user is passed back the capture value from the timer.
FTM timer on NXP IMX7 and General purpose timers on STM32 are capable of generating output_compare and input_capture interrupts and are also able to reconfigure the channels as OC or IC at will.
We can therefore multiplex the use of timer channels for OC/IC depending on application needs without needing to instanciate 2 peripherals (PWM and COUNTER drivers), which could save power, software resources and maybe simplify the layout decisions on some boards where the choice of pads make it mandatory to share the Timer's OC/IC feature.
As context, I have a (special) application on the IMX7D/M4 core that needs to use 1 single FTM timer to trigger both output_compare and input_capture interrupts that need to be issued from the exact same timer tick source.
I've therefore implemented the output_compare and input_capture driver into the counter implementation for imx7d in my zephyr fork.
I use it as follows:
A channel can be configured as a normal timing alarm while not setting any attribute flags (or only the ABSOLUTE flag).
If a user needs to be notified when a falling edge or rising edge occurs on the line, the specific input capture flag can be used.
Multiple vendors are able to provide both input_capture and output_compare on the same peripheral, at least, STM32, NXP general purpose timers and Flexible timers. I'm sure others can provide this feature too.
As per the implementation, drivers not supporting the Input capture can simply return -ENOTSUP upon calls of the counter_set_channel_alarm function.
I know that the PWM driver is mean to be used with input-capture but I wanted the simplicity of the counter API to implement it into the FTM/GPT drivers for my IMX7d platform. Knowing it could also work on STM32, I thought it would be a great addition to other developers.
Here is my FTM implementation for the input-capture and output-compare features working in parallel:
Beta Was this translation helpful? Give feedback.
All reactions