summaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/rc-ir-raw.c
diff options
context:
space:
mode:
authorJames Hogan <james@albanarts.com>2014-03-15 00:04:12 +0100
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2017-01-30 16:50:05 +0100
commitcaec098477d228d44ae2266ee78a37bed070441a (patch)
tree829045d0cd56c392845df98b650b30b0d751d2ca /drivers/media/rc/rc-ir-raw.c
parent[media] rc: rc-ir-raw: Add Manchester encoder (phase encoder) helper (diff)
downloadlinux-caec098477d228d44ae2266ee78a37bed070441a.tar.xz
linux-caec098477d228d44ae2266ee78a37bed070441a.zip
[media] rc: rc-ir-raw: Add pulse-distance modulation helper
Add IR encoding helper for pulse-distance modulation as used by the NEC protocol. Signed-off-by: James Hogan <james@albanarts.com> Signed-off-by: Sean Young <sean@mess.org> Cc: Antti Seppälä <a.seppala@gmail.com> Cc: David Härdeman <david@hardeman.nu> 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.c59
1 files changed, 59 insertions, 0 deletions
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
@@ -324,6 +324,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
*
* @protocol: protocol