home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / bsd / 5240 < prev    next >
Encoding:
Text File  |  1992-09-08  |  11.3 KB  |  403 lines

  1. Newsgroups: comp.unix.bsd
  2. Path: sparky!uunet!haven.umd.edu!wam.umd.edu!fcawth
  3. From: fcawth@wam.umd.edu (Alfred B. Cawthorne)
  4. Subject: [386bsd] bus mouse driver
  5. Message-ID: <1992Sep7.152230.22199@wam.umd.edu>
  6. Originator: fcawth@rac2.wam.umd.edu
  7. Sender: usenet@wam.umd.edu (USENET News system)
  8. Nntp-Posting-Host: rac2.wam.umd.edu
  9. Organization: University of Maryland at College Park
  10. Date: Mon, 7 Sep 1992 15:22:30 GMT
  11. Lines: 390
  12.  
  13.  
  14. Here is the second version of my logitech bus mouse driver.  I use it with
  15. X386 with good results.  It requires no modification of the X386 code so
  16. you can use it with the binaries that are floating around.  Please send
  17. any fixes, etc... to fcawth@delphi.umd.edu
  18.  
  19.                                             Fred.
  20. cut here.---------------
  21.  
  22. # This is a shell archive.  Save it in a file, remove anything before
  23. # this line, and then unpack it by entering "sh file".  Note, it may
  24. # create directories; files and directories will be owned by you and
  25. # have default permissions.
  26. #
  27. # This archive contains:
  28. #
  29. #    README
  30. #    mse.c
  31. #    mse.h
  32. #    tst.c
  33. #
  34. echo x - README
  35. sed 's/^X//' >README << 'END-of-README'
  36. XThis is a simple bus mouse driver I wrote so I could use my logitech bus
  37. Xmouse with X386.  The standard disclaimer applies to this code.  USE AT 
  38. XYOUR OWN RISK!!!  This is not a finished product, and I don't have lots of time
  39. Xto make it really nice.  I just wanted to use my mouse with X386! 
  40. X
  41. XVersion 0.1: First attempt, non interrupt driven.  This version worked ok, but
  42. X certain operations (like moving the scrollbar) were slow because the mouse 
  43. X port did not get read fast enough.  
  44. X
  45. XVersion 0.2: Still not as nice as I'd like it, but it works much better than
  46. X the first version.  A buffer was added which stores mouse values when the 
  47. X mouse card interrupts.  I am not sure why, but buttons need to be posted 
  48. X twice to be recognized correctly by X386.  I noticed that I would have to
  49. X move my cheapo serial mouse for the buttons to get recognized, so I suspect
  50. X that this is a feature of X386.  The buffering in this version is very
  51. X primative.
  52. X
  53. XFuture:  Write a nifty circular queue for the mouse data, and don't reset
  54. X after each read.  
  55. X
  56. XInstallation Instructions:
  57. X
  58. X1. copy the files mse.c and mse.h into the /sys/i386/isa directory.
  59. X
  60. X2. add the line:
  61. Xdevice    mse0    at isa? port 0x23c irq9 vector mseintr
  62. Xto your system's config file.
  63. X(Note: the port's address can be changed in the mse.h file)
  64. X
  65. X3. add the line:
  66. Xi386/isa/mse.c        optional mse device-driver
  67. Xto  /sys/i386/conf/files.i386
  68. X
  69. X4. add this to /sys/i386/i386/conf.c
  70. X
  71. X#include "mse.h"
  72. X#if NMSE >0
  73. Xint mseioctl(),mseopen(),mseclose(),mseread(),msewrite();
  74. X#else
  75. Xdefine mseiocntl enxio
  76. Xdefine mseclose enxio
  77. Xdefine mseread enxio
  78. Xdefine msewrite enxio
  79. Xdefine mseopen enxio
  80. X#endif
  81. X
  82. X5. change an entry in the cdevsw array (conf.c) to read:
  83. X
  84. X          { mseopen,      mseclose,       mseread,        msewrite,               
  85. X          mseioctl,     nullop,         nullop,         NULL,
  86. X          seltrue,      enodev,         enodev },
  87. X
  88. X(Note that the position of this determines the major device # of the driver)
  89. X( a hex number to the right of each entry is given so you don't even have to 
  90. X  count )
  91. X6. Make the driver special file:
  92. Xmknod /dev/mouse c <major> 0
  93. X
  94. X7. To use it with X386, add the line:
  95. XBusMouse    "/dev/mouse"
  96. Xto the Xconfig file and comment out all the serial mouse related stuff.
  97. X
  98. XNow, it should work.  I included a test program I used when writing this.
  99. X
  100. XSend any questions or comments to fcawth@delphi.umd.edu. 
  101. END-of-README
  102. echo x - mse.c
  103. sed 's/^X//' >mse.c << 'END-of-mse.c'
  104. X/* 386bsd logitech Bus Mouse driver   Fred Cawthorne 8/25/92                 */
  105. X/* This is a BETA release (at best) as it is my first attempt at programming */
  106. X/* a bsd device driver.  It is intended to be a simple but usable bus mouse  */
  107. X/* driver.  I have tested this with the binary X386 release from agate, and  */
  108. X/* it seems to work fine.  This driver gives the user two ways of accessing  */
  109. X/* the mouse.  IOCTLS probabally involve less overhead than READ's but the   */
  110. X/* mseread routine was included for compatibility with X386.                 */ 
  111. X/* Please send any improvements, suggestions, etc to fcawth@delphi.umd.edu   */
  112. X
  113. X
  114. X/*  Version 0.2  Interrupt driven version */
  115. X/* Permission is given to copy, modify, and use this code in any way you see */
  116. X/* fit.  I assume no responsibility for the problems this code could cause.  */
  117. X/* The only thing I know is that it works for me, it may or not work for you.*/
  118. X
  119. X
  120. X#include "mse.h"
  121. X
  122. X#include "param.h"
  123. X#include "ioctl.h"
  124. X#include "conf.h"
  125. X#include "uio.h"
  126. X#include "kernel.h"
  127. X
  128. X#include "i386/isa/isa_device.h"
  129. Xstatic char mse_buffer[193];
  130. Xstatic int mse_bufptr;
  131. Xint     mseprobe(), mseattach(),  msestart(), mseparam();
  132. Xstruct    isa_driver msedriver = {
  133. X    mseprobe, mseattach, "mse"
  134. X};
  135. X
  136. Xmseprobe(dev)
  137. Xstruct isa_device *dev;
  138. X{
  139. X/*hack for now, if your bus mouse doesn't like this, find out what its sig. is*/
  140. X/* we need a good way of finding out if it is really there but I don't have   */
  141. X/* any hardware documentation for the mouse */
  142. Xif (inb(SIGNATURE_PORT)==0)
  143. X        return(1);
  144. Xelse return(0);
  145. X}
  146. X
  147. X
  148. Xint
  149. Xmseattach(isdp)
  150. Xstruct isa_device *isdp;
  151. X{
  152. X outb (CONTROL,0);
  153. X/*    outb(CONTROL, MOUSEDEFAULT);
  154. X    outb(PORTC, PORTC_DISABLE_INTERRUPTS); */
  155. Xprintf (" sig=%d",inb(SIGNATURE_PORT));
  156. Xreturn (1);
  157. X}
  158. X
  159. Xmseopen(dev_t dev, int flag, int mode, struct proc *p)
  160. X{
  161. X    outb(CONTROL, MOUSEDEFAULT);
  162. Xmse_bufptr=0; 
  163. X    outb(PORTC, PORTC_ENABLE_INTERRUPTS);
  164. X        
  165. Xreturn(0);
  166. X}
  167. X
  168. Xmseclose(dev, flag, mode, p)
  169. X    dev_t dev;
  170. X    int flag, mode;
  171. X    struct proc *p;
  172. X{
  173. X        outb(CONTROL, 0);
  174. X    outb(PORTC, PORTC_DISABLE_INTERRUPTS);
  175. Xreturn(0);
  176. X}
  177. Xmseintr(unit)
  178. X{
  179. Xstruct mousedat mouse_dat;
  180. Xint i;
  181. Xstatic int oldbut;
  182. Xstatic int buttonpress = 0;
  183. X
  184. Xoutb(PORTC, PORTC_DISABLE_INTERRUPTS);
  185. X                    outb(PORTC, READ_X_LOW);
  186. X            mouse_dat.deltax = inb(PORTA) & 0xf;
  187. X            outb(PORTC, READ_X_HIGH);
  188. X            mouse_dat.deltax |= (inb(PORTA) & 0xf) << 4;
  189. X
  190. X            outb(PORTC, READ_Y_LOW );
  191. X            mouse_dat.deltay = inb(PORTA) & 0xf;
  192. X            outb(PORTC, READ_Y_HIGH);
  193. X            i = inb(PORTA);
  194. Xoutb(PORTC, PORTC_DISABLE_INTERRUPTS);
  195. X            mouse_dat.deltay |= (i & 0xf) << 4;
  196. X            mouse_dat.buttons = (i >> 5)|0x80;
  197. X            if((char)(mouse_dat.deltay)==(-128)) (char)mouse_dat.deltay++; 
  198. X          if ((char)(mouse_dat.deltay)!=0) mouse_dat.deltay=-mouse_dat.deltay; 
  199. X           if((char)(mouse_dat.deltax)==(-128)) (char)mouse_dat.deltax++; 
  200. Xif ((mouse_dat.deltax!=0)||(mouse_dat.deltay!=0)||(mouse_dat.buttons!=oldbut))
  201. X{ 
  202. Xif (buttonpress>1 ) {
  203. Xoldbut=mouse_dat.buttons;
  204. Xbuttonpress=0; }
  205. Xelse {
  206. Xbuttonpress++;
  207. Xoldbut=0; }
  208. X
  209. Xmse_buffer[mse_bufptr++]=(char)mouse_dat.buttons;
  210. Xmse_buffer[mse_bufptr++]=(char)mouse_dat.deltax;
  211. Xmse_buffer[mse_bufptr++]=(char)mouse_dat.deltay; 
  212. Xif (mse_bufptr>191) mse_bufptr=(189); 
  213. X/*printf ("mse_bufptr=%d\n",mse_bufptr++);  
  214. Xprintf ("MOUSEINTR called dx=%d dy=%d but=%d\n",mouse_dat.deltax,mouse_dat.deltay,mouse_dat.buttons);
  215. X*/
  216. X}
  217. Xoutb(PORTC,PORTC_ENABLE_INTERRUPTS);
  218. X
  219. X}
  220. Xmseioctl(dev, cmd, data, flag)
  221. X    dev_t dev;
  222. X        int cmd,flag;
  223. X        struct mousedat* data;
  224. X{ int i;
  225. Xregister struct mousedat mouse_dat;
  226. X switch(cmd) {
  227. X    case MIOGETDATA:outb(PORTC, READ_X_LOW);
  228. X            mouse_dat.deltax = inb(PORTA) & 0xf;
  229. X            outb(PORTC, READ_X_HIGH);
  230. X            mouse_dat.deltax |= (inb(PORTA) & 0xf) << 4;
  231. X
  232. X            outb(PORTC, READ_Y_LOW );
  233. X            mouse_dat.deltay = inb(PORTA) & 0xf;
  234. X            outb(PORTC, READ_Y_HIGH);
  235. X            i = inb(PORTA);
  236. X            mouse_dat.deltay |= (i & 0xf) << 4;
  237. X            mouse_dat.buttons = i >> 5;
  238. X(struct mousedat *)data->buttons=(7-(mouse_dat.buttons));
  239. X(struct mousedat *)data->deltax=mouse_dat.deltax;
  240. X(struct mousedat *)data->deltay=mouse_dat.deltay;
  241. Xreturn(0);
  242. X            break;
  243. X
  244. X    default:    return(EFAULT);
  245. X            break;
  246. X    }
  247. Xreturn(0);
  248. X}
  249. X
  250. Xmsestart(tp)
  251. X    register struct mousedat *tp;
  252. X{
  253. X}
  254. X
  255. Xmseread (dev,uio,flag)
  256. X struct uio *uio;
  257. X dev_t dev;
  258. Xint flag;
  259. X
  260. X{ 
  261. Xint ptr;
  262. Xif (mse_bufptr!=0)
  263. Xfor (ptr=0; ptr<mse_bufptr; ptr++ ) {
  264. X/*printf ("mse_buffer[%d]=%d,",ptr,mse_buffer[ptr]);  */
  265. Xif ((uio->uio_resid)>3) {
  266. X   ureadc((char)mse_buffer[ptr++],uio);
  267. X   ureadc((char)mse_buffer[ptr++],uio);
  268. X   ureadc((char)mse_buffer[ptr],uio);
  269. X       }
  270. X}
  271. Xmse_bufptr=0;
  272. Xreturn(0);
  273. X}
  274. X
  275. Xmsewrite(dev,uio,flag) 
  276. Xdev_t dev;
  277. Xstruct uio *uio;
  278. X{}
  279. X
  280. END-of-mse.c
  281. echo x - mse.h
  282. sed 's/^X//' >mse.h << 'END-of-mse.h'
  283. X/*    mouse.h:    header file for Logitech Bus Mouse driver    */
  284. X
  285. X#ifndef MOUSE_H
  286. X#define MOUSE_H
  287. X
  288. X/* #define USE_INTS    /* Should the driver use interrupts? */
  289. X
  290. X#define    PORTA    0x23c        /*    1100        */
  291. X#define    SIGNATURE_PORT    0x23d    /*    1101        */
  292. X#define    PORTC    0x23e        /*    1110        */
  293. X#define    CONTROL    0x23f        /*    1111        */
  294. X
  295. X#define    SETMODE        0x80    /*    1xxx xxxx    */
  296. X    /* Group A */
  297. X#define M_AMODE0    0x00    /*    x00x xxxx    */
  298. X#define M_AMODE1    0x20    /*    x01x xxxx    */
  299. X#define M_AMODE2    0x40    /*    x10x xxxx    */
  300. X#define M_AIN        0x10    /*    xxx1 xxxx    */
  301. X#define M_AOUT        0x00    /*    xxx0 xxxx    */
  302. X#define M_CUIN        0x08    /*    xxxx 1xxx    */
  303. X#define M_CUOUT        0x00    /*    xxxx 0xxx    */
  304. X    /* Group B */
  305. X#define M_BMODE0    0x00    /*    xxxx x0xx    */
  306. X#define M_BMODE1    0x04    /*    xxxx x1xx    */
  307. X#define M_BIN        0x02    /*    xxxx xx1x    */
  308. X#define M_BOUT        0x00    /*    xxxx xx0x    */
  309. X#define M_CLIN        0x01    /*    xxxx xxx1    */
  310. X#define M_CLOUT        0x00    /*    xxxx xxx0    */
  311. X
  312. X#define MOUSEDEFAULT    (SETMODE|M_AMODE0|M_AIN)    /* 1001 0000 */
  313. X
  314. X#define    READ_X_LOW    0x80    /*    1000 0000    */
  315. X#define    READ_X_HIGH    0xa0    /*    1010 0000    */
  316. X#define    READ_Y_LOW    0xc0    /*    1100 0000    */
  317. X#define    READ_Y_HIGH    0xe0    /*    1110 0000    */
  318. X
  319. X#define    PORTC_ENABLE_INTERRUPTS        0x80    /*    1000 0000    */
  320. X#define    PORTC_DISABLE_INTERRUPTS    0x10    /*    0000 0000    */
  321. X
  322. Xstruct    mousedat { 
  323. X    unsigned char buttons; 
  324. X    char deltax,deltay;
  325. X};
  326. X
  327. X/* IOCTLS */
  328. X#define    MIOGETDATA    ((sizeof(struct mousedat*)<<16)|('M'<<8) | 0x01 |0x40000000)    /* get mouse data */
  329. X
  330. X#endif
  331. X
  332. END-of-mse.h
  333. echo x - tst.c
  334. sed 's/^X//' >tst.c << 'END-of-tst.c'
  335. X
  336. X/*
  337. X    Test program for Mouse Driver
  338. X DON'T use this while you are using the mouse under X windows or it will
  339. X    get confused...
  340. X*/
  341. X
  342. X#include <sys/file.h>
  343. X#include <sys/ioctl.h>
  344. X#include <sys/types.h>
  345. X#include "mse.h"
  346. X
  347. Xint     mousefd;
  348. X
  349. X
  350. Xmain()
  351. X{
  352. X struct mousedat    new,old;
  353. X int xpos, ypos;
  354. X
  355. X    old.deltax = old.deltay = old.buttons = 1;
  356. X
  357. X    if ((mousefd = open("/dev/mouse",O_RDWR,0)) == -1) {
  358. X        perror("open of mouse device");
  359. X        exit(1);
  360. X    }
  361. Xwhile (1)  readmouse(&new);
  362. X
  363. Xold.buttons=0;
  364. X    xpos = ypos = 1;
  365. X    while (old.buttons != 7) {    /* press all 3 buttons to quit */
  366. X        readmouse(&new);
  367. X    if ((new.deltax!=0)||(new.deltay!=0)||(new.buttons!=old.buttons)){    
  368. X            xpos += new.deltax; ypos += new.deltay;
  369. X                printf("X=%03d Y=%03d  Buttons=%c%c%c\n", xpos, ypos,
  370. X                   new.buttons & 4 ? '*' : ' ',
  371. X                      new.buttons & 2 ? '*' : ' ',
  372. X                         new.buttons & 1 ? '*' : ' ' );
  373. X                        old.buttons=new.buttons;
  374. X                        old.deltax=new.deltax;
  375. X                        old.deltay=new.deltay;
  376. X        }
  377. X    }
  378. X}
  379. X
  380. Xreadmouse( md )
  381. Xregister struct mousedat *md;
  382. X{
  383. Xint i;
  384. Xchar buf[1024];
  385. Xint len = 10;
  386. X/*    if ((ioctl(mousefd,MIOGETDATA,md)) == -1) {  
  387. X        perror("IOCTL failed on /dev/mouse");
  388. X        exit(2);
  389. X    } */
  390. X/* some printfs to see if everything's OK */
  391. X
  392. X/*printf ("deltax=%d deltay=%d buttons=%d \n",md->deltax,md->deltay,md->buttons); */
  393. Xlen=read(mousefd,&buf,64);
  394. Xfor (i=0; i<len ; i++)
  395. Xprintf ("len=%d buf[%d]=%d  \n",len,i,buf[i]);
  396. Xsleep(1); 
  397. X}
  398. X
  399. END-of-tst.c
  400. exit
  401.  
  402.