USB HID device for CMSIS-DAP
Dependents: lpcterm2 Simple-CMSIS-DAP
Revision 2:7dee016756ce, committed 2014-07-05
- Comitter:
- va009039
- Date:
- Sat Jul 05 08:19:19 2014 +0000
- Parent:
- 1:366f6f649a7d
- Commit message:
- setting the product name.
Changed in this revision
USBDAP.cpp | Show annotated file Show diff for this revision Revisions of this file |
USBDAP.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 366f6f649a7d -r 7dee016756ce USBDAP.cpp --- a/USBDAP.cpp Tue Apr 01 23:28:19 2014 +0000 +++ b/USBDAP.cpp Sat Jul 05 08:19:19 2014 +0000 @@ -20,16 +20,36 @@ #include "USBHAL.h" #include "USBDAP.h" - -USBDAP::USBDAP(uint8_t output_report_length, uint8_t input_report_length, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect): USBDevice(vendor_id, product_id, product_release) +USBDAP::USBDAP(const char *product, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect): USBDevice(vendor_id, product_id, product_release) { - output_length = output_report_length; - input_length = input_report_length; + buildStringIproductDescriptor(product); + if(connect) { USBDevice::connect(); } } +USBDAP::USBDAP(uint8_t output_report_length, uint8_t input_report_length, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect): USBDevice(vendor_id, product_id, product_release) +{ + const char* product = "CMSIS-DAP"; + buildStringIproductDescriptor(product); + + if(connect) { + USBDevice::connect(); + } +} + +void USBDAP::buildStringIproductDescriptor(const char* s) +{ + int len = 2+strlen(s)*2; + _stringIproductDescriptor = new uint8_t[len]; + _stringIproductDescriptor[0] = len; + _stringIproductDescriptor[1] = STRING_DESCRIPTOR; + for (int i = 0; i < strlen(s); i++) { + _stringIproductDescriptor[2+i*2] = s[i]; + _stringIproductDescriptor[3+i*2] = 0; + } +} bool USBDAP::send(HID_REPORT *report) { @@ -187,12 +207,7 @@ } uint8_t * USBDAP::stringIproductDesc() { - static uint8_t stringIproductDescriptor[] = { - 32, //bLength - STRING_DESCRIPTOR, //bDescriptorType 0x03 - 'K',0,'L',0,'2',0,'5',0,'Z',0,' ',0,'C',0,'M',0,'S',0,'I',0,'S',0,'-',0,'D',0,'A',0,'P',0 // KL25Z CMSIs-DAP - }; - return stringIproductDescriptor; + return _stringIproductDescriptor; } uint8_t * USBDAP::reportDesc() {
diff -r 366f6f649a7d -r 7dee016756ce USBDAP.h --- a/USBDAP.h Tue Apr 01 23:28:19 2014 +0000 +++ b/USBDAP.h Sat Jul 05 08:19:19 2014 +0000 @@ -35,6 +35,17 @@ /** * Constructor * + * @param product product name default: "CMSIS-DAP" + * @param vendor_id Your vendor_id + * @param product_id Your product_id + * @param product_release Your preoduct_release + * @param connect Connect the device + */ + USBDAP(const char *product = "CMSIS-DAP", uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true); + + /** + * Constructor + * * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes) * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes) * @param vendor_id Your vendor_id @@ -147,8 +158,8 @@ private: HID_REPORT outputReport; - uint8_t output_length; - uint8_t input_length; + uint8_t *_stringIproductDescriptor; + void buildStringIproductDescriptor(const char* s); }; #endif