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

📄 main.c

📁 CSR蓝牙芯片 无线蓝牙耳机的语音网关程序 蓝牙耳机程序已经上传
💻 C
📖 第 1 页 / 共 5 页
字号:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
            }
            break;
        case BUTTON_PLAY_PAUSE_REL:
            DEBUG(("BUTTON_PLAY_PAUSE_REL button lock=%d\n",app.button_action_pending_lock));
            DEBUG(("profile=%d  hfp=%d av=%d pend=%d\n",app.active_profile,current_hfp_state,current_avrcp_state,app.avrcp_pending));
            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                    case avHeadsetAvrcpDisconnecting:
                        avHeadsetPausePress(&app);
                        avHeadsetPauseRelease(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
            }
            else if ((app.active_profile == hfp_active) && !app.button_action_pending_lock)
            {
                switch(current_hfp_state)
                {           
                case headsetIncomingCallEstablish:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Accept the call */
                        hfpHeadsetAnswerCall(&app);
                    else
                        /* Must be the HSP so send a button press */
                        HfpSendHsButtonPress(app.hsp);
                    break;

                case headsetActiveCall:
                    if (app.profile_connected == hfp_handsfree_profile)
                    {
                        /* Transfer the audio to/ from the AG */ 
                        if (!app.sco_sink)
                            hfpHeadsetTransferAudio(&app, hfp_audio_to_hfp);
                        else
                            hfpHeadsetTransferAudio(&app, hfp_audio_to_ag);
                    }
                    else
                    {
                        /* Must be the HSP so send a button press */
                        HfpSendHsButtonPress(app.hsp);
                    }
                    break;

                case headsetOutgoingCallEstablish:
                    if (app.profile_connected == hfp_headset_profile)
                        HfpSendHsButtonPress(app.hsp);
                    break;

                case headsetReady:
                case headsetConnected:
                case headsetConnecting:
                    break;

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;
            
        case BUTTON_PLAY_PAUSE_LONG:
            DEBUG(("BUTTON_PLAY_PAUSE_LONG\n"));
            if (!app.button_action_pending_lock)
            {
                switch(current_hfp_state)
                {               
                case headsetReady:
                    /* Set the button pending lock */
                    app.button_action_pending_lock = 1;
                    /* Queue up the message */
                    MessageSendConditionally(&app.task, BUTTON_PLAY_PAUSE_LONG, 0, &app.button_action_pending_lock);                    
                    /* Connect an SLC */
                    hfpHeadsetHandleSlcConnectRequest(&app, hfp_handsfree_profile);
                    break;
                
                case headsetConnecting:
                    break;

                case headsetConnected:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Initiate voice dial */
                        hfpHeadsetVoiceRecognitionEnable(&app, 1);
                    else
                        /* Must be the HSP so send a button press */
                        HfpSendHsButtonPress(app.hsp);
                    break;
                
                case headsetIncomingCallEstablish:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Accept the call */
                        hfpHeadsetAnswerCall(&app);
                    else
                        /* Must be the HSP so send a button press */
                        HfpSendHsButtonPress(app.hsp);
                    break;

                case headsetOutgoingCallEstablish:
                    if (app.profile_connected == hfp_headset_profile)
                        HfpSendHsButtonPress(app.hsp);
                    break;

                case headsetActiveCall:
                    if (app.profile_connected == hfp_handsfree_profile)
                    {
                        /* Transfer the audio to/ from the AG */ 
                        if (!app.sco_sink)
                            hfpHeadsetTransferAudio(&app, hfp_audio_to_hfp);
                        else
                            hfpHeadsetTransferAudio(&app, hfp_audio_to_ag);
                    }
                    else    
                    {
                        /* Must be the HSP so send a button press */
                        HfpSendHsButtonPress(app.hsp);
                    }
                    break;

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;
        case BUTTON_STOP_REL:
            DEBUG(("BUTTON_STOP_REL\n"));
            if (app.active_profile == av_active)
            {
                switch(current_avrcp_state)
                {
                    case avHeadsetAvrcpConnected:
                    case avHeadsetAvrcpDisconnecting:
                        avHeadsetStopPress(&app);
                        avHeadsetStopRelease(&app);
                        break;
                    case avHeadsetAvrcpReady:
                    case avHeadsetAvrcpInitialising:
                    case avHeadsetAvrcpConnecting:
                    default:
                        unhandledAvrcpState(current_avrcp_state, id);
                        break;      
                }
            }
            else if ((app.active_profile == hfp_active) && !app.button_action_pending_lock)
            {
                switch(current_hfp_state)
                {
                case headsetReady:
                case headsetConnecting:
                case headsetConnected:
                    break;

                case headsetIncomingCallEstablish:
                    DEBUG(("End Call\n"));
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Reject the call */
                        hfpHeadsetRejectCall(&app);
                    break;

                case headsetOutgoingCallEstablish:
                case headsetActiveCall:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Hang up active call */
                        hfpHeadsetHangUpCall(&app);
                    break;

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;
        
        case BUTTON_STOP_LONG:
            DEBUG(("BUTTON_STOP_LONG\n"));
            if (!app.button_action_pending_lock)
            {
                switch(current_hfp_state)
                {
                case headsetReady:
                    /* Set the button pending lock */
                    app.button_action_pending_lock = 1;
                    /* Queue up the message */
                    MessageSendConditionally(&app.task, BUTTON_STOP_LONG, 0, &app.button_action_pending_lock);                   
                    /* Connect an SLC */
                    hfpHeadsetHandleSlcConnectRequest(&app, hfp_handsfree_profile);
                    break;

                case headsetConnecting:
                    break;

                case headsetConnected:
                    if (app.profile_connected == hfp_handsfree_profile)
                        hfpHeadsetLastNumberRedial(&app);
                    else     
                        HfpSendHsButtonPress(app.hsp);
                    break;

                case headsetIncomingCallEstablish:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Reject the call */
                        hfpHeadsetRejectCall(&app);
                    break;

                case headsetOutgoingCallEstablish:              
                case headsetActiveCall:
                    if (app.profile_connected == hfp_handsfree_profile)
                        /* Hang up active call */
                        hfpHeadsetHangUpCall(&app);
                    break;

                case headsetInitialising:
                default:
                    unhandledHfpState(current_hfp_state, id);
                }
            }
            break;
            
        case BUTTON_PLAY_PAUSE_STOP_LONG:
            DEBUG(("BUTTON_PLAY_PAUSE_STOP_LONG\n"));
            if (!app.button_action_pending_lock && (app.profile_connected == hfp_handsfree_profile))
                /* Disconnect the SLC */
                hfpHeadsetDisconnectSlc(&app);
            break;
    
        case APP_PAIR_MODE_END_IND:
            DEBUG(("APP_PAIR_MODE_END_IND\n"));
            app.pairing_enabled = 0;
            /* Make device undiscoverable and test for connectability
               so that if we are still connectable it will set the appropriate
               scan interval and window when not in pairing mode
            */
            headsetDisableDiscoverable(&app);
            headsetTestForConnectablilty(&app);
            app.led_state &= ~LED_PAIRING;
            break;
            
        case POWER_DOWN_REQUIRED:
            DEBUG(("POWER_DOWN_REQUIRED\n"));
            avHeadsetStartPowerDown(&app);
            break;
        
        case APP_POWER_OFF_IND:
            DEBUG(("APP_POWER_OFF_IND\n"));
            avHeadsetPowerDown(&app);
            break;
            
        default:
            DEBUG(("AV Headset - Unhandled msg 0x%x\n",id));
            break;
    }
}


/* The AV Headset Application starts here...*/
int main(void)
{
    uint16 pio_get, pair_mode;
    
    DEBUG(("main started\n"));
    /* Set up the Application task handler */
    app.task.handler = app_handler;
    
    /* Set initial states */
    app.a2dp_state = avHeadsetA2dpInitialising;
    app.avrcp_state = avHeadsetAvrcpInitialising;
    
    /* Initialise LEDs */
    app.led_state = LED_NONE;
    startLED(app.led_state);
    
    /* Set up common states */
    app.active_profile = hfp_active;
    app.pcm_audio_state = pcm_none;
    app.powering_down = FALSE;
    
    /* Set up HFP variables */
    app.page_scan_enabled = 0;
    app.inquiry_scan_enabled = 0;
    app.pairing_enabled = 0;
    app.in_band_ring_enabled = 0;
    app.voice_recognition_enabled = 0;
    app.button_action_pending_lock = 0;
    app.sco_sink = 0;
    app.supp_features_0 = 0;
    app.profile_connected = hfp_no_profile;
    app.hfp = 0;
    app.hsp = 0;
    
    /* Set up AV variables */
    app.av_stream_stopped = TRUE;
    app.sent_suspend = FALSE;
	app.channel_mode = a2dp_mono;
	app.rate = VM_PCM_RATE_8K;
            
    app.remote_bdaddr.lap = 0;
    app.remote_bdaddr.uap = 0;
    app.remote_bdaddr.nap = 0;
    
    /* read our bonded device from the PS */
    (void)PsRetrieve(LAST_USED_AV_SOURCE,&app.remote_bdaddr,sizeof(bdaddr));

    /* Initialise the controls */
    avHeadsetInitialiseControls(&app);
    
    /* Initialise PIO */
    pioInit(&app.pio_state, &app.task);
    
    /* Check if we should enter pairing mode */
    pair_mode = (1<<4) | (1<<5);
    pio_get = PioGet();
    if ((pio_get & pair_mode) == pair_mode)
    {
        DEBUG(("PAIRING ENABLED.\n"));
        app.pairing_enabled = 1;
        MessageSendLater(getAppTask(), APP_PAIR_MODE_END_IND, 0, 60000);
        app.led_state |= LED_PAIRING;
    }

#ifdef WOLFSON_CODEC
    /* Init the Wolfson codec with default params. */
    CodecInitWolfson(&app.task, 0);
#else
    /* Initialise the Codec Library */
    CodecInitCsrInternal(&app.task);
#endif

    /* Start the message scheduler loop */
    MessageLoop();
    
    /* Never get here...*/
    return 0;
}

⌨️ 快捷键说明

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