Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
pwm.h File Reference

Public PWM Driver APIs. More...

#include <errno.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <sys/math_extras.h>
#include <device.h>
#include <dt-bindings/pwm/pwm.h>
#include <syscalls/pwm.h>

Go to the source code of this file.

Data Structures

struct  pwm_driver_api
 PWM driver API definition. More...
 

Macros

PWM capture configuration flags
#define PWM_CAPTURE_TYPE_PERIOD   (1U << PWM_CAPTURE_TYPE_SHIFT)
 
#define PWM_CAPTURE_TYPE_PULSE   (2U << PWM_CAPTURE_TYPE_SHIFT)
 
#define PWM_CAPTURE_TYPE_BOTH
 
#define PWM_CAPTURE_MODE_SINGLE   (0U << PWM_CAPTURE_MODE_SHIFT)
 
#define PWM_CAPTURE_MODE_CONTINUOUS   (1U << PWM_CAPTURE_MODE_SHIFT)
 

Typedefs

typedef uint8_t pwm_flags_t
 Provides a type to hold PWM configuration flags. More...
 
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. More...
 
typedef void(* pwm_capture_callback_handler_t) (const struct device *dev, uint32_t pwm, uint32_t period_cycles, uint32_t pulse_cycles, int status, void *user_data)
 PWM capture callback handler function signature. More...
 
typedef int(* pwm_pin_configure_capture_t) (const struct device *dev, uint32_t pwm, pwm_flags_t flags, pwm_capture_callback_handler_t cb, void *user_data)
 Callback API upon configuring PWM pin capture See pwm_pin_configure_capture() for argument description. More...
 
typedef int(* pwm_pin_enable_capture_t) (const struct device *dev, uint32_t pwm)
 Callback API upon enabling PWM pin capture See pwm_pin_enable_capture() for argument description. More...
 
typedef int(* pwm_pin_disable_capture_t) (const struct device *dev, uint32_t pwm)
 Callback API upon disabling PWM pin capture See pwm_pin_disable_capture() for argument description. More...
 
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. More...
 

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. More...
 
static int pwm_pin_configure_capture (const struct device *dev, uint32_t pwm, pwm_flags_t flags, pwm_capture_callback_handler_t cb, void *user_data)
 Configure PWM period/pulse width capture for a single PWM input. More...
 
int pwm_pin_enable_capture (const struct device *dev, uint32_t pwm)
 Enable PWM period/pulse width capture for a single PWM input. More...
 
int pwm_pin_disable_capture (const struct device *dev, uint32_t pwm)
 Disable PWM period/pulse width capture for a single PWM input. More...
 
int pwm_pin_capture_cycles (const struct device *dev, uint32_t pwm, pwm_flags_t flags, uint32_t *period, uint32_t *pulse, k_timeout_t timeout)
 Capture a single PWM period/pulse width in clock cycles for a single PWM input. More...
 
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. More...
 
static 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. More...
 
static 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. More...
 
static int pwm_pin_cycles_to_usec (const struct device *dev, uint32_t pwm, uint32_t cycles, uint64_t *usec)
 Convert from PWM cycles to microseconds. More...
 
static int pwm_pin_cycles_to_nsec (const struct device *dev, uint32_t pwm, uint32_t cycles, uint64_t *nsec)
 Convert from PWM cycles to nanoseconds. More...
 
static int pwm_pin_capture_usec (const struct device *dev, uint32_t pwm, pwm_flags_t flags, uint64_t *period, uint64_t *pulse, k_timeout_t timeout)
 Capture a single PWM period/pulse width in microseconds for a single PWM input. More...
 
static int pwm_pin_capture_nsec (const struct device *dev, uint32_t pwm, pwm_flags_t flags, uint64_t *period, uint64_t *pulse, k_timeout_t timeout)
 Capture a single PWM period/pulse width in nanoseconds for a single PWM input. More...
 

Detailed Description

Public PWM Driver APIs.