summaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/rc-ir-raw.c
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2016-12-06 18:33:57 -0200
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-01-30 13:54:54 -0200
commit103293be9d23de8347fc2e5aecd06f8962d18154 (patch)
treeaef55f3c9d26081cc01cbf33f518c9d52cd97600 /drivers/media/rc/rc-ir-raw.c
parentd35afc5fe0971bd1d40c824bd3c7587aeda823b2 (diff)
downloadlinux-103293be9d23de8347fc2e5aecd06f8962d18154.tar.bz2
[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 <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/rc/rc-ir-raw.c')
-rw-r--r--drivers/media/rc/rc-ir-raw.c64
1 files changed, 64 insertions, 0 deletions
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
@@ -383,6 +383,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
*
* @protocol: protocol