diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/usb/arcotg_dcd.c | 37 | ||||
-rw-r--r-- | firmware/drivers/usb/arcotg_dcd.h | 2 | ||||
-rw-r--r-- | firmware/usbstack/controller.h | 6 | ||||
-rw-r--r-- | firmware/usbstack/core/epsetup.c | 19 | ||||
-rw-r--r-- | firmware/usbstack/drivers/device/usb_serial.c | 56 | ||||
-rw-r--r-- | firmware/usbstack/drivers/device/usb_storage.c | 85 | ||||
-rw-r--r-- | firmware/usbstack/drivers/device/usb_storage.h | 1 |
7 files changed, 121 insertions, 85 deletions
diff --git a/firmware/drivers/usb/arcotg_dcd.c b/firmware/drivers/usb/arcotg_dcd.c index 09e71fee41..c85b4ba374 100644 --- a/firmware/drivers/usb/arcotg_dcd.c +++ b/firmware/drivers/usb/arcotg_dcd.c | |||
@@ -197,12 +197,6 @@ void usb_arcotg_dcd_start(void) | |||
197 | { | 197 | { |
198 | logf("start"); | 198 | logf("start"); |
199 | 199 | ||
200 | if (arcotg_dcd.device_driver != NULL) { | ||
201 | logf("YEEEEEEESSSSSSS"); | ||
202 | } else { | ||
203 | logf("NOOOOOO"); | ||
204 | } | ||
205 | |||
206 | /* clear stopped bit */ | 200 | /* clear stopped bit */ |
207 | dcd_controller.stopped = false; | 201 | dcd_controller.stopped = false; |
208 | 202 | ||
@@ -461,7 +455,7 @@ static void reset_int(void) | |||
461 | /*-------------------------------------------------------------------------*/ | 455 | /*-------------------------------------------------------------------------*/ |
462 | /* usb controller ops */ | 456 | /* usb controller ops */ |
463 | 457 | ||
464 | int usb_arcotg_dcd_enable(struct usb_ep* ep) | 458 | int usb_arcotg_dcd_enable(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) |
465 | { | 459 | { |
466 | unsigned short max = 0; | 460 | unsigned short max = 0; |
467 | unsigned char mult = 0, zlt = 0; | 461 | unsigned char mult = 0, zlt = 0; |
@@ -473,14 +467,12 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) | |||
473 | return -EINVAL; | 467 | return -EINVAL; |
474 | } | 468 | } |
475 | 469 | ||
476 | logf("ahhh %d", ep->desc->wMaxPacketSize); | 470 | max = desc->wMaxPacketSize; |
477 | max = ep->desc->wMaxPacketSize; | ||
478 | retval = -EINVAL; | 471 | retval = -EINVAL; |
479 | 472 | ||
480 | /* check the max package size validate for this endpoint */ | 473 | /* check the max package size validate for this endpoint */ |
481 | /* Refer to USB2.0 spec table 9-13, | 474 | /* Refer to USB2.0 spec table 9-13. */ |
482 | */ | 475 | switch (desc->bmAttributes & 0x03) { |
483 | switch (ep->desc->bmAttributes & 0x03) { | ||
484 | case USB_ENDPOINT_XFER_BULK: | 476 | case USB_ENDPOINT_XFER_BULK: |
485 | zlt = 1; | 477 | zlt = 1; |
486 | break; | 478 | break; |
@@ -493,6 +485,7 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) | |||
493 | break; | 485 | break; |
494 | 486 | ||
495 | case USB_ENDPOINT_XFER_CONTROL: | 487 | case USB_ENDPOINT_XFER_CONTROL: |
488 | zlt = 1; | ||
496 | break; | 489 | break; |
497 | } | 490 | } |
498 | 491 | ||
@@ -599,28 +592,32 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) | |||
599 | + } | 592 | + } |
600 | #endif | 593 | #endif |
601 | 594 | ||
595 | /* set address of used ep in desc */ | ||
596 | desc->bEndpointAddress |= ep->ep_num; | ||
597 | |||
602 | /* here initialize variable of ep */ | 598 | /* here initialize variable of ep */ |
603 | ep->maxpacket = max; | 599 | ep->maxpacket = max; |
600 | ep->desc = desc; | ||
604 | 601 | ||
605 | /* hardware special operation */ | 602 | /* hardware special operation */ |
606 | 603 | ||
607 | /* Init EPx Queue Head (Ep Capabilites field in QH | 604 | /* Init EPx Queue Head (Ep Capabilites field in QH |
608 | * according to max, zlt, mult) */ | 605 | * according to max, zlt, mult) */ |
609 | qh_init(ep->ep_num, | 606 | qh_init(ep->ep_num, |
610 | (ep->desc->bEndpointAddress & USB_DIR_IN) ? USB_RECV : USB_SEND, | 607 | (desc->bEndpointAddress & USB_DIR_IN) ? USB_RECV : USB_SEND, |
611 | (unsigned char) (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK), | 608 | (unsigned char) (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK), |
612 | max, zlt, mult); | 609 | max, zlt, mult); |
613 | 610 | ||
614 | /* Init endpoint x at here */ | 611 | /* Init endpoint x at here */ |
615 | ep_setup(ep->ep_num, | 612 | ep_setup(ep->ep_num, |
616 | (unsigned char)((ep->desc->bEndpointAddress & USB_DIR_IN) ? USB_RECV : USB_SEND), | 613 | (unsigned char)(desc->bEndpointAddress & USB_DIR_IN) ? USB_RECV : USB_SEND, |
617 | (unsigned char)(ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)); | 614 | (unsigned char)(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)); |
618 | 615 | ||
619 | /* Now HW will be NAKing transfers to that EP, | 616 | /* Now HW will be NAKing transfers to that EP, |
620 | * until a buffer is queued to it. */ | 617 | * until a buffer is queued to it. */ |
621 | 618 | ||
622 | retval = 0; | 619 | retval = 0; |
623 | switch (ep->desc->bmAttributes & 0x03) { | 620 | switch (desc->bmAttributes & 0x03) { |
624 | case USB_ENDPOINT_XFER_BULK: | 621 | case USB_ENDPOINT_XFER_BULK: |
625 | val = "bulk"; | 622 | val = "bulk"; |
626 | break; | 623 | break; |
@@ -638,8 +635,8 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep) | |||
638 | logf("ep num %d", (int)ep->ep_num); | 635 | logf("ep num %d", (int)ep->ep_num); |
639 | 636 | ||
640 | logf("enabled %s (ep%d%s-%s)", ep->name, | 637 | logf("enabled %s (ep%d%s-%s)", ep->name, |
641 | ep->desc->bEndpointAddress & 0x0f, | 638 | desc->bEndpointAddress & 0x0f, |
642 | (ep->desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", val); | 639 | (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", val); |
643 | logf(" maxpacket %d", max); | 640 | logf(" maxpacket %d", max); |
644 | 641 | ||
645 | return retval; | 642 | return retval; |
diff --git a/firmware/drivers/usb/arcotg_dcd.h b/firmware/drivers/usb/arcotg_dcd.h index 2e6f71ef94..6c5f5739d5 100644 --- a/firmware/drivers/usb/arcotg_dcd.h +++ b/firmware/drivers/usb/arcotg_dcd.h | |||
@@ -146,7 +146,7 @@ void usb_arcotg_dcd_start(void); | |||
146 | void usb_arcotg_dcd_stop(void); | 146 | void usb_arcotg_dcd_stop(void); |
147 | 147 | ||
148 | /* usb controller ops */ | 148 | /* usb controller ops */ |
149 | int usb_arcotg_dcd_enable(struct usb_ep* ep); | 149 | int usb_arcotg_dcd_enable(struct usb_ep* ep, struct usb_endpoint_descriptor* desc); |
150 | int usb_arcotg_dcd_disable(struct usb_ep* ep); | 150 | int usb_arcotg_dcd_disable(struct usb_ep* ep); |
151 | int usb_arcotg_dcd_set_halt(struct usb_ep* ep, bool halt); | 151 | int usb_arcotg_dcd_set_halt(struct usb_ep* ep, bool halt); |
152 | int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* request); | 152 | int usb_arcotg_dcd_send(struct usb_ep* ep, struct usb_response* request); |
diff --git a/firmware/usbstack/controller.h b/firmware/usbstack/controller.h index d626899f70..4e742035e6 100644 --- a/firmware/usbstack/controller.h +++ b/firmware/usbstack/controller.h | |||
@@ -38,14 +38,14 @@ struct usb_controller { | |||
38 | 38 | ||
39 | struct usb_dcd_controller_ops { | 39 | struct usb_dcd_controller_ops { |
40 | /* endpoint management */ | 40 | /* endpoint management */ |
41 | int (*enable)(struct usb_ep* ep); | 41 | int (*enable)(struct usb_ep* ep, struct usb_endpoint_descriptor* desc); |
42 | int (*disable)(struct usb_ep* ep); | 42 | int (*disable)(struct usb_ep* ep); |
43 | int (*set_halt)(struct usb_ep* ep, bool hald); | 43 | int (*set_halt)(struct usb_ep* ep, bool hald); |
44 | 44 | ||
45 | /* transmitting */ | 45 | /* transmitting */ |
46 | int (*send)(struct usb_ep* ep, struct usb_response* req); | 46 | int (*send)(struct usb_ep* ep, struct usb_response* req); |
47 | int (*receive)(struct usb_ep* ep, struct usb_response* res); | 47 | int (*receive)(struct usb_ep* ep, struct usb_response* res); |
48 | 48 | ||
49 | /* ep0 */ | 49 | /* ep0 */ |
50 | struct usb_ep* ep0; | 50 | struct usb_ep* ep0; |
51 | }; | 51 | }; |
diff --git a/firmware/usbstack/core/epsetup.c b/firmware/usbstack/core/epsetup.c index 338285e8c3..702108a1cb 100644 --- a/firmware/usbstack/core/epsetup.c +++ b/firmware/usbstack/core/epsetup.c | |||
@@ -164,23 +164,6 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) | |||
164 | } | 164 | } |
165 | 165 | ||
166 | /* MATCH!! */ | 166 | /* MATCH!! */ |
167 | 167 | ||
168 | /* report address */ | ||
169 | desc->bEndpointAddress |= ep->ep_num; | ||
170 | |||
171 | /* report (variable) full speed bulk maxpacket */ | ||
172 | if (type == USB_ENDPOINT_XFER_BULK) { | ||
173 | int size = max; | ||
174 | |||
175 | /* min() doesn't work on bitfields with gcc-3.5 */ | ||
176 | if (size > 64) { | ||
177 | size = 64; | ||
178 | } | ||
179 | desc->wMaxPacketSize = size; | ||
180 | } | ||
181 | |||
182 | /* save desc in endpoint */ | ||
183 | ep->desc = desc; | ||
184 | |||
185 | return 1; | 168 | return 1; |
186 | } | 169 | } |
diff --git a/firmware/usbstack/drivers/device/usb_serial.c b/firmware/usbstack/drivers/device/usb_serial.c index 7750ccb8b7..7299dc6765 100644 --- a/firmware/usbstack/drivers/device/usb_serial.c +++ b/firmware/usbstack/drivers/device/usb_serial.c | |||
@@ -81,7 +81,7 @@ static struct usb_interface_descriptor serial_bulk_interface_desc = { | |||
81 | .iInterface = GS_DATA_STR_ID, | 81 | .iInterface = GS_DATA_STR_ID, |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static struct usb_endpoint_descriptor serial_fullspeed_in_desc = { | 84 | static struct usb_endpoint_descriptor serial_fs_in_desc = { |
85 | .bLength = USB_DT_ENDPOINT_SIZE, | 85 | .bLength = USB_DT_ENDPOINT_SIZE, |
86 | .bDescriptorType = USB_DT_ENDPOINT, | 86 | .bDescriptorType = USB_DT_ENDPOINT, |
87 | .bEndpointAddress = USB_DIR_IN, | 87 | .bEndpointAddress = USB_DIR_IN, |
@@ -89,7 +89,7 @@ static struct usb_endpoint_descriptor serial_fullspeed_in_desc = { | |||
89 | .wMaxPacketSize = 8, | 89 | .wMaxPacketSize = 8, |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static struct usb_endpoint_descriptor serial_fullspeed_out_desc = { | 92 | static struct usb_endpoint_descriptor serial_fs_out_desc = { |
93 | .bLength = USB_DT_ENDPOINT_SIZE, | 93 | .bLength = USB_DT_ENDPOINT_SIZE, |
94 | .bDescriptorType = USB_DT_ENDPOINT, | 94 | .bDescriptorType = USB_DT_ENDPOINT, |
95 | .bEndpointAddress = USB_DIR_OUT, | 95 | .bEndpointAddress = USB_DIR_OUT, |
@@ -110,10 +110,34 @@ static struct usb_qualifier_descriptor serial_qualifier_desc = { | |||
110 | .bNumConfigurations = 1, | 110 | .bNumConfigurations = 1, |
111 | }; | 111 | }; |
112 | 112 | ||
113 | struct usb_descriptor_header *serial_bulk_fullspeed_function[] = { | 113 | struct usb_descriptor_header *serial_fs_function[] = { |
114 | (struct usb_descriptor_header *) &serial_bulk_interface_desc, | 114 | (struct usb_descriptor_header *) &serial_bulk_interface_desc, |
115 | (struct usb_descriptor_header *) &serial_fullspeed_in_desc, | 115 | (struct usb_descriptor_header *) &serial_fs_in_desc, |
116 | (struct usb_descriptor_header *) &serial_fullspeed_out_desc, | 116 | (struct usb_descriptor_header *) &serial_fs_out_desc, |
117 | NULL, | ||
118 | }; | ||
119 | |||
120 | /* USB 2.0 */ | ||
121 | static struct usb_endpoint_descriptor serial_hs_in_desc = { | ||
122 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
123 | .bDescriptorType = USB_DT_ENDPOINT, | ||
124 | .bEndpointAddress = USB_DIR_IN, | ||
125 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
126 | .wMaxPacketSize = 512, | ||
127 | }; | ||
128 | |||
129 | static struct usb_endpoint_descriptor serial_hs_out_desc = { | ||
130 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
131 | .bDescriptorType = USB_DT_ENDPOINT, | ||
132 | .bEndpointAddress = USB_DIR_IN, | ||
133 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
134 | .wMaxPacketSize = 512, | ||
135 | }; | ||
136 | |||
137 | struct usb_descriptor_header *serial_hs_function[] = { | ||
138 | (struct usb_descriptor_header *) &serial_bulk_interface_desc, | ||
139 | (struct usb_descriptor_header *) &serial_hs_in_desc, | ||
140 | (struct usb_descriptor_header *) &serial_hs_out_desc, | ||
117 | NULL, | 141 | NULL, |
118 | }; | 142 | }; |
119 | 143 | ||
@@ -126,11 +150,11 @@ struct usb_response res; | |||
126 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); | 150 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); |
127 | static int set_config(int config); | 151 | static int set_config(int config); |
128 | 152 | ||
129 | |||
130 | struct device { | 153 | struct device { |
131 | struct usb_ep* in; | 154 | struct usb_ep* in; |
132 | struct usb_ep* out; | 155 | struct usb_ep* out; |
133 | uint32_t used_config; | 156 | uint32_t used_config; |
157 | struct usb_descriptor_header** descriptors; | ||
134 | }; | 158 | }; |
135 | 159 | ||
136 | static struct device dev; | 160 | static struct device dev; |
@@ -153,14 +177,14 @@ void usb_serial_driver_bind(void* controler_ops) | |||
153 | /* serach and asign endpoints */ | 177 | /* serach and asign endpoints */ |
154 | usb_ep_autoconfig_reset(); | 178 | usb_ep_autoconfig_reset(); |
155 | 179 | ||
156 | dev.in = usb_ep_autoconfig(&serial_fullspeed_in_desc); | 180 | dev.in = usb_ep_autoconfig(&serial_fs_in_desc); |
157 | if (!dev.in) { | 181 | if (!dev.in) { |
158 | goto autoconf_fail; | 182 | goto autoconf_fail; |
159 | } | 183 | } |
160 | dev.in->claimed = true; | 184 | dev.in->claimed = true; |
161 | logf("usb serial: in: %s", dev.in->name); | 185 | logf("usb serial: in: %s", dev.in->name); |
162 | 186 | ||
163 | dev.out = usb_ep_autoconfig(&serial_fullspeed_out_desc); | 187 | dev.out = usb_ep_autoconfig(&serial_fs_out_desc); |
164 | if (!dev.out) { | 188 | if (!dev.out) { |
165 | goto autoconf_fail; | 189 | goto autoconf_fail; |
166 | } | 190 | } |
@@ -180,7 +204,7 @@ void usb_serial_driver_bind(void* controler_ops) | |||
180 | return; | 204 | return; |
181 | 205 | ||
182 | autoconf_fail: | 206 | autoconf_fail: |
183 | logf("failed to find endpoiunts"); | 207 | logf("failed to find endpoints"); |
184 | } | 208 | } |
185 | 209 | ||
186 | int usb_serial_driver_request(struct usb_ctrlrequest* request) | 210 | int usb_serial_driver_request(struct usb_ctrlrequest* request) |
@@ -252,15 +276,13 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request) | |||
252 | void usb_serial_driver_speed(enum usb_device_speed speed) | 276 | void usb_serial_driver_speed(enum usb_device_speed speed) |
253 | { | 277 | { |
254 | switch (speed) { | 278 | switch (speed) { |
255 | case USB_SPEED_LOW: | ||
256 | case USB_SPEED_FULL: | ||
257 | logf("usb serial: using fullspeed"); | ||
258 | break; | ||
259 | case USB_SPEED_HIGH: | 279 | case USB_SPEED_HIGH: |
260 | logf("usb serial: using highspeed"); | 280 | logf("usb serial: using highspeed"); |
281 | dev.descriptors = serial_hs_function; | ||
261 | break; | 282 | break; |
262 | default: | 283 | default: |
263 | logf("speed: hmm"); | 284 | logf("usb serial: using fullspeed"); |
285 | dev.descriptors = serial_fs_function; | ||
264 | break; | 286 | break; |
265 | } | 287 | } |
266 | } | 288 | } |
@@ -274,7 +296,7 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index) | |||
274 | 296 | ||
275 | /* TODO check index*/ | 297 | /* TODO check index*/ |
276 | 298 | ||
277 | len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, serial_bulk_fullspeed_function); | 299 | len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, dev.descriptors); |
278 | if (len < 0) { | 300 | if (len < 0) { |
279 | return len; | 301 | return len; |
280 | } | 302 | } |
@@ -288,9 +310,9 @@ static int set_config(int config) | |||
288 | 310 | ||
289 | /* enable endpoints */ | 311 | /* enable endpoints */ |
290 | logf("setup %s", dev.in->name); | 312 | logf("setup %s", dev.in->name); |
291 | ops->enable(dev.in); | 313 | ops->enable(dev.in, (struct usb_endpoint_descriptor*)dev.descriptors[1]); |
292 | logf("setup %s", dev.out->name); | 314 | logf("setup %s", dev.out->name); |
293 | ops->enable(dev.out); | 315 | ops->enable(dev.out, (struct usb_endpoint_descriptor*)dev.descriptors[2]); |
294 | 316 | ||
295 | /* store config */ | 317 | /* store config */ |
296 | logf("using config %d", config); | 318 | logf("using config %d", config); |
diff --git a/firmware/usbstack/drivers/device/usb_storage.c b/firmware/usbstack/drivers/device/usb_storage.c index 38c2b97eb0..3db379c1df 100644 --- a/firmware/usbstack/drivers/device/usb_storage.c +++ b/firmware/usbstack/drivers/device/usb_storage.c | |||
@@ -31,17 +31,9 @@ struct usb_device_driver usb_storage_driver = { | |||
31 | .request = usb_storage_driver_request, | 31 | .request = usb_storage_driver_request, |
32 | .suspend = NULL, | 32 | .suspend = NULL, |
33 | .resume = NULL, | 33 | .resume = NULL, |
34 | .speed = NULL, | 34 | .speed = usb_storage_driver_speed, |
35 | }; | 35 | }; |
36 | 36 | ||
37 | struct device { | ||
38 | struct usb_ep* in; | ||
39 | struct usb_ep* out; | ||
40 | struct usb_ep* intr; | ||
41 | }; | ||
42 | |||
43 | static struct device dev; | ||
44 | |||
45 | /*-------------------------------------------------------------------------*/ | 37 | /*-------------------------------------------------------------------------*/ |
46 | 38 | ||
47 | #define PROTO_BULK 0x50 // Bulk only | 39 | #define PROTO_BULK 0x50 // Bulk only |
@@ -92,8 +84,31 @@ static struct usb_interface_descriptor storage_interface_desc = { | |||
92 | .iInterface = 0, | 84 | .iInterface = 0, |
93 | }; | 85 | }; |
94 | 86 | ||
95 | /* endpoint I -> bulk in */ | 87 | static struct usb_endpoint_descriptor storage_fs_bulk_in_desc = { |
96 | static struct usb_endpoint_descriptor storage_bulk_in_desc = { | 88 | .bLength = USB_DT_ENDPOINT_SIZE, |
89 | .bDescriptorType = USB_DT_ENDPOINT, | ||
90 | .bEndpointAddress = USB_DIR_IN, | ||
91 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
92 | .wMaxPacketSize = 64, | ||
93 | }; | ||
94 | |||
95 | static struct usb_endpoint_descriptor storage_fs_bulk_out_desc = { | ||
96 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
97 | .bDescriptorType = USB_DT_ENDPOINT, | ||
98 | .bEndpointAddress = USB_DIR_OUT, | ||
99 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | ||
100 | .wMaxPacketSize = 64, | ||
101 | }; | ||
102 | |||
103 | struct usb_descriptor_header *storage_fs_function[] = { | ||
104 | (struct usb_descriptor_header *) &storage_interface_desc, | ||
105 | (struct usb_descriptor_header *) &storage_fs_bulk_in_desc, | ||
106 | (struct usb_descriptor_header *) &storage_fs_bulk_out_desc, | ||
107 | NULL, | ||
108 | }; | ||
109 | |||
110 | /* USB 2.0 */ | ||
111 | static struct usb_endpoint_descriptor storage_hs_bulk_in_desc = { | ||
97 | .bLength = USB_DT_ENDPOINT_SIZE, | 112 | .bLength = USB_DT_ENDPOINT_SIZE, |
98 | .bDescriptorType = USB_DT_ENDPOINT, | 113 | .bDescriptorType = USB_DT_ENDPOINT, |
99 | .bEndpointAddress = USB_DIR_IN, | 114 | .bEndpointAddress = USB_DIR_IN, |
@@ -101,8 +116,7 @@ static struct usb_endpoint_descriptor storage_bulk_in_desc = { | |||
101 | .wMaxPacketSize = 512, | 116 | .wMaxPacketSize = 512, |
102 | }; | 117 | }; |
103 | 118 | ||
104 | /* endpoint II -> bulk out */ | 119 | static struct usb_endpoint_descriptor storage_hs_bulk_out_desc = { |
105 | static struct usb_endpoint_descriptor storage_bulk_out_desc = { | ||
106 | .bLength = USB_DT_ENDPOINT_SIZE, | 120 | .bLength = USB_DT_ENDPOINT_SIZE, |
107 | .bDescriptorType = USB_DT_ENDPOINT, | 121 | .bDescriptorType = USB_DT_ENDPOINT, |
108 | .bEndpointAddress = USB_DIR_OUT, | 122 | .bEndpointAddress = USB_DIR_OUT, |
@@ -110,10 +124,10 @@ static struct usb_endpoint_descriptor storage_bulk_out_desc = { | |||
110 | .wMaxPacketSize = 512, | 124 | .wMaxPacketSize = 512, |
111 | }; | 125 | }; |
112 | 126 | ||
113 | struct usb_descriptor_header *storage_fullspeed_function[] = { | 127 | struct usb_descriptor_header *storage_hs_function[] = { |
114 | (struct usb_descriptor_header *) &storage_interface_desc, | 128 | (struct usb_descriptor_header *) &storage_interface_desc, |
115 | (struct usb_descriptor_header *) &storage_bulk_in_desc, | 129 | (struct usb_descriptor_header *) &storage_hs_bulk_in_desc, |
116 | (struct usb_descriptor_header *) &storage_bulk_out_desc, | 130 | (struct usb_descriptor_header *) &storage_hs_bulk_out_desc, |
117 | NULL, | 131 | NULL, |
118 | }; | 132 | }; |
119 | 133 | ||
@@ -126,6 +140,15 @@ struct usb_response res; | |||
126 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); | 140 | static int config_buf(uint8_t *buf, uint8_t type, unsigned index); |
127 | static int set_config(int config); | 141 | static int set_config(int config); |
128 | 142 | ||
143 | struct device { | ||
144 | struct usb_ep* in; | ||
145 | struct usb_ep* out; | ||
146 | struct usb_ep* intr; | ||
147 | struct usb_descriptor_header** descriptors; | ||
148 | }; | ||
149 | |||
150 | static struct device dev; | ||
151 | |||
129 | /*-------------------------------------------------------------------------*/ | 152 | /*-------------------------------------------------------------------------*/ |
130 | 153 | ||
131 | void usb_storage_driver_init(void) | 154 | void usb_storage_driver_init(void) |
@@ -144,14 +167,14 @@ void usb_storage_driver_bind(void* controler_ops) | |||
144 | /* serach and asign endpoints */ | 167 | /* serach and asign endpoints */ |
145 | usb_ep_autoconfig_reset(); | 168 | usb_ep_autoconfig_reset(); |
146 | 169 | ||
147 | dev.in = usb_ep_autoconfig(&storage_bulk_in_desc); | 170 | dev.in = usb_ep_autoconfig(&storage_fs_bulk_in_desc); |
148 | if (!dev.in) { | 171 | if (!dev.in) { |
149 | goto autoconf_fail; | 172 | goto autoconf_fail; |
150 | } | 173 | } |
151 | dev.in->claimed = true; | 174 | dev.in->claimed = true; |
152 | logf("usb storage: in: %s", dev.in->name); | 175 | logf("usb storage: in: %s", dev.in->name); |
153 | 176 | ||
154 | dev.out = usb_ep_autoconfig(&storage_bulk_out_desc); | 177 | dev.out = usb_ep_autoconfig(&storage_fs_bulk_out_desc); |
155 | if (!dev.out) { | 178 | if (!dev.out) { |
156 | goto autoconf_fail; | 179 | goto autoconf_fail; |
157 | } | 180 | } |
@@ -234,6 +257,20 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request) | |||
234 | return ret; | 257 | return ret; |
235 | } | 258 | } |
236 | 259 | ||
260 | void usb_storage_driver_speed(enum usb_device_speed speed) | ||
261 | { | ||
262 | switch (speed) { | ||
263 | case USB_SPEED_HIGH: | ||
264 | logf("usb storage: using highspeed"); | ||
265 | dev.descriptors = storage_hs_function; | ||
266 | break; | ||
267 | default: | ||
268 | logf("usb storage: using fullspeed"); | ||
269 | dev.descriptors = storage_fs_function; | ||
270 | break; | ||
271 | } | ||
272 | } | ||
273 | |||
237 | /*-------------------------------------------------------------------------*/ | 274 | /*-------------------------------------------------------------------------*/ |
238 | /* S/GET CONFIGURATION helpers */ | 275 | /* S/GET CONFIGURATION helpers */ |
239 | 276 | ||
@@ -241,12 +278,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index) | |||
241 | { | 278 | { |
242 | int len; | 279 | int len; |
243 | 280 | ||
244 | /* only one configuration */ | 281 | len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, dev.descriptors); |
245 | if (index != 0) { | 282 | logf("result %d", len); |
246 | return -EINVAL; | ||
247 | } | ||
248 | |||
249 | len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, storage_fullspeed_function); | ||
250 | if (len < 0) { | 283 | if (len < 0) { |
251 | return len; | 284 | return len; |
252 | } | 285 | } |
@@ -258,9 +291,9 @@ static int set_config(int config) | |||
258 | { | 291 | { |
259 | /* enable endpoints */ | 292 | /* enable endpoints */ |
260 | logf("setup %s", dev.in->name); | 293 | logf("setup %s", dev.in->name); |
261 | ops->enable(dev.in); | 294 | ops->enable(dev.in, (struct usb_endpoint_descriptor*)dev.descriptors[1]); |
262 | logf("setup %s", dev.out->name); | 295 | logf("setup %s", dev.out->name); |
263 | ops->enable(dev.out); | 296 | ops->enable(dev.out, (struct usb_endpoint_descriptor*)dev.descriptors[2]); |
264 | 297 | ||
265 | /* setup buffers */ | 298 | /* setup buffers */ |
266 | 299 | ||
diff --git a/firmware/usbstack/drivers/device/usb_storage.h b/firmware/usbstack/drivers/device/usb_storage.h index f148d4228c..ff4b187064 100644 --- a/firmware/usbstack/drivers/device/usb_storage.h +++ b/firmware/usbstack/drivers/device/usb_storage.h | |||
@@ -27,5 +27,6 @@ void usb_storage_driver_init(void); | |||
27 | 27 | ||
28 | void usb_storage_driver_bind(void* controller_ops); | 28 | void usb_storage_driver_bind(void* controller_ops); |
29 | int usb_storage_driver_request(struct usb_ctrlrequest* req); | 29 | int usb_storage_driver_request(struct usb_ctrlrequest* req); |
30 | void usb_storage_driver_speed(enum usb_device_speed speed); | ||
30 | 31 | ||
31 | #endif /*_STORGAGE_H_*/ | 32 | #endif /*_STORGAGE_H_*/ |