13#ifndef ZEPHYR_INCLUDE_DRIVERS_PWM_H_
14#define ZEPHYR_INCLUDE_DRIVERS_PWM_H_
41#define PWM_CAPTURE_TYPE_SHIFT 1U
42#define PWM_CAPTURE_TYPE_MASK (3U << PWM_CAPTURE_TYPE_SHIFT)
43#define PWM_CAPTURE_MODE_SHIFT 3U
44#define PWM_CAPTURE_MODE_MASK (1U << PWM_CAPTURE_MODE_SHIFT)
48#define PWM_CAPTURE_TYPE_PERIOD (1U << PWM_CAPTURE_TYPE_SHIFT)
51#define PWM_CAPTURE_TYPE_PULSE (2U << PWM_CAPTURE_TYPE_SHIFT)
54#define PWM_CAPTURE_TYPE_BOTH (PWM_CAPTURE_TYPE_PERIOD | \
55 PWM_CAPTURE_TYPE_PULSE)
58#define PWM_CAPTURE_MODE_SINGLE (0U << PWM_CAPTURE_MODE_SHIFT)
61#define PWM_CAPTURE_MODE_CONTINUOUS (1U << PWM_CAPTURE_MODE_SHIFT)
144#ifdef CONFIG_PWM_CAPTURE
184static inline int z_impl_pwm_pin_set_cycles(
const struct device *dev,
223#ifdef CONFIG_PWM_CAPTURE
260#ifdef CONFIG_PWM_CAPTURE
261static inline int z_impl_pwm_pin_enable_capture(
const struct device *dev,
291#ifdef CONFIG_PWM_CAPTURE
292static inline int z_impl_pwm_pin_disable_capture(
const struct device *dev,
352static inline int z_impl_pwm_get_cycles_per_sec(
const struct device *dev,
378 uint64_t period_cycles, pulse_cycles, cycles_per_sec;
384 period_cycles = (period * cycles_per_sec) /
USEC_PER_SEC;
385 if (period_cycles >= ((
uint64_t)1 << 32)) {
390 if (pulse_cycles >= ((
uint64_t)1 << 32)) {
414 uint64_t period_cycles, pulse_cycles, cycles_per_sec;
420 period_cycles = (period * cycles_per_sec) /
NSEC_PER_SEC;
421 if (period_cycles >= ((
uint64_t)1 << 32)) {
426 if (pulse_cycles >= ((
uint64_t)1 << 32)) {
460 *usec = temp / cycles_per_sec;
491 *nsec = temp / cycles_per_sec;
616#include <syscalls/pwm.h>
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
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.
uint8_t pwm_flags_t
Provides a type to hold PWM configuration flags.
Definition: pwm.h:68
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.
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.
Definition: pwm.h:579
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.
Definition: pwm.h:477
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.
Definition: pwm.h:137
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.
Definition: pwm.h:224
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.
Definition: pwm.h:374
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.
Definition: pwm.h:121
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.
int pwm_pin_enable_capture(const struct device *dev, uint32_t pwm)
Enable PWM period/pulse width capture for a single PWM input.
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.
Definition: pwm.h:523
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.
Definition: pwm.h:99
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.
Definition: pwm.h:446
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.
Definition: pwm.h:75
int pwm_pin_disable_capture(const struct device *dev, uint32_t pwm)
Disable PWM period/pulse width capture for a single PWM input.
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 descriptio...
Definition: pwm.h:111
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.
Definition: pwm.h:410
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.
Definition: pwm.h:129
#define ENOSYS
Definition: errno.h:83
#define EIO
Definition: errno.h:44
#define ENOTSUP
Definition: errno.h:115
#define ERANGE
Definition: errno.h:73
flags
Definition: http_parser.h:131
#define NSEC_PER_SEC
Definition: sys_clock.h:136
#define USEC_PER_SEC
Definition: sys_clock.h:133
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Kernel timeout type.
Definition: sys_clock.h:65
PWM driver API definition.
Definition: pwm.h:142
pwm_pin_disable_capture_t pin_disable_capture
Definition: pwm.h:147
pwm_get_cycles_per_sec_t get_cycles_per_sec
Definition: pwm.h:149
pwm_pin_configure_capture_t pin_configure_capture
Definition: pwm.h:145
pwm_pin_set_t pin_set
Definition: pwm.h:143
pwm_pin_enable_capture_t pin_enable_capture
Definition: pwm.h:146
static const intptr_t user_data[5]
Definition: main.c:590