-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/periph/adc_multi: add test for reading two ADC lines to buffer
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BOARD ?= same54-xpro | ||
include ../Makefile.periph_common | ||
|
||
FEATURES_REQUIRED = periph_adc_multi | ||
USEMODULE += ztimer | ||
USEMODULE += ztimer_msec | ||
|
||
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,64 @@ | ||
/* | ||
* Copyright (C) 2024 ML!PA Consulting GmbH | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for taking multiple samples from two ADCs in parallel | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "macros/units.h" | ||
#include "periph/adc.h" | ||
#include "ztimer.h" | ||
|
||
#define RES ADC_RES_10BIT | ||
#define DELAY_MS 100U | ||
#define NUM_SAMPLES 128U | ||
#define SAMPLE_FREQ KHZ(100) | ||
|
||
int main(void) | ||
{ | ||
if (ADC_NUMOF < 2) { | ||
printf("This test needs at leasst 2 ADC lines\n"); | ||
return -1; | ||
} | ||
|
||
/* initialize two ADC lines */ | ||
for (unsigned i = 0; i < 2; i++) { | ||
if (adc_init(ADC_LINE(i)) < 0) { | ||
printf("Initialization of ADC_LINE(%u) failed\n", i); | ||
return 1; | ||
} else { | ||
printf("Successfully initialized ADC_LINE(%u)\n", i); | ||
} | ||
} | ||
|
||
while (1) { | ||
uint16_t samples[2][NUM_SAMPLES]; | ||
|
||
const adc_t lines[] = { ADC_LINE(0), ADC_LINE(1) }; | ||
|
||
adc_sample_multi(2, lines, NUM_SAMPLES, samples, RES, SAMPLE_FREQ); | ||
|
||
for (unsigned i = 0; i < NUM_SAMPLES; ++i) { | ||
printf("%u\t%u\n", samples[0][i], samples[1][i]); | ||
} | ||
|
||
ztimer_sleep(ZTIMER_MSEC, DELAY_MS); | ||
} | ||
|
||
return 0; | ||
} |