123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #include "includes.h"
- unsigned long g_ulKeyValue;
- unsigned char g_ucKeyFree=0;
- unsigned char g_ucKeyMode=0;
- unsigned char g_ucKeyPPTPress=0;
- unsigned char g_ucUKC=0;
- signed char Headsetsta=0;
- unsigned short KeyScan(void)
- {
- unsigned char i;
- unsigned short RetDat=0;
- HC165_PL_LOW;
- HC165_PL_HIGH;
- for(i = 0; i < 16; i++)
- {
- RetDat <<= 1;
- if(HC165_DATA_READ == 1)
- {
- RetDat |= 0x01;
- }else RetDat &= 0xFFFE;
-
- HC165_CP_LOW;
- HC165_CP_HIGH;
- }
- HC165_CP_LOW;
- return RetDat;
- }
- void CheckPwrKeyOn(void)
- {
- unsigned int tick=0;
- if(KeyPwrStatus !=0)
- {
- POWER_ON_FAILED:
- SlwTrace(INF, "\r\nPwrOnFailed",1);
- DelayMs(10);
- PWR_EN_LOW;
- while(1);
- }
-
- while(KeyPwrStatus==0)
- {
- if(++tick >= 200000)
- {
- MODEM_LED2_HIGH;
- SlwTrace(INF, "\r\nPwrOnOk",1);
-
- PWR_EN_HIGH;
- return;
- }
- }
- SlwTrace(INF,"\r\nPwr erro",1);
- goto POWER_ON_FAILED;
- }
- void OnOff_Init(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO , ENABLE);
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = ONOFF_CK_PIN;
- GPIO_Init(ONOFF_CK_PORT, &GPIO_InitStructure);
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource2);
- EXTI_InitStructure.EXTI_Line = EXTI_Line2;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
- void EXTI2_IRQHandler(void)
- {
- if(SET==EXTI_GetFlagStatus(EXTI_Line2))
- {
- if(modemInitReady==1)
- {
- PWR_EN_HIGH;
- modemPwrOffNow=1;
- }
- EXTI_ClearFlag(EXTI_Line2);
- }
- }
- void SoftPwrOffCheck(void)
- {
- static unsigned int seconds;
-
- if(!seconds) seconds=uSysTickGet()+500;
-
- if(KeyPwrStatus==0)
- {
- if(uSysTickGet() > seconds)
- {
- SlwTrace(INF, "PwrOffOk",1);
- MODEM_LED1_HIGH;
-
-
- GuiClearAll();
- GuiShowBmp(0,0,"BYEBYE.bmp");
- MODEM_PWREN_LOW;
- PWR_EN_LOW;
- MODEM_LED1_LOW;
- while(1);
- }
- }else seconds=uSysTickGet()+200;
-
- }
- void KeyInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
- GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);
-
-
-
-
- GPIO_InitStructure.GPIO_Pin = BEEP_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(BEEP_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin=GPIO_InitStructure.GPIO_Pin=HC165_READ_PIN;;
- GPIO_Init(HC165_READ_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin=GPIO_InitStructure.GPIO_Pin=HC165_PL_PIN;;
- GPIO_Init(HC165_PL_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin=GPIO_InitStructure.GPIO_Pin=HC165_CP_PIN;;
- GPIO_Init(HC165_CP_PORT, &GPIO_InitStructure);
-
- g_ucKeyMode=0;
- HC165_PL_LOW;
- HC165_CP_LOW;
- }
- int GetKey(void)
- {
- static unsigned char sucCt=0;
- static unsigned char sucFlag=0;
- static unsigned char sucPress=0;
- static unsigned char sucLastPress=0;
- static unsigned short Key=0;
- static unsigned short Key1=0;
- static unsigned short Key2=0;
- static signed char LastHeadsetsta=0;
-
-
-
- if(++sucFlag>2){
- sucFlag=0;
- }
- if(sucFlag==0){
- Key1=KeyScan();
- }else{
- Key2=KeyScan();
- }
-
- if(Key1!=Key2)return 0;
-
-
- if(Key1&(0x01<<2)){
-
- Headsetsta=0;
-
- }else {
-
- Headsetsta=1;
- }
- if(LastHeadsetsta!=Headsetsta&&sutUIstatus.Status!=UIS_NULL){
- LastHeadsetsta=Headsetsta;
- if(LastHeadsetsta){
- GuiShowBmp(120,0,"Ear.bmp");
- printf("耳机接入\r\n");
- SPK_MAIN_MUTE_HIGH;
- }else{
- printf("耳机拔出\r\n");
-
-
-
- GuiShowStr(120,1," ",0x01,0);
- SPK_MAIN_MUTE_LOW;
- }
- SetSpkLvProcess(2);
- }
- Key1=Key1&HEDESET_DET;
-
-
- if(Key!=Key1){
- Key=Key1;
- if(Key!=KEY_ALL_IDLE)
- {
- sucPress=1;
- printf("KEY=%x\r\n",Key);
- }
- else
- {
- sucPress=0;
- }
- }
- if(sucPress){
- if(g_ucKeyMode){
- if(sucLastPress!=sucPress){
- sucLastPress=sucPress;
- g_ulKeyValue=Key;
- return 1;
- }else{
- return 0;
- }
- }else{
- sucLastPress=sucPress;
- if(0==sucCt){
- g_ulKeyValue=Key1;
- sucCt=25;
- return 1;
- }else{
- sucCt--;
- return 0;
- }
- }
- }else{
- sucCt=0;
- if(sucLastPress){
- sucLastPress=0;
- return -1;
- }
- }
- return 0;
- }
- void KeyCount(void)
- {
-
- if(g_ucUKC<255)g_ucUKC++;
- }
|