00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #define __SKIP_FATFS__
00036 #include "sceptre.h"
00037
00038 #include "lpcusb\target\type.h"
00039 #include "lpcusb\target\debug.h"
00040 #include "lpcusb\target\usbapi.h"
00041 #include "msc_bot.h"
00042 #include "blockdev.h"
00043
00044
00045
00046 #define MAX_PACKET_SIZE 64
00047
00048 #define LE_WORD(x) ((x)&0xFF),((x)>>8)
00049
00050
00051 static U8 abClassReqData[4];
00052
00053 static const U8 abDescriptors[] = {
00054
00055
00056 0x12,
00057 DESC_DEVICE,
00058 LE_WORD(0x0200),
00059 0x00,
00060 0x00,
00061 0x00,
00062 MAX_PACKET_SIZE0,
00063 LE_WORD(0xFFFF),
00064 LE_WORD(0x0003),
00065 LE_WORD(0x0100),
00066 0x01,
00067 0x02,
00068 0x03,
00069 0x01,
00070
00071
00072 0x09,
00073 DESC_CONFIGURATION,
00074 LE_WORD(32),
00075 0x01,
00076 0x01,
00077 0x00,
00078 0xC0,
00079 0x32,
00080
00081
00082 0x09,
00083 DESC_INTERFACE,
00084 0x00,
00085 0x00,
00086 0x02,
00087 0x08,
00088 0x06,
00089 0x50,
00090 0x00,
00091
00092 0x07,
00093 DESC_ENDPOINT,
00094 MSC_BULK_IN_EP,
00095 0x02,
00096 LE_WORD(MAX_PACKET_SIZE),
00097 0x00,
00098
00099 0x07,
00100 DESC_ENDPOINT,
00101 MSC_BULK_OUT_EP,
00102 0x02,
00103 LE_WORD(MAX_PACKET_SIZE),
00104 0x00,
00105
00106
00107 0x04,
00108 DESC_STRING,
00109 LE_WORD(0x0409),
00110
00111 0x0E,
00112 DESC_STRING,
00113 'L', 0, 'P', 0, 'C', 0, 'U', 0, 'S', 0, 'B', 0,
00114
00115 0x12,
00116 DESC_STRING,
00117 'P', 0, 'r', 0, 'o', 0, 'd', 0, 'u', 0, 'c', 0, 't', 0, 'X', 0,
00118
00119 0x1A,
00120 DESC_STRING,
00121 'D', 0, 'E', 0, 'A', 0, 'D', 0, 'C', 0, '0', 0, 'D', 0, 'E', 0, 'C', 0, 'A', 0, 'F', 0, 'E', 0,
00122
00123
00124 0
00125 };
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00143 static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
00144 {
00145 if (pSetup->wIndex != 0) {
00146 DBG("Invalid idx %X\n", pSetup->wIndex);
00147 return FALSE;
00148 }
00149 if (pSetup->wValue != 0) {
00150 DBG("Invalid val %X\n", pSetup->wValue);
00151 return FALSE;
00152 }
00153
00154 switch (pSetup->bRequest) {
00155
00156
00157 case 0xFE:
00158 *ppbData[0] = 0;
00159 *piLen = 1;
00160 break;
00161
00162
00163 case 0xFF:
00164 if (pSetup->wLength > 0) {
00165 return FALSE;
00166 }
00167 MSCBotReset();
00168 break;
00169
00170 default:
00171 DBG("Unhandled class\n");
00172 return FALSE;
00173 }
00174 return TRUE;
00175 }
00176
00177
00183 bool_t usb_mass_storage_init(void)
00184 {
00185
00186 BlockDevInit();
00187
00188
00189 USBInit();
00190
00191
00192
00193 USBHwNakIntEnable(INACK_BI);
00194
00195
00196 USBRegisterDescriptors(abDescriptors);
00197
00198
00199 USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData);
00200
00201
00202 USBHwRegisterEPIntHandler(MSC_BULK_IN_EP, MSCBotBulkIn);
00203 USBHwRegisterEPIntHandler(MSC_BULK_OUT_EP, MSCBotBulkOut);
00204
00205
00206
00207
00208
00209
00210
00211 USBHwConnect(TRUE);
00212
00213 return true;
00214 }
00215
00216
00224 bool_t usb_mass_storage_tick(void)
00225 {
00226
00227 USBHwISR();
00228 return true;
00229 }
00230