2 * ImgTec IR Decoder setup for NEC protocol.
4 * Copyright 2010-2014 Imagination Technologies Ltd.
8 #include <linux/bitrev.h>
10 /* Convert NEC data to a scancode */
11 static int img_ir_nec_scancode(int len
, u64 raw
, int *scancode
, u64 protocols
)
13 unsigned int addr
, addr_inv
, data
, data_inv
;
14 /* a repeat code has no data */
16 return IMG_IR_REPEATCODE
;
19 /* raw encoding: ddDDaaAA */
20 addr
= (raw
>> 0) & 0xff;
21 addr_inv
= (raw
>> 8) & 0xff;
22 data
= (raw
>> 16) & 0xff;
23 data_inv
= (raw
>> 24) & 0xff;
24 if ((data_inv
^ data
) != 0xff) {
25 /* 32-bit NEC (used by Apple and TiVo remotes) */
26 /* scan encoding: as transmitted, MSBit = first received bit */
27 *scancode
= bitrev8(addr
) << 24 |
28 bitrev8(addr_inv
) << 16 |
31 } else if ((addr_inv
^ addr
) != 0xff) {
33 /* scan encoding: AAaaDD */
34 *scancode
= addr
<< 16 |
39 /* scan encoding: AADD */
40 *scancode
= addr
<< 8 |
43 return IMG_IR_SCANCODE
;
46 /* Convert NEC scancode to NEC data filter */
47 static int img_ir_nec_filter(const struct rc_scancode_filter
*in
,
48 struct img_ir_filter
*out
, u64 protocols
)
50 unsigned int addr
, addr_inv
, data
, data_inv
;
51 unsigned int addr_m
, addr_inv_m
, data_m
, data_inv_m
;
53 data
= in
->data
& 0xff;
54 data_m
= in
->mask
& 0xff;
56 if ((in
->data
| in
->mask
) & 0xff000000) {
57 /* 32-bit NEC (used by Apple and TiVo remotes) */
58 /* scan encoding: as transmitted, MSBit = first received bit */
59 addr
= bitrev8(in
->data
>> 24);
60 addr_m
= bitrev8(in
->mask
>> 24);
61 addr_inv
= bitrev8(in
->data
>> 16);
62 addr_inv_m
= bitrev8(in
->mask
>> 16);
63 data
= bitrev8(in
->data
>> 8);
64 data_m
= bitrev8(in
->mask
>> 8);
65 data_inv
= bitrev8(in
->data
>> 0);
66 data_inv_m
= bitrev8(in
->mask
>> 0);
67 } else if ((in
->data
| in
->mask
) & 0x00ff0000) {
69 /* scan encoding AAaaDD */
70 addr
= (in
->data
>> 16) & 0xff;
71 addr_m
= (in
->mask
>> 16) & 0xff;
72 addr_inv
= (in
->data
>> 8) & 0xff;
73 addr_inv_m
= (in
->mask
>> 8) & 0xff;
74 data_inv
= data
^ 0xff;
78 /* scan encoding: AADD */
79 addr
= (in
->data
>> 8) & 0xff;
80 addr_m
= (in
->mask
>> 8) & 0xff;
81 addr_inv
= addr
^ 0xff;
83 data_inv
= data
^ 0xff;
87 /* raw encoding: ddDDaaAA */
88 out
->data
= data_inv
<< 24 |
92 out
->mask
= data_inv_m
<< 24 |
101 * See also http://www.sbprojects.com/knowledge/ir/nec.php
102 * http://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocol
104 struct img_ir_decoder img_ir_nec
= {
108 .code_type
= IMG_IR_CODETYPE_PULSEDIST
,
111 .unit
= 562500, /* 562.5 us */
115 .pulse
= { 16 /* 9ms */ },
116 .space
= { 8 /* 4.5ms */ },
120 .pulse
= { 1 /* 562.5 us */ },
121 .space
= { 1 /* 562.5 us */ },
125 .pulse
= { 1 /* 562.5 us */ },
126 .space
= { 3 /* 1687.5 us */ },
132 .ft_min
= 10, /* 5.625 ms */
136 .repeat
= 108, /* 108 ms */
140 .space
= { 4 /* 2.25 ms */ },
144 .minlen
= 0, /* repeat code has no data */
149 .scancode
= img_ir_nec_scancode
,
150 .filter
= img_ir_nec_filter
,