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

📄 main.c

📁 csr 蓝牙芯片 无线蓝牙耳机的嵌入式程序
💻 C
📖 第 1 页 / 共 2 页
字号:
            DEBUG(("AVRCP_CONNECT_CFM status = %d\n",((AVRCP_CONNECT_CFM_T*)message)->status));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnecting:
                    avHeadsetHandleAvrcpConnectCfm(&theAvApp, (AVRCP_CONNECT_CFM_T*) message);
                    break;
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
            
        case AVRCP_CONNECT_IND:
            DEBUG(("AVRCP_CONNECT_IND\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpReady:
                    /* Only accept the RCP connection if we are in the ready state */
                    avHeadsetHandleAvrcpConnectInd(&theAvApp, (AVRCP_CONNECT_IND_T *) message);
                    break;

                case avHeadsetAvrcpConnecting:
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetHandleAvrcpConnectIndReject(theAvApp.avrcp, (AVRCP_CONNECT_IND_T *) message);
                    break;
                
                case avHeadsetAvrcpInitialising:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
            
       case AVRCP_PASSTHROUGH_CFM:
            DEBUG(("AVRCP_PASSTHROUGH_CFM status = %d\n",((AVRCP_PASSTHROUGH_CFM_T*)message)->status));
            /* clearing the pending flag should allow another
               pending event to be delivered to controls_handler */
			theAvApp.avrcp_pending = FALSE;
            break;
            
        case AVRCP_PASSTHROUGH_IND:
            DEBUG(("AVRCP_PASSTHROUGH_IND\n"));
			/* always respond whatever the state */
            avHeadsetHandleAvrcpPassthroughInd((AVRCP_PASSTHROUGH_IND_T *) message);
            break;
            
        case AVRCP_UNITINFO_IND:
            DEBUG(("AVRCP_UNITINFO_IND\n"));
			/* always respond whatever the state */
            avHeadetHandleAvrcpUnitInfo((AVRCP_UNITINFO_IND_T*) message);
            break;

        case AVRCP_SUBUNITINFO_IND:
            DEBUG(("AVRCP_SUBUNITINFO_IND\n"));
			/* always respond whatever the state */
            avHeadetHandleAvrcpSubUnitInfo((AVRCP_SUBUNITINFO_IND_T*) message);
            break;

        case AVRCP_VENDORDEPENDENT_IND:
            DEBUG(("AVRCP_VENDORDEPENDENT_IND\n"));
			/* always respond whatever the state */
			avHeadetHandleAvrcpVendorDependent((AVRCP_VENDORDEPENDENT_IND_T*) message);
            break;
            
        case AVRCP_DISCONNECT_IND:
            DEBUG(("AVRCP_DISCONNECT_IND\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetHandleAvrcpDisconnectInd();
					avHeadsetCheckPowerDownStatus(&theAvApp);
                    break;
                case avHeadsetAvrcpConnecting:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpReady:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }   
            break;
                        
        case CL_SDP_REGISTER_CFM:
            DEBUG(("CL_SDP_REGISTER_CFM\n"));
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpInitialising:
                    avHeadsetHandleSdpRegisterCfm(&theAvApp, (CL_SDP_REGISTER_CFM_T*) message);
                    break;
                    
                case avHeadsetA2dpReady:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
				case avHeadsetA2dpPairing:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case CL_SM_PIN_CODE_IND:
            DEBUG(("CL_SM_PIN_IND\n"));
            avHeadsetHandlePinCodeInd(&theAvApp, (CL_SM_PIN_CODE_IND_T*) message);
            break;
            
        case CL_SM_AUTHORISE_IND:
            DEBUG(("CL_SM_AUTHORISE_IND\n"));
            avHeadsetHandleAuthoriseInd((CL_SM_AUTHORISE_IND_T*) message);
            break;
            
        case CL_SM_AUTHENTICATE_CFM:
            DEBUG(("CL_SM_AUTHENTICATE_CFM\n"));
            avHeadsetHandleAuthenticateCfm((CL_SM_AUTHENTICATE_CFM_T*) message);
            break;
            
        case CL_DM_ROLE_CFM:
        case CL_DM_INQUIRE_RESULT:
        case CL_DM_REMOTE_NAME_COMPLETE:
        case CL_DM_CLASS_OF_DEVICE_CFM:
        case CL_DM_SCO_CONNECT_CFM:
        case CL_DM_SCO_CONNECT_IND:
        case CL_DM_SCO_DISCONNECT_IND:
        case CL_DM_LOCAL_BD_ADDR_CFM:
        case CL_DM_LINK_QUALITY_CFM:
        case CL_DM_RSSI_CFM:
        case CL_DM_REMOTE_FEATURES_CFM:
        case CL_DM_CLOCK_OFFSET_CFM:
		case CL_DM_ACL_OPENED_IND:
		case CL_DM_ACL_CLOSED_IND:
        case CL_SM_SECURITY_LEVEL_CFM:
		case CL_SM_ENCRYPTION_CHANGE_IND:
        case CL_SDP_UNREGISTER_CFM:
        case CL_SDP_OPEN_SEARCH_CFM:
        case CL_SDP_CLOSE_SEARCH_CFM:
        case CL_SDP_SERVICE_SEARCH_CFM:
        case CL_SDP_ATTRIBUTE_SEARCH_CFM:
        case CL_SDP_SERVICE_SEARCH_ATTRIBUTE_CFM:
        case CL_L2CAP_REGISTER_CFM:
        case CL_L2CAP_UNREGISTER_CFM:
        case CL_L2CAP_CONNECT_CFM:
        case CL_L2CAP_CONNECT_IND:
        case CL_L2CAP_DISCONNECT_IND:
        case CL_RFCOMM_REGISTER_CFM:
        case CL_RFCOMM_CONNECT_CFM:
        case CL_RFCOMM_CONNECT_IND:
        case CL_RFCOMM_DISCONNECT_IND:
        case CL_RFCOMM_CONTROL_IND:
        case CL_DM_LINK_POLICY_IND:
            DEBUG(("AV Headset - CL msg\n"));
            break;

        case VOL_UP:
            DEBUG(("VOL_UP\n"));
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpReady:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                    avHeadsetHandleVolUp(&theAvApp);
                    break;
                    
                case avHeadsetA2dpInitialising:
				case avHeadsetA2dpPairing:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case VOL_DOWN:
            DEBUG(("VOL_DOWN\n"));
            switch(current_a2dp_state)
            {
                case avHeadsetA2dpReady:
                case avHeadsetA2dpConnected:
                case avHeadsetA2dpStreaming:
                case avHeadsetA2dpDisconnecting:
                case avHeadsetA2dpInitiating:
                    avHeadsetHandleVolDown(&theAvApp);
                    break;
                    
                case avHeadsetA2dpInitialising:
				case avHeadsetA2dpPairing:
                default:
                    unhandledA2dpState(current_a2dp_state, id);
                    break;      
            }
            break;
            
        case BUTTON_FORWARD_PRESS:
            DEBUG(("BUTTON_FORWARD_PRESS\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetForwardPress(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_FORWARD_REL:
            DEBUG(("BUTTON_FORWARD_REL\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetForwardRelease(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_BACKWARD_PRESS:
            DEBUG(("BUTTON_BACKWARD_PRESS\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetBackwardPress(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_BACKWARD_REL:
            DEBUG(("BUTTON_BACKWARD_REL\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetBackwardRelease(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_PLAY_PAUSE_PRESS:
            DEBUG(("BUTTON_PLAY_PAUSE_PRESS\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetPausePress(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_PLAY_PAUSE_REL:
            DEBUG(("BUTTON_PLAY_PAUSE_REL\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetPauseRelease(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_STOP_PRESS:
            DEBUG(("BUTTON_STOP_PRESS\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetStopPress(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        case BUTTON_STOP_REL:
            DEBUG(("BUTTON_STOP_REL\n"));
            switch(current_avrcp_state)
            {
                case avHeadsetAvrcpConnected:
                case avHeadsetAvrcpDisconnecting:
                    avHeadsetStopRelease(&theAvApp);
                    break;
                case avHeadsetAvrcpReady:
                case avHeadsetAvrcpInitialising:
                case avHeadsetAvrcpConnecting:
                default:
                    unhandledAvrcpState(current_avrcp_state, id);
                    break;      
            }
            break;
        
        case LED_UPDATE_REQUIRED:
            theAvApp.led_state = updateLED(&theAvApp, theAvApp.led_state);
            break;
        
        case PAIR_MODE_END:
            theAvApp.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(&theAvApp);
            headsetTestForConnectablilty(&theAvApp);
            theAvApp.led_state &= ~led_pairing;				/*lint !e641 */
            break;
			
		case POWER_DOWN_REQUIRED:
            DEBUG(("POWER_DOWN_REQUIRED\n"));
            avHeadsetStartPowerDown(&theAvApp);
            break;
        
        case POWER_OFF:
            DEBUG(("POWER_OFF\n"));
            avHeadsetPowerDown();
            break;
            
        default:
            DEBUG(("AV Headset - Unhandled msg\n"));
            break;
    }
}


/* The AV Headset Application starts here...*/
int main(void)
{
    /* Set up the Application task handler */
    theAvApp.task.handler = app_handler;

	/* Init the profile instance */
	theAvApp.a2dp = 0;
	theAvApp.avrcp = 0;

    /* Init the local states */
    avHeadsetSetA2dpState(avHeadsetA2dpInitialising);
    theAvApp.avrcp_state = avHeadsetAvrcpInitialising;

	/* Init the scanning flags */
    theAvApp.page_scan_enabled = 0;
    theAvApp.inquiry_scan_enabled = 0;
    theAvApp.pairing_enabled = 0;
    theAvApp.powering_down = FALSE;
	
	/* Init the AV state */
	theAvApp.channel_mode = a2dp_mono;

	/* Init the sinks */
	theAvApp.media_sink = 0;
	theAvApp.avrcp_sink = 0;
    
    /* Initialise the controls */
    avHeadsetInitialiseControls(&theAvApp);
    theAvApp.led_state = led_none;
    startLED(led_none);
    
    /*
        Holding down VOL+ and VOL- on boot up
        deletes the current bonding and so forces discovery.
    */
    if (PioGet() & (1<<4 | 1<<5))
    {
        /* delete current stored value */
		BdaddrSetZero(&theAvApp.remote_bdaddr);
        (void)PsStore(0,&theAvApp.remote_bdaddr,sizeof(bdaddr));
        
        theAvApp.pairing_enabled = 1;
        MessageSendLater(getAppTask(), PAIR_MODE_END, 0, 60000);
        theAvApp.led_state |= led_pairing;	/*lint !e655 */
    }
    else
    {
        /* read our bonded device from the PS */
        (void)PsRetrieve(0,&theAvApp.remote_bdaddr,sizeof(bdaddr));
        DEBUG(("Read PSKey remote of 0x%lx / 0x%x / 0x%x\n",theAvApp.remote_bdaddr.lap,theAvApp.remote_bdaddr.uap,theAvApp.remote_bdaddr.nap));
    }

    
    /* Initialise PIO */
    pioInit(&theAvApp.pio_state, &theAvApp.task);
            
    /* Initialise the Connection Library */
    ConnectionInit(&theAvApp.task);

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

⌨️ 快捷键说明

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