1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 Frank Gevaerts
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _USB_CLASS_DRIVER_H_
23 #define _USB_CLASS_DRIVER_H_
25 /* Common api, implemented by all class drivers */
27 struct usb_class_driver
{
28 /* First some runtime data */
33 /* Driver api starts here */
35 /* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
36 bool needs_exclusive_storage
;
38 /* Let the driver request endpoints it need. Returns zero on success */
39 int (*request_endpoints
)(struct usb_class_driver
*);
41 /* Tells the driver what its first interface number will be. The driver
42 returns the number of the first available interface for the next driver
43 (i.e. a driver with one interface will return interface+1)
44 A driver must have at least one interface
46 int (*set_first_interface
)(int interface
);
48 /* Asks the driver to put the interface descriptor and all other
49 needed descriptor for this driver at dest.
50 Returns the number of bytes taken by these descriptors.
52 int (*get_config_descriptor
)(unsigned char *dest
, int max_packet_size
);
54 /* Tells the driver that a usb connection has been set up and is now
57 void (*init_connection
)(void);
59 /* Initialises the driver. This can be called multiple times,
60 and should not perform any action that can disturb other threads
61 (like getting the audio buffer)
65 /* Tells the driver that the usb connection is no longer active
67 void (*disconnect
)(void);
69 /* Tells the driver that a usb transfer has been completed. Note that "dir"
70 is relative to the host
72 void (*transfer_complete
)(int ep
,int dir
, int status
, int length
);
74 /* Tells the driver that a control request has come in. If the driver is
75 able to handle it, it should ack the request, and return true. Otherwise
76 it should return false.
78 bool (*control_request
)(struct usb_ctrlrequest
* req
, unsigned char *dest
);
81 /* Tells the driver that a hotswappable disk/card was inserted or
84 void (*notify_hotswap
)(int volume
, bool inserted
);
88 #define PACK_DATA(dest, data) \
90 memcpy(dest, &(data), sizeof(data)); \
91 dest += sizeof(data); \