PWM

Overview

API Reference

group pwm_interface

PWM Interface.

Typedefs

typedef uint8_t pwm_flags_t

Provides a type to hold PWM configuration flags.

typedef int (*pwm_pin_set_t)(const struct device *dev, uint32_t pwm, uint32_t period_cycles, uint32_t pulse_cycles, pwm_flags_t flags)

Callback API upon setting the pin See pwm_pin_set_cycles() for argument description.

typedef int (*pwm_get_cycles_per_sec_t)(const struct device *dev, uint32_t pwm, uint64_t *cycles)

Callback API upon getting cycles per second See pwm_get_cycles_per_sec() for argument description.

Functions

int pwm_pin_set_cycles(const struct device *dev, uint32_t pwm, uint32_t period, uint32_t pulse, pwm_flags_t flags)

Set the period and pulse width for a single PWM output.

Passing 0 as pulse will cause the pin to be driven to a constant inactive level. Passing a non-zero pulse equal to period will cause the pin to be driven to a constant active level.

Parameters
  • dev: Pointer to the device structure for the driver instance.

  • pwm: PWM pin.

  • period: Period (in clock cycle) set to the PWM. HW specific.

  • pulse: Pulse width (in clock cycle) set to the PWM. HW specific.

  • flags: Flags for pin configuration (polarity).

Return Value
  • 0: If successful.

  • Negative: errno code if failure.

int pwm_get_cycles_per_sec(const struct device *dev, uint32_t pwm, uint64_t *cycles)

Get the clock rate (cycles per second) for a single PWM output.

Parameters
  • dev: Pointer to the device structure for the driver instance.

  • pwm: PWM pin.

  • cycles: Pointer to the memory to store clock rate (cycles per sec). HW specific.

Return Value
  • 0: If successful.

  • Negative: errno code if failure.

int pwm_pin_set_usec(const struct device *dev, uint32_t pwm, uint32_t period, uint32_t pulse, pwm_flags_t flags)

Set the period and pulse width for a single PWM output.

Parameters
  • dev: Pointer to the device structure for the driver instance.

  • pwm: PWM pin.

  • period: Period (in microseconds) set to the PWM.

  • pulse: Pulse width (in microseconds) set to the PWM.

  • flags: Flags for pin configuration (polarity).

Return Value
  • 0: If successful.

  • Negative: errno code if failure.

int pwm_pin_set_nsec(const struct device *dev, uint32_t pwm, uint32_t period, uint32_t pulse, pwm_flags_t flags)

Set the period and pulse width for a single PWM output.

Parameters
  • dev: Pointer to the device structure for the driver instance.

  • pwm: PWM pin.

  • period: Period (in nanoseconds) set to the PWM.

  • pulse: Pulse width (in nanoseconds) set to the PWM.

  • flags: Flags for pin configuration (polarity).

Return Value
  • 0: If successful.

  • Negative: errno code if failure.

struct pwm_driver_api
#include <pwm.h>

PWM driver API definition.