2008-03-06 21:25:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2008-04-18 17:05:15 +00:00
|
|
|
* $Id$
|
2008-03-06 21:25:09 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Frank Gevaerts
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-03-06 21:25:09 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _USB_CLASS_DRIVER_H_
|
|
|
|
#define _USB_CLASS_DRIVER_H_
|
|
|
|
|
|
|
|
/* Common api, implemented by all class drivers */
|
|
|
|
|
|
|
|
struct usb_class_driver {
|
2009-04-18 18:17:29 +00:00
|
|
|
/* First some runtime data */
|
2008-03-06 21:25:09 +00:00
|
|
|
bool enabled;
|
2008-04-26 19:02:16 +00:00
|
|
|
int first_interface;
|
|
|
|
int last_interface;
|
|
|
|
|
2009-04-18 18:17:29 +00:00
|
|
|
/* Driver api starts here */
|
2008-04-26 19:02:16 +00:00
|
|
|
|
2009-04-18 18:17:29 +00:00
|
|
|
/* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
|
2009-01-13 16:27:35 +00:00
|
|
|
bool needs_exclusive_storage;
|
2008-04-26 19:02:16 +00:00
|
|
|
|
2008-10-03 22:43:16 +00:00
|
|
|
/* Let the driver request endpoints it need. Returns zero on success */
|
|
|
|
int (*request_endpoints)(struct usb_class_driver *);
|
|
|
|
|
2008-04-26 19:02:16 +00:00
|
|
|
/* Tells the driver what its first interface number will be. The driver
|
|
|
|
returns the number of the first available interface for the next driver
|
|
|
|
(i.e. a driver with one interface will return interface+1)
|
2010-01-03 10:35:31 +00:00
|
|
|
A driver must have at least one interface
|
|
|
|
Mandatory function */
|
2008-04-26 19:02:16 +00:00
|
|
|
int (*set_first_interface)(int interface);
|
|
|
|
|
2008-03-06 21:25:09 +00:00
|
|
|
/* Asks the driver to put the interface descriptor and all other
|
2008-04-26 19:02:16 +00:00
|
|
|
needed descriptor for this driver at dest.
|
|
|
|
Returns the number of bytes taken by these descriptors.
|
2010-01-03 10:35:31 +00:00
|
|
|
Mandatory function */
|
2008-04-26 19:02:16 +00:00
|
|
|
int (*get_config_descriptor)(unsigned char *dest, int max_packet_size);
|
2008-03-06 21:25:09 +00:00
|
|
|
|
|
|
|
/* Tells the driver that a usb connection has been set up and is now
|
2009-04-18 18:17:29 +00:00
|
|
|
ready to use.
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2008-04-26 19:02:16 +00:00
|
|
|
void (*init_connection)(void);
|
2008-03-06 21:25:09 +00:00
|
|
|
|
|
|
|
/* Initialises the driver. This can be called multiple times,
|
|
|
|
and should not perform any action that can disturb other threads
|
2008-04-26 19:02:16 +00:00
|
|
|
(like getting the audio buffer)
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2008-03-06 21:25:09 +00:00
|
|
|
void (*init)(void);
|
|
|
|
|
2009-04-18 18:17:29 +00:00
|
|
|
/* Tells the driver that the usb connection is no longer active
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2008-03-06 21:25:09 +00:00
|
|
|
void (*disconnect)(void);
|
|
|
|
|
2008-10-03 22:43:16 +00:00
|
|
|
/* Tells the driver that a usb transfer has been completed. Note that "dir"
|
2009-04-18 18:17:29 +00:00
|
|
|
is relative to the host
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2008-10-03 22:43:16 +00:00
|
|
|
void (*transfer_complete)(int ep,int dir, int status, int length);
|
2008-03-06 21:25:09 +00:00
|
|
|
|
|
|
|
/* Tells the driver that a control request has come in. If the driver is
|
|
|
|
able to handle it, it should ack the request, and return true. Otherwise
|
2009-04-18 18:17:29 +00:00
|
|
|
it should return false.
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2009-04-18 20:40:50 +00:00
|
|
|
bool (*control_request)(struct usb_ctrlrequest* req, unsigned char *dest);
|
2008-03-10 20:55:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_HOTSWAP
|
|
|
|
/* Tells the driver that a hotswappable disk/card was inserted or
|
2009-04-18 18:17:29 +00:00
|
|
|
extracted
|
2010-01-03 10:35:31 +00:00
|
|
|
Optional function */
|
2008-03-10 20:55:24 +00:00
|
|
|
void (*notify_hotswap)(int volume, bool inserted);
|
|
|
|
#endif
|
2008-03-06 21:25:09 +00:00
|
|
|
};
|
|
|
|
|
2009-05-16 15:30:09 +00:00
|
|
|
#define PACK_DATA(dest, data) \
|
2009-04-18 20:04:52 +00:00
|
|
|
do { \
|
2009-05-16 15:30:09 +00:00
|
|
|
memcpy(dest, &(data), sizeof(data)); \
|
|
|
|
dest += sizeof(data); \
|
2009-04-18 20:04:52 +00:00
|
|
|
} while (0)
|
|
|
|
|
2008-03-06 21:25:09 +00:00
|
|
|
#endif
|