2 LPCUSB, an USB device driver for LPC microcontrollers
3 Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "../usb/usbapi.h"
40 #define MAX_PACKET_SIZE 64
41 #define LE_WORD(x) ((x)&0xff),((x)>>8)
46 static U8 abClassReqData [4];
48 static const U8 abDescriptors [] =
55 LE_WORD(0x0200), // bcdUSB
57 0x00, // bDeviceSubClass
58 0x00, // bDeviceProtocol
59 MAX_PACKET_SIZE0, // bMaxPacketSize
60 LE_WORD(0xFFFF), // idVendor
61 LE_WORD(0x0003), // idProduct
62 LE_WORD(0x0100), // bcdDevice
63 0x01, // iManufacturer
65 0x03, // iSerialNumber
66 0x01, // bNumConfigurations
69 // Configuration descriptor
73 LE_WORD(32), // wTotalLength
74 0x01, // bNumInterfaces
75 0x01, // bConfigurationValue
76 0x00, // iConfiguration
85 0x00, // bInterfaceNumber
86 0x00, // bAlternateSetting
87 0x02, // bNumEndPoints
88 0x08, // bInterfaceClass = mass storage
89 0x06, // bInterfaceSubClass = transparent SCSI
90 0x50, // bInterfaceProtocol = BOT
98 MSC_BULK_IN_EP, // bEndpointAddress
99 0x02, // bmAttributes = bulk
100 LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
108 MSC_BULK_OUT_EP, // bEndpointAddress
109 0x02, // bmAttributes = bulk
110 LE_WORD(MAX_PACKET_SIZE), // wMaxPacketSize
114 // String descriptors
122 'L', 0, 'P', 0, 'C', 0, 'U', 0, 'S', 0, 'B', 0,
126 'P', 0, 'r', 0, 'o', 0, 'd', 0, 'u', 0, 'c', 0, 't', 0, 'X', 0,
130 'D', 0, 'E', 0, 'A', 0, 'D', 0, 'C', 0, '0', 0, 'D', 0, 'E', 0, 'C', 0, 'A', 0, 'F', 0, 'E', 0,
140 static BOOL HandleClassRequest (TSetupPacket *pSetup, int *piLen, U8 **ppbData)
142 if (pSetup->wIndex != 0)
144 DBG ("Invalid idx %X\n", pSetup->wIndex);
148 if (pSetup->wValue != 0)
150 DBG ("Invalid val %X\n", pSetup->wValue);
154 switch (pSetup->bRequest)
157 // Get max LUN (always return no LUNs)
171 if (pSetup->wLength > 0)
180 DBG ("Unhandled class\n");
191 void usbmassInit (void)
193 portENTER_CRITICAL ();
195 usbRegisterHandlers ();
196 usbRegisterDescriptors (abDescriptors);
197 usbRegisterRequestHandler (REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);
198 usbHardwareRegisterEPIntHandler (MSC_BULK_IN_EP, mscbotBulkIn);
199 usbHardwareRegisterEPIntHandler (MSC_BULK_OUT_EP, mscbotBulkOut);
200 usbHardwareNakIntEnable (INACK_BI);
201 usbSetupInterruptHandler ();
202 portEXIT_CRITICAL ();
204 usbHardwareConnect (TRUE);