You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/12/28 09:01:32 UTC

[incubator-nuttx] branch master updated: pwm: add option to break the loops when using multiple PWM channels

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 1e2f067  pwm: add option to break the loops when using multiple PWM channels
1e2f067 is described below

commit 1e2f06718103e7028809012a69b7ac932e9ae537
Author: Norman Rasmussen <no...@rasmussen.co.za>
AuthorDate: Mon Dec 27 22:56:56 2021 -0800

    pwm: add option to break the loops when using multiple PWM channels
    
    commit 7354ab187ed701ae041b45a0a6603878ab9b165d added an option to break
    the loops when using multiple PWM channels to arm pwm drivers. This adds
    the same support to the risc-v pwm drivers.
---
 arch/risc-v/src/bl602/bl602_pwm_lowerhalf.c |  9 +++++++++
 arch/risc-v/src/mpfs/mpfs_corepwm.c         | 16 ++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/arch/risc-v/src/bl602/bl602_pwm_lowerhalf.c b/arch/risc-v/src/bl602/bl602_pwm_lowerhalf.c
index 62aa2e2..1bce6c3 100644
--- a/arch/risc-v/src/bl602/bl602_pwm_lowerhalf.c
+++ b/arch/risc-v/src/bl602/bl602_pwm_lowerhalf.c
@@ -372,6 +372,15 @@ static int bl602_pwm_start(struct pwm_lowerhalf_s *dev,
 #ifdef CONFIG_PWM_NCHANNELS
   for (i = 0; i < CONFIG_PWM_NCHANNELS; i++)
     {
+      int8_t chan = info->channels[i].channel;
+
+      /* Break the loop if all following channels are not configured */
+
+      if (chan == -1)
+        {
+          break;
+        }
+
       bl602_pwm_freq(priv, i, info->frequency);
       bl602_pwm_duty(priv, i, info->channels[i].duty);
       pwm_channel_enable(i);
diff --git a/arch/risc-v/src/mpfs/mpfs_corepwm.c b/arch/risc-v/src/mpfs/mpfs_corepwm.c
index a5641ed..51554f4 100644
--- a/arch/risc-v/src/mpfs/mpfs_corepwm.c
+++ b/arch/risc-v/src/mpfs/mpfs_corepwm.c
@@ -424,7 +424,7 @@ static int pwm_timer(struct mpfs_pwmtimer_s *priv,
   for (i = 0; i < CONFIG_PWM_NCHANNELS; i++)
     {
       ub32_t    duty;
-      uint8_t   channel;
+      int8_t   channel;
       uint32_t  neg_edge;
 
       channel   = info->channels[i].channel;
@@ -436,6 +436,13 @@ static int pwm_timer(struct mpfs_pwmtimer_s *priv,
       duty      = ub16toub32(info->channels[i].duty);
       neg_edge  = b32toi(duty * period + b32HALF);
 
+      /* Break the loop if all following channels are not configured */
+
+      if (channel == -1)
+        {
+          break;
+        }
+
       if (channel == 0)   /* A value of zero means to skip this channel */
         {
           continue;
@@ -627,7 +634,12 @@ static int pwm_start(struct pwm_lowerhalf_s *dev,
         {
           /* Set output if channel configured */
 
-          uint8_t chan = info->channels[i].channel;
+          int8_t chan = info->channels[i].channel;
+
+          if (chan == -1)
+            {
+              break;
+            }
 
           if (chan != 0 && chan <= priv->nchannels)
             {