Lines Matching +full:toggle +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* ir-rc6-decoder.c - A decoder for the RC6 IR protocol
7 #include "rc-core-priv.h"
12 * RC6-0-16 (standard toggle bit in header)
13 * RC6-6A-20 (no toggle bit)
14 * RC6-6A-24 (no toggle bit)
15 * RC6-6A-32 (MCE version with toggle bit in body)
19 #define RC6_HEADER_NBITS 4 /* not including toggle bit */
33 #define RC6_6A_LCC_MASK 0xffff0000 /* RC6-6A-32 long customer code mask */
36 #define RC6_6A_KATHREIN_CC 0x80460000 /* Kathrein RCU-676 customer code */
61 switch (data->header & RC6_MODE_MASK) { in rc6_mode()
65 if (!data->toggle) in rc6_mode()
74 * ir_rc6_decode() - Decode one RC6 pulse or space
78 * This function returns -EINVAL if the pulse violates the state machine
82 struct rc6_dec *data = &dev->raw->rc6; in ir_rc6_decode()
84 u8 toggle; in ir_rc6_decode() local
89 data->state = STATE_INACTIVE; in ir_rc6_decode()
97 dev_dbg(&dev->dev, "RC6 decode started at state %i (%uus %s)\n", in ir_rc6_decode()
98 data->state, ev.duration, TO_STR(ev.pulse)); in ir_rc6_decode()
103 switch (data->state) { in ir_rc6_decode()
115 data->state = STATE_PREFIX_SPACE; in ir_rc6_decode()
116 data->count = 0; in ir_rc6_decode()
126 data->state = STATE_HEADER_BIT_START; in ir_rc6_decode()
127 data->header = 0; in ir_rc6_decode()
134 data->header <<= 1; in ir_rc6_decode()
136 data->header |= 1; in ir_rc6_decode()
137 data->count++; in ir_rc6_decode()
138 data->state = STATE_HEADER_BIT_END; in ir_rc6_decode()
142 if (data->count == RC6_HEADER_NBITS) in ir_rc6_decode()
143 data->state = STATE_TOGGLE_START; in ir_rc6_decode()
145 data->state = STATE_HEADER_BIT_START; in ir_rc6_decode()
154 data->toggle = ev.pulse; in ir_rc6_decode()
155 data->state = STATE_TOGGLE_END; in ir_rc6_decode()
159 if (!(data->header & RC6_STARTBIT_MASK)) { in ir_rc6_decode()
160 dev_dbg(&dev->dev, "RC6 invalid start bit\n"); in ir_rc6_decode()
164 data->state = STATE_BODY_BIT_START; in ir_rc6_decode()
166 data->count = 0; in ir_rc6_decode()
167 data->body = 0; in ir_rc6_decode()
171 data->wanted_bits = RC6_0_NBITS; in ir_rc6_decode()
174 data->wanted_bits = RC6_6A_NBITS; in ir_rc6_decode()
177 dev_dbg(&dev->dev, "RC6 unknown mode\n"); in ir_rc6_decode()
184 /* Discard LSB's that won't fit in data->body */ in ir_rc6_decode()
185 if (data->count++ < CHAR_BIT * sizeof data->body) { in ir_rc6_decode()
186 data->body <<= 1; in ir_rc6_decode()
188 data->body |= 1; in ir_rc6_decode()
190 data->state = STATE_BODY_BIT_END; in ir_rc6_decode()
194 data->state = STATE_FINISHED; in ir_rc6_decode()
200 if (data->count == data->wanted_bits) in ir_rc6_decode()
201 data->state = STATE_FINISHED; in ir_rc6_decode()
203 data->state = STATE_BODY_BIT_START; in ir_rc6_decode()
214 scancode = data->body; in ir_rc6_decode()
215 toggle = data->toggle; in ir_rc6_decode()
217 dev_dbg(&dev->dev, "RC6(0) scancode 0x%04x (toggle: %u)\n", in ir_rc6_decode()
218 scancode, toggle); in ir_rc6_decode()
222 if (data->count > CHAR_BIT * sizeof data->body) { in ir_rc6_decode()
223 dev_dbg(&dev->dev, "RC6 too many (%u) data bits\n", in ir_rc6_decode()
224 data->count); in ir_rc6_decode()
228 scancode = data->body; in ir_rc6_decode()
229 switch (data->count) { in ir_rc6_decode()
232 toggle = 0; in ir_rc6_decode()
236 toggle = 0; in ir_rc6_decode()
244 toggle = !!(scancode & RC6_6A_MCE_TOGGLE_MASK); in ir_rc6_decode()
249 toggle = 0; in ir_rc6_decode()
254 dev_dbg(&dev->dev, "RC6(6A) unsupported length\n"); in ir_rc6_decode()
258 dev_dbg(&dev->dev, "RC6(6A) proto 0x%04x, scancode 0x%08x (toggle: %u)\n", in ir_rc6_decode()
259 protocol, scancode, toggle); in ir_rc6_decode()
262 dev_dbg(&dev->dev, "RC6 unknown mode\n"); in ir_rc6_decode()
266 rc_keydown(dev, protocol, scancode, toggle); in ir_rc6_decode()
267 data->state = STATE_INACTIVE; in ir_rc6_decode()
272 dev_dbg(&dev->dev, "RC6 decode failed at state %i (%uus %s)\n", in ir_rc6_decode()
273 data->state, ev.duration, TO_STR(ev.pulse)); in ir_rc6_decode()
274 data->state = STATE_INACTIVE; in ir_rc6_decode()
275 return -EINVAL; in ir_rc6_decode()
297 * ir_rc6_encode() - Encode a scancode as a stream of raw events
305 * -ENOBUFS if there isn't enough space in the array to fit the
307 * -EINVAL if the scancode is ambiguous or invalid.
316 /* Modulate the header (Start Bit & Mode-0) */ in ir_rc6_encode()
317 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
324 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
330 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
351 return -EINVAL; in ir_rc6_encode()
354 /* Modulate the header (Start Bit & Header-version 6 */ in ir_rc6_encode()
355 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
362 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
368 ret = ir_raw_gen_manchester(&e, max - (e - events), in ir_rc6_encode()
376 return e - events; in ir_rc6_encode()