Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
USBBULK.cpp
00001 #include "stdint.h" 00002 #include "USBHAL.h" 00003 #include "USBBULK.h" 00004 00005 /* Made By Shoichi Yamasuge */ 00006 /* Operatration Movie */ 00007 /* http://youtu.be/uGPH3AwrFpU */ 00008 00009 USBBULK::USBBULK( uint16_t vendor_id, uint16_t product_id, uint16_t product_release ):USBDevice( vendor_id, product_id, product_release) 00010 { 00011 VendorId = vendor_id; 00012 ProductId = product_id; 00013 ProductReleas = product_release; 00014 } 00015 00016 00017 bool USBBULK::Write( uint8_t *Data ) 00018 { 00019 return write(EPBULK_IN, Data, MAX_BULK_SIZE, MAX_BULK_SIZE); 00020 } 00021 00022 bool USBBULK::WriteNB( uint8_t *Data ) 00023 { 00024 return writeNB(EPBULK_IN, Data, MAX_BULK_SIZE, MAX_BULK_SIZE); 00025 } 00026 00027 bool USBBULK::read( uint8_t *Data ) 00028 { 00029 uint32_t bytesRead = 0; 00030 bool result; 00031 result = USBDevice::readEP(EPBULK_OUT, Data, &bytesRead, MAX_BULK_SIZE ); 00032 #if defined(TARGET_LPC11UXX) 00033 wait_us(100); //Counter Mesure USB Bank Wait!? 00034 #endif 00035 if(!readStart(EPBULK_OUT, MAX_BULK_SIZE )) 00036 { 00037 return false; 00038 } 00039 00040 return result; 00041 00042 } 00043 00044 bool USBBULK::readNB( uint8_t *Data ) 00045 { 00046 uint32_t bytesRead = 0; 00047 bool result; 00048 result = USBDevice::readEP_NB(EPBULK_OUT, Data, &bytesRead, MAX_BULK_SIZE ); 00049 #if defined(TARGET_LPC11UXX) 00050 wait_us(100); //Counter Mesure USB Bank Wait !? 00051 #endif 00052 if(!readStart(EPBULK_OUT, MAX_BULK_SIZE )) 00053 { 00054 return false; 00055 } 00056 00057 return result; 00058 } 00059 00060 00061 // 00062 // Route callbacks from lower layers to class(es) 00063 // 00064 00065 #define DEFAULT_CONFIGURATION (1) 00066 00067 00068 bool USBBULK::USBCallback_setConfiguration(uint8_t configuration) 00069 { 00070 if (configuration != DEFAULT_CONFIGURATION) 00071 { 00072 return false; 00073 } 00074 00075 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPINT); 00076 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPINT); 00077 00078 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPINT); 00079 return true; 00080 } 00081 00082 uint8_t * USBBULK::stringLangidDesc() 00083 { 00084 static uint8_t stringLangidDescriptor[] = 00085 { 00086 0x04, /*bLength*/ 00087 0x03, /*bDescriptorType 0x03*/ 00088 0x09, 00089 0x04 /*bString Lang ID - 0x409 */ 00090 }; 00091 return stringLangidDescriptor; 00092 } 00093 00094 uint8_t * USBBULK::stringImanufacturerDesc() 00095 { 00096 static uint8_t stringImanufacturerDescriptor[] = { 00097 00, /* Dummy Lenght */ 00098 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 00099 'Y',0, 00100 'o',0, 00101 'u',0, 00102 'r',0, 00103 ' ',0, 00104 'C',0, 00105 'o',0, 00106 'm',0, 00107 'p',0, 00108 'a',0, 00109 'n',0, 00110 'y',0, 00111 ' ',0, 00112 'N',0, 00113 'a',0, 00114 'm',0, 00115 'e',0, 00116 0 ,0 00117 }; 00118 stringImanufacturerDescriptor[0] = sizeof(stringImanufacturerDescriptor-2); 00119 return stringImanufacturerDescriptor; 00120 } 00121 00122 uint8_t * USBBULK::stringIserialDesc() 00123 { 00124 static uint8_t stringIserialDescriptor[] = { 00125 00, /* Dummy Lenght */ 00126 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 00127 '0',0, 00128 '1',0, 00129 '2',0, 00130 '3',0, 00131 '4',0, 00132 '5',0, 00133 '6',0, 00134 '7',0, 00135 '8',0, 00136 '9',0, 00137 0,0 00138 }; 00139 stringIserialDescriptor[0] = sizeof(stringIserialDescriptor)-2; // bLength 00140 return stringIserialDescriptor; 00141 } 00142 00143 00144 uint8_t * USBBULK::stringIproductDesc() 00145 { 00146 static uint8_t stringIproductlDescriptor[] = { 00147 00, /* Dummy Lenght */ 00148 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 00149 'U',0, 00150 's',0, 00151 'b',0, 00152 ' ',0, 00153 'B',0, 00154 'u',0, 00155 'l',0, 00156 'k',0, 00157 ' ',0, 00158 'P',0, 00159 'r',0, 00160 'o',0, 00161 'd',0, 00162 'u',0, 00163 'c',0, 00164 't',0, 00165 0,0 00166 }; 00167 stringIproductlDescriptor[0] = sizeof(stringIproductlDescriptor)-2; // bLength 00168 return stringIproductlDescriptor; 00169 } 00170 00171 uint8_t * USBBULK::stringIConfigurationDesc() 00172 { 00173 static uint8_t stringIconfigurationDescriptor[] = { 00174 00, //bLength 00175 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/ 00176 '0',0,'1',0 /*bString iConfiguration - 01*/ 00177 }; 00178 stringIconfigurationDescriptor[0] = sizeof(stringIconfigurationDescriptor)-2; 00179 return stringIconfigurationDescriptor; 00180 } 00181 00182 00183 uint8_t * USBBULK::stringIinterfaceDesc() { 00184 static uint8_t stringIinterfaceDescriptor[] = { 00185 0, //bLength 00186 STRING_DESCRIPTOR, //bDescriptorType 0x03 00187 'U',0, 00188 's',0, 00189 'b',0, 00190 ' ',0, 00191 'B',0, 00192 'u',0, 00193 'l',0, 00194 'k',0, 00195 ' ',0, 00196 'I',0, 00197 'n',0, 00198 't',0, 00199 'e',0, 00200 'r',0, 00201 'F',0, 00202 'a',0, 00203 'c',0, 00204 'e',0, 00205 0,0 00206 }; 00207 stringIinterfaceDescriptor[0] = sizeof(stringIinterfaceDescriptor)-2; //bLength 00208 return stringIinterfaceDescriptor; 00209 } 00210 00211 #define DEFAULT_CONFIGURATION (1) 00212 00213 uint8_t * USBBULK::configurationDesc() { 00214 00215 static uint8_t configurationDescriptor[] = { 00216 /* *****Configuration Descriptor ******** */ 00217 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength (#9) 00218 CONFIGURATION_DESCRIPTOR, // bDescriptorType (#2) 00219 LSB(CONFIGURATION_DESCRIPTOR_LENGTH+INTERFACE_DESCRIPTOR_LENGTH+ENDPOINT_DESCRIPTOR_LENGTH*2), // wTotalLength (LSB) 00220 MSB(CONFIGURATION_DESCRIPTOR_LENGTH+INTERFACE_DESCRIPTOR_LENGTH+ENDPOINT_DESCRIPTOR_LENGTH*2), // wTotalLength (MSB) 00221 0x01, // bNumInterfaces 00222 DEFAULT_CONFIGURATION, // bConfigurationValue 00223 0x00, // iConfiguration 00224 C_RESERVED | C_SELF_POWERED, // bmAttributes 00225 C_POWER(250), // bMaxPower 250mA 00226 /* ****** Interface Descriptor ******** */ 00227 INTERFACE_DESCRIPTOR_LENGTH, // bLength (#9) 00228 INTERFACE_DESCRIPTOR, // bDescriptorType (#4) 00229 0x00, // bInterfaceNumber: Number of Interface 00230 0x00, // bAlternateSetting: Alternate setting 00231 0x02, // bNumEndpoints: One endpoints used 00232 VENDER_SPECIFIC_CLASS, // bInterfaceClass: Communication Interface Class 00233 0x00, // bInterfaceSubClass 00234 0x00, // bInterfaceProtocol 00235 0x00, // iInterface 00236 /* ****** EndPoint Descriptor ******** */ 00237 ENDPOINT_DESCRIPTOR_LENGTH, // bLength (#7) 00238 ENDPOINT_DESCRIPTOR, // bDescriptorType (#5) 00239 PHY_TO_DESC(EPBULK_IN), // bEndpointAddress (#81) 00240 E_BULK, // bmAttributes (#02) 00241 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) 00242 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) 00243 0, // bInterval (milliseconds 0:none..) 00244 00245 ENDPOINT_DESCRIPTOR_LENGTH, // bLength (#7) 00246 ENDPOINT_DESCRIPTOR, // bDescriptorType (#5) 00247 PHY_TO_DESC(EPBULK_OUT ), // bEndpointAddress (#02) 00248 E_BULK, // bmAttributes (#02) 00249 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) 00250 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) 00251 0, // bInterval (milliseconds 0:none..) 00252 }; 00253 return configurationDescriptor; 00254 }
Generated on Sun Jul 17 2022 00:27:15 by
1.7.2