Forked to make modifications to bring the USBHID into USB compliance and add additional features.
Fork of USBDevice by
As of Revision 18 everything in the USBHID specification is now implemented, except Multi-reports.
Revision comments for changelist 18
USBHID.cpp
- Added SET_PROTOCOL support
- Added GET_PROTOCOL support
- protocolSate is set to 1 by default to match USB HID specification. This variable should be checked to determine which format theinput report should have. 1 - Use the user specified report format. 0 - Use the BOOT protocol report format.
Revision comments for changelist 16
- HID_REPORT transformed from structure to class. This was done for several reasons.
- When multiple reports are used the 64 byte size for every report becomes a problem.
- The length value should always remain the same for a report, Make the constructor set the vale at the same time it allocates memory for the DATA area.
- By default the data will be an array of MAX_HID_REPORT_SIZE like the structure,
- When given a length argument, the hid_report.length will be set, and hid_report.data will be an array of the size given.
- Length zero causes data to be NULL
- Mostly backwards compatible. The definition of a destructor caused a compiler error in USBMouse::update and USBMousekeyboard::update. This error was caused by instatiation of HID_REPORT in the middle of an IF logic statement. These files have been modified. The error complained that the logic skipped object initialization. The HID_REPORT has been moved to the class definition. Since both ABSOLUTE and RELATIVE modes used the HID_REPORT, this seems to make more sense. Previously the hid_report would be instatiated in <class>::mousesend and <class>::update.
Revision comments for changelist 14
USBdevice.cpp
- Modified USB device state to change from Configure when disconnect is called.
- Modified the call back function for when the suspend state changes. This should be used to turn off peripherals to conserve power.
Revision comments for changelist 13
USBdevice.cpp
- ) Changed DEBUG messages to be more descriptive for string descriptor
- ) Bug fix: Control Transfers did not actually transfer the data from Buffer to transfer->ptr
USBHIDTypes.h
- ) Added ALL CLASS request to KEYWORD list
- ) Added KEYWORDS for report type
USBHID.h
- ) Added a new constructor to specify size of feature report
- ) Added HID_REPORT inputReport and featureReport
- ) Added data structures to support IDLE rate
- ) Added data structures to support callback functions
USBHID.cpp
- ) Changed constructor to initialize new feature data structures
- ) Implemented Set_IDLE/GET_IDLE and the periodic resend of non-changed data
- ) Implemented HID specification required control transfer GET_REPORT
- ) Fixed issue where Intreput transfers and control transfers did not access the same data structures.
- ) Implemented Feature reports
- ) Implemented Callback Hooks for get_report/set_report actions.
- ) Added callback hooks for interupt actions in the new functions.
- ) interupt transfer can now write to outputReport
- ) Modified SET_REPORT code to function for multiple types.
- ) Refactored some code in preperation to add multi report support
Test Number | Test Description | Test Result | Notes | ||||||
1 | Use USBmouse to verify backward compatibility of constructor and methods | Pass | |||||||
2 | Test SET_REPORT can set a feature report | Pass | |||||||
3 | Test GET_REPORT can retrieve a feature report | Pass | |||||||
4 | Test SET_IDLE sets up a reoccuring trigger | Pass | IOCTL_SET_POLL_FREQUENCY_MSEC does not function for the windows HID driver. A Special test program is used to rearm the IDLE rate after windows sets it to zero | ||||||
5 | Test SET_IDLE disables a trigger | Pass | Windows automatically sends this command to a HID device when it is inserted. | ||||||
6 | Enabled DEBUG in USBDevice.cpp and generated str descriptor requests. | Pass | |||||||
7 | Test SET_REPORT can set an output report | Pass | |||||||
8 | Test GET_REPORT can retrieve an output report | Pass | |||||||
9 | ReadFile, accesses the input_report | Pass | |||||||
10 | WriteFile accesses the output_report, via interupt transfer when ep1_out is used. | Pass | |||||||
11 | WriteFile accesses the output_report, via control transfer when ep1_out is NOT used. | Not Tested | |||||||
12 | Callback hooks trigger independently for each type of set_report/get_report | Pass | |||||||
13 | New constructor sets feature_report size | Pass | |||||||
14 | Control transfer SET_REPORT and writeFile access the same data structure | BUG | The same data structure is accessed, but the data transfer size is different. The writeFile strips the leading byte which is the report ID, The Control transfer keeps the byte. | ||||||
15 | Control transfer GET_REPORT and readFile access the same data structure | BUG | The same dtat structure is accessed, but the data transfer size is different. The readFile strips the leading byte which is the report ID, The Control transfer keeps the byte. | ||||||
16 | Test GET_IDLE retrieves the IDLE rate | Unknown | Windows HID driver does not implement IOCTL_HID_GET_POLL_FREQUENCY_MSEC |
USBSerial/USBCDC.cpp
- Committer:
- samux
- Date:
- 2012-10-14
- Revision:
- 5:d27e4c226965
- Parent:
- 1:80ab0d068708
- Child:
- 6:d0945750af57
File content as of revision 5:d27e4c226965:
/* Copyright (c) 2010-2011 mbed.org, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "stdint.h" #include "USBCDC.h" static uint8_t cdc_line_coding[7]= {0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08}; #define DEFAULT_CONFIGURATION (1) #define CDC_SET_LINE_CODING 0x20 #define CDC_GET_LINE_CODING 0x21 #define CDC_SET_CONTROL_LINE_STATE 0x22 #define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) { USBDevice::connect(); } bool USBCDC::USBCallback_request(void) { /* Called in ISR context */ bool success = false; CONTROL_TRANSFER * transfer = getTransferPtr(); /* Process class-specific requests */ if (transfer->setup.bmRequestType.Type == CLASS_TYPE) { switch (transfer->setup.bRequest) { case CDC_GET_LINE_CODING: transfer->remaining = 7; transfer->ptr = cdc_line_coding; transfer->direction = DEVICE_TO_HOST; success = true; break; case CDC_SET_LINE_CODING: transfer->remaining = 7; success = true; break; case CDC_SET_CONTROL_LINE_STATE: success = true; break; default: break; } } return success; } // Called in ISR context // Set configuration. Return false if the // configuration is not supported. bool USBCDC::USBCallback_setConfiguration(uint8_t configuration) { if (configuration != DEFAULT_CONFIGURATION) { return false; } // Configure endpoints > 0 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT); addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK); addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); // We activate the endpoint to be able to recceive data readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); return true; } bool USBCDC::send(uint8_t * buffer, uint32_t size) { return USBDevice::write(EPBULK_IN, buffer, size, MAX_CDC_REPORT_SIZE); } bool USBCDC::readEP(uint8_t * buffer, uint32_t * size) { if (!USBDevice::readEP(EPBULK_OUT, buffer, size, MAX_CDC_REPORT_SIZE)) return false; if (!readStart(EPBULK_OUT, MAX_CDC_REPORT_SIZE)) return false; return true; } bool USBCDC::readEP_NB(uint8_t * buffer, uint32_t * size) { if (!USBDevice::readEP_NB(EPBULK_OUT, buffer, size, MAX_CDC_REPORT_SIZE)) return false; if (!readStart(EPBULK_OUT, MAX_CDC_REPORT_SIZE)) return false; return true; } uint8_t * USBCDC::deviceDesc() { static uint8_t deviceDescriptor[] = { 18, // bLength 1, // bDescriptorType 0x10, 0x01, // bcdUSB 2, // bDeviceClass 0, // bDeviceSubClass 0, // bDeviceProtocol MAX_PACKET_SIZE_EP0, // bMaxPacketSize0 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor LSB(PRODUCT_ID), MSB(PRODUCT_ID),// idProduct 0x00, 0x01, // bcdDevice 1, // iManufacturer 2, // iProduct 3, // iSerialNumber 1 // bNumConfigurations }; return deviceDescriptor; } uint8_t * USBCDC::stringIinterfaceDesc() { static uint8_t stringIinterfaceDescriptor[] = { 0x08, STRING_DESCRIPTOR, 'C',0,'D',0,'C',0, }; return stringIinterfaceDescriptor; } uint8_t * USBCDC::stringIproductDesc() { static uint8_t stringIproductDescriptor[] = { 0x16, STRING_DESCRIPTOR, 'C',0,'D',0,'C',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 }; return stringIproductDescriptor; } #define CONFIG1_DESC_SIZE (9+9+5+5+4+5+7+9+7+7) uint8_t * USBCDC::configurationDesc() { static uint8_t configDescriptor[] = { 9, // bLength; 2, // bDescriptorType; LSB(CONFIG1_DESC_SIZE), // wTotalLength MSB(CONFIG1_DESC_SIZE), 2, // bNumInterfaces 1, // bConfigurationValue 0, // iConfiguration 0x80, // bmAttributes 50, // bMaxPower // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 9, // bLength 4, // bDescriptorType 0, // bInterfaceNumber 0, // bAlternateSetting 1, // bNumEndpoints 0x02, // bInterfaceClass 0x02, // bInterfaceSubClass 0x01, // bInterfaceProtocol 0, // iInterface // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26 5, // bFunctionLength 0x24, // bDescriptorType 0x00, // bDescriptorSubtype 0x10, 0x01, // bcdCDC // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27 5, // bFunctionLength 0x24, // bDescriptorType 0x01, // bDescriptorSubtype 0x03, // bmCapabilities 1, // bDataInterface // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28 4, // bFunctionLength 0x24, // bDescriptorType 0x02, // bDescriptorSubtype 0x06, // bmCapabilities // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33 5, // bFunctionLength 0x24, // bDescriptorType 0x06, // bDescriptorSubtype 0, // bMasterInterface 1, // bSlaveInterface0 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 ENDPOINT_DESCRIPTOR_LENGTH, // bLength ENDPOINT_DESCRIPTOR, // bDescriptorType PHY_TO_DESC(EPINT_IN), // bEndpointAddress E_INTERRUPT, // bmAttributes (0x03=intr) LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) 16, // bInterval // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 9, // bLength 4, // bDescriptorType 1, // bInterfaceNumber 0, // bAlternateSetting 2, // bNumEndpoints 0x0A, // bInterfaceClass 0x00, // bInterfaceSubClass 0x00, // bInterfaceProtocol 0, // iInterface // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 7, // bLength 5, // bDescriptorType PHY_TO_DESC(EPBULK_IN), // bEndpointAddress 0x02, // bmAttributes (0x02=bulk) LSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (LSB) MSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (MSB) 0, // bInterval // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 7, // bLength 5, // bDescriptorType PHY_TO_DESC(EPBULK_OUT),// bEndpointAddress 0x02, // bmAttributes (0x02=bulk) LSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (LSB) MSB(MAX_PACKET_SIZE_EPBULK), // wMaxPacketSize (MSB) 0 // bInterval }; return configDescriptor; }