OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [drivers/] [mou_gpm.c] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3
 * Copyright (c) 1999 Alex Holden
4
 * Copyright (c) 1991 David I. Bell
5
 * Permission is granted to use, distribute, or modify this source,
6
 * provided that this copyright notice remains intact.
7
 *
8
 * GPM Mouse Driver
9
 *
10
 * Rewritten to understand the Logitech Mouseman protocol which GPM
11
 * produces on /dev/gpmdata when in repeater mode. Remember to start
12
 * GPM with the -R flag or it won't work. (gpm -R -t ps2)
13
 *
14
 */
15
#include <stdio.h>
16
#include <errno.h>
17
#include <unistd.h>
18
#include <fcntl.h>
19
#include "device.h"
20
 
21
#define SCALE           3       /* default scaling factor for acceleration */
22
#define THRESH          5       /* default threshhold for acceleration */
23
 
24
#define GPM_DEV_FILE    "/dev/gpmdata"
25
 
26
static int      GPM_Open(MOUSEDEVICE *pmd);
27
static void     GPM_Close(void);
28
static int      GPM_GetButtonInfo(void);
29
static void     MOU_GetDefaultAccel(int *pscale,int *pthresh);
30
static int      GPM_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);
31
 
32
MOUSEDEVICE mousedev = {
33
        GPM_Open,
34
        GPM_Close,
35
        GPM_GetButtonInfo,
36
        MOU_GetDefaultAccel,
37
        GPM_Read,
38
        NULL
39
};
40
 
41
static int mouse_fd;
42
 
43
/*
44
 * Open up the mouse device.
45
 * Returns the fd if successful, or negative if unsuccessful.
46
 */
47
static int
48
GPM_Open(MOUSEDEVICE *pmd)
49
{
50
        mouse_fd = open(GPM_DEV_FILE, O_NONBLOCK);
51
        if (mouse_fd < 0)
52
                return -1;
53
        return mouse_fd;
54
}
55
 
56
/*
57
 * Close the mouse device.
58
 */
59
static void
60
GPM_Close(void)
61
{
62
        if (mouse_fd > 0)
63
                close(mouse_fd);
64
        mouse_fd = 0;
65
}
66
 
67
/*
68
 * Get mouse buttons supported
69
 */
70
static int
71
GPM_GetButtonInfo(void)
72
{
73
        return MWBUTTON_L | MWBUTTON_M | MWBUTTON_R;
74
}
75
 
76
/*
77
 * Get default mouse acceleration settings
78
 */
79
static void
80
MOU_GetDefaultAccel(int *pscale,int *pthresh)
81
{
82
        *pscale = SCALE;
83
        *pthresh = THRESH;
84
}
85
 
86
/*
87
 * Attempt to read bytes from the mouse and interpret them.
88
 * Returns -1 on error, 0 if either no bytes were read or not enough
89
 * was read for a complete state, or 1 if the new state was read.
90
 * When a new state is read, the current buttons and x and y deltas
91
 * are returned.  This routine does not block.
92
 */
93
static int
94
GPM_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
95
{
96
        static unsigned char buf[5];
97
        static int nbytes;
98
        int n;
99
 
100
        while((n = read(mouse_fd, &buf[nbytes], 5 - nbytes))) {
101
                if(n < 0) {
102
                        if ((errno == EINTR) || (errno == EAGAIN))
103
                                return 0;
104
                        else return -1;
105
                }
106
 
107
                nbytes += n;
108
 
109
                if(nbytes == 5) {
110
                        /* button data matches defines, no conversion*/
111
                        *bp = (~buf[0]) & 0x07;
112
                        *dx = (signed char)(buf[1]) + (signed char)(buf[3]);
113
                        *dy = -((signed char)(buf[2]) + (signed char)(buf[4]));
114
                        *dz = 0;
115
                        nbytes = 0;
116
                        return 1;
117
                }
118
        }
119
        return 0;
120
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.