From patchwork Fri May 20 22:45:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9130193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 35DDF60221 for ; Fri, 20 May 2016 23:25:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 284A127CF9 for ; Fri, 20 May 2016 23:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D66827E72; Fri, 20 May 2016 23:25:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id BACCC27CF9 for ; Fri, 20 May 2016 23:25:06 +0000 (UTC) Received: from localhost ([::1]:37961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3tmz-0003VO-PA for patchwork-qemu-devel@patchwork.kernel.org; Fri, 20 May 2016 19:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3tAM-0006XV-8A for qemu-devel@nongnu.org; Fri, 20 May 2016 18:45:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3tAI-0006NC-TW for qemu-devel@nongnu.org; Fri, 20 May 2016 18:45:10 -0400 Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]:32806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3tAI-0006Mj-Nv for qemu-devel@nongnu.org; Fri, 20 May 2016 18:45:06 -0400 Received: by mail-io0-x242.google.com with SMTP id x35so23048012ioi.0 for ; Fri, 20 May 2016 15:45:06 -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=QEg5r1R5F1TN8tPvhf7kOQX2F5b6GGoQ9ZKRq8g4PwY=; b=nKU/y+Py/77kPTXEjY51hp2s4brSdFfgnckYv8/I0QnJYHVeF9PCgDBT0T1rsuCzU2 47qA9Vb6qyvo+kh3oUtGLUz4WTk1OjqHw7B/YCHdHp9YsKnFG+DkSzpI3NLr8QnJ6PNz WrkjTVIyBvADMNLd7ttHEQbHq03UugauqIxjivEYfzdWh7zkI46KZOCXYi7VyvEexKcq 1b9qzsWhxPm60cP7PZO66H8pvwCG/kyMNfoGWbUSULmibalQKpY53OxLEaC/4iYJsqnn Mj6ngAozhwS5jiF9WSnxs4RKlYTilGRvrE7+eUBxqlzJ1jKYdtKkHQB4itlbZx4f54oG 5QTg== 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=QEg5r1R5F1TN8tPvhf7kOQX2F5b6GGoQ9ZKRq8g4PwY=; b=fUVvCg4lNrdw/X3P4NTXMdOoERATnSGDPhMjIXPJKIHfjm5y56WSgnk7rGCAWxSbYG VuNYEB+y8DDIAQUrpmkCloBdh/0T3upK5ThEEioQdzS6WYCpNx/W6v7Os3ICp8yQPW8/ B7No7/QyKAVmgTUVhmKW+u5bWY5g8AeMRxGTGcYZuqSWZJd8/9RDhpVgsxEheKeE/nLm 55wy2u077zNvOjQXdlp5YYYgFmvl0MwEPnRBnd0/wLQ+0lagp/mlSXshMUUoC+K2mav/ gjax+ZK8tkueTnil4JFiMWPTNGZI1GJ3o3+3rnS/8aBW0y0MN23Abu8RSaT4dYXi7OdQ 8pfQ== X-Gm-Message-State: AOPr4FUsHTZnH4ccxOsfwp+w3OB/Uhguo5wsD1O8cX3CwyPA6v4PEWA/a1Jb5hBoEqLnhA== X-Received: by 10.107.30.17 with SMTP id e17mr4742244ioe.142.1463784306119; Fri, 20 May 2016 15:45:06 -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 k72sm92048ita.17.2016.05.20.15.45.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 May 2016 15:45:05 -0700 (PDT) From: Programmingkid Date: Fri, 20 May 2016 18:45:04 -0400 Message-Id: To: Peter Maydell 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::242 Subject: [Qemu-devel] [PATCH v4 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-Virus-Scanned: ClamAV using ClamSMTP Add support for the power key. Signed-off-by: John Arbuckle --- v4 changes Removed double-quote from end of comment. Removed debug printf statement. v3 change Add several suggested comments. Moved the location of an else statement in the adb_keyboard_event() function. hw/input/adb.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/hw/input/adb.c b/hw/input/adb.c index 2042903..3998490 100644 --- a/hw/input/adb.c +++ b/hw/input/adb.c @@ -340,10 +340,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; } @@ -421,14 +436,22 @@ 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 */ + + /* The power button is a special case because it is a 16-bit value */ + if (qcode == Q_KEY_CODE_POWER) { + 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); } - if (evt->u.key.data->down == false) { /* if key release event */ - keycode = keycode | 0x80; /* create keyboard break code */ - } - - adb_kbd_put_keycode(s, keycode); } static const VMStateDescription vmstate_adb_kbd = {