Hardware Reference
In-Depth Information
Some of the data is split over multiple bytes. For example, the X acceleration bits
9:2 are obtained from byte 3. The lowest 2 bits are found in byte 6, in bits 3 and 2. These
together form the 9-bit X acceleration value.
To retrieve this data, we are always required to tell the Nunchuk where to begin. So
the sequence always begins with a write of offset 0x00 followed by a pause:
Write
Pause
Read 6 bytes
00
-
01
02
03
04
05
06
The Nunchuk doesn't allow us to do this in one ioctl(2) call, using two I/O
messages. A write of 0 must be followed by a pause. Then the 6 data bytes can be read as
a separate I2C read operation. If the pause is too long, however, the Nunchuk controller
seems to time out, resulting in incorrect data being returned. So we must do things the
Nunchuk way.
Linux uinput Interface
While reading the Nunchuk is fun, we need to apply it to our desktop as a mouse. We
need to insert mouse events based on what we read from it.
The Linux uinput driver allows programmers to develop nonstandard input drivers
so that events can be injected into the input stream. This approach allows new input
streams to be added without changing application code. Certainly the Nunchuk qualifies
as a nonstandard input device!
A problem with this uinput API is its general lack of documentation. The best
information available on the Internet seems to be from these three online sources:
“Getting started with uinput: the user level input subsystem”
http://thiemonge.org/getting-started-with-uinput
“Using uinput driver in Linux- 2.6.x to send user input”
http://www.einfochips.com/download/dash_jan_tip.pdf
http://www.kernel.org/doc/Documentation/input/
event-codes.txt
“Types”
The only other source of information seems to be the device driver source code itself:
drivers/input/misc/uinput.c
The example program provided in this chapter can help pull all the necessary details
together for you.
 
 
Search WWH ::




Custom Search