Skip to content

Commit

Permalink
Implement enough of hid4 that we can poll a GH guitar
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjay900 committed Oct 17, 2023
1 parent 7e5f12f commit e308bd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 2 additions & 0 deletions include/usb_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct {
/* VID and PID */
u16 vid;
u16 pid;
u16 max_packet_len;
u8 endpoint_address;
/* Used to communicate with Wii's USB module */
int host_fd;
u32 dev_id;
Expand Down
17 changes: 11 additions & 6 deletions source/usb_drivers/sony_ds3.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ static inline void turntable_get_analog_axis(const struct turntable_input_report

static int ds3_set_operational(usb_input_device_t *device)
{
return 0;
u8 buf[17] ATTRIBUTE_ALIGN(32);
return usb_device_driver_issue_ctrl_transfer(device,
USB_REQTYPE_INTERFACE_GET,
Expand All @@ -640,16 +641,20 @@ static int ds3_set_operational(usb_input_device_t *device)

static inline int ds3_request_data(usb_input_device_t *device)
{
return usb_device_driver_issue_ctrl_transfer_async(device,
USB_REQTYPE_INTERFACE_GET,
USB_REQ_GETREPORT,
(USB_REPTYPE_INPUT << 8) | 0x01, 0,
device->usb_async_resp,
32);
return usb_device_driver_issue_intr_transfer_async(device, device->endpoint_address, device->usb_async_resp,
device->max_packet_len);

// return usb_device_driver_issue_ctrl_transfer_async(device,
// USB_REQTYPE_INTERFACE_GET,
// USB_REQ_GETREPORT,
// (USB_REPTYPE_INPUT << 8) | 0x01, 0,
// device->usb_async_resp,
// device->max_packet_len);
}

static int ds3_set_leds_rumble(usb_input_device_t *device, u8 leds, const struct ds3_rumble *rumble)
{
return 0;
u8 buf[] ATTRIBUTE_ALIGN(32) = {
0x00, /* Padding */
0x00, 0x00, 0x00, 0x00, /* Rumble (r, r, l, l) */
Expand Down
43 changes: 20 additions & 23 deletions source/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ struct usb_hid_v4_transfer {
void* data; // virtual pointer, not physical!
} ATTRIBUTE_PACKED; // 32 bytes

struct usb_endpoint_descriptor {
u8 bLength; // Length of this descriptor.
u8 bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
u8 bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
u8 bmAttributes; // Endpoint transfer type.
u16 wMaxPacketSize; // Maximum packet size.
u8 bInterval; // Polling interval in frames.
} ATTRIBUTE_PACKED;

static_assert(sizeof(struct usb_hid_v5_transfer) == 64);
static_assert(sizeof(struct usb_hid_v4_transfer) == 32);

Expand Down Expand Up @@ -602,6 +593,8 @@ static void handle_v4_device_change_reply(int host_fd, areply *reply)
u16 vid, pid;
u32 vid_pid;
u32 dev_id;
u16 packet_size = 128;
u8 endpoint_address = 0;
bool found;

DEBUG("Device change, #Attached devices: %d\n", reply->result);
Expand Down Expand Up @@ -640,20 +633,22 @@ static void handle_v4_device_change_reply(int host_fd, areply *reply)
vid = (vid_pid >> 16) & 0xFFFF;
pid = vid_pid & 0xFFFF;
DEBUG("[%d] VID: 0x%04x, PID: 0x%04x, dev_id: 0x%x\n", i, vid, pid, dev_id);
// u32 total_len = device_change_devices[i] / 4;
// int j = 0;
// while (j < total_len) {
// struct usb_endpoint_descriptor* desc = (struct usb_endpoint_descriptor*)(device_change_devices + i);
// if (desc->bDescriptorType == 5) {
// int in = (desc->bEndpointAddress & USB_ENDPOINT_IN);
// if (in) {
// endpoint_address = desc->bEndpointAddress;
// packet_size = desc->wMaxPacketSize;
// break;
// }
// }
// j += desc->bLength;
// }
u32 total_len = device_change_v4_devices[i] / 4;
int j = 2;
while (j < total_len) {
u8 len = (device_change_v4_devices[i+j] >> 24) & 0xFF;
u8 type = (device_change_v4_devices[i+j] >> 16) & 0xFF;
if (type == 5) {
u8 addr = (device_change_v4_devices[i+j] >> 8) & 0xFF;
int in = (addr & USB_ENDPOINT_IN);
if (in) {
packet_size = (device_change_v4_devices[i+j+1] >> 16) & 0xFFFF;
endpoint_address = addr;
break;
}
}
j += (len / 4) + 1;
}

/* Find if we have a driver for that VID/PID */
driver = get_usb_device_driver_for(vid, pid);
Expand All @@ -678,8 +673,10 @@ static void handle_v4_device_change_reply(int host_fd, areply *reply)
device->vid = vid;
device->pid = pid;
device->host_fd = host_fd;
device->max_packet_len = packet_size;
device->dev_id = dev_id;
device->driver = driver;
device->endpoint_address = endpoint_address;
/* We will get a fake Wiimote assigneed at the init() callback */
device->wiimote = NULL;
device->suspended = false;
Expand Down

0 comments on commit e308bd0

Please sign in to comment.