From 097a9b652e7bc08aa2d933eaea1fe623210150b0 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 30 Apr 2024 23:08:07 +0200 Subject: [PATCH] drivers: blink: Use DEVICE_API Demonstrate DEVICE_API usage for blink_driver_api. Signed-off-by: Pieter De Gendt --- drivers/blink/gpio_led.c | 2 +- include/app/drivers/blink.h | 8 +++++--- west.yml | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/blink/gpio_led.c b/drivers/blink/gpio_led.c index ec482b78..471adea9 100644 --- a/drivers/blink/gpio_led.c +++ b/drivers/blink/gpio_led.c @@ -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, }; diff --git a/include/app/drivers/blink.h b/include/app/drivers/blink.h index 278c9549..0c9c4b54 100644 --- a/include/app/drivers/blink.h +++ b/include/app/drivers/blink.h @@ -8,6 +8,7 @@ #include #include +#include /** * @defgroup drivers_blink Blink drivers @@ -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); } /** diff --git a/west.yml b/west.yml index 5a99b35f..6bb551cb 100644 --- a/west.yml +++ b/west.yml @@ -12,7 +12,7 @@ manifest: projects: - name: zephyr remote: zephyrproject-rtos - revision: pull/72293/head + revision: main import: # By using name-allowlist we can clone only the modules that are # strictly needed by the application.