From caec098477d228d44ae2266ee78a37bed070441a Mon Sep 17 00:00:00 2001 From: James Hogan Date: Fri, 14 Mar 2014 20:04:12 -0300 Subject: [media] rc: rc-ir-raw: Add pulse-distance modulation helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add IR encoding helper for pulse-distance modulation as used by the NEC protocol. Signed-off-by: James Hogan Signed-off-by: Sean Young Cc: Antti Seppälä Cc: David Härdeman Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-ir-raw.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'drivers/media/rc/rc-ir-raw.c') diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c index 85ac5070376c..58039e6666af 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -323,6 +323,65 @@ nobufs: } EXPORT_SYMBOL(ir_raw_gen_manchester); +/** + * ir_raw_gen_pd() - Encode data to raw events with pulse-distance modulation. + * @ev: Pointer to pointer to next free event. *@ev is incremented for + * each raw event filled. + * @max: Maximum number of raw events to fill. + * @timings: Pulse distance modulation timings. + * @n: Number of bits of data. + * @data: Data bits to encode. + * + * Encodes the @n least significant bits of @data using pulse-distance + * modulation with the timing characteristics described by @timings, writing up + * to @max raw IR events using the *@ev pointer. + * + * Returns: 0 on success. + * -ENOBUFS if there isn't enough space in the array to fit the + * full encoded data. In this case all @max events will have been + * written. + */ +int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int max, + const struct ir_raw_timings_pd *timings, + unsigned int n, u64 data) +{ + int i; + int ret; + unsigned int space; + + if (timings->header_pulse) { + ret = ir_raw_gen_pulse_space(ev, &max, timings->header_pulse, + timings->header_space); + if (ret) + return ret; + } + + if (timings->msb_first) { + for (i = n - 1; i >= 0; --i) { + space = timings->bit_space[(data >> i) & 1]; + ret = ir_raw_gen_pulse_space(ev, &max, + timings->bit_pulse, + space); + if (ret) + return ret; + } + } else { + for (i = 0; i < n; ++i, data >>= 1) { + space = timings->bit_space[data & 1]; + ret = ir_raw_gen_pulse_space(ev, &max, + timings->bit_pulse, + space); + if (ret) + return ret; + } + } + + ret = ir_raw_gen_pulse_space(ev, &max, timings->trailer_pulse, + timings->trailer_space); + return ret; +} +EXPORT_SYMBOL(ir_raw_gen_pd); + /** * ir_raw_encode_scancode() - Encode a scancode as raw events * -- cgit v1.2.3