-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
include ../Makefile.tests_common | ||
|
||
FEATURES_REQUIRED = periph_adc | ||
|
||
USEMODULE += ztimer | ||
USEMODULE += ztimer_msec | ||
USEMODULE += embunit | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# this file enables modules defined in Kconfig. Do not use this file for | ||
# application configuration. This is only needed during migration. | ||
# enable ADC peripheral driver | ||
CONFIG_MODULE_PERIPH_ADC=y | ||
|
||
# enable xtimer to wake up periodically | ||
CONFIG_MODULE_ZTIMER=y | ||
CONFIG_MODULE_ZTIMER_MSEC=y | ||
|
||
CONFIG_MODULE_EMBUNIT=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
@defgroup periph_adc | ||
@ingroup test_group | ||
@{ | ||
|
||
## Test the [A]nalog to [D]igital [C}onverter peripheral | ||
|
||
To test the code in automatic mode: | ||
|
||
```c | ||
make flash test | ||
``` | ||
|
||
@} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2022 Mesh4all mesh4all.org | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @brief ADC test | ||
* | ||
* @author Luis A. Ruiz <[email protected]> | ||
*/ | ||
#include <string.h> | ||
#include <errno.h> | ||
#include "periph/adc.h" | ||
#include "ztimer.h" | ||
#include "embUnit.h" | ||
|
||
#define RES ADC_RES_10BIT | ||
#define DELAY_MS 100U | ||
#define LAPS 5 | ||
|
||
/* initialize all available ADC lines */ | ||
void test_adc_init(void) { | ||
int err; | ||
for (unsigned i = 0; i < ADC_NUMOF; i++) { | ||
if (adc_init(ADC_LINE(i)) < 0) { | ||
printf("\nInitialization of ADC_LINE(%u) failed\n", i); | ||
err = 1; | ||
} else { | ||
printf("\nSuccessfully initialized ADC_LINE(%u)\n", i); | ||
printf("Channel %u of %u\n", i + 1, ADC_NUMOF); | ||
err = 0; | ||
} | ||
ztimer_sleep(ZTIMER_MSEC, DELAY_MS); | ||
} | ||
|
||
TEST_ASSERT_EQUAL_INT(0, err); | ||
} | ||
|
||
void test_adc_read(void) { | ||
int err; | ||
int sample; | ||
for (int lap = 0; lap < LAPS; lap++) { | ||
|
||
printf("\nRound %d of %d\n", lap + 1, LAPS); | ||
|
||
for (unsigned i = 0; i < ADC_NUMOF; i++) { | ||
sample = adc_sample(ADC_LINE(i), RES); | ||
if (sample < 0) { | ||
printf("ADC_LINE(%u): selected resolution not applicable\n", i); | ||
err = 1; | ||
} else { | ||
printf("ADC_LINE(%u): %i\n", i, sample); | ||
err = 0; | ||
} | ||
} | ||
ztimer_sleep(ZTIMER_MSEC, DELAY_MS); | ||
} | ||
|
||
TEST_ASSERT_EQUAL_INT(0, err); | ||
} | ||
|
||
Test *test_periph_adc(void) { | ||
|
||
EMB_UNIT_TESTFIXTURES(fixtures){ | ||
new_TestFixture(test_adc_init), // init. ADC lines available | ||
new_TestFixture(test_adc_read), // read value for each line | ||
}; | ||
|
||
EMB_UNIT_TESTCALLER(test_periph_adc, NULL, NULL, fixtures); | ||
|
||
return (Test *)&test_periph_adc; | ||
} | ||
int main(void) { | ||
printf("Test ADC peripherals\n"); | ||
TESTS_START(); | ||
TESTS_RUN(test_periph_adc()); | ||
TESTS_END(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2017 Freie Universität Berlin | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import sys | ||
from testrunner import run_check_unittests | ||
|
||
if __name__ == "__main__": | ||
sys.exit(run_check_unittests()) |