📄 main.c.svn-base
字号:
#define __MAIN_C
#include "regfile.h"
#include "os.h"
#include "bios.h"
#include "regfile.h"
#include "api.h"
#include "File.h"
#include "Utility.h"
#include "gui.h"
#include "dci.h"
#include "drv_Siu.h"
#include "drv_hiu.h"
#include "ss_SystemConfig.h"
#include "ap.h"
#include "com_port.h"
#include "ip.h"
#include "..\..\..\kernel\Middleware\shell\include\shell.h"
#include "..\Middleware\network\include\net_socket.h"
#include "..\..\..\kernel\Middleware\tracelog\include\trclogtask.h"
#include "bluetooth.h"
#include "..\FunctionControl\pseduoi2s\include\pseudoi2sBufferApi.h"
#include "..\..\..\kernel\plugin\bluetooth\include\spp_mpx.h"
#define MP321_HIU 0
#define MP522_UART 1
#define MP522_HUART 2
#define BT_TEST_TYPE MP522_HUART
#if (BT_TEST_TYPE==MP321_HIU)
//config.f
//IMAGIC_CHIP_TYPE = 0
//LD_FILE=../../../templet/banksize_2m
#define USING_HIUKEY
#define BT_UART COM_OPEN_TAG_UART
#define DPRINT_UART COM_OPEN_TAG_HIU
#elif (BT_TEST_TYPE==MP522_HUART)
//config.f
//IMAGIC_CHIP_TYPE = 2
//LD_FILE=../../../templet/banksize_4m
#define BT_UART COM_OPEN_TAG_HUART
#define DPRINT_UART COM_OPEN_TAG_UART
#elif (BT_TEST_TYPE==MP522_UART)
//config.f modify
//IMAGIC_CHIP_TYPE = 2
//LD_FILE=../../../templet/banksize_4m
//comhuart.c
//void HUartPut(U08* pBuffer, U32 length)
//{
//#if 1
//it can't work, because HUART init first, so it using 96000000
//and then UART init change it to 88500000
#define BT_UART COM_OPEN_TAG_UART
#define DPRINT_UART COM_OPEN_TAG_HUART
#else
#error "not support BT_TEST_TYPE"
#endif
#define OS_HEAP_SIZE (512 * 1024) // omeag is 94KB
//#define OS_HEAP_SIZE 0x00350000
U08 AUDIO_TEST_WORKING_FOLDER[] = "\\Music";
U32 u32Argument[256];
U08 mainTaskMsgId, mainTaskId;
static ST_SHELL_FUNC stShellFunc;
static U08 fsMusicNodePosition;
static U08 u08AutoExecTimerID = -1;
static U08 AutoExecIndex;
static S32 s32AutoExecTaskId = OS_STATUS_INVALID_ID;
static U08 AutoExecEvent = NULL;
typedef struct _AutoExecTableItem
{
U32 tick;
U08 KeyPressed;
} AutoExecTableItem;
static AutoExecTableItem AutoExecTable[12] =
{
{1,13},
{500,1},
{3000,7},
{750,1},
{750,1},
{750,2},
{100,6},
{100,2},
{1,8},
{10,8},
{10,8},
{0,0}
};
static void AutoExecTimerIsr( void )
{
static U32 KeyMessage;
DPrintf("Press Virtual Key: %d", AutoExecTable[AutoExecIndex].KeyPressed);
//Press Virtual key
KeyMessage = SYSTEM_MESSAGE_KEY;
KeyMessage = (KeyMessage << 24) | (U32)AutoExecTable[AutoExecIndex].KeyPressed;
mpx_MessageDrop(mainTaskMsgId, (U08*)&KeyMessage, sizeof(KeyMessage));
mpx_EventSet( AutoExecEvent, 1 );
}
void PmpTestMusicPlayend(void)
{
S32 retCode;
U16 fileFormat;
U08 imageNodePosition;
mpx_TaskPriorityChange(mainTaskId, SYSTEM_TASK_PRI);
DPrintf("INT_AUDIO_PLAY");
imageNodePosition = mpx_DirNodePositionGet();
mpx_DirNodePositionSet(fsMusicNodePosition);
if (mpx_DirNodeForward() != NO_ERR)
{
mpx_DirNodeMove(0);
}
mpx_DirNodePositionRelease(fsMusicNodePosition);
if (mpx_DirExtCompare("MP3") == NO_ERR)
{
fileFormat = FILE_FORMAT_MP3;
}
else if (mpx_DirExtCompare("AAC") == NO_ERR)
{
fileFormat = FILE_FORMAT_AAC;
}
else if (mpx_DirExtCompare("WMA") == NO_ERR)
{
fileFormat = FILE_FORMAT_WMA;
}
else
{
DPrintf("Music format not support");
return;
}
fsMusicNodePosition = mpx_DirNodePositionGet();
mpx_AudioPlayStop();
mpx_AudioClose();
mpx_AudioOpen(0, fileFormat, 0, 0, 0, 0, 0, 0);
mpx_AudioPlayStart(0);
mpx_DirNodePositionSet(imageNodePosition);
mpx_DirNodePositionRelease(imageNodePosition);
mpx_TaskPriorityChange(mainTaskId, UI_TASK_MAX_PRI);
}
void PmpTestIntMsgService(U32 *msgBuffer)
{
U08 tagId = msgBuffer[0] >> 24;
U08 *msgBufferPtr;
if ( (tagId > INT_SERVICE_BASE) &&
(tagId < INT_SERVICE_MAX) )
{
DPrintf("Int-0x%2X triggered", tagId);
msgBufferPtr = (U08 *) &u32Argument[0];
msgBufferPtr += 2;
switch (tagId)
{
case INT_AUDIO_PLAY:
PmpTestMusicPlayend();
break;
case INT_JPG_ENCODE:
//DemoJpgEncodeFinishCallBack();
break;
default:
DPrintf("Undefine INT code - 0x%2X", tagId);
break;
}
}
else
{
DPrintf("Not Int Msg - Tag is 0x%2X", tagId);
}
}
void ApiInit(void)
{
//mpx_SystemParameterInit();
}
BOOL AudioCodec_InitEmbededCodec(U32 codecAct)
{
ST_AUDIO_FREQ_CONFIG pllConfig;
ST_I2S_CONFIG i2sConfig;
#if defined ( CHIP_TYPE_MP322 )
pllConfig.bEmbededCodec = 1;
pllConfig.bAdcDataType = 0;
pllConfig.bOutClkConstant = 0;
pllConfig.bNoMclkOutput = 0; // GPIO0 => 0: Output, 1: Input
pllConfig.u32MultiSampleRate = 256; // KHz (12MHz)
pllConfig.bAutoGanClk = 1;
pllConfig.bSwAgcEnable = 0;
pllConfig.u16SwAgcGainLevel = 0;
if( mpx_AudioFrequencySet(&pllConfig, NULL) )
{
DPrintf("Audio PLL Config setting error!!");
return FALSE;
}
if ( codecAct == 1 )
{
// DAC Action: using I2S1
i2sConfig.u08ModuleNumber = I2S_MODULE_0;
i2sConfig.u08AnalogPath = NO_TRANSMISSION_MODE;
i2sConfig.u16ConfigFlags = 0;
i2sConfig.u16FrameLength = 0;
if( mpx_AudioI2SConfig(&i2sConfig) )
{
DPrintf("Audio I2S Config setting error!!");
return FALSE;
}
i2sConfig.u08ModuleNumber = I2S_MODULE_1;
i2sConfig.u08AnalogPath = MEM_TO_DAC_MODE;
i2sConfig.u16ConfigFlags = 0x1367; // I2S in Master mode
i2sConfig.u16FrameLength = 32;
if( mpx_AudioI2SConfig(&i2sConfig) )
{
DPrintf("Audio I2S Config setting error!!");
return FALSE;
}
}
if ( codecAct == 0 )
{
// ADC Action: using I2S0
i2sConfig.u08ModuleNumber = I2S_MODULE_0;
i2sConfig.u08AnalogPath = ADC_TO_EXT_MODE;
i2sConfig.u16ConfigFlags = 0x133a; // I2S in Slave mode
i2sConfig.u16FrameLength = 32;
if( mpx_AudioI2SConfig(&i2sConfig) )
{
DPrintf("Audio I2S Config setting error!!");
return FALSE;
}
// DAC Action: using I2S1
i2sConfig.u08ModuleNumber = I2S_MODULE_1;
i2sConfig.u08AnalogPath = EXT_TO_DAC_MODE;
i2sConfig.u16ConfigFlags = 0x133a; // I2S in Slave mode
i2sConfig.u16FrameLength = 32;
if( mpx_AudioI2SConfig(&i2sConfig) )
{
DPrintf("Audio I2S Config setting error!!");
return FALSE;
}
}
return TRUE;
#else
return FALSE;
#endif
}
void mainInit(void)
{
mpx_CkgPllInit(CKG_CLOCK_SEL_PLL2);
UtilGpioInit();
//mpx_UartInit();
//mpx_UartIntEnable();
IntEnable();
mpx_OsInit(OS_HEAP_SIZE);
mpx_GpioIntInit();
mpx_ComInit();
#ifdef USING_HIUKEY
mpx_HiuIntEnable();
#endif
}
/********************uart testing*****************/
ST_COM_PORT *hicom;
U08 hrxbuf[30000];
U08 rxbuf[1000];
////////////////////////////////////////////////////////////////////////////
//
//
//
//
///////////////////////////////////////////////////////////////////////////
#define BTINT_CATEGORY(buf) (buf[4])
#define BTINT_TYPE(buf) (buf[5])
#define BTINT_ACTION(buf) (buf[6])
#define BTINT_WHO(buf) (buf[7])
#define BTINT_DATALEN(buf) ((buf[2] << 16) + buf[3])
#define BTINT_U32DATA(buf, n) (*(U32*)(buf+8+(n<<2)))
#define BTINT_U08DATA(buf, n) (*(buf+8+n))
typedef struct _MnuItem {
U16 key;
U16 cmd;
U08 *text;
U08 enabled;
} ST_MENU_ITEM;
typedef struct ST_MENU
{
void (*handler)(U32 type, ...); //BTCMD or BTINT
ST_MENU_ITEM *items;
BOOL refresh;
}ST_MENU;
#define BTCMD 0
#define BTINT 1
U08 btexit = FALSE;
ST_MENU *pagemenu;
void MenuShow()
{
U08 first = TRUE;
ST_MENU_ITEM *m;
if(pagemenu->refresh == TRUE)
{
for(m = pagemenu->items; m->key; m++)
{
if(m->enabled)
{
if(first)
{
DPrintf("*****************************************");
first = FALSE;
}
DPrintf("\t\t%1d : %s", m->key, m->text);
}
}
if(!first)
{
DPrintf("*****************************************");
DPrintf("please input key :\\-");
}
pagemenu->refresh = FALSE;
}
}
void MenuItemDisable(U16 cmd)
{
ST_MENU_ITEM *m;
for(m = pagemenu->items; m->key; m++)
{
if(cmd == m->cmd)
{
if(m->enabled == TRUE)
{
m->enabled = FALSE;
pagemenu->refresh = TRUE;
}
}
}
}
void MenuItemEnable(U16 cmd)
{
ST_MENU_ITEM *m;
for(m = pagemenu->items; m->key; m++)
{
if(cmd == m->cmd)
{
if(m->enabled == FALSE)
{
m->enabled = TRUE;
pagemenu->refresh = TRUE;
}
}
}
}
BOOL BtProcessKey(U16 key)
{
ST_MENU_ITEM *m;
for(m = pagemenu->items; m->key; m++)
{
if(key == m->key && m->enabled)
{
DPrintf("%2d", key);
pagemenu->handler(BTCMD, m->cmd);
return TRUE;
}
}
}
void BtProcessInt(U08* buffer)
{
pagemenu->handler(BTINT, buffer);
}
/***************************************************************************/
/*
* main menu
*/
#define BT_START 0
#define BT_EXIT 1
#define BT_STOP 2
#define BT_SETTING 6
#define BT_DEVLST 3
#define BT_OPP 4
#define BT_FTP 5
#define BT_A2DP_SRC 7
#define BT_HANDSET_GW 8
#define BT_SPP 9
#define BT_HANDSET 10
void MainMenuHandler(U32 type, ...);
const ST_MENU_ITEM MainMenuItem[] = { {1, BT_START, "start bluetooth", TRUE},
{1, BT_STOP, "stop bluetooth", FALSE},
{2, BT_EXIT, "exit bluetooth function", TRUE},
{3, BT_SETTING, "bluetooth setting", FALSE},
{4, BT_DEVLST, "devices list", FALSE},
{5, BT_OPP, "opp profile", FALSE},
{6, BT_FTP, "ftp profile", FALSE},
{7, BT_A2DP_SRC,"a2dp source profile", FALSE},
{8, BT_HANDSET_GW,"handset gw profile", FALSE},
{9, BT_SPP ,"spp profile", FALSE},
{10, BT_HANDSET ,"Handset profile", FALSE},
{0, 0, 0, 0}};
const ST_MENU MainMenu = {MainMenuHandler, MainMenuItem, TRUE};
/***************************************************************************/
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -