linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Chaogui Zhang <czhang@marywood.edu>
Cc: linux-input@vger.kernel.org
Subject: Re: [PATCH] TiVo USB IR Dongle support
Date: Mon, 14 Dec 2009 14:28:43 -0800	[thread overview]
Message-ID: <20091214222843.GE2373@core.coreip.homeip.net> (raw)
In-Reply-To: <20091214220059.GA16776@drzhang.net>

On Mon, Dec 14, 2009 at 05:00:59PM -0500, Chaogui Zhang wrote:
> On Sat, Dec 12, 2009 at 03:32:59PM -0800, Dmitry Torokhov wrote:
> > Hi Chaogui,
> > 
> > On Sat, Dec 12, 2009 at 02:01:43PM -0500, Chaogui Zhang wrote:
> > > +/* Check the inital AGC burst and space value to match the NEC protocol */
> > > +static inline int is_nec(int leadpulse, int leadspace)
> > > +{
> > > +	/* leadpulse should be 9 ms = 9000 us and leadspace should be
> > > +	 * 4.5 ms = 4500 us. We allow +/- 200 microseconds for both.
> > > +	 * Time is measured in units of 50 microseconds.
> > > +	 * 170 == 8800/50, 184 == 9200/50,
> > > +	 * 86 == 4300/50, 94 == 4700/50.
> > > +	 */
> > > +	return (leadpulse >= 170 && leadpulse <= 184) 
> > > +	    && (leadspace >= 86 && leadspace <= 94);
> > 
> > That surely should be '||'. I prefer it at the end too.
> 
> I think it should be && as the protocol specifies both the 9ms AGC burst
> and the 4.5ms space following it.
> 

Ah, yes, I misread the statement and did not see that it involved 2
different variables: leadpulse and leadspace.

> +	{ KE_KEY, 0x28, { KEY_1 } },
> +	{ KE_KEY, 0x29, { KEY_2 } },
> +	{ KE_KEY, 0x2a, { KEY_3 } },
> +	{ KE_KEY, 0x2b, { KEY_4 } },
> +	{ KE_KEY, 0x2c, { KEY_5 } },
> +	{ KE_KEY, 0x2d, { KEY_6 } },
> +	{ KE_KEY, 0x2e, { KEY_7 } },
> +	{ KE_KEY, 0x2f, { KEY_8 } },
> +	{ KE_KEY, 0x30, { KEY_9 } },
> +	{ KE_KEY, 0x31, { KEY_0 } },

Hm, I forgot to mention this in my previous mail - I am trying to move
RC and phones to KEY_NUMERIC_X keycodes which are supposed to be
independent on state of shift and NumLock. I will change it locally -
and if users want old definitions - why, EVIOSKEYCODE now works ;)

> +	{ KE_KEY, 0x32, { KEY_CLEAR } },
> +	{ KE_KEY, 0x33, { KEY_ENTER } },
> +	{ KE_KEY, 0x34, { KEY_VIDEO } },	/* TV Input */
> +	{ KE_KEY, 0x36, { KEY_EPG } },		/* Guide */
> +	{ KE_KEY, 0x44, { KEY_ZOOM } },		/* Aspect */
> +	{ KE_KEY, 0x48, { KEY_STOP } },
> +	{ KE_KEY, 0x4a, { KEY_DVD } },		/* DVD Menu */
> +	{ KE_KEY, 0x5f, { KEY_CYCLEWINDOWS } },	/* Window */
> +	{ KE_END, 0}
> +};
> +
> +/* table of devices that work with this driver */
> +static struct usb_device_id tivoir_table[] = {
> +	{USB_DEVICE(USB_TIVOIR_VENDOR_ID, USB_TIVOIR_PRODUCT_ID)},
> +	{}			/* Terminating entry */
> +};
> +
> +/* Structure to hold all of our driver specific stuff */
> +struct usb_tivoir {
> +	char name[128];
> +	char phys[64];
> +	struct usb_device *udev;
> +	struct input_dev *input;
> +	struct usb_interface *interface;
> +	struct usb_endpoint_descriptor *in_endpoint;
> +	struct urb *irq_urb;
> +	dma_addr_t in_dma;
> +	unsigned char *in_buffer;
> +
> +	/* variables used to parse messages from remote. */
> +	int stage;
> +	int pulse;
> +	int space;
> +	u32 code;	/* 32 bit raw code from the remote */
> +	int repeat;
> +	int bitcount;
> +};
> +
> +static struct usb_driver tivoir_driver;
> +
> +/*
> + * Debug routine that prints out what we've received from the remote.
> + */
> +static void tivoir_print_packet(struct usb_tivoir *remote)
> +{
> +	u8 codes[4 * TIVOIR_RECV_SIZE];
> +	int i, length;
> +
> +	/* The lower 5 bits of the first byte of each packet indicates the size
> +	 * of the transferred buffer, not including the first byte itself.
> +	 */
> +
> +	length = (remote->in_buffer[0]) & 0x1f;
> +	for (i = 0; i <= length; i++)
> +		snprintf(codes + i * 3, 4, "%02x ", remote->in_buffer[i]);
> +
> +	/* 0x80 at the end of a regular packet or in a separate packet
> +	   indicates key release */
> +
> +	if (i < TIVOIR_RECV_SIZE && remote->in_buffer[i] == 0x80)
> +		snprintf(codes + i * 3, 4, "%02x ", remote->in_buffer[i]);
> +
> +	dev_printk(KERN_DEBUG, &remote->udev->dev, "%s: %s\n", __func__, codes);
> +}
> +
> +static inline u16 code_address(u32 code)
> +{
> +	/* Higher 16 bits of the code is the remote address */
> +	return code >> 16;
> +}
> +
> +static inline u8 code_command(u32 code)
> +{
> +	/* Lower 8 bits of the code is the command */
> +	return code & 0xff;
> +}
> +
> +static void tivoir_report_key(struct usb_tivoir *remote)
> +{
> +	struct input_dev *input = remote->input;
> +	struct key_entry *key;
> +
> +
> +	dev_dbg(&remote->udev->dev, "%s: address = 0x%04x, command = 0x%02x\n",
> +		__func__, remote->code >> 16, remote->code & 0xff);
> +
> +	if (code_address(remote->code) == TIVO_REMOTE_ADDR) {
> +		key = sparse_keymap_entry_from_scancode(input,
> +						code_command(remote->code));
> +		if (!key) {	/* invalid code, do nothing */
> +			remote->code = 0;
> +			return;
> +		}
> +		sparse_keymap_report_entry(input, key, 1, !remote->repeat);

Should not this be

		sparse_keymap_report_entry(input, key, remote->repeat, false);

?

In fact remote->repeat  is more like "button down", not necessarily
repeat, right? I also do not see the readon for keeping it in the device
structure, you can simply pass it in tivoir_report_key(), can't you?

Thanks.

-- 
Dmitry

  reply	other threads:[~2009-12-14 22:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-06 21:45 [PATCH] TiVo USB IR Dongle support Chaogui Zhang
2009-12-12 19:01 ` Chaogui Zhang
2009-12-12 23:32   ` Dmitry Torokhov
2009-12-14 22:00     ` Chaogui Zhang
2009-12-14 22:28       ` Dmitry Torokhov [this message]
2009-12-16  0:53         ` Chaogui Zhang
2010-01-13  7:53           ` Dmitry Torokhov
2010-01-13 14:25             ` Jarod Wilson
2010-01-14  1:22             ` Chaogui Zhang
2010-01-14  1:28               ` Chaogui Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091214222843.GE2373@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=czhang@marywood.edu \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).