- #include "Config.h" // Global Configuration - do not remove!
- #include "Kernelker_api.h"
- #include "Kerneleventdef.h"
- #include "CPUcpu_api.h"
- #include "CPUTimefunc.h"
- #include "PlaycoreCoremaincoremain.h"
- #include "PlaycoreCoremaincoredefs.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "Remoteir_api.h"
- #include "Remoteir_ll.h"
- #include "Remoterc6_irrc6_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 RC6_GROUPSIZE 8 // bits
- #define RC6_CODESIZE 8 // bits
- #define RC6_SHORTPULSE 444UL
- #define RC6_JITTER 200UL
- #define RC6_LONGPULSE 888UL
- #define RC6_HEADPULSE (6*RC6_SHORTPULSE)
- // State of the remote key decoder
- #define ERROR 0
- #define IDLE 1
- #define HEADER1 2
- #define HEADER2 3
- #define HEADER3 4
- #define MODE 5
- #define REVERSE 6
- #define DECODE 7
- #define RESYNC 8
- #define REPEAT_DELAY 5 // pre-delay before repeating.
- #define REPEAT_STEP 2 // delay between repeated events.
- #define STOPKEY_DELAY 0x10 //for the Philips project
- #define IRKC_NULL 0xFF //for the philips project
- #define Philips_DVD 0x04
- #define PHILIPS 1
- void ir_init(void)
- {
- ir_interrupt_and_timer_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 oldcode;
- static BYTE bit = 0;
- static BYTE check = 0;
- static BYTE repeating = 0;
- static BYTE repeatDelay = REPEAT_DELAY; // Repeat code counter
- static BYTE repeatStep=0;
- static DWORD timeCountOld;
- /* henry start */
- static BYTE model; /* mode value */
- static BYTE border; /*indicator of a border of long cycle*/
- static BYTE start; /* indicator of starting next segment */
- /* henry end */
- DWORD timeCount;
- DWORD deltaTime;
- BYTE validRepeat = 0;
- BYTE key = 0; // Hold the key code
- /* for the Philips project */
- static BYTE lastkey;
- static BYTE stopkey_repeatDelay;
- timeCount =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:
- bitCount = 0;
- model = 0;
- group = 0;
- code = 0;
- border = 0;
- start = 0;
- bit = 1;
- if(interruptTypeFlag == 1)
- state = HEADER1;
- else
- state = ERROR;
- break;
- case HEADER1:
- if(deltaTime - RC6_JITTER < RC6_HEADPULSE && RC6_HEADPULSE < deltaTime + RC6_JITTER)
- state = HEADER2;
- else
- state = ERROR;
- break;
- case HEADER2:
- if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
- state = HEADER3;
- else
- state = ERROR;
- break;
- case HEADER3:
- if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
- state = MODE;
- else
- state = ERROR;
- break;
- case MODE:
- if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
- {
- if(border)
- {
- state = ERROR;
- border = 0;
- break;
- }
- bit = !bit;
- bitCount++;
- model <<= 1;
- model |= bit & 1;
- }
- else if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
- {
- if(border)
- {
- border = 0;
- bitCount++;
- model <<= 1;
- model |= bit & 1;
- }
- else
- border = 1;
- }
- else
- {
- state = ERROR;
- break;
- }
- if(bitCount == 3)
- {
- state = REVERSE;
- start = 1;
- bitCount = 0;
- }
- break;
- case REVERSE:
- if(deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
- {
- if(border)
- state = ERROR;
- else
- {
- border = 1;
- start = 0;
- }
- }
- else if(deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
- {
- if(!border)
- state = ERROR;
- else
- state = DECODE;
- }
- else if(deltaTime - RC6_JITTER < (RC6_LONGPULSE + RC6_SHORTPULSE)
- && (RC6_LONGPULSE + RC6_SHORTPULSE) < deltaTime + RC6_JITTER)
- {
- if(start)
- {
- start = 0;
- bit = !bit;
- state = DECODE;
- }
- else
- state = ERROR;
- }
- else
- state = ERROR;
- if(state == DECODE)
- {
- if((bit & 1) ^ check)
- repeating = 0;
- else
- repeating = 1;
- check = bit & 1;
- start = 1;
- border = 0;
- }
- break;
- case DECODE:
- if (deltaTime - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
- {
- if(start)
- state = ERROR;
- else if(border)
- {
- border = 0;
- bitCount++;
- }
- else
- border = 1;
- }
- else if (deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
- {
- if(start)
- {
- start = 0;
- border = 1;
- }
- else if(border)
- state = ERROR;
- else
- {
- bit = !bit;
- bitCount++;
- }
- }
- else if (deltaTime - RC6_JITTER < (RC6_LONGPULSE + RC6_SHORTPULSE)
- && (RC6_LONGPULSE + RC6_SHORTPULSE) < deltaTime + RC6_JITTER)
- {
- if(start)
- {
- start = 0;
- border = 0;
- bit = !bit;
- bitCount++;
- }
- else
- state = ERROR;
- }
- else
- state = ERROR;
- if(state == DECODE)
- {
- if(bitCount <= RC6_GROUPSIZE)
- {
- group |= (bit & 1)<<(RC6_GROUPSIZE - bitCount);
- }
- else
- {
- code |= (bit & 1)<<(RC6_CODESIZE + RC6_GROUPSIZE - bitCount);
- }
- if(bitCount == RC6_GROUPSIZE + RC6_CODESIZE)
- {
- if (group == g_ir_system_code)
- {
- /* add code for judging if the key is pressed repeatly more truly */
- if((oldcode != code) && (repeating == 1))
- repeating = 0;
- oldcode = code;
- /* add code end */
- key = (BYTE)(0x00FF&code);
- 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)
- {
- /* design for philips project:repeating to push stop key instead of pushing open key */
- #ifdef PHILIPS
- if(key == IRKC_STOP)
- {
- if(stopkey_repeatDelay)
- stopkey_repeatDelay--;
- else
- {
- key = IRKC_EJECT;
- if(lastkey != key)
- {
- lastkey = key;
- send_remote_event((WORD)key&0x00FF);
- }
- }
- }
- else
- #endif //End ifdef PHILIPS
- if(repeatDelay)
- {
- repeatDelay--;
- }
- else if (validRepeat)
- {
- if (!(repeatStep++ % REPEAT_STEP))
- send_remote_event(((WORD)key)&0x00FF );
- }
- }
- else
- {
- #ifdef PHILIPS
- if(key == IRKC_STOP)
- {
- stopkey_repeatDelay = STOPKEY_DELAY;
- lastkey = IRKC_NULL;
- }
- #endif //End ifdef PHILIPS
- repeatDelay = REPEAT_DELAY;
- send_remote_event(((WORD)key)&0x00FF);
- }
- if (bit & 1)
- { // 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( RISING_EDGE );
- interruptTypeFlag = 1;
- }
- 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 - RC6_JITTER < RC6_SHORTPULSE && RC6_SHORTPULSE < deltaTime + RC6_JITTER)
- {
- state = IDLE;
- ir_interrupt_set_edge( RISING_EDGE );
- interruptTypeFlag = 1;
- }
- else if (deltaTime - RC6_JITTER < RC6_LONGPULSE && RC6_LONGPULSE < deltaTime + RC6_JITTER)
- {
- state = IDLE;
- ir_interrupt_set_edge( RISING_EDGE );
- interruptTypeFlag = 1;
- }
- else
- {
- state = ERROR;
- }
- break;
- default:
- state = ERROR;
- break;
- }
- }