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

📄 a2dp_sd_init.c

📁 实现蓝牙 立体声传送
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release

FILE NAME
    a2dp_sd_init.c

DESCRIPTION
    Initialisation of the application.

NOTES
    
*/


/****************************************************************************
    Header files
*/
#include "a2dp_sd_private.h"
#include "a2dp_sd_init.h"
#include "a2dp_sd_security.h"

#include <a2dp.h>
#include <avrcp.h>
#include <bdaddr.h>
#include <ps.h>



/* Set up the config params and attempt to add the SEP. */
static void addSep(A2DP *a2dp)
{
    /* Set up the SEP config */
    a2dp_sep_config config;    
	config.sep_type = a2dp_sbc;
    config.params = 0;

    /* Register SEP */
    A2dpAddSep(a2dp, &config);
}


/* Initialise the AV RCP library */
static void initAvrcpLib(void)
{
    avrcp_init_params config;
    config.device_type = avrcp_target;
    config.priority = 50;

    /* Init the AV RCP library */
    AvrcpInit(getTheAppTask(), &config);
}


/****************************************************************************
NAME    
    a2dpSdInitLocalState
    
DESCRIPTION
    Initialise the locally stored state 

RETURNS
    void
*/
void a2dpSdInitLocalState(a2dpSourceDongleTaskData *theApp)
{
    /* Initialise the local state */
    avSourceDongleUpdateA2dpState(a2dp_state_initialising);
    avSourceDongleUpdateAvrcpState(avrcp_state_initialising);

    /* Reset the profile instances */
    theApp->a2dp = 0;
    theApp->avrcp = 0;

    /* Retrieve the address of the sink device */
    if (!PsRetrieve(PS_AV_SINK_ADDR, &theApp->av_sink_addr, sizeof(bdaddr)))
        /* If we don't have an address stored, reset this to all zeroes. */
        BdaddrSetZero(&theApp->av_sink_addr);

    /* Reset the discovery pending flag. */
    theApp->discover_pending = 0;
    
    /* Reset the media sink and MTU */
    theApp->media_sink = 0;

    /* Reset the RCP sink */
    theApp->rcp_sink = 0;

    /* Reset the scan enabled flag */
    theApp->scan_enabled = hci_scan_enable_off;
    
    /* Reset the connect_timer_expired flag. */
    theApp->connect_timer_expired = 0;

    /* 
        DO NOT reset the USB source as it already has a valid value 
        this is because we have to register our USB descriptos quickly 
        and we do have time to faff around initialising the local state 
        first so we get the descriptors registered and then worry about 
        doing this bit! 
    */
}


/****************************************************************************
NAME    
    a2dpSdClInitSuccess
    
DESCRIPTION
    Connection lib init has succeeded, proceed with app init.

RETURNS
    void
*/
void a2dpSdClInitSuccess(a2dpSourceDongleTaskData *theApp)
{
    /* Config the device role for the A2DP */
    a2dp_init_params config;

#ifdef USB_AUDIO_MODE
    config.role = a2dp_source_usb;
#else
#ifdef WOLFSON_CODEC
	config.role = a2dp_source_wolfson;
#else
	config.role = a2dp_source_analogue;
#endif
#endif

    config.size_service_record = 0;
    config.service_record = 0;
    config.priority = 512;
    
    /* Connection lib initialised ok - init the AV lib. */
    A2dpInit(&theApp->task, &config);
}


/****************************************************************************
NAME    
    a2dpSdA2dpLibInitSuccess
    
DESCRIPTION
    A2DP lib has been initialised successfully. Proceed with registering a
    SEP and initialising the AV RCP library.

RETURNS
    void
*/
void a2dpSdA2dpLibInitSuccess(const a2dpSourceDongleTaskData *theApp)
{
    /* Add SEP */
    addSep(theApp->a2dp);

    /* Init the AV RCP library */
    initAvrcpLib();
}


/****************************************************************************
NAME    
    a2dpSdSepAddedCfm
    
DESCRIPTION
    The SEP has been added successfully.

RETURNS
    void
*/
void a2dpSdSepAddedCfm(a2dpSourceDongleTaskData *theApp)
{
    /* Update state to accepting */
    avSourceDongleUpdateA2dpState(a2dp_state_accepting);

    /* Register the class of device. */
    ConnectionWriteClassOfDevice(AV_MAJOR_DEVICE_CLASS | AV_MINOR_HIFI | AV_COD_CAPTURE);

    /* Init the security settings */
    a2dpSdSecurityInit();

    /* Send an internal message to indicate app init complete */
    MessageSend(&theApp->task, APP_INIT_CFM, 0);
}

⌨️ 快捷键说明

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