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

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


The following commit(s) were added to refs/heads/master by this push:
     new 78d13a4c641 drivers/pwm: using ub32_t to support fixed point frequency
78d13a4c641 is described below

commit 78d13a4c641d53ee6d00a275acb970ac7901212a
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Fri Sep 19 13:59:54 2025 +0800

    drivers/pwm: using ub32_t to support fixed point frequency
    
    Add CONFIG_PWM_FREQUENCY_FIXED.  When it is enabled,
    pwm_info_s.frequency is a ub32_t fixed point value, so a lower half
    can generate frequencies below 1 Hz.  By default the field stays a
    uint32_t in Hz.
    
    Signed-off-by: dongjiuzhu1 <[email protected]>
---
 Documentation/os/drivers/character/timers/pwm.rst | 6 +++++-
 drivers/timers/Kconfig                            | 6 ++++++
 drivers/timers/pwm.c                              | 8 +++++++-
 include/nuttx/timers/pwm.h                        | 8 +++++++-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/Documentation/os/drivers/character/timers/pwm.rst 
b/Documentation/os/drivers/character/timers/pwm.rst
index cbce4028569..f911d031ab4 100644
--- a/Documentation/os/drivers/character/timers/pwm.rst
+++ b/Documentation/os/drivers/character/timers/pwm.rst
@@ -69,13 +69,17 @@ set through ``pwm_info_s`` structure.
     struct pwm_info_s
     {
       /* Frequency of the pulse train */
-      uint32_t frequency;
+      pwm_freq_t frequency;
       /* Per-channel output state */
       struct pwm_chan_s channels[CONFIG_PWM_NCHANNELS];
       /* User provided argument to be used in the lower half */
       FAR void *arg;
     };
 
+``pwm_freq_t`` is ``uint32_t`` (Hz).  With ``CONFIG_PWM_FREQUENCY_FIXED``
+it is ``ub32_t`` (Hz in 32.32 fixed point), so frequencies below 1 Hz
+can be set.
+
 Structure ``pwm_chan_s`` holds the representation of one PWM channel.
 
 .. c:struct:: pwm_chan_s
diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig
index a7014d5f261..c8e848431fa 100644
--- a/drivers/timers/Kconfig
+++ b/drivers/timers/Kconfig
@@ -36,6 +36,12 @@ config PULSECOUNT
 
 if PWM
 
+config PWM_FREQUENCY_FIXED
+       bool "PWM Frequency Fixed Point Support"
+       default n
+       ---help---
+               Using ub32_t to define frequency to support accuracy less than 
1HZ.
+
 config PWM_OVERWRITE
        bool "PWM Overwrite Support"
        default n
diff --git a/drivers/timers/pwm.c b/drivers/timers/pwm.c
index d6687bbc95d..bc5f5dd20f2 100644
--- a/drivers/timers/pwm.c
+++ b/drivers/timers/pwm.c
@@ -107,7 +107,13 @@ static void pwm_dump(FAR const char *msg, FAR const struct 
pwm_info_s *info,
 {
   int i;
 
-  pwminfo("%s: frequency: %" PRId32 "\n", msg, info->frequency);
+  pwminfo("%s: frequency: "
+#ifdef CONFIG_PWM_FREQUENCY_FIXED
+          "%016" PRIx64
+#else
+          "%" PRId32
+#endif
+          "\n", msg, info->frequency);
 
   for (i = 0; i < CONFIG_PWM_NCHANNELS; i++)
     {
diff --git a/include/nuttx/timers/pwm.h b/include/nuttx/timers/pwm.h
index bd1a50ff88e..4c252febfb6 100644
--- a/include/nuttx/timers/pwm.h
+++ b/include/nuttx/timers/pwm.h
@@ -201,11 +201,17 @@ struct pwm_chan_s
   int8_t channel;                    /* Channel number: 1~N=active, 0=skip, 
-1=end */
 };
 
+#ifdef CONFIG_PWM_FREQUENCY_FIXED
+typedef ub32_t pwm_freq_t;
+#else
+typedef uint32_t pwm_freq_t;
+#endif
+
 /* This structure describes the characteristics of the pulsed output */
 
 struct pwm_info_s
 {
-  uint32_t           frequency; /* Frequency of the pulse train */
+  pwm_freq_t         frequency; /* Frequency of the pulse train */
 
   /* Per-channel output state */
 

Reply via email to