add LPC1549, add FRDM-KL46Z, fix epComplete bit operation.

Dependents:   XBee-ExplorerLite USBLocalFileSystem USB-to-UART-bridge USBLocalFileSystem

Fork of USBDevice by mbed official

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Sat Jun 21 07:25:16 2014 +0900
Parent:
22:8615d80a0568
Child:
24:8bd969c0b0f2
Commit message:
merge(LPC11U68,LPC1549)

Changed in this revision

USBAudio/USBAudio.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBDescriptor.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBDevice.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBDevice.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBEndpoints.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBEndpoints_KL25Z.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_LPC11U.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_LPC15.cpp Show diff for this revision Revisions of this file
USBDevice/USBHAL_LPC17.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_LPC40.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_STM32F4.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBRegs_STM32.h Show annotated file Show diff for this revision Revisions of this file
USBHID/USBHID.cpp Show annotated file Show diff for this revision Revisions of this file
USBHID/USBHID.h Show annotated file Show diff for this revision Revisions of this file
USBHID/USBKeyboard.cpp Show annotated file Show diff for this revision Revisions of this file
USBHID/USBKeyboard.h Show annotated file Show diff for this revision Revisions of this file
USBHID/USBMouse.h Show annotated file Show diff for this revision Revisions of this file
USBHID/USBMouseKeyboard.cpp Show annotated file Show diff for this revision Revisions of this file
USBHID/USBMouseKeyboard.h Show annotated file Show diff for this revision Revisions of this file
USBMIDI/MIDIMessage.h Show annotated file Show diff for this revision Revisions of this file
USBMIDI/USBMIDI.h Show annotated file Show diff for this revision Revisions of this file
USBMSD/USBMSD.h Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBCDC.cpp Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBCDC.h Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBSerial.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBAudio/USBAudio.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBAudio/USBAudio.h	Sat Jun 21 07:25:16 2014 +0900
@@ -50,7 +50,7 @@
 *
 * int main() {
 *    int16_t buf[AUDIO_LENGTH_PACKET/2];
-*    
+*
 *    while (1) {
 *        // read an audio packet
 *        audio.read((uint8_t *)buf);
@@ -88,7 +88,7 @@
     * @returns volume
     */
     float getVolume();
-    
+
     /**
     * Read an audio packet. During a frame, only a single reading (you can't write and read an audio packet during the same frame)can be done using this method. Warning: Blocking
     *
@@ -97,7 +97,7 @@
     * @returns true if successfull
     */
     bool read(uint8_t * buf);
-    
+
     /**
     * Try to read an audio packet. During a frame, only a single reading (you can't write and read an audio packet during the same frame)can be done using this method. Warning: Non Blocking
     *
@@ -106,7 +106,7 @@
     * @returns true if successfull
     */
     bool readNB(uint8_t * buf);
-    
+
     /**
     * Write an audio packet. During a frame, only a single writing (you can't write and read an audio packet during the same frame)can be done using this method.
     *
@@ -114,7 +114,7 @@
     * @returns true if successful
     */
     bool write(uint8_t * buf);
-    
+
     /**
     * Write and read an audio packet at the same time (on the same frame)
     *
@@ -123,7 +123,7 @@
     * @returns true if successful
     */
     bool readWrite(uint8_t * buf_read, uint8_t * buf_write);
-    
+
 
     /** attach a handler to update the volume
      *
@@ -212,12 +212,12 @@
     * Callback called on each Start of Frame event
     */
     virtual void SOF(int frameNumber);
-    
+
     /*
     * Callback called when a packet is received
     */
     virtual bool EP3_OUT_callback();
-    
+
     /*
     * Callback called when a packet has been sent
     */
@@ -227,13 +227,13 @@
 
     // stream available ?
     volatile bool available;
-    
+
     // interrupt OUT has been received
     volatile bool interruptOUT;
-    
+
     // interrupt IN has been received
     volatile bool interruptIN;
-    
+
     // audio packet has been written
     volatile bool writeIN;
 
@@ -248,7 +248,7 @@
     // mono, stereo,...
     uint8_t channel_nb_in;
     uint8_t channel_nb_out;
-    
+
     // channel config: master, left, right
     uint8_t channel_config_in;
     uint8_t channel_config_out;
@@ -270,16 +270,16 @@
 
     // Buffer containing one audio packet (to be read)
     volatile uint8_t * buf_stream_in;
-    
+
     // Buffer containing one audio packet (to be written)
     volatile uint8_t * buf_stream_out;
-    
+
     // callback to update volume
     FunctionPointer updateVol;
-    
+
     // boolean showing that the SOF handler has been called. Useful for readNB.
     volatile bool SOF_handler;
-    
+
     volatile float volume;
 
 };
--- a/USBDevice/USBDescriptor.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBDescriptor.h	Sat Jun 21 07:25:16 2014 +0900
@@ -32,7 +32,7 @@
 
 
 /*string offset*/
-#define STRING_OFFSET_LANGID            (0) 
+#define STRING_OFFSET_LANGID            (0)
 #define STRING_OFFSET_IMANUFACTURER     (1)
 #define STRING_OFFSET_IPRODUCT          (2)
 #define STRING_OFFSET_ISERIAL           (3)
--- a/USBDevice/USBDevice.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBDevice.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -106,7 +106,7 @@
                                 transfer.ptr = stringImanufacturerDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
-                                break;       
+                                break;
                             case STRING_OFFSET_IPRODUCT:
 #ifdef DEBUG
                                 printf("3\r\n");
@@ -115,7 +115,7 @@
                                 transfer.ptr = stringIproductDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
-                                break;            
+                                break;
                             case STRING_OFFSET_ISERIAL:
 #ifdef DEBUG
                                 printf("4\r\n");
@@ -124,7 +124,7 @@
                                 transfer.ptr = stringIserialDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
-                                break;        
+                                break;
                             case STRING_OFFSET_ICONFIGURATION:
 #ifdef DEBUG
                                 printf("5\r\n");
@@ -133,7 +133,7 @@
                                 transfer.ptr = stringIConfigurationDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
-                                break; 
+                                break;
                             case STRING_OFFSET_IINTERFACE:
 #ifdef DEBUG
                                 printf("6\r\n");
@@ -142,7 +142,7 @@
                                 transfer.ptr = stringIinterfaceDesc();
                                 transfer.direction = DEVICE_TO_HOST;
                                 success = true;
-                                break; 
+                                break;
             }
             break;
         case INTERFACE_DESCRIPTOR:
@@ -357,7 +357,7 @@
     {
         success = true;
         currentInterface = transfer.setup.wIndex;
-        currentAlternate = transfer.setup.wValue;       
+        currentAlternate = transfer.setup.wValue;
     }
     return success;
 }
@@ -473,12 +473,12 @@
 
     if (success)
     {
-        /* Send the status */ 
+        /* Send the status */
         transfer.ptr = (uint8_t *)&status; /* Assumes little endian */
         transfer.remaining = sizeof(status);
         transfer.direction = DEVICE_TO_HOST;
     }
-    
+
     return success;
 }
 
@@ -546,7 +546,7 @@
     transfer.direction = 0;
     transfer.zlp = false;
     transfer.notify = false;
-    
+
 #ifdef DEBUG
     printf("dataTransferDirection: %d\r\nType: %d\r\nRecipient: %d\r\nbRequest: %d\r\nwValue: %d\r\nwIndex: %d\r\nwLength: %d\r\n",transfer.setup.bmRequestType.dataTransferDirection,
                                                                                                                                    transfer.setup.bmRequestType.Type,
@@ -593,7 +593,7 @@
         }
         else
         {
-            
+
             /* OUT data stage is required */
             if (transfer.direction != HOST_TO_DEVICE)
             {
@@ -707,7 +707,7 @@
 {
     /* Connect device */
     USBHAL::connect();
-    
+
     if (blocking) {
         /* Block if not configured */
         while (!configured());
@@ -718,6 +718,11 @@
 {
     /* Disconnect device */
     USBHAL::disconnect();
+    
+    /* Set initial device state */
+    device.state = POWERED;
+    device.configuration = 0;
+    device.suspended = false;
 }
 
 CONTROL_TRANSFER * USBDevice::getTransferPtr(void)
@@ -793,8 +798,8 @@
 
 
 USBDevice::USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release){
-    VENDOR_ID = vendor_id; 
-    PRODUCT_ID = product_id; 
+    VENDOR_ID = vendor_id;
+    PRODUCT_ID = product_id;
     PRODUCT_RELEASE = product_release;
 
     /* Set initial device state */
@@ -818,12 +823,12 @@
     {
         return false;
     }
-    
-    
+
+
     if(!configured()) {
         return false;
     }
-    
+
     /* Send report */
     result = endpointWrite(endpoint, buffer, size);
 
@@ -849,7 +854,7 @@
     {
         return false;
     }
-    
+
     if(!configured()) {
         return false;
     }
@@ -872,7 +877,7 @@
 bool USBDevice::readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize)
 {
     EP_STATUS result;
-    
+
     if(!configured()) {
         return false;
     }
@@ -889,13 +894,13 @@
 bool USBDevice::readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize)
 {
     EP_STATUS result;
-    
+
     if(!configured()) {
         return false;
     }
 
     result = endpointReadResult(endpoint, buffer, size);
-    
+
     return (result == EP_COMPLETED);
 }
 
--- a/USBDevice/USBDevice.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBDevice.h	Sat Jun 21 07:25:16 2014 +0900
@@ -27,26 +27,26 @@
 {
 public:
     USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
-    
+
     /*
     * Check if the device is configured
     *
     * @returns true if configured, false otherwise
     */
     bool configured(void);
-    
+
     /*
     * Connect a device
-    * 
+    *
     * @param blocking: block if not configured
     */
     void connect(bool blocking = true);
-    
+
     /*
     * Disconnect a device
     */
     void disconnect(void);
-    
+
     /*
     * Add an endpoint
     *
@@ -65,7 +65,7 @@
     * @return true if successful
     */
     bool readStart(uint8_t endpoint, uint32_t maxSize);
-    
+
     /*
     * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
     * must be called.
@@ -79,20 +79,20 @@
     * @returns true if successful
     */
     bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
-    
+
     /*
     * Read a certain endpoint.
     *
     * Warning: non blocking
     *
     * @param endpoint endpoint which will be read
-    * @param buffer buffer will be filled with the data received (if data are available) 
+    * @param buffer buffer will be filled with the data received (if data are available)
     * @param size the number of bytes read will be stored in *size
     * @param maxSize the maximum length that can be read
     * @returns true if successful
     */
     bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
-    
+
     /*
     * Write a certain endpoint.
     *
@@ -104,8 +104,8 @@
     * @param maxSize the maximum length that can be written on this endpoint
     */
     bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
-    
-    
+
+
     /*
     * Write a certain endpoint.
     *
@@ -118,14 +118,14 @@
     */
     bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
 
-    
+
     /*
     * Called by USBDevice layer on bus reset. Warning: Called in ISR context
     *
     * May be used to reset state
     */
     virtual void USBCallback_busReset(void) {};
-    
+
     /*
     * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
     * This is used to handle extensions to standard requests
@@ -133,8 +133,8 @@
     *
     * @returns true if class handles this request
     */
-    virtual bool USBCallback_request() { return false; };   
-    
+    virtual bool USBCallback_request() { return false; };
+
     /*
     * Called by USBDevice on Endpoint0 request completion
     * if the 'notify' flag has been set to true. Warning: Called in ISR context
@@ -146,7 +146,7 @@
     * @param length length of this buffer
     */
     virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
-    
+
     /*
     * Called by USBDevice layer. Set configuration of the device.
     * For instance, you can add all endpoints that you need on this function.
@@ -154,7 +154,7 @@
     * @param configuration Number of the configuration
     */
     virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
-    
+
     /*
      * Called by USBDevice layer. Set interface/alternate of the device.
      *
@@ -170,63 +170,63 @@
     * @returns pointer to the device descriptor
     */
     virtual uint8_t * deviceDesc();
-    
+
     /*
     * Get configuration descriptor
     *
     * @returns pointer to the configuration descriptor
     */
     virtual uint8_t * configurationDesc(){return NULL;};
-    
+
     /*
     * Get string lang id descriptor
     *
     * @return pointer to the string lang id descriptor
     */
     virtual uint8_t * stringLangidDesc();
-    
+
     /*
     * Get string manufacturer descriptor
     *
     * @returns pointer to the string manufacturer descriptor
     */
     virtual uint8_t * stringImanufacturerDesc();
-    
+
     /*
     * Get string product descriptor
     *
     * @returns pointer to the string product descriptor
     */
     virtual uint8_t * stringIproductDesc();
-    
+
     /*
     * Get string serial descriptor
     *
     * @returns pointer to the string serial descriptor
     */
     virtual uint8_t * stringIserialDesc();
-    
+
     /*
     * Get string configuration descriptor
     *
     * @returns pointer to the string configuration descriptor
     */
     virtual uint8_t * stringIConfigurationDesc();
-    
+
     /*
     * Get string interface descriptor
     *
     * @returns pointer to the string interface descriptor
     */
     virtual uint8_t * stringIinterfaceDesc();
-    
+
     /*
     * Get the length of the report descriptor
     *
     * @returns length of the report descriptor
     */
     virtual uint16_t reportDescLength() { return 0; };
-    
+
 
 
 protected:
@@ -238,7 +238,7 @@
     virtual void suspendStateChanged(unsigned int suspended);
     uint8_t * findDescriptor(uint8_t descriptorType);
     CONTROL_TRANSFER * getTransferPtr(void);
-    
+
     uint16_t VENDOR_ID;
     uint16_t PRODUCT_ID;
     uint16_t PRODUCT_RELEASE;
@@ -262,7 +262,7 @@
 
     CONTROL_TRANSFER transfer;
     USB_DEVICE device;
-    
+
     uint16_t currentInterface;
     uint8_t currentAlternate;
 };
--- a/USBDevice/USBEndpoints.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBEndpoints.h	Sat Jun 21 07:25:16 2014 +0900
@@ -39,7 +39,7 @@
 /* Include configuration for specific target */
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
 #include "USBEndpoints_LPC17_LPC23.h"
-#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)||defined(TARGET_LPC1549)
+#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347) || defined (TARGET_LPC11U6X) || defined (TARGET_LPC1549)
 #include "USBEndpoints_LPC11U.h"
 #elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
 #include "USBEndpoints_KL25Z.h"
--- a/USBDevice/USBEndpoints_KL25Z.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBEndpoints_KL25Z.h	Sat Jun 21 07:25:16 2014 +0900
@@ -23,38 +23,38 @@
 
 /*      Endpoint    No.   */
 /*      ----------------  */
-#define EP0OUT      (0)  
-#define EP0IN       (1)  
-#define EP1OUT      (2)  
-#define EP1IN       (3)  
-#define EP2OUT      (4)  
-#define EP2IN       (5)  
-#define EP3OUT      (6)  
-#define EP3IN       (7)  
-#define EP4OUT      (8)  
-#define EP4IN       (9)  
-#define EP5OUT      (10) 
-#define EP5IN       (11) 
-#define EP6OUT      (12) 
-#define EP6IN       (13) 
-#define EP7OUT      (14) 
-#define EP7IN       (15) 
-#define EP8OUT      (16) 
-#define EP8IN       (17) 
-#define EP9OUT      (18) 
-#define EP9IN       (19) 
-#define EP10OUT     (20) 
-#define EP10IN      (21) 
-#define EP11OUT     (22) 
-#define EP11IN      (23) 
-#define EP12OUT     (24) 
-#define EP12IN      (25) 
-#define EP13OUT     (26) 
-#define EP13IN      (27) 
-#define EP14OUT     (28) 
-#define EP14IN      (29) 
-#define EP15OUT     (30) 
-#define EP15IN      (31) 
+#define EP0OUT      (0)
+#define EP0IN       (1)
+#define EP1OUT      (2)
+#define EP1IN       (3)
+#define EP2OUT      (4)
+#define EP2IN       (5)
+#define EP3OUT      (6)
+#define EP3IN       (7)
+#define EP4OUT      (8)
+#define EP4IN       (9)
+#define EP5OUT      (10)
+#define EP5IN       (11)
+#define EP6OUT      (12)
+#define EP6IN       (13)
+#define EP7OUT      (14)
+#define EP7IN       (15)
+#define EP8OUT      (16)
+#define EP8IN       (17)
+#define EP9OUT      (18)
+#define EP9IN       (19)
+#define EP10OUT     (20)
+#define EP10IN      (21)
+#define EP11OUT     (22)
+#define EP11IN      (23)
+#define EP12OUT     (24)
+#define EP12IN      (25)
+#define EP13OUT     (26)
+#define EP13IN      (27)
+#define EP14OUT     (28)
+#define EP14IN      (29)
+#define EP15OUT     (30)
+#define EP15IN      (31)
 
 /* Maximum Packet sizes */
 
--- a/USBDevice/USBHAL.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBHAL.h	Sat Jun 21 07:25:16 2014 +0900
@@ -58,7 +58,7 @@
     bool realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options);
     bool getEndpointStallState(unsigned char endpoint);
     uint32_t endpointReadcore(uint8_t endpoint, uint8_t *buffer);
-    
+
 protected:
     virtual void busReset(void){};
     virtual void EP0setupCallback(void){};
@@ -67,7 +67,7 @@
     virtual void connectStateChanged(unsigned int connected){};
     virtual void suspendStateChanged(unsigned int suspended){};
     virtual void SOF(int frameNumber){};
-            
+
     virtual bool EP1_OUT_callback(){return false;};
     virtual bool EP1_IN_callback(){return false;};
     virtual bool EP2_OUT_callback(){return false;};
@@ -102,7 +102,7 @@
     virtual bool EP15_IN_callback(){return false;};
 #endif
 #endif
-    
+
 private:
     void usbisr(void);
     static void _usbisr(void);
--- a/USBDevice/USBHAL_LPC11U.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBHAL_LPC11U.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -16,17 +16,20 @@
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC1347)
+#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC1347) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPC11U68) || defined(TARGET_LPC1549)
 
-#if defined(TARGET_LPC1347)
+#if defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
 #define USB_IRQ USB_IRQ_IRQn
-#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)
+#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPC11U68)
 #define USB_IRQ USB_IRQn
 #endif
 
 #include "USBHAL.h"
 
 USBHAL * USBHAL::instance;
+#if defined(TARGET_LPC1549)
+static uint8_t usbmem[2048] __attribute__((aligned(2048)));
+#endif
 
 // Valid physical endpoint numbers are 0 to (NUMBER_OF_PHYSICAL_ENDPOINTS-1)
 #define LAST_PHYSICAL_ENDPOINT (NUMBER_OF_PHYSICAL_ENDPOINTS-1)
@@ -42,12 +45,21 @@
 #define OUT_EP(endpoint)    ((endpoint) & 1U ? false : true)
 
 // USB RAM
+#if defined(TARGET_LPC1549)
+#define USB_RAM_START ((uint32_t)usbmem)
+#define USB_RAM_SIZE  sizeof(usbmem)
+#else
 #define USB_RAM_START (0x20004000)
 #define USB_RAM_SIZE  (0x00000800)
+#endif
 
 // SYSAHBCLKCTRL
+#if defined(TARGET_LPC1549)
+#define CLK_USB     (1UL<<23)
+#else
 #define CLK_USB     (1UL<<14)
 #define CLK_USBRAM  (1UL<<27)
+#endif
 
 // USB Information register
 #define FRAME_NR(a)     ((a) & 0x7ff)   // Frame number
@@ -134,7 +146,7 @@
 
 USBHAL::USBHAL(void) {
     NVIC_DisableIRQ(USB_IRQ);
-    
+
     // fill in callback array
     epCallback[0] = &USBHAL::EP1_OUT_callback;
     epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -145,11 +157,42 @@
     epCallback[6] = &USBHAL::EP4_OUT_callback;
     epCallback[7] = &USBHAL::EP4_IN_callback;
 
-    #if defined(TARGET_LPC11U35_401)
+#if defined(TARGET_LPC1549)
+    /* Set USB PLL input to system oscillator */
+    LPC_SYSCON->USBPLLCLKSEL = 0x01;
+
+    /* Setup USB PLL  (FCLKIN = 12MHz) * 4 = 48MHz
+       MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
+       FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
+       FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
+    LPC_SYSCON->USBPLLCTRL = (0x3 | (1UL << 6));
+
+    /* Powerup USB PLL */  
+    LPC_SYSCON->PDRUNCFG &= ~(CLK_USB);
+
+    /* Wait for PLL to lock */
+    while(!(LPC_SYSCON->USBPLLSTAT & 0x01));
+
+    /* enable USB main clock */
+    LPC_SYSCON->USBCLKSEL = 0x02;
+    LPC_SYSCON->USBCLKDIV = 1;
+
+    /* Enable AHB clock to the USB block. */
+    LPC_SYSCON->SYSAHBCLKCTRL1 |= CLK_USB;
+
+    /* power UP USB Phy */
+    LPC_SYSCON->PDRUNCFG &= ~(1UL << 9);
+
+    /* Reset USB block */
+    LPC_SYSCON->PRESETCTRL1 |= (CLK_USB);
+    LPC_SYSCON->PRESETCTRL1 &= ~(CLK_USB);
+
+#else
+    #if defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
     // USB_VBUS input with pull-down
     LPC_IOCON->PIO0_3 = 0x00000009;
     #endif
-    
+
     // nUSB_CONNECT output
     LPC_IOCON->PIO0_6 = 0x00000001;
 
@@ -158,7 +201,7 @@
 
     // Ensure device disconnected (DCON not set)
     LPC_USB->DEVCMDSTAT = 0;
-
+#endif
     // to ensure that the USB host sees the device as
     // disconnected if the target CPU is reset.
     wait(0.3);
@@ -287,13 +330,13 @@
             bf = 0;
         }
     }
-    
+
     // if isochronous endpoint, T = 1
     if(endpointState[endpoint].options & ISOCHRONOUS)
     {
         flags |= CMDSTS_T;
     }
-        
+
     //Active the endpoint for reading
     ep[PHY_TO_LOG(endpoint)].out[bf] = CMDSTS_A | CMDSTS_NBYTES(maximumSize) \
                                        | CMDSTS_ADDRESS_OFFSET((uint32_t)ct->out) | flags;
@@ -408,7 +451,7 @@
 
 EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
     uint32_t bf;
-    
+
     // Validate parameters
     if (endpoint > LAST_PHYSICAL_ENDPOINT) {
         return EP_INVALID;
@@ -680,7 +723,7 @@
         // EP0IN ACK event (IN data sent)
         EP0in();
     }
-    
+
     for (uint8_t num = 2; num < 5*2; num++) {
         if (LPC_USB->INTSTAT & EP(num)) {
             LPC_USB->INTSTAT = EP(num);
--- a/USBDevice/USBHAL_LPC15.cpp	Tue May 13 15:31:04 2014 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,701 +0,0 @@
-/* Copyright (c) 2010-2011 mbed.org, MIT License
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
-* and associated documentation files (the "Software"), to deal in the Software without
-* restriction, including without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or
-* substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
-* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#if defined(TARGET_LPC1549)
-
-#define USB_IRQ USB_IRQ_IRQn
-
-#include "USBHAL.h"
-
-USBHAL * USBHAL::instance;
-static uint8_t usbmem[2048] __attribute__((aligned(2048)));
-
-// Valid physical endpoint numbers are 0 to (NUMBER_OF_PHYSICAL_ENDPOINTS-1)
-#define LAST_PHYSICAL_ENDPOINT (NUMBER_OF_PHYSICAL_ENDPOINTS-1)
-
-// Convert physical endpoint number to register bit
-#define EP(endpoint) (1UL<<endpoint)
-
-// Convert physical to logical
-#define PHY_TO_LOG(endpoint)    ((endpoint)>>1)
-
-// Get endpoint direction
-#define IN_EP(endpoint)     ((endpoint) & 1U ? true : false)
-#define OUT_EP(endpoint)    ((endpoint) & 1U ? false : true)
-
-// USB RAM
-#define USB_RAM_START ((uint32_t)usbmem)
-#define USB_RAM_SIZE  sizeof(usbmem)
-
-// SYSAHBCLKCTRL1
-#define CLK_USB     (1UL<<23)
-
-// USB Information register
-#define FRAME_NR(a)     ((a) & 0x7ff)   // Frame number
-
-// USB Device Command/Status register
-#define DEV_ADDR_MASK   (0x7f)          // Device address
-#define DEV_ADDR(a)     ((a) & DEV_ADDR_MASK)
-#define DEV_EN          (1UL<<7)        // Device enable
-#define SETUP           (1UL<<8)        // SETUP token received
-#define PLL_ON          (1UL<<9)        // PLL enabled in suspend
-#define DCON            (1UL<<16)       // Device status - connect
-#define DSUS            (1UL<<17)       // Device status - suspend
-#define DCON_C          (1UL<<24)       // Connect change
-#define DSUS_C          (1UL<<25)       // Suspend change
-#define DRES_C          (1UL<<26)       // Reset change
-#define VBUSDEBOUNCED   (1UL<<28)       // Vbus detected
-
-// Endpoint Command/Status list
-#define CMDSTS_A                 (1UL<<31)          // Active
-#define CMDSTS_D                 (1UL<<30)          // Disable
-#define CMDSTS_S                 (1UL<<29)          // Stall
-#define CMDSTS_TR                (1UL<<28)          // Toggle Reset
-#define CMDSTS_RF                (1UL<<27)          // Rate Feedback mode
-#define CMDSTS_TV                (1UL<<27)          // Toggle Value
-#define CMDSTS_T                 (1UL<<26)          // Endpoint Type
-#define CMDSTS_NBYTES(n)         (((n)&0x3ff)<<16)  // Number of bytes
-#define CMDSTS_ADDRESS_OFFSET(a) (((a)>>6)&0xffff)  // Buffer start address
-
-#define BYTES_REMAINING(s)       (((s)>>16)&0x3ff)  // Bytes remaining after transfer
-
-// USB Non-endpoint interrupt sources
-#define FRAME_INT   (1UL<<30)
-#define DEV_INT     (1UL<<31)
-
-static volatile int epComplete = 0;
-
-// One entry for a double-buffered logical endpoint in the endpoint
-// command/status list. Endpoint 0 is single buffered, out[1] is used
-// for the SETUP packet and in[1] is not used
-typedef struct {
-    uint32_t out[2];
-    uint32_t in[2];
-} PACKED EP_COMMAND_STATUS;
-
-typedef struct {
-    uint8_t out[MAX_PACKET_SIZE_EP0];
-    uint8_t in[MAX_PACKET_SIZE_EP0];
-    uint8_t setup[SETUP_PACKET_SIZE];
-} PACKED CONTROL_TRANSFER;
-
-typedef struct {
-    uint32_t    maxPacket;
-    uint32_t    buffer[2];
-    uint32_t    options;
-} PACKED EP_STATE;
-
-static volatile EP_STATE endpointState[NUMBER_OF_PHYSICAL_ENDPOINTS];
-
-// Pointer to the endpoint command/status list
-static EP_COMMAND_STATUS *ep = NULL;
-
-// Pointer to endpoint 0 data (IN/OUT and SETUP)
-static CONTROL_TRANSFER *ct = NULL;
-
-// Shadow DEVCMDSTAT register to avoid accidentally clearing flags or
-// initiating a remote wakeup event.
-static volatile uint32_t devCmdStat;
-
-// Pointers used to allocate USB RAM
-static uint32_t usbRamPtr = USB_RAM_START;
-static uint32_t epRamPtr = 0; // Buffers for endpoints > 0 start here
-
-#define ROUND_UP_TO_MULTIPLE(x, m) ((((x)+((m)-1))/(m))*(m))
-
-void USBMemCopy(uint8_t *dst, uint8_t *src, uint32_t size);
-void USBMemCopy(uint8_t *dst, uint8_t *src, uint32_t size) {
-    if (size > 0) {
-        do {
-            *dst++ = *src++;
-        } while (--size > 0);
-    }
-}
-
-
-USBHAL::USBHAL(void) {
-    NVIC_DisableIRQ(USB_IRQ);
-    
-    // fill in callback array
-    epCallback[0] = &USBHAL::EP1_OUT_callback;
-    epCallback[1] = &USBHAL::EP1_IN_callback;
-    epCallback[2] = &USBHAL::EP2_OUT_callback;
-    epCallback[3] = &USBHAL::EP2_IN_callback;
-    epCallback[4] = &USBHAL::EP3_OUT_callback;
-    epCallback[5] = &USBHAL::EP3_IN_callback;
-    epCallback[6] = &USBHAL::EP4_OUT_callback;
-    epCallback[7] = &USBHAL::EP4_IN_callback;
-
-    /* Set USB PLL input to main oscillator */
-    LPC_SYSCON->USBPLLCLKSEL = 0x01;
-    /* Setup USB PLL  (FCLKIN = 12MHz) * 4 = 48MHz
-       MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
-       FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
-       FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
-    LPC_SYSCON->USBPLLCTRL = 3|(1<<6);
-
-    /* Powerup USB PLL */  
-    LPC_SYSCON->PDRUNCFG &= ~(1<<23);
-
-    /* Wait for PLL to lock */
-    while(!(LPC_SYSCON->USBPLLSTAT&0x01));
-
-    /* enable USB main clock */
-    LPC_SYSCON->USBCLKSEL = 0x02;
-    LPC_SYSCON->USBCLKDIV = 1;
-    /* Enable AHB clock to the USB block. */
-    LPC_SYSCON->SYSAHBCLKCTRL1 |= CLK_USB;
-    /* power UP USB Phy */
-    LPC_SYSCON->PDRUNCFG &= ~(1<<9);
-    /* Reset USB block */
-    LPC_SYSCON->PRESETCTRL1 |= (1<23);
-
-    // to ensure that the USB host sees the device as
-    // disconnected if the target CPU is reset.
-    wait(0.3);
-
-    // Reserve space in USB RAM for endpoint command/status list
-    // Must be 256 byte aligned
-    usbRamPtr = ROUND_UP_TO_MULTIPLE(usbRamPtr, 256);
-    ep = (EP_COMMAND_STATUS *)usbRamPtr;
-    usbRamPtr += (sizeof(EP_COMMAND_STATUS) * NUMBER_OF_LOGICAL_ENDPOINTS);
-    LPC_USB->EPLISTSTART = (uint32_t)(ep) & 0xffffff00;
-
-    // Reserve space in USB RAM for Endpoint 0
-    // Must be 64 byte aligned
-    usbRamPtr = ROUND_UP_TO_MULTIPLE(usbRamPtr, 64);
-    ct = (CONTROL_TRANSFER *)usbRamPtr;
-    usbRamPtr += sizeof(CONTROL_TRANSFER);
-    LPC_USB->DATABUFSTART =(uint32_t)(ct) & 0xffc00000;
-
-    // Setup command/status list for EP0
-    ep[0].out[0] = 0;
-    ep[0].in[0] =  0;
-    ep[0].out[1] = CMDSTS_ADDRESS_OFFSET((uint32_t)ct->setup);
-
-    // Route all interrupts to IRQ, some can be routed to
-    // USB_FIQ if you wish.
-    LPC_USB->INTROUTING = 0;
-
-    // Set device address 0, enable USB device, no remote wakeup
-    devCmdStat = DEV_ADDR(0) | DEV_EN | DSUS;
-    LPC_USB->DEVCMDSTAT = devCmdStat;
-
-    // Enable interrupts for device events and EP0
-    LPC_USB->INTEN = DEV_INT | EP(EP0IN) | EP(EP0OUT) | FRAME_INT;
-    instance = this;
-
-    //attach IRQ handler and enable interrupts
-    NVIC_SetVector(USB_IRQ, (uint32_t)&_usbisr);
-}
-
-USBHAL::~USBHAL(void) {
-    // Ensure device disconnected (DCON not set)
-    LPC_USB->DEVCMDSTAT = 0;
-    // Disable USB interrupts
-    NVIC_DisableIRQ(USB_IRQ);
-}
-
-void USBHAL::connect(void) {
-    NVIC_EnableIRQ(USB_IRQ);
-    devCmdStat |= DCON;
-    LPC_USB->DEVCMDSTAT = devCmdStat;
-}
-
-void USBHAL::disconnect(void) {
-    NVIC_DisableIRQ(USB_IRQ);
-    devCmdStat &= ~DCON;
-    LPC_USB->DEVCMDSTAT = devCmdStat;
-}
-
-void USBHAL::configureDevice(void) {
-    // Not required
-}
-
-void USBHAL::unconfigureDevice(void) {
-    // Not required
-}
-
-void USBHAL::EP0setup(uint8_t *buffer) {
-    // Copy setup packet data
-    USBMemCopy(buffer, ct->setup, SETUP_PACKET_SIZE);
-}
-
-void USBHAL::EP0read(void) {
-    // Start an endpoint 0 read
-
-    // The USB ISR will call USBDevice_EP0out() when a packet has been read,
-    // the USBDevice layer then calls USBBusInterface_EP0getReadResult() to
-    // read the data.
-
-    ep[0].out[0] = CMDSTS_A |CMDSTS_NBYTES(MAX_PACKET_SIZE_EP0) \
-                   | CMDSTS_ADDRESS_OFFSET((uint32_t)ct->out);
-}
-
-uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) {
-    // Complete an endpoint 0 read
-    uint32_t bytesRead;
-
-    // Find how many bytes were read
-    bytesRead = MAX_PACKET_SIZE_EP0 - BYTES_REMAINING(ep[0].out[0]);
-
-    // Copy data
-    USBMemCopy(buffer, ct->out, bytesRead);
-    return bytesRead;
-}
-
-
-void USBHAL::EP0readStage(void) {
-    // Not required
-}
-
-void USBHAL::EP0write(uint8_t *buffer, uint32_t size) {
-    // Start and endpoint 0 write
-
-    // The USB ISR will call USBDevice_EP0in() when the data has
-    // been written, the USBDevice layer then calls
-    // USBBusInterface_EP0getWriteResult() to complete the transaction.
-
-    // Copy data
-    USBMemCopy(ct->in, buffer, size);
-
-    // Start transfer
-    ep[0].in[0] = CMDSTS_A | CMDSTS_NBYTES(size) \
-                  | CMDSTS_ADDRESS_OFFSET((uint32_t)ct->in);
-}
-
-
-EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) {
-    uint8_t bf = 0;
-    uint32_t flags = 0;
-
-    //check which buffer must be filled
-    if (LPC_USB->EPBUFCFG & EP(endpoint)) {
-        // Double buffered
-        if (LPC_USB->EPINUSE & EP(endpoint)) {
-            bf = 1;
-        } else {
-            bf = 0;
-        }
-    }
-    
-    // if isochronous endpoint, T = 1
-    if(endpointState[endpoint].options & ISOCHRONOUS)
-    {
-        flags |= CMDSTS_T;
-    }
-        
-    //Active the endpoint for reading
-    ep[PHY_TO_LOG(endpoint)].out[bf] = CMDSTS_A | CMDSTS_NBYTES(maximumSize) \
-                                       | CMDSTS_ADDRESS_OFFSET((uint32_t)ct->out) | flags;
-    return EP_PENDING;
-}
-
-EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t *data, uint32_t *bytesRead) {
-
-    uint8_t bf = 0;
-
-    if (!(epComplete & EP(endpoint)))
-        return EP_PENDING;
-    else {
-        epComplete &= ~EP(endpoint);
-
-        //check which buffer has been filled
-        if (LPC_USB->EPBUFCFG & EP(endpoint)) {
-            // Double buffered (here we read the previous buffer which was used)
-            if (LPC_USB->EPINUSE & EP(endpoint)) {
-                bf = 0;
-            } else {
-                bf = 1;
-            }
-        }
-
-        // Find how many bytes were read
-        *bytesRead = (uint32_t) (endpointState[endpoint].maxPacket - BYTES_REMAINING(ep[PHY_TO_LOG(endpoint)].out[bf]));
-
-        // Copy data
-        USBMemCopy(data, ct->out, *bytesRead);
-        return EP_COMPLETED;
-    }
-}
-
-void USBHAL::EP0getWriteResult(void) {
-    // Not required
-}
-
-void USBHAL::EP0stall(void) {
-    ep[0].in[0] = CMDSTS_S;
-    ep[0].out[0] = CMDSTS_S;
-}
-
-void USBHAL::setAddress(uint8_t address) {
-    devCmdStat &= ~DEV_ADDR_MASK;
-    devCmdStat |= DEV_ADDR(address);
-    LPC_USB->DEVCMDSTAT = devCmdStat;
-}
-
-EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) {
-    uint32_t flags = 0;
-    uint32_t bf;
-
-    // Validate parameters
-    if (data == NULL) {
-        return EP_INVALID;
-    }
-
-    if (endpoint > LAST_PHYSICAL_ENDPOINT) {
-        return EP_INVALID;
-    }
-
-    if ((endpoint==EP0IN) || (endpoint==EP0OUT)) {
-        return EP_INVALID;
-    }
-
-    if (size > endpointState[endpoint].maxPacket) {
-        return EP_INVALID;
-    }
-
-    if (LPC_USB->EPBUFCFG & EP(endpoint)) {
-        // Double buffered
-        if (LPC_USB->EPINUSE & EP(endpoint)) {
-            bf = 1;
-        } else {
-            bf = 0;
-        }
-    } else {
-        // Single buffered
-        bf = 0;
-    }
-
-    // Check if already active
-    if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_A) {
-        return EP_INVALID;
-    }
-
-    // Check if stalled
-    if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_S) {
-        return EP_STALLED;
-    }
-
-    // Copy data to USB RAM
-    USBMemCopy((uint8_t *)endpointState[endpoint].buffer[bf], data, size);
-
-    // Add options
-    if (endpointState[endpoint].options & RATE_FEEDBACK_MODE) {
-        flags |= CMDSTS_RF;
-    }
-
-    if (endpointState[endpoint].options & ISOCHRONOUS) {
-        flags |= CMDSTS_T;
-    }
-
-    // Add transfer
-    ep[PHY_TO_LOG(endpoint)].in[bf] = CMDSTS_ADDRESS_OFFSET( \
-                                      endpointState[endpoint].buffer[bf]) \
-                                      | CMDSTS_NBYTES(size) | CMDSTS_A | flags;
-
-    return EP_PENDING;
-}
-
-EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
-    uint32_t bf;
-    
-    // Validate parameters
-    if (endpoint > LAST_PHYSICAL_ENDPOINT) {
-        return EP_INVALID;
-    }
-
-    if (OUT_EP(endpoint)) {
-        return EP_INVALID;
-    }
-
-    if (LPC_USB->EPBUFCFG & EP(endpoint)) {
-        // Double buffered     // TODO: FIX THIS
-        if (LPC_USB->EPINUSE & EP(endpoint)) {
-            bf = 1;
-        } else {
-            bf = 0;
-        }
-    } else {
-        // Single buffered
-        bf = 0;
-    }
-
-    // Check if endpoint still active
-    if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_A) {
-        return EP_PENDING;
-    }
-
-    // Check if stalled
-    if (ep[PHY_TO_LOG(endpoint)].in[bf] & CMDSTS_S) {
-        return EP_STALLED;
-    }
-
-    return EP_COMPLETED;
-}
-
-void USBHAL::stallEndpoint(uint8_t endpoint) {
-
-    // FIX: should this clear active bit?
-    if (IN_EP(endpoint)) {
-        ep[PHY_TO_LOG(endpoint)].in[0] |= CMDSTS_S;
-        ep[PHY_TO_LOG(endpoint)].in[1] |= CMDSTS_S;
-    } else {
-        ep[PHY_TO_LOG(endpoint)].out[0] |= CMDSTS_S;
-        ep[PHY_TO_LOG(endpoint)].out[1] |= CMDSTS_S;
-    }
-}
-
-void USBHAL::unstallEndpoint(uint8_t endpoint) {
-    if (LPC_USB->EPBUFCFG & EP(endpoint)) {
-        // Double buffered
-        if (IN_EP(endpoint)) {
-            ep[PHY_TO_LOG(endpoint)].in[0] = 0; // S = 0
-            ep[PHY_TO_LOG(endpoint)].in[1] = 0; // S = 0
-
-            if (LPC_USB->EPINUSE & EP(endpoint)) {
-                ep[PHY_TO_LOG(endpoint)].in[1] = CMDSTS_TR; // S = 0, TR = 1, TV = 0
-            } else {
-                ep[PHY_TO_LOG(endpoint)].in[0] = CMDSTS_TR; // S = 0, TR = 1, TV = 0
-            }
-        } else {
-            ep[PHY_TO_LOG(endpoint)].out[0] = 0; // S = 0
-            ep[PHY_TO_LOG(endpoint)].out[1] = 0; // S = 0
-
-            if (LPC_USB->EPINUSE & EP(endpoint)) {
-                ep[PHY_TO_LOG(endpoint)].out[1] = CMDSTS_TR; // S = 0, TR = 1, TV = 0
-            } else {
-                ep[PHY_TO_LOG(endpoint)].out[0] = CMDSTS_TR; // S = 0, TR = 1, TV = 0
-            }
-        }
-    } else {
-        // Single buffered
-        if (IN_EP(endpoint)) {
-            ep[PHY_TO_LOG(endpoint)].in[0] = CMDSTS_TR;     // S = 0, TR = 1, TV = 0
-        } else {
-            ep[PHY_TO_LOG(endpoint)].out[0] = CMDSTS_TR;    // S = 0, TR = 1, TV = 0
-        }
-    }
-}
-
-bool USBHAL::getEndpointStallState(unsigned char endpoint) {
-    if (IN_EP(endpoint)) {
-        if (LPC_USB->EPINUSE & EP(endpoint)) {
-            if (ep[PHY_TO_LOG(endpoint)].in[1] & CMDSTS_S) {
-                return true;
-            }
-        } else {
-            if (ep[PHY_TO_LOG(endpoint)].in[0] & CMDSTS_S) {
-                return true;
-            }
-        }
-    } else {
-        if (LPC_USB->EPINUSE & EP(endpoint)) {
-            if (ep[PHY_TO_LOG(endpoint)].out[1] & CMDSTS_S) {
-                return true;
-            }
-        } else {
-            if (ep[PHY_TO_LOG(endpoint)].out[0] & CMDSTS_S) {
-                return true;
-            }
-        }
-    }
-
-    return false;
-}
-
-bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options) {
-    uint32_t tmpEpRamPtr;
-
-    if (endpoint > LAST_PHYSICAL_ENDPOINT) {
-        return false;
-    }
-
-    // Not applicable to the control endpoints
-    if ((endpoint==EP0IN) || (endpoint==EP0OUT)) {
-        return false;
-    }
-
-    // Allocate buffers in USB RAM
-    tmpEpRamPtr = epRamPtr;
-
-    // Must be 64 byte aligned
-    tmpEpRamPtr = ROUND_UP_TO_MULTIPLE(tmpEpRamPtr, 64);
-
-    if ((tmpEpRamPtr + maxPacket) > (USB_RAM_START + USB_RAM_SIZE)) {
-        // Out of memory
-        return false;
-    }
-
-    // Allocate first buffer
-    endpointState[endpoint].buffer[0] = tmpEpRamPtr;
-    tmpEpRamPtr += maxPacket;
-
-    if (!(options & SINGLE_BUFFERED)) {
-        // Must be 64 byte aligned
-        tmpEpRamPtr = ROUND_UP_TO_MULTIPLE(tmpEpRamPtr, 64);
-
-        if ((tmpEpRamPtr + maxPacket) > (USB_RAM_START + USB_RAM_SIZE)) {
-            // Out of memory
-            return false;
-        }
-
-        // Allocate second buffer
-        endpointState[endpoint].buffer[1] = tmpEpRamPtr;
-        tmpEpRamPtr += maxPacket;
-    }
-
-    // Commit to this USB RAM allocation
-    epRamPtr = tmpEpRamPtr;
-
-    // Remaining endpoint state values
-    endpointState[endpoint].maxPacket = maxPacket;
-    endpointState[endpoint].options = options;
-
-    // Enable double buffering if required
-    if (options & SINGLE_BUFFERED) {
-        LPC_USB->EPBUFCFG &= ~EP(endpoint);
-    } else {
-        // Double buffered
-        LPC_USB->EPBUFCFG |= EP(endpoint);
-    }
-
-    // Enable interrupt
-    LPC_USB->INTEN |= EP(endpoint);
-
-    // Enable endpoint
-    unstallEndpoint(endpoint);
-    return true;
-}
-
-void USBHAL::remoteWakeup(void) {
-    // Clearing DSUS bit initiates a remote wakeup if the
-    // device is currently enabled and suspended - otherwise
-    // it has no effect.
-    LPC_USB->DEVCMDSTAT = devCmdStat & ~DSUS;
-}
-
-
-static void disableEndpoints(void) {
-    uint32_t logEp;
-
-    // Ref. Table 158 "When a bus reset is received, software
-    // must set the disable bit of all endpoints to 1".
-
-    for (logEp = 1; logEp < NUMBER_OF_LOGICAL_ENDPOINTS; logEp++) {
-        ep[logEp].out[0] = CMDSTS_D;
-        ep[logEp].out[1] = CMDSTS_D;
-        ep[logEp].in[0] =  CMDSTS_D;
-        ep[logEp].in[1] =  CMDSTS_D;
-    }
-
-    // Start of USB RAM for endpoints > 0
-    epRamPtr = usbRamPtr;
-}
-
-
-
-void USBHAL::_usbisr(void) {
-    instance->usbisr();
-}
-
-void USBHAL::usbisr(void) {
-    // Start of frame
-    if (LPC_USB->INTSTAT & FRAME_INT) {
-        // Clear SOF interrupt
-        LPC_USB->INTSTAT = FRAME_INT;
-
-        // SOF event, read frame number
-        SOF(FRAME_NR(LPC_USB->INFO));
-    }
-
-    // Device state
-    if (LPC_USB->INTSTAT & DEV_INT) {
-        LPC_USB->INTSTAT = DEV_INT;
-
-        if (LPC_USB->DEVCMDSTAT & DSUS_C) {
-            // Suspend status changed
-            LPC_USB->DEVCMDSTAT = devCmdStat | DSUS_C;
-            if((LPC_USB->DEVCMDSTAT & DSUS) != 0) {
-                suspendStateChanged(1);
-            }
-        }
-
-        if (LPC_USB->DEVCMDSTAT & DRES_C) {
-            // Bus reset
-            LPC_USB->DEVCMDSTAT = devCmdStat | DRES_C;
-
-            suspendStateChanged(0);
-
-            // Disable endpoints > 0
-            disableEndpoints();
-
-            // Bus reset event
-            busReset();
-        }
-    }
-
-    // Endpoint 0
-    if (LPC_USB->INTSTAT & EP(EP0OUT)) {
-        // Clear EP0OUT/SETUP interrupt
-        LPC_USB->INTSTAT = EP(EP0OUT);
-
-        // Check if SETUP
-        if (LPC_USB->DEVCMDSTAT & SETUP) {
-            // Clear Active and Stall bits for EP0
-            // Documentation does not make it clear if we must use the
-            // EPSKIP register to achieve this, Fig. 16 and NXP reference
-            // code suggests we can just clear the Active bits - check with
-            // NXP to be sure.
-            ep[0].in[0] = 0;
-            ep[0].out[0] = 0;
-
-            // Clear EP0IN interrupt
-            LPC_USB->INTSTAT = EP(EP0IN);
-
-            // Clear SETUP (and INTONNAK_CI/O) in device status register
-            LPC_USB->DEVCMDSTAT = devCmdStat | SETUP;
-
-            // EP0 SETUP event (SETUP data received)
-            EP0setupCallback();
-        } else {
-            // EP0OUT ACK event (OUT data received)
-            EP0out();
-        }
-    }
-
-    if (LPC_USB->INTSTAT & EP(EP0IN)) {
-        // Clear EP0IN interrupt
-        LPC_USB->INTSTAT = EP(EP0IN);
-
-        // EP0IN ACK event (IN data sent)
-        EP0in();
-    }
-    
-    for (uint8_t num = 2; num < 5*2; num++) {
-        if (LPC_USB->INTSTAT & EP(num)) {
-            LPC_USB->INTSTAT = EP(num);
-            epComplete |= EP(num);
-            if ((instance->*(epCallback[num - 2]))()) {
-                epComplete &= ~EP(num);
-            }
-        }
-    }
-}
-
-#endif
--- a/USBDevice/USBHAL_LPC17.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBHAL_LPC17.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -279,7 +279,7 @@
         SIEselectEndpoint(endpoint);
         SIEclearBuffer();
     }
-    
+
     return size;
 }
 
@@ -327,7 +327,7 @@
 USBHAL::USBHAL(void) {
     // Disable IRQ
     NVIC_DisableIRQ(USB_IRQn);
-    
+
     // fill in callback array
     epCallback[0] = &USBHAL::EP1_OUT_callback;
     epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -466,7 +466,7 @@
         if (!(epComplete & EP(endpoint)))
             return EP_PENDING;
     }
-    
+
     *bytesRead = endpointReadcore(endpoint, buffer);
     epComplete &= ~EP(endpoint);
     return EP_COMPLETED;
@@ -606,7 +606,7 @@
             LPC_USB->USBDevIntClr = EP_SLOW;
             EP0in();
         }
-        
+
         for (uint8_t num = 2; num < 16*2; num++) {
             if (LPC_USB->USBEpIntSt & EP(num)) {
                 selectEndpointClearInterrupt(num);
--- a/USBDevice/USBHAL_LPC40.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBHAL_LPC40.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -280,7 +280,7 @@
         SIEselectEndpoint(endpoint);
         SIEclearBuffer();
     }
-    
+
     return size;
 }
 
@@ -328,7 +328,7 @@
 USBHAL::USBHAL(void) {
     // Disable IRQ
     NVIC_DisableIRQ(USB_IRQn);
-    
+
     // fill in callback array
     epCallback[0] = &USBHAL::EP1_OUT_callback;
     epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -367,7 +367,7 @@
     // Enable USB clocks
     LPC_USB->USBClkCtrl |= DEV_CLK_EN | AHB_CLK_EN | PORT_CLK_EN;
     while ((LPC_USB->USBClkSt & (DEV_CLK_EN | AHB_CLK_EN | PORT_CLK_EN)) != (DEV_CLK_ON | AHB_CLK_ON | PORT_CLK_EN));
-    
+
     // Select port USB2
     LPC_USB->StCtrl |= 3;
 
@@ -375,13 +375,13 @@
     // Configure pin P0.31 to be USB2
     LPC_IOCON->P0_31 &= ~0x07;
     LPC_IOCON->P0_31 |= 0x01;
-    
+
     // Disconnect USB device
     SIEdisconnect();
 
     // Configure pin P0.14 to be Connect
     LPC_IOCON->P0_14 &= ~0x07;
-    LPC_IOCON->P0_14 |= 0x03;    
+    LPC_IOCON->P0_14 |= 0x03;
 
     // Connect must be low for at least 2.5uS
     wait(0.3);
@@ -471,7 +471,7 @@
         if (!(epComplete & EP(endpoint)))
             return EP_PENDING;
     }
-    
+
     *bytesRead = endpointReadcore(endpoint, buffer);
     epComplete &= ~EP(endpoint);
     return EP_COMPLETED;
@@ -611,7 +611,7 @@
             LPC_USB->DevIntClr = EP_SLOW;
             EP0in();
         }
-        
+
         for (uint8_t num = 2; num < 16*2; num++) {
             if (LPC_USB->EpIntSt & EP(num)) {
                 selectEndpointClearInterrupt(num);
--- a/USBDevice/USBHAL_STM32F4.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBHAL_STM32F4.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -36,7 +36,7 @@
     return 0;
 }
 
-USBHAL::USBHAL(void) {    
+USBHAL::USBHAL(void) {
     NVIC_DisableIRQ(OTG_FS_IRQn);
     epCallback[0] = &USBHAL::EP1_OUT_callback;
     epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -63,7 +63,7 @@
     pin_mode(PA_9, OpenDrain);
 
     RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
-    
+
     // Enable interrupts
     OTG_FS->GREGS.GAHBCFG |= (1 << 0);
 
@@ -116,21 +116,21 @@
 
     uint32_t type;
     switch (endpoint) {
-        case EP0IN:  
+        case EP0IN:
         case EP0OUT:
             type = 0;
-            break;   
+            break;
         case EPISO_IN:
         case EPISO_OUT:
-            type = 1; 
+            type = 1;
         case EPBULK_IN:
         case EPBULK_OUT:
-            type = 2;  
-            break;   
+            type = 2;
+            break;
         case EPINT_IN:
         case EPINT_OUT:
-            type = 3; 
-            break;   
+            type = 3;
+            break;
     }
 
     // Generic in or out EP controls
@@ -154,7 +154,7 @@
         if (endpoint != EP0IN) {
             control |= (1 << 28); // SD0PID
         }
-        
+
         control |= (epIndex << 22) | // TxFIFO index
                    (1 << 27); // SNAK
         OTG_FS->INEP_REGS[epIndex].DIEPCTL = control;
@@ -166,7 +166,7 @@
         // Set the out EP specific control settings
         control |= (1 << 26); // CNAK
         OTG_FS->OUTEP_REGS[epIndex].DOEPCTL = control;
-        
+
         // Unmask the interrupt
         OTG_FS->DREGS.DAINTMSK |= (1 << (epIndex + 16));
     }
@@ -190,7 +190,7 @@
     for (uint32_t i = 0; i < length; i += 4) {
         buffer32[i >> 2] = OTG_FS->FIFO[0][0];
     }
-                        
+
     rxFifoCount = 0;
     return length;
 }
@@ -266,7 +266,7 @@
         return EP_COMPLETED;
     }
 
-    return EP_PENDING; 
+    return EP_PENDING;
 }
 
 void USBHAL::stallEndpoint(uint8_t endpoint) {
@@ -282,7 +282,7 @@
 }
 
 void USBHAL::unstallEndpoint(uint8_t endpoint) {
-    
+
 }
 
 bool USBHAL::getEndpointStallState(uint8_t endpoint) {
--- a/USBDevice/USBRegs_STM32.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBDevice/USBRegs_STM32.h	Sat Jun 21 07:25:16 2014 +0900
@@ -16,8 +16,8 @@
   *
   *        http://www.st.com/software_license_agreement_liberty_v2
   *
-  * Unless required by applicable law or agreed to in writing, software 
-  * distributed under the License is distributed on an "AS IS" BASIS, 
+  * Unless required by applicable law or agreed to in writing, software
+  * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
@@ -70,7 +70,7 @@
 }
 USB_OTG_DREGS;
 
-typedef struct 
+typedef struct
 {
   __IO uint32_t DIEPCTL; /* dev IN Endpoint Control Reg 900h + (ep_num * 20h) + 00h*/
   uint32_t Reserved04;             /* Reserved                       900h + (ep_num * 20h) + 04h*/
@@ -83,7 +83,7 @@
 }
 USB_OTG_INEPREGS;
 
-typedef struct 
+typedef struct
 {
   __IO uint32_t DOEPCTL;       /* dev OUT Endpoint Control Reg  B00h + (ep_num * 20h) + 00h*/
   uint32_t Reserved04;         /* Reserved                      B00h + (ep_num * 20h) + 04h*/
@@ -117,7 +117,7 @@
 }
 USB_OTG_HC_REGS;
 
-typedef struct 
+typedef struct
 {
     USB_OTG_GREGS         GREGS;
     uint32_t RESERVED0[188];
--- a/USBHID/USBHID.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBHID.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -121,7 +121,7 @@
                                 success = true;
                             }
                             break;
-                     
+
                     default:
                         break;
                 }
--- a/USBHID/USBHID.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBHID.h	Sat Jun 21 07:25:16 2014 +0900
@@ -70,8 +70,8 @@
     * @returns true if successful
     */
     bool send(HID_REPORT *report);
-    
-    
+
+
     /**
     * Send a Report. warning: non blocking
     *
@@ -79,7 +79,7 @@
     * @returns true if successful
     */
     bool sendNB(HID_REPORT *report);
-    
+
     /**
     * Read a report: blocking
     *
@@ -87,7 +87,7 @@
     * @returns true if successful
     */
     bool read(HID_REPORT * report);
-    
+
     /**
     * Read a report: non blocking
     *
@@ -98,7 +98,7 @@
 
 protected:
     uint16_t reportLength;
-    
+
     /*
     * Get the Report descriptor
     *
@@ -119,14 +119,14 @@
     * @returns pointer to the string product descriptor
     */
     virtual uint8_t * stringIproductDesc();
-    
+
     /*
     * Get string interface descriptor
     *
     * @returns pointer to the string interface descriptor
     */
     virtual uint8_t * stringIinterfaceDesc();
-    
+
     /*
     * Get configuration descriptor
     *
--- a/USBHID/USBKeyboard.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBKeyboard.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -183,7 +183,7 @@
     {0x4a, 0},          /* HOME */
     {0x4b, 0},          /* PAGE_UP */
     {0x4e, 0},          /* PAGE_DOWN */
-    
+
     {0x4f, 0},          /* RIGHT_ARROW */
     {0x50, 0},          /* LEFT_ARROW */
     {0x51, 0},          /* DOWN_ARROW */
@@ -344,7 +344,7 @@
     {0x4a, 0},          /* HOME */
     {0x4b, 0},          /* PAGE_UP */
     {0x4e, 0},          /* PAGE_DOWN */
-    
+
     {0x4f, 0},          /* RIGHT_ARROW */
     {0x50, 0},          /* LEFT_ARROW */
     {0x51, 0},          /* DOWN_ARROW */
@@ -424,10 +424,10 @@
     uint32_t bytesRead = 0;
     uint8_t led[65];
     USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
-    
+
     // we take led[1] because led[0] is the report ID
     lock_status = led[1] & 0x07;
-    
+
     // We activate the endpoint to be able to recceive data
     if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
         return false;
--- a/USBHID/USBKeyboard.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBKeyboard.h	Sat Jun 21 07:25:16 2014 +0900
@@ -53,7 +53,7 @@
     KEY_F10,        /* F10 key */
     KEY_F11,        /* F11 key */
     KEY_F12,        /* F12 key */
-    
+
     KEY_PRINT_SCREEN,   /* Print Screen key */
     KEY_SCROLL_LOCK,    /* Scroll lock */
     KEY_CAPS_LOCK,      /* caps lock */
@@ -62,7 +62,7 @@
     KEY_HOME,           /* Home key */
     KEY_PAGE_UP,        /* Page Up key */
     KEY_PAGE_DOWN,      /* Page Down key */
-    
+
     RIGHT_ARROW,        /* Right arrow */
     LEFT_ARROW,         /* Left arrow */
     DOWN_ARROW,         /* Down arrow */
--- a/USBHID/USBMouse.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBMouse.h	Sat Jun 21 07:25:16 2014 +0900
@@ -35,7 +35,7 @@
 /* X and Y limits */
 /* These values do not directly map to screen pixels */
 /* Zero may be interpreted as meaning 'no movement' */
-#define X_MIN_ABS    (1)        /*!< Minimum value on x-axis */  
+#define X_MIN_ABS    (1)        /*!< Minimum value on x-axis */
 #define Y_MIN_ABS    (1)        /*!< Minimum value on y-axis */
 #define X_MAX_ABS    (0x7fff)   /*!< Maximum value on x-axis */
 #define Y_MAX_ABS    (0x7fff)   /*!< Maximum value on y-axis */
@@ -85,7 +85,7 @@
  *   uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
  *   uint16_t x_screen = 0;
  *   uint16_t y_screen = 0;
- *   
+ *
  *   uint32_t x_origin = x_center;
  *   uint32_t y_origin = y_center;
  *   uint32_t radius = 5000;
@@ -95,7 +95,7 @@
  *   {
  *       x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
  *       y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
- *       
+ *
  *       mouse.move(x_screen, y_screen);
  *       angle += 3;
  *       wait(0.01);
@@ -107,7 +107,7 @@
 class USBMouse: public USBHID
 {
     public:
-        
+
         /**
         *   Constructor
         *
@@ -117,14 +117,14 @@
         * @param product_release Your preoduct_release (default: 0x0001)
         *
         */
-        USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001): 
+        USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001):
             USBHID(0, 0, vendor_id, product_id, product_release, false)
-            { 
+            {
                 button = 0;
                 this->mouse_type = mouse_type;
                 connect();
             };
-        
+
         /**
         * Write a state of the mouse
         *
@@ -135,8 +135,8 @@
         * @returns true if there is no error, false otherwise
         */
         bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
-        
-        
+
+
         /**
         * Move the cursor to (x, y)
         *
@@ -145,7 +145,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool move(int16_t x, int16_t y);
-        
+
         /**
         * Press one or several buttons
         *
@@ -153,7 +153,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool press(uint8_t button);
-        
+
         /**
         * Release one or several buttons
         *
@@ -161,22 +161,22 @@
         * @returns true if there is no error, false otherwise
         */
         bool release(uint8_t button);
-        
+
         /**
         * Double click (MOUSE_LEFT)
         *
         * @returns true if there is no error, false otherwise
         */
         bool doubleClick();
-        
+
         /**
         * Click
         *
         * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
         * @returns true if there is no error, false otherwise
         */
-        bool click(uint8_t button); 
-        
+        bool click(uint8_t button);
+
         /**
         * Scrolling
         *
@@ -184,7 +184,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool scroll(int8_t z);
-        
+
         /*
         * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
         *
@@ -199,7 +199,7 @@
         * @returns pointer to the configuration descriptor
         */
         virtual uint8_t * configurationDesc();
-        
+
     private:
         MOUSE_TYPE mouse_type;
         uint8_t button;
--- a/USBHID/USBMouseKeyboard.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBMouseKeyboard.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -178,7 +178,7 @@
     {0x4a, 0},          /* HOME */
     {0x4b, 0},          /* PAGE_UP */
     {0x4e, 0},          /* PAGE_DOWN */
-    
+
     {0x4f, 0},          /* RIGHT_ARROW */
     {0x50, 0},          /* LEFT_ARROW */
     {0x51, 0},          /* DOWN_ARROW */
@@ -339,7 +339,7 @@
     {0x4a, 0},          /* HOME */
     {0x4b, 0},          /* PAGE_UP */
     {0x4e, 0},          /* PAGE_DOWN */
-    
+
     {0x4f, 0},          /* RIGHT_ARROW */
     {0x50, 0},          /* LEFT_ARROW */
     {0x51, 0},          /* DOWN_ARROW */
@@ -552,10 +552,10 @@
     uint32_t bytesRead = 0;
     uint8_t led[65];
     USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
-    
+
     // we take led[1] because led[0] is the report ID
     lock_status = led[1] & 0x07;
-    
+
     // We activate the endpoint to be able to recceive data
     if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
         return false;
@@ -696,7 +696,7 @@
     report.length = 2;
 
     send(&report);
-    
+
     report.data[0] = REPORT_ID_VOLUME;
     report.data[1] = 0;
 
--- a/USBHID/USBMouseKeyboard.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBHID/USBMouseKeyboard.h	Sat Jun 21 07:25:16 2014 +0900
@@ -28,7 +28,7 @@
 #include "Stream.h"
 #include "USBHID.h"
 
-/** 
+/**
  * USBMouseKeyboard example
  * @code
  *
@@ -70,7 +70,7 @@
 class USBMouseKeyboard: public USBHID, public Stream
 {
     public:
-    
+
         /**
         *   Constructor
         *
@@ -81,7 +81,7 @@
         * @param product_release Your preoduct_release (default: 0x0001)
         *
         */
-        USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001): 
+        USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001):
             USBHID(0, 0, vendor_id, product_id, product_release, false)
             {
                 lock_status = 0;
@@ -89,7 +89,7 @@
                 this->mouse_type = mouse_type;
                 connect();
             };
-            
+
         /**
         * Write a state of the mouse
         *
@@ -100,8 +100,8 @@
         * @returns true if there is no error, false otherwise
         */
         bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
-        
-        
+
+
         /**
         * Move the cursor to (x, y)
         *
@@ -110,7 +110,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool move(int16_t x, int16_t y);
-        
+
         /**
         * Press one or several buttons
         *
@@ -118,7 +118,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool press(uint8_t button);
-        
+
         /**
         * Release one or several buttons
         *
@@ -126,22 +126,22 @@
         * @returns true if there is no error, false otherwise
         */
         bool release(uint8_t button);
-        
+
         /**
         * Double click (MOUSE_LEFT)
         *
         * @returns true if there is no error, false otherwise
         */
         bool doubleClick();
-        
+
         /**
         * Click
         *
         * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
         * @returns true if there is no error, false otherwise
         */
-        bool click(uint8_t button); 
-        
+        bool click(uint8_t button);
+
         /**
         * Scrolling
         *
@@ -151,7 +151,7 @@
         bool scroll(int8_t z);
 
         /**
-        * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key 
+        * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
         *
         * @code
         * //To send CTRL + s (save)
@@ -163,7 +163,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool keyCode(uint8_t key, uint8_t modifier = 0);
-        
+
         /**
         * Send a character
         *
@@ -171,7 +171,7 @@
         * @returns true if there is no error, false otherwise
         */
         virtual int _putc(int c);
-        
+
         /**
         * Control media keys
         *
@@ -179,7 +179,7 @@
         * @returns true if there is no error, false otherwise
         */
         bool mediaControl(MEDIA_KEY key);
-        
+
         /**
         * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:
         *   - First bit: NUM_LOCK
@@ -189,30 +189,30 @@
         * @returns status of lock keys
         */
         uint8_t lockStatus();
-        
+
         /*
         * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
         *
         * @returns pointer to the report descriptor
         */
         virtual uint8_t * reportDesc();
-        
+
         /*
         * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
         *
         * @returns if handle by subclass, return true
         */
         virtual bool EP1_OUT_callback();
-        
-        
+
+
     private:
         bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z);
         MOUSE_TYPE mouse_type;
         uint8_t button;
         bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
-        
+
         uint8_t lock_status;
-        
+
         //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
         virtual int _getc() { return -1;}
 };
--- a/USBMIDI/MIDIMessage.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBMIDI/MIDIMessage.h	Sat Jun 21 07:25:16 2014 +0900
@@ -22,7 +22,7 @@
 #include "mbed.h"
 
 // MIDI Message Format
-// 
+//
 // [ msg(4) | channel(4) ] [ 0 | n(7) ] [ 0 | m(7) ]
 //
 // MIDI Data Messages (Channel Specific)
@@ -43,15 +43,15 @@
 class MIDIMessage {
 public:
     MIDIMessage() {}
-    
+
     MIDIMessage(uint8_t *buf) {
         for (int i = 0; i < 4; i++)
             data[i] = buf[i];
     }
-    
+
     // create messages
-    
-    /** Create a NoteOff message 
+
+    /** Create a NoteOff message
      * @param key Key ID
      * @param velocity Key velocity (0-127, default = 127)
      * @param channel Key channel (0-15, default 0)
@@ -62,11 +62,11 @@
         msg.data[0] = CABLE_NUM | 0x08;
         msg.data[1] = 0x80 | (channel & 0x0F);
         msg.data[2] = key & 0x7F;
-        msg.data[3] = velocity & 0x7F; 
+        msg.data[3] = velocity & 0x7F;
         return msg;
     }
-    
-    /** Create a NoteOn message 
+
+    /** Create a NoteOn message
      * @param key Key ID
      * @param velocity Key velocity (0-127, default = 127)
      * @param channel Key channel (0-15, default 0)
@@ -77,26 +77,26 @@
         msg.data[0] = CABLE_NUM | 0x09;
         msg.data[1] = 0x90 | (channel & 0x0F);
         msg.data[2] = key & 0x7F;
-        msg.data[3] = velocity & 0x7F;                 
+        msg.data[3] = velocity & 0x7F;
         return msg;
     }
-    
-    /** Create a PolyPhonic Aftertouch message 
+
+    /** Create a PolyPhonic Aftertouch message
      * @param key Key ID
      * @param pressure Aftertouch pressure (0-127)
      * @param channel Key channel (0-15, default 0)
      * @returns A MIDIMessage
-     */    
+     */
     static MIDIMessage PolyphonicAftertouch(int key, int pressure, int channel = 0) {
         MIDIMessage msg;
         msg.data[0] = CABLE_NUM | 0x0A;
         msg.data[1] = 0xA0 | (channel & 0x0F);
         msg.data[2] = key & 0x7F;
-        msg.data[3] = pressure & 0x7F;         
+        msg.data[3] = pressure & 0x7F;
         return msg;
     }
-    
-    /** Create a Control Change message 
+
+    /** Create a Control Change message
      * @param control Controller ID
      * @param value Controller value (0-127)
      * @param channel Controller channel (0-15, default 0)
@@ -107,63 +107,63 @@
         msg.data[0] = CABLE_NUM | 0x0B;
         msg.data[1] = 0xB0 | (channel & 0x0F);
         msg.data[2] = control & 0x7F;
-        msg.data[3] = value & 0x7F;         
+        msg.data[3] = value & 0x7F;
         return msg;
     }
-    
-    /** Create a Program Change message 
+
+    /** Create a Program Change message
      * @param program Program ID
      * @param channel Channel (0-15, default 0)
      * @returns A MIDIMessage
-     */    
+     */
     static MIDIMessage ProgramChange(int program, int channel = 0) {
         MIDIMessage msg;
         msg.data[0] = CABLE_NUM | 0x0C;
         msg.data[1] = 0xC0 | (channel & 0x0F);
         msg.data[2] = program & 0x7F;
-        msg.data[3] = 0x00;         
+        msg.data[3] = 0x00;
         return msg;
     }
-    
-    /** Create a Channel Aftertouch message 
-     * @param pressure Pressure 
+
+    /** Create a Channel Aftertouch message
+     * @param pressure Pressure
      * @param channel Key channel (0-15, default 0)
      * @returns A MIDIMessage
-     */    
+     */
     static MIDIMessage ChannelAftertouch(int pressure, int channel = 0) {
         MIDIMessage msg;
         msg.data[0] = CABLE_NUM | 0x0D;
         msg.data[1] = 0xD0 | (channel & 0x0F);
         msg.data[2] = pressure & 0x7F;
-        msg.data[3] = 0x00;         
+        msg.data[3] = 0x00;
         return msg;
     }
-    
-    /** Create a Pitch Wheel message 
+
+    /** Create a Pitch Wheel message
      * @param pitch Pitch (-8192 - 8191, default = 0)
      * @param channel Channel (0-15, default 0)
      * @returns A MIDIMessage
-     */    
+     */
     static MIDIMessage PitchWheel(int pitch = 0, int channel = 0) {
         MIDIMessage msg;
         int p = pitch + 8192;    // 0 - 16383, 8192 is center
         msg.data[0] = CABLE_NUM | 0x0E;
         msg.data[1] = 0xE0 | (channel & 0x0F);
         msg.data[2] = p & 0x7F;
-        msg.data[3] = (p >> 7) & 0x7F;                 
+        msg.data[3] = (p >> 7) & 0x7F;
         return msg;
     }
-    
-    /** Create an All Notes Off message 
+
+    /** Create an All Notes Off message
      * @param channel Channel (0-15, default 0)
      * @returns A MIDIMessage
-     */    
+     */
     static MIDIMessage AllNotesOff(int channel = 0) {
         return ControlChange(123, 0, channel);
     }
-    
+
     // decode messages
-    
+
     /** MIDI Message Types */
     enum MIDIMessageType {
         ErrorType,
@@ -176,16 +176,16 @@
         PitchWheelType,
         AllNotesOffType
     };
-    
+
     /** Read the message type
      * @returns MIDIMessageType
-     */    
+     */
     MIDIMessageType type() {
         switch((data[1] >> 4) & 0xF) {
             case 0x8: return NoteOffType;
             case 0x9: return NoteOnType;
             case 0xA: return PolyphonicAftertouchType;
-            case 0xB: 
+            case 0xB:
                 if(controller() < 120) { // standard controllers
                     return ControlChangeType;
                 } else if(controller() == 123) {
@@ -200,51 +200,51 @@
         }
     }
 
-    /** Read the channel number */    
+    /** Read the channel number */
     int channel() {
         return (data[1] & 0x0F);
     }
-    
-    /** Read the key ID */    
+
+    /** Read the key ID */
     int key() {
-        return (data[2] & 0x7F);        
+        return (data[2] & 0x7F);
     }
-        
-    /** Read the velocity */    
+
+    /** Read the velocity */
     int velocity() {
-        return (data[3] & 0x7F);        
+        return (data[3] & 0x7F);
     }
 
-    /** Read the controller value */    
+    /** Read the controller value */
     int value() {
-        return (data[3] & 0x7F);        
+        return (data[3] & 0x7F);
     }
-    
-    /** Read the aftertouch pressure */        
+
+    /** Read the aftertouch pressure */
     int pressure() {
         if(type() == PolyphonicAftertouchType) {
-            return (data[3] & 0x7F);        
+            return (data[3] & 0x7F);
         } else {
-            return (data[2] & 0x7F);        
+            return (data[2] & 0x7F);
         }
     }
 
-    /** Read the controller number */    
+    /** Read the controller number */
     int controller() {
-        return (data[2] & 0x7F);        
+        return (data[2] & 0x7F);
     }
 
-    /** Read the program number */    
+    /** Read the program number */
     int program() {
-        return (data[2] & 0x7F);        
+        return (data[2] & 0x7F);
     }
-    
-    /** Read the pitch value */        
+
+    /** Read the pitch value */
     int pitch() {
         int p = ((data[3] & 0x7F) << 7) | (data[2] & 0x7F);
         return p - 8192; // 0 - 16383, 8192 is center
     }
-    
+
     uint8_t data[4];
 };
 
--- a/USBMIDI/USBMIDI.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBMIDI/USBMIDI.h	Sat Jun 21 07:25:16 2014 +0900
@@ -29,7 +29,7 @@
 
 #define DEFAULT_CONFIGURATION (1)
 
-/** 
+/**
 * USBMIDI example
 *
 * @code
@@ -38,8 +38,8 @@
 *
 * USBMIDI midi;
 *
-* int main() {            
-*    while (1) {    
+* int main() {
+*    while (1) {
 *        for(int i=48; i<83; i++) {     // send some messages!
 *            midi.write(MIDIMessage::NoteOn(i));
 *            wait(0.25);
@@ -61,12 +61,12 @@
     * @param product_release Your preoduct_release
     */
     USBMIDI(uint16_t vendor_id = 0x0700, uint16_t product_id = 0x0101, uint16_t product_release = 0x0001);
-    
+
     /**
      * Send a MIDIMessage
      *
      * @param m The MIDIMessage to send
-     */    
+     */
     void write(MIDIMessage m);
 
     /**
@@ -75,8 +75,8 @@
      * @param fptr function pointer
      */
     void attach(void (*fptr)(MIDIMessage));
-    
-    
+
+
 protected:
     virtual bool EP2_OUT_callback();
     virtual bool USBCallback_setConfiguration(uint8_t configuration);
@@ -86,14 +86,14 @@
     * @returns pointer to the string product descriptor
     */
     virtual uint8_t * stringIproductDesc();
-    
+
     /*
     * Get string interface descriptor
     *
     * @returns pointer to the string interface descriptor
     */
     virtual uint8_t * stringIinterfaceDesc();
-    
+
     /*
     * Get configuration descriptor
     *
--- a/USBMSD/USBMSD.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBMSD/USBMSD.h	Sat Jun 21 07:25:16 2014 +0900
@@ -79,7 +79,7 @@
     * Disconnect the USB MSD device.
     */
     void disconnect();
-    
+
     /**
     * Destructor
     */
--- a/USBSerial/USBCDC.cpp	Tue May 13 15:31:04 2014 +0900
+++ b/USBSerial/USBCDC.cpp	Sat Jun 21 07:25:16 2014 +0900
@@ -80,15 +80,15 @@
     if (length != 7) {
         return;
     }
-    
+
     CONTROL_TRANSFER * transfer = getTransferPtr();
- 
+
     /* Process class-specific requests */
     if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
         if (transfer->setup.bRequest == CDC_SET_LINE_CODING) {
             if (memcmp(cdc_line_coding, buf, 7)) {
-                memcpy(cdc_line_coding, buf, 7); 
- 
+                memcpy(cdc_line_coding, buf, 7);
+
                 int baud = buf[0] + (buf[1] << 8)
                          + (buf[2] << 16) + (buf[3] << 24);
                 int stop = buf[4];
@@ -193,7 +193,7 @@
         0,                      // iConfiguration
         0x80,                   // bmAttributes
         50,                     // bMaxPower
-        
+
         // IAD to associate the two CDC interfaces
         0x08,                   // bLength
         0x0b,                   // bDescriptorType
--- a/USBSerial/USBCDC.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBSerial/USBCDC.h	Sat Jun 21 07:25:16 2014 +0900
@@ -40,35 +40,35 @@
     USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
 
 protected:
-    
+
     /*
     * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
     *
     * @returns pointer to the device descriptor
     */
     virtual uint8_t * deviceDesc();
-    
+
     /*
     * Get string product descriptor
     *
     * @returns pointer to the string product descriptor
     */
     virtual uint8_t * stringIproductDesc();
-    
+
     /*
     * Get string interface descriptor
     *
     * @returns pointer to the string interface descriptor
     */
     virtual uint8_t * stringIinterfaceDesc();
-    
+
     /*
     * Get configuration descriptor
     *
     * @returns pointer to the configuration descriptor
     */
     virtual uint8_t * configurationDesc();
-    
+
     /*
     * Send a buffer
     *
@@ -78,7 +78,7 @@
     * @returns true if successful
     */
     bool send(uint8_t * buffer, uint32_t size);
-    
+
     /*
     * Read a buffer from a certain endpoint. Warning: blocking
     *
@@ -89,7 +89,7 @@
     * @returns true if successful
     */
     bool readEP(uint8_t * buffer, uint32_t * size);
-    
+
     /*
     * Read a buffer from a certain endpoint. Warning: non blocking
     *
--- a/USBSerial/USBSerial.h	Tue May 13 15:31:04 2014 +0900
+++ b/USBSerial/USBSerial.h	Sat Jun 21 07:25:16 2014 +0900
@@ -68,20 +68,20 @@
     * @returns true if there is no error, false otherwise
     */
     virtual int _putc(int c);
-    
+
     /**
     * Read a character: blocking
     *
     * @returns character read
     */
     virtual int _getc();
-    
+
     /**
     * Check the number of bytes available.
     *
     * @returns the number of bytes available
     */
-    uint8_t available(); 
+    uint8_t available();
 
     /** Determine if there is a character available to read
      *
@@ -90,7 +90,7 @@
      *    0 otherwise
      */
     int readable() { return available() ? 1 : 0; }
-    
+
     /** Determine if there is space available to write a character
      *
      *  @returns
@@ -98,9 +98,9 @@
      *    0 otherwise
      */
     int writeable() { return 1; } // always return 1, for write operation is blocking
-    
+
     /**
-    * Write a block of data. 
+    * Write a block of data.
     *
     * For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written.
     *
@@ -112,7 +112,7 @@
     bool writeBlock(uint8_t * buf, uint16_t size);
 
     /**
-     *  Attach a member function to call when a packet is received. 
+     *  Attach a member function to call when a packet is received.
      *
      *  @param tptr pointer to the object to call the member function on
      *  @param mptr pointer to the member function to be called