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/nuttx.git

commit f851b79f89b9e54a5a68f282f72c65eeca14433c
Author: Michal Lenc <[email protected]>
AuthorDate: Wed Aug 23 18:01:34 2023 +0200

    pwm: add option to set channel output polarity with IOCTL command
    
    Channel polarity can now be set with PWMIOC_SETCHARACTERISTICS ioctl
    command as field cpol was added to pwm_info_s structure. This way the
    polarity can be easily set from application layer for each channel
    apart and also can be change on at runtime if required (although this is
    not likely).
    
    Helper defines were also added to simplify the definition of low and high
    polarity level. Architecture level should take care of writing the
    polarity to correct MCU registers.
    
    Signed-off-by: Michal Lenc <[email protected]>
---
 include/nuttx/timers/pwm.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/nuttx/timers/pwm.h b/include/nuttx/timers/pwm.h
index d19153e07e..f6fbdce717 100644
--- a/include/nuttx/timers/pwm.h
+++ b/include/nuttx/timers/pwm.h
@@ -114,6 +114,17 @@
 #define PWMIOC_START              _PWMIOC(3)
 #define PWMIOC_STOP               _PWMIOC(4)
 
+/* PWM channel polarity *****************************************************/
+
+/* These are helper definitions for setting PWM channel output polarity to
+ * logical low or high level. The pulsed output should start with this
+ * logical value and should return to it when the output is disabled.
+ */
+
+#define PWM_CPOL_NDEF             0   /* Not defined, default value by arch 
driver should be used */
+#define PWM_CPOL_LOW              1   /* Logical zero */
+#define PWM_CPOL_HIGH             2   /* Logical one */
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
@@ -134,6 +145,7 @@ struct pwm_chan_s
   ub16_t dead_time_a;
   ub16_t dead_time_b;
 #endif
+  uint8_t cpol;
   int8_t channel;
 };
 #endif
@@ -161,6 +173,7 @@ struct pwm_info_s
   uint32_t           count;     /* The number of pulse to generate.  0 means to
                                  * generate an indefinite number of pulses */
 #  endif
+  uint8_t cpol;                 /* Channel polarity */
 #endif /* CONFIG_PWM_MULTICHAN */
 
   FAR void           *arg;      /* User provided argument to be used in the

Reply via email to