1/**
2 * \brief this file contains device related definitions for the USB client driver
3 */
4
5/*
6 * Copyright (c) 2007-2013 ETH Zurich.
7 * All rights reserved.
8 *
9 * This file is distributed under the terms in the attached LICENSE file.
10 * If you do not find this file, copies can be found by writing to:
11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
12 */
13
14#ifndef LIBUSB_DEVICE_H
15#define LIBUSB_DEVICE_H
16
17/**
18 * ------------------------------------------------------------------------
19 * USB Endpoint
20 * ------------------------------------------------------------------------
21 * This data structure defines an USB tendpoint reflecting the state on a
22 * physical endpoint on the device.
23 */
24struct usb_endpoint
25{
26    uint8_t ep_direction;           ///< the direction of this endpoint
27    uint8_t ep_number;              ///< the endpoint number
28    uint8_t ep_type;                ///< the type of this endpoint
29    uint8_t ep_usage;               ///< for isochronus only: usage
30    uint8_t ep_sync;                ///< for isochronus only: sync field
31    struct usb_interface *iface;    ///< the parent interface
32    uint8_t iface_index;            ///< the interface index
33};
34
35/// endpoint status flag for usb_status_t
36#define USB_ENDPOINT_STATUS_HALT 0x0001
37
38/// the USB control endpoint
39#define USB_ENDPOINT_CONTROL 0
40
41/// the maximum number of endpoints
42#define USB_ENDPOINT_MAX 32
43
44/**
45 * ------------------------------------------------------------------------
46 * USB Interface
47 * ------------------------------------------------------------------------
48 * This data structure defines an USB tendpoint reflecting the state on a
49 * physical endpoint on the device.
50 *
51 * Fields:
52 *  - descriptor        pointer to the interface descriptor
53 *  - alt_setting       alternative setting for this iface
54 *  - iface_index       interface index of this interface
55 *  - device            pointer to the device
56 *  - num_endpoints     the number of endpoints for this interface
57 *  - endpoints         array of pointer to the endpoints of this iface
58 */
59struct usb_interface
60{
61    uint8_t alt_setting;        ///< alternative settings
62    uint8_t parent_iface_index; ///< the parent interface index
63    uint8_t iface_number;       ///< interface number of this interface
64    uint8_t iface_class;        ///< the interface class code
65    uint8_t iface_subclass;     ///< the interface subclass code
66    uint8_t iface_protocol;     ///< the interface protocol
67    uint8_t num_endpoints;      ///< the number of endpoints in this iface
68    uint8_t config;             ///< the configuration value
69    struct usb_endpoint endpoints[USB_ENDPOINT_MAX];
70};
71
72/// used for lookups
73#define USB_INTERFACE_INDEX_ANY 0xFF
74
75/**
76 * this struct represents a device for the client drivers
77 */
78struct usb_device {
79    struct usb_interface *ifaces;   ///< the interfaces of the current config
80    struct usb_endpoint *endpoints; ///< the endpoints of the current config
81    struct usb_config_descriptor *config_desc; ///< configuration descriptor
82    uint8_t dev_class;              ///< device class code
83    uint8_t dev_subclass;           ///< device sub class code
84    uint8_t dev_protocol;           ///< device protocol
85    uint16_t vendor;                ///< vendor id
86    uint16_t product;               ///< product id
87    uint16_t version;               ///< the device version
88    uint8_t iface_max;              ///< maximum interfaces
89    uint8_t ep_max;                 ///< maximum endpoints
90    uint8_t num_config;             ///< the number of configurations
91    uint8_t current_config;         ///< the current active configuration
92};
93
94typedef struct usb_device usb_device_t;
95
96
97/*
98 * Prototypes
99 */
100void usb_device_init(void *desc);
101
102uint8_t usb_device_get_num_config(void);
103
104struct usb_interface *usb_device_get_iface(uint8_t iface);
105
106usb_error_t usb_device_get_iface_count(uint8_t *ret_count);
107
108usb_error_t usb_device_get_speed(usb_speed_t *ret_speed);
109
110usb_error_t usb_device_state(void);
111
112struct usb_config_descriptor *usb_device_get_cfg_desc(void);
113
114usb_error_t usb_device_suspend(void);
115
116usb_error_t usb_device_resume(void);
117
118usb_error_t usb_device_powersave(void);
119
120#endif /* USB_DEVICE_H_ */
121