----------------------------------------------------------------------------------------
主机操作系统:centos 6.7
交叉编译器版本:arm-linux-gcc-4.5.4
开发板平台:fl2440
linux内核版本:Linux-3.0
Author: shaocongshuai <[email protected]>
-----------------------------------------------------------------------------------------------------------------
一、在初始化文件中加入UDA1341 设备结构
Linux-3.0 已经完美的支持UDA1341 音频芯片的驱动。 UDA1341音频芯片,走的标准的IIS总线,Linux中对IIS及UDA1341的支持已经非常完善了,我们只需要将相应的IIS管脚设置为我们开发板的原理图设计的管脚就可以了。我们只要在/arch/arm/mach-s3c2440/mach-smdk2440.c文件中注册UDA1341 平台设备的控制端口就可以了,打开mach-smdk2440.c,添加如下内容:
[shaocongshuai@localhost linux-3.0.2]$ vim arch/arm/mach-s3c2440/mach-smdk2440.c
...
50 #include
...
这三个引脚是跟据fl2440开发板的硬件连接决定的,L3接口需要三个线:时钟、数据、模式选择线
154 static struct s3c24xx_uda134x_platform_data s3c24xx_uda134x_data = {
155 .l3_clk = S3C2410_GPB(4),
156 .l3_data = S3C2410_GPB(3),
157 .l3_mode = S3C2410_GPB(2),
158 .model = UDA134X_UDA1341,
159 };
160
161 static struct platform_device s3c24xx_uda134x = {
162 .name = "s3c24xx_uda134x",
163 .dev = {
164 .platform_data = &s3c24xx_uda134x_data,
165 }
166 };
167
168 static struct platform_device uda1340_codec = {
169 .name = "uda134x-codec",
170 .id = -1,
171 };
172
173 static struct platform_device *smdk2440_devices[] __initdata = {
174 &s3c_device_ohci,
175 &s3c_device_lcd,
176 &s3c_device_wdt,
177 &s3c_device_i2c0,
178 &s3c_device_iis,
179 &s3c_device_dm9000,
180 &uda1340_codec,
181 &s3c24xx_uda134x,
182 &samsung_asoc_dma,
183 };
....
注意:上述添加的各类结构体均要放在添加设备的devices[ ]结构体数组之前,否则会出现未定义,以及定义了没使用等错误。因为编译器是按顺序编译,所以声明必须放在结构体或者函数之前。
二、在内核中配置UDA1341 设备驱动
要注意的是,这里的OSS 接口其实是基于ALSA 接口创建的,因为新的内核中现在都已经改用ALSA 设计,这里是为了和以前的软件兼容才这样做的
oss简介 http://blog.csdn.net/suer0101/article/details/7263751
alsa简介 http://blog.csdn.net/droidphone/article/details/6271122
[shaocongshuai@localhost linux-3.0.2]$ make menuconfig
Device Drivers --->
<*> Sound card support --->
[*] Preclaim OSS device numbers
<*> Advanced Linux Sound Architecture --->
<*> OSS Mixer API
<*> OSS PCM (digital audio) API
[*] OSS PCM (digital audio) API - Include plugin system
[*] OSS Sequencer API
[*] Verbose procfs contents
<*> ALSA for SoC audio support --->
<*> ASoC support for Samsung
<*> SoC I2S Audio support UDA134X wired to a S3C24XX
make之后烧录到板子上,若在内核启动过程中打印的一长串信息里找到下述打印出的信息则表示成功 。
.....
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: uda134x-hifi <-> s3c24xx-iis mapping ok
ALSA device list:
#0: S3C24XX_UDA134X
Netfilter messages via NETLINK v0.30.
.....
~ >: cat /proc/devices
Character devices:
....
10 misc
13 input
14 sound
21 sg
.....
三、madplay移植和播放MP3音乐
(一)移植前的准备
所需源码包:
下载地址 https://sourceforge.net/projects/mad/files/
madplay-0.15.2b.tar.gz, //播放程序的压缩包,MP3播放器的源码
libmad-0.15.1b.tar.gz, //madplay的库文件
libid3tag-0.15.1b.tar.gz //mp3的解码库
zlib-1.1.4.tar.gz //用于文件的压缩与解压
下载地址 http://zlib.net/fossils/
新建文件目录并上传源码包到madplay目录并解压;
[shaocongshuai@localhost ~]$ mkdir madplay
[shaocongshuai@localhost ~]$ mkdir madplay/mad
[shaocongshuai@localhost madplay]$ ls
libid3tag-0.15.1b libmad-0.15.1b mad madplay-0.15.2b zlib-1.1.4
移植第三方程序的主要步骤分别为:解压缩、配置(./configure)、编译(make)、安装(make install);
一般源码包解压缩之后,若已经存在Makefile则可以直接make编译;但大多数情况下需要使用源码包目录下的./configure脚本来配置源码包生成Makefile文件;
这里我们必须知道以下几个配置参数:
--host: 用于指定平台;如: --host==arm-linux
--prefix: 用于指定文件的安装路径; 如:--prefix=/home/shaocongshuai/madplay/mad
-I 指定头文件的路径; 如:-I /home/shaocongshuai/madplay/mad/include/
-L 指定库文件的路径;如:-L /home/shaocongshuai/madplay/mad/lib
--disable-shared 使用静态库编译;
如果是要编译到arm板子上跑则在make的时候还需要加上AR(将.o文件打包生成.a的静态库文件)= LD(所链接)= CC(交叉编译器)= RANLIB(随机库创建器) AS(汇编器)= NM(库查看工具)
(二)开始正式配置,编译
注意:以下的步骤不能打乱,因为其中有依赖关系;还有每次都需要使用sudo权限,否则可能因权限不够而出错。
1>首先编译zlib-1.1.4
[shaocongshuai@localhost madplay]$ cd zlib-1.1.4/
(1)配置configure文件,生成Makefile
[shaocongshuai@localhost zlib-1.1.4]$ sudo ./configure --prefix=/home/shaocongshuai/madplay/mad
(2)修改Makefile文件
[shaocongshuai@localhost zlib-1.1.4]$ vim Makefile
.......
15 CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
......
31 AR=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ar rc
32 RANLIB=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-ranlib
......
(3)编译make
[shaocongshuai@localhost zlib-1.1.4]$ sudo make
(4)安装make install
[shaocongshuai@localhost zlib-1.1.4]$ sudo make install
2>编译libid3tag-0.15.1b
[shaocongshuai@localhost madplay]$ cd libid3tag-0.15.1b/
[shaocongshuai@localhost libid3tag-0.15.1b]$ sudo ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --host=arm-linux --disable-shared --prefix=/home/shaocongshuai/madplay/mad CPPFLAGS=-I/home/shaocongshuai/madplay/mad/include/ LDFLAGS=-L/home/shaocongshuai/madplay/mad/lib
[shaocongshuai@localhost libid3tag-0.15.1b]$ sudo make
[shaocongshuai@localhost libid3tag-0.15.1b]$ sudo make install
3>编译libmad-0.15.1b
[shaocongshuai@localhost madplay]$ cd libmad-0.15.1b/
[shaocongshuai@localhost libmad-0.15.1b]$ sudo ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --host=arm-linux --disable-shared --prefix=/home/shaocongshuai/madplay/mad CPPFLAGS=-I/home/shaocongshuai/madplay/mad/include/ LDFLAGS=-L/home/shaocongshuai/madplay/mad/lib
[shaocongshuai@localhost libmad-0.15.1b]$ sudo make
.....
cc1: error: unrecognized command line option "-fforce-mem"
make[2]: *** [version.lo] Error 1
make[2]: Leaving directory `/home/shaocongshuai/madplay/libmad-0.15.1b'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/shaocongshuai/madplay/libmad-0.15.1b'
make: *** [all] Error 2
解决方式是:
找到libmad configure之后的Makefile,删除 -fforce-mem原因是gcc 3.4 或者更高版本,已经将其去除了,所以会出现上面的错误!
[shaocongshuai@localhost libmad-0.15.1b]$ sudo make install
4>安装madplay
[shaocongshuai@localhost madplay]$ cd madplay-0.15.2b/
[shaocongshuai@localhost madplay-0.15.2b]$ sudo ./configure CC=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc --host=arm-linux --disable-shared --prefix=/home/shaocongshuai/madplay/mad CPPFLAGS=-I/home/shaocongshuai/madplay/mad/include/ LDFLAGS=-L/home/shaocongshuai/madplay/mad/lib
[shaocongshuai@localhost madplay-0.15.2b]$ sudo make
至此,终于make成功生成madplay的绿色可执行程序了.又因为我使用的是静态编译。此时可不用再make install,直接将 madplay下载到开发板后给予权限即可。
[shaocongshuai@localhost madplay-0.15.2b]$ du -sh madplay
704K madplay
[shaocongshuai@localhost madplay-0.15.2b]$ file madplay
madplay: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
~ >: tftp -gr madplay 192.168.1.93
madplay 100% |*******************************| 703k 0:00:00 ETA
~ >: set -o vi
~ >: tftp -gr New_Soul_Yael_Naim_New-Soul.mp3 192.168.1.93
New_Soul_Yael_Naim_N 100% |*******************************| 8766k 0:00:00 ETA
~ >: chmod 777 madplay
~ >: ./madplay New_Soul_Yael_Naim_New-Soul.mp3
MPEG Audio Decoder 0.15.2 (beta) - Copyright (C) 2000-2004 Robert Leslie et al.
Title: New Soul
Artist: ael Naim)
Orchestra: ael Naim)
Album: New Soul
Track: 1/1
Year: 2008
Genre: Pop
madpaly还有一些快捷键,比如:增大/减小音量(+/-),暂停(b),停止(ESC)
按键盘的减号可以减小音量,shift+可以增大音量,shift-瞬间恢复满音量,s键停止。