From b56629b09caedf9f717b178ba7d526e84e91cc49 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 17 Apr 2024 16:06:51 +0200 Subject: [PATCH] wip --- drivers/include/periph/pdm.h | 7 +---- makefiles/features_existing.inc.mk | 1 + tests/periph/pdm/Makefile | 15 +--------- tests/periph/pdm/main.c | 45 +++++++++++------------------- tests/periph/pdm/tests/01-run.py | 18 ++++++++++++ 5 files changed, 38 insertions(+), 48 deletions(-) create mode 100755 tests/periph/pdm/tests/01-run.py diff --git a/drivers/include/periph/pdm.h b/drivers/include/periph/pdm.h index c4714a6348167..f2d6c42145865 100644 --- a/drivers/include/periph/pdm.h +++ b/drivers/include/periph/pdm.h @@ -74,14 +74,9 @@ typedef enum { * @brief Default PDM samples frame buffer size */ #ifndef PDM_BUF_SIZE -#define PDM_BUF_SIZE (128U) +#define PDM_BUF_SIZE (64U) #endif -/** - * @brief Define the new buffer size - */ -#define NEW_BUF_SIZE (PDM_BUF_SIZE * 5 * 16 * 16) - /** * @brief Signature for data received interrupt callback * diff --git a/makefiles/features_existing.inc.mk b/makefiles/features_existing.inc.mk index 66fdfb684f8f0..1067dc6c7d820 100644 --- a/makefiles/features_existing.inc.mk +++ b/makefiles/features_existing.inc.mk @@ -192,6 +192,7 @@ FEATURES_EXISTING := \ periph_mcg \ periph_mcg_lite \ periph_nvm \ + periph_pdm \ periph_pio \ periph_plic \ periph_pm \ diff --git a/tests/periph/pdm/Makefile b/tests/periph/pdm/Makefile index 138449bbb553c..d6d317a57fdaa 100644 --- a/tests/periph/pdm/Makefile +++ b/tests/periph/pdm/Makefile @@ -1,21 +1,8 @@ -# name of your application -APPLICATION = shell - BOARD ?= feather-nrf52840-sense -include ../Makefile.tests_common - -CFLAGS +=-DPDM_BUF_SIZE=\(64\) +include ../Makefile.periph_common FEATURES_REQUIRED = periph_pdm -# use the shell module -USEMODULE += shell - USEMODULE += ztimer_msec -# Comment this out to disable code in RIOT that does safety checking -# which is not needed in a production environment but helps in the -# development process: -DEVELHELP ?= 1 - include $(RIOTBASE)/Makefile.include diff --git a/tests/periph/pdm/main.c b/tests/periph/pdm/main.c index 140513247c416..1150fdf4d51ea 100644 --- a/tests/periph/pdm/main.c +++ b/tests/periph/pdm/main.c @@ -29,12 +29,6 @@ #include "periph/pdm.h" #include "ztimer.h" -static kernel_pid_t _main_thread_pid = KERNEL_PID_UNDEF; - -#ifndef PDM_DATA_PRINT_BINARY -#define PDM_DATA_PRINT_BINARY (0) -#endif - #ifndef PDM_TEST_MODE #define PDM_TEST_MODE (PDM_MODE_MONO) #endif @@ -47,7 +41,16 @@ static kernel_pid_t _main_thread_pid = KERNEL_PID_UNDEF; #define PDM_TEST_GAIN (-10) #endif -int16_t new_buf[NEW_BUF_SIZE]; +#ifdef RECORD_TIME_IN_SECONDS +#define RECORD_TIME_IN_SECONDS (1) +#endif + +#define APP_BUF_SIZE (PDM_BUF_SIZE * RECORD_TIME_IN_SECONDS * 16 * 16) + +static kernel_pid_t _main_thread_pid = KERNEL_PID_UNDEF; + +/* Global only because we don't want to worry about stack size. */ +static int16_t _buf[APP_BUF_SIZE]; static void _pdm_cb(void *arg, int16_t *buf) { @@ -60,29 +63,18 @@ static void _pdm_cb(void *arg, int16_t *buf) } } -int start_recording_cmd(int argc, char **argv) +int start_recording_cmd(void) { - if (argc != 1) { - puts("Note: Start Recording \n"); - return 1; - } - (void)argv; _main_thread_pid = thread_getpid(); -#if !PDM_DATA_PRINT_BINARY -#endif - for (unsigned repeat = 0; repeat < NEW_BUF_SIZE / PDM_BUF_SIZE; repeat++) { + for (unsigned repeat = 0; repeat < APP_BUF_SIZE / PDM_BUF_SIZE; repeat++) { msg_t msg; msg_receive(&msg); int16_t *buf = (int16_t *)msg.content.ptr; -#if PDM_DATA_PRINT_BINARY - stdio_write((uint8_t *)buf, PDM_BUF_SIZE >> 2); -#else - // Copy PDM_BUF_SIZE to NEW_BUF_SIZE repeatedly + for (unsigned idx = 0; idx < PDM_BUF_SIZE; idx++) { - new_buf[repeat*PDM_BUF_SIZE+idx] = buf[idx]; + _buf[repeat * PDM_BUF_SIZE + idx] = buf[idx]; } -#endif } // Parse the new_buf _main_thread_pid = KERNEL_PID_UNDEF; @@ -95,16 +87,13 @@ int start_recording_cmd(int argc, char **argv) return 0; } -SHELL_COMMAND(start,"Start Recording", start_recording_cmd); - int main(void) { -char line_buf[SHELL_DEFAULT_BUFSIZE]; -if (pdm_init(PDM_TEST_MODE, PDM_TEST_SAMPLE_RATE, PDM_TEST_GAIN, _pdm_cb, NULL) < 0) { + if (pdm_init(PDM_TEST_MODE, PDM_TEST_SAMPLE_RATE, PDM_TEST_GAIN, _pdm_cb, NULL) < 0) { puts("Failed to initialize PDM peripheral"); return 1; } pdm_start(); - shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); -return 0; + start_recording_cmd(); + return 0; } diff --git a/tests/periph/pdm/tests/01-run.py b/tests/periph/pdm/tests/01-run.py new file mode 100755 index 0000000000000..d69fd91a34eb0 --- /dev/null +++ b/tests/periph/pdm/tests/01-run.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg +# +# 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 + + +def testfunc(child): + child.expect_exact("TEST SUCCEEDED!\r\n") + + +if __name__ == "__main__": + sys.exit(run(testfunc))