The latest development version of this page may be more current than this released 1.14.0 version.

PWM

Overview

API Reference

group pwm_interface

PWM Interface.

Defines

PWM_ACCESS_BY_PIN
PWM_ACCESS_ALL

Typedefs

typedef pwm_pin_set_t

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

typedef pwm_get_cycles_per_sec_t

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

Functions

int pwm_pin_set_cycles(struct device *dev, u32_t pwm, u32_t period, u32_t pulse)

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 clock cycle) set to the PWM. HW specific.
  • pulse: Pulse width (in clock cycle) set to the PWM. HW specific.
Return Value
  • 0: If successful.
  • Negative: errno code if failure.

static int z_impl_pwm_pin_set_cycles(struct device *dev, u32_t pwm, u32_t period, u32_t pulse)
int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm, u64_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.

static int z_impl_pwm_get_cycles_per_sec(struct device *dev, u32_t pwm, u64_t *cycles)
static int pwm_pin_set_usec(struct device *dev, u32_t pwm, u32_t period, u32_t pulse)

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.
Return Value
  • 0: If successful.
  • Negative: errno code if failure.

static int pwm_pin_set_nsec(struct device *dev, u32_t pwm, u32_t period, u32_t pulse)

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.
Return Value
  • 0: If successful.
  • Negative: errno code if failure.

struct pwm_driver_api
#include <pwm.h>

PWM driver API definition.