From 012348085138cb6d4447018610bbb437249d93ad Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Wed, 6 Jun 2018 12:45:51 +0000 Subject: [PATCH] Merged in masayuki2009/nuttx.apps/i2sloop_test (pull request #137) apps/examples/i2sloop: Add i2sloop application This application can be used to test I2S loopback nsh> i2sloop & Signed-off-by: Masayuki Ishikawa Approved-by: Gregory Nutt --- examples/i2sloop/.gitignore | 11 +++ examples/i2sloop/Kconfig | 11 +++ examples/i2sloop/Make.defs | 39 ++++++++ examples/i2sloop/Makefile | 53 +++++++++++ examples/i2sloop/i2sloop_main.c | 153 ++++++++++++++++++++++++++++++++ 5 files changed, 267 insertions(+) create mode 100644 examples/i2sloop/.gitignore create mode 100644 examples/i2sloop/Kconfig create mode 100644 examples/i2sloop/Make.defs create mode 100644 examples/i2sloop/Makefile create mode 100644 examples/i2sloop/i2sloop_main.c diff --git a/examples/i2sloop/.gitignore b/examples/i2sloop/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/examples/i2sloop/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/examples/i2sloop/Kconfig b/examples/i2sloop/Kconfig new file mode 100644 index 000000000..63a504222 --- /dev/null +++ b/examples/i2sloop/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_I2SLOOP + bool "I2S loopback test" + default n + depends on I2S && AUDIO && DRIVERS_AUDIO && AUDIO_I2SCHAR + ---help--- + Enable the I2S loopback test diff --git a/examples/i2sloop/Make.defs b/examples/i2sloop/Make.defs new file mode 100644 index 000000000..d26f84da2 --- /dev/null +++ b/examples/i2sloop/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/i2sloop/Make.defs +# Adds selected applications to apps/ build +# +# Copyright 2018 Sony Video & Sound Products Inc. +# Author: Masayuki Ishikawa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_I2SLOOP),y) +CONFIGURED_APPS += examples/i2sloop +endif diff --git a/examples/i2sloop/Makefile b/examples/i2sloop/Makefile new file mode 100644 index 000000000..e2085a6a6 --- /dev/null +++ b/examples/i2sloop/Makefile @@ -0,0 +1,53 @@ +############################################################################ +# apps/examples/i2sloop/Makefile +# +# Copyright 2018 Sony Video & Sound Products Inc. +# Author: Masayuki Ishikawa +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +# I2S character driver test + +ASRCS = +CSRCS = +MAINSRC = i2sloop_main.c + +CONFIG_XYZ_PROGNAME ?= i2sloop$(EXEEXT) +PROGNAME = $(CONFIG_XYZ_PROGNAME) + +# Touchscreen built-in application info + +APPNAME = i2sloop +PRIORITY = 140 +STACKSIZE = 2048 + +include $(APPDIR)/Application.mk diff --git a/examples/i2sloop/i2sloop_main.c b/examples/i2sloop/i2sloop_main.c new file mode 100644 index 000000000..4728c1507 --- /dev/null +++ b/examples/i2sloop/i2sloop_main.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * examples/i2sloop/i2sloop_main.c + * + * Copyright 2018 Sony Video & Sound Products Inc. + * Author: Masayuki Ishikawa + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static bool g_i2sloop_running; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void _signal_handler(int number) +{ + g_i2sloop_running = false; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: i2sloop_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int i2sloop_main(int argc, char *argv[]) +#endif +{ + FAR struct ap_buffer_s *apb; + struct audio_buf_desc_s desc; + ssize_t bufsize; + int ret; + int fd; + int opt; + int ch; + int freq; + + ch = 1; + freq = 16000; + + while ((opt = getopt(argc, argv, "c:f:")) != -1) + { + switch (opt) + { + case 'c': + ch = atoi(optarg); + break; + + case 'f': + freq = atoi(optarg); + break; + } + } + + /* Open the I2S character device */ + + fd = open("/dev/i2schar0", O_RDWR); + ASSERT(0 < fd); + + /* Setup sample freq for i2s */ + + struct audio_caps_desc_s cap_desc; + cap_desc.caps.ac_len = sizeof(struct audio_caps_s); + cap_desc.caps.ac_type = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_INPUT; + cap_desc.caps.ac_controls.w = freq; + cap_desc.caps.ac_channels = ch; + cap_desc.caps.ac_format.hw = AUDIO_FMT_PCM; + + ioctl(fd, AUDIOIOC_CONFIGURE, (unsigned long)&cap_desc); + + /* Allocate an audio buffer */ + + desc.numbytes = 1024; + desc.u.ppBuffer = &apb; + + ret = apb_alloc(&desc); + ASSERT(ret == sizeof(desc)); + + signal(1, _signal_handler); + g_i2sloop_running = true; + + while (g_i2sloop_running) + { + bufsize = sizeof(struct ap_buffer_s) + apb->nmaxbytes; + ret = read(fd, apb, bufsize); + + if (0 < ret) + { + apb->nbytes = apb->nmaxbytes; + bufsize = sizeof(struct ap_buffer_s) + apb->nbytes; + ret = write(fd, apb, bufsize); + } + + } + + apb_free(apb); + close(fd); + + return EXIT_SUCCESS; +}