Skip to content

Commit

Permalink
drivers: blink: Use DEVICE_API
Browse files Browse the repository at this point in the history
Demonstrate DEVICE_API usage for blink_driver_api.

Signed-off-by: Pieter De Gendt <[email protected]>
  • Loading branch information
pdgendt committed May 3, 2024
1 parent 52c73c6 commit 772eafa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/blink/gpio_led.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static int blink_gpio_led_set_period_ms(const struct device *dev,
return 0;
}

static const struct blink_driver_api blink_gpio_led_api = {
static DEVICE_API(blink, blink_gpio_led_api) = {
.set_period_ms = &blink_gpio_led_set_period_ms,
};

Expand Down
5 changes: 5 additions & 0 deletions include/app/drivers/blink.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <zephyr/device.h>
#include <zephyr/toolchain.h>
#include <zephyr/sys/check.h>

/**
* @defgroup drivers_blink Blink drivers
Expand Down Expand Up @@ -85,6 +86,10 @@ static inline int z_impl_blink_set_period_ms(const struct device *dev,
const struct blink_driver_api *api =
(const struct blink_driver_api *)dev->api;

CHECKIF(!DEVICE_API_IS(blink, api)) {
return -ENODEV;
}

return api->set_period_ms(dev, period_ms);
}

Expand Down

0 comments on commit 772eafa

Please sign in to comment.