Subversion Repositories shark

Rev

Rev 538 | Rev 548 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 mauro 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Mauro Marinoni      <mauro.marinoni@unipv.it>
10
 *
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
#define __JOY_DEBUG__
20
//#define __JOY_DUMP__
21
 
22
#include <kernel/kern.h>
23
 
24
#include "../include/drivers/shark_input26.h"
25
#include "../include/drivers/shark_joy26.h"
26
 
27
#include <kernel/func.h>
28
 
29
/* Devices */
30
extern int ns558_init(void);
31
extern int ns558_exit(void);
32
 
33
extern int analog_init(void);
34
extern int analog_exit(void);
35
 
36
extern int joydump_init(void);
37
extern int joydump_exit(void);
38
 
39
/* Handler */
40
extern int joystick_init(void);
41
extern int joystick_exit(void);
42
 
547 mauro 43
/* Functions */
44
extern int joystick_enable(void);
45
extern int joystick_disable(void);
46
extern int joystick_get(int *type, int *number, int *value);
47
 
538 mauro 48
extern int input_installed;
49
 
547 mauro 50
#define JS_EVENT_BUTTON         0x01    /* button pressed/released */
51
#define JS_EVENT_AXIS           0x02    /* joystick moved */
52
#define JS_EVENT_INIT           0x80    /* initial state of device */
53
 
54
/* joystick driver currently installed */
55
static int joystick_installed = FALSE;
56
static int axis[4], button;
57
 
58
/* Called by handler */
59
void shark_joy_exec(void) {
60
        int type, number, value;
61
 
62
        if (joystick_get(&type, &number, &value))
63
                return;
64
 
65
        switch (type) {
66
                case JS_EVENT_BUTTON:
67
                        button = number;                /* TODO */
68
                        break;
69
                case JS_EVENT_AXIS:
70
                        axis[number] = value;           /* TODO */
71
                        break;
72
                default:
73
                        return;
74
        }
75
#ifdef __JOY_DEBUG__
76
        printk(KERN_DEBUG "shark_joy.c: (%4d,%4d) (%4d,%4d) %4d\n", axis[0], axis[1], axis[2], axis[3], button);
77
#endif
78
}
79
 
538 mauro 80
/* User Functions */
547 mauro 81
void joy_enable(void)
82
{
83
        joystick_enable();
84
}
538 mauro 85
 
547 mauro 86
void joy_disable(void)
87
{
88
        joystick_disable();
89
}
90
 
91
 
538 mauro 92
/* Init the Linux Joystick Driver */
93
int JOY26_init() {
94
 
95
        int ret;
96
 
97
        if (input_installed == FALSE)
98
                if (INPUT26_init()) {
99
                        printk(KERN_ERR "Unable to open Input SubSystem.\n");
100
                        return -1;
101
                }
102
 
103
        ret = ns558_init();
104
        if (ret) {
105
                printk(KERN_ERR "Gameport_Init return: %d\n", ret);
106
                return -1;
107
        }
108
 
109
#ifdef __JOY_DUMP__
110
        ret = joydump_init();
111
#else
112
        ret = analog_init();
113
#endif
114
        if (ret) {
115
                printk(KERN_ERR "Joystick_Device_Init return: %d\n", ret);
116
                return -1;
117
        }
118
 
119
        ret = joystick_init();
120
        if (ret) {
121
                printk(KERN_ERR "Joystick_Handler_Init return: %d\n", ret);
122
                return -1;
123
        }
124
 
547 mauro 125
        joy_enable();
126
        joystick_installed = TRUE;
538 mauro 127
        return 0;
128
}
129
 
130
int JOY26_close() {
547 mauro 131
        if (!joystick_installed)
132
                return -1;
538 mauro 133
 
547 mauro 134
        joy_disable();
538 mauro 135
        joystick_exit();
136
#ifdef __JOY_DUMP__
137
        joydump_exit();
138
#else
139
        analog_exit();
140
#endif
141
        ns558_exit();
547 mauro 142
 
143
        joystick_installed = FALSE;
538 mauro 144
        return 0;
145
}