Lines Matching +full:data +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0+
2 // ir-imon-decoder.c - handle iMon protocol
9 #include "rc-core-priv.h"
19 * This protocol has 30 bits. The format is one IMON_UNIT header pulse,
20 * followed by 30 bits. Each bit is one IMON_UNIT check field, and then
22 * The check field is always space for some bits, for others it is pulse if
24 * defines which bits are of type check.
27 * the lower bits are all set, iow. the last pulse is for the lowest
40 struct imon_dec *imon = &dev->raw->imon; in ir_imon_decode_scancode()
43 if (imon->bits == 0x299115b7) in ir_imon_decode_scancode()
44 imon->stick_keyboard = !imon->stick_keyboard; in ir_imon_decode_scancode()
46 if ((imon->bits & 0xfc0000ff) == 0x680000b7) { in ir_imon_decode_scancode()
50 buf = imon->bits >> 16; in ir_imon_decode_scancode()
53 if (imon->bits & 0x02000000) in ir_imon_decode_scancode()
55 buf = imon->bits >> 8; in ir_imon_decode_scancode()
58 if (imon->bits & 0x01000000) in ir_imon_decode_scancode()
61 if (rel_x && rel_y && imon->stick_keyboard) { in ir_imon_decode_scancode()
63 imon->bits = rel_y > 0 ? in ir_imon_decode_scancode()
67 imon->bits = rel_x > 0 ? in ir_imon_decode_scancode()
72 if (!imon->stick_keyboard) { in ir_imon_decode_scancode()
73 input_report_rel(dev->input_dev, REL_X, rel_x); in ir_imon_decode_scancode()
74 input_report_rel(dev->input_dev, REL_Y, rel_y); in ir_imon_decode_scancode()
76 input_report_key(dev->input_dev, BTN_LEFT, in ir_imon_decode_scancode()
77 (imon->bits & 0x00010000) != 0); in ir_imon_decode_scancode()
78 input_report_key(dev->input_dev, BTN_RIGHT, in ir_imon_decode_scancode()
79 (imon->bits & 0x00040000) != 0); in ir_imon_decode_scancode()
83 rc_keydown(dev, RC_PROTO_IMON, imon->bits, 0); in ir_imon_decode_scancode()
87 * ir_imon_decode() - Decode one iMON pulse or space
91 * This function returns -EINVAL if the pulse violates the state machine
95 struct imon_dec *data = &dev->raw->imon; in ir_imon_decode() local
99 data->state = STATE_INACTIVE; in ir_imon_decode()
103 dev_dbg(&dev->dev, in ir_imon_decode()
105 data->state, data->count, ev.duration, TO_STR(ev.pulse)); in ir_imon_decode()
108 * Since iMON protocol is a series of bits, if at any point in ir_imon_decode()
109 * we encounter an error, make sure that any remaining bits in ir_imon_decode()
110 * aren't parsed as a scancode made up of less bits. in ir_imon_decode()
117 if (data->state == STATE_ERROR) { in ir_imon_decode()
119 data->state = STATE_INACTIVE; in ir_imon_decode()
129 switch (data->state) { in ir_imon_decode()
132 data->state = STATE_BIT_CHK; in ir_imon_decode()
133 data->bits = 0; in ir_imon_decode()
134 data->count = IMON_BITS; in ir_imon_decode()
138 if (IMON_CHKBITS & BIT(data->count)) in ir_imon_decode()
139 data->last_chk = ev.pulse; in ir_imon_decode()
142 data->state = STATE_BIT_START; in ir_imon_decode()
145 data->bits <<= 1; in ir_imon_decode()
147 data->bits |= 1; in ir_imon_decode()
149 if (IMON_CHKBITS & BIT(data->count)) { in ir_imon_decode()
150 if (data->last_chk != !(data->bits & 3)) in ir_imon_decode()
154 if (!data->count--) in ir_imon_decode()
155 data->state = STATE_FINISHED; in ir_imon_decode()
157 data->state = STATE_BIT_CHK; in ir_imon_decode()
163 data->state = STATE_INACTIVE; in ir_imon_decode()
169 dev_dbg(&dev->dev, in ir_imon_decode()
171 data->state, data->count, ev.duration, TO_STR(ev.pulse)); in ir_imon_decode()
173 data->state = STATE_ERROR; in ir_imon_decode()
175 return -EINVAL; in ir_imon_decode()
179 * ir_imon_encode() - Encode a scancode as a stream of raw events
187 * -ENOBUFS if there isn't enough space in the array to fit the
196 if (!max--) in ir_imon_encode()
197 return -ENOBUFS; in ir_imon_encode()
200 for (i = IMON_BITS; i >= 0; i--) { in ir_imon_encode()
206 if (pulse == e->pulse) { in ir_imon_encode()
207 e->duration += IMON_UNIT; in ir_imon_encode()
209 if (!max--) in ir_imon_encode()
210 return -ENOBUFS; in ir_imon_encode()
216 if (pulse == e->pulse) { in ir_imon_encode()
217 e->duration += IMON_UNIT; in ir_imon_encode()
219 if (!max--) in ir_imon_encode()
220 return -ENOBUFS; in ir_imon_encode()
225 if (e->pulse) in ir_imon_encode()
228 return e - events; in ir_imon_encode()
233 struct imon_dec *imon = &dev->raw->imon; in ir_imon_register()
235 imon->stick_keyboard = false; in ir_imon_register()