diff -Nru ../HIDKeys.2006-03-14/usbdrv/usbdrv.c usbdrv/usbdrv.c --- ../HIDKeys.2006-03-14/usbdrv/usbdrv.c 2006-03-14 10:50:43.000000000 -0500 +++ usbdrv/usbdrv.c 2006-04-25 21:45:24.000000000 -0400 @@ -15,7 +15,7 @@ #endif #include "usbdrv.h" #include "oddebug.h" - +#include "../leds.h" /* General Description: This module implements the C-part of the USB driver. See usbdrv.h for a @@ -64,6 +64,10 @@ #define USB_FLG_MSGPTR_IS_ROM (1<<6) #define USB_FLG_USE_DEFAULT_RW (1<<7) +/* Parameters that are configurable at runtime */ +const char *rt_usbHidReportDescriptor; +uchar rt_usbHidReportDescriptorSize; + /* optimizing hints: - do not post/pre inc/dec integer values in operations @@ -107,7 +111,7 @@ 9, /* sizeof(usbDescrConfig): length of descriptor in bytes */ USBDESCR_CONFIG, /* descriptor type */ (18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT -#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH || defined(USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME) + 9 #endif ), 0, /* total length of data returned (including inlined descriptors) */ @@ -130,14 +134,19 @@ USB_CFG_INTERFACE_SUBCLASS, USB_CFG_INTERFACE_PROTOCOL, 0, /* string index for interface */ -#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH /* HID descriptor */ +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH || defined(USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME) /* HID descriptor */ 9, /* sizeof(usbDescrHID): length of descriptor in bytes */ USBDESCR_HID, /* descriptor type: HID */ 0x01, 0x01, /* BCD representation of HID version */ 0x00, /* target country code */ 0x01, /* number of HID Report (or other HID class) Descriptor infos to follow */ 0x22, /* descriptor type: report */ - USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, 0, /* total length of report descriptor */ +#ifndef USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH + 0, /* substituted with real value on the fly in usbRead */ +#else + USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH, +#endif + 0, /* total length of report descriptor */ #endif #if USB_CFG_HAVE_INTRIN_ENDPOINT /* endpoint descriptor for endpoint 1 */ 7, /* sizeof(usbDescrEndpoint) */ @@ -235,7 +244,17 @@ if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ while(i--){ uchar c = PRG_RDB(r); /* assign to char size variable to enforce byte ops */ - *data++ = c; +#ifdef USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME + if ((usbDescrConfig + 18 + 7) == (void*)r) { + *data++ = rt_usbHidReportDescriptorSize; + } + else { + *data++ = c; + } +#else + *data++ = c; +#endif + r++; } }else{ /* RAM data */ @@ -264,6 +283,8 @@ { usbRequest_t *rq = (void *)data; uchar replyLen = 0, flags = USB_FLG_USE_DEFAULT_RW; + + /* We use if() cascades because the compare is done byte-wise while switch() * is int-based. The if() cascades are therefore more efficient. */ @@ -321,13 +342,22 @@ #endif } } -#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH || defined(USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME) else if(rq->wValue.bytes[1] == USBDESCR_HID){ /* 0x21 */ replyLen = 9; replyData = (uchar *)usbDescrConfig + 18; }else if(rq->wValue.bytes[1] == USBDESCR_HID_REPORT){ /* 0x22 */ +#ifdef USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH replyLen = USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH; replyData = (uchar *)usbHidReportDescriptor; +#endif +#ifdef USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME + replyLen = rt_usbHidReportDescriptorSize; + replyData = (uchar *)rt_usbHidReportDescriptor; + //replyData = snes_usbHidReportDescriptor; +// if (replyData != (void*)0x86) { LED_ON(); } +// if (replyLen != 42) { LED_ON(); } +#endif } #endif }else if(rq->bRequest == USBRQ_GET_CONFIGURATION){ /* 8 */ diff -Nru ../HIDKeys.2006-03-14/usbdrv/usbdrv.h usbdrv/usbdrv.h --- ../HIDKeys.2006-03-14/usbdrv/usbdrv.h 2006-03-14 10:50:43.000000000 -0500 +++ usbdrv/usbdrv.h 2006-04-25 19:23:58.000000000 -0400 @@ -198,7 +198,7 @@ * message already buffered will be lost. */ #endif /* USB_CFG_HAVE_INTRIN_ENDPOINT */ -#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH +#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH extern PROGMEM const char usbHidReportDescriptor[]; /* If you implement an HID device, you need to provide a report descriptor. * The HID report descriptor syntax is a bit complex. If you understand how @@ -207,6 +207,15 @@ * Otherwise you should probably start with a working example. */ #endif /* USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH */ +#ifdef USB_CFG_HID_REPORT_DESCRIPTOR_RUNTIME +/* If you have many different HID report descriptors and + * you want to select one of them at runtime (dip switchs?), + * set those globals variables before initializing the driver. + */ +extern const char *rt_usbHidReportDescriptor; +extern uchar rt_usbHidReportDescriptorSize; +#endif + #if USB_CFG_IMPLEMENT_FN_WRITE extern uchar usbFunctionWrite(uchar *data, uchar len); /* This function is called by the driver to provide a control transfer's