71 #if (FM_PERIPHERAL_USB_DEVICE_ENABLED == ON)
81 #if (USE_USBDEVICEHW_H == 1)
82 #include "usbdevicehw.h"
91 static void ConfigChangeCallback(stc_usbn_t* pstcUsb);
92 static void SetupRxCallback(stc_usbn_t* pstcUsb);
99 #define USBDEVICE_INSTANCE_COUNT (uint32_t)(sizeof(m_astcUsbDeviceInstanceDataLut) / sizeof(m_astcUsbDeviceInstanceDataLut[0]))
108 #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (defined(USB0)) && (FM_PERIPHERAL_ENABLE_USB0_DEVICE == ON))
113 #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (defined(USB1)) && (FM_PERIPHERAL_ENABLE_USB1_DEVICE == ON))
131 volatile uint32_t u32Instance;
133 for (u32Instance = 0; u32Instance < USBDEVICE_INSTANCE_COUNT; u32Instance++)
135 if ((uint32_t)pstcUsb == (uint32_t)(m_astcUsbDeviceInstanceDataLut[u32Instance].pstcInstance))
137 return &m_astcUsbDeviceInstanceDataLut[u32Instance].
stcInternData;
158 uint16_t u16DataSend = 0;
159 uint32_t u32TransferredData;
213 uint16_t u16DataReceived = 0;
254 uint16_t u16DataReceived = 0;
255 volatile uint32_t u32Timeout;
264 u32Timeout = 1000000;
278 if (u16DataReceived < pstcEndpoint->u16EndpointSize)
289 #if USB_USES_DMA == ON
317 uint16_t u16DataSend = 0;
318 volatile uint32_t u32Timeout;
323 USBDBG(
"\nERROR: Buffer == NULL!");
335 u32Timeout = 1000000;
365 Usb_HalSend(pstcEndpoint,pu8Buffer,u32DataSize,&u16DataSend);
370 #if USB_USES_DMA == ON
373 Usb_HalSendDma(pstcEndpoint,pu8Buffer,u32DataSize,&u16DataSend);
405 static uint8_t pu8Buffer[64];
406 uint16_t u16BytesCount;
408 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
418 if (u16BytesCount == 0)
457 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
474 static void ConfigChangeCallback(stc_usbn_t* pstcUsb)
478 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
506 static void SetupRxCallback(stc_usbn_t* pstcUsb)
508 static uint8_t u8DataToSend[255];
509 uint16_t u16BytesCount;
511 static uint8_t pu8Buffer[8];
517 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
519 pstcUsb->EP0OS_f.DRQOIE = 0;
530 stcSetup.
wValue = pu8Buffer[3] << 8;
531 stcSetup.
wValue += pu8Buffer[2];
532 stcSetup.
wIndex = pu8Buffer[5] << 8;
533 stcSetup.
wIndex += pu8Buffer[4];
534 stcSetup.
wLength = pu8Buffer[7] << 8;
535 stcSetup.
wLength += pu8Buffer[6];
560 pstcUsb->EP0OS_f.DRQOIE = 1;
571 switch((stcSetup.
wValue) >> 8)
584 USBDBG(
"Req Conf Desc\n");
594 switch ((stcSetup.
wValue) & 0xFF)
597 u8DataToSend[0] = 0x04;
598 u8DataToSend[1] = 0x03;
599 u8DataToSend[2] = 0x09;
600 u8DataToSend[3] = 0x04;
608 u8DataToSend[1] = 0x03;
612 u8DataToSend[3 + u8Size * 2] = 0;
614 u8DataToSend[0] = u8DataToSend[0] + 2 * u8Size;
624 if (u8DataToSend[0] > stcSetup.
wLength)
626 u8DataToSend[0] = stcSetup.
wLength;
652 if (stcSetup.
wIndex < USBDEVICE_MAXCLASSES)
683 pstcUsb->EP0OS_f.DRQOIE = 1;
684 u16BytesCount = u16BytesCount;
702 volatile uint32_t u32Timeout;
704 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
725 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
728 pfnCompletionCallback(pstcUsb, pstcUsbDeviceIntern->
pstcEp0OUT);
762 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
789 *pu8InterfaceLength = (uint8_t)((uint32_t)u16i - (uint32_t)(((uint32_t)*ppu8Buffer - (uint32_t)pstcUsbDeviceIntern->
pu8ConfigDescriptor)));
811 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
812 return pstcUsbDeviceIntern->
enStatus;
842 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
886 pstcUsbDeviceIntern = UsbDeviceGetInternDataPtr(pstcUsb);
932 return pstcEndpointHandle;