diff options
Diffstat (limited to 'firmware/usbstack/drivers/device/usb_serial.c')
-rw-r--r-- | firmware/usbstack/drivers/device/usb_serial.c | 56 |
1 files changed, 39 insertions, 17 deletions
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); |