📄 dvb_fp.c
字号:
/******************************************************************************
(C)Copyright Cheertek Inc. 2002-2005,
K000, all right reserved.
Product : STB Firmware
******************************************************************************/
#include <string.h>
#include "dev_fd.h"
#include "dev_ir.h"
#include "dev_kd.h"
#include "dvb_msg.h"
#include "dvb_sys.h"
#include "dvb_timer.h"
#include "dvb_fp.h"
#include "ct_os.h"
#include "ct_ir_kd.h"
#include "ir_defs.h"
#include "ct_fp.h"
//#include "io_config.h"
/*******************************************************************************************/
#if 1
#define FP_MSG(p)
#else
#define FP_MSG(p) printf p
#endif
#if 1
#define FP_DBG(p)
#else
#define FP_DBG(p) printf p
#endif
/*******************************************************************************************/
#define KEY_BUFFER_SIZE 4
/*******************************************************************************************/
static CTOS_SEMAPHORE Key_Semaphore, NewKey_Semaphore;
static bool8 _bKeyEnable = TRUE;
static u8 _u8KeybufferIndex_Top=0;
static u8 _u8KeybufferIndex_Bottom =0;
static u32 KeyBuffer[KEY_BUFFER_SIZE];
static u8 _u8KeyInFrontOfQueue = KEY_NO_KEY;
static bool8 _b8CleanKeyInQueue = FALSE;
static u8 _u8FPKeyPrev = 0xFF;
static u32 _u32TimeISRFPKeyPrev = 0;
#ifdef HOLD_POWER_RESET_DEFAULT
static CTOS_TIMER HoldKeyTimer;
#define defaultKey KEY_POWER
static bool8 defaultkeyenble=TRUE;
#define Release_time 150
static bool8 b8Defaultflag=FALSE;
static void HoldKeyTimerCB( u32 argc, void * argv )
{
if(b8Defaultflag==FALSE)
{
DVB_SendKey(KEY_POWER);
FP_MSG(("\n*****DVB_SendKey(KEY_POWER);*******\n"));
}
CT_OS_ControlTimer(& HoldKeyTimer, EN_CTOS_TIMER_DISABLE);
if(b8Defaultflag!=FALSE)
b8Defaultflag=FALSE;
}
//(GFG-002) static void ResetHoldKeyTimer()
static void ResetHoldKeyTimer(void) //(GFG-002)
{
//_u8FPKeyPrev=0;
//(GFG-002) CT_OS_ResetTimer(&HoldKeyTimer,EN_CTOS_TIMER_CONTINUOUS,HoldKeyTimerCB,Release_time);
CT_OS_ResetTimer(&HoldKeyTimer,EN_CTOS_TIMER_CONTINUOUS,(void *)HoldKeyTimerCB,Release_time); //(GFG-002)
//printf("\n*****ResetHoldKeyTimer*******\n");
CT_OS_ControlTimer(& HoldKeyTimer, EN_CTOS_TIMER_ENABLE);
}
#endif
static void IR_Key_Notification( u32 key_code );
static void FP_Key_Notification( u32 key_code );
/*******************************************************************************************/
// Export Function
void DVB_FP_Init(void)
{
/* Set IR customer code to device let device never call DVB directly any more. */
extern void DEV_SetIR_CustomerCode(u8 u8Code, u8 u8Code1);
DEV_SetIR_CustomerCode(IR_CUSTOMER_CODE, IR_CUSTOMER_CODE1);
//Front Panel initial
if ( DRV_OK != DEV_FD_Initial())
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_FD_Initial Error"));
}
DVB_7SegOff();
//IR initial
if ( DRV_OK != DEV_IR_Initial())
{
FP_MSG(("\n\rDVB_FP_WARNING: CT_IR_Initial Error"));
}
if (DRV_OK != DEV_IR_RegisterEventFunc( IR_Key_Notification ))
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_IR_RegisterEventFunc Error"));
}
//KD initial
#ifdef HOLD_POWER_RESET_DEFAULT
defaultkeyenble=TRUE;
//(GFG-002) CT_OS_MS_CreateTimer(& HoldKeyTimer, "holdtime", EN_CTOS_TIMER_CONTINUOUS, HoldKeyTimerCB, 0,Release_time);
CT_OS_MS_CreateTimer(& HoldKeyTimer, "holdtime", EN_CTOS_TIMER_CONTINUOUS, (void*)HoldKeyTimerCB, 0,
Release_time); //(GFG-002)
CT_OS_ControlTimer(& HoldKeyTimer, EN_CTOS_TIMER_DISABLE);
#endif
if ( DRV_OK != DEV_KD_Initial())
{
FP_MSG(("\n\rDVB_FP_WARNING: CT_KD_Initial Error"));
}
if (DRV_OK != DEV_KD_RegisterEventFunc( FP_Key_Notification ))
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_KD_RegisterEventFunc Error"));
}
/* Create a semaphore with an initial count of 1 and priority order task suspend. */
if (EN_CTOS_SUCCESS != CT_OS_CreateSemaphore(&Key_Semaphore, "SemKD", 1, EN_CTOS_SUSPEND_FIFO))
{
FP_MSG(("\n\rDVB_FP_WARNING: CT_OS_CreateSemaphore Error"));
}
if (EN_CTOS_SUCCESS != CT_OS_CreateSemaphore(&NewKey_Semaphore, "SemNKd", 0, EN_CTOS_SUSPEND_FIFO))
{
FP_MSG(("\n\rDVB_FP_WARNING: CT_OS_CreateSemaphore Error"));
}
return;
}
/*******************************************************************************************/
#if defined (CT216X)
void DVB_7Seg_Strengthen(bool8 b8Enable)
{
DEV_LEDDisplay_Strengthen(b8Enable);
}
#endif
/*******************************************************************************************/
void DVB_7SegOff(void)
{
if (DRV_OK != DEV_FD_DisplayText("00000"))
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_FD_DisplayText Error"));
}
return;
}
/*******************************************************************************************/
void DVB_7SegShow (u16 u16Number)
{
if ((u16Number <=9999 && NUM_OF_7SEG == 4) ||(u16Number <=99999 && NUM_OF_7SEG == 5))
{
DEV_FD_DisplayDecimal(u16Number);
}
else
{
FP_MSG(("\n\rDVB_FP_WARNING: Out of Range"));
}
return;
}
/*******************************************************************************************/
void DVB_7SegShowNumByIdx(u8 u8Idx, u8 u8Number)
{
if (u8Number <=9)
{
u8Number += 48;//exchange to ASCII 48 - 57(number 0-9)
if (DRV_OK != DEV_FD_DisplayASCII(u8Idx , u8Number))
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_FD_DisplayASCII Error"));
}
}
else
{
FP_MSG(("\n\rDVB_FP_WARNING: Out of Range"));
}
return;
}
/*******************************************************************************************/
void DVB_7SegShowDetial(u8 u8Idx, u8 u8Data)
{
if (u8Idx <= NUM_OF_7SEG)
{
if (DRV_OK != DEV_FD_DisplayData(u8Idx , u8Data))
{
FP_MSG(("\n\rDVB_FP_WARNING: DEV_FD_DisplayData Error"));
}
}
else
{
FP_MSG(("\n\rDVB_FP_WARNING: Out of Range"));
}
return;
}
/*******************************************************************************************/
void DVB_7SegShowText(u8 *pu8Text)
{
DEV_FD_DisplayText(pu8Text);
return;
}
/*******************************************************************************************/
//**************************************
// KEYPAD and IR Function
//**************************************
u16 DVB_GetIR_CustomerCode(void)
{
u16 u16CustomerCode;
u8 u8Code;
u8Code = IR_CUSTOMER_CODE1;
u16CustomerCode = u8Code;
u16CustomerCode <<=8;
u8Code = IR_CUSTOMER_CODE;
u16CustomerCode |= u8Code;
return u16CustomerCode;
}
/*******************************************************************************************/
void DVB_EnableKey(bool8 b8Enable)
{
if (TRUE == b8Enable)
{
_bKeyEnable = TRUE;
}
else
{
_bKeyEnable = FALSE;
}
return;
}
/*******************************************************************************************/
void DVB_EnableIRKey(bool8 b8Enable)
{
if (TRUE == b8Enable)
{
extern u16 DEV_GetIR_CustomerCode(void);
CT_IR_SetCustomCode(DEV_GetIR_CustomerCode());
}
else
{
CT_IR_SetCustomCode(0);
}
return;
}
/*******************************************************************************************/
bool8 _is_dvbmain_task(void)
{
char strTaskName[9];
CT_OS_GetRunningTaskName( strTaskName, 8);
strTaskName[7]=0;
if( strcmp(strTaskName, "DVBMAIN")==0 )
{
return TRUE;
}
else
{
// FP_DBG(("_is_dvbmain_task %s\n", strTaskName));
return FALSE;
}
}
/*******************************************************************************************/
bool8 DVB_DetectKey (void)
{
bool8 b8Ret;
if(_is_dvbmain_task()==TRUE)
{
DVB_TimerRunEvent(0);
}
if (FALSE ==_bKeyEnable)
{
return FALSE;
}
if (EN_CTOS_SUCCESS != CT_OS_WaitOnSemaphore(&Key_Semaphore,CTOS_WAIT))
{
FP_DBG(("DVB_FP_WARNING: CT_OS_WaitOnSemaphore Error\n"));
}
if(_u8KeyInFrontOfQueue != KEY_NO_KEY)
{
b8Ret = TRUE;
}
else
{
if (_u8KeybufferIndex_Top != _u8KeybufferIndex_Bottom)
{
b8Ret=TRUE;
}
else
{
b8Ret=FALSE;
}
}
if (EN_CTOS_SUCCESS != CT_OS_FreeSemaphore(&Key_Semaphore))
{
FP_DBG(("DVB_FP_WARNING: CT_OS_FreeSemaphore Error\n"));
}
return b8Ret;
}
/*******************************************************************************************/
u8 DVB_CheckKey (void)// get key, but it doesn't remove the key form key buffer
{
#if 1
u8 u8KeyCode;
if (FALSE ==_bKeyEnable)
{
if(_is_dvbmain_task()==TRUE)
{
DVB_TimerRunEvent(0);
}
return KEY_NO_KEY;
}
else
{
while(DVB_DetectKey() == FALSE) // run timer in detect key.
{
CT_OS_MS_Delay(5);
}
}
if (EN_CTOS_SUCCESS != CT_OS_WaitOnSemaphore(&Key_Semaphore,CTOS_WAIT))
{
FP_MSG(("DVB_FP_WARNING: CT_OS_WaitOnSemaphore Error\n"));
}
if(_u8KeyInFrontOfQueue != KEY_NO_KEY)
{
u8KeyCode = _u8KeyInFrontOfQueue;
}
else
{
u8KeyCode = (u8)KeyBuffer[_u8KeybufferIndex_Top];
}
if (EN_CTOS_SUCCESS != CT_OS_FreeSemaphore(&Key_Semaphore))
{
FP_MSG(("DVB_FP_WARNING: CT_OS_FreeSemaphore Error\n"));
}
return u8KeyCode;
#else
u8 u8KeyCode;
if (FALSE ==_bKeyEnable)
{
return KEY_NO_KEY;
}
if (EN_CTOS_SUCCESS != CT_OS_WaitOnSemaphore(&Key_Semaphore,CTOS_WAIT))
{
FP_MSG(("DVB_FP_WARNING: CT_OS_WaitOnSemaphore Error\n"));
}
if(_u8KeyInFrontOfQueue != KEY_NO_KEY)
{
u8KeyCode = _u8KeyInFrontOfQueue;
}
else
{
u8KeyCode = (u8)KeyBuffer[_u8KeybufferIndex_Top];
}
if (EN_CTOS_SUCCESS != CT_OS_FreeSemaphore(&Key_Semaphore))
{
FP_MSG(("DVB_FP_WARNING: CT_OS_FreeSemaphore Error\n"));
}
return u8KeyCode;
#endif
}
/*******************************************************************************************/
bool8 DVB_DetectKeyTimeout (u16 u16Timeout)
{
/*
bool8 b8Status;
if ( DVB_DetectKey()==FALSE )
{
CT_OS_WaitOnSemaphore(&NewKey_Semaphore,u16Timeout/CTOS_MS_PER_TICKS);
}
return DVB_DetectKey();
*/
u32 u32CurrentTick, u32TimeoutTick;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -