Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_usbd.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file usbd.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V1.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 15 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 14/10/02 4:14p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 USBD driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #include "NUC472_442.h" |
sahilmgandhi | 18:6a4db94011d3 | 12 | |
sahilmgandhi | 18:6a4db94011d3 | 13 | /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver |
sahilmgandhi | 18:6a4db94011d3 | 14 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | /** @addtogroup NUC472_442_USBD_Driver USBD Driver |
sahilmgandhi | 18:6a4db94011d3 | 18 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 19 | */ |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | /** @addtogroup NUC472_442_USBD_EXPORTED_FUNCTIONS USBD Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 23 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 24 | */ |
sahilmgandhi | 18:6a4db94011d3 | 25 | /*--------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 26 | /*!< Global variables for Control Pipe */ |
sahilmgandhi | 18:6a4db94011d3 | 27 | S_USBD_CMD_T gUsbCmd; |
sahilmgandhi | 18:6a4db94011d3 | 28 | S_USBD_INFO_T *g_usbd_sInfo; |
sahilmgandhi | 18:6a4db94011d3 | 29 | |
sahilmgandhi | 18:6a4db94011d3 | 30 | VENDOR_REQ g_usbd_pfnVendorRequest = NULL; |
sahilmgandhi | 18:6a4db94011d3 | 31 | CLASS_REQ g_usbd_pfnClassRequest = NULL; |
sahilmgandhi | 18:6a4db94011d3 | 32 | SET_INTERFACE_REQ g_usbd_pfnSetInterface = NULL; |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | static uint8_t *g_usbd_CtrlInPointer = 0; |
sahilmgandhi | 18:6a4db94011d3 | 35 | static uint32_t g_usbd_UsbConfig = 0; |
sahilmgandhi | 18:6a4db94011d3 | 36 | static uint32_t g_usbd_UsbAltInterface = 0; |
sahilmgandhi | 18:6a4db94011d3 | 37 | static uint32_t g_usbd_CtrlMaxPktSize = 64; |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | #ifdef __ICCARM__ |
sahilmgandhi | 18:6a4db94011d3 | 40 | #pragma data_alignment=4 |
sahilmgandhi | 18:6a4db94011d3 | 41 | static uint8_t g_usbd_buf[12]; |
sahilmgandhi | 18:6a4db94011d3 | 42 | #elif defined (__CC_ARM) |
sahilmgandhi | 18:6a4db94011d3 | 43 | __align(4) static uint8_t g_usbd_buf[12]; |
sahilmgandhi | 18:6a4db94011d3 | 44 | #elif defined ( __GNUC__ ) |
sahilmgandhi | 18:6a4db94011d3 | 45 | static uint8_t g_usbd_buf[12] __attribute__((aligned (4))); |
sahilmgandhi | 18:6a4db94011d3 | 46 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | uint32_t g_usbd_CtrlZero = 0; |
sahilmgandhi | 18:6a4db94011d3 | 50 | uint32_t g_usbd_UsbAddr = 0; |
sahilmgandhi | 18:6a4db94011d3 | 51 | uint32_t g_usbd_CtrlInSize = 0; |
sahilmgandhi | 18:6a4db94011d3 | 52 | uint32_t g_usbd_ShortPacket = 0; |
sahilmgandhi | 18:6a4db94011d3 | 53 | uint32_t volatile g_usbd_DmaDone = 0; |
sahilmgandhi | 18:6a4db94011d3 | 54 | uint32_t g_usbd_Configured = 0; |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | /** |
sahilmgandhi | 18:6a4db94011d3 | 57 | * @brief USBD Initial |
sahilmgandhi | 18:6a4db94011d3 | 58 | * |
sahilmgandhi | 18:6a4db94011d3 | 59 | * @param[in] param Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 60 | * @param[in] pfnClassReq Class Request Callback Function |
sahilmgandhi | 18:6a4db94011d3 | 61 | * @param[in] pfnSetInterface SetInterface Request Callback Function |
sahilmgandhi | 18:6a4db94011d3 | 62 | * |
sahilmgandhi | 18:6a4db94011d3 | 63 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 64 | * |
sahilmgandhi | 18:6a4db94011d3 | 65 | * @details This function is used to initial USBD. |
sahilmgandhi | 18:6a4db94011d3 | 66 | */ |
sahilmgandhi | 18:6a4db94011d3 | 67 | void USBD_Open(S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface) |
sahilmgandhi | 18:6a4db94011d3 | 68 | { |
sahilmgandhi | 18:6a4db94011d3 | 69 | g_usbd_sInfo = param; |
sahilmgandhi | 18:6a4db94011d3 | 70 | g_usbd_pfnClassRequest = pfnClassReq; |
sahilmgandhi | 18:6a4db94011d3 | 71 | g_usbd_pfnSetInterface = pfnSetInterface; |
sahilmgandhi | 18:6a4db94011d3 | 72 | |
sahilmgandhi | 18:6a4db94011d3 | 73 | /* get EP0 maximum packet size */ |
sahilmgandhi | 18:6a4db94011d3 | 74 | g_usbd_CtrlMaxPktSize = g_usbd_sInfo->gu8DevDesc[7]; |
sahilmgandhi | 18:6a4db94011d3 | 75 | |
sahilmgandhi | 18:6a4db94011d3 | 76 | /* Initial USB engine */ |
sahilmgandhi | 18:6a4db94011d3 | 77 | /* Enable PHY */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | USBD_ENABLE_PHY(); |
sahilmgandhi | 18:6a4db94011d3 | 79 | /* wait PHY clock ready */ |
sahilmgandhi | 18:6a4db94011d3 | 80 | while (1) { |
sahilmgandhi | 18:6a4db94011d3 | 81 | USBD->EPAMPS = 0x20; |
sahilmgandhi | 18:6a4db94011d3 | 82 | if (USBD->EPAMPS == 0x20) |
sahilmgandhi | 18:6a4db94011d3 | 83 | break; |
sahilmgandhi | 18:6a4db94011d3 | 84 | } |
sahilmgandhi | 18:6a4db94011d3 | 85 | /* Force SE0, and then clear it to connect*/ |
sahilmgandhi | 18:6a4db94011d3 | 86 | USBD_SET_SE0(); |
sahilmgandhi | 18:6a4db94011d3 | 87 | } |
sahilmgandhi | 18:6a4db94011d3 | 88 | |
sahilmgandhi | 18:6a4db94011d3 | 89 | /** |
sahilmgandhi | 18:6a4db94011d3 | 90 | * @brief USBD Start |
sahilmgandhi | 18:6a4db94011d3 | 91 | * |
sahilmgandhi | 18:6a4db94011d3 | 92 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 93 | * |
sahilmgandhi | 18:6a4db94011d3 | 94 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 95 | * |
sahilmgandhi | 18:6a4db94011d3 | 96 | * @details This function is used to start transfer |
sahilmgandhi | 18:6a4db94011d3 | 97 | */ |
sahilmgandhi | 18:6a4db94011d3 | 98 | void USBD_Start(void) |
sahilmgandhi | 18:6a4db94011d3 | 99 | { |
sahilmgandhi | 18:6a4db94011d3 | 100 | USBD_CLR_SE0(); |
sahilmgandhi | 18:6a4db94011d3 | 101 | } |
sahilmgandhi | 18:6a4db94011d3 | 102 | |
sahilmgandhi | 18:6a4db94011d3 | 103 | /** |
sahilmgandhi | 18:6a4db94011d3 | 104 | * @brief Process Setup Packet |
sahilmgandhi | 18:6a4db94011d3 | 105 | * |
sahilmgandhi | 18:6a4db94011d3 | 106 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 107 | * |
sahilmgandhi | 18:6a4db94011d3 | 108 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 109 | * |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @details This function is used to process Setup packet. |
sahilmgandhi | 18:6a4db94011d3 | 111 | */ |
sahilmgandhi | 18:6a4db94011d3 | 112 | void USBD_ProcessSetupPacket(void) |
sahilmgandhi | 18:6a4db94011d3 | 113 | { |
sahilmgandhi | 18:6a4db94011d3 | 114 | // Setup packet process |
sahilmgandhi | 18:6a4db94011d3 | 115 | gUsbCmd.bmRequestType = (uint8_t)(USBD->SETUP1_0 & 0xff); |
sahilmgandhi | 18:6a4db94011d3 | 116 | gUsbCmd.bRequest = (int8_t)(USBD->SETUP1_0 >> 8) & 0xff; |
sahilmgandhi | 18:6a4db94011d3 | 117 | gUsbCmd.wValue = (uint16_t)USBD->SETUP3_2; |
sahilmgandhi | 18:6a4db94011d3 | 118 | gUsbCmd.wIndex = (uint16_t)USBD->SETUP5_4; |
sahilmgandhi | 18:6a4db94011d3 | 119 | gUsbCmd.wLength = (uint16_t)USBD->SETUP7_6; |
sahilmgandhi | 18:6a4db94011d3 | 120 | |
sahilmgandhi | 18:6a4db94011d3 | 121 | /* USB device request in setup packet: offset 0, D[6..5]: 0=Standard, 1=Class, 2=Vendor, 3=Reserved */ |
sahilmgandhi | 18:6a4db94011d3 | 122 | switch (gUsbCmd.bmRequestType & 0x60) { |
sahilmgandhi | 18:6a4db94011d3 | 123 | case REQ_STANDARD: { // Standard |
sahilmgandhi | 18:6a4db94011d3 | 124 | USBD_StandardRequest(); |
sahilmgandhi | 18:6a4db94011d3 | 125 | break; |
sahilmgandhi | 18:6a4db94011d3 | 126 | } |
sahilmgandhi | 18:6a4db94011d3 | 127 | case REQ_CLASS: { // Class |
sahilmgandhi | 18:6a4db94011d3 | 128 | if (g_usbd_pfnClassRequest != NULL) { |
sahilmgandhi | 18:6a4db94011d3 | 129 | g_usbd_pfnClassRequest(); |
sahilmgandhi | 18:6a4db94011d3 | 130 | } |
sahilmgandhi | 18:6a4db94011d3 | 131 | break; |
sahilmgandhi | 18:6a4db94011d3 | 132 | } |
sahilmgandhi | 18:6a4db94011d3 | 133 | case REQ_VENDOR: { // Vendor |
sahilmgandhi | 18:6a4db94011d3 | 134 | if (g_usbd_pfnVendorRequest != NULL) { |
sahilmgandhi | 18:6a4db94011d3 | 135 | g_usbd_pfnVendorRequest(); |
sahilmgandhi | 18:6a4db94011d3 | 136 | } |
sahilmgandhi | 18:6a4db94011d3 | 137 | break; |
sahilmgandhi | 18:6a4db94011d3 | 138 | } |
sahilmgandhi | 18:6a4db94011d3 | 139 | default: { // reserved |
sahilmgandhi | 18:6a4db94011d3 | 140 | /* Setup error, stall the device */ |
sahilmgandhi | 18:6a4db94011d3 | 141 | USBD_SET_CEP_STATE(USBD_CEPCTL_STALLEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 142 | break; |
sahilmgandhi | 18:6a4db94011d3 | 143 | } |
sahilmgandhi | 18:6a4db94011d3 | 144 | } |
sahilmgandhi | 18:6a4db94011d3 | 145 | } |
sahilmgandhi | 18:6a4db94011d3 | 146 | |
sahilmgandhi | 18:6a4db94011d3 | 147 | /** |
sahilmgandhi | 18:6a4db94011d3 | 148 | * @brief Get Descriptor request |
sahilmgandhi | 18:6a4db94011d3 | 149 | * |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 151 | * |
sahilmgandhi | 18:6a4db94011d3 | 152 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 153 | * |
sahilmgandhi | 18:6a4db94011d3 | 154 | * @details This function is used to process GetDescriptor request. |
sahilmgandhi | 18:6a4db94011d3 | 155 | */ |
sahilmgandhi | 18:6a4db94011d3 | 156 | int USBD_GetDescriptor(void) |
sahilmgandhi | 18:6a4db94011d3 | 157 | { |
sahilmgandhi | 18:6a4db94011d3 | 158 | uint32_t u32Len; |
sahilmgandhi | 18:6a4db94011d3 | 159 | |
sahilmgandhi | 18:6a4db94011d3 | 160 | u32Len = gUsbCmd.wLength; |
sahilmgandhi | 18:6a4db94011d3 | 161 | g_usbd_CtrlZero = 0; |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | switch ((gUsbCmd.wValue & 0xff00) >> 8) { |
sahilmgandhi | 18:6a4db94011d3 | 164 | // Get Device Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 165 | case DESC_DEVICE: { |
sahilmgandhi | 18:6a4db94011d3 | 166 | u32Len = Minimum(u32Len, LEN_DEVICE); |
sahilmgandhi | 18:6a4db94011d3 | 167 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8DevDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 168 | break; |
sahilmgandhi | 18:6a4db94011d3 | 169 | } |
sahilmgandhi | 18:6a4db94011d3 | 170 | // Get Configuration Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 171 | case DESC_CONFIG: { |
sahilmgandhi | 18:6a4db94011d3 | 172 | uint32_t u32TotalLen; |
sahilmgandhi | 18:6a4db94011d3 | 173 | |
sahilmgandhi | 18:6a4db94011d3 | 174 | if (USBD->OPER & 0x04) { /* high speed */ |
sahilmgandhi | 18:6a4db94011d3 | 175 | u32TotalLen = g_usbd_sInfo->gu8ConfigDesc[3]; |
sahilmgandhi | 18:6a4db94011d3 | 176 | u32TotalLen = g_usbd_sInfo->gu8ConfigDesc[2] + (u32TotalLen << 8); |
sahilmgandhi | 18:6a4db94011d3 | 177 | |
sahilmgandhi | 18:6a4db94011d3 | 178 | u32Len = Minimum(u32Len, u32TotalLen); |
sahilmgandhi | 18:6a4db94011d3 | 179 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 180 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 181 | |
sahilmgandhi | 18:6a4db94011d3 | 182 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8ConfigDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 183 | } else { /* full speed */ |
sahilmgandhi | 18:6a4db94011d3 | 184 | u32TotalLen = g_usbd_sInfo->gu8OtherConfigDesc[3]; |
sahilmgandhi | 18:6a4db94011d3 | 185 | u32TotalLen = g_usbd_sInfo->gu8OtherConfigDesc[2] + (u32TotalLen << 8); |
sahilmgandhi | 18:6a4db94011d3 | 186 | |
sahilmgandhi | 18:6a4db94011d3 | 187 | u32Len = Minimum(u32Len, u32TotalLen); |
sahilmgandhi | 18:6a4db94011d3 | 188 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 189 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 190 | |
sahilmgandhi | 18:6a4db94011d3 | 191 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8OtherConfigDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 192 | } |
sahilmgandhi | 18:6a4db94011d3 | 193 | break; |
sahilmgandhi | 18:6a4db94011d3 | 194 | } |
sahilmgandhi | 18:6a4db94011d3 | 195 | // Get Qualifier Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 196 | case DESC_QUALIFIER: { |
sahilmgandhi | 18:6a4db94011d3 | 197 | u32Len = Minimum(u32Len, LEN_QUALIFIER); |
sahilmgandhi | 18:6a4db94011d3 | 198 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8QualDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 199 | break; |
sahilmgandhi | 18:6a4db94011d3 | 200 | } |
sahilmgandhi | 18:6a4db94011d3 | 201 | // Get Other Speed Descriptor - Full speed |
sahilmgandhi | 18:6a4db94011d3 | 202 | case DESC_OTHERSPEED: { |
sahilmgandhi | 18:6a4db94011d3 | 203 | uint32_t u32TotalLen; |
sahilmgandhi | 18:6a4db94011d3 | 204 | |
sahilmgandhi | 18:6a4db94011d3 | 205 | u32TotalLen = g_usbd_sInfo->gu8OtherConfigDesc[3]; |
sahilmgandhi | 18:6a4db94011d3 | 206 | u32TotalLen = g_usbd_sInfo->gu8OtherConfigDesc[2] + (u32TotalLen << 8); |
sahilmgandhi | 18:6a4db94011d3 | 207 | |
sahilmgandhi | 18:6a4db94011d3 | 208 | u32Len = Minimum(u32Len, u32TotalLen); |
sahilmgandhi | 18:6a4db94011d3 | 209 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 210 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 211 | |
sahilmgandhi | 18:6a4db94011d3 | 212 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8OtherConfigDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 213 | break; |
sahilmgandhi | 18:6a4db94011d3 | 214 | } |
sahilmgandhi | 18:6a4db94011d3 | 215 | // Get HID Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 216 | case DESC_HID: { |
sahilmgandhi | 18:6a4db94011d3 | 217 | u32Len = Minimum(u32Len, LEN_HID); |
sahilmgandhi | 18:6a4db94011d3 | 218 | USBD_MemCopy(g_usbd_buf, (uint8_t *)&g_usbd_sInfo->gu8ConfigDesc[LEN_CONFIG+LEN_INTERFACE], u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 219 | USBD_PrepareCtrlIn(g_usbd_buf, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 220 | break; |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | // Get Report Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 223 | case DESC_HID_RPT: { |
sahilmgandhi | 18:6a4db94011d3 | 224 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 225 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 226 | |
sahilmgandhi | 18:6a4db94011d3 | 227 | switch (gUsbCmd.wIndex & 0xff) { |
sahilmgandhi | 18:6a4db94011d3 | 228 | case 0: { |
sahilmgandhi | 18:6a4db94011d3 | 229 | u32Len = Minimum(u32Len, g_usbd_sInfo->gu32HidReportSize[0]); |
sahilmgandhi | 18:6a4db94011d3 | 230 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8HidReportDesc[0], u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 231 | break; |
sahilmgandhi | 18:6a4db94011d3 | 232 | } |
sahilmgandhi | 18:6a4db94011d3 | 233 | case 1: { |
sahilmgandhi | 18:6a4db94011d3 | 234 | u32Len = Minimum(u32Len, g_usbd_sInfo->gu32HidReportSize[1]); |
sahilmgandhi | 18:6a4db94011d3 | 235 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8HidReportDesc[1], u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 236 | break; |
sahilmgandhi | 18:6a4db94011d3 | 237 | } |
sahilmgandhi | 18:6a4db94011d3 | 238 | case 2: { |
sahilmgandhi | 18:6a4db94011d3 | 239 | u32Len = Minimum(u32Len, g_usbd_sInfo->gu32HidReportSize[2]); |
sahilmgandhi | 18:6a4db94011d3 | 240 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8HidReportDesc[2], u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 241 | break; |
sahilmgandhi | 18:6a4db94011d3 | 242 | } |
sahilmgandhi | 18:6a4db94011d3 | 243 | } |
sahilmgandhi | 18:6a4db94011d3 | 244 | break; |
sahilmgandhi | 18:6a4db94011d3 | 245 | } |
sahilmgandhi | 18:6a4db94011d3 | 246 | // Get String Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 247 | case DESC_STRING: { |
sahilmgandhi | 18:6a4db94011d3 | 248 | // Get Language |
sahilmgandhi | 18:6a4db94011d3 | 249 | if ((gUsbCmd.wValue & 0xff) == 0) { |
sahilmgandhi | 18:6a4db94011d3 | 250 | u32Len = Minimum(u32Len, 4); |
sahilmgandhi | 18:6a4db94011d3 | 251 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8StrLangDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 252 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 253 | // Get String Descriptor |
sahilmgandhi | 18:6a4db94011d3 | 254 | switch (gUsbCmd.wValue & 0xff) { |
sahilmgandhi | 18:6a4db94011d3 | 255 | case 1: { |
sahilmgandhi | 18:6a4db94011d3 | 256 | u32Len = Minimum(u32Len, g_usbd_sInfo->gu8StrVendorDesc[0]); |
sahilmgandhi | 18:6a4db94011d3 | 257 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 258 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 259 | |
sahilmgandhi | 18:6a4db94011d3 | 260 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8StrVendorDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 261 | break; |
sahilmgandhi | 18:6a4db94011d3 | 262 | } |
sahilmgandhi | 18:6a4db94011d3 | 263 | case 2: { |
sahilmgandhi | 18:6a4db94011d3 | 264 | u32Len = Minimum(u32Len, g_usbd_sInfo->gu8StrProductDesc[0]); |
sahilmgandhi | 18:6a4db94011d3 | 265 | if ((u32Len % g_usbd_CtrlMaxPktSize) == 0) |
sahilmgandhi | 18:6a4db94011d3 | 266 | g_usbd_CtrlZero = 1; |
sahilmgandhi | 18:6a4db94011d3 | 267 | |
sahilmgandhi | 18:6a4db94011d3 | 268 | USBD_PrepareCtrlIn((uint8_t *)g_usbd_sInfo->gu8StrProductDesc, u32Len); |
sahilmgandhi | 18:6a4db94011d3 | 269 | break; |
sahilmgandhi | 18:6a4db94011d3 | 270 | } |
sahilmgandhi | 18:6a4db94011d3 | 271 | default: |
sahilmgandhi | 18:6a4db94011d3 | 272 | // Not support. Reply STALL. |
sahilmgandhi | 18:6a4db94011d3 | 273 | USBD_SET_CEP_STATE(USBD_CEPCTL_STALLEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 274 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 275 | } |
sahilmgandhi | 18:6a4db94011d3 | 276 | } |
sahilmgandhi | 18:6a4db94011d3 | 277 | break; |
sahilmgandhi | 18:6a4db94011d3 | 278 | } |
sahilmgandhi | 18:6a4db94011d3 | 279 | default: |
sahilmgandhi | 18:6a4db94011d3 | 280 | // Not support. Reply STALL. |
sahilmgandhi | 18:6a4db94011d3 | 281 | USBD_SET_CEP_STATE(USBD_CEPCTL_STALLEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 282 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 283 | } |
sahilmgandhi | 18:6a4db94011d3 | 284 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 285 | } |
sahilmgandhi | 18:6a4db94011d3 | 286 | |
sahilmgandhi | 18:6a4db94011d3 | 287 | |
sahilmgandhi | 18:6a4db94011d3 | 288 | /** |
sahilmgandhi | 18:6a4db94011d3 | 289 | * @brief Process USB standard request |
sahilmgandhi | 18:6a4db94011d3 | 290 | * |
sahilmgandhi | 18:6a4db94011d3 | 291 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 292 | * |
sahilmgandhi | 18:6a4db94011d3 | 293 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 294 | * |
sahilmgandhi | 18:6a4db94011d3 | 295 | * @details This function is used to process USB Standard Request. |
sahilmgandhi | 18:6a4db94011d3 | 296 | */ |
sahilmgandhi | 18:6a4db94011d3 | 297 | void USBD_StandardRequest(void) |
sahilmgandhi | 18:6a4db94011d3 | 298 | { |
sahilmgandhi | 18:6a4db94011d3 | 299 | /* clear global variables for new request */ |
sahilmgandhi | 18:6a4db94011d3 | 300 | g_usbd_CtrlInPointer = 0; |
sahilmgandhi | 18:6a4db94011d3 | 301 | g_usbd_CtrlInSize = 0; |
sahilmgandhi | 18:6a4db94011d3 | 302 | |
sahilmgandhi | 18:6a4db94011d3 | 303 | if (gUsbCmd.bmRequestType & 0x80) { /* request data transfer direction */ |
sahilmgandhi | 18:6a4db94011d3 | 304 | // Device to host |
sahilmgandhi | 18:6a4db94011d3 | 305 | switch (gUsbCmd.bRequest) { |
sahilmgandhi | 18:6a4db94011d3 | 306 | case USBD_GET_CONFIGURATION: { |
sahilmgandhi | 18:6a4db94011d3 | 307 | // Return current configuration setting |
sahilmgandhi | 18:6a4db94011d3 | 308 | USBD_PrepareCtrlIn((uint8_t *)&g_usbd_UsbConfig, 1); |
sahilmgandhi | 18:6a4db94011d3 | 309 | |
sahilmgandhi | 18:6a4db94011d3 | 310 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 311 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 312 | break; |
sahilmgandhi | 18:6a4db94011d3 | 313 | } |
sahilmgandhi | 18:6a4db94011d3 | 314 | case USBD_GET_DESCRIPTOR: { |
sahilmgandhi | 18:6a4db94011d3 | 315 | if (!USBD_GetDescriptor()) { |
sahilmgandhi | 18:6a4db94011d3 | 316 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 317 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 318 | } |
sahilmgandhi | 18:6a4db94011d3 | 319 | break; |
sahilmgandhi | 18:6a4db94011d3 | 320 | } |
sahilmgandhi | 18:6a4db94011d3 | 321 | case USBD_GET_INTERFACE: { |
sahilmgandhi | 18:6a4db94011d3 | 322 | // Return current interface setting |
sahilmgandhi | 18:6a4db94011d3 | 323 | USBD_PrepareCtrlIn((uint8_t *)&g_usbd_UsbAltInterface, 1); |
sahilmgandhi | 18:6a4db94011d3 | 324 | |
sahilmgandhi | 18:6a4db94011d3 | 325 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 326 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 327 | break; |
sahilmgandhi | 18:6a4db94011d3 | 328 | } |
sahilmgandhi | 18:6a4db94011d3 | 329 | case USBD_GET_STATUS: { |
sahilmgandhi | 18:6a4db94011d3 | 330 | // Device |
sahilmgandhi | 18:6a4db94011d3 | 331 | if (gUsbCmd.bmRequestType == 0x80) { |
sahilmgandhi | 18:6a4db94011d3 | 332 | if (g_usbd_sInfo->gu8ConfigDesc[7] & 0x40) |
sahilmgandhi | 18:6a4db94011d3 | 333 | g_usbd_buf[0] = 1; // Self-Powered |
sahilmgandhi | 18:6a4db94011d3 | 334 | else |
sahilmgandhi | 18:6a4db94011d3 | 335 | g_usbd_buf[0] = 0; // bus-Powered |
sahilmgandhi | 18:6a4db94011d3 | 336 | } |
sahilmgandhi | 18:6a4db94011d3 | 337 | // Interface |
sahilmgandhi | 18:6a4db94011d3 | 338 | else if (gUsbCmd.bmRequestType == 0x81) |
sahilmgandhi | 18:6a4db94011d3 | 339 | g_usbd_buf[0] = 0; |
sahilmgandhi | 18:6a4db94011d3 | 340 | // Endpoint |
sahilmgandhi | 18:6a4db94011d3 | 341 | else if (gUsbCmd.bmRequestType == 0x82) { |
sahilmgandhi | 18:6a4db94011d3 | 342 | uint8_t ep = gUsbCmd.wIndex & 0xF; |
sahilmgandhi | 18:6a4db94011d3 | 343 | g_usbd_buf[0] = USBD_GetStall(ep)? 1 : 0; |
sahilmgandhi | 18:6a4db94011d3 | 344 | } |
sahilmgandhi | 18:6a4db94011d3 | 345 | g_usbd_buf[1] = 0; |
sahilmgandhi | 18:6a4db94011d3 | 346 | USBD_PrepareCtrlIn(g_usbd_buf, 2); |
sahilmgandhi | 18:6a4db94011d3 | 347 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_INTKIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 348 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_INTKIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 349 | break; |
sahilmgandhi | 18:6a4db94011d3 | 350 | } |
sahilmgandhi | 18:6a4db94011d3 | 351 | default: { |
sahilmgandhi | 18:6a4db94011d3 | 352 | /* Setup error, stall the device */ |
sahilmgandhi | 18:6a4db94011d3 | 353 | USBD_SET_CEP_STATE(USBD_CEPCTL_STALLEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 354 | break; |
sahilmgandhi | 18:6a4db94011d3 | 355 | } |
sahilmgandhi | 18:6a4db94011d3 | 356 | } |
sahilmgandhi | 18:6a4db94011d3 | 357 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 358 | // Host to device |
sahilmgandhi | 18:6a4db94011d3 | 359 | switch (gUsbCmd.bRequest) { |
sahilmgandhi | 18:6a4db94011d3 | 360 | case USBD_CLEAR_FEATURE: { |
sahilmgandhi | 18:6a4db94011d3 | 361 | /* Status stage */ |
sahilmgandhi | 18:6a4db94011d3 | 362 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 363 | USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); |
sahilmgandhi | 18:6a4db94011d3 | 364 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 365 | break; |
sahilmgandhi | 18:6a4db94011d3 | 366 | } |
sahilmgandhi | 18:6a4db94011d3 | 367 | case USBD_SET_ADDRESS: { |
sahilmgandhi | 18:6a4db94011d3 | 368 | g_usbd_UsbAddr = (uint8_t)gUsbCmd.wValue; |
sahilmgandhi | 18:6a4db94011d3 | 369 | |
sahilmgandhi | 18:6a4db94011d3 | 370 | // DATA IN for end of setup |
sahilmgandhi | 18:6a4db94011d3 | 371 | /* Status Stage */ |
sahilmgandhi | 18:6a4db94011d3 | 372 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 373 | USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); |
sahilmgandhi | 18:6a4db94011d3 | 374 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 375 | break; |
sahilmgandhi | 18:6a4db94011d3 | 376 | } |
sahilmgandhi | 18:6a4db94011d3 | 377 | case USBD_SET_CONFIGURATION: { |
sahilmgandhi | 18:6a4db94011d3 | 378 | g_usbd_UsbConfig = (uint8_t)gUsbCmd.wValue; |
sahilmgandhi | 18:6a4db94011d3 | 379 | g_usbd_Configured = 1; |
sahilmgandhi | 18:6a4db94011d3 | 380 | // DATA IN for end of setup |
sahilmgandhi | 18:6a4db94011d3 | 381 | /* Status stage */ |
sahilmgandhi | 18:6a4db94011d3 | 382 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 383 | USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); |
sahilmgandhi | 18:6a4db94011d3 | 384 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 385 | break; |
sahilmgandhi | 18:6a4db94011d3 | 386 | } |
sahilmgandhi | 18:6a4db94011d3 | 387 | case USBD_SET_FEATURE: { |
sahilmgandhi | 18:6a4db94011d3 | 388 | /* Status stage */ |
sahilmgandhi | 18:6a4db94011d3 | 389 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 390 | USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); |
sahilmgandhi | 18:6a4db94011d3 | 391 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 392 | break; |
sahilmgandhi | 18:6a4db94011d3 | 393 | } |
sahilmgandhi | 18:6a4db94011d3 | 394 | case USBD_SET_INTERFACE: { |
sahilmgandhi | 18:6a4db94011d3 | 395 | g_usbd_UsbAltInterface = (uint8_t)gUsbCmd.wValue; |
sahilmgandhi | 18:6a4db94011d3 | 396 | if (g_usbd_pfnSetInterface != NULL) |
sahilmgandhi | 18:6a4db94011d3 | 397 | g_usbd_pfnSetInterface(g_usbd_UsbAltInterface); |
sahilmgandhi | 18:6a4db94011d3 | 398 | /* Status stage */ |
sahilmgandhi | 18:6a4db94011d3 | 399 | USBD_CLR_CEP_INT_FLAG(USBD_CEPINTSTS_STSDONEIF_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 400 | USBD_SET_CEP_STATE(USB_CEPCTL_NAKCLR); |
sahilmgandhi | 18:6a4db94011d3 | 401 | USBD_ENABLE_CEP_INT(USBD_CEPINTEN_STSDONEIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 402 | break; |
sahilmgandhi | 18:6a4db94011d3 | 403 | } |
sahilmgandhi | 18:6a4db94011d3 | 404 | default: { |
sahilmgandhi | 18:6a4db94011d3 | 405 | /* Setup error, stall the device */ |
sahilmgandhi | 18:6a4db94011d3 | 406 | USBD_SET_CEP_STATE(USBD_CEPCTL_STALLEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 407 | break; |
sahilmgandhi | 18:6a4db94011d3 | 408 | } |
sahilmgandhi | 18:6a4db94011d3 | 409 | } |
sahilmgandhi | 18:6a4db94011d3 | 410 | } |
sahilmgandhi | 18:6a4db94011d3 | 411 | } |
sahilmgandhi | 18:6a4db94011d3 | 412 | |
sahilmgandhi | 18:6a4db94011d3 | 413 | /** |
sahilmgandhi | 18:6a4db94011d3 | 414 | * @brief Update Device State |
sahilmgandhi | 18:6a4db94011d3 | 415 | * |
sahilmgandhi | 18:6a4db94011d3 | 416 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 417 | * |
sahilmgandhi | 18:6a4db94011d3 | 418 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 419 | * |
sahilmgandhi | 18:6a4db94011d3 | 420 | * @details This function is used to update Device state when Setup packet complete |
sahilmgandhi | 18:6a4db94011d3 | 421 | */ |
sahilmgandhi | 18:6a4db94011d3 | 422 | void USBD_UpdateDeviceState(void) |
sahilmgandhi | 18:6a4db94011d3 | 423 | { |
sahilmgandhi | 18:6a4db94011d3 | 424 | switch (gUsbCmd.bRequest) { |
sahilmgandhi | 18:6a4db94011d3 | 425 | case USBD_SET_ADDRESS: { |
sahilmgandhi | 18:6a4db94011d3 | 426 | USBD_SET_ADDR(g_usbd_UsbAddr); |
sahilmgandhi | 18:6a4db94011d3 | 427 | break; |
sahilmgandhi | 18:6a4db94011d3 | 428 | } |
sahilmgandhi | 18:6a4db94011d3 | 429 | case USBD_SET_FEATURE: { |
sahilmgandhi | 18:6a4db94011d3 | 430 | if(gUsbCmd.wValue == FEATURE_ENDPOINT_HALT) |
sahilmgandhi | 18:6a4db94011d3 | 431 | USBD_SetStall(gUsbCmd.wIndex & 0xF); |
sahilmgandhi | 18:6a4db94011d3 | 432 | break; |
sahilmgandhi | 18:6a4db94011d3 | 433 | } |
sahilmgandhi | 18:6a4db94011d3 | 434 | case USBD_CLEAR_FEATURE: { |
sahilmgandhi | 18:6a4db94011d3 | 435 | if(gUsbCmd.wValue == FEATURE_ENDPOINT_HALT) |
sahilmgandhi | 18:6a4db94011d3 | 436 | USBD_ClearStall(gUsbCmd.wIndex & 0xF); |
sahilmgandhi | 18:6a4db94011d3 | 437 | break; |
sahilmgandhi | 18:6a4db94011d3 | 438 | } |
sahilmgandhi | 18:6a4db94011d3 | 439 | default: |
sahilmgandhi | 18:6a4db94011d3 | 440 | ; |
sahilmgandhi | 18:6a4db94011d3 | 441 | } |
sahilmgandhi | 18:6a4db94011d3 | 442 | } |
sahilmgandhi | 18:6a4db94011d3 | 443 | |
sahilmgandhi | 18:6a4db94011d3 | 444 | |
sahilmgandhi | 18:6a4db94011d3 | 445 | /** |
sahilmgandhi | 18:6a4db94011d3 | 446 | * @brief Prepare Control IN transaction |
sahilmgandhi | 18:6a4db94011d3 | 447 | * |
sahilmgandhi | 18:6a4db94011d3 | 448 | * @param[in] pu8Buf Control IN data pointer |
sahilmgandhi | 18:6a4db94011d3 | 449 | * @param[in] u32Size IN transfer size |
sahilmgandhi | 18:6a4db94011d3 | 450 | * |
sahilmgandhi | 18:6a4db94011d3 | 451 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 452 | * |
sahilmgandhi | 18:6a4db94011d3 | 453 | * @details This function is used to prepare Control IN transfer |
sahilmgandhi | 18:6a4db94011d3 | 454 | */ |
sahilmgandhi | 18:6a4db94011d3 | 455 | void USBD_PrepareCtrlIn(uint8_t *pu8Buf, uint32_t u32Size) |
sahilmgandhi | 18:6a4db94011d3 | 456 | { |
sahilmgandhi | 18:6a4db94011d3 | 457 | g_usbd_CtrlInPointer = pu8Buf; |
sahilmgandhi | 18:6a4db94011d3 | 458 | g_usbd_CtrlInSize = u32Size; |
sahilmgandhi | 18:6a4db94011d3 | 459 | } |
sahilmgandhi | 18:6a4db94011d3 | 460 | |
sahilmgandhi | 18:6a4db94011d3 | 461 | |
sahilmgandhi | 18:6a4db94011d3 | 462 | |
sahilmgandhi | 18:6a4db94011d3 | 463 | /** |
sahilmgandhi | 18:6a4db94011d3 | 464 | * @brief Start Control IN transfer |
sahilmgandhi | 18:6a4db94011d3 | 465 | * |
sahilmgandhi | 18:6a4db94011d3 | 466 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 467 | * |
sahilmgandhi | 18:6a4db94011d3 | 468 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 469 | * |
sahilmgandhi | 18:6a4db94011d3 | 470 | * @details This function is used to start Control IN |
sahilmgandhi | 18:6a4db94011d3 | 471 | */ |
sahilmgandhi | 18:6a4db94011d3 | 472 | void USBD_CtrlIn(void) |
sahilmgandhi | 18:6a4db94011d3 | 473 | { |
sahilmgandhi | 18:6a4db94011d3 | 474 | int volatile i; |
sahilmgandhi | 18:6a4db94011d3 | 475 | uint32_t volatile count; |
sahilmgandhi | 18:6a4db94011d3 | 476 | |
sahilmgandhi | 18:6a4db94011d3 | 477 | // Process remained data |
sahilmgandhi | 18:6a4db94011d3 | 478 | if(g_usbd_CtrlInSize >= g_usbd_CtrlMaxPktSize) { |
sahilmgandhi | 18:6a4db94011d3 | 479 | // Data size > MXPLD |
sahilmgandhi | 18:6a4db94011d3 | 480 | for (i=0; i<(g_usbd_CtrlMaxPktSize >> 2); i++, g_usbd_CtrlInPointer+=4) |
sahilmgandhi | 18:6a4db94011d3 | 481 | USBD->CEPDAT = *(uint32_t *)g_usbd_CtrlInPointer; |
sahilmgandhi | 18:6a4db94011d3 | 482 | USBD_START_CEP_IN(g_usbd_CtrlMaxPktSize); |
sahilmgandhi | 18:6a4db94011d3 | 483 | g_usbd_CtrlInSize -= g_usbd_CtrlMaxPktSize; |
sahilmgandhi | 18:6a4db94011d3 | 484 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 485 | // Data size <= MXPLD |
sahilmgandhi | 18:6a4db94011d3 | 486 | for (i=0; i<(g_usbd_CtrlInSize >> 2); i++, g_usbd_CtrlInPointer+=4) |
sahilmgandhi | 18:6a4db94011d3 | 487 | USBD->CEPDAT = *(uint32_t *)g_usbd_CtrlInPointer; |
sahilmgandhi | 18:6a4db94011d3 | 488 | |
sahilmgandhi | 18:6a4db94011d3 | 489 | count = g_usbd_CtrlInSize % 4; |
sahilmgandhi | 18:6a4db94011d3 | 490 | for (i=0; i<count; i++) |
sahilmgandhi | 18:6a4db94011d3 | 491 | USBD->CEPDAT_BYTE = *(uint8_t *)(g_usbd_CtrlInPointer + i); |
sahilmgandhi | 18:6a4db94011d3 | 492 | |
sahilmgandhi | 18:6a4db94011d3 | 493 | USBD_START_CEP_IN(g_usbd_CtrlInSize); |
sahilmgandhi | 18:6a4db94011d3 | 494 | g_usbd_CtrlInPointer = 0; |
sahilmgandhi | 18:6a4db94011d3 | 495 | g_usbd_CtrlInSize = 0; |
sahilmgandhi | 18:6a4db94011d3 | 496 | } |
sahilmgandhi | 18:6a4db94011d3 | 497 | } |
sahilmgandhi | 18:6a4db94011d3 | 498 | |
sahilmgandhi | 18:6a4db94011d3 | 499 | /** |
sahilmgandhi | 18:6a4db94011d3 | 500 | * @brief Start Control OUT transaction |
sahilmgandhi | 18:6a4db94011d3 | 501 | * |
sahilmgandhi | 18:6a4db94011d3 | 502 | * @param[in] pu8Buf Control OUT data pointer |
sahilmgandhi | 18:6a4db94011d3 | 503 | * @param[in] u32Size OUT transfer size |
sahilmgandhi | 18:6a4db94011d3 | 504 | * |
sahilmgandhi | 18:6a4db94011d3 | 505 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 506 | * |
sahilmgandhi | 18:6a4db94011d3 | 507 | * @details This function is used to start Control OUT transfer |
sahilmgandhi | 18:6a4db94011d3 | 508 | */ |
sahilmgandhi | 18:6a4db94011d3 | 509 | void USBD_CtrlOut(uint8_t *pu8Buf, uint32_t u32Size) |
sahilmgandhi | 18:6a4db94011d3 | 510 | { |
sahilmgandhi | 18:6a4db94011d3 | 511 | int volatile i; |
sahilmgandhi | 18:6a4db94011d3 | 512 | |
sahilmgandhi | 18:6a4db94011d3 | 513 | while(1) { |
sahilmgandhi | 18:6a4db94011d3 | 514 | if (USBD->CEPINTSTS & USBD_CEPINTSTS_RXPKIF_Msk) { |
sahilmgandhi | 18:6a4db94011d3 | 515 | for (i=0; i<u32Size; i++) |
sahilmgandhi | 18:6a4db94011d3 | 516 | *(uint8_t *)(pu8Buf + i) = USBD->CEPDAT_BYTE; |
sahilmgandhi | 18:6a4db94011d3 | 517 | USBD->CEPINTSTS = USBD_CEPINTSTS_RXPKIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 518 | break; |
sahilmgandhi | 18:6a4db94011d3 | 519 | } |
sahilmgandhi | 18:6a4db94011d3 | 520 | } |
sahilmgandhi | 18:6a4db94011d3 | 521 | } |
sahilmgandhi | 18:6a4db94011d3 | 522 | |
sahilmgandhi | 18:6a4db94011d3 | 523 | /** |
sahilmgandhi | 18:6a4db94011d3 | 524 | * @brief Clear all software flags |
sahilmgandhi | 18:6a4db94011d3 | 525 | * |
sahilmgandhi | 18:6a4db94011d3 | 526 | * @param[in] None |
sahilmgandhi | 18:6a4db94011d3 | 527 | * |
sahilmgandhi | 18:6a4db94011d3 | 528 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 529 | * |
sahilmgandhi | 18:6a4db94011d3 | 530 | * @details This function is used to clear all software control flag |
sahilmgandhi | 18:6a4db94011d3 | 531 | */ |
sahilmgandhi | 18:6a4db94011d3 | 532 | void USBD_SwReset(void) |
sahilmgandhi | 18:6a4db94011d3 | 533 | { |
sahilmgandhi | 18:6a4db94011d3 | 534 | // Reset all variables for protocol |
sahilmgandhi | 18:6a4db94011d3 | 535 | g_usbd_UsbAddr = 0; |
sahilmgandhi | 18:6a4db94011d3 | 536 | g_usbd_DmaDone = 0; |
sahilmgandhi | 18:6a4db94011d3 | 537 | g_usbd_ShortPacket = 0; |
sahilmgandhi | 18:6a4db94011d3 | 538 | g_usbd_Configured = 0; |
sahilmgandhi | 18:6a4db94011d3 | 539 | |
sahilmgandhi | 18:6a4db94011d3 | 540 | // Reset USB device address |
sahilmgandhi | 18:6a4db94011d3 | 541 | USBD_SET_ADDR(0); |
sahilmgandhi | 18:6a4db94011d3 | 542 | } |
sahilmgandhi | 18:6a4db94011d3 | 543 | |
sahilmgandhi | 18:6a4db94011d3 | 544 | /** |
sahilmgandhi | 18:6a4db94011d3 | 545 | * @brief USBD Set Vendor Request |
sahilmgandhi | 18:6a4db94011d3 | 546 | * |
sahilmgandhi | 18:6a4db94011d3 | 547 | * @param[in] pfnVendorReq Vendor Request Callback Function |
sahilmgandhi | 18:6a4db94011d3 | 548 | * |
sahilmgandhi | 18:6a4db94011d3 | 549 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 550 | * |
sahilmgandhi | 18:6a4db94011d3 | 551 | * @details This function is used to set USBD vendor request callback function |
sahilmgandhi | 18:6a4db94011d3 | 552 | */ |
sahilmgandhi | 18:6a4db94011d3 | 553 | void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq) |
sahilmgandhi | 18:6a4db94011d3 | 554 | { |
sahilmgandhi | 18:6a4db94011d3 | 555 | g_usbd_pfnVendorRequest = pfnVendorReq; |
sahilmgandhi | 18:6a4db94011d3 | 556 | } |
sahilmgandhi | 18:6a4db94011d3 | 557 | |
sahilmgandhi | 18:6a4db94011d3 | 558 | |
sahilmgandhi | 18:6a4db94011d3 | 559 | /*@}*/ /* end of group NUC472_442_GPIO_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 560 | |
sahilmgandhi | 18:6a4db94011d3 | 561 | /*@}*/ /* end of group NUC472_442_GPIO_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 562 | |
sahilmgandhi | 18:6a4db94011d3 | 563 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 564 | |
sahilmgandhi | 18:6a4db94011d3 | 565 | /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |