📄 ir.c
字号:
#include "common.h"
#include "const.h"
#include "constvar.h"
#include "dsc.h"
#include "ioport.h"
#include "ir.h"
#include "mvd.h"
#include "timedef.h"
#include "util.h"
#include "Hm612ndi.h"
PRIVATE unsigned int prevIRtime = 0; /* Last time IR intr. happens */
PRIVATE unsigned short dataIR; /* System/customer IR code */
PRIVATE unsigned int diffIR[2]; /* Array to store time gap */
PRIVATE char cntIRchg = 0; /* Number of unprocessed IR intr*/
PRIVATE char cntIRbits = 0; /* Number of IR sys/cust. bits */
PRIVATE char killIR = 0; /* Whether to "kill" next IR bit*/
PRIVATE volatile char stateIR = IR_IDLE; /* IR state machine state */
void IR_init(){
mvd[riface_clear_dbgirq] = 0; /* Clear debug_irq */
enable_int(debug);
return;
}
void IR_recv_interrupt_service(){
int falling_edge = 0, tmp;
unsigned int currIRtime, tmp1;
currIRtime = ((unsigned int) mvd[riface_timer2]);
tmp1 = currIRtime - prevIRtime;
if (currIRtime < prevIRtime) {/* Wrap around case */
tmp1 += -timer2_period;
}
diffIR[cntIRchg++] = tmp1;
prevIRtime = currIRtime;
if (IS_IRXOR_HIGH) {
CLEAR_IRXOR; /* set to low */
falling_edge = 1; /* Interupt caused by IR falling edge */
/* If we want to kill IR, then send 1; else send 0 */
tmp = killIR ? 1 : 0;
} else {
SET_IRXOR;
tmp = killIR ? 0 : 1;
}
mvd[riface_clear_dbgirq] = 0; /* Clear debug_irq */
if (stateIR == IR_IDLE) {
if (falling_edge) stateIR = IR_LEADER_LOW;
else cntIRchg = prevIRtime = 0;
}
if (cntIRchg == 2) {
unsigned char data;
char reset = 0;
unsigned int width;
cntIRchg = 0;
width = diffIR[1];
if (stateIR == IR_CUSTOM) {/* Put most common case first */
width += diffIR[0]; /* Get data + gap */
dataIR <<= 1;
if (width > cRmDATA_1_MIN){
dataIR |= 0x1;
}
cntIRbits++;
if ((cntIRbits == 16) && (dataIR != cRmCustom)) reset = 1;
if (cntIRbits == 24) {
GRmCodeData = dataIR & 0xff;
}
else if (cntIRbits == 32){
reset = 1;
if (GRmCodeData == ((dataIR & 0xff) ^ 0xff)){
FRmDecodOK = 1;
/*
debug_osd("IR:",GRmCodeData,5); */
}
}
}
else if (stateIR == IR_LEADER_LOW) {
if ((width >= cRmLEADER_LOW_MIN) && (width <= cRmLEADER_LOW_MAX)) {
stateIR = IR_LEADER_HIGH;
cntIRchg = 1; /* We'll only collect 1 change next time */
}
else reset = 1;
}
else {
/* stateIR has to be equal to IR_LEADER_HIGH */
if ((width >= cRmLEADER_HIGH_MIN) && (width <= cRmLEADER_HIGH_MAX)) {
dataIR = cntIRbits = 0;
stateIR = IR_CUSTOM;
}
else reset = 1;
}
if (reset) {
/* Reset all, start from the very beginning */
stateIR = IR_IDLE;
cntIRchg = prevIRtime = 0;
}
}
return;
}
void IR_send_data(unsigned char code, int repeat){
++code;
++repeat;
return;
}
void IR_xmit_interrupt_service(void){
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -