blob: 55fe6fb590cf3ebb092b2edaaeaa9dd0032c6db9 [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/** \file */
30/** \addtogroup usbd_composite_cdcmsd
31 *@{
32 */
33
34/*---------------------------------------------------------------------------
35 * Headers
36 *---------------------------------------------------------------------------*/
37
38#include <USBLib_Trace.h>
39
40#include <CDCMSDDriver.h>
41
42#include <CDCDSerial.h>
43#include <MSDFunction.h>
44
45/*---------------------------------------------------------------------------
46 * Defines
47 *---------------------------------------------------------------------------*/
48
49/*---------------------------------------------------------------------------
50 * Types
51 *---------------------------------------------------------------------------*/
52
53/*---------------------------------------------------------------------------
54 * Internal variables
55 *---------------------------------------------------------------------------*/
56
57/*---------------------------------------------------------------------------
58 * Internal functions
59 *---------------------------------------------------------------------------*/
60
61/*---------------------------------------------------------------------------
62 * Exported functions
63 *---------------------------------------------------------------------------*/
64
65/**
66 * Initializes the USB device CDCMSD device driver.
67 */
68void CDCMSDDriver_Initialize(
69 const USBDDriverDescriptors *pDescriptors,
70 MSDLun *pLuns, unsigned char numLuns)
71{
72 USBDDriver *pUsbd = USBD_GetDriver();
73
74 /* Initialize the standard USB driver */
75 USBDDriver_Initialize(pUsbd, pDescriptors, 0);
76
77 /* CDC */
78 CDCDSerial_Initialize(pUsbd, CDCMSDDriverDescriptors_CDC_INTERFACE);
79
80 /* MSD */
81 MSDFunction_Initialize(pUsbd, CDCMSDDriverDescriptors_MSD_INTERFACE,
82 pLuns, numLuns);
83
84 /* Initialize the USB driver */
85 USBD_Init();
86}
87
88/**
89 * Invoked whenever the configuration value of a device is changed by the host
90 * \param cfgnum Configuration number.
91 */
92void CDCMSDDriver_ConfigurationChangedHandler(unsigned char cfgnum)
93{
94 USBDDriver *pUsbd = USBD_GetDriver();
95 USBConfigurationDescriptor *pDesc;
96 if (cfgnum > 0) {
97 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
98 /* CDC */
99 CDCDSerial_ConfigureFunction((USBGenericDescriptor*)pDesc,
100 pDesc->wTotalLength);
101 /* MSD */
102 MSDFunction_Configure((USBGenericDescriptor*)pDesc,
103 pDesc->wTotalLength);
104 }
105}
106
107/**
108 * Handles CDCMSD-specific USB requests sent by the host, and forwards
109 * standard ones to the USB device driver.
110 * \param request Pointer to a USBGenericRequest instance.
111 */
112void CDCMSDDriver_RequestHandler(const USBGenericRequest *request)
113{
114 USBDDriver *pUsbd = USBD_GetDriver();
115
116 TRACE_INFO_WP("NewReq ");
117
118 if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS)
119 return;
120
121 if (MSDFunction_RequestHandler(request) == USBRC_SUCCESS)
122 return;
123
124 USBDDriver_RequestHandler(pUsbd, request);
125}
126
127/**@}*/
128