From f582dd180ade5578d037aac6f53bce23e18a17c1 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 30 Apr 2024 23:06:18 +0200 Subject: [PATCH 1/2] drivers: sensor: Use DEVICE_API Demonstrate DEVICE_API usage for sensor_driver_api. Signed-off-by: Pieter De Gendt --- drivers/sensor/example_sensor/example_sensor.c | 2 +- west.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/sensor/example_sensor/example_sensor.c b/drivers/sensor/example_sensor/example_sensor.c index 7422591b..b300cfeb 100644 --- a/drivers/sensor/example_sensor/example_sensor.c +++ b/drivers/sensor/example_sensor/example_sensor.c @@ -46,7 +46,7 @@ static int example_sensor_channel_get(const struct device *dev, return 0; } -static const struct sensor_driver_api example_sensor_api = { +static DEVICE_API(sensor, example_sensor_api) = { .sample_fetch = &example_sensor_sample_fetch, .channel_get = &example_sensor_channel_get, }; diff --git a/west.yml b/west.yml index 6bb551cb..5a99b35f 100644 --- a/west.yml +++ b/west.yml @@ -12,7 +12,7 @@ manifest: projects: - name: zephyr remote: zephyrproject-rtos - revision: main + revision: pull/72293/head import: # By using name-allowlist we can clone only the modules that are # strictly needed by the application. From b26e170652ece733fa4c8a229b61ad641bd90d8d Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 30 Apr 2024 23:08:07 +0200 Subject: [PATCH 2/2] 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 | 5 ++--- west.yml | 2 +- 3 files changed, 4 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..a5beeb96 100644 --- a/include/app/drivers/blink.h +++ b/include/app/drivers/blink.h @@ -82,10 +82,9 @@ __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; + __ASSERT_NO_MSG(DEVICE_API_IS(blink, dev)); - 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.