static void cx23885_input_process_raw_rc5(struct cx23885_dev *dev) { struct card_ir *ir_input = dev->ir_input; unsigned int code, command; u32 rc5; /* Ignore codes that are too short to be valid RC-5 */ if (ir_input->last_bit < (RC5_HALF_BITS - 1)) return; /* The library has the manchester coding backwards; XOR to adapt. */ code = (ir_input->code & RC5_HALF_BITS_MASK) ^ RC5_HALF_BITS_MASK; rc5 = ir_rc5_decode(code); switch (RC5_START(rc5)) { case RC5_START_BITS_NORMAL: break; case RC5_START_BITS_EXTENDED: /* Don't allow if the remote only emits standard commands */ if (ir_input->start == RC5_START_BITS_NORMAL) return; break; default: return; } if (ir_input->addr != RC5_ADDR(rc5)) return; /* Don't generate a keypress for RC-5 auto-repeated keypresses */ command = rc5_command(rc5); if (RC5_TOGGLE(rc5) != RC5_TOGGLE(ir_input->last_rc5) || command != rc5_command(ir_input->last_rc5) || /* Catch T == 0, CMD == 0 (e.g. '0') as first keypress after init */ RC5_START(ir_input->last_rc5) == 0) { /* This keypress is differnet: not an auto repeat */ ir_input_nokey(ir_input->dev, &ir_input->ir); ir_input_keydown(ir_input->dev, &ir_input->ir, command); } ir_input->last_rc5 = rc5; /* Schedule when we should do the key up event: ir_input_nokey() */ mod_timer(&ir_input->timer_keyup, jiffies + msecs_to_jiffies(ir_input->rc5_key_timeout)); }
static void sms_rc5_parse_word(struct smscore_device_t *coredev) { #define RC5_START(x) (((x)>>12)&3) #define RC5_TOGGLE(x) (((x)>>11)&1) #define RC5_ADDR(x) (((x)>>6)&0x1F) #define RC5_INSTR(x) ((x)&0x3F) int i, j; u32 rc5_word = 0; /* Reverse the IR word direction */ for (i = 0 ; i < 28 ; i++) RC5_PUSH_BIT(rc5_word, (ir_word>>i)&1, j) rc5_word = ir_rc5_decode(rc5_word); /* sms_log("temp = 0x%x, rc5_code = 0x%x", ir_word, rc5_word); */ sms_ir_rc5_event(coredev, RC5_TOGGLE(rc5_word), RC5_ADDR(rc5_word), RC5_INSTR(rc5_word)); }
void ir_rc5_timer_end(unsigned long data) { struct card_ir *ir = (struct card_ir *)data; struct timeval tv; unsigned long current_jiffies, timeout; u32 gap; u32 rc5 = 0; /* get time */ current_jiffies = jiffies; do_gettimeofday(&tv); /* avoid overflow with gap >1s */ if (tv.tv_sec - ir->base_time.tv_sec > 1) { gap = 200000; } else { gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + tv.tv_usec - ir->base_time.tv_usec; } /* signal we're ready to start a new code */ ir->active = 0; /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */ if (gap < 28000) { dprintk(1, "ir-common: spurious timer_end\n"); return; } if (ir->last_bit < 20) { /* ignore spurious codes (caused by light/other remotes) */ dprintk(1, "ir-common: short code: %x\n", ir->code); } else { ir->code = (ir->code << ir->shift_by) | 1; rc5 = ir_rc5_decode(ir->code); /* two start bits? */ if (RC5_START(rc5) != ir->start) { dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5)); /* right address? */ } else if (RC5_ADDR(rc5) == ir->addr) { u32 toggle = RC5_TOGGLE(rc5); u32 instr = RC5_INSTR(rc5); /* Good code, decide if repeat/repress */ if (toggle != RC5_TOGGLE(ir->last_rc5) || instr != RC5_INSTR(ir->last_rc5)) { dprintk(1, "ir-common: instruction %x, toggle %x\n", instr, toggle); ir_input_nokey(ir->dev, &ir->ir); ir_input_keydown(ir->dev, &ir->ir, instr, instr); } /* Set/reset key-up timer */ timeout = current_jiffies + (500 + ir->rc5_key_timeout * HZ) / 1000; mod_timer(&ir->timer_keyup, timeout); /* Save code for repeat test */ ir->last_rc5 = rc5; } } }