Exemplo n.º 1
0
/* decode raw bit pattern to RC5 code */
static u32 rc5_decode(unsigned int code)
{
	unsigned int org_code = code;
	unsigned int pair;
	unsigned int rc5 = 0;
	int i;

	code = (code << 1) | 1;
	for (i = 0; i < 14; ++i) {
		pair = code & 0x3;
		code >>= 2;

		rc5 <<= 1;
		switch (pair) {
		case 0:
		case 2:
			break;
		case 1:
			rc5 |= 1;
			break;
		case 3:
			dprintk(KERN_WARNING "bad code: %x\n", org_code);
			return 0;
		}
	}
	dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
		"instr=%x\n", rc5, org_code, RC5_START(rc5),
		RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
	return rc5;
}
Exemplo n.º 2
0
/* decode raw bit pattern to RC5 code */
u32 ir_rc5_decode(unsigned int code)
{
	unsigned int org_code = code;
	unsigned int pair;
	unsigned int rc5 = 0;
	int i;

	for (i = 0; i < 14; ++i) {
		pair = code & 0x3;
		code >>= 2;

		rc5 <<= 1;
		switch (pair) {
		case 0:
		case 2:
			break;
		case 1:
			rc5 |= 1;
			break;
		case 3:
			dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
			return 0;
		}
	}
	dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
		"instr=%x\n", rc5, org_code, RC5_START(rc5),
		RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
	return rc5;
}
Exemplo n.º 3
0
static void bttv_rc5_timer_end(unsigned long data)
{
	struct bttv_ir *ir = (struct bttv_ir *)data;
	struct timeval tv;
	u32 gap;
	u32 rc5 = 0;

	/* get time */
	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 = false;

	/* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
	if (gap < 28000) {
		dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
		return;
	}

	if (ir->last_bit < 20) {
		/* ignore spurious codes (caused by light/other remotes) */
		dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
	} else {
		ir->code = (ir->code << ir->shift_by) | 1;
		rc5 = bttv_rc5_decode(ir->code);

		/* two start bits? */
		if (RC5_START(rc5) != ir->start) {
			printk(KERN_INFO DEVNAME ":"
			       " 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 */
			rc_keydown(ir->dev, instr, toggle);
			dprintk(KERN_INFO DEVNAME ":"
				" instruction %x, toggle %x\n",
				instr, toggle);
		}
	}
}
Exemplo n.º 4
0
static void bttv_rc5_timer_end(unsigned long data)
{
	struct bttv_ir *ir = (struct bttv_ir *)data;
	ktime_t tv;
	u32 gap, rc5, scancode;
	u8 toggle, command, system;

	/* get time */
	tv = ktime_get();

	gap = ktime_to_us(ktime_sub(tv, ir->base_time));
	/* avoid overflow with gap >1s */
	if (gap > USEC_PER_SEC) {
		gap = 200000;
	}
	/* signal we're ready to start a new code */
	ir->active = false;

	/* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
	if (gap < 28000) {
		dprintk("spurious timer_end\n");
		return;
	}

	if (ir->last_bit < 20) {
		/* ignore spurious codes (caused by light/other remotes) */
		dprintk("short code: %x\n", ir->code);
		return;
	}

	ir->code = (ir->code << ir->shift_by) | 1;
	rc5 = bttv_rc5_decode(ir->code);

	toggle = RC5_TOGGLE(rc5);
	system = RC5_ADDR(rc5);
	command = RC5_INSTR(rc5);

	switch (RC5_START(rc5)) {
	case 0x3:
		break;
	case 0x2:
		command += 0x40;
		break;
	default:
		return;
	}

	scancode = RC_SCANCODE_RC5(system, command);
	rc_keydown(ir->dev, RC_TYPE_RC5, scancode, toggle);
	dprintk("scancode %x, toggle %x\n", scancode, toggle);
}
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));
}
Exemplo n.º 6
0
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));
}
Exemplo n.º 7
0
static void bttv_rc5_timer_end(unsigned long data)
{
	struct bttv_ir *ir = (struct bttv_ir *)data;
	struct timeval tv;
	unsigned long current_jiffies, timeout;
	u32 gap;

	/* 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;
	}

	/* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
	if (gap < 28000) {
		dprintk(KERN_WARNING "spurious timer_end\n");
		return;
	}

	ir->active = 0;
	if (ir->last_bit < 20) {
		/* ignore spurious codes (caused by light/other remotes) */
		dprintk(KERN_WARNING "short code: %x\n", ir->code);
	} else {
		u32 rc5 = rc5_decode(ir->code);

		/* two start bits? */
		if (RC5_START(rc5) != 3) {
			dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));

			/* right address? */
		} else if (RC5_ADDR(rc5) == 0x0) {
			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(KERN_WARNING "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 + rc5_key_timeout
						     * HZ) / 1000;
			mod_timer(&ir->timer_keyup, timeout);

			/* Save code for repeat test */
			ir->last_rc5 = rc5;
		}
	}
}