1 /*
2  * Copyright (c) 2020 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 #include <zephyr/device.h>
9 #include "abstract_driver.h"
10 
11 #define MY_DRIVER_A	"my_driver_A"
12 #define MY_DRIVER_B	"my_driver_B"
13 
14 /* define individual driver A */
my_driver_A_do_this(const struct device * dev,int foo,int bar)15 static int my_driver_A_do_this(const struct device *dev, int foo, int bar)
16 {
17 	return foo + bar;
18 }
19 
my_driver_A_do_that(const struct device * dev,unsigned int * baz)20 static void my_driver_A_do_that(const struct device *dev, unsigned int *baz)
21 {
22 	*baz = 1;
23 }
24 
25 static DEVICE_API(abstract, my_driver_A_api_funcs) = {
26 	.do_this = my_driver_A_do_this,
27 	.do_that = my_driver_A_do_that,
28 };
29 
common_driver_init(const struct device * dev)30 int common_driver_init(const struct device *dev)
31 {
32 	return 0;
33 }
34 
35 /* define individual driver B */
my_driver_B_do_this(const struct device * dev,int foo,int bar)36 static int my_driver_B_do_this(const struct device *dev, int foo, int bar)
37 {
38 	return foo - bar;
39 }
40 
my_driver_B_do_that(const struct device * dev,unsigned int * baz)41 static void my_driver_B_do_that(const struct device *dev, unsigned int *baz)
42 {
43 	*baz = 2;
44 }
45 
46 static DEVICE_API(abstract, my_driver_B_api_funcs) = {
47 	.do_this = my_driver_B_do_this,
48 	.do_that = my_driver_B_do_that,
49 };
50 
51 /**
52  * @cond INTERNAL_HIDDEN
53  */
54 DEVICE_DEFINE(my_driver_A, MY_DRIVER_A, &common_driver_init,
55 		NULL, NULL, NULL,
56 		POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
57 		&my_driver_A_api_funcs);
58 
59 DEVICE_DEFINE(my_driver_B, MY_DRIVER_B, &common_driver_init,
60 		NULL, NULL, NULL,
61 		POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
62 		&my_driver_B_api_funcs);
63 
64 /**
65  * @endcond
66  */
67