1 /* 2 * Copyright (c) 2009, Google Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef __DEV_UDC_H 30 #define __DEV_UDC_H 31 32 #include <stdint.h> 33 34 typedef struct udc_request udc_request_t; 35 typedef struct udc_gadget udc_gadget_t; 36 typedef struct udc_device udc_device_t; 37 38 /* endpoints are opaque handles specific to the particular device controller */ 39 typedef struct udc_endpoint udc_endpoint_t; 40 41 /* USB Device Controller Transfer Request */ 42 struct udc_request { 43 void *buffer; 44 unsigned length; 45 void (*complete)(udc_request_t *req, unsigned actual, int status); 46 void *context; 47 }; 48 49 udc_request_t *udc_request_alloc(void); 50 void udc_request_free(udc_request_t *req); 51 int udc_request_queue(udc_endpoint_t *ept, udc_request_t *req); 52 int udc_request_cancel(udc_endpoint_t *ept, udc_request_t *req); 53 54 #define UDC_BULK_IN 0x82 55 #define UDC_BULK_OUT 0x02 56 57 udc_endpoint_t *udc_endpoint_alloc(unsigned type, unsigned maxpkt); 58 void udc_endpoint_free(udc_endpoint_t *ept); 59 60 #define UDC_EVENT_ONLINE 1 61 #define UDC_EVENT_OFFLINE 2 62 63 struct udc_gadget { 64 void (*notify)(udc_gadget_t *gadget, unsigned event); 65 void *context; 66 67 struct udc_gadget *next; // do not modify 68 69 uint8_t ifc_class; 70 uint8_t ifc_subclass; 71 uint8_t ifc_protocol; 72 uint8_t ifc_endpoints; 73 const char *ifc_string; 74 unsigned flags; 75 76 udc_endpoint_t **ept; 77 }; 78 79 struct udc_device { 80 uint16_t vendor_id; 81 uint16_t product_id; 82 uint16_t version_id; 83 84 const char *manufacturer; 85 const char *product; 86 const char *serialno; 87 }; 88 89 int udc_init(udc_device_t *devinfo); 90 int udc_register_gadget(udc_gadget_t *gadget); 91 int udc_start(void); 92 int udc_stop(void); 93 94 #endif 95