common: Don't attempt to stop the USB clock in USB_VcomDeinit().
[gps-watch.git] / src / common / virtual_com.c
index 933b8fd08a95b78872d1f8ab1d4bb2bf09e8041b..aa25cd78590424c7d567414888c855fd3aa9d2c4 100644 (file)
@@ -105,7 +105,6 @@ static uint8_t s_currRecvBuf[DATA_BUFF_SIZE];
 volatile static uint32_t s_recvSize = 0;
 volatile static uint32_t s_sendSize = 0;
 volatile static uint8_t s_sendComplete = 0;
-volatile static uint8_t s_currRecvIndex = 0;
 static uint32_t s_usbBulkMaxPacketSize = FS_CDC_VCOM_BULK_OUT_PACKET_SIZE;
 /*******************************************************************************
 * Prototypes
@@ -601,19 +600,6 @@ usb_status_t USB_DeviceConfigureEndpointStatus(usb_device_handle handle, uint8_t
     }
 }
 
-/* See virtual_com.h for documentation of this function. */
-void USB_VcomWriteBlocking(usb_device_handle baseAddr, const uint8_t *buf, size_t count)
-{
-    while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
-    {
-    };
-    USB_DeviceSendRequest((usb_device_handle)baseAddr, USB_CDC_VCOM_BULK_IN_ENDPOINT, (uint8_t *)buf, count);
-    while (!s_sendComplete)
-    {
-    };
-    s_sendComplete = 0;
-}
-
 static ssize_t
 flush_tx_buffer (void *user_data, void *vbuf, size_t bufsiz, size_t count)
 {
@@ -638,58 +624,8 @@ flush_tx_buffer (void *user_data, void *vbuf, size_t bufsiz, size_t count)
 }
 
 /* See virtual_com.h for documentation of this function. */
-status_t USB_VcomReadBlocking(usb_device_handle baseAddr, uint8_t *buf, size_t count)
-{
-    status_t error = kStatus_Success;
-    size_t bufIndex = 0U, bytesToReceive = 0U;
-    assert(count != 0U);
-
-    /* Waiting for the USB ready. */
-    while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
-    {
-    };
-
-    do
-    {
-        /* If no receive request. */
-        if (s_recvSize <= 0)
-        {
-            if (kStatus_USB_Success !=
-                USB_DeviceRecvRequest(baseAddr, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf, s_usbBulkMaxPacketSize))
-            {
-                return kStatus_Fail;
-            }
-            s_currRecvIndex = 0;
-        }
-        /* Waiting for data received by virtual com. */
-        while (s_recvSize <= 0)
-        {
-        };
-
-        /* When receive request is error. */
-        if (0xFFFFFFFFU == s_recvSize)
-        {
-            /* Waiting for the USB ready and transfer started. */
-            while ((s_cdcVcom.attach != 1) || (s_cdcVcom.startTransactions != 1))
-            {
-            };
-            s_recvSize = 0;
-        }
-        else
-        {
-            bytesToReceive = MIN(count, s_recvSize);
-            memcpy((void *)&buf[bufIndex], s_currRecvBuf + s_currRecvIndex, bytesToReceive);
-            count -= bytesToReceive;
-            s_recvSize -= bytesToReceive;
-            bufIndex += bytesToReceive;
-            s_currRecvIndex += bytesToReceive;
-        }
-    } while (0U != count);
-    return error;
-}
-
-/* See virtual_com.h for documentation of this function. */
-usb_device_handle USB_VcomInit(void)
+usb_device_handle
+USB_VcomInit (uint16_t vid, uint16_t pid)
 {
     usb_device_handle deviceHandle = NULL;
 
@@ -703,6 +639,9 @@ usb_device_handle USB_VcomInit(void)
     s_cdcVcom.attach = 0;
     s_cdcVcom.deviceHandle = NULL;
 
+       USB_DeviceSetVendorId(vid);
+       USB_DeviceSetProductId(pid);
+
     if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &s_cdcVcom.deviceHandle))
     {
         deviceHandle = NULL;
@@ -726,20 +665,8 @@ void USB_VcomDeinit(usb_device_handle deviceHandle)
     USB_DeviceStop(deviceHandle);
     USB_DeviceDeinit(deviceHandle);
     s_cdcVcom.deviceHandle = NULL;
-#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
-    USB_EhciPhyDeinit(CONTROLLER_ID);
-#endif
-#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
-    CLOCK_DisableUsbfs0Clock();
-#endif
-#if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
-    /* enable USB IP clock, user code. */
-    CLOCK_DisableClock(kCLOCK_Usbd0);
-#endif /* USB_DEVICE_CONFIG_LPCIP3511FS */
-
-#if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
-/* enable USB IP clock,user code. */
-#endif /* USB_DEVICE_CONFIG_LPCIP3511HS */
+
+       /* XXX: We are not stopping the USBOTG clock yet. */
 }
 
 void