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

📄 headset_common.c

📁 针对bluelab3.42的handsfree车载蓝牙的参考
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.4.2-release

FILE NAME
    headset_common.c

DESCRIPTION
    Deals with general headset functionality.

NOTES

*/


/****************************************************************************
    Header files
*/
#include "headset_private.h"
#include "a2dp_handler.h"
#include "cvc_headset.h"
#include "headset_common.h"
#include "headset_power.h"
#include "headset_volume.h"
#include "hfp_slc.h"

#include <connection.h>
#include <hfp.h>
#include <kalimba.h>
#include <ps.h>


#ifdef DEBUG_COMMON
#define COMMON_DEBUG(x) DEBUG(x)
#else
#define COMMON_DEBUG(x) 
#endif


#define SCAN_INTERVAL_NORMAL    (0x800)
#define SCAN_WINDOW_NORMAL      (0x12)
#define SCAN_INTERVAL_PAIRING   (0x400)
#define SCAN_WINDOW_PAIRING     (0x200)


/*****************************************************************************/
void updateHeadsetScanning(headsetTaskData *app)
{
    hci_scan_enable scan = hci_scan_enable_off;

    if (isHeadsetIdle(app))
    {
        /* If headset is ilde be discoverable and connectable */
        scan = hci_scan_enable_inq_and_page;
    }
    else if (((app->a2dp_state == avHeadsetA2dpConnected) || 
            (app->a2dp_state == avHeadsetA2dpStreaming)) &&
            (app->hfp_state >= headsetConnected))
    {
        /* If AV and HFP connected disable all scanning */
        scan = hci_scan_enable_off;
    }
    else if ((app->a2dp_state == avHeadsetA2dpConnected) || 
        (app->a2dp_state == avHeadsetA2dpStreaming))
    {
        /* If only AV connected disable inquiry scan */
        scan = hci_scan_enable_page;
    }
    else
    {
        /* Enable both page and inquiry scan */
        scan = hci_scan_enable_inq_and_page;
    }
	/*Disable all scanning if the headset is off*/
	if ((app->headset_power_state != power_state_on)&(app->headset_power_state != power_state_on_charging))
		scan = hci_scan_enable_off;
    
    COMMON_DEBUG(("COMMON: scan = %d\n",scan));
	
    if ((app->a2dp_state != avHeadsetA2dpInitialising) &&
        (app->avrcp_state != avHeadsetAvrcpInitialising) && 
        (app->hfp_state != headsetInitialising))
    {
        /* If headset is initialising don't attempt to enter any scan mode */			
        ConnectionWriteScanEnable(scan);
        COMMON_DEBUG(("COMMON: Write scan enable\n"));
    }
}


/**************************************************************************/
void setA2dpState(headsetTaskData *app, const headsetA2dpState state)
{
    COMMON_DEBUG(("COMMON: AV Headset A2DP State - C=%d N=%d\n", app->a2dp_state, state));

    app->a2dp_state = state;
      
    /* Check if we should be setting the idle timer running */
    headsetPowerCheckAutoOff(app);

    /* Check to see if we need to update out page/ inquiry scan settings */
    updateHeadsetScanning(app);
}


/**************************************************************************/
void setAvrcpState(headsetTaskData *app, const headsetAvrcpState state)
{
    COMMON_DEBUG(("COMMON: AV Headset AVRCP State - C=%d N=%d\n", app->avrcp_state, state));
 
    app->avrcp_state = state;

    /* Check to see if we need to update out page/ inquiry scan settings */
    updateHeadsetScanning(app);
}


/**************************************************************************/
void setHfpState(headsetTaskData *app, const headsetHfpState state)
{
    COMMON_DEBUG(("COMMON: AV Headset HFP State - C=%d N=%d\n", app->hfp_state, state));

    app->hfp_state = state;
    
    /* Check if we should be setting the idle timer running */
    headsetPowerCheckAutoOff(app);

    /* Check to see if we need to update out page/ inquiry scan settings */
    updateHeadsetScanning(app);
}

/**************************************************************************/
void setPcmState(headsetTaskData *app, const pcmAudioState state)
{
    COMMON_DEBUG(("COMMON: AV Headset PCM State - C=%d N=%d\n", app->pcm_audio_state, state));
    
    app->pcm_audio_state = state;
}

/*****************************************************************************/
void headsetHandleRemoteSuppFeatures(headsetTaskData *app, const CL_DM_REMOTE_FEATURES_CFM_T *cfm)
{
    /* 
        If the read request succeeded then store the first work of the supported features 
        We should in theory store all four words but currently we only need the info in 
        the first word so for the sake of efficiency for the moment only store that.
    */
    if (cfm->status == hci_success)
        app->supp_features_0 = cfm->features[0];
}


/*****************************************************************************/
bool isHeadsetIdle(const headsetTaskData *app)
{
    if ((app->a2dp_state == avHeadsetA2dpReady) &&
        (app->avrcp_state == avHeadsetAvrcpReady) &&
        (app->hfp_state == headsetReady))
        return TRUE;
    else
        return FALSE;
}


/*****************************************************************************/
bool isHeadsetPairing(const headsetTaskData *app)
{
    return app->pairing_enabled;
}


/*****************************************************************************/
void headsetConnectToLastDevices(headsetTaskData *app)
{
    if (app->features.auto_reconnect == 1)
    {
        COMMON_DEBUG(("COMMON: Connect to last devices\n"));
        hfpHeadsetHandleSlcConnectRequest(app, hfp_handsfree_profile);
        avHeadsetHandleAvConnectRequest(app);
    }
}


/*****************************************************************************/
void headsetRestartAV(headsetTaskData *app)
{
#ifdef INCLUDE_CVC
    /* Indicate that the CVC DSP has stopped */
    if (((app->a2dp_state == avHeadsetA2dpConnected) || (app->a2dp_state == avHeadsetA2dpStreaming))
        && app->cvc.hfkdspready)
    {
        headsetUpdateVolume(app->codec_task, 0);
        CvcHeadsetUnloaded(app);
        KalimbaPowerOff();
    }
#endif
    (void) MessageCancelAll(&app->task, APP_MUSIC_RESTART_IND);
    MessageSendLater(&app->task, APP_MUSIC_RESTART_IND, 0, (uint32) MUSIC_RESTART_DELAY);
}

⌨️ 快捷键说明

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