Lines Matching +full:duration +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ir-xmp-decoder.c - handle XMP IR Pulse/Space protocol
6 * - Based on info from http://www.hifi-remote.com
7 * - Ignore Toggle=9 frames
8 * - Ignore XMP-1 XMP-2 difference, always store 16 bit OBC
13 #include "rc-core-priv.h"
15 #define XMP_UNIT 136 /* us */
16 #define XMP_LEADER 210 /* us */
17 #define XMP_NIBBLE_PREFIX 760 /* us */
18 #define XMP_HALFFRAME_SPACE 13800 /* us */
19 /* should be 80ms but not all duration supliers can go that high */
29 * ir_xmp_decode() - Decode one XMP pulse or space
33 * This function returns -EINVAL if the pulse violates the state machine
37 struct xmp_dec *data = &dev->raw->xmp; in ir_xmp_decode()
41 data->state = STATE_INACTIVE; in ir_xmp_decode()
45 dev_dbg(&dev->dev, "XMP decode started at state %d %d (%uus %s)\n", in ir_xmp_decode()
46 data->state, data->count, ev.duration, TO_STR(ev.pulse)); in ir_xmp_decode()
48 switch (data->state) { in ir_xmp_decode()
54 if (eq_margin(ev.duration, XMP_LEADER, XMP_UNIT / 2)) { in ir_xmp_decode()
55 data->count = 0; in ir_xmp_decode()
56 data->state = STATE_NIBBLE_SPACE; in ir_xmp_decode()
65 if (eq_margin(ev.duration, XMP_LEADER, XMP_UNIT / 2)) in ir_xmp_decode()
66 data->state = STATE_NIBBLE_SPACE; in ir_xmp_decode()
74 if (geq_margin(ev.duration, XMP_TRAILER_SPACE, XMP_NIBBLE_PREFIX)) { in ir_xmp_decode()
80 if (data->count != 16) { in ir_xmp_decode()
81 dev_dbg(&dev->dev, "received TRAILER period at index %d: %u\n", in ir_xmp_decode()
82 data->count, ev.duration); in ir_xmp_decode()
83 data->state = STATE_INACTIVE; in ir_xmp_decode()
84 return -EINVAL; in ir_xmp_decode()
87 n = data->durations; in ir_xmp_decode()
93 divider = (n[3] - XMP_NIBBLE_PREFIX) / 15 - 2000; in ir_xmp_decode()
95 dev_dbg(&dev->dev, "divider to small %d.\n", in ir_xmp_decode()
97 data->state = STATE_INACTIVE; in ir_xmp_decode()
98 return -EINVAL; in ir_xmp_decode()
103 n[i] = (n[i] - XMP_NIBBLE_PREFIX) / divider; in ir_xmp_decode()
110 dev_dbg(&dev->dev, "checksum errors sum1=0x%X sum2=0x%X\n", in ir_xmp_decode()
112 data->state = STATE_INACTIVE; in ir_xmp_decode()
113 return -EINVAL; in ir_xmp_decode()
124 dev_dbg(&dev->dev, "subaddress nibbles mismatch 0x%02X != 0x%02X\n", in ir_xmp_decode()
126 data->state = STATE_INACTIVE; in ir_xmp_decode()
127 return -EINVAL; in ir_xmp_decode()
130 dev_dbg(&dev->dev, "Warning: OEM nibbles 0x%02X. Expected 0x44\n", in ir_xmp_decode()
135 dev_dbg(&dev->dev, "XMP scancode 0x%06x\n", scancode); in ir_xmp_decode()
141 dev_dbg(&dev->dev, "Repeat last key\n"); in ir_xmp_decode()
143 data->state = STATE_INACTIVE; in ir_xmp_decode()
147 } else if (geq_margin(ev.duration, XMP_HALFFRAME_SPACE, XMP_NIBBLE_PREFIX)) { in ir_xmp_decode()
149 if (data->count == 16) { in ir_xmp_decode()
150 …dev_dbg(&dev->dev, "received half frame pulse at index %d. Probably a final frame key-up event: %u… in ir_xmp_decode()
151 data->count, ev.duration); in ir_xmp_decode()
157 data->count = 8; in ir_xmp_decode()
160 else if (data->count != 8) in ir_xmp_decode()
161 dev_dbg(&dev->dev, "received half frame pulse at index %d: %u\n", in ir_xmp_decode()
162 data->count, ev.duration); in ir_xmp_decode()
163 data->state = STATE_LEADER_PULSE; in ir_xmp_decode()
167 } else if (geq_margin(ev.duration, XMP_NIBBLE_PREFIX, XMP_UNIT)) { in ir_xmp_decode()
169 if (data->count == 16) { in ir_xmp_decode()
170 dev_dbg(&dev->dev, "too many pulses (%d) ignoring: %u\n", in ir_xmp_decode()
171 data->count, ev.duration); in ir_xmp_decode()
172 data->state = STATE_INACTIVE; in ir_xmp_decode()
173 return -EINVAL; in ir_xmp_decode()
175 data->durations[data->count] = ev.duration; in ir_xmp_decode()
176 data->count++; in ir_xmp_decode()
177 data->state = STATE_LEADER_PULSE; in ir_xmp_decode()
186 dev_dbg(&dev->dev, "XMP decode failed at count %d state %d (%uus %s)\n", in ir_xmp_decode()
187 data->count, data->state, ev.duration, TO_STR(ev.pulse)); in ir_xmp_decode()
188 data->state = STATE_INACTIVE; in ir_xmp_decode()
189 return -EINVAL; in ir_xmp_decode()