summaryrefslogtreecommitdiff
path: root/firmware/usbstack
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2007-09-17 20:49:02 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2007-09-17 20:49:02 +0000
commitb0c996ba92713e06ff28e610e7bebab8a065b68e (patch)
tree8854e3a4fd5a054ecadb50a654297bad1da30c79 /firmware/usbstack
parent5011d43d13f4a5964fd6fe7b62d0fa2577d5edf9 (diff)
downloadrockbox-b0c996ba92713e06ff28e610e7bebab8a065b68e.tar.gz
rockbox-b0c996ba92713e06ff28e610e7bebab8a065b68e.zip
code police, no functional changes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14737 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usbstack')
-rw-r--r--firmware/usbstack/core/config.c9
-rw-r--r--firmware/usbstack/core/core.c31
-rw-r--r--firmware/usbstack/core/epsetup.c6
-rw-r--r--firmware/usbstack/drivers/device/usb_serial.c21
-rw-r--r--firmware/usbstack/drivers/device/usb_storage.c27
5 files changed, 60 insertions, 34 deletions
diff --git a/firmware/usbstack/core/config.c b/firmware/usbstack/core/config.c
index c49d54702c..1a9b12508e 100644
--- a/firmware/usbstack/core/config.c
+++ b/firmware/usbstack/core/config.c
@@ -23,7 +23,8 @@
23#include <string.h> 23#include <string.h>
24#include "usbstack/core.h" 24#include "usbstack/core.h"
25 25
26static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) 26static int usb_descriptor_fillbuf(void* buf, unsigned buflen,
27 struct usb_descriptor_header** src)
27{ 28{
28 uint8_t* dest = buf; 29 uint8_t* dest = buf;
29 30
@@ -45,7 +46,8 @@ static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descrip
45 return dest - (uint8_t *)buf; 46 return dest - (uint8_t *)buf;
46} 47}
47 48
48int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) 49int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf,
50 unsigned length, struct usb_descriptor_header** desc)
49{ 51{
50 struct usb_config_descriptor* cp = buf; 52 struct usb_config_descriptor* cp = buf;
51 int len; 53 int len;
@@ -58,7 +60,8 @@ int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf,
58 *cp = *config; 60 *cp = *config;
59 61
60 /* then interface/endpoint/class/vendor/... */ 62 /* then interface/endpoint/class/vendor/... */
61 len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc); 63 len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf,
64 length - USB_DT_CONFIG_SIZE, desc);
62 65
63 if (len < 0) { 66 if (len < 0) {
64 return len; 67 return len;
diff --git a/firmware/usbstack/core/core.c b/firmware/usbstack/core/core.c
index 2fbec5d571..0d2cfc67b9 100644
--- a/firmware/usbstack/core/core.c
+++ b/firmware/usbstack/core/core.c
@@ -99,7 +99,8 @@ void usb_stack_start(void)
99 * and if it has a device driver bind to it */ 99 * and if it has a device driver bind to it */
100 logf("check for auto bind"); 100 logf("check for auto bind");
101 if (usbcore.active_controller->type == DEVICE) { 101 if (usbcore.active_controller->type == DEVICE) {
102 if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) { 102 if (usbcore.active_controller->device_driver == NULL &&
103 usbcore.device_driver != NULL) {
103 /* bind driver */ 104 /* bind driver */
104 logf("binding..."); 105 logf("binding...");
105 bind_device_driver(usbcore.device_driver); 106 bind_device_driver(usbcore.device_driver);
@@ -130,7 +131,8 @@ void usb_stack_stop(void)
130void usb_stack_irq(void) 131void usb_stack_irq(void)
131{ 132{
132 /* simply notify usb controller */ 133 /* simply notify usb controller */
133 if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) { 134 if (usbcore.active_controller != NULL &&
135 usbcore.active_controller->irq != NULL) {
134 usbcore.active_controller->irq(); 136 usbcore.active_controller->irq();
135 } 137 }
136} 138}
@@ -190,7 +192,8 @@ int usb_controller_register(struct usb_controller* ctrl)
190 * @param ctrl pointer to controller to unregister. 192 * @param ctrl pointer to controller to unregister.
191 * @return 0 on success else a defined error code. 193 * @return 0 on success else a defined error code.
192 */ 194 */
193int usb_controller_unregister(struct usb_controller* ctrl) { 195int usb_controller_unregister(struct usb_controller* ctrl)
196{
194 197
195 if (ctrl == NULL) { 198 if (ctrl == NULL) {
196 return EINVAL; 199 return EINVAL;
@@ -226,7 +229,8 @@ void usb_controller_select(int type)
226 struct usb_controller* new = NULL; 229 struct usb_controller* new = NULL;
227 230
228 /* check if a controller of the wanted type is already loaded */ 231 /* check if a controller of the wanted type is already loaded */
229 if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) { 232 if (usbcore.active_controller != NULL &&
233 (int)usbcore.active_controller->type == type) {
230 logf("controller already set"); 234 logf("controller already set");
231 return; 235 return;
232 } 236 }
@@ -263,7 +267,8 @@ void usb_controller_select(int type)
263 usbcore.active_controller->init(); 267 usbcore.active_controller->init();
264} 268}
265 269
266int usb_stack_get_mode(void) { 270int usb_stack_get_mode(void)
271{
267 return usbcore.mode; 272 return usbcore.mode;
268} 273}
269 274
@@ -296,8 +301,8 @@ int usb_device_driver_register(struct usb_device_driver* driver)
296 return 0; 301 return 0;
297} 302}
298 303
299int usb_device_driver_bind(const char* name) { 304int usb_device_driver_bind(const char* name)
300 305{
301 int i; 306 int i;
302 struct usb_device_driver *tmp = NULL; 307 struct usb_device_driver *tmp = NULL;
303 struct usb_device_driver *driver = NULL; 308 struct usb_device_driver *driver = NULL;
@@ -340,8 +345,8 @@ int usb_device_driver_bind(const char* name) {
340 return 0; 345 return 0;
341} 346}
342 347
343void usb_device_driver_unbind(void) { 348void usb_device_driver_unbind(void)
344 349{
345 logf("usb_device_driver_unbind"); 350 logf("usb_device_driver_unbind");
346 if (usbcore.active_controller->device_driver != NULL) { 351 if (usbcore.active_controller->device_driver != NULL) {
347 usbcore.active_controller->device_driver->unbind(); 352 usbcore.active_controller->device_driver->unbind();
@@ -351,8 +356,8 @@ void usb_device_driver_unbind(void) {
351 usbcore.device_driver = NULL; 356 usbcore.device_driver = NULL;
352} 357}
353 358
354static void update_driver_names(unsigned char* result) { 359static void update_driver_names(unsigned char* result)
355 360{
356 int i; 361 int i;
357 int pos = 0; 362 int pos = 0;
358 unsigned char terminator = ','; 363 unsigned char terminator = ',';
@@ -376,8 +381,8 @@ static void update_driver_names(unsigned char* result) {
376 } 381 }
377} 382}
378 383
379static void bind_device_driver(struct usb_device_driver* driver) { 384static void bind_device_driver(struct usb_device_driver* driver)
380 385{
381 int ret = 0; 386 int ret = 0;
382 387
383 /* look if there is an old driver */ 388 /* look if there is an old driver */
diff --git a/firmware/usbstack/core/epsetup.c b/firmware/usbstack/core/epsetup.c
index 969678e18f..ef98935fe3 100644
--- a/firmware/usbstack/core/epsetup.c
+++ b/firmware/usbstack/core/epsetup.c
@@ -151,13 +151,15 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc)
151 switch (type) { 151 switch (type) {
152 case USB_ENDPOINT_XFER_INT: 152 case USB_ENDPOINT_XFER_INT:
153 /* INT: limit 64 bytes full speed, 1024 high speed */ 153 /* INT: limit 64 bytes full speed, 1024 high speed */
154 if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) { 154 if ((usbcore.active_controller->speed != USB_SPEED_HIGH) &&
155 (max > 64)) {
155 return 0; 156 return 0;
156 } 157 }
157 /* FALLTHROUGH */ 158 /* FALLTHROUGH */
158 159
159 case USB_ENDPOINT_XFER_ISOC: 160 case USB_ENDPOINT_XFER_ISOC:
160 if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) { 161 if ((usbcore.active_controller->speed != USB_SPEED_HIGH) &&
162 (max > 1023)) {
161 return 0; 163 return 0;
162 } 164 }
163 break; 165 break;
diff --git a/firmware/usbstack/drivers/device/usb_serial.c b/firmware/usbstack/drivers/device/usb_serial.c
index 0c66cf68fe..c8850042cd 100644
--- a/firmware/usbstack/drivers/device/usb_serial.c
+++ b/firmware/usbstack/drivers/device/usb_serial.c
@@ -209,7 +209,8 @@ int usb_serial_driver_bind(void* controler_ops)
209 serial_debug_desc.bDebugInEndpoint = dev.in->ep_num; 209 serial_debug_desc.bDebugInEndpoint = dev.in->ep_num;
210 serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num; 210 serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num;
211 211
212 /* update hs descriptors as we asume that endpoints are the same for fs and hs */ 212 /* update hs descriptors as we asume that endpoints
213 are the same for fs and hs */
213 serial_hs_in_desc.bEndpointAddress = serial_fs_in_desc.bEndpointAddress; 214 serial_hs_in_desc.bEndpointAddress = serial_fs_in_desc.bEndpointAddress;
214 serial_hs_out_desc.bEndpointAddress = serial_fs_out_desc.bEndpointAddress; 215 serial_hs_out_desc.bEndpointAddress = serial_fs_out_desc.bEndpointAddress;
215 216
@@ -242,13 +243,15 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
242 switch (request->wValue >> 8) { 243 switch (request->wValue >> 8) {
243 case USB_DT_DEVICE: 244 case USB_DT_DEVICE:
244 logf("usb serial: sending device desc"); 245 logf("usb serial: sending device desc");
245 ret = MIN(sizeof(struct usb_device_descriptor), request->wLength); 246 ret = MIN(sizeof(struct usb_device_descriptor),
247 request->wLength);
246 res.buf = &serial_device_desc; 248 res.buf = &serial_device_desc;
247 break; 249 break;
248 250
249 case USB_DT_DEVICE_QUALIFIER: 251 case USB_DT_DEVICE_QUALIFIER:
250 logf("usb serial: sending qualifier dec"); 252 logf("usb serial: sending qualifier dec");
251 ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength); 253 ret = MIN(sizeof(struct usb_qualifier_descriptor),
254 request->wLength);
252 res.buf = &serial_qualifier_desc; 255 res.buf = &serial_qualifier_desc;
253 break; 256 break;
254 257
@@ -256,7 +259,8 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
256 case USB_DT_CONFIG: 259 case USB_DT_CONFIG:
257 logf("usb serial: sending config desc"); 260 logf("usb serial: sending config desc");
258 261
259 ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff); 262 ret = config_buf(buf, request->wValue >> 8,
263 request->wValue & 0xff);
260 if (ret >= 0) { 264 if (ret >= 0) {
261 logf("%d, vs %d", request->wLength, ret); 265 logf("%d, vs %d", request->wLength, ret);
262 ret = MIN(request->wLength, (uint16_t)ret); 266 ret = MIN(request->wLength, (uint16_t)ret);
@@ -266,13 +270,15 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
266 270
267 case USB_DT_DEBUG: 271 case USB_DT_DEBUG:
268 logf("usb serial: sending debug desc"); 272 logf("usb serial: sending debug desc");
269 ret = MIN(sizeof(struct usb_debug_descriptor), request->wLength); 273 ret = MIN(sizeof(struct usb_debug_descriptor),
274 request->wLength);
270 res.buf = &serial_debug_desc; 275 res.buf = &serial_debug_desc;
271 break; 276 break;
272 277
273 case USB_DT_STRING: 278 case USB_DT_STRING:
274 logf("usb serial: sending string desc"); 279 logf("usb serial: sending string desc");
275 ret = usb_stack_get_string(strings, request->wValue & 0xff, buf); 280 ret = usb_stack_get_string(strings, request->wValue & 0xff,
281 buf);
276 ret = MIN(ret, request->wLength); 282 ret = MIN(ret, request->wLength);
277 res.buf = buf; 283 res.buf = buf;
278 break; 284 break;
@@ -324,7 +330,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
324 /* TODO check index*/ 330 /* TODO check index*/
325 (void)index; 331 (void)index;
326 332
327 len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, dev.descriptors); 333 len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE,
334 dev.descriptors);
328 if (len < 0) { 335 if (len < 0) {
329 return len; 336 return len;
330 } 337 }
diff --git a/firmware/usbstack/drivers/device/usb_storage.c b/firmware/usbstack/drivers/device/usb_storage.c
index 45fd5c14b7..8fc9df672f 100644
--- a/firmware/usbstack/drivers/device/usb_storage.c
+++ b/firmware/usbstack/drivers/device/usb_storage.c
@@ -207,9 +207,12 @@ int usb_storage_driver_bind(void* controler_ops)
207 /* update device decsriptor */ 207 /* update device decsriptor */
208 storage_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket; 208 storage_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
209 209
210 /* update hs descriptors as we asume that endpoints are the same for fs and hs */ 210 /* update hs descriptors as we asume that endpoints
211 storage_hs_bulk_in_desc.bEndpointAddress = storage_fs_bulk_in_desc.bEndpointAddress; 211 are the same for fs and hs */
212 storage_hs_bulk_out_desc.bEndpointAddress = storage_fs_bulk_out_desc.bEndpointAddress; 212 storage_hs_bulk_in_desc.bEndpointAddress =
213 storage_fs_bulk_in_desc.bEndpointAddress;
214 storage_hs_bulk_out_desc.bEndpointAddress =
215 storage_fs_bulk_out_desc.bEndpointAddress;
213 216
214 return 0; 217 return 0;
215 218
@@ -218,7 +221,8 @@ autoconf_fail:
218 return -EOPNOTSUPP; 221 return -EOPNOTSUPP;
219} 222}
220 223
221void usb_storage_driver_unbind(void) { 224void usb_storage_driver_unbind(void)
225{
222 226
223 /* disable endpoints... */ 227 /* disable endpoints... */
224} 228}
@@ -240,13 +244,15 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
240 switch (request->wValue >> 8) { 244 switch (request->wValue >> 8) {
241 case USB_DT_DEVICE: 245 case USB_DT_DEVICE:
242 logf("usb storage: sending device desc"); 246 logf("usb storage: sending device desc");
243 ret = MIN(sizeof(struct usb_device_descriptor), request->wLength); 247 ret = MIN(sizeof(struct usb_device_descriptor),
248 request->wLength);
244 res.buf = &storage_device_desc; 249 res.buf = &storage_device_desc;
245 break; 250 break;
246 251
247 case USB_DT_DEVICE_QUALIFIER: 252 case USB_DT_DEVICE_QUALIFIER:
248 logf("usb storage: sending qualifier dec"); 253 logf("usb storage: sending qualifier dec");
249 ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength); 254 ret = MIN(sizeof(struct usb_qualifier_descriptor),
255 request->wLength);
250 res.buf = &storage_qualifier_desc; 256 res.buf = &storage_qualifier_desc;
251 break; 257 break;
252 258
@@ -254,7 +260,8 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
254 case USB_DT_CONFIG: 260 case USB_DT_CONFIG:
255 logf("usb storage: sending config desc"); 261 logf("usb storage: sending config desc");
256 262
257 ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff); 263 ret = config_buf(buf, request->wValue >> 8,
264 request->wValue & 0xff);
258 if (ret >= 0) { 265 if (ret >= 0) {
259 logf("%d, vs %d", request->wLength, ret); 266 logf("%d, vs %d", request->wLength, ret);
260 ret = MIN(request->wLength, (uint16_t)ret); 267 ret = MIN(request->wLength, (uint16_t)ret);
@@ -264,7 +271,8 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
264 271
265 case USB_DT_STRING: 272 case USB_DT_STRING:
266 logf("usb storage: sending string desc"); 273 logf("usb storage: sending string desc");
267 ret = usb_stack_get_string(strings, request->wValue & 0xff, buf); 274 ret = usb_stack_get_string(strings, request->wValue & 0xff,
275 buf);
268 ret = MIN(ret, request->wLength); 276 ret = MIN(ret, request->wLength);
269 res.buf = buf; 277 res.buf = buf;
270 break; 278 break;
@@ -336,7 +344,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
336 344
337 (void)index; 345 (void)index;
338 346
339 len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, dev.descriptors); 347 len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE,
348 dev.descriptors);
340 logf("result %d", len); 349 logf("result %d", len);
341 if (len < 0) { 350 if (len < 0) {
342 return len; 351 return len;