Lines Matching +full:duration +full:- +full:us
1 /* ir-sharp-decoder.c - handle Sharp IR Pulse/Space protocol
3 * Copyright (C) 2013-2014 Imagination Technologies Ltd.
20 #include "rc-core-priv.h"
24 #define SHARP_BIT_PULSE (8 * SHARP_UNIT) /* 320us */
25 #define SHARP_BIT_0_PERIOD (25 * SHARP_UNIT) /* 1ms (680us space) */
40 * ir_sharp_decode() - Decode one Sharp pulse or space
44 * This function returns -EINVAL if the pulse violates the state machine
48 struct sharp_dec *data = &dev->raw->sharp; in ir_sharp_decode()
53 data->state = STATE_INACTIVE; in ir_sharp_decode()
57 dev_dbg(&dev->dev, "Sharp decode started at state %d (%uus %s)\n", in ir_sharp_decode()
58 data->state, TO_US(ev.duration), TO_STR(ev.pulse)); in ir_sharp_decode()
60 switch (data->state) { in ir_sharp_decode()
66 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
70 data->count = 0; in ir_sharp_decode()
71 data->pulse_len = ev.duration; in ir_sharp_decode()
72 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
79 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
83 data->pulse_len = ev.duration; in ir_sharp_decode()
84 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
91 data->bits <<= 1; in ir_sharp_decode()
92 if (eq_margin(data->pulse_len + ev.duration, SHARP_BIT_1_PERIOD, in ir_sharp_decode()
94 data->bits |= 1; in ir_sharp_decode()
95 else if (!eq_margin(data->pulse_len + ev.duration, in ir_sharp_decode()
98 data->count++; in ir_sharp_decode()
100 if (data->count == SHARP_NBITS || in ir_sharp_decode()
101 data->count == SHARP_NBITS * 2) in ir_sharp_decode()
102 data->state = STATE_TRAILER_PULSE; in ir_sharp_decode()
104 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
112 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
116 if (data->count == SHARP_NBITS) { in ir_sharp_decode()
118 if ((data->bits & 0x3) != 0x2 && in ir_sharp_decode()
120 (data->bits & 0x3) != 0x0) in ir_sharp_decode()
122 data->state = STATE_ECHO_SPACE; in ir_sharp_decode()
124 data->state = STATE_TRAILER_SPACE; in ir_sharp_decode()
132 if (!eq_margin(ev.duration, SHARP_ECHO_SPACE, in ir_sharp_decode()
136 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
144 if (!geq_margin(ev.duration, SHARP_TRAILER_SPACE, in ir_sharp_decode()
148 /* Validate - command, ext, chk should be inverted in 2nd */ in ir_sharp_decode()
149 msg = (data->bits >> 15) & 0x7fff; in ir_sharp_decode()
150 echo = data->bits & 0x7fff; in ir_sharp_decode()
152 dev_dbg(&dev->dev, in ir_sharp_decode()
162 dev_dbg(&dev->dev, "Sharp scancode 0x%04x\n", scancode); in ir_sharp_decode()
165 data->state = STATE_INACTIVE; in ir_sharp_decode()
169 dev_dbg(&dev->dev, "Sharp decode failed at count %d state %d (%uus %s)\n", in ir_sharp_decode()
170 data->count, data->state, TO_US(ev.duration), TO_STR(ev.pulse)); in ir_sharp_decode()
171 data->state = STATE_INACTIVE; in ir_sharp_decode()
172 return -EINVAL; in ir_sharp_decode()
187 * ir_sharp_encode() - Encode a scancode as a stream of raw events
195 * -ENOBUFS if there isn't enough space in the array to fit the
212 max -= ret; in ir_sharp_encode()
221 return e - events; in ir_sharp_encode()