Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevinWeiss committed Apr 17, 2024
1 parent f59e10b commit b56629b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
7 changes: 1 addition & 6 deletions drivers/include/periph/pdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions makefiles/features_existing.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ FEATURES_EXISTING := \
periph_mcg \
periph_mcg_lite \
periph_nvm \
periph_pdm \
periph_pio \
periph_plic \
periph_pm \
Expand Down
15 changes: 1 addition & 14 deletions tests/periph/pdm/Makefile
Original file line number Diff line number Diff line change
@@ -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
45 changes: 17 additions & 28 deletions tests/periph/pdm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
}
18 changes: 18 additions & 0 deletions tests/periph/pdm/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit b56629b

Please sign in to comment.