app_cmd_bt.c 6.24 KB
#include "os_config.h"

#include "c_def.h"
#include "debug.h"
#include "oem.h"

#include "regmap.h"

#include "mem_reloc.h"

#include "audio_dec.h"
#include "audio_com.h"

#include "hw_uart.h"
#include "hw_misc.h"
//#include "da_pp.h"
//#include "hw_rtc.h"
#include "hw_timer.h"

#include "message.h"


#include "app_string_oem.h"
#include "app_main.h"
#include "app_process.h"
#include "app_cmd.h"
#include "app_sdram.h"
#include "Audio_Device.h"
#include "bt_common.h"
#include "optek_link.h"

void app_nav_rmt_convert_bt_hci(void)
{
	U8 *p;
	//STREAM_ID s;
	//SDRAM_STREAM_CONFIG stream_config;
	U8 *pStreamBuf;
	U32 size;

	if (app_main_data.media != MEDIA_BT_HCI)
	{
		if (app_nav_media_finish())
		{
			return;
		}

		DBG_Printf("covert to BT HCI\n");

#ifdef OPL_MASTER_ENABLE	
		if(app_main_data.share_link_role != SL_ROLE_SLAVE)
		{
	void app_change_mode_req(u8 mode, u8 max_master_tx_len, u8 max_master_rx_len);
			//app_change_mode_req(IDLE_W_BT,6,6);
			app_change_mode_req(TWS_SUBW_W_BT_T6_SF44K,245,6);
			//optek_link_role_stop();
			delayms(100);
		}
#endif


		if(app_main_data.share_link_role != SL_ROLE_SLAVE)
		{
			if (bt_status.bt_main_status == enBT_DISCONNECTED)
			{
				app_bt_set_scan_enable_mode(enBT_BOTH_SCAN_ENABLE);
			}
		}		
		//AMPLIFIER_MUTE_ON;

//		app_cmd_DecoderExit();

#ifdef PCM_RECEIVE_ENABLE
		app_dac_receive_pcm_enable(FALSE);
#endif

		//app_sdram_stream_flush ();

		app_main_data.media = MEDIA_BT_HCI;
		//app_main_data.pre_media = MEDIA_BT_HCI;

#ifdef BT_ID3_DISPLAY_EANBLE
		app_main_data.disp_info = DISP_INFO_WAITING;
		track_id3_ready = FALSE;
		track_id3_rx_flag = DISP_INFO_TITLE;
		memset( id3_tag.title, 0, (MAX_ID3_TEXT + 1)*2);
		memset( id3_tag.artist, 0, (MAX_ID3_TEXT + 1)*2);
		memset( id3_tag.album, 0, (MAX_ID3_TEXT + 1)*2);
#endif

#if 0//def BT_HFP_ENABLE
		da_pp_music_eq();
#endif

#if 0
		uart_setBaudRate(en_UART0, UART_BT_HCI_INIT_BAUD, SystemClock/2);

#ifdef UART0_TX_DMA
		//when open, it is ready send data
		tx_event_flags_set(&event_grop, UART0_TX_EVENT, TX_OR);
#endif

#ifdef UART0_RX_DMA
		//init Uart0 rx DMA
		pDmaSource = (U32 *)( UART0_BASE_ADDR + 24 );
		//pDmaSource = (U32)( &REG_UART0_RX_DATA);
		DMA_Channel4_Init(uart0_rx_dma_buf, pDmaSource,UART0_RX_DMA_BUF_SIZE, SOURCE_DMA_UART_0_RX);
#endif //UART0_RX_DMA

#endif

#if 0
		ht_hci_init ();
		ht_hci_open ();
#endif

		//app_lcd_stream_type_icon(STREAM_UNKNOWN);
		//app_lcd_disp_stop();
		//app_lcd_disp_media();
		//app_lcd_disp_reading();
		//app_cmd_clear_timer_convert_flag();
		//app_cmd_clear_snooze_flag();

		//timer_delayms(5);

		//miscPll_power_up();
		//misClockFreq_Set(app_main_data.sys_freq);

		app_timer_window_time_set(0);
		app_nav_window_set(&dummy_window, app_window_data.window_index);

		//app_main_data.Mute = FALSE;

		app_main_data.ui_background = app_nav_bt_hci_process;
		app_timer_window_time_set (0);

		//app_nav_spk_level_init ();

		//app_save_system_data();

#ifdef UART0_ENABLE
		//app_uart0_fifo_init();
		//uart_setBaudRate( en_UART0, 921600, SystemClock/2 );
#endif

		p = (U8 *) STRING_HTHCI_APP;
		CPU_SoftReset_Flag_Setting((U8 *) p, FALSE);

		app_nav_window_set(&bt_hci_window, 0);


		app_nav_window_set(&bt_hci_window, 0);
		AUDIO_FIFO_STREAM_FLUSH();

#ifdef STREAM_BUFFER_SIZE_UNFIXED

		if (app_main_data.share_link_role == SL_ROLE_SLAVE)
		{
			pStreamBuf = MP3_STREAM_START;
			size = MP3_STREAM_END - MP3_STREAM_START;
		}
		else
		{
			pStreamBuf = BT_STREAM_START;
			size = BT_STREAM_END - BT_STREAM_START;
		}

#else
		pStreamBuf = stream_buffer;
		#ifdef STREAM_BUFFER_USED_POINTER
		size = STREAM_BUF_MAX_SIZE;
		#else
		size = sizeof(stream_buffer);
		#endif
#endif

		AUDIO_FIFO_STREAM_OPEN(pStreamBuf, size);

		AUDIO_FIFO_STREAM_CREATE(0, STREAM_LENTH_UNKNOWN, 0, 0);

		app_main_data.playing_stream_status = STREAM_WAITING_DATA;
		app_main_data.ui_background = app_nav_bt_hci_process;

		#ifdef BT_RELINK_ENABLE
		if(app_main_data.share_link_role != SL_ROLE_SLAVE)
		{
			//uiBtHCI_relink();
			app_timer_bt_reLinktTimer_time_set(3000);
		}
		#endif
		
		if (app_main_data.share_link_role == SL_ROLE_SLAVE)
		{
#if (defined OPL_MODE_TWO_WAY || defined OPL_MODE_SINGLE_WAY)	
			uDecSend(DECODE_SET,DECODE_LC3);	
#elif defined OPL_MODE_WIRELESS_MIC
			//uDecSend (DECODE_INIT, 0);
			uDecSend(DECODE_SET,DECODE_PCM);
#else	
			uDecSend(DECODE_SET,DECODE_PCM_DOWNSAMPLE);	
#endif					
		}
		else
		{
			uDecSend(DECODE_SET,DECODE_SBC);
		}
		/*{
			app_main_data.playing_stream_status = STREAM_DEC_INIT;
			entry_id3_flag = ID3_UNKNOWN;
			app_main_data.coming_stream_status = STREAM_MEDIA;
			app_main_data.coming_stream_type = STREAM_DATA_CDROM;


			uDecSend (DECODE_SET, DECODE_SBC);
			//app_main_data.ui_background = app_nav_mp3_process;

			app_sdram_stream_flush ();

			//stream_config.start_addr = (long) SDRAM_MP3_STREAM_START ;
			//stream_config.end_addr = (long) SDRAM_MP3_STREAM_END;
			stream_config.start_addr = (long) BT_STREAM_START;
			stream_config.end_addr = (long) BT_STREAM_END;
			stream_config.overwrite = FALSE;
			app_sdram_stream_open (&stream_config);

			s = app_sdram_stream_create_wstream(0,
				-1,
				0);

			DBG_Assert(s != INVALID_STREAM_ID);
			s = app_sdram_stream_open_rstream(s);
			DBG_Assert(s != INVALID_STREAM_ID);
		}*/


#if defined AUDIO_CODEC_USED_CHANNEL
		AUDIOdevice.Set_Channel(app_main_data.media);
#elif defined AUDIO_AMP_USED_CHANNEL
		audioAmp_Dev.Set_Channel(app_main_data.media);
#endif

#if defined AUDIO_CODEC_USED_VOL
		AUDIOdevice.Set_Volume(app_main_data.volume);
#elif defined AUDIO_AMP_USED_VOL
#ifndef AUDIO_AMP_MUTE_BY_VOLUME_0
		audioAmp_Dev.Set_Volume(app_main_data.volume);
#endif
#endif

#if 0//def VOLUME_AUTO_PLUS
		if (timer_alarm_power_on)
		{
			app_timer_vol_auto_plus_time_set(1000);
		}
		else
		{
			//don't need this in stop.
			if ( (app_main_data.volume > VOLUME_AUTO_PLUS_DEFAULT) && volume_need_auto_plus)
			{
				volume_need_auto_plus = FALSE;
				app_main_data.volume_bak = app_main_data.volume;
				app_main_data.volume = VOLUME_MIDDLE;
				app_nav_volume_auto_plus();
				app_timer_vol_auto_plus_time_set(1000);
			}
		}
#endif

#ifdef PCM_RECEIVE_ENABLE
#ifdef MIC_MIXER
		app_dac_receive_pcm_enable(TRUE);
#endif
#endif

		//AMPLIFIER_MUTE_OFF;
		//app_timer_mute_off_time_set(3000);

		app_timer_window_time_set (app_main_data.window->window_time);
	}

	DBG_Printf("BT HCI Exit\n");
}