From: Grant Likely <grant.likely@secretlab.ca>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org
Subject: Re: [RFC PATCH] input: Add wiichuck driver
Date: Mon, 16 May 2011 12:31:24 -0600 [thread overview]
Message-ID: <20110516183124.GA4875@ponder.secretlab.ca> (raw)
In-Reply-To: <20110516164427.GA21232@core.coreip.homeip.net>
On Mon, May 16, 2011 at 09:44:27AM -0700, Dmitry Torokhov wrote:
> Hi Grant,
>
> On Thu, May 12, 2011 at 06:29:44AM +0200, Grant Likely wrote:
> > This patch adds a driver for the Nintendo Nunchuck (wiimote accessory)
> > attached to an i2c bus via something like a wiichuck adapter board
> > from Sparkfun.
> >
> > Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> > ---
> >
> > This is RFC because the driver doesn't completely work yet. The
> > joystick and buttons work fine. There is a bug with the accelerometer
> > reporting though (nothing gets reported), and I'm not even sure I'm
> > using the right input type for reporting accelerometer values.
>
> Looks quite reasonable and I think that ABS_Rx is reasonable events for
> accelerometer in this particular case.
>
> A few more comments below.
Hi Dmitry, thanks for the review. Replies below.
>
> > Comments welcome.
> >
> > drivers/input/joystick/Kconfig | 8 +
> > drivers/input/joystick/Makefile | 1
> > drivers/input/joystick/wiichuck.c | 225 +++++++++++++++++++++++++++++++++++++
> > 3 files changed, 234 insertions(+), 0 deletions(-)
> > create mode 100644 drivers/input/joystick/wiichuck.c
> >
> > diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
> > index 56eb471..79f18db 100644
> > --- a/drivers/input/joystick/Kconfig
> > +++ b/drivers/input/joystick/Kconfig
> > @@ -193,6 +193,14 @@ config JOYSTICK_TWIDJOY
> > To compile this driver as a module, choose M here: the
> > module will be called twidjoy.
> >
> > +config JOYSTICK_WIICHUCK
> > + tristate "Nintendo Nunchuck on i2c bus"
> > + depends on I2C
> > + select INPUT_POLLDEV
> > + help
> > + Say Y here if you have a Nintendo Nunchuck directly attached to
> > + the machine's i2c bus.
> > +
>
> To compile this driver as a module, ...
That ends up being pretty useless boilerplate. I've stopped adding
that line to any of the Kconfig text I maintain.
> > +static void wiichuck_poll(struct input_polled_dev *poll_dev)
> > +{
> > + struct wiichuck_device *wiichuck = poll_dev->private;
> > + struct i2c_client *i2c = wiichuck->i2c_client;
> > + static uint8_t cmd_byte = 0;
> > + struct i2c_msg cmd_msg =
> > + { .addr = i2c->addr, .len = 1, .buf = &cmd_byte };
> > + uint8_t b[6];
>
> As mentioned by others these buffers should not be on stack.
Fixed.
>
> > + struct i2c_msg data_msg =
> > + { .addr = i2c->addr, .flags = I2C_M_RD, .len = 6, .buf = b };
> > + int jx, jy, ax, ay, az;
> > + bool c, z;
> > +
> > + switch (wiichuck->state) {
> > + case 0:
> > + i2c_transfer(i2c->adapter, &cmd_msg, 1);
> > + wiichuck->state = 1;
>
> Do you really need to have a state machine here? Why not do both
> transfers in one poll invocation?
Mostly because there needs to a gap between setting up the data
capture and reading the data back. I could flip things around to
setup the next transfer after reading the previous, but in my current
version I also add state for handling hotplug of the wiimote
accessories, so I think the state machine is still warranted.
> > + set_bit(EV_KEY, input_dev->evbit);
> > + set_bit(BTN_C, input_dev->keybit); /* buttons */
> > + set_bit(BTN_Z, input_dev->keybit);
>
> I prefer __set_bit() here since there is no concurrency.
In general, I avoid using __* versions of functions unless it is
actually important that I do so. I'm not concerned about slightly
higher overhead here, and I'd rather my code set a good example.
g.
next prev parent reply other threads:[~2011-05-16 18:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-12 4:29 [RFC PATCH] input: Add wiichuck driver Grant Likely
2011-05-12 6:24 ` simon
2011-05-15 21:17 ` Grant Likely
2011-05-14 19:17 ` Oliver Neukum
2011-05-14 19:20 ` Grant Likely
2011-05-16 16:44 ` Dmitry Torokhov
2011-05-16 18:31 ` Grant Likely [this message]
2011-05-16 19:44 ` Dmitry Torokhov
2011-05-16 21:01 ` Grant Likely
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=20110516183124.GA4875@ponder.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@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