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 Nov 21, 2024
1 parent f582dd1 commit a8083cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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
8 changes: 5 additions & 3 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 @@ -82,10 +83,11 @@ __syscall int blink_set_period_ms(const struct device *dev,
static inline int z_impl_blink_set_period_ms(const struct device *dev,
unsigned int period_ms)
{
const struct blink_driver_api *api =
(const struct blink_driver_api *)dev->api;
CHECKIF(!DEVICE_API_IS(blink, dev)) {
return -ENODEV;
}

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

/**
Expand Down

0 comments on commit a8083cc

Please sign in to comment.