diff options
author | James Hogan <james@albanarts.com> | 2014-03-14 20:04:14 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-01-30 13:52:28 -0200 |
commit | 141cfb1432f5c8e120d49229be52a32c8705afba (patch) | |
tree | 57c18d9dc7133ff42f3790b2bafc6943a2b72fe5 /drivers/media/rc | |
parent | 9d974e49339dc0ad9a6fbd7438a0887d7a445e29 (diff) |
[media] rc: ir-nec-decoder: Add encode capability
Add the capability to encode NEC scancodes as raw events. The
scancode_to_raw is pretty much taken from the img-ir NEC filter()
callback, and modulation uses the pulse distance helper added in a
previous commit.
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')
-rw-r--r-- | drivers/media/rc/ir-nec-decoder.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c index a5d418e33eca..3ce850314dca 100644 --- a/drivers/media/rc/ir-nec-decoder.c +++ b/drivers/media/rc/ir-nec-decoder.c @@ -204,9 +204,90 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev) return -EINVAL; } +/** + * ir_nec_scancode_to_raw() - encode an NEC scancode ready for modulation. + * @protocol: specific protocol to use + * @scancode: a single NEC scancode. + * @raw: raw data to be modulated. + */ +static u32 ir_nec_scancode_to_raw(enum rc_type protocol, u32 scancode) +{ + unsigned int addr, addr_inv, data, data_inv; + + data = scancode & 0xff; + + if (protocol == RC_TYPE_NEC32) { + /* 32-bit NEC (used by Apple and TiVo remotes) */ + /* scan encoding: aaAAddDD */ + addr_inv = (scancode >> 24) & 0xff; + addr = (scancode >> 16) & 0xff; + data_inv = (scancode >> 8) & 0xff; + } else if (protocol == RC_TYPE_NECX) { + /* Extended NEC */ + /* scan encoding AAaaDD */ + addr = (scancode >> 16) & 0xff; + addr_inv = (scancode >> 8) & 0xff; + data_inv = data ^ 0xff; + } else { + /* Normal NEC */ + /* scan encoding: AADD */ + addr = (scancode >> 8) & 0xff; + addr_inv = addr ^ 0xff; + data_inv = data ^ 0xff; + } + + /* raw encoding: ddDDaaAA */ + return data_inv << 24 | + data << 16 | + addr_inv << 8 | + addr; +} + +static const struct ir_raw_timings_pd ir_nec_timings = { + .header_pulse = NEC_HEADER_PULSE, + .header_space = NEC_HEADER_SPACE, + .bit_pulse = NEC_BIT_PULSE, + .bit_space[0] = NEC_BIT_0_SPACE, + .bit_space[1] = NEC_BIT_1_SPACE, + .trailer_pulse = NEC_TRAILER_PULSE, + .trailer_space = NEC_TRAILER_SPACE, + .msb_first = 0, +}; + +/** + * ir_nec_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_nec_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; + + /* Convert a NEC scancode to raw NEC data */ + raw = ir_nec_scancode_to_raw(protocol, scancode); + + /* Modulate the raw data using a pulse distance modulation */ + ret = ir_raw_gen_pd(&e, max, &ir_nec_timings, NEC_NBITS, raw); + if (ret < 0) + return ret; + + return e - events; +} + static struct ir_raw_handler nec_handler = { .protocols = RC_BIT_NEC | RC_BIT_NECX | RC_BIT_NEC32, .decode = ir_nec_decode, + .encode = ir_nec_encode, }; static int __init ir_nec_decode_init(void) |