diff options
-rw-r--r-- | nuttx/audio/Makefile | 2 | ||||
-rw-r--r-- | nuttx/audio/README.txt | 12 | ||||
-rw-r--r-- | nuttx/audio/pcm_decode.c | 564 | ||||
-rw-r--r-- | nuttx/configs/sama5d4-ek/include/board.h | 23 | ||||
-rw-r--r-- | nuttx/configs/sama5d4-ek/src/sam_nsh.c | 24 | ||||
-rw-r--r-- | nuttx/configs/sama5d4-ek/src/sam_wm8904.c | 46 | ||||
-rw-r--r-- | nuttx/configs/sama5d4-ek/src/sama5d4-ek.h | 5 | ||||
-rw-r--r-- | nuttx/include/nuttx/audio/audio.h | 17 | ||||
-rw-r--r-- | nuttx/include/nuttx/audio/pcm_decode.h (renamed from nuttx/audio/pcm.c) | 88 |
9 files changed, 708 insertions, 73 deletions
diff --git a/nuttx/audio/Makefile b/nuttx/audio/Makefile index b95e3900b..33b3a26a7 100644 --- a/nuttx/audio/Makefile +++ b/nuttx/audio/Makefile @@ -50,7 +50,7 @@ VPATH = . # the appropriate paths to the VPATH variable ifeq ($(CONFIG_AUDIO_FORMAT_PCM),y) - CSRCS += pcm.c + CSRCS += pcm_decode.c endif AOBJS = $(ASRCS:.S=$(OBJEXT)) diff --git a/nuttx/audio/README.txt b/nuttx/audio/README.txt index be86cacb0..85ab2e1a3 100644 --- a/nuttx/audio/README.txt +++ b/nuttx/audio/README.txt @@ -17,12 +17,12 @@ This directory holds the NuttX audio subsystem upper-half. The upper-half provi a common interface for applications to interface with and also defines a bind layer for specific lower-half audio device drivers. - audio.c - The upper-half driver that binds to a lower-half driver from the - drivers/audio subdirectory. For each attached audio device, there - will be an instance of this upper-half driver bound to the - instance of the lower half driver context. - pcm.c - Routines to manage PCM / WAV type data. Currently just a placeholder. - README - This file! + audio.c - The upper-half driver that binds to a lower-half driver from the + drivers/audio subdirectory. For each attached audio device, there + will be an instance of this upper-half driver bound to the + instance of the lower half driver context. + pcm_decode.c - Routines to decode PCM / WAV type data. + README - This file! Portions of the the audio system interface have application interfaces. Those portions reside in the nuttx/libc/audio directory where the will be built for diff --git a/nuttx/audio/pcm_decode.c b/nuttx/audio/pcm_decode.c new file mode 100644 index 000000000..ba817a313 --- /dev/null +++ b/nuttx/audio/pcm_decode.c @@ -0,0 +1,564 @@ +/**************************************************************************** + * audio/pcm_decode.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * Based on the original audio framework from: + * + * Author: Ken Pettit <pettitkd@gmail.com> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <semaphore.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/kmalloc.h> +#include <nuttx/audio/audio.h> +#include <nuttx/audio/pcm_decode.h> + +#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ +/* This structure describes the internal state of the PCM decoder */ + +struct pcm_decode_s +{ + /* This is is our our appearance to the outside world. This *MUST* be the + * first element of the structure so that we can freely cast between types + * struct audio_lowerhalf and struct pcm_decode_s. + */ + + struct audio_lowerhalf_s export; + + /* These are our operations that intervene between the player application + * and the lower level driver. Unlike the ops in the struct + * audio_lowerhalf_s, these are writeable because we need to customize a + * few of the methods based upon what is supported by the the lower level + * driver. + */ + + struct audio_ops_s ops; + + /* This is the contained, low-level DAC-type device and will receive the + * decoded PCM audio data. + */ + + FAR struct audio_lowerhalf_s *lower; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* struct audio_lowerhalf_s methods *****************************************/ + +static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type, + FAR struct audio_caps_s *caps); + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_configure(FAR struct audio_lowerhalf_s *dev, + FAR void *session, FAR const struct audio_caps_s *caps); +#else +static int pcm_configure(FAR struct audio_lowerhalf_s *dev, + FAR const struct audio_caps_s *caps); +#endif + +static int pcm_shutdown(FAR struct audio_lowerhalf_s *dev); + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_start(FAR struct audio_lowerhalf_s *dev, FAR void *session); +#else +static int pcm_start(FAR struct audio_lowerhalf_s *dev); +#endif + +#ifndef CONFIG_AUDIO_EXCLUDE_STOP +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session); +#else +static int pcm_stop(FAR struct audio_lowerhalf_s *dev); +#endif +#endif + +#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session); +#else +static int pcm_pause(FAR struct audio_lowerhalf_s *dev); +#endif + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session); +#else +static int pcm_resume(FAR struct audio_lowerhalf_s *dev); +#endif +#endif + +static int pcm_allocbuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct audio_buf_desc_s *apb); +static int pcm_freebuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct audio_buf_desc_s *apb); +static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct ap_buffer_s *apb); +static int pcm_cancelbuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct ap_buffer_s *apb); +static int pcm_ioctl(FAR struct audio_lowerhalf_s *dev, + int cmd, unsigned long arg); + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_reserve(FAR struct audio_lowerhalf_s *dev, FAR void **session); +#else +static int pcm_reserve(FAR struct audio_lowerhalf_s *dev); +#endif + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_release(FAR struct audio_lowerhalf_s *dev, FAR void *session); +#else +static int pcm_release(FAR struct audio_lowerhalf_s *dev); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pcm_getcaps + * + * Description: + * This method is called to retrieve the lower-half device capabilities. + * It will be called with device type AUDIO_TYPE_QUERY to request the + * overall capabilities, such as to determine the types of devices supported + * audio formats supported, etc. Then it may be called once or more with + * reported supported device types to determine the specific capabilities + * of that device type (such as MP3 encoder, WMA encoder, PCM output, etc.). + * + ****************************************************************************/ + +static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type, + FAR struct audio_caps_s *caps) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_configure + * + * Description: + * This method is called to bind the lower-level driver to the upper-level + * driver and to configure the driver for a specific mode of + * operation defined by the parameters selected in supplied device caps + * structure. The lower-level device should perform any initialization + * needed to prepare for operations in the specified mode. It should not, + * however, process any audio data until the start method is called. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_configure(FAR struct audio_lowerhalf_s *dev, + FAR void *session, FAR const struct audio_caps_s *caps) +#else +static int pcm_configure(FAR struct audio_lowerhalf_s *dev, + FAR const struct audio_caps_s *caps) +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_shutdown + * + * Description: + * This method is called when the driver is closed. The lower half driver + * should stop processing audio data, including terminating any active + * output generation. It should also disable the audio hardware and put + * it into the lowest possible power usage state. + * + * Any enqueued Audio Pipeline Buffers that have not been processed / dequeued + * should be dequeued by this function. + * + ****************************************************************************/ + +static int pcm_shutdown(FAR struct audio_lowerhalf_s *dev) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_start + * + * Description: + * Start audio streaming in the configured mode. For input and synthesis + * devices, this means it should begin sending streaming audio data. For output + * or processing type device, it means it should begin processing of any enqueued + * Audio Pipeline Buffers. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_start(FAR struct audio_lowerhalf_s *dev, FAR void *session) +#else +static int pcm_start(FAR struct audio_lowerhalf_s *dev) +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_stop + * + * Description: + * Stop audio streaming and/or processing of enqueued Audio Pipeline + * Buffers + * + ****************************************************************************/ + +#ifndef CONFIG_AUDIO_EXCLUDE_STOP +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session) +#else +static int pcm_stop(FAR struct audio_lowerhalf_s *dev) +#endif +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_pause + * + * Description: + * Pause the audio stream. Should keep current playback context active + * in case a resume is issued. Could be called and then followed by a stop. + * + ****************************************************************************/ + +#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session) +#else +static int pcm_pause(FAR struct audio_lowerhalf_s *dev) +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_resume + * + * Description: + * Resumes audio streaming after a pause. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_resume(FAR struct audio_lowerhalf_s *dev, FAR void *session) +#else +static int pcm_resume(FAR struct audio_lowerhalf_s *dev) +#endif +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_allocbuffer + * + * Description: + * Allocate an audio pipeline buffer. This routine provides the + * lower-half driver with the opportunity to perform special buffer + * allocation if needed, such as allocating from a specific memory + * region (DMA-able, etc.). If not supplied, then the top-half + * driver will perform a standard kumalloc using normal user-space + * memory region. + * + ****************************************************************************/ + +static int pcm_allocbuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct audio_buf_desc_s *apb) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; + FAR struct audio_lowerhalf_s *lower; + + DEBUGASSERT(priv); + + /* Defer the operation to the lower device driver */ + + lower = priv->lower; + DEBUGASSERT(lower && lower->ops->allocbuffer); + return lower->ops->allocbuffer(lower, apb); +} + +/**************************************************************************** + * Name: pcm_freebuffer + * + * Description: + * Free an audio pipeline buffer. If the lower-level driver + * provides an allocbuffer routine, it should also provide the + * freebuffer routine to perform the free operation. + * + ****************************************************************************/ + +static int pcm_freebuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct audio_buf_desc_s *apb) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; + FAR struct audio_lowerhalf_s *lower; + + DEBUGASSERT(priv); + + /* Defer the operation to the lower device driver */ + + lower = priv->lower; + DEBUGASSERT(lower && lower->ops->freebuffer); + return lower->ops->freebuffer(lower, apb); +} + +/**************************************************************************** + * Name: pcm_enqueuebuffer + * + * Description: + * Enqueue a buffer for processing. This is a non-blocking enqueue operation. + * If the lower-half driver's buffer queue is full, then it should return an + * error code of -ENOMEM, and the upper-half driver can decide to either block + * the calling thread or deal with it in a non-blocking manner. + * + * For each call to enqueuebuffer, the lower-half driver must call + * audio_dequeuebuffer when it is finished processing the bufferr, passing the + * previously enqueued apb and a dequeue status so that the upper-half driver + * can decide if a waiting thread needs to be release, if the dequeued buffer + * should be passed to the next block in the Audio Pipeline, etc. + * + ****************************************************************************/ + +static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct ap_buffer_s *apb) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_cancelbuffer + * + * Description: + * Cancel a previously enqueued buffer. + * + ****************************************************************************/ + +static int pcm_cancelbuffer(FAR struct audio_lowerhalf_s *dev, + FAR struct ap_buffer_s *apb) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_ioctl + * + * Description: + * Lower-half logic may support platform-specific ioctl commands. + * + ****************************************************************************/ + +static int pcm_ioctl(FAR struct audio_lowerhalf_s *dev, + int cmd, unsigned long arg) +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_reserve + * + * Description: + * Reserve a session (may only be one per device or may be multiple) for + * use by a client. Client software can open audio devices and issue + * AUDIOIOC_GETCAPS calls freely, but other operations require a + * reservation. A session reservation will assign a context that must + * be passed with + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_reserve(FAR struct audio_lowerhalf_s *dev, FAR void **session) +#else +static int pcm_reserve(FAR struct audio_lowerhalf_s *dev) +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Name: pcm_release + * + * Description: + * Release a session. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_MULTI_SESSION +static int pcm_release(FAR struct audio_lowerhalf_s *dev, FAR void *session) +#else +static int pcm_release(FAR struct audio_lowerhalf_s *dev) +#endif +{ + FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; +#warning Missing logic + return -ENOSYS; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pcm_decode_initialize + * + * Description: + * Initialize the PCM device. The PCM device accepts and contains a + * low-level audio DAC-type device. It then returns a new audio lower + * half interface at adds a PCM decoding from end to the low-level + * audio device + * + * Input Parameters: + * dev - A reference to the low-level audio DAC-type device to contain. + * + * Returned Value: + * On success, a new audio device instance is returned that wraps the + * low-level device and provides a PCM decoding front end. NULL is + * returned on failure. + * + ****************************************************************************/ + +FAR struct audio_lowerhalf_s * + pcm_decode_initialize(FAR struct audio_lowerhalf_s *dev) +{ + FAR struct pcm_decode_s *priv; + FAR struct audio_ops_s *ops; + + /* Allocate an instance of our private data structure */ + + priv = (FAR struct pcm_decode_s *)kzalloc(sizeof(struct pcm_decode_s)); + if (!priv) + { + auddbg("ERROR: Failed to allocate driver structure\n"); + return NULL; + } + + /* Initialize our private data structure. Since kzalloc() was used for + * the allocation, we need to initialize only non-zero, non-NULL, non- + * false fields. + */ + + ops = &priv->ops; + ops->getcaps = pcm_getcaps; + ops->configure = pcm_configure; + ops->shutdown = pcm_shutdown; + ops->start = pcm_start; + +#ifndef CONFIG_AUDIO_EXCLUDE_STOP + ops->stop = pcm_stop; +#endif + +#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME + ops->pause = pcm_pause; + ops->resume = pcm_resume; +#endif + + if (dev->ops->allocbuffer) + { + DEBUGASSERT(dev->ops->freebuffer); + ops->allocbuffer = pcm_allocbuffer; + ops->freebuffer = pcm_freebuffer; + } + + ops->enqueuebuffer = pcm_enqueuebuffer; + ops->cancelbuffer = pcm_cancelbuffer; + ops->ioctl = pcm_ioctl; + ops->reserve = pcm_reserve; + ops->release = pcm_release; + + priv->export.ops = &priv->ops; + priv->export.priv = priv; + priv->lower = dev; + + return &priv->export; +} + +#endif /* CONFIG_AUDIO && CONFIG_AUDIO_FORMAT_PCM */ + diff --git a/nuttx/configs/sama5d4-ek/include/board.h b/nuttx/configs/sama5d4-ek/include/board.h index 9f3b8abef..b1507a5d6 100644 --- a/nuttx/configs/sama5d4-ek/include/board.h +++ b/nuttx/configs/sama5d4-ek/include/board.h @@ -243,11 +243,26 @@ #define PIO_SSC0_TD PIO_SSC0_TD_2 -/* PCK0 is provided to the WM8904 audio CODEC via PB26 */ +/* PCK2 is provides the MCLK to the WM8904 audio CODEC via PB10 */ -#ifdef CONFIG_AUDIO_WM8904 -# define PIO_PMC_PCK0 PIO_PMC_PCK0_1 -#endif +#define PIO_PMC_PCK2 PIO_PMC_PCK2_1 + +/* PCK0 and PCK1 are not currently used, but the PCK logic wants these definitions + * anyway. The assignments here are arbitrary and will not be used (at least not + * until we implement ISI of HDMI). + * + * PIO_PMC_PCK0_1: PB26 is used by I2S with the WM8904 (AUDIO_RK0_PB26) + * PIO_PMC_PCK0_2: PD8 is the HDMI MCLK (HDMI_MCK_PD8) + * PIO_PMC_PCK0_3: PA24 is used for the LCD backlight (LCD_PWM_PA24) + * + * PIO_PMC_PCK1_1: PD31 goes to the expansion interface and is not used on-board + * (EXP_PD31). + * PIO_PMC_PCK1_2: PC24 is used for ISI data (ISI_D5) + * PIO_PMC_PCK1_3: PC4 is ISI_MCK_PC4, MCI0_CK_PC4, EXP_PC4 + */ + +#define PIO_PMC_PCK0 PIO_PMC_PCK0_2 +#define PIO_PMC_PCK1 PIO_PMC_PCK1_1 /************************************************************************************ * Assembly Language Macros diff --git a/nuttx/configs/sama5d4-ek/src/sam_nsh.c b/nuttx/configs/sama5d4-ek/src/sam_nsh.c index aeb4fe75b..76ccb2824 100644 --- a/nuttx/configs/sama5d4-ek/src/sam_nsh.c +++ b/nuttx/configs/sama5d4-ek/src/sam_nsh.c @@ -87,7 +87,7 @@ int nsh_archinitialize(void) { #if defined(HAVE_NAND) || defined(HAVE_AT25) || defined(HAVE_HSMCI) || \ - defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) + defined(HAVE_USBHOST) || defined(HAVE_USBMONITOR) || defined(HAVE_WM8904) int ret; #endif @@ -98,7 +98,6 @@ int nsh_archinitialize(void) if (ret < 0) { message("ERROR: sam_nand_automount failed: %d\n", ret); - return ret; } #endif @@ -109,7 +108,6 @@ int nsh_archinitialize(void) if (ret < 0) { message("ERROR: sam_at25_automount failed: %d\n", ret); - return ret; } #endif @@ -122,7 +120,6 @@ int nsh_archinitialize(void) { message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", HSMCI0_SLOTNO, HSMCI0_MINOR, ret); - return ret; } #endif @@ -134,7 +131,6 @@ int nsh_archinitialize(void) { message("ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n", HSMCI1_SLOTNO, HSMCI1_MINOR, ret); - return ret; } #endif #endif @@ -148,7 +144,6 @@ int nsh_archinitialize(void) if (ret != OK) { message("ERROR: Failed to initialize USB host: %d\n", ret); - return ret; } #endif @@ -158,9 +153,24 @@ int nsh_archinitialize(void) ret = usbmonitor_start(0, NULL); if (ret != OK) { - message("nsh_archinitialize: Start USB monitor: %d\n", ret); + message("ERROR: Failed to start the USB monitor: %d\n", ret); } #endif +#ifdef HAVE_WM8904 + /* Start the USB Monitor */ + + ret = sam_wm8904_initialize(0); + if (ret != OK) + { + message("ERROR: Failed to initialize WM8904 audio: %d\n", ret); + } +#endif + + /* If we got here then perhaps not all initialization was successful, but + * at least enough succeeded to bring-up NSH with perhaps reduced + * capabilities. + */ + return OK; } diff --git a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c index 09ea542ff..012d33f82 100644 --- a/nuttx/configs/sama5d4-ek/src/sam_wm8904.c +++ b/nuttx/configs/sama5d4-ek/src/sam_wm8904.c @@ -48,6 +48,7 @@ #include <nuttx/i2c.h> #include <nuttx/audio/i2s.h> #include <nuttx/audio/wm8904.h> +#include <nuttx/audio/pcm_decode.h> #include <arch/board/board.h> @@ -220,11 +221,12 @@ static int wm8904_interrupt(int irq, FAR void *context) int sam_wm8904_initialize(int minor) { - FAR struct audio_lowerhalf_s *audio; + FAR struct audio_lowerhalf_s *wm8904; + FAR struct audio_lowerhalf_s *pcm; FAR struct i2c_dev_s *i2c; FAR struct i2s_dev_s *i2s; static bool initialized = false; - char devname[8]; + char devname[12]; int ret; auddbg("minor %d\n", minor); @@ -266,21 +268,20 @@ int sam_wm8904_initialize(int minor) * MW8904 which will return an audio interface. */ - audio = wm8904_initialize(i2c, i2s, &g_mxtinfo.lower, minor); - if (!audio) + wm8904 = wm8904_initialize(i2c, i2s, &g_mxtinfo.lower); + if (!wm8904) { auddbg("Failed to initialize the WM8904\n"); ret = -ENODEV; goto errout_with_i2s; } - /* Configure the DAC master clock. This clock is provided by PCK0 (PB26) - * that is connected to the WM8904 BCLK/GPIO4 and also drives the SSC - * TK0 input clock. + /* Configure the DAC master clock. This clock is provided by PCK2 (PB10) + * that is connected to the WM8904 MCLK. */ sam_sckc_enable(true); - (void)sam_pck_configure(PCK0, PCKSRC_SCK, BOARD_SLOWCLK_FREQUENCY); + (void)sam_pck_configure(PCK2, PCKSRC_SCK, BOARD_SLOWCLK_FREQUENCY); /* Enable the DAC master clock */ @@ -292,21 +293,37 @@ int sam_wm8904_initialize(int minor) ret = irq_attach(IRQ_INT_WM8904, wm8904_interrupt); if (ret < 0) { - auddbg("ERROR: Failed to register WM8904 device: %d\n", ret); + auddbg("ERROR: Failed to attach WM8904 interrupt: %d\n", ret); goto errout_with_audio; } + /* No we can embed the WM8904/I2C/I2S conglomerate into a PCM decoder + * instance so that we will have a PCM front end for the the WM8904 + * driver. + */ + + pcm = pcm_decode_initialize(wm8904); + if (!pcm) + { + auddbg("ERROR: Failed create the PCM decoder\n"); + ret = -ENODEV; + goto errout_with_irq; + } + /* Create a device name */ - snprintf(devname, 8, "wm8904%c", 'a' + minor); + snprintf(devname, 12, "pcm%d", minor); - /* Register the WM8904 audio device */ + /* Finally, we can register the PCM/WM8904/I2C/I2S audio device. + * + * Is anyone young enough to remember Rube Goldberg? + */ - ret = audio_register(devname, audio); + ret = audio_register(devname, pcm); if (ret < 0) { auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret); - goto errout_with_irq; + goto errout_with_pcm; } /* Now we are initialized */ @@ -317,9 +334,10 @@ int sam_wm8904_initialize(int minor) return OK; /* Error exits. Unfortunately there is no mechanism in place now to - * recover errors on initialization failures. + * recover from most errors on initialization failures. */ +errout_with_pcm: errout_with_irq: irq_detach(IRQ_INT_WM8904); errout_with_audio: diff --git a/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h b/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h index 5286716b5..5e6a71d94 100644 --- a/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h +++ b/nuttx/configs/sama5d4-ek/src/sama5d4-ek.h @@ -334,6 +334,11 @@ # undef HAVE_WM8904 # endif +# ifndef CONFIG_AUDIO_FORMAT_PCM +# warning CONFIG_AUDIO_FORMAT_PCM is required for audio support +# undef HAVE_WM8904 +# endif + # ifndef CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY # warning Defaulting to maximum WM8904 I2C frequency # define CONFIG_SAMA5D4EK_WM8904_I2CFREQUENCY 400000 diff --git a/nuttx/include/nuttx/audio/audio.h b/nuttx/include/nuttx/audio/audio.h index 128005b49..162db9ad3 100644 --- a/nuttx/include/nuttx/audio/audio.h +++ b/nuttx/include/nuttx/audio/audio.h @@ -287,9 +287,9 @@ /* Define the size of AP Buffer sample count base on CONFIG */ #ifdef CONFIG_AUDIO_LARGE_BUFFERS -typedef uint32_t apb_samp_t; +typedef uint32_t apb_samp_t; #else -typedef uint16_t apb_samp_t; +typedef uint16_t apb_samp_t; #endif /* This structure is used to describe the audio device capabilities */ @@ -375,8 +375,7 @@ struct audio_msg_s } u; }; - -/* Strucure defining the built-in sounds */ +/* Structure defining the built-in sounds */ #ifdef CONFIG_AUDIO_BUILTIN_SOUNDS struct audio_sound_s @@ -390,7 +389,7 @@ struct audio_sound_s #endif -/* Structure for allocating, freeing and enqueuing audio pipeline +/* Structure for allocating, freeing and enqueueing audio pipeline * buffers via the AUDIOIOC_ALLOCBUFFER, AUDIOIOC_FREEBUFFER, * and AUDIOIOC_ENQUEUEBUFFER ioctls. */ @@ -404,7 +403,7 @@ struct audio_buf_desc_s union { FAR struct ap_buffer_s *pBuffer; /* Buffer to free / enqueue */ - FAR struct ap_buffer_s **ppBuffer; /* Pointer to receive alloced buffer */ + FAR struct ap_buffer_s **ppBuffer; /* Pointer to receive allocated buffer */ } u; }; @@ -467,7 +466,7 @@ struct audio_ops_s /* Start audio streaming in the configured mode. For input and synthesis * devices, this means it should begin sending streaming audio data. For output * or processing type device, it means it should begin processing of any enqueued - * Audio Pipline Buffers. + * Audio Pipeline Buffers. */ #ifdef CONFIG_AUDIO_MULTI_SESSION @@ -568,7 +567,7 @@ struct audio_ops_s */ #ifdef CONFIG_AUDIO_MULTI_SESSION - CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev, FAR void **psession ); + CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev, FAR void **psession); #else CODE int (*reserve)(FAR struct audio_lowerhalf_s *dev); #endif @@ -576,7 +575,7 @@ struct audio_ops_s /* Release a session. */ #ifdef CONFIG_AUDIO_MULTI_SESSION - CODE int (*release)(FAR struct audio_lowerhalf_s *dev, FAR void *session ); + CODE int (*release)(FAR struct audio_lowerhalf_s *dev, FAR void *session); #else CODE int (*release)(FAR struct audio_lowerhalf_s *dev); #endif diff --git a/nuttx/audio/pcm.c b/nuttx/include/nuttx/audio/pcm_decode.h index aeb1b7b64..300c8c908 100644 --- a/nuttx/audio/pcm.c +++ b/nuttx/include/nuttx/audio/pcm_decode.h @@ -1,8 +1,8 @@ /**************************************************************************** - * audio/pcm.c + * include/nuttx/audio/pcm_decode.h * - * Copyright (C) 2013 Ken Pettit. All rights reserved. - * Author: Ken Pettit <pettitkd@gmail.com> + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,62 +33,86 @@ * ****************************************************************************/ +#ifndef __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H +#define __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H + /**************************************************************************** * Included Files ****************************************************************************/ -#include <nuttx/config.h> - -#include <sys/types.h> #include <stdint.h> #include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <semaphore.h> -#include <errno.h> -#include <debug.h> -#include <nuttx/kmalloc.h> -#include <nuttx/audio/audio.h> +#include <nuttx/irq.h> -#if defined(CONFIG_AUDIO) && defined(CONFIG_AUDIO_FORMAT_PCM) +#ifdef CONFIG_AUDIO_FORMAT_PCM /**************************************************************************** - * Preprocessor Definitions + * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************ + * + * CONFIG_AUDIO_FORMAT_PCM - Enabled PCM support + */ -/* Configuration ************************************************************/ +/* Pre-requisites */ -/**************************************************************************** - * Private Types - ****************************************************************************/ +#ifndef CONFIG_AUDIO +# error CONFIG_AUDIO is required for PCM support +#endif + +#ifndef CONFIG_SCHED_WORKQUEUE +# error CONFIG_SCHED_WORKQUEUE is required by the PCM driver +#endif + +/* Default configuration values */ /**************************************************************************** - * Private Variables + * Public Types ****************************************************************************/ -/**************************************************************************** - * Public Variables + /**************************************************************************** + * Public Data ****************************************************************************/ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /**************************************************************************** - * Private Functions + * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: audio_pcm_init + * Name: pcm_decode_initialize + * + * Description: + * Initialize the PCM device. The PCM device accepts and contains a + * low-level audio DAC-type device. It then returns a new audio lower + * half interface at adds a PCM decoding from end to the low-level + * audio device * - * Initialized the Audio PCM library. + * Input Parameters: + * dev - A reference to the low-level audio DAC-type device to contain. + * + * Returned Value: + * On success, a new audio device instance is returned that wraps the + * low-level device and provides a PCM decoding front end. NULL is + * returned on failure. * ****************************************************************************/ -int audio_pcm_initialize(void) -{ - /* Initialze the Audio PCM routines */ +FAR struct audio_lowerhalf_s * + pcm_decode_initialize(FAR struct audio_lowerhalf_s *dev); - return OK; +#undef EXTERN +#ifdef __cplusplus } +#endif -#endif /* CONFIG_AUDIO && CONFIG_AUDIO_FORMAT_PCM */ - +#endif /* CONFIG_AUDIO_FORMAT_PCM */ +#endif /* __INCLUDE_NUTTX_AUDIO_PCM_DECODE_H */ |