Home | History | Annotate | Line # | Download | only in dec
lk201_ws.c revision 1.1
      1 /* $NetBSD: lk201_ws.c,v 1.1 1998/09/17 20:01:57 drochner Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998
      5  *	Matthias Drochner.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed for the NetBSD Project
     18  *	by Matthias Drochner.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 
     38 #include <dev/wscons/wsconsio.h>
     39 
     40 #include <dev/dec/lk201reg.h>
     41 #include <dev/dec/lk201var.h>
     42 #include <dev/dec/wskbdmap_lk201.h> /* for {MIN,MAX}_LK201_KEY */
     43 
     44 void
     45 lk201_init_keystate(lks)
     46 	struct lk201_state *lks;
     47 {
     48 	int i;
     49 
     50 	for (i = 0; i < LK_KLL; i++)
     51 		lks->down_keys_list[i] = -1;
     52 }
     53 
     54 int
     55 lk201_decode(lks, datain, type, dataout)
     56 	struct lk201_state *lks;
     57 	int datain;
     58 	u_int *type;
     59 	int *dataout;
     60 {
     61 	int i, freeslot;
     62 
     63 	switch (datain) {
     64 	    case LK_KEY_UP:
     65 		for (i = 0; i < LK_KLL; i++)
     66 			lks->down_keys_list[i] = -1;
     67 		*type = WSCONS_EVENT_ALL_KEYS_UP;
     68 		return (1);
     69 	    case LK_POWER_UP:
     70 		printf("lk201_decode: powerup detected\n");
     71 		/* XXX should reinitialize here */
     72 		return (0);
     73 	    case LK_KDOWN_ERROR:
     74 	    case LK_POWER_ERROR:
     75 	    case LK_OUTPUT_ERROR:
     76 	    case LK_INPUT_ERROR:
     77 		printf("lk201_decode: error %x\n", datain);
     78 		/* FALLTHRU */
     79 	    case LK_KEY_REPEAT: /* autorepeat handled by wskbd */
     80 	    case LK_MODE_CHANGE: /* ignore silently */
     81 		return (0);
     82 	}
     83 
     84 	if (datain < MIN_LK201_KEY || datain > MAX_LK201_KEY) {
     85 		printf("lk201_decode: %x\n", datain);
     86 		return (0);
     87 	}
     88 
     89 	*dataout = datain - MIN_LK201_KEY;
     90 
     91 	freeslot = -1;
     92 	for (i = 0; i < LK_KLL; i++) {
     93 		if (lks->down_keys_list[i] == datain) {
     94 			*type = WSCONS_EVENT_KEY_UP;
     95 			lks->down_keys_list[i] = -1;
     96 			return (1);
     97 		}
     98 		if (lks->down_keys_list[i] == -1 && freeslot == -1)
     99 			freeslot = i;
    100 	}
    101 
    102 	if (freeslot == -1) {
    103 		printf("lk201_decode: down(%d) no free slot\n", datain);
    104 		return (0);
    105 	}
    106 
    107 	*type = WSCONS_EVENT_KEY_DOWN;
    108 	lks->down_keys_list[freeslot] = datain;
    109 	return (1);
    110 }
    111