2 * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
5 * Short descripton of file:
6 * I take the function names and parameters mainly from
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of the FH Augsburg nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #include "../host/host.h"
46 #include "../usbspec/usb11spec.h"
47 #include "../../malloc.h"
50 /******************* Device Operations **********************/
53 * Open a device with verndor- and product-id for a communication.
55 usb_device * usb_open(u32 vendor_id, u32 product_id)
58 element * iterator = core.devices->head;
59 while(iterator != NULL) {
60 dev = (usb_device*)iterator->data;
62 if(dev->idVendor==vendor_id&&dev->idProduct==product_id)
65 iterator=iterator->next;
73 * Open a device with an class code for a communication.
75 usb_device * usb_open_class(u8 class)
78 element * iterator = core.devices->head;
79 while(iterator != NULL) {
80 dev = (usb_device*)iterator->data;
82 if(dev->bDeviceClass==class)
85 iterator=iterator->next;
91 * Close device after a communication.
93 u8 usb_close(usb_device *dev)
99 u8 usb_get_device_descriptor(usb_device *dev, char *buf,u8 size)
105 u8 usb_set_address(usb_device *dev, u8 address)
111 u8 usb_set_configuration(usb_device *dev, u8 configuration)
117 u8 usb_set_altinterface(usb_device *dev, u8 alternate)
123 u8 usb_reset(usb_device *dev)
131 /******************* Control Transfer **********************/
134 * Create a control transfer.
136 u8 usb_control_msg(usb_device *dev, u8 requesttype, u8 request, u16 value, u16 index, u16 length,char *buf, u16 size, u16 timeout)
138 //usb_control_msg(dev, 0x80, GET_DESCRIPTOR, 1, 0, 8, buf, 8, 0);
139 usb_irp *irp = (usb_irp*)malloc(sizeof(usb_irp));
143 irp->epsize = dev->bMaxPacketSize0;
144 irp->type = USB_CTRL;
147 buf[0]=(char)requesttype;
148 buf[1]=(char)request;
149 buf[2]=(char)(value >> 8);
150 buf[3]=(char)(value);
151 buf[4]=(char)(index >> 8);
152 buf[5]=(char)(index);
153 // lenght buf are the only where the order is inverted
154 buf[6]=(char)(length);
155 buf[7]=(char)(length >> 8);
158 //should be the right way around? :O
159 buf[0]=(char)requesttype;
160 buf[1]=(char)request;
161 buf[2]=(char)(value);
162 buf[3]=(char)(value >> 8);
163 buf[4]=(char)(index);
164 buf[5]=(char)(index >> 8);
165 // lenght buf are the only where the order is inverted
166 buf[6]=(char)(length);
167 buf[7]=(char)(length >> 8);
172 irp->timeout = timeout;
181 u8 usb_get_string(usb_device *dev, u8 index, u8 langid, char *buf, u8 buflen)
188 u8 usb_get_string_simple(usb_device *dev, u8 index, char *buf, u8 buflen)
194 u8 usb_get_descriptor(usb_device *dev, unsigned char type, unsigned char index, void *buf, u8 size)
201 /******************* Bulk Transfer **********************/
204 * Write to an a bulk endpoint.
206 u8 usb_bulk_write(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)
208 usb_irp * irp = (usb_irp*)malloc(sizeof(usb_irp));
210 //irp->devaddress = dev->address;
213 irp->epsize = dev->epSize[ep]; // ermitteln
214 irp->type = USB_BULK;
218 irp->timeout = timeout;
227 * Read from an bulk endpoint.
229 u8 usb_bulk_read(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)
231 usb_irp * irp = (usb_irp*)malloc(sizeof(usb_irp));
232 //irp->devaddress = dev->address;
235 irp->endpoint = ep | 0x80; // from device to host
236 irp->epsize = dev->epSize[ep]; // ermitteln
237 irp->type = USB_BULK;
241 irp->timeout = timeout;
250 /******************* Interrupt Transfer **********************/
252 * Write to an interrupt endpoint.
254 u8 usb_interrupt_write(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)
261 * Read from an interrupt endpoint.
263 u8 usb_interrupt_read(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)
270 /******************* Isochron Transfer **********************/
273 * Write to an isochron endpoint.
275 u8 usb_isochron_write(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)
282 * Read from an isochron endpoint.
284 u8 usb_isochron_read(usb_device *dev, u8 ep, char *buf, u8 size, u8 timeout)