From 103293be9d23de8347fc2e5aecd06f8962d18154 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 6 Dec 2016 18:33:57 -0200 Subject: [media] rc: ir-sony-decoder: Add encode capability Add the capability to encode Sony scancodes as raw events. Sony uses pulse length rather than pulse distance. Signed-off-by: Sean Young Signed-off-by: Mauro Carvalho Chehab --- drivers/media/rc/rc-ir-raw.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 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 58039e6666af..4cad5c4cf941 100644 --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -382,6 +382,70 @@ int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int max, } EXPORT_SYMBOL(ir_raw_gen_pd); +/** + * ir_raw_gen_pl() - Encode data to raw events with pulse-length 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 space-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_pl(struct ir_raw_event **ev, unsigned int max, + const struct ir_raw_timings_pl *timings, + unsigned int n, u64 data) +{ + int i; + int ret = -ENOBUFS; + unsigned int pulse; + + if (!max--) + return ret; + + init_ir_raw_event_duration((*ev)++, 1, timings->header_pulse); + + if (timings->msb_first) { + for (i = n - 1; i >= 0; --i) { + if (!max--) + return ret; + init_ir_raw_event_duration((*ev)++, 0, + timings->bit_space); + if (!max--) + return ret; + pulse = timings->bit_pulse[(data >> i) & 1]; + init_ir_raw_event_duration((*ev)++, 1, pulse); + } + } else { + for (i = 0; i < n; ++i, data >>= 1) { + if (!max--) + return ret; + init_ir_raw_event_duration((*ev)++, 0, + timings->bit_space); + if (!max--) + return ret; + pulse = timings->bit_pulse[data & 1]; + init_ir_raw_event_duration((*ev)++, 1, pulse); + } + } + + if (!max--) + return ret; + + init_ir_raw_event_duration((*ev)++, 0, timings->trailer_space); + + return 0; +} +EXPORT_SYMBOL(ir_raw_gen_pl); + /** * ir_raw_encode_scancode() - Encode a scancode as raw events * -- cgit v1.2.3