Rev 538 |
Rev 548 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Mauro Marinoni <mauro.marinoni@unipv.it>
*
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
#define __JOY_DEBUG__
//#define __JOY_DUMP__
#include <kernel/kern.h>
#include "../include/drivers/shark_input26.h"
#include "../include/drivers/shark_joy26.h"
#include <kernel/func.h>
/* Devices */
extern int ns558_init(void);
extern int ns558_exit(void);
extern int analog_init(void);
extern int analog_exit(void);
extern int joydump_init(void);
extern int joydump_exit(void);
/* Handler */
extern int joystick_init(void);
extern int joystick_exit(void);
/* Functions */
extern int joystick_enable(void);
extern int joystick_disable(void);
extern int joystick_get(int *type, int *number, int *value);
extern int input_installed;
#define JS_EVENT_BUTTON 0x01 /* button pressed/released */
#define JS_EVENT_AXIS 0x02 /* joystick moved */
#define JS_EVENT_INIT 0x80 /* initial state of device */
/* joystick driver currently installed */
static int joystick_installed = FALSE;
static int axis[4], button;
/* Called by handler */
void shark_joy_exec(void) {
int type, number, value;
if (joystick_get(&type, &number, &value))
return;
switch (type) {
case JS_EVENT_BUTTON:
button = number; /* TODO */
break;
case JS_EVENT_AXIS:
axis[number] = value; /* TODO */
break;
default:
return;
}
#ifdef __JOY_DEBUG__
printk(KERN_DEBUG "shark_joy.c: (%4d,%4d) (%4d,%4d) %4d\n", axis[0], axis[1], axis[2], axis[3], button);
#endif
}
/* User Functions */
void joy_enable(void)
{
joystick_enable();
}
void joy_disable(void)
{
joystick_disable();
}
/* Init the Linux Joystick Driver */
int JOY26_init() {
int ret;
if (input_installed == FALSE)
if (INPUT26_init()) {
printk(KERN_ERR "Unable to open Input SubSystem.\n");
return -1;
}
ret = ns558_init();
if (ret) {
printk(KERN_ERR "Gameport_Init return: %d\n", ret);
return -1;
}
#ifdef __JOY_DUMP__
ret = joydump_init();
#else
ret = analog_init();
#endif
if (ret) {
printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret);
return -1;
}
ret = joystick_init();
if (ret) {
printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret);
return -1;
}
joy_enable();
joystick_installed = TRUE;
return 0;
}
int JOY26_close() {
if (!joystick_installed)
return -1;
joy_disable();
joystick_exit();
#ifdef __JOY_DUMP__
joydump_exit();
#else
analog_exit();
#endif
ns558_exit();
joystick_installed = FALSE;
return 0;
}