Zephyr API Documentation 4.5.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Fake LED controller

Fake LED controller driver. More...

Files

file  led_fake.h
 Fake LED controller driver API functions.

Functions

int fake_led_on (const struct device *, uint32_t)
 Fake implementation of the led_driver_api::on driver operation.
int fake_led_off (const struct device *, uint32_t)
 Fake implementation of the led_driver_api::off driver operation.
int fake_led_set_brightness (const struct device *, uint32_t, uint8_t)
 Fake implementation of the led_driver_api::set_brightness driver operation.
int fake_led_blink (const struct device *, uint32_t, uint32_t, uint32_t)
 Fake implementation of the led_driver_api::blink driver operation.
int fake_led_get_info (const struct device *, uint32_t, const struct led_info **)
 Fake implementation of the led_driver_api::get_info driver operation.
int fake_led_set_color (const struct device *, uint32_t, uint8_t, const uint8_t *)
 Fake implementation of the led_driver_api::set_color driver operation.
int fake_led_write_channels (const struct device *, uint32_t, uint32_t, const uint8_t *)
 Fake implementation of the led_driver_api::write_channels driver operation.

Detailed Description

Fake LED controller driver.

This is a Fake Function Framework (FFF) implementation of the LED API, provided for use in tests. It is enabled by CONFIG_LED_FAKE and instantiated from zephyr,fake-leds 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.

fake_led_get_info() and fake_led_set_color() are given a default custom_fake resolving the LED index and colour count against the devicetree node, re-installed on every reset. Install your own custom_fake in the test case to change what they report.

const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(fake_leds));
fake_led_on_fake.return_val = -EIO;
zassert_equal(1, fake_led_on_fake.call_count);
zassert_equal(2, fake_led_on_fake.arg1_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 led_on(const struct device *dev, uint32_t led)
Turn on an LED.
#define EIO
I/O error.
Definition errno.h:44
#define zassert_equal(a, b,...)
Assert that a equals b.
Definition ztest_assert.h:346
Runtime device structure (in ROM) per driver instance.
Definition device.h:543

Function Documentation

◆ fake_led_blink()

int fake_led_blink ( const struct device * ,
uint32_t ,
uint32_t ,
uint32_t  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::blink driver operation.

◆ fake_led_get_info()

int fake_led_get_info ( const struct device * ,
uint32_t ,
const struct led_info **  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::get_info driver operation.

◆ fake_led_off()

int fake_led_off ( const struct device * ,
uint32_t  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::off driver operation.

◆ fake_led_on()

int fake_led_on ( const struct device * ,
uint32_t  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::on driver operation.

◆ fake_led_set_brightness()

int fake_led_set_brightness ( const struct device * ,
uint32_t ,
uint8_t  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::set_brightness driver operation.

◆ fake_led_set_color()

int fake_led_set_color ( const struct device * ,
uint32_t ,
uint8_t ,
const uint8_t *  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::set_color driver operation.

◆ fake_led_write_channels()

int fake_led_write_channels ( const struct device * ,
uint32_t ,
uint32_t ,
const uint8_t *  )

#include <zephyr/drivers/led/led_fake.h>

Fake implementation of the led_driver_api::write_channels driver operation.