Hi all,
I am trying the keil usbhid example with my board and gui. My aim is to send three adc value to my gui by usb. but i can send only one adc data, i can't send the other two. I have tried to change the descriptor file but i couldn't. I think i have to send my adc data as byte pockets, in other words as char array, but i couldn't set them. If you know how i can do it please help me.
for now, simplehidwrite can only get InReport[0] data but it can't get the others. my edited last desc files are below:
usbdesc.c:
#define HID_INPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_OUTPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_FEATURE_REPORT_BYTES 8 /* size of report in Bytes */ const U8 HID_ReportDescriptor[] = { HID_UsagePageVendor(0x00), HID_Usage(0x01), HID_Collection(HID_Application), HID_UsagePage(HID_USAGE_PAGE_BUTTON), HID_UsageMin(1), HID_UsageMax(3), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportCount(3), HID_ReportSize(1), HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(5), HID_Input(HID_Constant), HID_UsagePage(HID_USAGE_PAGE_LED), HID_Usage(HID_USAGE_LED_GENERIC_INDICATOR), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportCount(8), HID_ReportSize(8), HID_Output(HID_Data | HID_Variable | HID_Absolute), HID_EndCollection, }; const U16 HID_ReportDescSize = sizeof(HID_ReportDescriptor); /* USB Standard Device Descriptor */ const U8 USB_DeviceDescriptor[] = { USB_DEVICE_DESC_SIZE, /* bLength */ USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0200), /* 2.00 */ /* bcdUSB */ 0x00, /* bDeviceClass */ 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ USB_MAX_PACKET0, /* bMaxPacketSize0 */ WBVAL(0xC251), /* idVendor */ WBVAL(0x2201), /* idProduct */ WBVAL(0x0100), /* 1.00 */ /* bcdDevice */ 0x01, /* iManufacturer */ 0x02, /* iProduct */ 0x03, /* iSerialNumber */ 0x01 /* bNumConfigurations: one possible configuration*/ }; /* USB Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor) */ const U8 USB_ConfigDescriptor[] = { /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bLength */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + USB_ENDPOINT_DESC_SIZE // added // added ), 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue: 0x01 is used to select this configuration */ 0x00, /* iConfiguration: no string to describe this configuration */ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */ /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower, device power consumption is 100 mA */ /* Interface 0, Alternate Setting 0, HID Class */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ // 0x01, /* bNumEndpoints */ 0x01, /* bNumEndpoints */ USB_DEVICE_CLASS_HUMAN_INTERFACE, /* bInterfaceClass */ HID_SUBCLASS_NONE, /* bInterfaceSubClass */ HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x04, /* iInterface */ /* HID Class Descriptor */ /* HID_DESC_OFFSET = 0x0012 */ HID_DESC_SIZE, /* bLength */ HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0100), /* 1.00 */ /* bcdHID */ 0x00, /* bCountryCode */ 0x01, /* bNumDescriptors */ HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */ /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ // WBVAL(0x0004), /* wMaxPacketSize */ WBVAL(0x0008), /* wMaxPacketSize */ 0x01, /* 32ms */ /* bInterval */ // 0x01, /* 1ms */ /* bInterval */ /* Endpoint, HID Interrupt Out */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ // WBVAL(0x0004), /* wMaxPacketSize */ WBVAL(0x0008), /* wMaxPacketSize */ 0x01, /* 32ms */ /* bInterval */ // 0x01, /* 1ms */ /* bInterval */ /* Terminator */ 0 /* bLength */ };
hiduser.c
BOOL HID_GetReport (void) { /* ReportID = SetupPacket.wValue.WB.L; */ switch (SetupPacket.wValue.WB.H) { case HID_REPORT_INPUT: GetInReport(); // EP0Buf[0] = InReport; // memcpy( EP0Buf, InReport, SetupPacket.wLength ); memcpy(&EP0Buf[0],&InReport[0], 8); break; case HID_REPORT_OUTPUT: return (__FALSE); /* Not Supported */ case HID_REPORT_FEATURE: /* EP0Buf[] = ...; */ /* break; */ return (__FALSE); /* Not Supported */ } return (__TRUE); } /* * HID Set Report Request Callback * Called automatically on HID Set Report Request * Parameters: None (global SetupPacket and EP0Buf) * Return Value: TRUE - Success, FALSE - Error */ BOOL HID_SetReport (void) { /* ReportID = SetupPacket.wValue.WB.L; */ switch (SetupPacket.wValue.WB.H) { case HID_REPORT_INPUT: return (__FALSE); /* Not Supported */ case HID_REPORT_OUTPUT: //OutReport = EP0Buf[0]; memcpy( &OutReport[0], &EP0Buf[0], SetupPacket.wLength ); SetOutReport(); break; case HID_REPORT_FEATURE: return (__FALSE); /* Not Supported */ } return (__TRUE); }
demo.c
U8 InReport[8]; U8 OutReport[8]; void GetInReport (void) { InReport[0]=50; }
if you can see something wrong please inform me . By the way thanks for replies.
bakaci.
I'm really not good with USB, but one thing makes me curious.
When something has a name wMaxPacketSize, that seems to indicate that the packet can actually be smaller. So if the packet can be max 8 bytes - how do the USB stack know if you want to send 8 bytes, or only 3 or 5? When data is processed in the other direction, there is a struct with a member SetupPacket.wLength that informs about about the amount of data.
Modify report descriptor, so that it defines the report size as you expect.
#define HID_INPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_OUTPUT_REPORT_BYTES 8 /* size of report in Bytes */ #define HID_FEATURE_REPORT_BYTES 8 /* size of report in Bytes */ const U8 HID_ReportDescriptor[] = { HID_UsagePageVendor( 0x00 ), HID_Usage ( 0x01 ), HID_Collection ( HID_Application ), HID_LogicalMin ( 0 ), /* value range: 0 - 0xFF */ HID_LogicalMaxS ( 0xFF ), HID_ReportSize ( 8 ), /* 8 bits */ HID_ReportCount ( HID_INPUT_REPORT_BYTES ), HID_Usage ( 0x01 ), HID_Input ( HID_Data | HID_Variable | HID_Absolute ), HID_ReportCount ( HID_OUTPUT_REPORT_BYTES ), HID_Usage ( 0x01 ), HID_Output ( HID_Data | HID_Variable | HID_Absolute ), HID_ReportCount ( HID_FEATURE_REPORT_BYTES), HID_Usage ( 0x01 ), HID_Feature ( HID_Data | HID_Variable | HID_Absolute ), HID_EndCollection, };
Tsuneo