From 90aae554700e7c2a332d927cf7dca380ce2f766f Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sun, 9 Oct 2016 23:47:36 -0400 Subject: [PATCH] Support for an extra interrupt endpoint - Reduced interrupt endpoint size (reports are 15 bytes so it fits in 16) --- usb.c | 169 +++++++++++++++++++++++++++++++++++++--------------------- usb.h | 9 ++-- 2 files changed, 113 insertions(+), 65 deletions(-) diff --git a/usb.c b/usb.c index 430c946..0484aca 100644 --- a/usb.c +++ b/usb.c @@ -1,5 +1,5 @@ /* gc_n64_usb : Gamecube or N64 controller to USB firmware - Copyright (C) 2007-2013 Raphael Assenat + Copyright (C) 2007-2016 Raphael Assenat This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,6 +37,8 @@ static uint8_t g_device_state = STATE_DEFAULT; static uint8_t g_current_config; static void *interrupt_data; static volatile int interrupt_data_len = -1; +static void *interrupt_data3; +static volatile int interrupt_data_len3 = -1; #define CONTROL_WRITE_BUFSIZE 64 static struct usb_request control_write_rq; @@ -64,7 +66,7 @@ static int wcslen(const wchar_t *str) return i; } -static void setupEndpoints(void) +static void setupEndpoints() { /*** EP0 ***/ @@ -89,7 +91,7 @@ static void setupEndpoints(void) UECONX = 1<n_hid_interfaces > 2) { + /*** EP3 ***/ + UENUM = 0x03; // select endpoint + + UECONX = 1< 64) { + buf2EP(0, data+pos, 64, 64, progmem); + UEINTX &= ~(1<flags & USB_PARAM_FLAG_DEVDESC_PROGMEM); break; case CONFIGURATION_DESCRIPTOR: - // Check index if more than 1 config - buf2EP(0, (unsigned char*)g_params->configdesc, g_params->configdesc_ttllen, + // Would need to check index if more than 1 configs... + longDescriptorHelper(g_params->configdesc, g_params->configdesc_ttllen, rq->wLength, g_params->flags & USB_PARAM_FLAG_CONFDESC_PROGMEM); break; case STRING_DESCRIPTOR: @@ -352,51 +398,17 @@ static void handleSetupPacket(struct usb_request *rq) { case REPORT_DESCRIPTOR: { - uint16_t rqlen = rq->wLength; - uint16_t todo = rqlen; - uint16_t pos = 0; - unsigned char *reportdesc; - // HID 1.1 : 7.1.1 Get_Descriptor request. wIndex is the interface number. // - if (rq->wIndex > g_params->n_hid_interfaces) + if (rq->wIndex > g_params->n_hid_interfaces) { + unhandled = 1; break; - - reportdesc = (unsigned char*)g_params->hid_params[rq->wIndex].reportdesc; - if (rqlen > g_params->hid_params[rq->wIndex].reportdesc_len) { -// rqlen = g_params->hid_params[rq->wIndex].reportdesc_len; - }; - -// printf_P(PSTR("t: %02x, rq: 0x%02x, val: %04x, l: %d\r\n"), rq->bmRequestType, rq->bRequest, rq->wValue, rq->wLength); - - while(1) - { -// printf_P(PSTR("pos %d todo %d\r\n"), pos, todo); - if (todo > 64) { - buf2EP(0, reportdesc+pos, 64, - 64, - g_params->flags & USB_PARAM_FLAG_REPORTDESC_PROGMEM); - UEINTX &= ~(1<flags & USB_PARAM_FLAG_REPORTDESC_PROGMEM); - UEINTX &= ~(1<hid_params[rq->wIndex].reportdesc, + g_params->hid_params[rq->wIndex].reportdesc_len, + rq->wLength, + g_params->flags & USB_PARAM_FLAG_REPORTDESC_PROGMEM); } break; @@ -576,6 +588,28 @@ ISR(USB_GEN_vect) } } +static void handle_interrupt_xmit(uint8_t ep, void **interrupt_data, volatile int *interrupt_data_len) +{ + uint8_t i; + + UENUM = ep; + i = UEINTX; + + if (i & (1<