Ejemplo n.º 1
0
static u_int
abtn_receive_packet(device_t dev, u_char status, 
    u_char command, u_char reg, int len, u_char *data)
{
	u_int cmd;

	cmd = data[0];

	switch (cmd) {
	case 0x0a:	/* decrease brightness */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "brightness",
			    "notify=down");
		break;

	case 0x09:	/* increase brightness */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "brightness", "notify=up");
		break;

	case 0x08:	/* mute */
	case 0x01:	/* mute, AV hardware */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "mute", NULL);
		break;
	case 0x07:	/* decrease volume */
	case 0x02:	/* decrease volume, AV hardware */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "volume", "notify=down");
		break;
	case 0x06:	/* increase volume */
	case 0x03:	/* increase volume, AV hardware */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "volume", "notify=up");
		break;
	case 0x0c:	/* mirror display key */
		/* Need callback to do something with this */
		break;
	case 0x0b:	/* eject tray */
		if (devctl_process_running())
			devctl_notify("PMU", "keys", "eject", NULL);
	case 0x7f:	/* numlock */
		/* Need callback to do something with this */
		break;

	default:
#ifdef DEBUG
		if ((cmd & ~0x7f) == 0)
			device_printf(dev, "unknown ADB button 0x%x\n", cmd);
#endif
		break;
	}
	return 0;
}
Ejemplo n.º 2
0
static u_int 
adb_kbd_receive_packet(device_t dev, u_char status, 
    u_char command, u_char reg, int len, u_char *data)
{
	struct adb_kbd_softc *sc;

	sc = device_get_softc(dev);

	if (command != ADB_COMMAND_TALK)
		return 0;

	if (reg != 0 || len != 2)
		return (0);

	mtx_lock(&sc->sc_mutex);
		/* 0x7f is always the power button */
		if (data[0] == 0x7f && devctl_process_running()) {
			devctl_notify("PMU", "Button", "pressed", NULL);
			mtx_unlock(&sc->sc_mutex);
			return (0);
		} else if (data[0] == 0xff) {
			mtx_unlock(&sc->sc_mutex);
			return (0);	/* Ignore power button release. */
		}
		if ((data[0] & 0x7f) == 57 && sc->buffers < 7) {
			/* Fake the down/up cycle for caps lock */
			sc->buffer[sc->buffers++] = data[0] & 0x7f;
			sc->buffer[sc->buffers++] = (data[0] & 0x7f) | (1 << 7);
		} else {
			sc->buffer[sc->buffers++] = data[0];
		}
		if (sc->buffer[sc->buffers-1] < 0xff)
			sc->last_press = sc->buffer[sc->buffers-1];

		if ((data[1] & 0x7f) == 57 && sc->buffers < 7) {
			/* Fake the down/up cycle for caps lock */
			sc->buffer[sc->buffers++] = data[1] & 0x7f;
			sc->buffer[sc->buffers++] = (data[1] & 0x7f) | (1 << 7);
		} else {
			sc->buffer[sc->buffers++] = data[1];
		}

		if (sc->buffer[sc->buffers-1] < 0xff)
			sc->last_press = sc->buffer[sc->buffers-1];

		/* Stop any existing key repeating */
		callout_stop(&sc->sc_repeater);

		/* Schedule a repeat callback on keydown */
		if (!(sc->last_press & (1 << 7))) {
			callout_reset(&sc->sc_repeater, 
			    ms_to_ticks(sc->sc_kbd.kb_delay1), akbd_repeat, sc);
		}
	mtx_unlock(&sc->sc_mutex);

	cv_broadcast(&sc->sc_cv);

	if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) {
		sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd,
			 KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg);
	}

	return (0);
}