Lines Matching +full:data +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0
2 // ir-rc5-decoder.c - decoder for RC5(x) and StreamZap protocols
12 #include "rc-core-priv.h"
34 * ir_rc5_decode() - Decode one RC-5 pulse or space
38 * This function returns -EINVAL if the pulse violates the state machine
42 struct rc5_dec *data = &dev->raw->rc5; in ir_rc5_decode() local
49 data->state = STATE_INACTIVE; in ir_rc5_decode()
57 dev_dbg(&dev->dev, "RC5(x/sz) decode started at state %i (%uus %s)\n", in ir_rc5_decode()
58 data->state, ev.duration, TO_STR(ev.pulse)); in ir_rc5_decode()
63 switch (data->state) { in ir_rc5_decode()
69 data->state = STATE_BIT_START; in ir_rc5_decode()
70 data->count = 1; in ir_rc5_decode()
76 data->state = STATE_FINISHED; in ir_rc5_decode()
83 data->bits <<= 1; in ir_rc5_decode()
85 data->bits |= 1; in ir_rc5_decode()
86 data->count++; in ir_rc5_decode()
87 data->state = STATE_BIT_END; in ir_rc5_decode()
91 if (data->count == CHECK_RC5X_NBITS) in ir_rc5_decode()
92 data->state = STATE_CHECK_RC5X; in ir_rc5_decode()
94 data->state = STATE_BIT_START; in ir_rc5_decode()
101 data->is_rc5x = true; in ir_rc5_decode()
104 data->is_rc5x = false; in ir_rc5_decode()
105 data->state = STATE_BIT_START; in ir_rc5_decode()
112 if (data->is_rc5x && data->count == RC5X_NBITS) { in ir_rc5_decode()
115 if (!(dev->enabled_protocols & RC_PROTO_BIT_RC5X_20)) { in ir_rc5_decode()
116 data->state = STATE_INACTIVE; in ir_rc5_decode()
119 xdata = (data->bits & 0x0003F) >> 0; in ir_rc5_decode()
120 command = (data->bits & 0x00FC0) >> 6; in ir_rc5_decode()
121 system = (data->bits & 0x1F000) >> 12; in ir_rc5_decode()
122 toggle = (data->bits & 0x20000) ? 1 : 0; in ir_rc5_decode()
123 command += (data->bits & 0x40000) ? 0 : 0x40; in ir_rc5_decode()
127 } else if (!data->is_rc5x && data->count == RC5_NBITS) { in ir_rc5_decode()
130 if (!(dev->enabled_protocols & RC_PROTO_BIT_RC5)) { in ir_rc5_decode()
131 data->state = STATE_INACTIVE; in ir_rc5_decode()
134 command = (data->bits & 0x0003F) >> 0; in ir_rc5_decode()
135 system = (data->bits & 0x007C0) >> 6; in ir_rc5_decode()
136 toggle = (data->bits & 0x00800) ? 1 : 0; in ir_rc5_decode()
137 command += (data->bits & 0x01000) ? 0 : 0x40; in ir_rc5_decode()
141 } else if (!data->is_rc5x && data->count == RC5_SZ_NBITS) { in ir_rc5_decode()
144 if (!(dev->enabled_protocols & RC_PROTO_BIT_RC5_SZ)) { in ir_rc5_decode()
145 data->state = STATE_INACTIVE; in ir_rc5_decode()
148 command = (data->bits & 0x0003F) >> 0; in ir_rc5_decode()
149 system = (data->bits & 0x02FC0) >> 6; in ir_rc5_decode()
150 toggle = (data->bits & 0x01000) ? 1 : 0; in ir_rc5_decode()
157 dev_dbg(&dev->dev, "RC5(x/sz) scancode 0x%06x (p: %u, t: %u)\n", in ir_rc5_decode()
161 data->state = STATE_INACTIVE; in ir_rc5_decode()
166 dev_dbg(&dev->dev, "RC5(x/sz) decode failed at state %i count %d (%uus %s)\n", in ir_rc5_decode()
167 data->state, data->count, ev.duration, TO_STR(ev.pulse)); in ir_rc5_decode()
168 data->state = STATE_INACTIVE; in ir_rc5_decode()
169 return -EINVAL; in ir_rc5_decode()
197 * ir_rc5_encode() - Encode a scancode as a stream of raw events
205 * -ENOBUFS if there isn't enough space in the array to fit the
207 * -EINVAL if the scancode is ambiguous or invalid.
214 unsigned int data, xdata, command, commandx, system, pre_space_data; in ir_rc5_encode() local
216 /* Detect protocol and convert scancode to raw data */ in ir_rc5_encode()
222 /* encode data */ in ir_rc5_encode()
223 data = !commandx << 12 | system << 6 | command; in ir_rc5_encode()
227 RC5_NBITS - 1, data); in ir_rc5_encode()
237 /* encode data */ in ir_rc5_encode()
238 data = commandx << 18 | system << 12 | command << 6 | xdata; in ir_rc5_encode()
241 pre_space_data = data >> (RC5X_NBITS - CHECK_RC5X_NBITS); in ir_rc5_encode()
243 CHECK_RC5X_NBITS - 1, in ir_rc5_encode()
247 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc5_encode()
249 RC5X_NBITS - CHECK_RC5X_NBITS, in ir_rc5_encode()
250 data); in ir_rc5_encode()
254 /* RC5-SZ scancode is raw enough for Manchester as it is */ in ir_rc5_encode()
257 RC5_SZ_NBITS - 1, in ir_rc5_encode()
262 return -EINVAL; in ir_rc5_encode()
265 return e - events; in ir_rc5_encode()