⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 CSR蓝牙芯片 无线蓝牙耳机的语音网关程序 蓝牙耳机程序已经上传
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004

FILE NAME
    main.c        

DESCRIPTION
    This file contains the main AV Headset Application

NOTES

*/


/****************************************************************************
    Header files
*/

#include "headset_private.h"
#include "headset_auth.h"
#include "headset_buttons.h"
#include "headset_led.h"
#include "headset_scan.h"

#include "hfp_headset_call_control.h"
#include "hfp_headset_dial.h"
#include "hfp_headset_indicators.h"
#include "hfp_headset_init.h"
#include "hfp_headset_ring.h"
#include "hfp_headset_sco.h"
#include "hfp_headset_slc.h"
#include "hfp_headset_voice.h"

#include "av_headset_init.h"
#include "av_headset_sep.h"
#include "av_headset_controls.h"
#include "av_headset_remote_control.h"
#include "av_headset_kalimba.h"
#include "cvc_headset.h"

#include <a2dp.h>
#include <avrcp.h>
#include <connection.h>
#include <hfp.h>
#include <panic.h>
#include <stdlib.h>
#include <stream.h>
#include <ps.h>
#include <pio.h>
#include <hfp.h>
#include <codec.h>

/* Single instance of AV Headset state */
static headsetTaskData app;

/*************************************************************************
NAME    
    getAppTask
    
DESCRIPTION
    Returns the AV application main task.

RETURNS
    Task
*/
Task getAppTask(void)
{
    return &app.task;
}

/*************************************************************************
NAME    
    getApp
    
DESCRIPTION
    Returns the AV application main task.

RETURNS
    Task
*/
headsetTaskData *getApp(void)
{
    return &app;
}

/*************************************************************************
NAME    
    avHeadsetSetA2dpState
    
DESCRIPTION
    Set the AV Headset A2DP State to the specified state

RETURNS
    
*/
void avHeadsetSetA2dpState(const avHeadsetA2dpState state)
{
    DEBUG(("AV Headset A2DP State - C=%d N=%d\n",app.a2dp_state, state));
    app.a2dp_state = state;
}


/*************************************************************************
NAME    
    avHeadsetSetAvrcpState
    
DESCRIPTION
    Set the AV Headset AVRCP State to the specified state

RETURNS
    
*/
void avHeadsetSetAvrcpState(const avHeadsetAvrcpState state)
{
    DEBUG(("AV Headset AVRCP State - C=%d N=%d\n",app.avrcp_state, state));
    app.avrcp_state = state;
}


/*************************************************************************
NAME    
    unhandledA2dpState
    
DESCRIPTION
    This function is called when a message arrives and the AV Headset is
    in an unexpected state.  The error condition is reported and then the
    AV Application will Panic
    
RETURNS
    
*/
static void unhandledA2dpState(avHeadsetA2dpState state, MessageId id)
{
	state = state;
	id = id;

    DEBUG(("A2DP current state %d message id 0x%x\n", state, id));  
}


/*************************************************************************
NAME    
    unhandledAvrcpState
    
DESCRIPTION
    This function is called when a message arrives and the AV Headset is
    in an unexpected state.  The error condition is reported and then the
    AV Application will Panic
    
RETURNS
    
*/
static void unhandledAvrcpState(avHeadsetAvrcpState state, MessageId id)
{
	state = state;
	id = id;

    DEBUG(("AVRCP current state %d message id 0x%x\n", state, id));
}

static void unhandledHfpState(headsetState state, MessageId id)
{
	state = state;
	id = id;

    DEBUG(("HFP current state %d message id 0x%x\n", state, id));
}


/*************************************************************************
NAME    
    app_handler
    
DESCRIPTION
    This is the main message handler for the AV Headset Application.  All
    messages pass through this handler.

RETURNS

*/
static void app_handler(Task task, MessageId id, Message message)
{
    /* Get the current Headset states */
    avHeadsetA2dpState current_a2dp_state = app.a2dp_state;
    avHeadsetAvrcpState current_avrcp_state = app.avrcp_state;
    headsetState current_hfp_state = app.hfp_state;

	task = task;

    /* Handle incoming message identified by its message ID */
    switch(id)
    {
         case CODEC_INIT_CFM:
            if(((CODEC_INIT_CFM_T*)message)->status == codec_success)
            {
                
                app.codec_task = ((CODEC_INIT_CFM_T*)message)->codecTask;
                /* Update the headset volume */
                avHeadsetUpdateAvVolume(app.codec_task, app.speaker_volume);
                /* Initialise the Connection Library */
                ConnectionInit(&app.task);
            }
            else
                Panic();
            break;
            
        case CL_INIT_CFM:
            DEBUG(("CL_INIT_CFM\n"));
            if(((CL_INIT_CFM_T*)message)->status == success)
            {
                /* Connection Library initialisation was a success, initailise the 
                   A2DP library */
                a2dp_init_params a2dp_config;
                a2dp_config.role = a2dp_sink;
                a2dp_config.priority = 512;
                a2dp_config.size_service_record = 0;
                a2dp_config.service_record = 0;
                A2dpInit(getAppTask(), &a2dp_config);
            }
            else
            {
                Panic();
            }
            break;
            
        case A2DP_INIT_CFM:
            DEBUG(("A2DP_INIT_CFM\n"));
                    
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpInitialising:
                    avHeadsetHandleA2dpInitCfm(&app, (A2DP_INIT_CFM_T*) message);
                    break;
                    
                case avHeadsetA2dpReady:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case A2DP_ADD_SEP_CFM:
            DEBUG(("A2DP_ADD_SEP_CFM\n"));
                    
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpInitialising:
                    avHeadsetHandleA2dpAddSepCfm(&app, (A2DP_ADD_SEP_CFM_T*) message);
                    break;
                    
                case avHeadsetA2dpReady:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case A2DP_OPEN_IND:
            DEBUG(("A2DP_OPEN_IND\n"));
                    
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpReady:
                    avHeadsetHandleA2dpOpenInd(&app, (A2DP_OPEN_IND_T*) message);
                    break;
                    
                case avHeadsetA2dpInitialising:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case A2DP_OPEN_CFM:
            DEBUG(("A2DP_OPEN_CFM\n"));
            
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpInitiating:
                    avHeadsetHandleA2dpOpenCfm(&app, (A2DP_OPEN_CFM_T*) message);
                    break;
                    
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpReady:
                case avHeadsetA2dpInitialising:
                case avHeadsetA2dpDisconnecting:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
                        
        case A2DP_START_IND:
            DEBUG(("A2DP_START_IND\n"));
                    
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpConnected:
                    avHeadsetHandleA2dpStartInd(&app, (A2DP_START_IND_T*) message);
                    break;
                    
                case avHeadsetA2dpReady:
                case avHeadsetA2dpInitialising:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case A2DP_START_CFM:
            DEBUG(("A2DP_START_CFM\n"));
                    
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpInitiating:
                case avHeadsetA2dpConnected:
                    avHeadsetHandleA2dpStartCfm(&app, (A2DP_START_CFM_T*) message);
                    break;
                    
                case avHeadsetA2dpReady:
                case avHeadsetA2dpInitialising:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case A2DP_SUSPEND_IND:
            DEBUG(("A2DP_SUSPEND_IND\n"));
                    
            switch(current_a2dp_state)
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -