📄 rc5_ir.c
字号:
// VESTEL RC5 PROTOCOL
// AUTHOR : SEDEF KARA
// DATE : 14.01.2003
// Data size = 14 bits
// 1 startup bit
// 1 check bit that toggles to indicate a new button
// Group size = 5 bits
// Code size = 6 bits
//
// Example codes:
// _ _ _ _ _ __ _ __ _ __ _
// ... |_| |_| |_| |_| |__| |__| |_| |_| |__| |_| ... = 0xb2
// S 0 0 0 0 1 0 1 1 0 0 1 0
//
// _ _ _ _ _ __ _ __ _ _ _
// ... |_| |_| |_| |_| |__| |__| |_| |_| |__| |_| ... = 0xb3
// S 0 0 0 0 1 0 1 1 0 0 1 1
//
// | 1778礢 | 1778礢 | 1778礢 | 1778礢 | 1778礢 |
// +-----+ +-----+
// 0 = ... | ... 1 = ... | ...
// +-----+ +-----+
// 894礢 894礢 894礢 894礢
//
#include "Config.h" // Global Configuration - do not remove!
#include "Kernel\ker_api.h"
#include "Kernel\eventdef.h"
#include "CPU\cpu_api.h"
#include "CPU\Timefunc.h"
#include "Playcore\Coremain\coremain.h"
#include "Playcore\Coremain\coredefs.h"
#include "Playcore\Coremain\coregdef.h"
#include "Remote\ir_api.h"
#include "Remote\ir_ll.h"
#include "Remote\rc5_ir\rc5_ir.h"
#include "UI_Manager\UI_Input\ui_input_ir.h"
extern CONST WORD g_ir_system_code;
extern CONST WORD g_ir_power_key_code;
extern CONST WORD g_ir_eject_key_code;
#define RC5_CHECK 1 // bit
#define RC5_GROUPSIZE 5 // bits
#define RC5_CODESIZE 6 // bits
#define RC5_SHORTPULSE 894UL // 礢
#define RC5_LONGPULSE 1778UL // 礢
#define RC5_SPACE 88900UL // 礢
#define RC5_JITTER 200UL // 礢
#define RC5_COMMANDGAP 30000UL // 礢
#define Vestel_DVD 0x02
// State of the remote key decoder
#define ERROR 0
#define IDLE 1
#define HIGH_HEADER 2
#define LOW_HEADER 3
#define STARTUP 4
#define DECODE 5
#define RESYNC 6
#define REPEAT_DELAY 5 // pre-delay before repeating.
#define REPEAT_STEP 2 // delay between repeated events.
void ir_init(void)
{
ir_interrupt_init( FALLING_EDGE );
}
void ir_isr( void )
{
static BYTE interruptTypeFlag = 0;
static BYTE state = IDLE;
static BYTE bitCount;
static BYTE decode;
static BYTE group;
static BYTE code;
static BYTE bit = 0;
static BYTE check = 1;
static BYTE repeating = 0;
static BYTE repeatDelay = REPEAT_DELAY; // Repeat code counter
static BYTE repeatStep=0;
static DWORD timeCountOld;
DWORD timeCount;
DWORD deltaTime;
BYTE validRepeat = 0;
BYTE key = 0; // Hold the key code
timeCount =cpu_gen_timer();
deltaTime = timeCount - timeCountOld;
timeCountOld = timeCount;
if (!interruptTypeFlag)
{
ir_interrupt_set_edge( RISING_EDGE );
interruptTypeFlag = 1;
}
else
{
ir_interrupt_set_edge( FALLING_EDGE );
interruptTypeFlag = 0;
}
switch (state) {
case ERROR:
// to be filled later when it is needed.
state = IDLE;
case IDLE:
decode = TRUE;
bitCount = 0;
group = 0;
code = 0;
bit = FALSE;
if (deltaTime > RC5_SPACE)
state = LOW_HEADER;
else
{
state = ERROR;
}
break;
case LOW_HEADER:
if (deltaTime - RC5_JITTER < RC5_SHORTPULSE && RC5_SHORTPULSE < deltaTime + RC5_JITTER)
state = HIGH_HEADER;
else
{
state = ERROR;
}
break;
case HIGH_HEADER:
if (deltaTime - RC5_JITTER < RC5_SHORTPULSE && RC5_SHORTPULSE < deltaTime + RC5_JITTER)
state = DECODE;
else
{
state = ERROR;
}
break;
case DECODE:
if (deltaTime - RC5_JITTER < RC5_SHORTPULSE && RC5_SHORTPULSE < deltaTime + RC5_JITTER)
{
decode = !decode;
}
else if (deltaTime - RC5_JITTER < RC5_LONGPULSE && RC5_LONGPULSE < deltaTime + RC5_JITTER)
{
bit = !bit;
decode = TRUE;
}
else
{
state = ERROR;
}
if (decode)
{
bitCount++;
if (bitCount == 1)
{
if(bit == check)
{
repeating = 1;
}
else
{
repeating = 0;
}
check = bit;
}
else if (bitCount > RC5_CHECK && bitCount <= RC5_CHECK + RC5_GROUPSIZE)
{
group += bit << (RC5_CHECK + RC5_GROUPSIZE - bitCount);
}
else
{
code += bit << (RC5_CHECK + RC5_GROUPSIZE + RC5_CODESIZE - bitCount);
}
if (bitCount == RC5_CHECK + RC5_GROUPSIZE + RC5_CODESIZE)
{
if (group == Vestel_DVD)
{
key = (BYTE)(0x00FF&code);
// tr_printf(("Key is %02x\n"));
#if 0
if (key == (BYTE)(0x00FF&g_ir_power_key_code))
{
switch(g_power_state)
{
case POWER_SEQUENCE_IN_ON_STATE:
g_power_state = POWER_SEQUENCE_OFF_REQUESTED;
break;
case POWER_SEQUENCE_IN_OFF_STATE:
g_power_state = POWER_SEQUENCE_ON_REQUESTED;
break;
case POWER_SEQUENCE_OFF_REQUESTED:
g_power_state = POWER_SEQUENCE_ON_REQUESTED;
cpu_soft_reset();
}
}
#endif
switch(key)
{
case IRKC_DOWN:
case IRKC_UP:
case IRKC_RIGHT:
case IRKC_LEFT:
validRepeat=1;
break;
#ifdef USE_SKIPF_KEY_FOR_STEPF_KEY_IN_PAUSE_MODE
#ifdef D_VESTEL_REMOTE
case IRKC_SKIPF: //BT021003: Add STEPF key repeating
if ( (gcs.pstate == PST_PAUSE) && (IS_COP_ENABLE(COP_STEP)) )
{
validRepeat=1;
break;
}
#endif //D_VESTEL_REMOTE
#endif //USE_SKIPF_KEY_FOR_STEPF_KEY_IN_PAUSE_MODE
default:
validRepeat=0;
}
if (repeating)
{
if(repeatDelay)
{
repeatDelay--;
}
else if (validRepeat)
{
if (!(repeatStep++ % REPEAT_STEP))
send_remote_event(((WORD)key)&0x00FF );
}
}
else
{
repeatDelay = REPEAT_DELAY;
send_remote_event(((WORD)key)&0x00FF);
}
if (bit)
{ // LOW to HIGH transition of clock
state = IDLE; // If_last bit is 1 then this is the last clock edge of stream
ir_interrupt_set_edge( FALLING_EDGE );
interruptTypeFlag = 0;
}
else // HIGH to LOW transition of clock
state = RESYNC; // If_last bit is 0 then we need to wait for one more clock edge
}
}
}
break;
case RESYNC:
if (deltaTime - RC5_JITTER < RC5_SHORTPULSE && RC5_SHORTPULSE < deltaTime + RC5_JITTER){
state = IDLE;
ir_interrupt_set_edge( FALLING_EDGE );
interruptTypeFlag = 0;
}
else if (deltaTime - RC5_JITTER < RC5_LONGPULSE && RC5_LONGPULSE < deltaTime + RC5_JITTER)
{
state = IDLE;
ir_interrupt_set_edge( FALLING_EDGE );
interruptTypeFlag = 0;
}
else
{
state = ERROR;
}
break;
default:
state = ERROR;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -