Esempio n. 1
0
bool UsbAudioControl(void)
{
	uint16_t Msg = 0;
    
#ifndef FUNC_MIXER_SRC_EN
	AudioSampleRateSet(44100);
#endif
    
#ifdef FUNC_USB_AUDIO_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO)
	{
		APP_DBG("Enter usb-audio\n");
	}
#endif

#ifdef FUNC_USB_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_READER)
	{
		APP_DBG("Enter sd reader\n");
	}
#endif

#ifdef FUNC_USB_AUDIO_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO_READER)
	{
		APP_DBG("Enter usb-audio-reader\n");
	}
#endif

	if(!IsPcLink())
	{
		APP_DBG("device not ready!\n");
		return FALSE;
	}

	TimeOutSet(&UsbAudioFreqAdjustTimer, 1000);    
	NVIC_EnableIRQ(USB_IRQn);
	UsbSetCurrentPort(PC_PORT_NUM);		// 选择USB端口

	APP_DBG("IsPcLink() OK!\n");

#ifdef FUNC_USB_AUDIO_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO)
	{
		// 单独USB声卡模式,PC识别出USB声卡
		APP_DBG("MODULE_ID_USB_AUDIO\n");
		DeviceAudioSetMode(USB_DEVICE_AUDIO);
		gDeviceVID = 0x0000;
		gDevicePID = 0x0201;
		gDeviceString_Manu = "MVSILICON";					//max length: 32bytes
		gDeviceString_Product = "MV USB AUDIO";				//max length: 32bytes
		gDeviceString_SerialNumber = "20130617A002";		//max length: 32bytes
	}
#endif

#ifdef FUNC_USB_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_READER)
	{
		// 单独USB读卡器模式,PC识别出USB读卡器
		APP_DBG("MODULE_ID_USB_READER\n");
		DeviceAudioSetMode(USB_DEVICE_READER);
		DeviceStorInit();
		gDeviceVID = 0x0000;
		gDevicePID = 0x1000;
		gDeviceString_Manu = "MVSILICON";				// max length: 32bytes
		gDeviceString_Product = "USB CARD READER";		// max length: 32bytes
		gDeviceString_SerialNumber = "20130617B002";	// max length: 32bytes
	}
#endif

#ifdef FUNC_USB_AUDIO_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO_READER)
	{
		// 一线通模式,PC同时识别出USB声卡和USB读卡器
		APP_DBG("MODULE_ID_USB_AUDIO_READER\n");
		DeviceAudioSetMode(USB_DEVICE_AUDIO_READER);
		DeviceStorInit();
		gDeviceVID = 0x0000;
		gDevicePID = 0x0201;
		gDeviceString_Manu = "MVSILICON";				// max length: 32bytes
		gDeviceString_Product = "MV USB AUDIO";			// max length: 32bytes
		gDeviceString_SerialNumber = "20130617C002";    // max length: 32bytes
	}
#endif


	//USB读卡器模式下,设备管理器中显示的磁盘驱动器名称
	gDeviceString_MassStor_Vendor = "MVSI";				// max length: 8bytes
	gDeviceString_MassStor_Product = "USB CARD READER";	// max length: 16bytes
	gDeviceString_MassStor_Ver = "V2.0";				// max length: 4bytes

	//USB声卡模式下,回调函数指针初始化
	gFpDeviceAudioMuteEn = DeviceAudioMuteEn;			// PC端执行MUTE命令时,回调此函数
	gFpDeviceAudioMuteDis = DeviceAudioMuteDis;			// PC端执行UNMUTE命令时,回调此函数
	gFpDeviceAudioSetVolume = DeviceAudioSetVolume;		// PC端改变音量时,回调此函数


	UsbDeviceEnableInt(DEVICE_CONTROL_EP, DeviceAudioOnCmd);
	UsbDeviceEnableInt(DEVICE_BULK_OUT_EP, DeviceAudioOnCmd);

//	CodecDacChannelSel(DAC_CH_DECD_L | DAC_CH_DECD_R); // select dac channel
	UsbDeviceInit();

//	NVIC_EnableIRQ(DECODER_IRQn);


	AudioAnaSetChannel(gSys.MicEnable ? AUDIO_CH_MIC : AUDIO_CH_NONE);	
	MixerConfigFormat(MIXER_SOURCE_USB, USB_DAC_FREQ, MIXER_FORMAT_STERO);
	mixer_pcm_format = MIXER_FORMAT_STERO;
	MixerConfigVolume(MIXER_SOURCE_USB, 4000, 4000);
	MixerUnmute(MIXER_SOURCE_USB);
	MixerEnable(MIXER_SOURCE_USB);

    AudioLeftVolume  = (AUDIO_MAX_VOLUME*3)/4;
    AudioRightVolume = (AUDIO_MAX_VOLUME*3)/4;
    APP_DBG("AudioLeftVolume = %d\n", AudioLeftVolume);
#ifdef FUNC_AUDIO_DRC_EFFECT_EN
	if(gSys.AudioDRCEffectFlag)
	{
		if(DRC_ERROR_OK != init_drc(&gSys.AudioDRCEffectHandle, MIXER_FORMAT_STERO, USB_DAC_FREQ, AUDIO_EFFECT_PARAM_DRC_THRESHHOLD,
							0, AUDIO_EFFECT_PARAM_DRC_RATIO, AUDIO_EFFECT_PARAM_DRC_ATTACK_TIME, 
							AUDIO_EFFECT_PARAM_DRC_RELEASE_TIME, AUDIO_EFFECT_PARAM_DRC_CROSSOVER_FREQ))
        {
            APP_DBG("Init DRC Effect fail,close\n");
            gDRCEffectInited = FALSE;
        }
        else
        {
        	gDRCEffectInited = TRUE;
        }
	}
#endif	
#ifdef FUNC_AUDIO_3D_EFFECT_EN
	if(gSys.Audio3dEffectFlag)
	{
		if(THREE_D_ERROR_OK != init_3d(&gSys.Audio3dEffectHandle, MIXER_FORMAT_STERO, USB_DAC_FREQ, AUDIO_EFFECT_PARAM_3D_BASS, AUDIO_EFFECT_PARAM_3D_MID_BOOST))
        {
            //gSys.Audio3dEffectFlag = 0;
            APP_DBG("Init 3D Effect fail,close\n");
            g3dEffectInited = FALSE;
        }
        else
        {
        	g3dEffectInited = TRUE;
        }
	}
#endif
#ifdef FUNC_AUDIO_VB_EFFECT_EN
    if(gSys.AudioVbEffectFlag)
    {
        if(VB_ERROR_OK != init_vb(&gSys.AudioVbEffectHandle, MIXER_FORMAT_STERO, USB_DAC_FREQ, AUDIO_EFFECT_PARAM_VB_CUTOFF_FREQ, AUDIO_EFFECT_PARAM_VB_LIMITER_EN))
        {
            gVbEffectInited = FALSE;
        }
        else
        {
            gVbEffectInited = TRUE;
        }
    }
#endif 
    SetModeSwitchState(MODE_SWITCH_STATE_DONE);
	while(Msg != MSG_COMMON_CLOSE)
	{
		//UsbDeviceDisableInt(DEVICE_BULK_OUT_EP);
		DeviceStorProcess();
		//UsbDeviceEnableInt(DEVICE_BULK_OUT_EP, DeviceAudioOnCmd);

		DeviceAudioProcess();
        
#if (!defined (OUTPUT_CHANNEL_CLASSD)) && (!defined (OUTPUT_CHANNEL_DAC_CLASSD))      //classd模式下,采用的clk mode = normal mode,禁止使用硬件微调
   #ifndef FUNC_SOFT_ADJUST_EN
        UsbAudioFreqAdjust();
   #endif
#endif        
		Msg = MsgRecv(10);// 消息接收,无消息阻塞20ms,有消息立即返回

		if(Msg == MSG_USB_DEVICE_INTERRUPT_CB)
		{
			UsbIntFlag = FALSE;
		}
                
		switch(Msg)
		{		
			case MSG_POWER:
				gSys.NextModuleID = MODULE_ID_STANDBY;
			case MSG_MODE: // mode change,end of this mode
				APP_DBG("CHANGE_MODE\n");
				// mode change,end of this mode
				Msg = MSG_COMMON_CLOSE;                    
				break;

			case MSG_PLAY_PAUSE:
				APP_DBG("PLAY_PAUSE\n");
				DeviceAudioSendPcCmd(PC_CMD_PLAY_PAUSE);
				break;

			case MSG_PRE:
				APP_DBG("PRE\n");
				DeviceAudioSendPcCmd(PC_CMD_PRE);
				SoundRemind(SOUND_PREV_TRACK);
				break;

			case MSG_NEXT:
				APP_DBG("NEXT\n");
				DeviceAudioSendPcCmd(PC_CMD_NEXT);				
                SoundRemind(SOUND_NEXT_TRACK);
				break;

			case MSG_STOP:
				APP_DBG("STOP\n");
				DeviceAudioSendPcCmd(PC_CMD_STOP);
				break;

			case MSG_MUTE:
				APP_DBG("MUTE\n");
				DeviceAudioSendPcCmd(PC_CMD_MUTE);
				break;
			
#ifdef FUNC_RECORD_EN
			case MSG_REC:  //录音
				gSys.ModuleIDBackUp = gSys.CurModuleID;
				gSys.NextModuleID = MODULE_ID_RECORDER;
				gSys.RecordState = RECORD_STATE_REC;
				gSys.RecordSource = RECORD_SOURCE_LINEIN;
				Msg = MSG_COMMON_CLOSE;
				break;
#endif
           
#ifdef FUNC_REC_PLAYBACK_EN
			case MSG_REC_PLAYBACK:
				EnterRecBackPlay(gSys.CurModuleID, IsUDiskLink() ? DEV_ID_USB : DEV_ID_SD, TRUE, 0, 0);
				break;
#endif
			default:
				CommonMsgProccess(Msg);
				break;
		}
	}

#ifdef FUNC_USB_AUDIO_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO)
	{
		APP_DBG("Leave usb-audio\n");
	}
#endif

#ifdef FUNC_USB_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_READER)
	{
		APP_DBG("Leave sd reader\n");
	}
#endif

#ifdef FUNC_USB_AUDIO_READER_EN
	if(gSys.CurModuleID == MODULE_ID_USB_AUDIO_READER)
	{
		APP_DBG("Leave usb-audio-reader\n");
	}
#endif

	MixerMute(MIXER_SOURCE_USB);
	MixerDisable(MIXER_SOURCE_USB);

	UsbDeviceDisConnect(); // 退出前断开usb device,停止接收数据,以免与SD/U盘播放产生冲突
#ifdef FUNC_USB_EN
	UsbSetCurrentPort(UDISK_PORT_NUM); // set usb host port
#endif
	return TRUE;//OK
}
//设备状态消息(Plugin、PlugOut)处理,成功处理 返回TRUE,否则返回FALSE
bool SysDeviceMsgCtrl(uint16_t Msg)
{
//	uint32_t CurMode;
	uint32_t DevModuleId;

	switch(Msg)
	{
		case MSG_SD_PLUGIN:
			if((gSys.CurModuleID == MODULE_ID_USB_READER) || (gSys.CurModuleID == MODULE_ID_USB_AUDIO_READER))
            {
                return TRUE;
            }
		case MSG_USB_PLUGIN:
		case MSG_PC_PLUGIN:
		case MSG_LINEIN_PLUGIN:
		case MSG_RTC_START_ALARM_REMIND:
            if((gSys.CurModuleID == MODULE_ID_RECORDER) && (gSys.RecordState == RECORD_STATE_REC))
            {
                return TRUE;
            }

			gSys.NextModuleID = GetModeId(Msg);
			return GotoNextMode();	

		case MSG_SD_PLUGOUT:		
		case MSG_USB_PLUGOUT:
		case MSG_PC_PLUGOUT:
		case MSG_LINEIN_PLUGOUT:
		case MSG_RTC_STOP_ALARM_REMIND:
			if(Msg == MSG_SD_PLUGOUT)
			{
				FSDeInit(DEV_ID_SD);
			}
			else if(Msg == MSG_USB_PLUGOUT)
			{
				FSDeInit(DEV_ID_USB);
			}
	
			DevModuleId = GetModeId(Msg);
			if(DevModuleId != gSys.CurModuleID)
			{
				//拔出的不是当前模式对应的设备,则忽略该事件
				return FALSE;
			}
			//拔出的当前模式对应的设备,则按照优先顺序切到下一个模式
			gSys.NextModuleID = GetNextModeIdByProi(MODULE_ID_UNKNOWN);
			return GotoNextMode();			
			
		case MSG_BT_HF_INTO_MODE:
			if(gSys.NextModuleID == MODULE_ID_BT_HF || gSys.CurModuleID == MODULE_ID_BT_HF)
				return FALSE;
			gSys.NextModuleID = MODULE_ID_BT_HF;
			return GotoNextMode();
		case MSG_BT_HF_OUT_MODE:
			APP_DBG("MSG_BT_HF_OUT_MODE SetNextMode:%d\n", gSys.NextModuleID);
			return GotoNextMode();

		// 蓝牙提示音
		case MSG_BT_CONNECTED:
			SoundRemind(SOUND_BT_CONNECT);
			return FALSE;

		case MSG_BT_DISCONNECTED:
			SoundRemind(SOUND_BT_DISCONNECT);
			return FALSE;
		case MSG_BT_PHONE_CALL_INCOMING:
			return FALSE;


        case MSG_MIC_PLUGIN:
			if(gSys.CurModuleID != MODULE_ID_RECORDER)
			{
				SoundRemind(SOUND_MIC_INSERT);  
			}

			if(gSys.CurModuleID == MODULE_ID_LINEIN)
			{
				AudioAnaSetChannel(AUDIO_CH_MIC_LINEIN);
			}
			else if(gSys.CurModuleID == MODULE_ID_RADIO)
			{
				AudioAnaSetChannel(AUDIO_CH_MIC_FM);
			}
			else if(gSys.CurModuleID == MODULE_ID_RECORDER)
			{
				if(gSys.RecordSource == RECORD_SOURCE_LINEIN)
				{
					AudioAnaSetChannel(AUDIO_CH_MIC_LINEIN);
				}
				else if(gSys.RecordSource == RECORD_SOURCE_FM)
				{
					AudioAnaSetChannel(AUDIO_CH_MIC_FM);
				}
			}
			else 
			{
				AudioAnaSetChannel(AUDIO_CH_MIC);
			}	

			return FALSE;
			
		case MSG_MIC_PLUGOUT:
			if(gSys.CurModuleID != MODULE_ID_RECORDER)
			{
				SoundRemind(SOUND_MIC_PULLOUT);  
			}

			if(gSys.CurModuleID == MODULE_ID_LINEIN)
			{
				AudioAnaSetChannel(AUDIO_CH_LINEIN);
			}
			else if(gSys.CurModuleID == MODULE_ID_RADIO)
			{
				AudioAnaSetChannel(AUDIO_CH_FM);
			}
			else if(gSys.CurModuleID == MODULE_ID_RECORDER)
			{
				if(gSys.RecordSource == RECORD_SOURCE_LINEIN)
				{
					AudioAnaSetChannel(AUDIO_CH_LINEIN);
				}
				else if(gSys.RecordSource == RECORD_SOURCE_FM)
				{
					AudioAnaSetChannel(AUDIO_CH_FM);
				}
			}
			else 
			{
				AudioAnaSetChannel(AUDIO_CH_NONE);
			}	
			return FALSE;
			
		default:
			break;
	}

	return FALSE;
}
Esempio n. 3
0
bool LineInControl(void)
{
	uint16_t Msg = 0;
	SW_TIMER LineInTimer;

	APP_DBG("Enter LineInControl...\n");

	if(!IsLineInLink())
	{
		APP_DBG("Exit LineInControl...\n");
		return TRUE;
	}

#ifndef FUNC_MIXER_SRC_EN
	AudioSampleRateSet(44100);
#endif	
	
	SoundRemind(SOUND_LINEIN); 
    
#ifdef FUNC_TREB_BASS_EN
	if(gSys.EqStatus == 0)
	{
		TrebBassSet(gSys.TrebVal, gSys.BassVal);
	}
#endif
	
	if(gSys.MicEnable)
	{
		MixerMute(MIXER_SOURCE_ANA_MONO);	
		MixerMute(MIXER_SOURCE_MIC);
	}
	else
	{
		MixerMute(MIXER_SOURCE_ANA_STERO);
	}
	WaitMs(20);
	
	AudioAnaSetChannel(gSys.MicEnable ? AUDIO_CH_MIC_LINEIN : AUDIO_CH_LINEIN);
	
	if(gSys.MicEnable)
	{
		MixerUnmute(MIXER_SOURCE_ANA_MONO);	
		MixerUnmute(MIXER_SOURCE_MIC);
	}
	else
	{
		MixerUnmute(MIXER_SOURCE_ANA_STERO);
	}
	
	// ÏûÏ¢×¢²á
    if(gSys.MuteFlag)
	{
    	gSys.MuteFlag = 0;
		AudioPlayerMute(gSys.MuteFlag);
	} 

	InitTimer(&LineInTimer, 250, LineInLedCb);
	StartTimer(&LineInTimer);
	AudioSysInfoSetBreakPoint();

	SetModeSwitchState(MODE_SWITCH_STATE_DONE);
	
	while(Msg != MSG_COMMON_CLOSE)
	{
		//led light timer
		CheckTimer(&LineInTimer);
		
		Msg = MsgRecv(5);

		switch(Msg)
		{			
			case MSG_MODE:        //working mode changing
				Msg = MSG_COMMON_CLOSE;
				break;
			
			case MSG_POWER:
				gSys.NextModuleID = MODULE_ID_STANDBY;
				Msg = MSG_COMMON_CLOSE;
				break;
			
#ifdef FUNC_RECORD_EN
			case MSG_REC:  //¼Òô
				gSys.ModuleIDBackUp = gSys.CurModuleID;
				gSys.NextModuleID = MODULE_ID_RECORDER;
				gSys.RecordState = RECORD_STATE_REC;
				gSys.RecordSource = RECORD_SOURCE_LINEIN;
				Msg = MSG_COMMON_CLOSE;
				break;
#endif
           
#ifdef FUNC_REC_PLAYBACK_EN
			case MSG_REC_PLAYBACK:
				EnterRecBackPlay(gSys.CurModuleID, IsUDiskLink() ? DEV_ID_USB : DEV_ID_SD, TRUE, 0, 0);
				break;
#endif

			default:
				CommonMsgProccess(Msg);
				break;

		}
	}
#if (defined(FUNC_BREAKPOINT_EN) && (defined(FUNC_USB_EN) || defined(FUNC_CARD_EN)))
	{
		BP_SYS_INFO *pBpSysInfo;
		pBpSysInfo = (BP_SYS_INFO *)BP_GetInfo(BP_SYS_INFO_TYPE);
		BP_SET_ELEMENT(pBpSysInfo->Volume, gSys.Volume);
        BP_SET_ELEMENT(pBpSysInfo->Eq, gSys.Eq);
		BP_SaveInfo(BP_SAVE2NVM);
	}
#endif
	AudioAnaSetChannel(gSys.MicEnable ? AUDIO_CH_MIC : AUDIO_CH_NONE);	
	APP_DBG("leave LineInControl...\n");
	return TRUE;//OK
}