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

📄 main.c.svn-base

📁 一款蓝牙芯片的驱动和应用代码
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
	static S32 fd, ClientFd;
	U08 buf[16];
	
    cmd = *(U32*)(((U08*)&type)+4);
    buffer = *(U32*)(((U08*)&type)+4);

    if(type == BTCMD)
    {
        switch(cmd)
        {
			case SPP_CLIENT_CONNECT:
                if(mpx_BtSppCliConnect())
                    DPrintf("connect fail");
                break;
			case SPP_CLIENT_DISCONNECT:
                if(mpx_BtSppCliDisconnect())
                    DPrintf("disconnect fail");
                break;
			case SPP_EXIT:                
                pagemenu = &MainMenu;
                pagemenu->refresh = TRUE;
				break;
        }
    }
    else
    {
        U08 inttype;
        U08 intaction;

        inttype = BTINT_TYPE(buffer);
        intaction = BTINT_ACTION(buffer);

        switch(intaction)
        {
            case REMOTE_DEVS:
                if(mpx_BtRemoteDevListNumGet(0))
                {
                    mpx_BtSelectDevsFromDevList(BRD_LIST_TRUSTED, SelectTrustedDevice());
                }
                else //no device in list
                    mpx_BtSelectDevsFromDevList(BRD_LIST_TRUSTED, 0xff);
            
                break;
            case SPP_LINK_CONNECT_CNF:
	            if(inttype == INFORM_COMPLETE)
	            {
	                DPrintf("client acl established");
	            }
	            break;
            case SPP_LINK_DISCONNECT_IND:
	            if(inttype == INFORM_COMPLETE)
	            {
	                DPrintf("client acl disconnect");
	            }
	            break;
            default:
                BtDefaultIntHandler(buffer);
                break;
        }
    }
}

void StartBluetoothTest()
{

    static BOOL IsBtIntReg = FALSE;
    
    if(IsBtIntReg == FALSE)
        mpx_BtIntHandleRegister(mainTaskMsgId);

    pagemenu = &MainMenu;

    while(1)
    {
        MenuShow(pagemenu);

        if(btexit) 
        {
            pagemenu->refresh = TRUE;
            break;
        }
        
        mpx_MessageReceive(mainTaskMsgId, (U08*)u32Argument);

        switch((u32Argument[0]>>24) & 0xE0)
        {
            case SYSTEM_MESSAGE_KEY:
                BtProcessKey(u32Argument[0] & 0xffff);
            break;

            case SYSTEM_MESSAGE_INT:
                BtProcessInt((U08*)u32Argument);
            break;

            default:
                DPrintf("unknow MsgId = %x", u32Argument[0]);
                break;
        }
    }

    btexit = FALSE;
}

U08 hrxeid;

void Huart_rx_info()
{
    mpx_EventSet(hrxeid, 1);
}


void Huart_rx_task()
{
    U32 release;
    DPrintf("open HUART tx rx com.......");

    //create message
    hrxeid = mpx_EventCreate(OS_ATTR_WAIT_MULTIPLE|OS_ATTR_EVENT_CLEAR, 0);

    //create com port
    if(mpx_ComOpen(&hicom, COM_OPEN_TAG_BT, COM_OPEN_TYPE_RXTX, hrxbuf, 30000, 1, Huart_rx_info, 921600))
		DPrintf("COM open fail");
    else
        DPrintf("COM open success");

    while(1)
    {
        mpx_EventWait(hrxeid, 1, OS_EVENT_OR, &release);
        while(hicom->ComRxCount(hicom))
        {
            U32 len;

            //read data from hrxbuf
            len = hicom->ComRxCount(hicom);
            hicom->ComRead(hicom, len, rxbuf);

            //print the read data
            U08 *data;
            data = rxbuf;

            //prevent the print influent the execution
            //if(len > 10)
            //    len = 10;

            while(len--)
            {    
                DPrintf("%c\\-", *data);
                data++;
            }        
        }    
    }
}


void StartComTest()
{
    BOOL quit = FALSE;

    mpx_TaskStartup(mpx_TaskCreate(Huart_rx_task, 25, 1000));    

}
////////////////////////////////////////////////////////////////////////////
//
//  Test Audio Region
//
////////////////////////////////////////////////////////////////////////////
BOOL MoveToWorkingFolder(U08* folderName)
{
    U16 *tempString = (U16 *) mpx_Malloc(512);
    //ST_DRIVE *drv = DriveGet(DriveCurIdGet());

    UtilStringCopy0816(tempString, folderName);
    mpx_DirRootChange();

    if(0 != mpx_DirNodeLocate(tempString))
    {
        DPrintf("no - %s - folder found", folderName);
        mpx_Free(tempString);
        return FALSE;
    }

    mpx_DirSubChange();

    if(!mpx_DirNodeCountGet())
    {
        DPrintf("In folder %s - no file found", folderName);
        mpx_Free(tempString);

        return FALSE;
    }

    mpx_Free(tempString);

    return TRUE;
}

void DisplayCurrentNodeName()
{
    U16 *wName = (U16*)mpx_Malloc(512);
    U16 actualLen = 0;
    U08 *tempStr;
    //ST_DRIVE *drv = DriveGet(DriveCurIdGet());
    //U16 i = 0;

    //wName = (U16 *) DirNodeWNameGet((ST_STREAM *) drv);
    mpx_DirNodeNameGet(wName, 512, &actualLen);
    tempStr = (U08 *) malloc(256);
    DPrintf("\n\nCurrent node name: %s", mpx_UtilUni2Asc(tempStr, wName));
    free(tempStr);
    mpx_Free(wName);
}

BOOL AudioCodec_InitWOLFSON8750()
{
    ST_AUDIO_FREQ_CONFIG pllConfig;
    ST_I2S_CONFIG  i2sConfig;
    U16 word[20];

    pllConfig.bEmbededCodec = 0;        //using WOLFSON8750 ADC for Mic input
    pllConfig.bAdcDataType = 0;
    pllConfig.bOutClkConstant = 1;
    pllConfig.bNoMclkOutput = 0;            // GPIO0 => 0: Output, 1: Input
    pllConfig.u32MultiSampleRate = 12000;            // KHz (12MHz)
    pllConfig.bAutoGanClk = 1;
    pllConfig.bSwAgcEnable = 1;
    pllConfig.u16SwAgcGainLevel = 31;

    if(mpx_AudioFrequencySet(&pllConfig,word))
    {
        DPrintf("Audio PLL Config setting error!!");
        return FALSE;
    }

    i2sConfig.u08ModuleNumber = I2S_MODULE_0;
    i2sConfig.u08AnalogPath = MEM_TO_EXT_MODE;
    i2sConfig.u16ConfigFlags = 0x0327;
    i2sConfig.u16FrameLength = 32;

    if(mpx_AudioI2SConfig(&i2sConfig))
    {
        DPrintf("Audio PLL Config setting error!!");
        return FALSE;
    }

    return TRUE;
}
BOOL AudioTestInit()
{
    if(!MoveToWorkingFolder(AUDIO_TEST_WORKING_FOLDER))
        return FALSE;

//    mpx_DirChangeToSub();
    DisplayCurrentNodeName();

    return TRUE;
}

S08 TestMoveToStart(void)
{
    S08 retCode;

    retCode = mpx_DirNodeMove(0);
    DisplayCurrentNodeName();

    return retCode;
}

S08 TestMoveToNext(void)
{
    S08 retCode;

    retCode = mpx_DirNodeForward();
    DisplayCurrentNodeName();

    return retCode;
}

S08 TestMoveToPrevious(void)
{
    S08 retCode;

    retCode = mpx_DirNodeBackward();
    DisplayCurrentNodeName();

    return retCode;
}

void SetProgressForwardTest()
{
   U32  progressTime;
   BOOL enableSpectrum;
   U16 nothing[8];

   mpx_AudioProgressGet(&progressTime,(U16*)nothing,&enableSpectrum);
   DPrintf("in");
   mpx_AudioProgressCtrl(progressTime+1000,0x01);
   DPrintf("ou");
   DPrintf("progress time =%d ms",progressTime);
}

void SetProgressBackwardTest()
{
    U32  progressTime;
    BOOL enableSpectrum;
    U16 nothing[8];

    mpx_AudioProgressGet(&progressTime,(U16*)nothing,&enableSpectrum);
    progressTime = (progressTime>1000)? (progressTime-1000):0;
    DPrintf("progress time =%d ms",progressTime);
    DPrintf("in");
    mpx_AudioProgressCtrl(progressTime,0x01);
    DPrintf("ou");
}

void StartAudioTest()
{
    BOOL quit = FALSE;
    U08* pNodeName;
    U32  u32Duration;
    U32  u32SampleRate;
    U32  audioLength;
    U32  bitRate;
    U32  sampleRate;
    U08  channelNumber;
    static U08  isFileOpen = FALSE;
    static U08  isRecord = FALSE;
    U32  status;
    static U08 playing_flag = FALSE ;
    static U08  initPcm = FALSE;
    U08 szFileName[13];
    S32 sts;
    U08 handle;
    U08 audioType = FILE_FORMAT_MP3;
    static U08 audioTypeCnt=0;
    static U32  progressTime;
    U08 recordSelect = FILE_FORMAT_AMR;
//    U08 recordSelect = FILE_FORMAT_WAV;
    U08 testff = FALSE ;
    U16 serialNum;
    typedef void (*funcptr)();
    funcptr SetProgressTest = SetProgressForwardTest;
    static U08 testProgressTimer = FALSE;
    U08 u08AudioTestTimerID;
    U16 spectrumData[16];
    BOOL spectrumEnable;
    U08 amGain=0;

    DPrintf("start audio test");

//pd initail

    if(!AudioTestInit()||mpx_AudioFunctionsStartup())
    {
        DPrintf("Audio initail fail");
        return ;
    }

    mpx_AudioIntHandleRegister(mainTaskMsgId);

    while(!quit)
    {
        DPrintf(" ");
        DPrintf("==========     Audio Test    =============");
        DPrintf("|                                        |");
        DPrintf("|    Key definition:                     |");
        DPrintf("|           1         3                  |");
        DPrintf("|                2                       |");
        DPrintf("|           4    5    6                  |");
        DPrintf("|           7    8    9                  |");
        DPrintf("|           10   11   12                 |");
        DPrintf("|                                        |");
        DPrintf("|   Press 1  to                          |");
        DPrintf("|   Press 2  to select recording format  |");
        DPrintf("|   Press 3  to quit                     |");
        DPrintf("|   Press 4  to get audio progress       |");
        DPrintf("|   Press 5  to start/stop audio record  |");
        DPrintf("|   Press 6  to recode pause/resume      |");
        DPrintf("|   Press 7  to previous file            |");
        DPrintf("|   Press 8  to open/Play/stop audio play|");
        DPrintf("|   Press 9  to next file                |");
        DPrintf("|   Press 10 to close file               |");
        DPrintf("|   Press 11 to progress forward test    |");
        DPrintf("|   Press 12 to progress backward test   |");
        DPrintf("==========================================");
        DPrintf(" ");

        mpx_MessageReceive(mainTaskMsgId, (U08*)u32Argument);
        switch(u32Argument[0]>>24)
        {
            case SYSTEM_MESSAGE_KEY:
            {
                switch(u32Argument[0] & 0xffff)
                {
                    case 1:

                        mpx_AudioProgressGet(&progressTime,(U16*)spectrumData,&spectrumEnable);
                        progressTime = (progressTime>1000)? (progressTime-1000):0;
                        DPrintf("progress time =%d ms",progressTime);
                        mpx_AudioProgressCtrl(progressTime,0x1);

//                        mpx_AmplifierChannelGainSet(LEFT_CHANNEL_PATH|RIGHT_CHANNEL_PATH, amGain-=20);
                    break;

                    case 2:
#ifdef AUDIO_MIXER_TEST
                        StartAudioMixerTest();
#else
/*
                          mpx_FmTunerInit();
                          //AudioCodec_EnableAnalogPath();
                          mpx_AudioCodecAnalogPathSet(AUX_INPUT, ADC_OUTPUT|SPEAKER_OUTPUT|HEADPHONE_OUTPUT, TRUE);
                          mpx_AudioCodecMuteSet(AUX_INPUT|ADC_OUTPUT|SPEAKER_OUTPUT|HEADPHONE_OUTPUT, FALSE);
                          mpx_AudioCodecVolumnSet(SPEAKER_OUTPUT, 0x15);
                          mpx_AudioCodecVolumnSet(HEADPHONE_OUTPUT, 0x15);
                          mpx_AudioCodecVolumnSet(ADC_OUTPUT, 0xc);
                          mpx_AudioCodecVolumnSet(AUX_INPUT, 0x1);

                          if ( mpx_FmTunerPowerUp(0) )
                              DPrintf("Fm Tuner Power Up Failure");
*/
/*
                        if ( mpx_AmplifierInit() )
                            DPrintf("Amplifier Initial Fail !!");
                        else if ( mpx_AmplifierPowerUp(LEFT_CHANNEL_PATH|RIGHT_CHANNEL_PATH) )
                            DPrintf("Amplifier Power Up Fail !!");
*/
                        if(recordSelect == FILE_FORMAT_WAV)
                        {
                            recordSelect = FILE_FORMAT_AAC;
                            DPrintf("AAC Encoder");
                        }
                        else if (recordSelect == FILE_FORMAT_AAC)
                        {
                             recordSelect = FILE_FORMAT_G729;
                             DPrintf("G729 Encoder");
                        }

                        else if (recordSelect == FILE_FORMAT_G729)
                        {
                            recordSelect = FILE_FORMAT_AMR;
                            DPrintf("AMR Encoder");
                        }
                        else if (recordSelect == FILE_FORMAT_AMR)
                        {
                            recordSelect = FILE_FORMAT_WAV;
                            DPrintf("WAV Encoder");
                        }

#endif
                    break;

                    case 3:
//                          mpx_AmplifierChannelGainSet(LEFT_CHANNEL_PATH|RIGHT_CHANNEL_PATH, amGain+=20);
                        quit = TRUE;
                        //mpx_SysApIntHandl

⌨️ 快捷键说明

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