You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/07/26 13:34:28 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.
acassis 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 7354ab1 pwm: add option to break the loops when using multiple PWM channels
7354ab1 is described below
commit 7354ab187ed701ae041b45a0a6603878ab9b165d
Author: Michal Lenc <mi...@seznam.cz>
AuthorDate: Sat Jul 24 20:13:10 2021 +0200
pwm: add option to break the loops when using multiple PWM channels
PWM drivers currently use channel number 0 for the channels that are not
used by the application. This commit adds number -1 which indicates that
all following channels are not configured and that the loop can be broken.
Signed-off-by: Michal Lenc <mi...@seznam.cz>
---
arch/arm/src/imxrt/imxrt_flexpwm.c | 26 +++++++++++++++++++++++---
arch/arm/src/nrf52/nrf52_pwm.c | 7 +++++++
arch/arm/src/stm32/stm32_pwm.c | 14 ++++++++++++++
arch/arm/src/stm32f0l0g0/stm32_pwm.c | 14 ++++++++++++++
arch/arm/src/stm32f7/stm32_pwm.c | 14 ++++++++++++++
arch/arm/src/stm32h7/stm32_pwm.c | 14 ++++++++++++++
arch/arm/src/stm32l4/stm32l4_pwm.c | 14 ++++++++++++++
include/nuttx/timers/pwm.h | 2 +-
8 files changed, 101 insertions(+), 4 deletions(-)
diff --git a/arch/arm/src/imxrt/imxrt_flexpwm.c b/arch/arm/src/imxrt/imxrt_flexpwm.c
index 2471bca..16885db 100644
--- a/arch/arm/src/imxrt/imxrt_flexpwm.c
+++ b/arch/arm/src/imxrt/imxrt_flexpwm.c
@@ -894,9 +894,19 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
{
for (int i = 0; i < PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Configure the module freq only if is set to be used */
- ret = pwm_change_freq(dev, info, i);
+ if (info->channels[i].channel != 0)
+ {
+ ret = pwm_change_freq(dev, info, i);
+ }
}
/* Save current frequency */
@@ -910,10 +920,20 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
#ifdef CONFIG_PWM_MULTICHAN
for (int i = 0; ret == OK && i < PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Enable PWM output for each channel */
- ret = pwm_set_output(dev, info->channels[i].channel,
- info->channels[i].duty);
+ if (info->channels[i].channel != 0)
+ {
+ ret = pwm_set_output(dev, info->channels[i].channel,
+ info->channels[i].duty);
+ }
}
#else
/* Enable PWM output just for first channel */
diff --git a/arch/arm/src/nrf52/nrf52_pwm.c b/arch/arm/src/nrf52/nrf52_pwm.c
index 982fcba..31dfdcd 100644
--- a/arch/arm/src/nrf52/nrf52_pwm.c
+++ b/arch/arm/src/nrf52/nrf52_pwm.c
@@ -574,6 +574,13 @@ static int nrf52_pwm_start(FAR struct pwm_lowerhalf_s *dev,
#ifdef CONFIG_PWM_MULTICHAN
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/arch/arm/src/stm32/stm32_pwm.c b/arch/arm/src/stm32/stm32_pwm.c
index e3f959b..da83158 100644
--- a/arch/arm/src/stm32/stm32_pwm.c
+++ b/arch/arm/src/stm32/stm32_pwm.c
@@ -3645,6 +3645,13 @@ static int pwm_duty_channels_update(FAR struct pwm_lowerhalf_s *dev,
#endif
{
#ifdef CONFIG_PWM_MULTICHAN
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
duty = info->channels[i].duty;
channel = info->channels[i].channel;
@@ -4390,6 +4397,13 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/arch/arm/src/stm32f0l0g0/stm32_pwm.c b/arch/arm/src/stm32f0l0g0/stm32_pwm.c
index 8efb04b..941b49f 100644
--- a/arch/arm/src/stm32f0l0g0/stm32_pwm.c
+++ b/arch/arm/src/stm32f0l0g0/stm32_pwm.c
@@ -1155,6 +1155,13 @@ static int stm32pwm_timer(FAR struct stm32_pwmtimer_s *priv,
enum stm32_chanmode_e mode;
#ifdef CONFIG_PWM_MULTICHAN
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
duty = info->channels[i].duty;
channel = info->channels[i].channel;
@@ -1946,6 +1953,13 @@ static int stm32pwm_start(FAR struct pwm_lowerhalf_s *dev,
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/arch/arm/src/stm32f7/stm32_pwm.c b/arch/arm/src/stm32f7/stm32_pwm.c
index a0c8cd3..b047aa5 100644
--- a/arch/arm/src/stm32f7/stm32_pwm.c
+++ b/arch/arm/src/stm32f7/stm32_pwm.c
@@ -1375,6 +1375,13 @@ static int pwm_timer(FAR struct stm32_pwmtimer_s *priv,
enum stm32_chanmode_e mode;
#ifdef CONFIG_PWM_MULTICHAN
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
duty = info->channels[i].duty;
channel = info->channels[i].channel;
@@ -2187,6 +2194,13 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/arch/arm/src/stm32h7/stm32_pwm.c b/arch/arm/src/stm32h7/stm32_pwm.c
index 145d7ca..101f9b8 100644
--- a/arch/arm/src/stm32h7/stm32_pwm.c
+++ b/arch/arm/src/stm32h7/stm32_pwm.c
@@ -3324,6 +3324,13 @@ static int pwm_duty_channels_update(FAR struct pwm_lowerhalf_s *dev,
#endif
{
#ifdef CONFIG_PWM_MULTICHAN
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
duty = info->channels[i].duty;
channel = info->channels[i].channel;
@@ -4029,6 +4036,13 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/arch/arm/src/stm32l4/stm32l4_pwm.c b/arch/arm/src/stm32l4/stm32l4_pwm.c
index 2e4c8c8..ffb6808 100644
--- a/arch/arm/src/stm32l4/stm32l4_pwm.c
+++ b/arch/arm/src/stm32l4/stm32l4_pwm.c
@@ -3105,6 +3105,13 @@ static int pwm_duty_channels_update(FAR struct pwm_lowerhalf_s *dev,
#endif
{
#ifdef CONFIG_STM32L4_PWM_MULTICHAN
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
duty = info->channels[i].duty;
channel = info->channels[i].channel;
@@ -3930,6 +3937,13 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev,
for (i = 0; ret == OK && i < CONFIG_PWM_NCHANNELS; i++)
{
+ /* Break the loop if all following channels are not configured */
+
+ if (info->channels[i].channel == -1)
+ {
+ break;
+ }
+
/* Set output if channel configured */
if (info->channels[i].channel != 0)
diff --git a/include/nuttx/timers/pwm.h b/include/nuttx/timers/pwm.h
index 9e57ab3..1c2a93e 100644
--- a/include/nuttx/timers/pwm.h
+++ b/include/nuttx/timers/pwm.h
@@ -120,7 +120,7 @@
struct pwm_chan_s
{
ub16_t duty;
- uint8_t channel;
+ int8_t channel;
};
#endif