Subversion Repositories shark

Rev

Rev 966 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
105 pj 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
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
966 pj 23
 CVS :        $Id: ps2mouse.c,v 1.2 2005-02-25 11:04:03 pj Exp $
105 pj 24
 
25
 File:        $File$
966 pj 26
 Revision:    $Revision: 1.2 $
27
 Last update: $Date: 2005-02-25 11:04:03 $
105 pj 28
 ------------
29
 
30
 Author:        Massimiliano Giorgi
31
 Date:  2/2/98
32
 
33
 File:  PS2MOUSE.C
34
 Revision:      1.0
35
 Last update: 22/mar/1999
36
 
37
 PS2 mouse driver
38
 
39
**/
40
 
41
/*
42
 * Copyright (C) 2000 Paolo Gai
43
 *
44
 * This program is free software; you can redistribute it and/or modify
45
 * it under the terms of the GNU General Public License as published by
46
 * the Free Software Foundation; either version 2 of the License, or
47
 * (at your option) any later version.
48
 *
49
 * This program is distributed in the hope that it will be useful,
50
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
52
 * GNU General Public License for more details.
53
 *
54
 * You should have received a copy of the GNU General Public License
55
 * along with this program; if not, write to the Free Software
56
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
57
 *
58
 */
59
 
60
/*#define __DEBUG_PS2MOUSE__*/
61
 
62
//#include <string.h>
63
//#include <stdlib.h>
64
//#include <cons.h>
65
 
66
//#include "vm.h"
67
#include <kernel/kern.h>
68
//#include "exc.h"
966 pj 69
#include <hartport/hartport/hartport.h>
105 pj 70
 
71
#include "8042.h"
72
#include <drivers/mouse.h>
73
 
74
#include "_mouse.h"
75
#include "ps2mouse.h"
76
 
77
#define WAITING 0
78
#define WAITX   1
79
#define WAITY   2
80
//static int status;
81
 
82
#ifdef __DEBUG_PS2MOUSE__
83
 
84
/* to print some debug information on line YDEB of the screen */
85
#define YDEB 2
86
 
87
#define change_status(x) {                            \
88
  status=(x);                                         \
89
  printf_xy(0,YDEB,WHITE,"[PS2mouse server] status: %s      ",#x); \
90
}
91
 
92
#define debug_show_data(b1,b2,b3) { \
93
  printf_xy(40,YDEB,WHITE,"B1: 0x%-2x ",b1);  \
94
  printf_xy(49,YDEB,WHITE,"B2: 0x%-2x ",b2);  \
95
  printf_xy(58,YDEB,WHITE,"B3: 0x%-2x ",b3);  \
96
}
97
 
98
#else
99
 
100
#define change_status(x) status=(x)
101
#define debug_show_data(b1,b2,b3)
102
 
103
#endif
104
 
105
/*
106
 * PS2 Mouse Server TASK
107
 *
108
 * This is the format of the incoming data.
109
 *
110
 * Data packet format:
111
 *
112
 *     |   D7      D6      D5      D4      D3      D2      D1      D0
113
 * -------------------------------------------------------------------
114
 * B1  |   XV      XV      YS      XS      1       0       R       L
115
 * B2  |   X7      X6      X5      X4      X3      X2      X1      X0
116
 * B3  |   Y7      Y6      Y5      Y4      Y3      Y2      Y1      Y0
117
 *
118
 * L       Left button state (1 = pressed down)
119
 * R       Right button state (1 = pressed down)
120
 * X0-X7   Movement in X direction
121
 * Y0-Y7   Movement in Y direction
122
 * XS,YS   Movement data sign bits (1 = negative)
123
 * XV,YV   Movement data overflow bits (1 = overflow has occured)
124
 *
125
 * Note:
126
 * -- X0-X7 and Y0-Y7 seems to be signed numbers
127
 * -- bit D3 in B1 seems to be the 3rd button (0 = pressed down)
128
 */
129
 
130
/*
131
 * the old ps/2 mouse server!
132
 * now the genaral mouse serve into mouse.c is used
133
 */
134
 
135
//TASK ps2mouse_server(void)
136
//{
137
//  int b1,b2,b3;
138
//  int mickey;
139
//
140
//  b3=b1=b2=0;
141
//  change_status(WAITING);
142
//  for (;;) {
143
//    wait_mouse();
144
//    
145
//    b3=get_mouse();
146
//
147
//    switch(status) {
148
//    case WAITING:
149
//      b1=b3;
150
//      debug_show_data(b1,b2,b3);
151
//      /* can only be tested if bit D3 is one ...*/
152
//      if ((b1&0x08)!=0x08) break;
153
//      change_status(WAITX);
154
//      break;
155
//    case WAITX:
156
//      b2=b3;
157
//      debug_show_data(b1,b2,b3);
158
//      change_status(WAITY);
159
//      break;
160
//    case WAITY:
161
//      debug_show_data(b1,b2,b3);
162
//
163
//      /* buttons */
164
//      mouse_buttons=((b1&0x1)<<1)|((b1&0x02)>>1)|(b1&0x04);
165
//
166
//      /* axes X */
167
//      mickey=((b1&0x10)?(b2-256):b2);
168
//      /* this part come from "sermouse.c" */
169
//      mouse_x_mick+=mickey;
170
//      while(mouse_x_mick>mouse_thresholdlim) {
171
//      mouse_x++;
172
//      mouse_x_mick-=mouse_thresholdlim;
173
//      }
174
//      while (mouse_x_mick<-mouse_thresholdlim) {
175
//      mouse_x--;
176
//      mouse_x_mick+=mouse_thresholdlim;
177
//      }
178
//      if (mouse_x>mouse_lim_x2) mouse_x=mouse_lim_x2;
179
//      else if (mouse_x<mouse_lim_x1) mouse_x=mouse_lim_x1;
180
//
181
//      /* axes Y */
182
//      mickey=((b1&0x20)?256-b3:-b3);
183
//      /* this part come from "sermouse.c" */
184
//      mouse_y_mick+=mickey;
185
//      while(mouse_y_mick>mouse_thresholdlim) {
186
//      mouse_y++;
187
//      mouse_y_mick-=mouse_thresholdlim;
188
//      }
189
//      while (mouse_y_mick<-mouse_thresholdlim) {
190
//      mouse_y--;
191
//      mouse_y_mick+=mouse_thresholdlim;
192
//      }
193
//      if (mouse_y>mouse_lim_y2) mouse_y=mouse_lim_y2;
194
//      else if (mouse_y<mouse_lim_y1) mouse_y=mouse_lim_y1;
195
//
196
//      /* mouse handler */
197
//      if (mouse_handler != NULL)
198
//      mouse_handler(mouse_x,mouse_y,mouse_buttons);
199
//
200
//      change_status(WAITING);
201
//      break;
202
//    }
203
//  }  
204
//}
205
//
206
 
207
TASK (*ps2mouse_getserveraddr(void))(void)
208
{
209
  return generalmouse_server;
210
}
211
 
212
/*
213
 * this is from gpm (see sermouse.c for comments)
214
 */
215
 
216
#include "gpmcomp.h"
217
 
218
int opt_glidepoint_tap=0;
219
 
220
/* mice.c START */
221
 
222
int M_ps2(Gpm_Event *state,  unsigned char *data)
223
{
224
  static int tap_active=0; /* there exist glidepoint ps2 mice */
225
 
226
  state->buttons=
227
    !!(data[0]&1) * GPM_B_LEFT +
228
    !!(data[0]&2) * GPM_B_RIGHT +
229
    !!(data[0]&4) * GPM_B_MIDDLE;
230
 
231
  if (data[0]==0 && opt_glidepoint_tap) /* by default this is false */
232
    state->buttons = tap_active = opt_glidepoint_tap;
233
  else if (tap_active) {
234
    if (data[0]==8)
235
      state->buttons = tap_active = 0;
236
    else state->buttons = tap_active;
237
}
238
 
239
 /* Some PS/2 mice send reports with negative bit set in data[0]
240
  * and zero for movement.  I think this is a bug in the mouse, but
241
  * working around it only causes artifacts when the actual report is -256;
242
  * they'll be treated as zero. This should be rare if the mouse sampling
243
  * rate is set to a reasonable value; the default of 100 Hz is plenty.
244
  * (Stephen Tell)
245
  */
246
  if(data[1] != 0)
247
    state->dx=   (data[0] & 0x10) ? data[1]-256 : data[1];
248
  else
249
    state->dx = 0;
250
  if(data[2] != 0)
251
    state->dy= -((data[0] & 0x20) ? data[2]-256 : data[2]);
252
  else
253
    state->dy = 0;
254
  return 0;
255
}
256
 
257
/* mice.c END */
258
 
259
/*
260
 * Virtual operation on a ps/2 mouse
261
 */
262
 
263
int ps2mouse_open(void *ptrPID)
264
{
265
  /* some modification are made into 8042.c to allow mouse reinitialization! */
266
  //static int first=1;
267
 
268
  //if (first) {
269
    C8042_auxinit(*(PID*)ptrPID);
270
    /* probably not needed! */
271
    task_activate(*(PID*)ptrPID);
272
  // first=0;
273
  //}
274
  C8042_auxportenable();
275
 
276
  return 0;
277
}
278
 
279
void ps2mouse_close(void)
280
{
281
  C8042_auxportdisable();
282
  C8042_auxend();
283
}
284
 
285
void ps2mouse_disable(void)
286
{
287
  C8042_auxportdisable();
288
}
289
 
290
void ps2mouse_enable(void)
291
{
292
  C8042_auxportenable();
293
}
294
 
295
void ps2mouse_wait(void)
296
{
297
  task_endcycle();
298
}
299
 
300
int ps2mouse_get(BYTE *data)
301
{
302
  return C8042_auxget(data,NON_BLOCK);
303
}
304
 
305
 
306
 
307
 
308