Permalink
Browse files

fixed descriptor parser HID_CLASS error

  • Loading branch information...
felis committed Sep 23, 2010
1 parent 608f3ac commit 4346aff086f2b101423266558b46c5ca651a00dc
Showing with 18 additions and 11 deletions.
  1. +1 −1 Usb.cpp
  2. +6 −6 ch9.h
  3. +3 −1 examples/descriptor_parser.h
  4. +8 −3 examples/descriptor_parser.pde
View
@@ -322,7 +322,7 @@ void USB::Task( void ) //USB state machine
delay = millis() + 20; //20ms wait after reset per USB spec
}
break;
- case USB_ATTACHED_SUBSTATE_WAIT_SOF:
+ case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order
if( regRd( rHIRQ ) & bmFRAMEIRQ ) { //when first SOF received we can continue
if( delay < millis() ) { //20ms passed
usb_task_state = USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE;
View
12 ch9.h
@@ -155,12 +155,12 @@ typedef struct
/* HID descriptor */
typedef struct {
- byte bLength;
- byte bDescriptorType;
- unsigned int bcdHID;
- byte bCountryCode;
- byte bNumDescriptors;
- byte bDescrType;
+ byte bLength;
+ byte bDescriptorType;
+ unsigned int bcdHID;
+ byte bCountryCode;
+ byte bNumDescriptors;
+ byte bDescrType;
unsigned int wDescriptorLength;
} USB_HID_DESCRIPTOR;
@@ -8,6 +8,7 @@
typedef void (*PARSE)( uint8_t bytes );
/* Common Messages */
+
const char descr_len [] PROGMEM = "\r\nDescriptor Length:\t";
const char descr_type [] PROGMEM = "\r\nDescriptor type:\t";
const char class_str [] PROGMEM = "\r\nClass:\t\t\t";
@@ -19,6 +20,7 @@ const char reserved_msg [] PROGMEM = "Reserved";
const char rcode_error_msg [] PROGMEM = "\r\nRequest error. Reurn code: ";
/* Endpoint attributes */
+
const char control_tr [] PROGMEM = "Control";
const char iso_tr [] PROGMEM = "Isochronous";
const char bulk_tr [] PROGMEM = "Bulk";
@@ -279,4 +281,4 @@ const char * usage_pages [] PROGMEM =
up_uni
};
-#endif //_DESCRIPTOR_PARSER_
+#endif //_DESCRIPTOR_PARSER_
@@ -12,13 +12,18 @@
#define getReportDescr( addr, ep, nbytes, parse_func, nak_limit ) ctrlXfer( addr, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_REPORT, 0x0000, nbytes, parse_func, nak_limit )
#define getReport( addr, ep, nbytes, interface, report_type, report_id, parse_func, nak_limit ) ctrlXfer( addr, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, interface, nbytes, parse_func, nak_limit )
-
/* Foeward declarations */
void setup();
void loop();
byte ctrlXfer( byte addr, byte ep, byte bmReqType, byte bRequest, byte wValLo, byte wValHi, unsigned int wInd, uint16_t nbytes, PARSE parse_func, uint16_t nak_limit );
void HIDreport_parse( uint8_t* buf, uint8_t* head, uint8_t* tail);
+typedef struct {
+ uint8_t bDescriptorType;
+ uint16_t wDescriptorLength;
+} HID_CLASS_DESCRIPTOR;
+
+
//typedef void (*PARSE)( int8_t*, int8_t*, int8_t );
MAX3421E Max;
@@ -390,7 +395,7 @@ void printhid_descr( char* descr_ptr )
descr_ptr += 6; //advance buffer pointer
for( uint8_t i = 0; i < tmpbyte; i++ ) {
uint8_t tmpdata;
- HID_CLASS* hidclass_ptr = ( HID_CLASS* )descr_ptr;
+ HID_CLASS_DESCRIPTOR* hidclass_ptr = ( HID_CLASS_DESCRIPTOR* )descr_ptr;
tmpdata = hidclass_ptr->bDescriptorType;
printProgStr(PSTR("\r\nClass Descriptor Type:\t"));
Serial.print( tmpdata, HEX );
@@ -712,4 +717,4 @@ void printProgStr(const char* str)
Serial.print(c,BYTE);
}
return;
-}
+}

2 comments on commit 4346aff

There is a bug in this. It appears if the device has multiple interfaces. Only the first HID report descriptor is right, because getReportDescr() always uses interface number 0.

Owner

felis replied Jan 13, 2011

Thanks, I'll keep this in mind for the next revision!

Oleg.

Please sign in to comment.