Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Fake PWM driver. More...

Files

file  pwm_fake.h
 Fake PWM driver API functions.

Functions

int fake_pwm_set_cycles (const struct device *, uint32_t, uint32_t, uint32_t, pwm_flags_t)
 Fake implementation of the pwm_driver_api::set_cycles driver operation.

Detailed Description

Fake PWM driver.

This is a Fake Function Framework (FFF) implementation of the PWM API, provided for use in tests. It is enabled by CONFIG_PWM_FAKE and instantiated from zephyr,fake-pwm devicetree nodes.

Each fake below is paired with an FFF control structure named after it with an additional _fake suffix, which tests use to set return values, install custom fakes, or inspect call counts and captured arguments. The control structures are not listed here; see Mocking via FFF.

Use return_val for fakes that only report status; a fake with output parameters must be driven with a custom_fake, as return_val leaves those parameters untouched.

When CONFIG_ZTEST is enabled, a ztest rule resets every fake before each test case.

const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(fake_pwm));
zassert_ok(pwm_set_cycles(dev, 0, 1000, 500, 0));
zassert_equal(1, fake_pwm_set_cycles_fake.call_count);
zassert_equal(1000, fake_pwm_set_cycles_fake.arg2_val);
zassert_equal(500, fake_pwm_set_cycles_fake.arg3_val);
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:323
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:197
int pwm_set_cycles(const struct device *dev, uint32_t channel, uint32_t period, uint32_t pulse, pwm_flags_t flags)
Set the period and pulse width for a single PWM output.
#define zassert_equal(a, b,...)
Assert that a equals b.
Definition ztest_assert.h:321
#define zassert_ok(cond,...)
Assert that cond is 0 (success).
Definition ztest_assert.h:289
Runtime device structure (in ROM) per driver instance.
Definition device.h:543

Function Documentation

◆ fake_pwm_set_cycles()

int fake_pwm_set_cycles ( const struct device * ,
uint32_t ,
uint32_t ,
uint32_t ,
pwm_flags_t  )

#include <zephyr/drivers/pwm/pwm_fake.h>

Fake implementation of the pwm_driver_api::set_cycles driver operation.