Joystick

From ArmadeusWiki
Jump to: navigation, search

Page under construction... Construction.png Informations on this page are not guaranteed !!

Introduction

Joystick can be a good device to play some games or to use graphical interface. Linux has an interface for it named joydev, to use it select joydev in linux configuration :

$ make linux-menuconfig

then select in menu:

Device Drivers  --->
    Input device support  --->
            <*>   Joystick interface

To use it on the target, node has to be made :

cd /dev
rm js*
mkdir input
mknod input/js0 c 13 0
mknod input/js1 c 13 1
mknod input/js2 c 13 2
mknod input/js3 c 13 3
ln -s input/js0 js0
ln -s input/js1 js1
ln -s input/js2 js2
ln -s input/js3 js3

Test the joystick

Two programs named jstest and jscal wrote by Vojtech Pavlik can be use to test and calibrate the joystick. To use it select joysticktest package in buildroot :

$ make menuconfig
Package Selection for the target  --->
    [*] Hardware handling / blockdevices and filesystem maintenance  --->
        [*] joysticktest  

To test the joystick on platform, just launch jstest with /dev/jstx argument :

$ jstest /dev/input/js0
Joystick (Austria Microsystem as5011 joystick) has 2 axes and 1 buttons. Driver version is 2.1.0.
Testing ... (interrupt to exit)
Axes:  0: 32767  1: 32767 Buttons:  0:off

Joystick can be calibrated with jscal command :

# jscal -c /dev/input/js0
Joystick has 2 axes and 1 buttons.
Correction for axis 0 is broken line, precision is 0.
Coeficients are: 42, 42, 2147483647, -5835375
Correction for axis 1 is broken line, precision is 0.
Coeficients are: 59, 59, -24402479, -4473788

Calibrating precision: wait and don't touch the joystick.
Done. Precision is:                                             
Axis: 0:     0
Axis: 1:     0

Move axis 0 to minimum position and push any button.
Axis 0:       69
Hold ... OK.                                                                  
Move axis 0 to center position and push any button.
Axis 0:       61
Hold ... OK.                                                                  
Move axis 0 to maximum position and push any button.
Axis 0:     -118
Hold ... OK.                                                                  
Move axis 1 to minimum position and push any button.
Axis 1:      101
Hold ... OK.                                                                  
Move axis 1 to center position and push any button.
Axis 1:       63
Hold ... OK.                                                                  
Move axis 1 to maximum position and push any button.
Axis 1:      -60
Hold ... OK.                                                                  

Setting correction to:
Correction for axis 0: broken line, precision: 0.
Coeficients: 61, 61, -67106816, -2949750
Correction for axis 1: broken line, precision: 0.
Coeficients: 63, 63, -14127751, -4364671

List of joysticks tested

Austria microsystems AS5011 joystick

The as5011 is a small hall effect joystick produced by Austria microsystem. This joystick must be plugged on i²c bus . The driver is included in ARMadeus distribution, but to use it, platform file (apf27-dev.c) must be modified.

For example, with as5011 plugged on i2c bus 1, this code must be added in buildroot/project_build_armv5te/apf27/linux-2.6.29.6/arch/arm/mach-mx2/apf27-dev.c :

...
#include <linux/as5011.h>
...
#define AS5011_BUTTON_PIN 19
#define AS5011_BUTTON_PORT GPIO_PORTE
#define AS5011_BUTTON_IRQ IRQ_GPIOE(AS5011_BUTTON_PIN)

#define AS5011_INT_PIN 18
#define AS5011_INT_PORT GPIO_PORTE
#define AS5011_INT_IRQ IRQ_GPIOE(AS5011_INT_PIN)

static int as5011_pins0[] = {
	(GPIO_IN | GPIO_GPIO | AS5011_BUTTON_PORT | AS5011_BUTTON_PIN),
	(GPIO_IN | GPIO_GPIO | AS5011_INT_PORT | AS5011_INT_PIN),
};

static int as5011_init_gpio(void)
{
	int ret;

	ret = mxc_gpio_setup_multiple_pins(as5011_pins0,
					   ARRAY_SIZE(as5011_pins0),
					   "AS5011_0");
	if (ret < 0) {
		goto as5011_gpio_setup_error;
	}
	set_irq_type(AS5011_INT_IRQ, IRQ_TYPE_EDGE_FALLING);
	set_irq_type(AS5011_BUTTON_IRQ, IRQ_TYPE_EDGE_BOTH);
	return ret;

	mxc_gpio_release_multiple_pins(as5011_pins0, ARRAY_SIZE(as5011_pins0));
as5011_gpio_setup_error:
	return ret;
}

static void as5011_exit_gpio(void)
{
	set_irq_type(AS5011_INT_IRQ, IRQ_TYPE_NONE);
	set_irq_type(AS5011_BUTTON_IRQ, IRQ_TYPE_NONE);
	mxc_gpio_release_multiple_pins(as5011_pins0, ARRAY_SIZE(as5011_pins0));
}

static struct as5011_platform_data as5011_plat_data0 = {
	.init_gpio	= as5011_init_gpio,
	.exit_gpio	= as5011_exit_gpio,
	.button_irq	= AS5011_BUTTON_IRQ,
	.int_irq	= AS5011_INT_IRQ,
	.button_gpio	= (AS5011_BUTTON_PORT | AS5011_BUTTON_PIN),
	.int_gpio	= (AS5011_INT_PORT | AS5011_INT_PIN),
	.Xp		= 40,
	.Xn		= -40,
	.Yp		= 40,
	.Yn		= -40,
};

...

/* I2C1 devices: RTC & Optionnal Camera */
static struct i2c_board_info apf27dev_i2c_devices_bus0[] = {
	[0] = {
		/* APF27Dev has an RTC */
		.type = "ds1374",
		.flags = 0,  /* FIXME */
		.addr = 0x68,	/* E0=0, E1=1, E2=0 */
		.platform_data = NULL,
		.irq = 0
	},
# ifdef CONFIG_VIDEO_OV96xx
	[1] = {
		.type = "ov96xx",
		.flags = 0,  /* FIXME */
		.addr = 0x30,
		.platform_data = NULL,
		.irq = 0
	},
	// XXX: just for test
	[2] = {
		.type = "as5011",
		.flags = 0,  /* FIXME */
		.addr = 0x40,
		.platform_data = &as5011_plat_data0,
		.irq = 0
	},
# endif
};
...
  • Select as5011 driver:
 $ make linux-menuconfig»:
Device Drivers  --->
    Input device support  --->
        [*]   Joysticks/Gamepads  --->
            <M>   Austria Microsystem AS5011 joystick

Once joystick selected in linux configuration file and platform adapted, rootfs and kernel must be flashed then on target you just have to mount module :

# modprobe as5011
input: Austria Microsystem as5011 joystick as /devices/virtual/input/input0

Links