Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/hpcmips WSMOUSE_SCALIBCOORDS/WSMOUSE_GCALIBCOORDS s...



details:   https://anonhg.NetBSD.org/src/rev/a6ee693507a9
branches:  trunk
changeset: 480383:a6ee693507a9
user:      takemura <takemura%NetBSD.org@localhost>
date:      Mon Jan 10 14:07:58 2000 +0000

description:
WSMOUSE_SCALIBCOORDS/WSMOUSE_GCALIBCOORDS support.

diffstat:

 sys/arch/hpcmips/conf/files.hpcmips |   11 +-
 sys/arch/hpcmips/dev/mra.c          |  111 ++++++++++++++++++++++++++++++
 sys/arch/hpcmips/dev/tpcalib.c      |  132 ++++++++++++++++++++++++++++++++++++
 sys/arch/hpcmips/dev/tpcalibvar.h   |   43 +++++++++++
 sys/arch/hpcmips/vr/mra.c           |  111 ------------------------------
 sys/arch/hpcmips/vr/vrpiu.c         |   77 +++++---------------
 sys/arch/hpcmips/vr/vrpiuvar.h      |    6 +-
 7 files changed, 314 insertions(+), 177 deletions(-)

diffs (truncated from 605 to 300 lines):

diff -r c08ace1a2d4a -r a6ee693507a9 sys/arch/hpcmips/conf/files.hpcmips
--- a/sys/arch/hpcmips/conf/files.hpcmips       Mon Jan 10 13:32:02 2000 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips       Mon Jan 10 14:07:58 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.hpcmips,v 1.15 2000/01/09 07:57:43 shin Exp $
+#      $NetBSD: files.hpcmips,v 1.16 2000/01/10 14:08:05 takemura Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -148,11 +148,12 @@
 attach vrdsu at vrip
 file arch/hpcmips/vr/vrdsu.c                   vrdsu needs-flag
 
-define mra
-file arch/hpcmips/vr/mra.c                     mra
+define tpcalib
+file arch/hpcmips/dev/tpcalib.c                        tpcalib
+file arch/hpcmips/dev/mra.c                    tpcalib
 
 device vrpiu: wsmousedev
-attach vrpiu at vrip: mra
+attach vrpiu at vrip: tpcalib
 file arch/hpcmips/vr/vrpiu.c                   vrpiu
 
 #
@@ -210,7 +211,7 @@
 
 #      PHILIPS UCB1200 modem/audio analog front-end
 device ucb: wsmousedev
-attach ucb at txsibif: mra
+attach ucb at txsibif: tpcalib
 file arch/hpcmips/dev/ucb1200.c                ucb
 
 
diff -r c08ace1a2d4a -r a6ee693507a9 sys/arch/hpcmips/dev/mra.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/mra.c        Mon Jan 10 14:07:58 2000 +0000
@@ -0,0 +1,111 @@
+/*     $NetBSD: mra.c,v 1.1 2000/01/10 14:07:58 takemura Exp $ */
+
+/*
+ * Copyright (c) 1999 Shin Takemura All rights reserved.
+ * Copyright (c) 1999 PocketBSD Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+int mra_Y_AX1_BX2_C __P((int *y, int ys, int *x1, int x1s, int *x2, int x2s,
+                        int n, int scale, int *a, int *b, int *c));
+
+/*
+ * multiple regression analysis
+ * Y = AX1 + BX2 + C
+ */
+int
+mra_Y_AX1_BX2_C(y, ys, x1, x1s, x2, x2s, n, scale, a, b, c)
+       int *y, ys, *x1, x1s, *x2, x2s, n, scale, *a, *b, *c;
+{
+       int i;
+       int64_t X1a, X2a, Ya;
+       int64_t X1X1s, X2X2s, X1X2s;
+       int64_t YYs, X1Ys, X2Ys;
+       int64_t S11, S22, S12;
+       int64_t SYY, S1Y, S2Y;
+       int64_t A, B, C, M;
+#define AA(p, s, i)    (*((long*)(((char*)(p)) + (s) * (i))))
+#define X1(i)          AA(x1, x1s, i)
+#define X2(i)          AA(x2, x2s, i)
+#define Y(i)           AA(y, ys, i)
+
+       /*
+        * get avarage and sum
+        */
+       X1a = 0;        X2a = 0;        Ya = 0;
+       X1X1s = 0;      X2X2s = 0;      X1X2s = 0;
+       X1Ys = 0;       X2Ys = 0;       YYs = 0;
+       for (i = 0; i < n; i++) {
+               X1a += X1(i);
+               X2a += X2(i);
+               Ya += Y(i);
+
+               X1X1s += X1(i) * X1(i);
+               X2X2s += X2(i) * X2(i);
+               X1X2s += X1(i) * X2(i);
+
+               X1Ys += X1(i) * Y(i);
+               X2Ys += X2(i) * Y(i);
+               YYs += Y(i) * Y(i);
+       }
+       X1a /= n;       X2a /= n;       Ya /= n;
+
+       S11 = X1X1s - n * X1a * X1a;
+       S22 = X2X2s - n * X2a * X2a;
+       S12 = X1X2s - n * X1a * X2a;
+
+       SYY = YYs - n * Ya * Ya;
+       S1Y = X1Ys - n * X1a * Ya;
+       S2Y = X2Ys - n * X2a * Ya;
+
+#if 0
+       printf("X1a=%d X2a=%d Ya=%d\n", (int)X1a, (int)X2a, (int)Ya);
+       printf("X1X1s=%d X2X2s=%d X1X2s=%d\n", (int)X1X1s, (int)X2X2s, (int)X1X2s);
+       printf("X1Ys=%d X2Ys=%d YYs=%d\n", (int)X1Ys, (int)X2Ys, (int)YYs);
+       printf("S11=%d S22=%d S12=%d\n", (int)S11, (int)S22, (int)S12);
+       printf("SYY=%d S1Y=%d S2Y=%d\n", (int)SYY, (int)S1Y, (int)S2Y);
+#endif
+
+       M = (S11 * S22 - S12 * S12);
+       if (M == 0) {
+               /* error */
+               return -1;
+       }
+
+       A = (S1Y * S22 - S2Y * S12) * scale / M;
+       B = (S2Y * S11 - S1Y * S12) * scale / M;
+       C = Ya - (A * X1a + B * X2a) / scale;
+
+#if 0
+       printf("A=%d B=%d C=%d\n", (int)A, (int)B, (int)C);
+#endif
+       *a = A;
+       *b = B;
+       *c = C;
+
+       return (0);
+}
diff -r c08ace1a2d4a -r a6ee693507a9 sys/arch/hpcmips/dev/tpcalib.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/tpcalib.c    Mon Jan 10 14:07:58 2000 +0000
@@ -0,0 +1,132 @@
+/*     $NetBSD: tpcalib.c,v 1.1 2000/01/10 14:07:59 takemura Exp $     */
+
+/*
+ * Copyright (c) 1999 Shin Takemura All rights reserved.
+ * Copyright (c) 1999 PocketBSD Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <dev/wscons/wsconsio.h>
+#include <hpcmips/dev/tpcalibvar.h>
+
+#define TPCALIBDEBUG
+#ifdef TPCALIBDEBUG
+int    tpcalib_debug = 0;
+#define        DPRINTF(arg) if (tpcalib_debug) printf arg;
+#else
+#define        DPRINTF(arg)
+#endif
+
+/* mra is defined in mra.c */
+int mra_Y_AX1_BX2_C __P((int *y, int ys, int *x1, int x1s, int *x2, int x2s,
+                        int n, int scale, int *a, int *b, int *c));
+
+#define SCALE  (1024*1024)
+
+int
+tpcalib_init(sc)
+       struct tpcalib_softc *sc;
+{
+       tpcalib_reset(sc);
+       return (0);
+}
+
+void
+tpcalib_reset(sc)
+       struct tpcalib_softc *sc;
+{
+       /* This indicate 'raw mode'. No translation will be done. */
+       sc->sc_saved.samplelen = WSMOUSE_CALIBCOORDS_RESET;
+}
+
+void
+tpcalib_trans(sc, rawx, rawy, x, y)
+       struct tpcalib_softc *sc;
+       int rawx, rawy;
+       int *x, *y;
+{
+       if (sc->sc_saved.samplelen == WSMOUSE_CALIBCOORDS_RESET) {
+               /* This indicate 'raw mode'. No translation will be done. */
+               *x = rawx;
+               *y = rawy;
+       } else {
+               *x = (sc->sc_ax * rawx + sc->sc_bx * rawy) / SCALE + sc->sc_cx;
+               *y = (sc->sc_ay * rawx + sc->sc_by * rawy) / SCALE + sc->sc_cy;
+               if (*x < sc->sc_minx) *x = sc->sc_minx;
+               if (*y < sc->sc_miny) *y = sc->sc_miny;
+               if (sc->sc_maxx < *x)
+                       *x = sc->sc_maxx;
+               if (sc->sc_maxy < *y)
+                       *y = sc->sc_maxy;
+       }
+}
+
+int
+tpcalib_ioctl(sc, cmd, data, flag, p)
+       struct tpcalib_softc *sc;
+       u_long cmd;
+       caddr_t data;
+       int flag;
+       struct proc *p;
+{
+       struct wsmouse_calibcoords *d;
+       int s = sizeof(struct wsmouse_calibcoord);
+
+       d = (struct wsmouse_calibcoords *)data;
+
+       switch (cmd) {
+       case WSMOUSEIO_SCALIBCOORDS:
+               if (mra_Y_AX1_BX2_C(&d->samples[0].x, s,
+                                   &d->samples[0].rawx, s,
+                                   &d->samples[0].rawy, s,
+                                   d->samplelen, SCALE,
+                                   &sc->sc_ax, &sc->sc_bx, &sc->sc_cx) ||
+                   mra_Y_AX1_BX2_C(&d->samples[0].y, s,
+                                   &d->samples[0].rawx, s,
+                                   &d->samples[0].rawy, s,
+                                   d->samplelen, SCALE,
+                                   &sc->sc_ay, &sc->sc_by, &sc->sc_cy)) {
+                       printf("tpcalib: MRA error");
+                       tpcalib_reset(sc);
+               } else {
+                       DPRINTF(("tpcalib: Ax=%d Bx=%d Cx=%d\n",
+                                sc->sc_ax, sc->sc_bx, sc->sc_cx));
+                       DPRINTF(("tpcalib: Ay=%d By=%d Cy=%d\n",
+                                sc->sc_ay, sc->sc_by, sc->sc_cy));
+               }
+               break;
+
+       case WSMOUSEIO_GCALIBCOORDS:
+               *d = sc->sc_saved;
+               break;
+
+       default:
+               return (-1);
+       }
+       return (0);
+}
diff -r c08ace1a2d4a -r a6ee693507a9 sys/arch/hpcmips/dev/tpcalibvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/tpcalibvar.h Mon Jan 10 14:07:58 2000 +0000
@@ -0,0 +1,43 @@
+/*     $NetBSD: tpcalibvar.h,v 1.1 2000/01/10 14:08:00 takemura Exp $  */
+
+/*
+ * Copyright (c) 1999 Shin Takemura All rights reserved.
+ * Copyright (c) 1999 PocketBSD Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.



Home | Main Index | Thread Index | Old Index