1 /*
2 * Copyright (c) 2021, Commonwealth Scientific and Industrial Research
3 * Organisation (CSIRO) ABN 41 687 119 230.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 /*
9 * This is not a real ADC driver. It is used to instantiate struct
10 * devices for the "vnd,adc" devicetree compatible used in test code.
11 */
12
13 #define DT_DRV_COMPAT vnd_adc
14
15 #include <zephyr/drivers/adc.h>
16 #include <zephyr/device.h>
17 #include <zephyr/kernel.h>
18
vnd_adc_channel_setup(const struct device * dev,const struct adc_channel_cfg * channel_cfg)19 static int vnd_adc_channel_setup(const struct device *dev,
20 const struct adc_channel_cfg *channel_cfg)
21 {
22 return -ENOTSUP;
23 }
24
vnd_adc_read(const struct device * dev,const struct adc_sequence * sequence)25 static int vnd_adc_read(const struct device *dev,
26 const struct adc_sequence *sequence)
27 {
28 return -ENOTSUP;
29 }
30
31 #ifdef CONFIG_ADC_ASYNC
vnd_adc_read_async(const struct device * dev,const struct adc_sequence * sequence,struct k_poll_signal * async)32 static int vnd_adc_read_async(const struct device *dev,
33 const struct adc_sequence *sequence,
34 struct k_poll_signal *async)
35 {
36 return -ENOTSUP;
37 }
38 #endif
39
40 static const struct adc_driver_api vnd_adc_api = {
41 .channel_setup = vnd_adc_channel_setup,
42 .read = vnd_adc_read,
43 #ifdef CONFIG_ADC_ASYNC
44 .read_async = vnd_adc_read_async,
45 #endif
46 };
47
48 #define VND_ADC_INIT(n) \
49 DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, \
50 POST_KERNEL, \
51 CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
52 &vnd_adc_api);
53
54 DT_INST_FOREACH_STATUS_OKAY(VND_ADC_INIT)
55