Lines Matching +full:encode +full:- +full:only

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"
32 * ir_sharp_decode() - Decode one Sharp pulse or space
36 * This function returns -EINVAL if the pulse violates the state machine
40 struct sharp_dec *data = &dev->raw->sharp; in ir_sharp_decode()
45 data->state = STATE_INACTIVE; in ir_sharp_decode()
49 dev_dbg(&dev->dev, "Sharp decode started at state %d (%uus %s)\n", in ir_sharp_decode()
50 data->state, ev.duration, TO_STR(ev.pulse)); in ir_sharp_decode()
52 switch (data->state) { in ir_sharp_decode()
62 data->count = 0; in ir_sharp_decode()
63 data->pulse_len = ev.duration; in ir_sharp_decode()
64 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
75 data->pulse_len = ev.duration; in ir_sharp_decode()
76 data->state = STATE_BIT_SPACE; in ir_sharp_decode()
83 data->bits <<= 1; in ir_sharp_decode()
84 if (eq_margin(data->pulse_len + ev.duration, SHARP_BIT_1_PERIOD, in ir_sharp_decode()
86 data->bits |= 1; in ir_sharp_decode()
87 else if (!eq_margin(data->pulse_len + ev.duration, in ir_sharp_decode()
90 data->count++; in ir_sharp_decode()
92 if (data->count == SHARP_NBITS || in ir_sharp_decode()
93 data->count == SHARP_NBITS * 2) in ir_sharp_decode()
94 data->state = STATE_TRAILER_PULSE; in ir_sharp_decode()
96 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
108 if (data->count == SHARP_NBITS) { in ir_sharp_decode()
110 if ((data->bits & 0x3) != 0x2 && in ir_sharp_decode()
112 (data->bits & 0x3) != 0x0) in ir_sharp_decode()
114 data->state = STATE_ECHO_SPACE; in ir_sharp_decode()
116 data->state = STATE_TRAILER_SPACE; in ir_sharp_decode()
128 data->state = STATE_BIT_PULSE; in ir_sharp_decode()
140 /* Validate - command, ext, chk should be inverted in 2nd */ in ir_sharp_decode()
141 msg = (data->bits >> 15) & 0x7fff; in ir_sharp_decode()
142 echo = data->bits & 0x7fff; in ir_sharp_decode()
144 dev_dbg(&dev->dev, in ir_sharp_decode()
154 dev_dbg(&dev->dev, "Sharp scancode 0x%04x\n", scancode); in ir_sharp_decode()
157 data->state = STATE_INACTIVE; in ir_sharp_decode()
161 dev_dbg(&dev->dev, "Sharp decode failed at count %d state %d (%uus %s)\n", in ir_sharp_decode()
162 data->count, data->state, ev.duration, TO_STR(ev.pulse)); in ir_sharp_decode()
163 data->state = STATE_INACTIVE; in ir_sharp_decode()
164 return -EINVAL; in ir_sharp_decode()
179 * ir_sharp_encode() - Encode a scancode as a stream of raw events
181 * @protocol: protocol to encode
182 * @scancode: scancode to encode
187 * -ENOBUFS if there isn't enough space in the array to fit the
204 max -= ret; in ir_sharp_encode()
213 return e - events; in ir_sharp_encode()
219 .encode = ir_sharp_encode,