/*
* Copyright (C) 1998 Colin Wood
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Colin Wood.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* Handle putting the keyboard data received from the ADB into
* an ADB event record.
*/
void
kbd_adbcomplete(uint8_t *buffer, void *data_area, int adb_command)
{
adb_event_t event;
struct akbd_softc *ksc;
int adbaddr;
#ifdef ADB_DEBUG
int i;
if (adb_debug)
printf("adb: transaction completion\n");
#endif
#ifdef ADB_DEBUG
if (adb_debug) {
printf("akbd: from %d at %d (org %d) %d:", event.addr,
event.hand_id, event.def_addr, buffer[0]);
for (i = 1; i <= buffer[0]; i++)
printf(" %x", buffer[i]);
printf("\n");
}
#endif
microtime(&event.timestamp);
kbd_processevent(&event, ksc);
}
/*
* Given a keyboard ADB event, record the keycodes and call the key
* repeat handler, optionally passing the event through the mouse
* button emulation handler first.
*/
static void
kbd_processevent(adb_event_t *event, struct akbd_softc *ksc)
{
adb_event_t new_event;
if ((result = aed_input(&new_event)) != 0)
return;
if (adb_polling || !result)
#endif
#if NWSKBD > 0
if (ksc->sc_wskbddev != NULL) /* wskbd is attached? */
kbd_intr(&new_event, ksc);
#else
/* do nothing */ ;
#endif
if (event->bytes[1] != 0xff) {
new_event.u.k.key = event->bytes[1];
new_event.bytes[0] = event->bytes[1];
new_event.bytes[1] = 0xff;
#if NAED > 0
if (adb_polling || !aed_input(&new_event))
#endif
#if NWSKBD > 0
if (ksc->sc_wskbddev != NULL) /* wskbd is attached? */
kbd_intr(&new_event, ksc);
#else
/* do nothing */ ;
#endif
}
}
#ifdef notyet
/*
* Get the actual hardware LED state and convert it to softc format.
*/
static u_char
getleds(int addr)
{
short cmd;
u_char buffer[9], leds;
/*
* Set the keyboard LED's.
*
* Automatically translates from ioctl/softc format to the
* actual keyboard register format
*/
static int
setleds(struct akbd_softc *ksc, u_char leds)
{
int addr;
short cmd;
u_char buffer[9];
if ((leds & 0x07) == (ksc->sc_leds & 0x07))
return (0);
int
akbd_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
{
switch (cmd) {
case WSKBDIO_GTYPE:
*(int *)data = WSKBD_TYPE_ADB;
return 0;
case WSKBDIO_SETLEDS:
return 0;
case WSKBDIO_GETLEDS:
*(int *)data = 0;
return 0;
case WSKBDIO_COMPLEXBELL:
#define d ((struct wskbd_bell_data *)data)
mac68k_ring_bell(d->pitch, d->period * hz / 1000, 100);
/* comes in as msec, goes out as ticks; volume ignored */
#undef d
return (0);
}
/* kbdioctl(...); */
return EPASSTHROUGH;
}
static int polledkey;
extern int adb_polling;
int
kbd_intr(adb_event_t *event, struct akbd_softc *sc)
{
int key, press, val;
int type;
key = event->u.k.key;
press = ADBK_PRESS(key);
val = ADBK_KEYVAL(key);
type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
if (key == 185) { /* Caps Lock released */
type = WSCONS_EVENT_KEY_DOWN;
wskbd_input(sc->sc_wskbddev, type, val);
type = WSCONS_EVENT_KEY_UP;
}
if (adb_polling)
polledkey = key;
else
wskbd_input(sc->sc_wskbddev, type, val);
return 0;
}
int
akbd_cnattach(void)
{
wskbd_cnattach(&akbd_consops, NULL, &akbd_keymapdata);
return 0;
}
void
akbd_cngetc(void *v, u_int *type, int *data)
{
int intbits, key, press, val;
int s;
s = splhigh();
polledkey = -1;
adb_polling = 1;
while (polledkey == -1) {
intbits = via_reg(VIA1, vIFR);