#Daisy 16 Audio Adapter

<div class="text-success lead">
Audio interface for FOX Board G20
</div>

@include='daisy_eol'

This module is designed for the FOX Board G20 and is not compatible with the Aria and Arietta G25
boards.

The audio codec used is the WM8731, is low power stereo codec with an integrated headphone driver, stereo line-out, stereo line-in and mono microphone level audio inputs.

*WM8731 Codecs is supported by the Linux kernel and works with alsa drivers.*

<img width="320px" src="DAISY-16.jpg" title="Daisy16"/>

Dimension: 40x40mm

## WM8731 Codec Features

* Stereo 24-bit, multi-bit sigma delta ADCs and DACs are used with oversampling digital interpolation and decimation filters.
* Highly Efficient Headphone Driver
* Audio Performance : ADC SNR 90dB at 3.3V , DAC SNR 100dB at 3.3V
* Low Power : Playback only 22mW
* Selectable ADC High Pass Filter
* Microphone Input and Electret Bias with Side Tone Mixer

## Communication between Fox Board and Codecs

<img style="float:left;margin-left:20px;" src="./communication_schem.png"/>

<table cellpadding="0" cellspacing="0" border ="0" bordercolor="white" style="float:left;margin-top:10px;margin-left:20px;">
<tr><td><center><h3>Audio Interface</h3></center></td></tr>
<tr><td>
<table class="basic">
<tr> <th>PB16</th><th>PB17</th><th>PB18</th><th>PB19</th><th>PB21</th> </tr>
<tr> <td>TK0 </td><td>TF0 </td><td>TD0 </td><td>RD0 </td><td>RF0 </td> </tr>
</table>
</td></tr>
</table>

<table cellpadding="0" cellspacing="0" border="0" bordercolor="white" style="float:left;margin-top:10px;margin-left:20px;">
<tr><td><center><h3>Control Interface</h3></center></td></tr>
<tr><td>
<center>
<table class="basic">
<tr> <th>PA23</th><th>PA24</th> </tr>
<tr> <td>SDA </td><td>SCL </td> </tr>
</table>
</center>
</table>
</td></tr>
</table>

<p style="margin-top:140px;margin-left:170px;position:absolute;">
The communication between the Fox Board and the Codec is done by SSC (Synchronous Serial Controller) for the audio interface (<b>Daisy D5 to J2</b>) and TWI (I2C) for control interface (<b>Daisy D6 to J1</b>).<br>
PB31 (PCK1) provides Master Clock to codec.<br>
RK0 is not used so PB20 control the Play-LED
</p>
<div style="height:250px"></div>

## Add audio support to the Linux Kernel for the Daisy16

WM8731 codecs is supported in the linux kernel but to be used with the Daisy16 needs some changes. You must apply an additional patch.

### Precompiled Kernel Image

Files to store in the first FAT16 partition:

* Kernel 2.6.35.4 image [daisy16_2.6.35.4_uImage](http://www.acmesystems.it/download/daisy16/daisy16_26354_uImage) (MD5:daf39e532a84e1a29f764efbe31a4e05)
* Kernel 2.6.38   image [daisy16_2.6.38_uImage](http://www.acmesystems.it/download/daisy16/daisy16_2638_uImage) (MD5:74ba68dd909db3edb2ab73bff9707250)

### How to apply Madefree patch and compile kernel

**Linux kernel 2.6.35.4**

* Download the kernel sources and apply Acme Systems patch:
<pre class="minicom">
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.35.4.tar.bz2
tar -xjvf linux-2.6.35.4.tar.bz2
cd linux-2.6.35.4
wget http://www.acmesystems.it/foxg20/download/kernel/0003-Acme-Systems-board-files.patch
patch -p1 < 0003-Acme-Systems-board-files.patch
wget http://www.acmesystems.it/foxg20/download/kernel/makefile
</pre>
* Download the Madefree Patch [daisy16_26354.tar.gz](http://www.acmesystems.it/download/daisy16/daisy16_26354.tar.gz) (MD5:8e5ede6d218e34574c71cfdbcb880dfc)
* Apply the patch:
<pre class="minicom">
tar -xzvf daisy16_26354.tar.gz
patch -p1 < daisy16_26354/daisy16_26354.patch
</pre>
* Then copy the .config to use the last Madefree factory default configuration files:
<pre class="minicom">
cp daisy16_26354/daisy16_26354.config .config
</pre>
* Configuring kernel (if you need):
<pre class="minicom">
make menuconfig
</pre>
* Building kernel:
<pre class="minicom">
make
</pre>

**Linux kernel 2.6.38**

* Download the kernel sources:
<pre class="minicom">
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.tar.bz2
tar -xjvf linux-2.6.38.tar.bz2
cd linux-2.6.38
wget http://foxg20.acmesystems.it/download/kernel_2.6.38/makefile
</pre>
* Download the Madefree Patch [daisy16_2638.tar.gz](http://www.acmesystems.it/download/daisy16/daisy16_2638.tar.gz) (MD5:c9f75aca53b6858c3c82edd5a497b718)
* Apply the patch:
<pre class="minicom">
tar -xzvf daisy16_2638.tar.gz
patch -p1 < daisy16_2638/daisy16_2638.patch
</pre>
* Then copy the .config to use the last Madefree factory default configuration files:
<pre class="minicom">
cp daisy16_2638/daisy16_2638.config .config
</pre>
* Configuring kernel (if you need):
<pre class="minicom">
make menuconfig
</pre>
* Building kernel:
<pre class="minicom">
make
</pre>

## Check the functionalities

* Check *dmesg* after boot:
<pre class="minicom">
...
ssc ssc.0: Atmel SSC device at 0xc48a0000 (irq 14)
...
netusG20_wm8731 : daisy16: wm8731__init() called
asoc: wm8731-hifi <-> atmel-ssc-dai.0 mapping ok
ALSA device list:
  #0: DAISY16
...
</pre>
* Install *alsa-utils*:
<pre class="minicom">
apt-get install alsa-utils
</pre>
* Run *alsamixer*:
<pre class="minicom">
alsamixer -V all
</pre>
* Configure *alsa* like this:

<img src="./alsa_conf.png" width="600"/>

* Launch recording for 5sec. stereo wav acquisition and play what you recorded:
<pre class="minicom">
arecord -d 5 -v -v -Dhw:0,0 -f cd record_line_in.wav
aplay record_line_in.wav
</pre>

## Play your music library

A great console music player is [cmus](http://cmus.sourceforge.net/).
<pre class="minicom">
apt-get install cmus
cmus
</pre>

Change output plugin (from cmus command line)
<pre class="minicom">
:set output_plugin=ao
</pre>

Cmus has a syntax very similar to vim:
<pre class="minicom">
:add 'directory_audio'  # add audio file to playlist
:q  # exit to cmus
z  # previous
x  # play
c  # pause
v  # stop
b  # next
^L # refresh
n  # search-next
r  # toggle repeat
1  # view tree
2  # view sorted
3  # view playlist
4  # view queue
5  # view browser
6  # view filters
7  # view settings
+  # vol +10%
-  # vol -10%
</pre>

<img src="./cmus.png"/>

## Playing in remote access

You can use Music Player Daemon (MPD) to allow remote access for playing audio files (Ogg-Vorbis, FLAC, MP3, Wave, and AIFF), streams (Ogg-Vorbis, MP3) and managing playlists.

* Install mpd
<pre class="minicom">
apt-get install mpd
</pre>

* Stop mpd daemon
<pre class="minicom">
/etc/init.d/mpd stop
</pre>

* Configure /etc/mpd.conf more info [here](http://mpd.wikia.com/wiki/Configuration), we have create an adhoc config file for you [mpd.conf](http://www.madefree.eu/download/daisy16/mpd.conf) (MD5:a52a320d5e609b0265091ee276587d39)
<pre class="minicom">
cp mpd.conf /etc/mpd.conf
</pre>

* Create database
<pre class="minicom">
mpd --create-db
</pre>

* Start mpd daemon
<pre class="minicom">
/etc/init.d/mpd start
</pre>

default directory to store your music is /var/lib/mpd/music/

Now connect the server with the client you want, a list [here](http://mpd.wikia.com/wiki/Clients).
Configure the client with right IP address of the server and *mpd* as password.

<iframe width="320" height="240" src="http://www.youtube.com/embed/VHWEIl3bI9I" frameborder="0" allowfullscreen></iframe>

In this video we chose as client [MPDroid](https://play.google.com/store/apps/details?id=com.namelessdev.mpdroid&hl=it) for Android phone and [Theremin](http://theremin.sigterm.eu/) for Mac...

## Related links

* [Schematic in pdf format](http://terzo.acmesystems.it/download/schematics/schematic_daisy16.pdf)
* [WM8731 Datasheet](http://www.wolfsonmicro.com/documents/uploads/data_sheets/en/WM8731.pdf)

