drivers/audio: Add CS4344 driver.

This commit is contained in:
Ouss4 2020-06-03 15:45:26 +01:00 committed by Alan Carvalho de Assis
parent d065bbe9b3
commit 8da4b02350
5 changed files with 1646 additions and 0 deletions

View File

@ -165,6 +165,39 @@ config CS43L22_CLKDEBUG
endif # AUDIO_CS43L22
config AUDIO_CS4344
bool "CS4344 audio chip"
default n
depends on AUDIO
---help---
Select to enable support for the CS4344 Audio codec by Cirrus Logic.
This chip is a lower level audio chip.. basically
an exotic D-to-A. It includes no built-in support for audio CODECS.
if AUDIO_CS4344
config CS4344_INFLIGHT
int "CS4344 maximum in-flight audio buffers"
default 2
config CS4344_MSG_PRIO
int "CS4344 message priority"
default 1
config CS4344_BUFFER_SIZE
int "CS4344 preferred buffer size"
default 8192
config CS4344_NUM_BUFFERS
int "CS4344 preferred number of buffers"
default 4
config CS4344_WORKER_STACKSIZE
int "CS4344 worker thread stack size"
default 768
endif # AUDIO_CS4344
config AUDIO_WM8776
bool "WM8776 audio chip"
default n

View File

@ -58,6 +58,10 @@ endif
endif
endif
ifeq ($(CONFIG_AUDIO_CS4344),y)
CSRCS += cs4344.c
endif
ifeq ($(CONFIG_AUDIO_WM8904),y)
CSRCS += wm8904.c
ifeq ($(CONFIG_WM8904_REGDUMP),y)

1370
drivers/audio/cs4344.c Normal file

File diff suppressed because it is too large Load Diff

98
drivers/audio/cs4344.h Normal file
View File

@ -0,0 +1,98 @@
/****************************************************************************
* drivers/audio/cs4344.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_AUDIO_CS4344_H
#define __DRIVERS_AUDIO_CS4344_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <pthread.h>
#include <mqueue.h>
#include <nuttx/wqueue.h>
#include <nuttx/fs/ioctl.h>
#ifdef CONFIG_AUDIO
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
#define CS4344_DEFAULT_SAMPRATE 11025 /* Initial sample rate */
#define CS4344_DEFAULT_NCHANNELS 1 /* Initial number of channels */
#define CS4344_DEFAULT_BPSAMP 16 /* Initial bits per sample */
/****************************************************************************
* Public Types
****************************************************************************/
struct cs4344_dev_s
{
/* We are an audio lower half driver (We are also the upper "half" of
* the CS4344 driver with respect to the board lower half driver).
*
* Terminology:
* Our "lower" half audio instances will be called dev for the publicly
* visible version and "priv" for the version that only this driver
* knows. From the point of view of this driver, it is the board lower
* "half" that is referred to as "lower".
*/
struct audio_lowerhalf_s dev; /* CS4344 audio lower half (this device) */
/* Our specific driver data goes here */
FAR struct i2s_dev_s *i2s; /* I2S driver to use */
struct dq_queue_s pendq; /* Queue of pending buffers to be sent */
struct dq_queue_s doneq; /* Queue of sent buffers to be returned */
mqd_t mq; /* Message queue for receiving messages */
char mqname[16]; /* Our message queue name */
pthread_t threadid; /* ID of our thread */
uint32_t bitrate; /* Actual programmed bit rate */
sem_t pendsem; /* Protect pendq */
uint16_t samprate; /* Configured samprate (samples/sec) */
uint8_t nchannels; /* Number of channels (1 or 2) */
uint8_t bpsamp; /* Bits per sample (8 or 16) */
volatile uint8_t inflight; /* Number of audio buffers in-flight */
bool running; /* True: Worker thread is running */
bool paused; /* True: Playing is paused */
bool mute; /* True: Output is muted */
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
bool terminating; /* True: Stop requested */
#endif
bool reserved; /* True: Device is reserved */
volatile int result; /* The result of the last transfer */
};
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* CONFIG_AUDIO */
#endif /* __DRIVERS_AUDIO_CS4344_H */

View File

@ -0,0 +1,141 @@
/****************************************************************************
* include/nuttx/audio/cs4344.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_AUDIO_CS4344_H
#define __INCLUDE_NUTTX_AUDIO_CS4344_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/irq.h>
#ifdef CONFIG_AUDIO_CS4344
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************
*
* CONFIG_AUDIO_CS4344 - Enables CS4344 support
* CONFIG_CS4344_INFLIGHT - Maximum number of buffers that the CS4344
* driver will send to the I2S driver before any have completed.
* CONFIG_CS4344_MSG_PRIO - Priority of messages sent to the CS4344
* worker thread.
* CONFIG_CS4344_BUFFER_SIZE - Preferred buffer size
* CONFIG_CS4344_NUM_BUFFERS - Preferred number of buffers
* CONFIG_CS4344_WORKER_STACKSIZE - Stack size to use when creating the the
* CS4344 worker thread.
* CONFIG_CS4344_REGDUMP - Enable logic to dump all CS4344 registers to
* the SYSLOG device.
*/
/* Pre-requisites */
#ifndef CONFIG_AUDIO
# error CONFIG_AUDIO is required for audio subsystem support
#endif
#ifndef CONFIG_I2S
# error CONFIG_I2S is required by the CS4344 driver
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
# error CONFIG_SCHED_WORKQUEUE is required by the CS4344 driver
#endif
/* Default configuration values */
#ifndef CONFIG_CS4344_INFLIGHT
# define CONFIG_CS4344_INFLIGHT 2
#endif
#if CONFIG_CS4344_INFLIGHT > 255
# error CONFIG_CS4344_INFLIGHT must fit in a uint8_t
#endif
#ifndef CONFIG_CS4344_MSG_PRIO
# define CONFIG_CS4344_MSG_PRIO 1
#endif
#ifndef CONFIG_CS4344_BUFFER_SIZE
# define CONFIG_CS4344_BUFFER_SIZE 8192
#endif
#ifndef CONFIG_CS4344_NUM_BUFFERS
# define CONFIG_CS4344_NUM_BUFFERS 4
#endif
#ifndef CONFIG_CS4344_WORKER_STACKSIZE
# define CONFIG_CS4344_WORKER_STACKSIZE 768
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: cs4344_initialize
*
* Description:
* Initialize the CS4344 device.
*
* Input Parameters:
* i2s - An I2S driver instance
* lower - Persistent board configuration data
*
* Returned Value:
* A new lower half audio interface for the CS4344 device is returned on
* success; NULL is returned on failure.
*
****************************************************************************/
struct i2s_dev_s; /* Forward reference. Defined in include/nuttx/audio/i2s.h */
struct audio_lowerhalf_s; /* Forward reference. Defined in nuttx/audio/audio.h */
FAR struct audio_lowerhalf_s * cs4344_initialize(FAR struct i2s_dev_s *i2s);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_AUDIO_CS4344 */
#endif /* __INCLUDE_NUTTX_AUDIO_CS4344_H */