BeOS Joystick Driver

Last update: Sep. 20, 2000


Introduction

This article describes how to write a BeOS joystick driver. It assumes knowledge on BeOS device drivers (kernel drivers and modules).

Be discloses little information on device driver development for minor fields, one of which is joysticks/gameports; a little information available is sonic_vibes driver source codes, BJoystick in Be Book and Be Developer Newsletter article. Thus I have investigated how to write a joystick driver and gained information enough to write a narrowly working one, as described below.

The contents of this article is based on my own investigation and Be does not publish nor guarantee them except some. I do not guarantee their correctness. Also beware that there are many unknown issues left.


Joystick API

First we will have a glance at BeOS joystick API (the BJoystick class). For details, refer to Be Book and Be Developer Newsletter article.

BJoystick has two operation modes, standard mode and enhanced mode. Standard mode is obsolete, based on BeBox gameports, limited to 2-axes and 2-buttons regardless of joystick models, and is seldom used. Enhanced mode is added in R4 and allows you to make best use of joystick features. In addition, the Joysticks preference is effective under enhanced mode only. Thus you will usually use enhanced mode. You can enter enhanced mode from standard mode, but it is done by default when the gameport is opened. In order to use standard mode, you have to explicity specify not to enter enhanced mode.

Applications will have access to joysticks as follows (function names represent the member functions in the BJoystick class). To use enhanced mode, you have to configure your joystick in the Joystick preference in advance.

standard mode

  1. Open a gameport by Open(), with specifying not to enter enhanced mode (you can enter enhanced mode later by EnterEnhancedMode()).
  2. Input joystick data by Update(). The data are stored in member variables (horizontal,vertical,button1,button2).
  3. Read the member variables directly.
  4. Close the gameport by Close().

enhanced mode

  1. Enumerate gameports using CountDevices() and GetDeviceName().
  2. Open a gameport by Open(), with entering enhanced mode.
  3. Obtain joystick characteristics using CountAxes(), CountButtons() etc.
  4. Input joystick data by Update().
  5. Read the input data by GetAxesValues(), ButtonValues() etc.
  6. Close the gameport by Close().

BeOS Joystick Support Framework

BeOS joystick support framework is constructed as follows:

	applications
	Joysticks preference------------+
		|			|
		|			|
		|BJoystick	joystick definition files
		|			|
		|			|
	operating system----------------+
		|
		|
		|kernel driver API
		|
		|
	gameport drivers--------+
		|		|
		|		|module API
		|		|
		|	joystick modules
		|
		|
	gameport hardware
		|
		|
	joystick hardware

Functionality of main components is show below:

Each file resides in the following locations:

Gameport drivers /system/add-ons/kernel/drivers/dev/joystick/*
Joystick modules /system/add-ons/kernel/media/joy/*
Joystick definition files /etc/joysticks/*
Gameport device files /dev/joysticks/*/*

Besides them, there is a thing called the "generic gameport module" (/system/add-ons/kernel/generic/gameport, the generic_gameport_module structure in joystick_driver.h) which is used in the sonic_vibes driver, but its role and usage are not clear. I will not take it into account here since you can write a driver without using it.

Developing a joystick driver implies writing a gameport driver, writing a joystick module and writing a joystick definition file.


Gameport Driver

I will breifly discuss processes the gameport driver API should implement. Refer to joystick_driver.h in the sonic_vibes driver for details about structures etc.


Joystick Module

I will breifly discuss processes the joystick module API should implement. There are still many unknown issues left about joystick modules compared to gameport drivers.


Sample Codes

Refer to my sample source codes.


Unknown Issues

Many left.


Conclusion


References


To ITO Takayuki's Home page