aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-nec-decoder.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-03-21 11:24:24 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:52:57 -0400
commitada39630c758c5c3098f4fc1361103ea2bc1afe0 (patch)
treecfad77eb7e0f96256edc08c058ea7b39ee2d30b1 /drivers/media/IR/ir-nec-decoder.c
parent6660de568d164e4eda6617dadcb999c96e62203f (diff)
V4L/DVB: ir-core/saa7134: Move ir keyup/keydown code to the ir-core
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-nec-decoder.c')
-rw-r--r--drivers/media/IR/ir-nec-decoder.c90
1 files changed, 58 insertions, 32 deletions
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index 16360eb4055b..a58c717ec6b0 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -30,37 +30,35 @@
30#define MIN_BIT0_TIME 360000 30#define MIN_BIT0_TIME 360000
31#define MAX_BIT0_TIME 760000 31#define MAX_BIT0_TIME 760000
32 32
33 33/**
34/** Decode NEC pulsecode. This code can take up to 76.5 ms to run. 34 * __ir_nec_decode() - Decode one NEC pulsecode
35 Unfortunately, using IRQ to decode pulse didn't work, since it uses 35 * @input_dev: the struct input_dev descriptor of the device
36 a pulse train of 38KHz. This means one pulse on each 52 us 36 * @evs: event array with type/duration of pulse/space
37*/ 37 * @len: length of the array
38 38 * @pos: position to start seeking for a code
39int ir_nec_decode(struct input_dev *input_dev, 39 * This function returns the decoded ircode or -EINVAL if no pulse got decoded
40 struct ir_raw_event *evs, 40 */
41 int len) 41static int __ir_nec_decode(struct input_dev *input_dev,
42 struct ir_raw_event *evs,
43 int len, int *pos)
42{ 44{
43 int i, count = -1; 45 int count = -1;
44 int ircode = 0, not_code = 0; 46 int ircode = 0, not_code = 0;
45#if 0
46 /* Needed only after porting the event code to the decoder */
47 struct ir_input_dev *ir = input_get_drvdata(input_dev);
48#endif
49 47
50 /* Be sure that the first event is an start one and is a pulse */ 48 /* Be sure that the first event is an start one and is a pulse */
51 for (i = 0; i < len; i++) { 49 for (; *pos < len; (*pos)++) {
52 if (evs[i].type & (IR_START_EVENT | IR_PULSE)) 50 if (evs[*pos].type & (IR_START_EVENT | IR_PULSE))
53 break; 51 break;
54 } 52 }
55 i++; /* First event doesn't contain data */ 53 (*pos)++; /* First event doesn't contain data */
56 54
57 if (i >= len) 55 if (*pos >= len)
58 return 0; 56 return 0;
59 57
60 /* First space should have 4.5 ms otherwise is not NEC protocol */ 58 /* First space should have 4.5 ms otherwise is not NEC protocol */
61 if ((evs[i].delta.tv_nsec < MIN_START_TIME) | 59 if ((evs[*pos].delta.tv_nsec < MIN_START_TIME) |
62 (evs[i].delta.tv_nsec > MAX_START_TIME) | 60 (evs[*pos].delta.tv_nsec > MAX_START_TIME) |
63 (evs[i].type != IR_SPACE)) 61 (evs[*pos].type != IR_SPACE))
64 goto err; 62 goto err;
65 63
66 /* 64 /*
@@ -68,24 +66,24 @@ int ir_nec_decode(struct input_dev *input_dev,
68 */ 66 */
69 67
70 count = 0; 68 count = 0;
71 for (i++; i < len; i++) { 69 for ((*pos)++; *pos < len; (*pos)++) {
72 int bit; 70 int bit;
73 71
74 if ((evs[i].delta.tv_nsec < MIN_PULSE_TIME) | 72 if ((evs[*pos].delta.tv_nsec < MIN_PULSE_TIME) |
75 (evs[i].delta.tv_nsec > MAX_PULSE_TIME) | 73 (evs[*pos].delta.tv_nsec > MAX_PULSE_TIME) |
76 (evs[i].type != IR_PULSE)) 74 (evs[*pos].type != IR_PULSE))
77 goto err; 75 goto err;
78 76
79 if (++i >= len) 77 if (++*pos >= len)
80 goto err; 78 goto err;
81 if (evs[i].type != IR_SPACE) 79 if (evs[*pos].type != IR_SPACE)
82 goto err; 80 goto err;
83 81
84 if ((evs[i].delta.tv_nsec > MIN_BIT1_TIME) && 82 if ((evs[*pos].delta.tv_nsec > MIN_BIT1_TIME) &&
85 (evs[i].delta.tv_nsec < MAX_BIT1_TIME)) 83 (evs[*pos].delta.tv_nsec < MAX_BIT1_TIME))
86 bit = 1; 84 bit = 1;
87 else if ((evs[i].delta.tv_nsec > MIN_BIT0_TIME) && 85 else if ((evs[*pos].delta.tv_nsec > MIN_BIT0_TIME) &&
88 (evs[i].delta.tv_nsec < MAX_BIT0_TIME)) 86 (evs[*pos].delta.tv_nsec < MAX_BIT0_TIME))
89 bit = 0; 87 bit = 0;
90 else 88 else
91 goto err; 89 goto err;
@@ -120,12 +118,40 @@ int ir_nec_decode(struct input_dev *input_dev,
120 } 118 }
121 119
122 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode); 120 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode);
121 ir_keydown(input_dev, ircode);
122 ir_keyup(input_dev);
123 123
124 return ircode; 124 return ircode;
125err: 125err:
126 IR_dprintk(1, "NEC decoded failed at bit %d while decoding %luus time\n", 126 IR_dprintk(1, "NEC decoded failed at bit %d while decoding %luus time\n",
127 count, (evs[i].delta.tv_nsec + 500) / 1000); 127 count, (evs[*pos].delta.tv_nsec + 500) / 1000);
128 128
129 return -EINVAL; 129 return -EINVAL;
130} 130}
131
132/**
133 * __ir_nec_decode() - Decodes all NEC pulsecodes on a given array
134 * @input_dev: the struct input_dev descriptor of the device
135 * @evs: event array with type/duration of pulse/space
136 * @len: length of the array
137 * This function returns the number of decoded pulses or -EINVAL if no
138 * pulse got decoded
139 */
140int ir_nec_decode(struct input_dev *input_dev,
141 struct ir_raw_event *evs,
142 int len)
143{
144 int pos = 0;
145 int rc = 0;
146
147 while (pos < len) {
148 if (__ir_nec_decode(input_dev, evs, len, &pos) >= 0)
149 rc++;
150 }
151
152 if (!rc)
153 return -EINVAL;
154 return rc;
155}
156
131EXPORT_SYMBOL_GPL(ir_nec_decode); 157EXPORT_SYMBOL_GPL(ir_nec_decode);