Linux userspace driver for the Logitech G13

First notes (2010-08-14).

I have implemented a daemon for the g13 that runs in userspace (so can't crash the entire kernel and system). It mostly works (I played a few games with it), though the LCD support is very basic.

I will provide more documentation in the next few days, for now the sources. Uncompress, run make (make sure you have libusb1 installed), run ./g13. Make sure you have the module uinput loaded and have write access as the user that runs g13. If you run udev, copy the file 91-g13.rules to /etc/udev/rules.d/ to make sure you have write access as the user that runs g13.

The daemon will create a pipe /tmp/g13-0 that you can send commands to (e.g. echo "rgb 100 0 0" > /tmp/g13-0).

Commands

rgb red green blue

Set the background color

mod int

Set the mode lights (M1-MR), this is the logical OR of all the values (so a number from 0-15).

bind key value

Bind a key to a scancode. This will change later, right now the first number is the key index (G13_KEY_??), the second number is the input key number (look in /usr/include/linux/input.h).

These will change, and I'll add something for the LCD.

Linux kernel module driver for the Logitech G13 (obsolete, deprecated)

This is deprecated, use the userspace driver above

Uploaded slightly modified version, seems to work fine except that it crashes evdev_drv (and thus xorg). Probably some problem with the event interface, still working on it. (2009-06-22).

This is a working first version of a kernel driver for the Logitech G13. It handles all keys and the stick, it can set the LCD, the backlight and the four M-key lights. I tested it on 2.6.29, but other kernel versions might work too.

Building

Download g13.tar.bz2, uncompress it, and run make.
   wget http://eutyche.swe.uni-linz.ac.at/g13/g13.tar.bz2
   tar xvjf g13.tar.bz2
   cd g13
   make
  
This should successfully build the kernel driver. If you get any errors, please report them to me, I'll try to fix them. In order to use the G13 driver, we need to tell module usbhid to ignore the G13. Add the following to /etc/modprobe.conf or to /etc/modprobe.d/g13:
    options usbhid quirks=0x046d:0xc21c:0x4
  
This tells the usbhid driver to ignore any device with the given usb vendor and device ids (which match exactly the G13).

Load the kernel module (this must be done as user root:

    insmod g13.ko
  
Plug in the G13, and cross your fingers :)

If the driver correctly recognizes the G13, you should see the following image on the LCD display:

You can interface with the driver through the files in /sys/kernel/g13.

/sys/kernel/g13/rgb

This sets the backlight, write three decimal integers values between 0 and 255 separated by spaces to set it:
    # set the backlight to medium red
    echo "100 0 0" > /sys/kernel/g13/rgb
  

/sys/kernel/g13/m_keys

This sets the M-keys lights, write a decimal integer value between 0 and 15 that specifies which lights to activate:
KeyValue
M11
M22
M34
MR8
The integer is the sum of the values of the lights to set.
    # set the M2 and MR lights, unset M1 and M3
    echo 10 > /sys/kernel/g13/m_keys
  

/sys/kernel/g13/lcd

This sets the LCD. The data needs to be a single block of 160 x 48 bits, representing the pixels in the image. For details, look at pbm2lpbm.c (compile with g++ pbm2lpbm.c, then run ./a.out < input.pbm > output.lpbm. It converts raw pbm images of size 160x43 to the correct format (conveniently named lcd-pbm or lpbm).
    # set the LCD to show hello.lpbm
    cat hello.lpbm > /sys/kernel/g13/lcd
  

/sys/kernel/g13/keymap

This sets the keymap for all the keys and buttons on the G13. The values are four digit hexadecimal integers representing the keycodes (from /usr/src/linux/include/linux/input.h) that the respective key or button sends. The values are in order:
KeyExplanation
G1 - G22The Gxx keys
Button-LeftThe button to the left of the stick
Button-DownThe button below the stick
Button-StickThe button that is activated when pushing the stick hard
M1 - MRThe Mx keys
NextThe round key to the left of the LCD
LeftThe leftmost key right below the LCD
Left-CenterThe second-to-left key right below the LCD
Right-CenterThe second-to-right key right below the LCD
RightThe rightmost key right below the LCD
LightThe key that toggles the LCD backlight, with a small sun on it
    # set my custom dvorak keymap
    echo "003b 003c 002d 0033 0020 003d 003e 003f 0040 001e 0027 0023 0041 0042 0043 0035 0030 0017 0044 000e 001c 0039 0110 0111 0112 0002 0003 0004 0005 0006 0007 0008 0009 000a 000b " > /sys/kernel/g13/keymap
  

Input

All keyboard and stick input is sent to /dev/event/inputn (n depends on your system, and probably changes between reboots, or even when you unplug and then re-plug the G13). Use evtest to see what the current keys are. Normally your X server should automatically use the device for input, the stick should work as an absolute pointing device (note that this depends on your setup, if your X server uses input hotplugging, you probably need some additional configuration).

Miscellaneous

I am still looking for a good default keymap, please email me with suggestions.