Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BaseUsbHost_example BaseJpegDecode_example SimpleJpegDecode_example
Revision 5:8a2d056e9b38, committed 2013-02-11
- Comitter:
- va009039
- Date:
- Mon Feb 11 12:00:47 2013 +0000
- Parent:
- 4:d931d24c2f81
- Commit message:
- add GetStringDescriptor()
Changed in this revision
| BaseUsbHost.h | Show annotated file Show diff for this revision Revisions of this file |
| BaseUsbHostCtlEp.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BaseUsbHost.h Fri Jan 25 14:51:33 2013 +0000
+++ b/BaseUsbHost.h Mon Feb 11 12:00:47 2013 +0000
@@ -1,6 +1,7 @@
-// BaseUsbHost.h 2013/1/24
+// BaseUsbHost.h 2013/2/11
#pragma once
#include <vector>
+#include <string>
#define USB_OK 0
#define USB_PROCESSING -1
@@ -82,6 +83,12 @@
uint8_t bInterval; // +6
}; // +7
+struct StandardStringDescriptor {// offset
+ uint8_t bLength; // +0
+ uint8_t bDescriptorType; // +1
+ char bString[0]; // +2
+}; // +3
+
struct HubDescriptor { // offset
uint8_t bDescLength; // +0
uint8_t bDescriptorType; // +1
@@ -333,6 +340,7 @@
int GetInterface(int interface, int *alternate);
int controlSend(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex=0, const uint8_t* data=NULL, int length=0);
int controlReceive(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t* data, int length);
+ string GetStringDescriptor(int index);
private:
int open(int addr);
virtual void enable(){};
--- a/BaseUsbHostCtlEp.cpp Fri Jan 25 14:51:33 2013 +0000
+++ b/BaseUsbHostCtlEp.cpp Mon Feb 11 12:00:47 2013 +0000
@@ -1,4 +1,4 @@
-// BaseUsbHostCtlEp.cpp 2013/1/25
+// BaseUsbHostCtlEp.cpp 2013/2/11
#include "mbed.h"
#include "rtos.h"
#include "BaseUsbHost.h"
@@ -87,6 +87,25 @@
return rc;
}
+string ControlEp::GetStringDescriptor(int index)
+{
+ string s = "";
+ uint8_t buf[128];
+ int r = GetDescriptor(USB_DESCRIPTOR_TYPE_STRING, index, buf, sizeof(buf));
+ if (r != USB_OK) {
+ return s;
+ }
+ DBG_HEX(buf, sizeof(buf));
+ StandardStringDescriptor* desc = reinterpret_cast<StandardStringDescriptor*>(buf);
+ if (desc->bLength <= 2 || desc->bDescriptorType != 3) {
+ return s;
+ }
+ for(int i = 0; i < desc->bLength-2; i += 2) {
+ s += desc->bString[i];
+ }
+ return s;
+}
+
int ControlEp::open(int addr)
{
TEST_ASSERT(addr >= 1 && addr <= 127);
@@ -149,7 +168,6 @@
return USB_ERROR;
}
r = wait_queue_HCTD(status_td, 100); // wait status stage
- TEST_ASSERT(r == USB_OK);
return r;
}
@@ -185,7 +203,6 @@
LPC_USB->HcControl |= OR_CONTROL_CLE;
int r = wait_queue_HCTD(status_td, 200); // wait status stage
- TEST_ASSERT(r == USB_OK);
return r;
}