Skip to content

Commit d83647d

Browse files
drivers: adc: add ADC emulator
ADC emulator is designed to be used in tests on native_posix board. It supports 1-16 bit resolution range and all GAINs from enum adc_gain. Reference voltages and number of emulated channels are set through dts. Using special API from drivers/adc/adc_emul.h it is possible to set constant voltage value returned by given ADC channel or set custom function which allows to simulate complex output. Also reference voltages can be changed in runtime using the API. The CL also includes: - Add adc definitions of ADC emulator in tests/drivers/adc/adc_api/src/test_adc.c for supporting test suites. - Add test for ADC emulator API in tests/drivers/adc/adc_emul/ Signed-off-by: Tomasz Michalec <[email protected]>
1 parent 32d9b68 commit d83647d

File tree

19 files changed

+1505
-0
lines changed

19 files changed

+1505
-0
lines changed

boards/posix/native_posix/native_posix.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ supported:
99
- eeprom
1010
- netif:eth
1111
- usb_device
12+
- adc
1213
testing:
1314
default: true

boards/posix/native_posix/native_posix_64.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ supported:
99
- eeprom
1010
- netif:eth
1111
- usb_device
12+
- adc

drivers/adc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ zephyr_library_sources_ifdef(CONFIG_ADC_MCP320X adc_mcp320x.c)
1919
zephyr_library_sources_ifdef(CONFIG_ADC_NPCX adc_npcx.c)
2020
zephyr_library_sources_ifdef(CONFIG_USERSPACE adc_handlers.c)
2121
zephyr_library_sources_ifdef(CONFIG_ADC_CC32XX adc_cc32xx.c)
22+
zephyr_library_sources_ifdef(CONFIG_ADC_EMUL adc_emul.c)

drivers/adc/Kconfig

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

6161
source "drivers/adc/Kconfig.cc32xx"
6262

63+
source "drivers/adc/Kconfig.adc_emul"
64+
6365
endif # ADC

drivers/adc/Kconfig.adc_emul

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2021 Google LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ADC_EMUL
5+
bool "ADC emulator"
6+
help
7+
Enable the ADC emulator driver. This is a fake driver in that it
8+
does not talk to real hardware. It prenteds to be actual ADC. It
9+
is used for testing higher-level API for ADC devices.
10+
11+
if ADC_EMUL
12+
13+
config ADC_EMUL_ACQUISITION_THREAD_STACK_SIZE
14+
int "Stack size for the ADC data acquisition thread"
15+
default 512
16+
help
17+
Size of the stack used for the internal data acquisition
18+
thread. Increasing size may be required when value function for
19+
emulated ADC require a lot of memory.
20+
21+
config ADC_EMUL_ACQUISITION_THREAD_PRIO
22+
int "Priority for the ADC data acquisition thread"
23+
default 0
24+
help
25+
Priority level for the internal ADC data acquisition thread.
26+
27+
endif # ADC_EMUL

0 commit comments

Comments
 (0)