Skip to content

Commit

Permalink
tests/periph/adc_multi: add test for reading two ADC lines to buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 15, 2024
1 parent 5356c02 commit a6a2fd4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/periph/adc_multi/Makefile
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
64 changes: 64 additions & 0 deletions tests/periph/adc_multi/main.c
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;
}

0 comments on commit a6a2fd4

Please sign in to comment.