+ /**
+ * Enum describing PWM polarities.
+ */
+ typedef enum PwmPolarity
+ {
+ /** High pulse: increasing duty increases the part of the signal at high level. */
+ PWM_POL_HIGH_PULSE,
+ /** Positive pulse: same as High pulse. */
+ PWM_POL_POSITIVE = PWM_POL_HIGH_PULSE,
+ /** Low pulse: increasing duty increases the part of the signal at low level. */
+ PWM_POL_LOW_PULSE,
+ /** Negative pulse: same as Low pulse. */
+ PWM_POL_NEGATIVE = PWM_POL_LOW_PULSE,
+ } PwmPolarity;
+
+ struct PwmHardware; //Fwd declaration
+
+ /**
+ * PWM context structure.
+ */
+ typedef struct Pwm
+ {
+ unsigned ch;
+ pwm_duty_t duty;
+ PwmPolarity pol;
+ bool enabled;
+ struct PwmHardware *hw;
+ } Pwm;
+
+ void pwm_setDuty(Pwm *ctx, pwm_duty_t duty);
+ void pwm_setFrequency(Pwm *ctx, pwm_freq_t freq);
+ void pwm_setPolarity(Pwm *ctx, PwmPolarity pol);
+ void pwm_enable(Pwm *ctx, bool state);
+ void pwm_init(Pwm *ctx, unsigned channel);
+ /** \} */ //defgroup pwm_api
+#endif
+
+
+#if CFG_PWM_ENABLE_OLD_API
+ /**
+ * \defgroup pwm_old_api Old PWM API
+ * This API has strong limititations, so it has been deprecated.
+ * It is active by default for backward compatibility reasons, but
+ * for new projects please use the new PWM API.
+ * In order to disable this API, check CFG_PWM_ENABLE_OLD_API.
+ * \see pwm_api
+ * \see CFG_PWM_ENABLE_OLD_API
+ * \{
+ */
+
+ #include CPU_HEADER(pwm)
+ #include "hw/pwm_map.h"
+
+ /**
+ * Set PWM polarity of pwm \p dev.
+ * \param dev PWM channel.
+ * \param pol if false positive polarity pulses are generated,
+ * if true negative polarity pulses are generated.
+ * \warning This function has to be called with PWM disabled, otherwise
+ * the output value will be undefined.
+ */
+ INLINE void pwm_setPolarity(PwmDev dev, bool pol)
+ {
+ pwm_hw_setPolarity(dev, pol);
+ }
+
+ void pwm_setDuty(PwmDev dev, pwm_duty_t duty);
+ void pwm_setFrequency(PwmDev dev, pwm_freq_t freq);
+ void pwm_enable(PwmDev dev, bool state);
+ void pwm_init(void);
+ /** \} */ //defgroup pwm_old_api
+#endif
+
+/*