hid mouse improvements

This commit is contained in:
Benjamin David Lunt 2023-04-09 10:44:00 -07:00 committed by GitHub
parent fd02efa536
commit 0985f9bfec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 980 additions and 312 deletions

View File

@ -455,7 +455,11 @@ int usb_device_c::handle_packet(USBPacket *p)
#endif
memcpy(data, d.data_buf + d.setup_index, l);
d.setup_index += l;
if (d.setup_index >= d.setup_len)
// if the count of bytes transfered is an even packet size, we have to allow the host controller to (possibly) do a short packet
// on the next zero byte transfer, so even if d.setup_index == d.setup_len we still have to allow another packet to be processed before
// we go to SETUP_STATE_ACK. If there is not another IN packet (meaning the STATUS packet is next), the OUT code below handles
// the STATUS stage for us.
if ((d.setup_index >= d.setup_len) && (l < get_mps(USB_CONTROL_EP)))
d.setup_state = SETUP_STATE_ACK;
ret = l;
usb_dump_packet(data, ret, 0, p->devaddr, USB_DIR_IN | p->devep, USB_TRANS_TYPE_CONTROL, false, true);
@ -537,6 +541,8 @@ int usb_device_c::handle_packet(USBPacket *p)
// it is okay for a host to send an OUT before it reads
// all of the expected IN. It is telling the controller
// that it doesn't want any more from that particular call.
// or
// we have (unexpectedly) encountered the STATUS packet.
ret = 0;
d.setup_state = SETUP_STATE_IDLE;
}

File diff suppressed because it is too large Load Diff

View File

@ -2,12 +2,12 @@
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// USB HID emulation support (mouse and tablet) ported from QEMU
// USB keypad emulation based on code by Benjamin D Lunt (fys [at] fysnet [dot] net)
// USB keyboard emulation is an extension to the keypad based on the specs
// USB HID emulation support (mouse and tablet) originally ported from QEMU
// Current USB emulation based on code by Benjamin D Lunt (fys [at] fysnet [dot] net)
//
// Copyright (c) 2005 Fabrice Bellard
// Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com)
// Copyright (C) 2004-2023 Benjamin D Lunt (fys [at] fysnet [dot] net)
// Copyright (C) 2009-2023 The Bochs Project
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@ -32,6 +32,73 @@
#ifndef BX_IODEV_USB_HID_H
#define BX_IODEV_USB_HID_H
// Physical Descriptor Items
#define HID_PHYS_BIAS_NOT_APP 0
#define HID_PHYS_BIAS_RIGHT_HAND 1
#define HID_PHYS_BIAS_LEFT_HAND 2
#define HID_PHYS_BIAS_BOTH_HANDS 3
#define HID_PHYS_BIAS_EITHER_HAND 4
typedef enum
{
None = 0,
Hand, Eyeball, Eyebrow, Eyelid, Ear, Nose, Mouth, UpperLip, LowerLip,
Jaw, Neck, UpperArm, Elbow, Forearm, Wrist, Palm,
Thumb, IndexFinger, MiddleFinger, RingFinger, LittleFinger,
Head, Shoulder, Hip, Waist, Thigh, Knee, Calf, Ankle, Foot, Heel,
BallofFoot, BigToe, SecondToe, ThirdToe, FourthToe, LittleToe,
Brow, Cheek,
} HID_PHYS_DESIGNATOR;
typedef enum
{
NotApp = 0,
Right, Left, Both, Either, Center
} HID_PHYS_QUALIFIER;
// Device Model types
typedef enum
{
// mice (w/o physical descriptor)
hid_mouse_2x2x8 = 0, // 2-button, 2-coords: X and Y coords, 8-bit
hid_mouse_3x3x8, // 3-button, 3-coords: X, Y, and Wheel coords, 8-bit (default)
hid_mouse_3x3x12, // 3-button, 3-coords: X, Y, and Wheel coords, 12-bit
hid_mouse_3x3xDebug, // 3-button, 3-coords: X, Y, and Wheel coords (debug)
hid_mouse_3x3x16, // 3-button, 3-coords: X, Y, and Wheel coords, 16-bit
// mice (w/ physical descriptor)
hid_mouse_3x3x8phy = 10, // 3-button, 3-coords: X, Y, and Wheel coords, 8-bit, Physical Descriptor included
// keyboards
// keypads
// tablets
} HID_MODEL;
// one (or more) of our models uses the Report ID field. This is the ID value used.
#define HID_REPORT_ID 1
// our HID device(s) return two class specific strings, index 4 and index 5
#define HID_CLASS_STR4 4
#define HID_CLASS_STR5 5
#define BX_M_ELEMENTS_SIZE 8
struct USBKBD {
Bit8u code;
Bit8u modkey;
};
#define BX_MODS_NONE 0
#define BX_MODS_LEFT_CTRL (1<<0)
#define BX_MODS_LEFT_SHIFT (1<<1)
#define BX_MODS_LEFT_ALT (1<<2)
#define BX_MODS_LEFT_GUI (1<<3)
#define BX_MODS_RIGHT_CTRL (1<<4)
#define BX_MODS_RIGHT_SHIFT (1<<5)
#define BX_MODS_RIGHT_ALT (1<<6)
#define BX_MODS_RIGHT_GUI (1<<7)
class usb_hid_device_c : public usb_device_c {
public:
@ -39,6 +106,7 @@ public:
virtual ~usb_hid_device_c();
virtual bool init();
virtual bool set_option(const char *option);
virtual const char *get_info();
virtual void handle_reset();
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
@ -46,10 +114,9 @@ public:
virtual void register_state_specific(bx_list_c *parent);
private:
struct {
struct HID_STATE {
bool has_events;
Bit8u idle;
bool boot_protocol; // 0 = boot protocol, 1 = report protocol
int mouse_delayed_dx;
int mouse_delayed_dy;
Bit16s mouse_x;
@ -57,11 +124,20 @@ private:
Bit8s mouse_z;
Bit8u b_state;
Bit8u mouse_event_count;
Bit8u mouse_event_buf[BX_KBD_ELEMENTS][6];
Bit8u mouse_event_buf[BX_KBD_ELEMENTS][BX_M_ELEMENTS_SIZE];
int mouse_event_buf_len[BX_KBD_ELEMENTS];
Bit8u kbd_packet[8];
int kbd_packet_indx;
Bit8u indicators;
Bit8u kbd_event_count;
Bit32u kbd_event_buf[BX_KBD_ELEMENTS];
// the remaining does not get cleared on a handle_reset()
HID_MODEL model;
Bit8u report_use_id; // id that we will use as soon as the HID report has been requested
Bit8u report_id; // id that we will use after the HID report has been requested
bool boot_protocol; // 0 = boot protocol, 1 = report protocol
int bx_mouse_hid_report_descriptor_len;
const Bit8u *bx_mouse_hid_report_descriptor;
} s;
int timer_index;
@ -73,10 +149,10 @@ private:
static void mouse_enabled_changed(void *dev, bool enabled);
static void mouse_enq_static(void *dev, int delta_x, int delta_y, int delta_z, unsigned button_state, bool absxy);
void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state, bool absxy);
int mouse_poll(Bit8u *buf, int len, bool force);
int create_mouse_packet(Bit8u *buf, int len);
int get_mouse_packet(Bit8u *buf, int len);
int keyboard_poll(Bit8u *buf, int len, bool force);
int mouse_poll(Bit8u *buf, bool force);
int create_mouse_packet(Bit8u *buf);
int get_mouse_packet(Bit8u *buf);
int keyboard_poll(Bit8u *buf, bool force);
static void hid_timer_handler(void *);
void start_idle_timer(void);