blob: 35878210032e387649bce9a4f28ec1f718888554 [file] [log] [blame]
Christina Quastb123d742014-12-23 13:03:36 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/**
31 * \file
32 *
33 * \section Purpose
34 *
35 * USB Device Driver class definition.
36 *
37 * \section Usage
38 *
39 * -# Instanciate a USBDDriver object and initialize it using
40 * USBDDriver_Initialize.
41 * -# When a USB SETUP request is received, forward it to the standard
42 * driver using USBDDriver_RequestHandler.
43 * -# Check the Remote Wakeup setting via USBDDriver_IsRemoteWakeUpEnabled.
44 */
45
46#ifndef USBDDRIVER_H
47#define USBDDRIVER_H
48
49/** \addtogroup usbd_interface
50 *@{
51 */
52
53/*------------------------------------------------------------------------------
54 * Headers
55 *------------------------------------------------------------------------------*/
56
57/* These headers were introduced in C99 by working group
58 * ISO/IEC JTC1/SC22/WG14.
59 */
60#include <stdbool.h>
61#include <stdint.h>
62#include <stdio.h>
63
64#include <USBRequests.h>
65#include <USBDescriptors.h>
66#include <USBLib_Types.h>
67
68/*------------------------------------------------------------------------------
69 * Types
70 *------------------------------------------------------------------------------*/
71
72/**
73 * \typedef USBDDriverDescriptors
74 * \brief List of all descriptors used by a USB device driver. Each descriptor
75 * can be provided in two versions: full-speed and high-speed. Devices
76 * which are not high-speed capable do not need to provided high-speed
77 * descriptors and the full-speed qualifier & other speed descriptors.
78 */
79typedef struct _USBDDriverDescriptors {
80
81 /** Pointer to the full-speed device descriptor */
82 const USBDeviceDescriptor *pFsDevice;
Christina Quast49ba6bc2015-02-20 14:35:36 +010083 /** Pointer to the full-speed configuration descriptor array */
84 const USBConfigurationDescriptor **pFsConfiguration;
Christina Quastb123d742014-12-23 13:03:36 +010085 /** Pointer to the full-speed qualifier descriptor */
86 const USBDeviceQualifierDescriptor *pFsQualifier;
87 /** Pointer to the full-speed other speed configuration descriptor */
88 const USBConfigurationDescriptor *pFsOtherSpeed;
89 /** Pointer to the high-speed device descriptor */
90 const USBDeviceDescriptor *pHsDevice;
91 /** Pointer to the high-speed configuration descriptor */
92 const USBConfigurationDescriptor *pHsConfiguration;
93 /** Pointer to the high-speed qualifier descriptor */
94 const USBDeviceQualifierDescriptor *pHsQualifier;
95 /** Pointer to the high-speed other speed configuration descriptor */
96 const USBConfigurationDescriptor *pHsOtherSpeed;
97 /** Pointer to the list of string descriptors */
98 const uint8_t **pStrings;
99 /** Number of string descriptors in list */
100 uint8_t numStrings;
101
102} USBDDriverDescriptors;
103
104/**
105 * \typedef USBDDriver
106 * \brief USB device driver structure, holding a list of descriptors identifying
107 * the device as well as the driver current state.
108 */
109typedef struct _USBDDriver {
110
111 /** List of descriptors used by the device. */
112 const USBDDriverDescriptors *pDescriptors;
113 /** Current setting for each interface. */
114 uint8_t *pInterfaces;
115 /** Current configuration number (0 -> device is not configured). */
116 uint8_t cfgnum;
117 /** Indicates if remote wake up has been enabled by the host. */
118 uint8_t isRemoteWakeUpEnabled;
119 /** Features supported by OTG */
120 uint8_t otg_features_supported;
121} USBDDriver;
122
123/*------------------------------------------------------------------------------
124 * Exported functions
125 *------------------------------------------------------------------------------*/
126
127extern USBDDriver *USBD_GetDriver(void);
128extern void USBDDriver_Initialize(
129 USBDDriver *pDriver,
130 const USBDDriverDescriptors *pDescriptors,
131 uint8_t *pInterfaces);
132extern USBConfigurationDescriptor* USBDDriver_GetCfgDescriptors(
133 USBDDriver * pDriver,
134 uint8_t cfgNum);
135extern void USBDDriver_RequestHandler(
136 USBDDriver *pDriver,
137 const USBGenericRequest *pRequest);
138extern uint8_t USBDDriver_IsRemoteWakeUpEnabled(const USBDDriver *pDriver);
139extern uint8_t USBDDriver_returnOTGFeatures(const USBDDriver *pDriver);
140extern void USBDDriver_clearOTGFeatures(USBDDriver *pDriver);
141
142extern void USBDDriverCallbacks_ConfigurationChanged(uint8_t cfgnum);
143extern void USBDDriverCallbacks_InterfaceSettingChanged(uint8_t interface, uint8_t setting);
144
145/**@}*/
146
147#endif /*#ifndef USBDDRIVER_H*/
148