📄 remocon.c
字号:
/******************************************************************************
* Filename: Remocon.c
* Start:
* By:
* Contact:
* Description: Remocon low level code
******************************************************************************
*/
#include "Basic_typedefs.h"
#include "S5h_common_reg.h"
#include "sys_call_abstract.h"
#include "remocon.h"
#include "vcd_def.h"
extern void KeyMsgSender( UINT data, void *param );
#if _KEY_CALLBACK
extern S5H_FPCALLBACK AttachedKeySendCallback;
SysHisr_t gIrKeyHisr;
static USHORT gIR_HISR_Msg; /* Copy of gIR_Data_Buffer */
#endif
//maymeng 050822:start
#define IR_REPEAT_COUNT 3
static unsigned int ir_repeat_count;
static unsigned int ir_State;
enum {
IR_IDLE,
//IR_LEADER,
IR_BITS,
IR_REPEAT1,
IR_REPEAT2,
//IR_DOUBLE1,
//IR_DOUBLE2
};
//maymeng 050822:end
#ifdef REMOCON_DEBUG
unsigned int ir_userdata1=0;
unsigned int ir_userdata2=0;
unsigned int ir_userdata3=0;
unsigned int ir_userdata4=0;
unsigned int ir_userdata5=0;
unsigned int ir_userdata6=0;
unsigned int ir_userdata7=0;
unsigned int ir_userdata8=0;
#endif
volatile unsigned long ir_custom=0;
volatile unsigned short ir_userdata=0;
volatile unsigned char ir_keybuffer=0xff;
volatile unsigned char ir_cnt=0;
BOOL ir_pulsechk_flag = FALSE;
void ISR_Interrupt_IR_INT(void);
void Remocon_Set(void)
{
//Full interrupt + PCLK/8192 + Falling edge mode
IO_WData32_EX((unsigned char *)&rIRCON_H, 0, 0x43B/*0x43B*/);
SysRegisterLisr(IR_INT, (SysLisrEntryPtr_t)ISR_Interrupt_IR_INT );
Enable_Int(IR_INT);
#if 0//_KEY_CALLBACK
if ( SysCreateHisr( &gIrKeyHisr, "IR_HISR",(SysHisrEntryPtr_t)IR_Hisr, 1, 800/*IR_HISR_SIZE*/ ) )
{
SysPrintf ( "Faile to carete IR Key HISR\n" );
return;
}
#endif
#ifdef REMOCON_DEBUG
ir_userdata1 = (unsigned int)DataZero;
ir_userdata2 = (unsigned int)DataOne;
ir_userdata3 = (unsigned int)LeadPulse;
ir_userdata4 = (unsigned int)DataRepeat;
ir_userdata5 = (unsigned int)DataOne_max;
ir_userdata6 = (unsigned int)DataOne_min;
ir_userdata7 = (unsigned int)DataRepeat_max;
//ir_userdata7 = (unsigned int)DataRepeat_max;
#endif
}
void IR_Variable_Init(void)
{
ir_pulsechk_flag = FALSE;
ir_cnt = 0;
ir_custom =0;
ir_userdata=0;
//#if VOL_REPEAT_KEY_CTL //maymeng 050822
ir_repeat_count = 0;
//#endif
}
void ISR_Interrupt_IR_INT(void)
{
static unsigned int ir_status;
static unsigned short ir_data;
unsigned long ctrl_reg,data_reg;
UCHAR i;
unsigned short con_L, con_H;
ctrl_reg = IO_RData32((unsigned char *)&rIRCON_H);
ir_status = (unsigned int)ctrl_reg;
if(ir_status & (01<<Ir_ovf_int))
{
IrInt_Clr(Ir_ovf_int); // Interrupt pending bit clear
data_reg = IO_RData32((unsigned char *)&rIRDAT_H);//Lumin20050927
ir_data = (unsigned short)data_reg; // dummy data read
IR_Variable_Init();
}
if(ir_status & (01<<Ir_full_int)){
while(!(((UINT)IO_RData32((unsigned char *)&rIRCON_H)) & Empty_stat)) //Lumin20050927
{
data_reg = IO_RData32((unsigned char *)&rIRDAT_H);//Lumin20050927
ir_data = data_reg;
if((ir_data >= LeadPulse_min) && (ir_data <= LeadPulse_max)){
ir_State=IR_BITS;
ir_cnt = 0;
}
else if((ir_State== IR_BITS)&&
(((ir_data >= DataZero_min) && (ir_data <= DataZero_max))||
((ir_data >= DataOne_min) && (ir_data <= DataOne_max)))
){
if ((ir_data >= DataZero_min) && (ir_data <= DataZero_max)){
if(ir_cnt < IR_CUSTOM_NUM)
ir_custom = (ir_custom << 1) + 0;
else
ir_userdata = ir_userdata & ~(1<<(ir_cnt -IR_CUSTOM_NUM)); // LSB first
}
else if ((ir_data >= DataOne_min) && (ir_data <= DataOne_max)){
if(ir_cnt < IR_CUSTOM_NUM)
ir_custom = (ir_custom << 1) + 1;
else
ir_userdata = ir_userdata | (1<<(ir_cnt -IR_CUSTOM_NUM));
}
ir_cnt++;
if(ir_cnt >= IR_RECEIVE_OK){
ir_cnt =0;
if(ir_custom == CustomCode){
ir_keybuffer = (unsigned char)ir_userdata;
#if _KEY_CALLBACK
(*AttachedKeySendCallback)( ir_keybuffer, 0 );
#else
KeyMsgSender(ir_keybuffer, 0 );
#endif
if( (ir_keybuffer== /*0x02*/KEY_VOL_REDUCE) ||( ir_keybuffer== /*0x03*/KEY_VOL_ADD)){
ir_State= IR_REPEAT1;
ir_repeat_count= 0;
}
}
}
}
else if((ir_State== IR_REPEAT1))
{
if((ir_data > DataRepeat_min)&&(ir_data <DataRepeat_max) )
{
if(ir_repeat_count<IR_REPEAT_COUNT)
ir_repeat_count++;
else{
#if _KEY_CALLBACK
(*AttachedKeySendCallback)( ir_keybuffer, 0 );
#else
KeyMsgSender(ir_keybuffer, 0 );
#endif
ir_repeat_count =0;
}
ir_State= IR_REPEAT1;
}
}
else{
IR_Variable_Init();
}
}
IrInt_Clr(Ir_full_int); // Interrupt pending bit clear
}
/*---------------------------------------------------------------------*/
if(ir_status & 01<<Ir_cap_int)
{
IrInt_Clr(Ir_cap_int); // Interrupt pending bit clear
}
/*---------------------------------------------------------------------*/
Intclr_Scr(IR_INT); // Source pending bit clear
Intclr_Pnd(IR_INT); // Interrupt pending bit clear
}
/*---------------------------------------------------------------------*/
#if 0
void LeadPulse_chk(unsigned short ir_data)
{
if((ir_data >= LeadPulse_min) && (ir_data <= LeadPulse_max))
{
ir_pulsechk_flag = TRUE;
ir_cnt = 0;
}
else // IR_Error
{
IR_Variable_Init();
}
}
#if VOL_REPEAT_KEY_CTL //added by maymeng 050822: start
void IrRepeatData_chk(unsigned short ir_data)
{
if ((ir_data >= DataRepeat_min) && (ir_data <= DataRepeat_max))
{
if(ir_repeat_count < IR_REPEAT_COUNT)
{
ir_repeat_count++;
}
}
else // IR_Error
{
IR_Variable_Init();
}
}
#endif //added by maymeng 050822: end
/*---------------------------------------------------------------------*/
void IrData_chk(unsigned short ir_data)
{
if ((ir_data >= DataZero_min) && (ir_data <= DataZero_max))
{
if(ir_cnt < IR_CUSTOM_NUM)
ir_custom = (ir_custom << 1) + 0;
// else ir_userdata = (ir_userdata << 1) + 0; // MSB first
else
ir_userdata = ir_userdata & ~(1<<(ir_cnt -IR_CUSTOM_NUM)); // LSB first
ir_cnt++;
}
else if ((ir_data >= DataOne_min) && (ir_data <= DataOne_max))
{
if(ir_cnt < IR_CUSTOM_NUM)
ir_custom = (ir_custom << 1) + 1;
// else ir_userdata = (ir_userdata << 1) + 1;
else
ir_userdata = ir_userdata | (1<<(ir_cnt -IR_CUSTOM_NUM));
ir_cnt++;
}
else // IR_Error (Data 0 or 1 捞 酒囱版快 )
{
IR_Variable_Init();
}
}
#endif
//#define IrInt_Clr(n) rIRCON = ((rIRCON & 0x3ff) | 01<<(n)) /* IR Pending bit clear */
void IrInt_Clr(unsigned long x)
{
unsigned long TempLong1,TempLong2;
TempLong1 = IO_RData32_EX((unsigned char *)&rIRCON_H);
TempLong2 = (TempLong1 & 0x07ff) | (1 <<x);
WRITE32((unsigned char *)&rIRCON_H, TempLong2 );
}
#if 0//_KEY_CALLBACK
void IR_Send_Msg(USHORT IR_Key, SINT Para)
{
Para = 0; /* for no warning */
gIR_HISR_Msg = IR_Key;
#if IR_DEBUG
SysPrintf("IR_Send_Msg [%x] / %x ", IR_Key, gIR_State);
#endif /* IR_DEBUG */
SysActivateHisr(&gIrKeyHisr ); /* Acrivate Hisr */
}
void IR_Hisr(void)
{
(*AttachedKeySendCallback)( gIR_HISR_Msg, 0 );
}
#endif
#if 0
/*---------------------------------------------------------------------*/
void Remocon_test(void)
{
char ch;
unsigned long temp;
Remocon_Set();
SysPrintf("\nRemocon Receive Test.... \n");
SysPrintf("\n Q:Remocon test quit(IR function enable) \n");
SysPrintf("\n X:Remocon test quit(IR function disable) \n");
ch = UART_GetByte();
while((ch != 'Q') && (ch != 'q'))
{
if((ch == 'x') || (ch =='X'))
{
Disable_Int(IR_INT); // INT disable (秦寸 MASK bit阑 clear)
//rIRCON = 0x01; // IR disable & clear
temp = IO_RData32_EX((unsigned char *)&rIRCON_H);
temp &= 0xfffffffd;
temp |= 0x01;
WRITE32((unsigned char *)&rIRCON_H, temp);
break;
}
if(ir_flag_t)
{
//rPDAT7 = 0x300 | ir_display;
SysPrintf("Remocon Input Key numer : %x \n", ir_keybuffer);
ir_flag_t =0;
if(ir_keybuffer==0x91)
{
SysPrintf("\n Remocon test quit(IR function enable) \n");
break;
}
}
}
// Remocon Interrupt Disable ?
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -