Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1255289
  • 博文数量: 404
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 5382
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-03 16:29
文章存档

2010年(40)

2009年(140)

2008年(224)

我的朋友

分类: LINUX

2008-12-17 10:28:57

#include  

#include

#include

#include

#include

#include

#include

 

#include "def_type.h"

#include "app.h"

#include "tlv320api.h"

 

i32_t opentlv320(void)

{  

i32_t fd = open("/dev/misc/tlv320",O_RDWR | O_NONBLOCK);

//非阻塞模式打开设备tlv320

    if(fd < 0)

    {

        printf("open fail!\n");

        return -1;

}

//打开失败,返回-1

    else

    {

        return fd;

}

//打开成功,返回文件描述符fd

}

 

i32_t InAudioControl(u32_t voiceclass)              //音量输入控制

{

i32_t fd = opentlv320();

//控制之前要打开设备,得到fd才能继续操作。

 

    if(-1 == fd)

    {

        return -1;

                   //设备打开失败

    }

    //app_SetAudioValue(1, dbvolume, voiceclass);//写日志???????????//

    app_SetAudioValue(1, dbmicvolume, voiceclass);//写日志???????????//

 

    switch(voiceclass)                               //选择音量等级voiceclass

    {

        case 0:                        //静音

            {

                //i32_t val = 0x10000010;

                i32_t val = 0x10000000;         //要设定的音量值

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)    //ioctl操作失败,具体操作见后面设备驱动的接口定义。

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

            }

        case 1:

            {

                i32_t val = 0x10000004;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

               

            }

        case 2:

            {

                i32_t val = 0x10000008;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

               

            }

        case 3:

            {

                i32_t val = 0x1000000b;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

               

            }

        case 4:

            {

                i32_t val = 0x10000010;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

               

            }

        case 5:

            {

                i32_t val = 0x10000014;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

            }

               

        case 6:

            {

                i32_t val = 0x10000018;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

            }

        case 7:

            {

                i32_t val = 0x1000001b;

                u32_t ret = ioctl(fd,0xaf03,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

            }

        case 8:

            {

                i32_t val = 0x1000001f;

                u32_t ret = ioctl(fd,0xaf03,&val);

//使用左声道音量操作命令(0xaf03)将音量值0x1000001f写入到对应的音量操作寄存器中

/*

 * extdrv/peripheral/ada/tlv320.h for Linux .

 *

 * History:

 *      10-April-2006 create this file

 

#ifndef __INC_ADA_H

         #define __INC_ADA_H   

 

 

        

         #define     SET_TLV_SAMPLERATE              0xaF01

         #define     ANALOG_INPUT_PATH                   0xaF02

         #define     LEFT_INPUT_VOLUME_MODIFY            0xaF03

         #define     RIGHT_INPUT_VOLUME_MODIFY           0xaF04

         #define     LINE_INPUT_MUTE                         0xaF05

         #define     MIC_INPUT_MUTE                      0xaF06

         #define     LEFT_HEADPHONE_VOLUME_MODIFY        0xaF07

         #define     RIGHT_HEADPHONE_VOLUME_MODIFY       0xaF08

         #define     HEADPHONE_VOLUME_MUTE               0xaF09

         #define     SET_TLV_WORK_MODE                   0xaF0a

        

        

         #define     SET_8K_SAMPLERATE                        0

         #define     SET_32K_SAMPLERATE                      3

         #define     SET_48K_SAMPLERATE                      5      

 

         #define     SET_MASTER_MODE                     0

         #define     SET_SLAVE_MODE                      1

#endif

 

*/

/*

****************ioctl arguments used set code attr ,specification belown:*****************

*LEFT_INPUT_VOLUME_MODIFY  :

 *                           Left headphone volume control (1111001 = 0 dB default)

 *                           1111111 = +6 dB, 79 steps between +6 dB and .73 dB (mute),

 *                           0110000 = .73 dB (mute),any thing below 0110000 does

 *                           nothing .  still in muted

 

下面贴出对应的驱动程序#define     LEFT_INPUT_VOLUME_MODIFY            0xaF03

static int tlv320_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)

case LEFT_INPUT_VOLUME_MODIFY:

                                get_user(tmp,argp);

                                volume    =(tmp & 0x0ff);

                                which_ada =(tmp & 0xf0000000);

                                which_ada = which_ada >> 28;

                                if((volume >0x1f )|| (volume<0x00))

                                         return -EINVAL;

                                gu8RegValue[which_ada][0] = volume;

hi_i2c_write(IIC_device_addr[which_ada], Lline_vol_ctrl,  gu8RegValue[which_ada][0]);

                                break;

*/

                  

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -4;

            }

        default:

            close(fd);

            return -5;

    }

 

}

 

i32_t OutAudioControl(u32_t voiceclass)// 9 class :0 silence 1-8 eigth class    //音量输出控制

{

    i32_t fd = opentlv320();

 

    if(-1 == fd)

    {

        return -1;

    }

   

    app_SetAudioValue(1, dbvolume, voiceclass);

 

    switch(voiceclass)

    {

        case 0:

            {

                i32_t val = 0x10000030;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 1:

            {

                u32_t val = 0x1000005e;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 2:

            {

                u32_t val = 0x10000062;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 3:

            {

                u32_t val = 0x10000066;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 4:

            {

                u32_t val = 0x1000006a;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 5:

            {

                u32_t val = 0x10000070;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 6:

            {

                u32_t val = 0x10000075;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 7:

            {

                u32_t val = 0x1000007a;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        case 8:

            {

                u32_t val = 0x1000007f;

                u32_t ret = ioctl(fd,0xaf07,&val);

                if( 0 == ret)

                {

                    close(fd);

                    return 0;

                }

                close(fd);

                return -2;

            }

        default:

            close(fd);

return -3;

           

    }

}

 

#if 0

int main()

{

    while(1)

    {

        u32_t regval = 0x10000030;

        u32_t ret = AudioControl(®val);

        regval ++ ;

        printf("ret===%d\n",ret);

        sleep(1);

        if(regval==0x1000007f)

            regval = 0x10000030;

    }

}

#endif

 

阅读(1088) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~