Lines Matching +full:duration +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ir-sharp-decoder.c - handle Sharp IR Pulse/Space protocol
4 * Copyright (C) 2013-2014 Imagination Technologies Ltd.
12 #include "rc-core-priv.h"
15 #define SHARP_UNIT 40 /* us */
16 #define SHARP_BIT_PULSE (8 * SHARP_UNIT) /* 320us */
17 #define SHARP_BIT_0_PERIOD (25 * SHARP_UNIT) /* 1ms (680us space) */
18 #define SHARP_BIT_1_PERIOD (50 * SHARP_UNIT) /* 2ms (1680us space) */
19 #define SHARP_BIT_0_SPACE (17 * SHARP_UNIT) /* 680us space */
20 #define SHARP_BIT_1_SPACE (42 * SHARP_UNIT) /* 1680us space */
34 * ir_sharp_decode() - Decode one Sharp pulse or space
38 * This function returns -EINVAL if the pulse violates the state machine
42 struct sharp_dec *data = &dev->raw->sharp; in ir_sharp_decode()
47 data->state = STATE_INACTIVE; in ir_sharp_decode()
51 dev_dbg(&dev->dev, "Sharp decode started at state %d (%uus %s)\n", in ir_sharp_decode()
52 data->state, ev.duration, TO_STR(ev.pulse)); in ir_sharp_decode()
54 switch (data->state) { in ir_sharp_decode()
60 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
64 data->count = 0; in ir_sharp_decode()
65 data->pulse_len = ev.duration; in ir_sharp_decode()
66 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
73 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
77 data->pulse_len = ev.duration; in ir_sharp_decode()
78 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
85 data->bits <<= 1; in ir_sharp_decode()
86 if (eq_margin(data->pulse_len + ev.duration, SHARP_BIT_1_PERIOD, in ir_sharp_decode()
88 data->bits |= 1; in ir_sharp_decode()
89 else if (!eq_margin(data->pulse_len + ev.duration, in ir_sharp_decode()
92 data->count++; in ir_sharp_decode()
94 if (data->count == SHARP_NBITS || in ir_sharp_decode()
95 data->count == SHARP_NBITS * 2) in ir_sharp_decode()
96 data->state = STATE_TRAILER_PULSE; in ir_sharp_decode()
98 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
106 if (!eq_margin(ev.duration, SHARP_BIT_PULSE, in ir_sharp_decode()
110 if (data->count == SHARP_NBITS) { in ir_sharp_decode()
112 if ((data->bits & 0x3) != 0x2 && in ir_sharp_decode()
114 (data->bits & 0x3) != 0x0) in ir_sharp_decode()
116 data->state = STATE_ECHO_SPACE; in ir_sharp_decode()
118 data->state = STATE_TRAILER_SPACE; in ir_sharp_decode()
126 if (!eq_margin(ev.duration, SHARP_ECHO_SPACE, in ir_sharp_decode()
130 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
138 if (!geq_margin(ev.duration, SHARP_TRAILER_SPACE, in ir_sharp_decode()
142 /* Validate - command, ext, chk should be inverted in 2nd */ in ir_sharp_decode()
143 msg = (data->bits >> 15) & 0x7fff; in ir_sharp_decode()
144 echo = data->bits & 0x7fff; in ir_sharp_decode()
146 dev_dbg(&dev->dev, in ir_sharp_decode()
156 dev_dbg(&dev->dev, "Sharp scancode 0x%04x\n", scancode); in ir_sharp_decode()
159 data->state = STATE_INACTIVE; in ir_sharp_decode()
163 dev_dbg(&dev->dev, "Sharp decode failed at count %d state %d (%uus %s)\n", in ir_sharp_decode()
164 data->count, data->state, ev.duration, TO_STR(ev.pulse)); in ir_sharp_decode()
165 data->state = STATE_INACTIVE; in ir_sharp_decode()
166 return -EINVAL; in ir_sharp_decode()
181 * ir_sharp_encode() - Encode a scancode as a stream of raw events
189 * -ENOBUFS if there isn't enough space in the array to fit the
206 max -= ret; in ir_sharp_encode()
215 return e - events; in ir_sharp_encode()