diff options
author | Sean Young <sean@mess.org> | 2016-12-06 21:11:30 +0100 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-01-30 16:53:57 +0100 |
commit | d35afc5fe0971bd1d40c824bd3c7587aeda823b2 (patch) | |
tree | 46aa0257daf0281acf0297d4d88a3d45c6d2fb0a /drivers/media/rc/ir-sharp-decoder.c | |
parent | [media] rc: ir-sanyo-decoder: Add encode capability (diff) | |
download | linux-d35afc5fe0971bd1d40c824bd3c7587aeda823b2.tar.xz linux-d35afc5fe0971bd1d40c824bd3c7587aeda823b2.zip |
[media] rc: ir-sharp-decoder: Add encode capability
Add the capability to encode Sharp scancodes as raw events.
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/rc/ir-sharp-decoder.c')
-rw-r--r-- | drivers/media/rc/ir-sharp-decoder.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/drivers/media/rc/ir-sharp-decoder.c b/drivers/media/rc/ir-sharp-decoder.c index 317677f06f2c..b47e89e2c1bd 100644 --- a/drivers/media/rc/ir-sharp-decoder.c +++ b/drivers/media/rc/ir-sharp-decoder.c @@ -173,9 +173,59 @@ static int ir_sharp_decode(struct rc_dev *dev, struct ir_raw_event ev) return -EINVAL; } +static const struct ir_raw_timings_pd ir_sharp_timings = { + .header_pulse = 0, + .header_space = 0, + .bit_pulse = SHARP_BIT_PULSE, + .bit_space[0] = SHARP_BIT_0_PERIOD, + .bit_space[1] = SHARP_BIT_1_PERIOD, + .trailer_pulse = SHARP_BIT_PULSE, + .trailer_space = SHARP_ECHO_SPACE, + .msb_first = 1, +}; + +/** + * ir_sharp_encode() - Encode a scancode as a stream of raw events + * + * @protocol: protocol to encode + * @scancode: scancode to encode + * @events: array of raw ir events to write into + * @max: maximum size of @events + * + * Returns: The number of events written. + * -ENOBUFS if there isn't enough space in the array to fit the + * encoding. In this case all @max events will have been written. + */ +static int ir_sharp_encode(enum rc_type protocol, u32 scancode, + struct ir_raw_event *events, unsigned int max) +{ + struct ir_raw_event *e = events; + int ret; + u32 raw; + + raw = (((bitrev8(scancode >> 8) >> 3) << 8) & 0x1f00) | + bitrev8(scancode); + ret = ir_raw_gen_pd(&e, max, &ir_sharp_timings, SHARP_NBITS, + (raw << 2) | 2); + if (ret < 0) + return ret; + + max -= ret; + + raw = (((bitrev8(scancode >> 8) >> 3) << 8) & 0x1f00) | + bitrev8(~scancode); + ret = ir_raw_gen_pd(&e, max, &ir_sharp_timings, SHARP_NBITS, + (raw << 2) | 1); + if (ret < 0) + return ret; + + return e - events; +} + static struct ir_raw_handler sharp_handler = { .protocols = RC_BIT_SHARP, .decode = ir_sharp_decode, + .encode = ir_sharp_encode, }; static int __init ir_sharp_decode_init(void) |