From patchwork Thu Nov 2 17:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 740450 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp961630wrv; Thu, 2 Nov 2023 10:40:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQB2Ffk/IvijSZ89SfH8fb91EGPhN4MNcAO9R6c6rZFGeukcAAzcBg0EWIvXMddqNsHcQm X-Received: by 2002:a05:6870:bb1b:b0:1f0:6565:9a37 with SMTP id nw27-20020a056870bb1b00b001f065659a37mr1128056oab.50.1698946812643; Thu, 02 Nov 2023 10:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698946812; cv=none; d=google.com; s=arc-20160816; b=D6Vy8nLbUEhNBlW6pLoyOCZnUjqw1irR5sgmMtBSDhElydVqEVHnFTvNwJKo3dZ4JK Y3WB2JswQeXuDuey619/TkqVYSALhc2psJrs8lKDME0lXI+xl0KPJfGi9VVfqr3kh8c3 sPj7obSqSZNL96JTZuemPv8SEd/854tRuE3TCJ9fTTblayC73AlpjUHmtluEnx+GyoML ymQnHAi6bDsdxoV2EO37IoGSNIEZt81CdEVB++UlHfCZtgFDxqt1xitjeDAEmOB8+xOg NdtoKM4yd3iXnK1S23W1Agnmf3p46X0453E0103v706dsXsFdHTViiBMTV37lU3pS/DM KbhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ldh6u2bWD7MniqjxzXyQCd0Qu18ZZOjaa+NiKkpmJMc=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=z+Ah2ZUQcBWzgHQe7HszERMhiCjYBgingGQnmkgIEcBVBkG42JCIwF4nmQm5fp9mST Iy1V8wL3j9Qr2CeAvElCHgYKfY7IMKF2pPst05JSRAQnqtu2MjD0WFf2yHiq+ccSeMbY hHcjel3kGvj1Da4UBQEaQN09Xes9ZRG+YTWkcr5++dw6O8vppypdiDRElnpLTCMGk87Z Z6tDWRIf4WR+jZYYTzBJQuWIBXo2oYovXrcCN4V3/QsYSBlvxAjBcIuk0sN8vrrbY+yY yBcR6Efg35amSr/+W/RaictL1scsjB5nkc72Eh9lESKSxnbVqqd1JwlSUSoh+thygjt+ CYWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cBlwRk1J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t7-20020a0cef07000000b0065d8846dd43si296472qvr.192.2023.11.02.10.40.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2023 10:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cBlwRk1J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qybed-0003E2-J8; Thu, 02 Nov 2023 13:38:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qybeZ-0003B5-2K for qemu-devel@nongnu.org; Thu, 02 Nov 2023 13:38:47 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qybeU-0002hl-1f for qemu-devel@nongnu.org; Thu, 02 Nov 2023 13:38:46 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-32f7bd27c2aso800834f8f.2 for ; Thu, 02 Nov 2023 10:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698946720; x=1699551520; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ldh6u2bWD7MniqjxzXyQCd0Qu18ZZOjaa+NiKkpmJMc=; b=cBlwRk1Jy+D4+IBixNtu65/lD/F2onN46RsgX4CR17m6sTJHc9UA9KHYS26oU+TczM jDESvAb9p3C8Xvqhfu0SXiUzvYf8cxoRRCx7u1XAOaxB863OZv3S4kmZtv+QZChAXJ19 2NB143plXon1LGnldQ7+8pk7lRghki3uxtn8Gei1qx1dr8yUj1tjHLTDtNIm8U21u657 DDm6MIDyNagGJY+2jrLWjE8eQzoC1qce6wTo1dHAcdEs71VnNciHdJscXyH1JCI6pLPd NlAonITdCpqlfX3nL4dJc/4lAO/POeFoHg61tj8uSIsQqXC2tw7aW4D/41o6abtN3pxn I9lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698946720; x=1699551520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ldh6u2bWD7MniqjxzXyQCd0Qu18ZZOjaa+NiKkpmJMc=; b=RruOOyN6pAJmIBgsHc1JQUBMeWd34aQU2U2CQbyJEPgX2GtD2rYDb/B7oMkLtl1UjA obq2hYnyiI4xOAxvSJi+DCC9FIYEIVIsisKZsTaRtcMcXcfBgLEvkTRI8QkGV464XnP2 oUvOiJQartlW1JQudjCNCAgJ4fe0Ax18GD/m1JlmaW4n1RE8zNAeHExo0PL/ihu0mMli sS5E2nruMD//6VjbQj6eTQHQwGS5Asa4jMmjX1k1HFNsWMGXzax0FWQup/E5GU4SoL7r DxMVuUPhULFRO2QOpchv2rUu/oFfPchxdeB2YhsVRIb2PC4uxZSYWt9Oy5K4V38e7VoI 3iCg== X-Gm-Message-State: AOJu0YyfwbL4A/SFO9LovMw2/q1tKV2wSVvxrwVhlw3L2LF7znH6pjts e6DqKmMnLeUTRu3ks0/QdJxl7emwahkdgzgi4xc= X-Received: by 2002:a5d:5887:0:b0:32f:7a07:be03 with SMTP id n7-20020a5d5887000000b0032f7a07be03mr14178010wrf.13.1698946720650; Thu, 02 Nov 2023 10:38:40 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id e16-20020adff350000000b003258934a4bcsm3046805wrp.42.2023.11.02.10.38.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 10:38:40 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 07/33] hw/input/stellaris_gamepad: Convert to qemu_input_handler_register() Date: Thu, 2 Nov 2023 17:38:09 +0000 Message-Id: <20231102173835.609985-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102173835.609985-1-peter.maydell@linaro.org> References: <20231102173835.609985-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Now that we have converted to qdev, we can use the newer qemu_input_handler_register() API rather than the legacy qemu_add_kbd_event_handler(). Since we only have one user, take the opportunity to convert from scancodes to QCodes, rather than using qemu_input_key_value_to_scancode() (which adds an 0xe0 prefix and encodes up/down indication in the scancode, which our old handler function then had to reverse). That lets us drop the old state field which was tracking whether we were halfway through a two-byte scancode. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Message-id: 20231030114802.3671871-7-peter.maydell@linaro.org --- include/hw/input/stellaris_gamepad.h | 2 +- hw/arm/stellaris.c | 6 ++++- hw/input/stellaris_gamepad.c | 37 +++++++++++++--------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/hw/input/stellaris_gamepad.h b/include/hw/input/stellaris_gamepad.h index d6a6aecb06d..51085e166ca 100644 --- a/include/hw/input/stellaris_gamepad.h +++ b/include/hw/input/stellaris_gamepad.h @@ -17,6 +17,7 @@ /* * QEMU interface: * + QOM array property "keycodes": uint32_t QEMU keycodes to handle + * (these are QCodes, ie the Q_KEY_* values) * + unnamed GPIO outputs: one per keycode, in the same order as the * "keycodes" array property entries; asserted when key is down */ @@ -31,7 +32,6 @@ struct StellarisGamepad { qemu_irq *irqs; uint32_t *keycodes; uint8_t *pressed; - int extension; }; #endif diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index 707b0dae375..dd90f686bfa 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -32,6 +32,7 @@ #include "hw/qdev-clock.h" #include "qom/object.h" #include "qapi/qmp/qlist.h" +#include "ui/input.h" #define GPIO_A 0 #define GPIO_B 1 @@ -1276,7 +1277,10 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) } if (board->peripherals & BP_GAMEPAD) { QList *gpad_keycode_list = qlist_new(); - static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d }; + static const int gpad_keycode[5] = { + Q_KEY_CODE_UP, Q_KEY_CODE_DOWN, Q_KEY_CODE_LEFT, + Q_KEY_CODE_RIGHT, Q_KEY_CODE_CTRL, + }; DeviceState *gpad; gpad = qdev_new(TYPE_STELLARIS_GAMEPAD); diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index d42ba4f0582..06a0c0ce839 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -15,42 +15,39 @@ #include "migration/vmstate.h" #include "ui/console.h" -static void stellaris_gamepad_put_key(void * opaque, int keycode) +static void stellaris_gamepad_event(DeviceState *dev, QemuConsole *src, + InputEvent *evt) { - StellarisGamepad *s = (StellarisGamepad *)opaque; + StellarisGamepad *s = STELLARIS_GAMEPAD(dev); + InputKeyEvent *key = evt->u.key.data; + int qcode = qemu_input_key_value_to_qcode(key->key); int i; - int down; - - if (keycode == 0xe0 && !s->extension) { - s->extension = 0x80; - return; - } - - down = (keycode & 0x80) == 0; - keycode = (keycode & 0x7f) | s->extension; for (i = 0; i < s->num_buttons; i++) { - if (s->keycodes[i] == keycode && s->pressed[i] != down) { - s->pressed[i] = down; - qemu_set_irq(s->irqs[i], down); + if (s->keycodes[i] == qcode && s->pressed[i] != key->down) { + s->pressed[i] = key->down; + qemu_set_irq(s->irqs[i], key->down); } } - - s->extension = 0; } static const VMStateDescription vmstate_stellaris_gamepad = { .name = "stellaris_gamepad", - .version_id = 3, - .minimum_version_id = 3, + .version_id = 4, + .minimum_version_id = 4, .fields = (VMStateField[]) { - VMSTATE_INT32(extension, StellarisGamepad), VMSTATE_VARRAY_UINT32(pressed, StellarisGamepad, num_buttons, 0, vmstate_info_uint8, uint8_t), VMSTATE_END_OF_LIST() } }; +static const QemuInputHandler stellaris_gamepad_handler = { + .name = "Stellaris Gamepad", + .mask = INPUT_EVENT_MASK_KEY, + .event = stellaris_gamepad_event, +}; + static void stellaris_gamepad_realize(DeviceState *dev, Error **errp) { StellarisGamepad *s = STELLARIS_GAMEPAD(dev); @@ -63,7 +60,7 @@ static void stellaris_gamepad_realize(DeviceState *dev, Error **errp) s->irqs = g_new0(qemu_irq, s->num_buttons); s->pressed = g_new0(uint8_t, s->num_buttons); qdev_init_gpio_out(dev, s->irqs, s->num_buttons); - qemu_add_kbd_event_handler(stellaris_gamepad_put_key, dev); + qemu_input_handler_register(dev, &stellaris_gamepad_handler); } static void stellaris_gamepad_reset_enter(Object *obj, ResetType type)