Re: [PATCH] [media] rc-core support for Microsoft IR keyboard/mouse

2011-06-12 Thread Jarod Wilson
On Jun 11, 2011, at 9:38 AM, Mauro Carvalho Chehab wrote:

 Em 03-06-2011 18:28, Jarod Wilson escreveu:
 This is a custom IR protocol decoder, for the RC-6-ish protocol used by
 the Microsoft Remote Keyboard.
 
 http://www.amazon.com/Microsoft-Remote-Keyboard-Windows-ZV1-4/dp/B000AOAAN8
 
 Its a standard keyboard with embedded thumb stick mouse pointer and
 mouse buttons, along with a number of media keys. The media keys are
 standard RC-6, identical to the signals from the stock MCE remotes, and
 will be handled as such. The keyboard and mouse signals will be decoded
 and delivered to the system by an input device registered specifically
 by this driver.
 
 Successfully tested with an mceusb-driven receiver, but this should
 actually work with any raw IR rc-core receiver.
 
 This work is inspired by lirc_mod_mce:
 
 http://mod-mce.sourceforge.net/
 
 The documentation there and code aided in understanding and decoding the
 protocol, but the bulk of the code is actually borrowed more from the
 existing in-kernel decoders than anything. I did recycle the keyboard
 keycode table and a few defines from lirc_mod_mce though.
 
 Signed-off-by: Jarod Wilson ja...@redhat.com
 ---
 
 I did only a quick review, and everything looks fine for me. Just two 
 comments:
 
 +#if 0
 +/* Adding this reference means two input devices are associated with
 + * this rc-core device, which ir-keytable doesn't cope with yet */
 +idev-dev.parent = dev-dev;
 +#endif
 
 Well, it was never tested with such config ;)

D'oh, I meant to mention that #if 0...


 Feel free to fix rc-core.

It wasn't actually rc-core that complained, it was ir-keytable that spit out
a message about not being able to handle an rc device with multiple input
devices, but the fix may well require both userspace and kernelspace changes...


 +static unsigned char kbd_keycodes[256] = {
 +  0,   0,   0,   0,  30,  48,  46,  32,  18,  33,  34,  35,  23,  
 36,  37,  38,
 + 50,  49,  24,  25,  16,  19,  31,  20,  22,  47,  17,  45,  21,  
 44,   2,   3,
 +  4,   5,   6,   7,   8,   9,  10,  11,  28,   1,  14,  15,  57,  
 12,  13,  26,
 + 27,  43,  43,  39,  40,  41,  51,  52,  53,  58,  59,  60,  61,  
 62,  63,  64,
 + 65,  66,  67,  68,  87,  88,  99,  70, 119, 110, 102, 104, 111, 
 107, 109, 106,
 +105, 108, 103,  69,  98,  55,  74,  78,  96,  79,  80,  81,  75,  
 76,  77,  71,
 + 72,  73,  82,  83,  86, 127, 116, 117, 183, 184, 185, 186, 187, 
 188, 189, 190,
 +191, 192, 193, 194, 134, 138, 130, 132, 128, 129, 131, 137, 133, 
 135, 136, 113,
 +115, 114,   0,   0,   0, 121,   0,  89,  93, 124,  92,  94,  95,   
 0,   0,   0,
 +122, 123,  90,  91,  85,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 + 29,  42,  56, 125,  97,  54, 100, 126, 164, 166, 165, 163, 161, 
 115, 114, 113,
 +150, 158, 159, 128, 136, 177, 178, 176, 142, 152, 173, 140
 +};
 
 This table looks weird to me: too much magic numbers there. Shouldn't
 the above be replaced by KEY_* definitions?

Yeah, probably. The above is basically the same convention as hid_keyboard in
drivers/hid/hid-input.c, but that doesn't mean we can't strive to do better. ;)


 PS.: I would like to have one of those keyboards, in order to test some 
 things here,
 in special, for the xorg input/event proposal on my TODO list ;) Is it a 
 cheap device?
 I may try to buy one the next time I would travel to US.

Looks like Amazon has them listed for less than $40USD right now, but they're
becoming increasingly hard to find, as I believe they're discontinued. Don't
know if I've ever seen them in a brick-n-mortar store anywhere. I should really
get one for myself, I have to send this one back to the guy who loaned it to me.
I could just make it a double order and stash one on the shelf for ya.

-- 
Jarod Wilson
ja...@wilsonet.com



--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [media] rc-core support for Microsoft IR keyboard/mouse

2011-06-11 Thread Mauro Carvalho Chehab
Em 03-06-2011 18:28, Jarod Wilson escreveu:
 This is a custom IR protocol decoder, for the RC-6-ish protocol used by
 the Microsoft Remote Keyboard.
 
 http://www.amazon.com/Microsoft-Remote-Keyboard-Windows-ZV1-4/dp/B000AOAAN8
 
 Its a standard keyboard with embedded thumb stick mouse pointer and
 mouse buttons, along with a number of media keys. The media keys are
 standard RC-6, identical to the signals from the stock MCE remotes, and
 will be handled as such. The keyboard and mouse signals will be decoded
 and delivered to the system by an input device registered specifically
 by this driver.
 
 Successfully tested with an mceusb-driven receiver, but this should
 actually work with any raw IR rc-core receiver.
 
 This work is inspired by lirc_mod_mce:
 
 http://mod-mce.sourceforge.net/
 
 The documentation there and code aided in understanding and decoding the
 protocol, but the bulk of the code is actually borrowed more from the
 existing in-kernel decoders than anything. I did recycle the keyboard
 keycode table and a few defines from lirc_mod_mce though.
 
 Signed-off-by: Jarod Wilson ja...@redhat.com
 ---

I did only a quick review, and everything looks fine for me. Just two comments:

 +#if 0
 + /* Adding this reference means two input devices are associated with
 +  * this rc-core device, which ir-keytable doesn't cope with yet */
 + idev-dev.parent = dev-dev;
 +#endif

Well, it was never tested with such config ;) Feel free to fix rc-core.

 +static unsigned char kbd_keycodes[256] = {
 +  0,   0,   0,   0,  30,  48,  46,  32,  18,  33,  34,  35,  23,  
 36,  37,  38,
 + 50,  49,  24,  25,  16,  19,  31,  20,  22,  47,  17,  45,  21,  
 44,   2,   3,
 +  4,   5,   6,   7,   8,   9,  10,  11,  28,   1,  14,  15,  57,  
 12,  13,  26,
 + 27,  43,  43,  39,  40,  41,  51,  52,  53,  58,  59,  60,  61,  
 62,  63,  64,
 + 65,  66,  67,  68,  87,  88,  99,  70, 119, 110, 102, 104, 111, 
 107, 109, 106,
 +105, 108, 103,  69,  98,  55,  74,  78,  96,  79,  80,  81,  75,  
 76,  77,  71,
 + 72,  73,  82,  83,  86, 127, 116, 117, 183, 184, 185, 186, 187, 
 188, 189, 190,
 +191, 192, 193, 194, 134, 138, 130, 132, 128, 129, 131, 137, 133, 
 135, 136, 113,
 +115, 114,   0,   0,   0, 121,   0,  89,  93, 124,  92,  94,  95,   
 0,   0,   0,
 +122, 123,  90,  91,  85,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 +  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   
 0,   0,   0,
 + 29,  42,  56, 125,  97,  54, 100, 126, 164, 166, 165, 163, 161, 
 115, 114, 113,
 +150, 158, 159, 128, 136, 177, 178, 176, 142, 152, 173, 140
 +};

This table looks weird to me: too much magic numbers there. Shouldn't
the above be replaced by KEY_* definitions?

Cheers,
Mauro

-

PS.: I would like to have one of those keyboards, in order to test some things 
here,
in special, for the xorg input/event proposal on my TODO list ;) Is it a cheap 
device?
I may try to buy one the next time I would travel to US.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [media] rc-core support for Microsoft IR keyboard/mouse

2011-06-04 Thread Jarod Wilson
On Jun 3, 2011, at 5:28 PM, Jarod Wilson wrote:

 This is a custom IR protocol decoder, for the RC-6-ish protocol used by
 the Microsoft Remote Keyboard.
 
 http://www.amazon.com/Microsoft-Remote-Keyboard-Windows-ZV1-4/dp/B000AOAAN8
 
 Its a standard keyboard with embedded thumb stick mouse pointer and
 mouse buttons, along with a number of media keys. The media keys are
 standard RC-6, identical to the signals from the stock MCE remotes, and
 will be handled as such. The keyboard and mouse signals will be decoded
 and delivered to the system by an input device registered specifically
 by this driver.
 
 Successfully tested with an mceusb-driven receiver, but this should
 actually work with any raw IR rc-core receiver.
 
 This work is inspired by lirc_mod_mce:
 
 http://mod-mce.sourceforge.net/
 
 The documentation there and code aided in understanding and decoding the
 protocol, but the bulk of the code is actually borrowed more from the
 existing in-kernel decoders than anything. I did recycle the keyboard
 keycode table and a few defines from lirc_mod_mce though.

Nb: this should more or less be considered as an RFC.

One thing I already know I need/want to add is a timer callback to make
sure we don't get stuck keys due to missing a release event signal.

The main area of contention though is over how the keyboard/mouse device is
set up. Currently, if you have three raw rc-core IR receivers in your system,
you get three separate keyboard/mouse event devices, stored inside
rc_dev-raw-mce_kbd-idev. I *think* this is the right way to do this, but
one could argue that the decoder should just have a single input_dev within
the decoder itself, which is used to feed along signals from any raw IR device.

The other question is whether or not this module should be loaded by default
when rc-core is initialized. The current implementation means this is loaded,
and input devices are set up for every raw IR device, and I doubt the vast
majority of people with raw IR receivers actually have this keyboard.

-- 
Jarod Wilson
ja...@wilsonet.com



--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [media] rc-core support for Microsoft IR keyboard/mouse

2011-06-03 Thread Jarod Wilson
This is a custom IR protocol decoder, for the RC-6-ish protocol used by
the Microsoft Remote Keyboard.

http://www.amazon.com/Microsoft-Remote-Keyboard-Windows-ZV1-4/dp/B000AOAAN8

Its a standard keyboard with embedded thumb stick mouse pointer and
mouse buttons, along with a number of media keys. The media keys are
standard RC-6, identical to the signals from the stock MCE remotes, and
will be handled as such. The keyboard and mouse signals will be decoded
and delivered to the system by an input device registered specifically
by this driver.

Successfully tested with an mceusb-driven receiver, but this should
actually work with any raw IR rc-core receiver.

This work is inspired by lirc_mod_mce:

http://mod-mce.sourceforge.net/

The documentation there and code aided in understanding and decoding the
protocol, but the bulk of the code is actually borrowed more from the
existing in-kernel decoders than anything. I did recycle the keyboard
keycode table and a few defines from lirc_mod_mce though.

Signed-off-by: Jarod Wilson ja...@redhat.com
---
 drivers/media/rc/Kconfig  |   11 +
 drivers/media/rc/Makefile |1 +
 drivers/media/rc/ir-mce_kbd-decoder.c |  383 +
 drivers/media/rc/ir-raw.c |1 +
 drivers/media/rc/rc-core-priv.h   |   17 ++
 drivers/media/rc/rc-main.c|1 +
 include/media/rc-map.h|3 +-
 7 files changed, 416 insertions(+), 1 deletions(-)
 create mode 100644 drivers/media/rc/ir-mce_kbd-decoder.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 7d4bbc2..899f783 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -87,6 +87,17 @@ config IR_RC5_SZ_DECODER
   uses an IR protocol that is almost standard RC-5, but not quite,
   as it uses an additional bit).
 
+config IR_MCE_KBD_DECODER
+   tristate Enable IR raw decoder for the MCE keyboard/mouse protocol
+   depends on RC_CORE
+   select BITREVERSE
+   default y
+
+   ---help---
+  Enable this option if you have a Microsoft Remote Keyboard for
+  Windows Media Center Edition, which you would like to use with
+  a raw IR receiver in your system.
+
 config IR_LIRC_CODEC
tristate Enable IR to LIRC bridge
depends on RC_CORE
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 52830e5..f224db0 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
 obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o
 obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
 obj-$(CONFIG_IR_RC5_SZ_DECODER) += ir-rc5-sz-decoder.o
+obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
 obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
 
 # stand-alone IR receivers/transmitters
diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
new file mode 100644
index 000..98d3bf5
--- /dev/null
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -0,0 +1,383 @@
+/* ir-mce_kbd-decoder.c - A decoder for the RC6-ish keyboard/mouse IR protocol
+ * used by the Microsoft Remote Keyboard for Windows Media Center Edition
+ *
+ * Copyright (C) 2011 by Jarod Wilson ja...@redhat.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include rc-core-priv.h
+
+/*
+ * This decoder currently supports:
+ * - RC6-like 29-bit IR signals used for mouse movement and buttons
+ * - RC6-like 32-bit IR signals used for standard keyboard keys
+ *
+ * The media keys on the keyboard send RC-6 signals that are inditinguishable
+ * from the keys of the same name on the stock MCE remote, and will be handled
+ * by the standard RC-6 decoder, and be made available to the system via the
+ * input device for the remote, rather than the keyboard/mouse one.
+ */
+
+#define MCE_KBD_UNIT   33  /* ns */
+#define MCE_KBD_HEADER_NBITS   5
+#define MCE_KBD_MOUSE_NBITS29
+#define MCE_KBD_KEYBOARD_NBITS 32
+#define MCE_KBD_PREFIX_PULSE   (8 * MCE_KBD_UNIT)
+#define MCE_KBD_PREFIX_SPACE   (1 * MCE_KBD_UNIT)
+#define MCE_KBD_MAX_LEN(3 * MCE_KBD_UNIT)
+#define MCE_KBD_BIT_START  (1 * MCE_KBD_UNIT)
+#define MCE_KBD_BIT_END(1 * MCE_KBD_UNIT)
+#define MCE_KBD_BIT_0  (1 * MCE_KBD_UNIT)
+#define MCE_KBD_BIT_SET(2 * MCE_KBD_UNIT)
+#define MCE_KBD_MODE_MASK  0xf /* for the header bits */
+#define MCE_KBD_HEADER 0x4
+#define MCE_MOUSE_HEADER   0x1
+#define