You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Michal Lenc <mi...@seznam.cz> on 2021/07/22 21:32:19 UTC

Option to break for loop in PWM driver code by -1 channel number

Hello,




the PWM driver currently uses channel number 0 for channels that are not 
supposed to be used. During the meeting for Google Summer of Code project 
NuttX Support for Rapid Control Applications Development with pysimCoder 
(information about the project can be found here https://cwiki.apache.org/
confluence/display/NUTTX/%5B2021%5D+NuttX+Support+for+Rapid+Control+
Applications+Development+with+pysimCoder) with Professor Bucher and Dr. Píša
we discussed an option to add channel number -1 as a "stop" value. That 
would indicate that it is not necessary to check the other channels and that
they all can be skipped. This can be useful when for example just one 
channel out of x is used and thus there is no need to waste time by checking
the others. The example of the code can be found here <https://github.com/
michallenc/incubator-nuttx/blob/teensy-dc/arch/arm/src/imxrt/imxrt_flexpwm.
c#L920>. The key part is:




for (int i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)

{       


   /* Enable PWM output for each channel */        


  


   if (info->channels[i].channel == -1)

     {

        break;

     }




   if (info->channels[i].channel != 0)

  {

    ...





The advantage is that this addition would not damage current drivers or 
already developed applications in any way but would just add the possibility
to break the loop from the application level code. It would be great if the 
options like 0 and -1 would be standardized and documented somewhere 
(probably extend this page https://nuttx.apache.org/docs/latest/components/
drivers/character/pwm.html).




If there is no major problem with adding -1 as a "stop" value to all PWM 
drivers I can create a PR during the following days.


Best regards,
Michal Lenc