From patchwork Fri May 6 02:39:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9028831 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 19AAF9F1D3 for ; Fri, 6 May 2016 02:40:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F0D320376 for ; Fri, 6 May 2016 02:40:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E2C320373 for ; Fri, 6 May 2016 02:40:36 +0000 (UTC) Received: from localhost ([::1]:56211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayVgu-0003p8-Qr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 May 2016 22:40:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayVgi-0003Yl-DF for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ayVgU-0004xO-06 for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:14 -0400 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:35781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ayVgS-0004rE-Ou for qemu-devel@nongnu.org; Thu, 05 May 2016 22:40:05 -0400 Received: by mail-io0-x241.google.com with SMTP id u185so12774446iod.2 for ; Thu, 05 May 2016 19:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-transfer-encoding:subject:date:message-id:cc:to :mime-version; bh=/983w8vkOvH+4NhYl1rsFbvQbZCKa5jOKUAVA+EQbrc=; b=kUgEFxe2kl/PSGDw5IGMHZDUoGX0ZI6eTkHT7jR6nX4fTH1Z1n3+OyynzYt2IdnEX0 IbtWmAqrtLQiUDXbZtR0dmjpBWNACQIXBg8NJJosIgRv7VnrWcaqf2143MkhU+mArTal 3coqbylJvjCbu7SQzVsqTxFbFiinOer/9UXOIrrDC64c7Tpg4rRpnGBPB+Os+CNOXycc nFhxj2/GTuVUnj1cvIUuhcDElsuejrqja1SY6XxEKKS54UGRN7sq7U41LnqTs5LyoqFa HoUWjn8vdNEj9f4VapH112JBGh7M8Oc/bsHhpPdQVs0D9mmOkNEExlmU8ug6CVROzB21 zOKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-transfer-encoding:subject:date :message-id:cc:to:mime-version; bh=/983w8vkOvH+4NhYl1rsFbvQbZCKa5jOKUAVA+EQbrc=; b=Yvp16SopytU3U3mSrT2rX0/mlB9uWc1CBLbAdhT+8T0VGGURhB7Qgq/Zvf6nIOi+JF LZC3UgJFWo61xs7mkHxz0x/hc0lONHNjCN34fym8Sx2+A+PmKEz8oEfUoiexbw7ftBCU csBR2jyqZKVd/ssWMfOXtULW3DQLpdn3kHO0x5YP+SEQLMNGS43lCBNgMAqtk6dEq06I emB86jyj7oxgWgW1pB7sb7TkuxL403DzfpS99R/Qrl9QW0H6l0ig0yH7X9OVW55flW9v bpp9M8HV8Q2cmQCgqymfhHypnuUfuLi49LfyOCDpXvCG1dtMgxvLBNeJNo4LjT47UYMw NDYQ== X-Gm-Message-State: AOPr4FWsxmdahd/uYvvtN+ddvvNx01DlDD/K85JWWZ47DcSDYE/ZIGkVqYOdqtwlhfJqWg== X-Received: by 10.107.167.206 with SMTP id q197mr21268707ioe.164.1462502387139; Thu, 05 May 2016 19:39:47 -0700 (PDT) Received: from [192.168.0.5] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id qb7sm3121886igb.17.2016.05.05.19.39.45 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 May 2016 19:39:46 -0700 (PDT) From: Programmingkid Date: Thu, 5 May 2016 22:39:43 -0400 Message-Id: To: Peter Maydell , Gerd Hoffmann Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] [PATCH v3 5/5] adb.c: add power key support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel qemu-devel Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for the power key. It has to be handled differently from the other keys because it is the only 16-bit value key. Signed-off-by: John Arbuckle Reviewed-by: Peter Maydell --- v3 change Add several suggested comments. Moved the location of an else statement in the adb_keyboard_event() function. hw/input/adb.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/hw/input/adb.c b/hw/input/adb.c index 37728b3..b5e53c7 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -343,10 +343,25 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) s->rptr = 0; } s->count--; - obuf[0] = keycode; - /* NOTE: could put a second keycode if needed */ - obuf[1] = 0xff; - olen = 2; + /* + * The power key is the only two byte value key, so it is a special case. + * Since 0x7f is not a used keycode for ADB we overload it to indicate the + * power button when we're storing keycodes in our internal buffer, and + * expand it out to two bytes when we send to the guest." + */ + if (keycode == 0x7f) { + obuf[0] = 0x7f; + obuf[1] = 0x7f; + olen = 2; + } else { + obuf[0] = keycode; + /* NOTE: the power key key-up is the two byte sequence 0xff 0xff; + * otherwise we could in theory send a second keycode in the second + * byte, but choose not to bother. + */ + obuf[1] = 0xff; + olen = 2; + } return olen; } @@ -424,15 +439,23 @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, return; } keycode = qcode_to_adb_keycode[qcode]; - if (keycode == NO_KEY) { /* We don't want to send this to the guest */ - return; - } - if (evt->u.key.data->down == false) { /* if key release event */ - keycode = keycode | 0x80; /* create keyboard break code */ + /* The power button is a special case because it is a 16-bit value */ + if (qcode == Q_KEY_CODE_POWER) { + printf("Power Key detected\n"); + if (evt->u.key.data->down == true) { /* Power button pushed keycode */ + adb_kbd_put_keycode(s, 0x7f); + } else { /* Power button released keycode */ + adb_kbd_put_keycode(s, 0xff); + } + } else if (keycode == NO_KEY) { /* NO_KEY shouldn't be sent to guest */ + return; + } else { /* For all non-power keys - safe for 8-bit keycodes */ + if (evt->u.key.data->down == false) { /* if key release event */ + keycode = keycode | 0x80; /* create keyboard break code */ + } + adb_kbd_put_keycode(s, keycode); } - - adb_kbd_put_keycode(s, keycode); } static const VMStateDescription vmstate_adb_kbd = {