Skip to content

Commit 8173277

Browse files
Jordan Yatesnashif
authored andcommitted
drivers: adc: test driver
Add a dummy driver for the `vnd,adc` compatible to allow compilation of drivers utilising an ADC when running "build_all" tests. Signed-off-by: Jordan Yates <[email protected]>
1 parent 4446272 commit 8173277

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

drivers/adc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ zephyr_library_sources_ifdef(CONFIG_USERSPACE adc_handlers.c)
2222
zephyr_library_sources_ifdef(CONFIG_ADC_CC32XX adc_cc32xx.c)
2323
zephyr_library_sources_ifdef(CONFIG_ADC_EMUL adc_emul.c)
2424
zephyr_library_sources_ifdef(CONFIG_ADC_XEC_V2 adc_mchp_xec_v2.c)
25+
zephyr_library_sources_ifdef(CONFIG_ADC_TEST adc_test.c)

drivers/adc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ source "drivers/adc/Kconfig.cc32xx"
6868

6969
source "drivers/adc/Kconfig.adc_emul"
7070

71+
source "drivers/adc/Kconfig.test"
72+
7173
endif # ADC

drivers/adc/Kconfig.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2021, Commonwealth Scientific and Industrial Research
2+
# Organisation (CSIRO) ABN 41 687 119 230.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
DT_COMPAT_VND_ADC := vnd,adc
6+
7+
# Hidden option for turning on the dummy driver for vnd,adc devices
8+
# used in testing.
9+
config ADC_TEST
10+
def_bool $(dt_compat_enabled,$(DT_COMPAT_VND_ADC))

drivers/adc/adc_test.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 <drivers/adc.h>
16+
#include <device.h>
17+
#include <kernel.h>
18+
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+
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
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+
static int vnd_adc_init(const struct device *dev)
49+
{
50+
return 0;
51+
}
52+
53+
#define VND_ADC_INIT(n) \
54+
DEVICE_DT_INST_DEFINE(n, &vnd_adc_init, NULL, \
55+
NULL, NULL, POST_KERNEL, \
56+
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
57+
&vnd_adc_api);
58+
59+
DT_INST_FOREACH_STATUS_OKAY(VND_ADC_INIT)

0 commit comments

Comments
 (0)