Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_usbd.h@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file usbd.h |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @brief M451 series USB driver header file |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @version 2.0.0 |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @date 10, January, 2014 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 8 | * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 9 | ******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 10 | #ifndef __USBD_H__ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #define __USBD_H__ |
sahilmgandhi | 18:6a4db94011d3 | 12 | |
sahilmgandhi | 18:6a4db94011d3 | 13 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 14 | extern "C" |
sahilmgandhi | 18:6a4db94011d3 | 15 | { |
sahilmgandhi | 18:6a4db94011d3 | 16 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 19 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 20 | */ |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | /** @addtogroup USBD_Driver USBD Driver |
sahilmgandhi | 18:6a4db94011d3 | 23 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 24 | */ |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | /** @addtogroup USBD_EXPORTED_STRUCTS USBD Exported Structs |
sahilmgandhi | 18:6a4db94011d3 | 27 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 28 | */ |
sahilmgandhi | 18:6a4db94011d3 | 29 | typedef struct s_usbd_info |
sahilmgandhi | 18:6a4db94011d3 | 30 | { |
sahilmgandhi | 18:6a4db94011d3 | 31 | const uint8_t *gu8DevDesc; /*!< Pointer for USB Device Descriptor */ |
sahilmgandhi | 18:6a4db94011d3 | 32 | const uint8_t *gu8ConfigDesc; /*!< Pointer for USB Configuration Descriptor */ |
sahilmgandhi | 18:6a4db94011d3 | 33 | const uint8_t **gu8StringDesc; /*!< Pointer for USB String Descriptor pointers */ |
sahilmgandhi | 18:6a4db94011d3 | 34 | const uint8_t **gu8HidReportDesc; /*!< Pointer for USB HID Report Descriptor */ |
sahilmgandhi | 18:6a4db94011d3 | 35 | const uint32_t *gu32HidReportSize; /*!< Pointer for HID Report descriptor Size */ |
sahilmgandhi | 18:6a4db94011d3 | 36 | const uint32_t *gu32ConfigHidDescIdx; /*!< Pointer for HID Descriptor start index */ |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | } S_USBD_INFO_T; |
sahilmgandhi | 18:6a4db94011d3 | 39 | |
sahilmgandhi | 18:6a4db94011d3 | 40 | extern const S_USBD_INFO_T gsInfo; |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | /*@}*/ /* end of group USBD_EXPORTED_STRUCTS */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | /** @addtogroup USBD_EXPORTED_CONSTANTS USBD Exported Constants |
sahilmgandhi | 18:6a4db94011d3 | 48 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 49 | */ |
sahilmgandhi | 18:6a4db94011d3 | 50 | #define USBD_BUF_BASE (USBD_BASE+0x100) |
sahilmgandhi | 18:6a4db94011d3 | 51 | #define USBD_MAX_EP 8 |
sahilmgandhi | 18:6a4db94011d3 | 52 | |
sahilmgandhi | 18:6a4db94011d3 | 53 | #define EP0 0 /*!< Endpoint 0 */ |
sahilmgandhi | 18:6a4db94011d3 | 54 | #define EP1 1 /*!< Endpoint 1 */ |
sahilmgandhi | 18:6a4db94011d3 | 55 | #define EP2 2 /*!< Endpoint 2 */ |
sahilmgandhi | 18:6a4db94011d3 | 56 | #define EP3 3 /*!< Endpoint 3 */ |
sahilmgandhi | 18:6a4db94011d3 | 57 | #define EP4 4 /*!< Endpoint 4 */ |
sahilmgandhi | 18:6a4db94011d3 | 58 | #define EP5 5 /*!< Endpoint 5 */ |
sahilmgandhi | 18:6a4db94011d3 | 59 | #define EP6 6 /*!< Endpoint 6 */ |
sahilmgandhi | 18:6a4db94011d3 | 60 | #define EP7 7 /*!< Endpoint 7 */ |
sahilmgandhi | 18:6a4db94011d3 | 61 | |
sahilmgandhi | 18:6a4db94011d3 | 62 | |
sahilmgandhi | 18:6a4db94011d3 | 63 | /*!<USB Request Type */ |
sahilmgandhi | 18:6a4db94011d3 | 64 | #define REQ_STANDARD 0x00 |
sahilmgandhi | 18:6a4db94011d3 | 65 | #define REQ_CLASS 0x20 |
sahilmgandhi | 18:6a4db94011d3 | 66 | #define REQ_VENDOR 0x40 |
sahilmgandhi | 18:6a4db94011d3 | 67 | |
sahilmgandhi | 18:6a4db94011d3 | 68 | /*!<USB Standard Request */ |
sahilmgandhi | 18:6a4db94011d3 | 69 | #define USBD_GET_STATUS 0x00 |
sahilmgandhi | 18:6a4db94011d3 | 70 | #define USBD_CLEAR_FEATURE 0x01 |
sahilmgandhi | 18:6a4db94011d3 | 71 | #define USBD_SET_FEATURE 0x03 |
sahilmgandhi | 18:6a4db94011d3 | 72 | #define USBD_SET_ADDRESS 0x05 |
sahilmgandhi | 18:6a4db94011d3 | 73 | #define USBD_GET_DESCRIPTOR 0x06 |
sahilmgandhi | 18:6a4db94011d3 | 74 | #define USBD_SET_DESCRIPTOR 0x07 |
sahilmgandhi | 18:6a4db94011d3 | 75 | #define USBD_GET_CONFIGURATION 0x08 |
sahilmgandhi | 18:6a4db94011d3 | 76 | #define USBD_SET_CONFIGURATION 0x09 |
sahilmgandhi | 18:6a4db94011d3 | 77 | #define USBD_GET_INTERFACE 0x0A |
sahilmgandhi | 18:6a4db94011d3 | 78 | #define USBD_SET_INTERFACE 0x0B |
sahilmgandhi | 18:6a4db94011d3 | 79 | #define USBD_SYNC_FRAME 0x0C |
sahilmgandhi | 18:6a4db94011d3 | 80 | |
sahilmgandhi | 18:6a4db94011d3 | 81 | /*!<USB Descriptor Type */ |
sahilmgandhi | 18:6a4db94011d3 | 82 | #define DESC_DEVICE 0x01 |
sahilmgandhi | 18:6a4db94011d3 | 83 | #define DESC_CONFIG 0x02 |
sahilmgandhi | 18:6a4db94011d3 | 84 | #define DESC_STRING 0x03 |
sahilmgandhi | 18:6a4db94011d3 | 85 | #define DESC_INTERFACE 0x04 |
sahilmgandhi | 18:6a4db94011d3 | 86 | #define DESC_ENDPOINT 0x05 |
sahilmgandhi | 18:6a4db94011d3 | 87 | #define DESC_QUALIFIER 0x06 |
sahilmgandhi | 18:6a4db94011d3 | 88 | #define DESC_OTHERSPEED 0x07 |
sahilmgandhi | 18:6a4db94011d3 | 89 | |
sahilmgandhi | 18:6a4db94011d3 | 90 | /*!<USB HID Descriptor Type */ |
sahilmgandhi | 18:6a4db94011d3 | 91 | #define DESC_HID 0x21 |
sahilmgandhi | 18:6a4db94011d3 | 92 | #define DESC_HID_RPT 0x22 |
sahilmgandhi | 18:6a4db94011d3 | 93 | |
sahilmgandhi | 18:6a4db94011d3 | 94 | /*!<USB Descriptor Length */ |
sahilmgandhi | 18:6a4db94011d3 | 95 | #define LEN_DEVICE 18 |
sahilmgandhi | 18:6a4db94011d3 | 96 | #define LEN_CONFIG 9 |
sahilmgandhi | 18:6a4db94011d3 | 97 | #define LEN_INTERFACE 9 |
sahilmgandhi | 18:6a4db94011d3 | 98 | #define LEN_ENDPOINT 7 |
sahilmgandhi | 18:6a4db94011d3 | 99 | #define LEN_HID 9 |
sahilmgandhi | 18:6a4db94011d3 | 100 | #define LEN_CCID 0x36 |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | /*!<USB Endpoint Type */ |
sahilmgandhi | 18:6a4db94011d3 | 103 | #define EP_ISO 0x01 |
sahilmgandhi | 18:6a4db94011d3 | 104 | #define EP_BULK 0x02 |
sahilmgandhi | 18:6a4db94011d3 | 105 | #define EP_INT 0x03 |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | #define EP_INPUT 0x80 |
sahilmgandhi | 18:6a4db94011d3 | 108 | #define EP_OUTPUT 0x00 |
sahilmgandhi | 18:6a4db94011d3 | 109 | |
sahilmgandhi | 18:6a4db94011d3 | 110 | /*!<USB Feature Selector */ |
sahilmgandhi | 18:6a4db94011d3 | 111 | #define FEATURE_DEVICE_REMOTE_WAKEUP 0x01 |
sahilmgandhi | 18:6a4db94011d3 | 112 | #define FEATURE_ENDPOINT_HALT 0x00 |
sahilmgandhi | 18:6a4db94011d3 | 113 | |
sahilmgandhi | 18:6a4db94011d3 | 114 | /******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 115 | /* USB Specific Macros */ |
sahilmgandhi | 18:6a4db94011d3 | 116 | /******************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 117 | |
sahilmgandhi | 18:6a4db94011d3 | 118 | #define USBD_WAKEUP_EN USBD_INTEN_WKEN_Msk /*!< USB Wake-up Enable */ |
sahilmgandhi | 18:6a4db94011d3 | 119 | #define USBD_DRVSE0 USBD_SE0_SE0_Msk /*!< Drive SE0 */ |
sahilmgandhi | 18:6a4db94011d3 | 120 | |
sahilmgandhi | 18:6a4db94011d3 | 121 | #define USBD_DPPU_EN USBD_ATTR_DPPUEN_Msk /*!< USB D+ Pull-up Enable */ |
sahilmgandhi | 18:6a4db94011d3 | 122 | #define USBD_PWRDN USBD_ATTR_PWRDN_Msk /*!< PHY Turn-On */ |
sahilmgandhi | 18:6a4db94011d3 | 123 | #define USBD_PHY_EN USBD_ATTR_PHYEN_Msk /*!< PHY Enable */ |
sahilmgandhi | 18:6a4db94011d3 | 124 | #define USBD_USB_EN USBD_ATTR_USBEN_Msk /*!< USB Enable */ |
sahilmgandhi | 18:6a4db94011d3 | 125 | |
sahilmgandhi | 18:6a4db94011d3 | 126 | #define USBD_INT_BUS USBD_INTEN_BUSIEN_Msk /*!< USB Bus Event Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 127 | #define USBD_INT_USB USBD_INTEN_USBIEN_Msk /*!< USB Event Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 128 | #define USBD_INT_FLDET USBD_INTEN_VBDETIEN_Msk /*!< USB VBUS Detection Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 129 | #define USBD_INT_WAKEUP (USBD_INTEN_NEVWKIEN_Msk | USBD_INTEN_WKEN_Msk) /*!< USB No-Event-Wake-Up Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 130 | |
sahilmgandhi | 18:6a4db94011d3 | 131 | #define USBD_INTSTS_WAKEUP USBD_INTSTS_NEVWKIF_Msk /*!< USB No-Event-Wake-Up Interrupt Status */ |
sahilmgandhi | 18:6a4db94011d3 | 132 | #define USBD_INTSTS_FLDET USBD_INTSTS_VBDETIF_Msk /*!< USB Float Detect Interrupt Status */ |
sahilmgandhi | 18:6a4db94011d3 | 133 | #define USBD_INTSTS_BUS USBD_INTSTS_BUSIF_Msk /*!< USB Bus Event Interrupt Status */ |
sahilmgandhi | 18:6a4db94011d3 | 134 | #define USBD_INTSTS_USB USBD_INTSTS_USBIF_Msk /*!< USB Event Interrupt Status */ |
sahilmgandhi | 18:6a4db94011d3 | 135 | #define USBD_INTSTS_SETUP USBD_INTSTS_SETUP_Msk /*!< USB Setup Event */ |
sahilmgandhi | 18:6a4db94011d3 | 136 | #define USBD_INTSTS_EP0 USBD_INTSTS_EPEVT0_Msk /*!< USB Endpoint 0 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 137 | #define USBD_INTSTS_EP1 USBD_INTSTS_EPEVT1_Msk /*!< USB Endpoint 1 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 138 | #define USBD_INTSTS_EP2 USBD_INTSTS_EPEVT2_Msk /*!< USB Endpoint 2 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 139 | #define USBD_INTSTS_EP3 USBD_INTSTS_EPEVT3_Msk /*!< USB Endpoint 3 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 140 | #define USBD_INTSTS_EP4 USBD_INTSTS_EPEVT4_Msk /*!< USB Endpoint 4 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 141 | #define USBD_INTSTS_EP5 USBD_INTSTS_EPEVT5_Msk /*!< USB Endpoint 5 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 142 | #define USBD_INTSTS_EP6 USBD_INTSTS_EPEVT6_Msk /*!< USB Endpoint 6 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 143 | #define USBD_INTSTS_EP7 USBD_INTSTS_EPEVT7_Msk /*!< USB Endpoint 7 Event */ |
sahilmgandhi | 18:6a4db94011d3 | 144 | |
sahilmgandhi | 18:6a4db94011d3 | 145 | #define USBD_STATE_USBRST USBD_ATTR_USBRST_Msk /*!< USB Bus Reset */ |
sahilmgandhi | 18:6a4db94011d3 | 146 | #define USBD_STATE_SUSPEND USBD_ATTR_SUSPEND_Msk /*!< USB Bus Suspend */ |
sahilmgandhi | 18:6a4db94011d3 | 147 | #define USBD_STATE_RESUME USBD_ATTR_RESUME_Msk /*!< USB Bus Resume */ |
sahilmgandhi | 18:6a4db94011d3 | 148 | #define USBD_STATE_TIMEOUT USBD_ATTR_TOUT_Msk /*!< USB Bus Timeout */ |
sahilmgandhi | 18:6a4db94011d3 | 149 | |
sahilmgandhi | 18:6a4db94011d3 | 150 | #define USBD_CFGP_SSTALL USBD_CFGP_SSTALL_Msk /*!< Set Stall */ |
sahilmgandhi | 18:6a4db94011d3 | 151 | #define USBD_CFG_CSTALL USBD_CFG_CSTALL_Msk /*!< Clear Stall */ |
sahilmgandhi | 18:6a4db94011d3 | 152 | |
sahilmgandhi | 18:6a4db94011d3 | 153 | #define USBD_CFG_EPMODE_DISABLE (0ul << USBD_CFG_STATE_Pos)/*!< Endpoint Disable */ |
sahilmgandhi | 18:6a4db94011d3 | 154 | #define USBD_CFG_EPMODE_OUT (1ul << USBD_CFG_STATE_Pos)/*!< Out Endpoint */ |
sahilmgandhi | 18:6a4db94011d3 | 155 | #define USBD_CFG_EPMODE_IN (2ul << USBD_CFG_STATE_Pos)/*!< In Endpoint */ |
sahilmgandhi | 18:6a4db94011d3 | 156 | #define USBD_CFG_TYPE_ISO (1ul << USBD_CFG_ISOCH_Pos) /*!< Isochronous */ |
sahilmgandhi | 18:6a4db94011d3 | 157 | |
sahilmgandhi | 18:6a4db94011d3 | 158 | |
sahilmgandhi | 18:6a4db94011d3 | 159 | |
sahilmgandhi | 18:6a4db94011d3 | 160 | /*@}*/ /* end of group USBD_EXPORTED_CONSTANTS */ |
sahilmgandhi | 18:6a4db94011d3 | 161 | |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | /** @addtogroup USBD_EXPORTED_FUNCTIONS USBD Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 164 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 165 | */ |
sahilmgandhi | 18:6a4db94011d3 | 166 | |
sahilmgandhi | 18:6a4db94011d3 | 167 | /** |
sahilmgandhi | 18:6a4db94011d3 | 168 | * @brief Compare two input numbers and return maximum one. |
sahilmgandhi | 18:6a4db94011d3 | 169 | * |
sahilmgandhi | 18:6a4db94011d3 | 170 | * @param[in] a First number to be compared. |
sahilmgandhi | 18:6a4db94011d3 | 171 | * @param[in] b Second number to be compared. |
sahilmgandhi | 18:6a4db94011d3 | 172 | * |
sahilmgandhi | 18:6a4db94011d3 | 173 | * @return Maximum value between a and b. |
sahilmgandhi | 18:6a4db94011d3 | 174 | * |
sahilmgandhi | 18:6a4db94011d3 | 175 | * @details If a > b, then return a. Otherwise, return b. |
sahilmgandhi | 18:6a4db94011d3 | 176 | */ |
sahilmgandhi | 18:6a4db94011d3 | 177 | #define Maximum(a,b) ((a)>(b) ? (a) : (b)) |
sahilmgandhi | 18:6a4db94011d3 | 178 | |
sahilmgandhi | 18:6a4db94011d3 | 179 | |
sahilmgandhi | 18:6a4db94011d3 | 180 | /** |
sahilmgandhi | 18:6a4db94011d3 | 181 | * @brief Compare two input numbers and return minimum one |
sahilmgandhi | 18:6a4db94011d3 | 182 | * |
sahilmgandhi | 18:6a4db94011d3 | 183 | * @param[in] a First number to be compared |
sahilmgandhi | 18:6a4db94011d3 | 184 | * @param[in] b Second number to be compared |
sahilmgandhi | 18:6a4db94011d3 | 185 | * |
sahilmgandhi | 18:6a4db94011d3 | 186 | * @return Minimum value between a and b |
sahilmgandhi | 18:6a4db94011d3 | 187 | * |
sahilmgandhi | 18:6a4db94011d3 | 188 | * @details If a < b, then return a. Otherwise, return b. |
sahilmgandhi | 18:6a4db94011d3 | 189 | */ |
sahilmgandhi | 18:6a4db94011d3 | 190 | #define Minimum(a,b) ((a)<(b) ? (a) : (b)) |
sahilmgandhi | 18:6a4db94011d3 | 191 | |
sahilmgandhi | 18:6a4db94011d3 | 192 | |
sahilmgandhi | 18:6a4db94011d3 | 193 | /** |
sahilmgandhi | 18:6a4db94011d3 | 194 | * @brief Enable USB |
sahilmgandhi | 18:6a4db94011d3 | 195 | * |
sahilmgandhi | 18:6a4db94011d3 | 196 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 197 | * |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 199 | * |
sahilmgandhi | 18:6a4db94011d3 | 200 | * @details To set USB ATTR control register to enable USB and PHY. |
sahilmgandhi | 18:6a4db94011d3 | 201 | * |
sahilmgandhi | 18:6a4db94011d3 | 202 | */ |
sahilmgandhi | 18:6a4db94011d3 | 203 | #define USBD_ENABLE_USB() ((uint32_t)(USBD->ATTR |= (USBD_USB_EN|USBD_PHY_EN))) |
sahilmgandhi | 18:6a4db94011d3 | 204 | |
sahilmgandhi | 18:6a4db94011d3 | 205 | /** |
sahilmgandhi | 18:6a4db94011d3 | 206 | * @brief Disable USB |
sahilmgandhi | 18:6a4db94011d3 | 207 | * |
sahilmgandhi | 18:6a4db94011d3 | 208 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 209 | * |
sahilmgandhi | 18:6a4db94011d3 | 210 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 211 | * |
sahilmgandhi | 18:6a4db94011d3 | 212 | * @details To set USB ATTR control register to disable USB. |
sahilmgandhi | 18:6a4db94011d3 | 213 | * |
sahilmgandhi | 18:6a4db94011d3 | 214 | */ |
sahilmgandhi | 18:6a4db94011d3 | 215 | #define USBD_DISABLE_USB() ((uint32_t)(USBD->ATTR &= ~USBD_USB_EN)) |
sahilmgandhi | 18:6a4db94011d3 | 216 | |
sahilmgandhi | 18:6a4db94011d3 | 217 | /** |
sahilmgandhi | 18:6a4db94011d3 | 218 | * @brief Enable USB PHY |
sahilmgandhi | 18:6a4db94011d3 | 219 | * |
sahilmgandhi | 18:6a4db94011d3 | 220 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 221 | * |
sahilmgandhi | 18:6a4db94011d3 | 222 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 223 | * |
sahilmgandhi | 18:6a4db94011d3 | 224 | * @details To set USB ATTR control register to enable USB PHY. |
sahilmgandhi | 18:6a4db94011d3 | 225 | * |
sahilmgandhi | 18:6a4db94011d3 | 226 | */ |
sahilmgandhi | 18:6a4db94011d3 | 227 | #define USBD_ENABLE_PHY() ((uint32_t)(USBD->ATTR |= USBD_PHY_EN)) |
sahilmgandhi | 18:6a4db94011d3 | 228 | |
sahilmgandhi | 18:6a4db94011d3 | 229 | /** |
sahilmgandhi | 18:6a4db94011d3 | 230 | * @brief Disable USB PHY |
sahilmgandhi | 18:6a4db94011d3 | 231 | * |
sahilmgandhi | 18:6a4db94011d3 | 232 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 233 | * |
sahilmgandhi | 18:6a4db94011d3 | 234 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 235 | * |
sahilmgandhi | 18:6a4db94011d3 | 236 | * @details To set USB ATTR control register to disable USB PHY. |
sahilmgandhi | 18:6a4db94011d3 | 237 | * |
sahilmgandhi | 18:6a4db94011d3 | 238 | */ |
sahilmgandhi | 18:6a4db94011d3 | 239 | #define USBD_DISABLE_PHY() ((uint32_t)(USBD->ATTR &= ~USBD_PHY_EN)) |
sahilmgandhi | 18:6a4db94011d3 | 240 | |
sahilmgandhi | 18:6a4db94011d3 | 241 | /** |
sahilmgandhi | 18:6a4db94011d3 | 242 | * @brief Enable SE0. Force USB PHY transceiver to drive SE0. |
sahilmgandhi | 18:6a4db94011d3 | 243 | * |
sahilmgandhi | 18:6a4db94011d3 | 244 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 245 | * |
sahilmgandhi | 18:6a4db94011d3 | 246 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 247 | * |
sahilmgandhi | 18:6a4db94011d3 | 248 | * @details Set DRVSE0 bit of USB_DRVSE0 register to enable software-disconnect function. Force USB PHY transceiver to drive SE0 to bus. |
sahilmgandhi | 18:6a4db94011d3 | 249 | * |
sahilmgandhi | 18:6a4db94011d3 | 250 | */ |
sahilmgandhi | 18:6a4db94011d3 | 251 | #define USBD_SET_SE0() ((uint32_t)(USBD->SE0 |= USBD_DRVSE0)) |
sahilmgandhi | 18:6a4db94011d3 | 252 | |
sahilmgandhi | 18:6a4db94011d3 | 253 | /** |
sahilmgandhi | 18:6a4db94011d3 | 254 | * @brief Disable SE0 |
sahilmgandhi | 18:6a4db94011d3 | 255 | * |
sahilmgandhi | 18:6a4db94011d3 | 256 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 257 | * |
sahilmgandhi | 18:6a4db94011d3 | 258 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 259 | * |
sahilmgandhi | 18:6a4db94011d3 | 260 | * @details Clear DRVSE0 bit of USB_DRVSE0 register to disable software-disconnect function. |
sahilmgandhi | 18:6a4db94011d3 | 261 | * |
sahilmgandhi | 18:6a4db94011d3 | 262 | */ |
sahilmgandhi | 18:6a4db94011d3 | 263 | #define USBD_CLR_SE0() ((uint32_t)(USBD->SE0 &= ~USBD_DRVSE0)) |
sahilmgandhi | 18:6a4db94011d3 | 264 | |
sahilmgandhi | 18:6a4db94011d3 | 265 | /** |
sahilmgandhi | 18:6a4db94011d3 | 266 | * @brief Set USB device address |
sahilmgandhi | 18:6a4db94011d3 | 267 | * |
sahilmgandhi | 18:6a4db94011d3 | 268 | * @param[in] addr The USB device address. |
sahilmgandhi | 18:6a4db94011d3 | 269 | * |
sahilmgandhi | 18:6a4db94011d3 | 270 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 271 | * |
sahilmgandhi | 18:6a4db94011d3 | 272 | * @details Write USB device address to USB_FADDR register. |
sahilmgandhi | 18:6a4db94011d3 | 273 | * |
sahilmgandhi | 18:6a4db94011d3 | 274 | */ |
sahilmgandhi | 18:6a4db94011d3 | 275 | #define USBD_SET_ADDR(addr) (USBD->FADDR = (addr)) |
sahilmgandhi | 18:6a4db94011d3 | 276 | |
sahilmgandhi | 18:6a4db94011d3 | 277 | /** |
sahilmgandhi | 18:6a4db94011d3 | 278 | * @brief Get USB device address |
sahilmgandhi | 18:6a4db94011d3 | 279 | * |
sahilmgandhi | 18:6a4db94011d3 | 280 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 281 | * |
sahilmgandhi | 18:6a4db94011d3 | 282 | * @return USB device address |
sahilmgandhi | 18:6a4db94011d3 | 283 | * |
sahilmgandhi | 18:6a4db94011d3 | 284 | * @details Read USB_FADDR register to get USB device address. |
sahilmgandhi | 18:6a4db94011d3 | 285 | * |
sahilmgandhi | 18:6a4db94011d3 | 286 | */ |
sahilmgandhi | 18:6a4db94011d3 | 287 | #define USBD_GET_ADDR() ((uint32_t)(USBD->FADDR)) |
sahilmgandhi | 18:6a4db94011d3 | 288 | |
sahilmgandhi | 18:6a4db94011d3 | 289 | /** |
sahilmgandhi | 18:6a4db94011d3 | 290 | * @brief Enable USB interrupt function |
sahilmgandhi | 18:6a4db94011d3 | 291 | * |
sahilmgandhi | 18:6a4db94011d3 | 292 | * @param[in] intr The combination of the specified interrupt enable bits. |
sahilmgandhi | 18:6a4db94011d3 | 293 | * Each bit corresponds to a interrupt enable bit. |
sahilmgandhi | 18:6a4db94011d3 | 294 | * This parameter decides which interrupts will be enabled. |
sahilmgandhi | 18:6a4db94011d3 | 295 | * (USBD_INT_WAKEUP, USBD_INT_FLDET, USBD_INT_USB, USBD_INT_BUS) |
sahilmgandhi | 18:6a4db94011d3 | 296 | * |
sahilmgandhi | 18:6a4db94011d3 | 297 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 298 | * |
sahilmgandhi | 18:6a4db94011d3 | 299 | * @details Enable USB related interrupt functions specified by intr parameter. |
sahilmgandhi | 18:6a4db94011d3 | 300 | * |
sahilmgandhi | 18:6a4db94011d3 | 301 | */ |
sahilmgandhi | 18:6a4db94011d3 | 302 | #define USBD_ENABLE_INT(intr) (USBD->INTEN |= (intr)) |
sahilmgandhi | 18:6a4db94011d3 | 303 | |
sahilmgandhi | 18:6a4db94011d3 | 304 | /** |
sahilmgandhi | 18:6a4db94011d3 | 305 | * @brief Get interrupt status |
sahilmgandhi | 18:6a4db94011d3 | 306 | * |
sahilmgandhi | 18:6a4db94011d3 | 307 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 308 | * |
sahilmgandhi | 18:6a4db94011d3 | 309 | * @return The value of USB_INTSTS register |
sahilmgandhi | 18:6a4db94011d3 | 310 | * |
sahilmgandhi | 18:6a4db94011d3 | 311 | * @details Return all interrupt flags of USB_INTSTS register. |
sahilmgandhi | 18:6a4db94011d3 | 312 | * |
sahilmgandhi | 18:6a4db94011d3 | 313 | */ |
sahilmgandhi | 18:6a4db94011d3 | 314 | #define USBD_GET_INT_FLAG() ((uint32_t)(USBD->INTSTS)) |
sahilmgandhi | 18:6a4db94011d3 | 315 | |
sahilmgandhi | 18:6a4db94011d3 | 316 | /** |
sahilmgandhi | 18:6a4db94011d3 | 317 | * @brief Clear USB interrupt flag |
sahilmgandhi | 18:6a4db94011d3 | 318 | * |
sahilmgandhi | 18:6a4db94011d3 | 319 | * @param[in] flag The combination of the specified interrupt flags. |
sahilmgandhi | 18:6a4db94011d3 | 320 | * Each bit corresponds to a interrupt source. |
sahilmgandhi | 18:6a4db94011d3 | 321 | * This parameter decides which interrupt flags will be cleared. |
sahilmgandhi | 18:6a4db94011d3 | 322 | * (USBD_INTSTS_WAKEUP, USBD_INTSTS_FLDET, USBD_INTSTS_BUS, USBD_INTSTS_USB) |
sahilmgandhi | 18:6a4db94011d3 | 323 | * |
sahilmgandhi | 18:6a4db94011d3 | 324 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 325 | * |
sahilmgandhi | 18:6a4db94011d3 | 326 | * @details Clear USB related interrupt flags specified by flag parameter. |
sahilmgandhi | 18:6a4db94011d3 | 327 | * |
sahilmgandhi | 18:6a4db94011d3 | 328 | */ |
sahilmgandhi | 18:6a4db94011d3 | 329 | #define USBD_CLR_INT_FLAG(flag) (USBD->INTSTS = (flag)) |
sahilmgandhi | 18:6a4db94011d3 | 330 | |
sahilmgandhi | 18:6a4db94011d3 | 331 | /** |
sahilmgandhi | 18:6a4db94011d3 | 332 | * @brief Get endpoint status |
sahilmgandhi | 18:6a4db94011d3 | 333 | * |
sahilmgandhi | 18:6a4db94011d3 | 334 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 335 | * |
sahilmgandhi | 18:6a4db94011d3 | 336 | * @return The value of USB_EPSTS register. |
sahilmgandhi | 18:6a4db94011d3 | 337 | * |
sahilmgandhi | 18:6a4db94011d3 | 338 | * @details Return all endpoint status. |
sahilmgandhi | 18:6a4db94011d3 | 339 | * |
sahilmgandhi | 18:6a4db94011d3 | 340 | */ |
sahilmgandhi | 18:6a4db94011d3 | 341 | #define USBD_GET_EP_FLAG() ((uint32_t)(USBD->EPSTS)) |
sahilmgandhi | 18:6a4db94011d3 | 342 | |
sahilmgandhi | 18:6a4db94011d3 | 343 | /** |
sahilmgandhi | 18:6a4db94011d3 | 344 | * @brief Get USB bus state |
sahilmgandhi | 18:6a4db94011d3 | 345 | * |
sahilmgandhi | 18:6a4db94011d3 | 346 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 347 | * |
sahilmgandhi | 18:6a4db94011d3 | 348 | * @return The value of USB_ATTR[3:0]. |
sahilmgandhi | 18:6a4db94011d3 | 349 | * Bit 0 indicates USB bus reset status. |
sahilmgandhi | 18:6a4db94011d3 | 350 | * Bit 1 indicates USB bus suspend status. |
sahilmgandhi | 18:6a4db94011d3 | 351 | * Bit 2 indicates USB bus resume status. |
sahilmgandhi | 18:6a4db94011d3 | 352 | * Bit 3 indicates USB bus time-out status. |
sahilmgandhi | 18:6a4db94011d3 | 353 | * |
sahilmgandhi | 18:6a4db94011d3 | 354 | * @details Return USB_ATTR[3:0] for USB bus events. |
sahilmgandhi | 18:6a4db94011d3 | 355 | * |
sahilmgandhi | 18:6a4db94011d3 | 356 | */ |
sahilmgandhi | 18:6a4db94011d3 | 357 | #define USBD_GET_BUS_STATE() ((uint32_t)(USBD->ATTR & 0xf)) |
sahilmgandhi | 18:6a4db94011d3 | 358 | |
sahilmgandhi | 18:6a4db94011d3 | 359 | /** |
sahilmgandhi | 18:6a4db94011d3 | 360 | * @brief Check cable connection state |
sahilmgandhi | 18:6a4db94011d3 | 361 | * |
sahilmgandhi | 18:6a4db94011d3 | 362 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 363 | * |
sahilmgandhi | 18:6a4db94011d3 | 364 | * @retval 0 USB cable is not attached. |
sahilmgandhi | 18:6a4db94011d3 | 365 | * @retval 1 USB cable is attached. |
sahilmgandhi | 18:6a4db94011d3 | 366 | * |
sahilmgandhi | 18:6a4db94011d3 | 367 | * @details Check the connection state by FLDET bit of USB_FLDET register. |
sahilmgandhi | 18:6a4db94011d3 | 368 | * |
sahilmgandhi | 18:6a4db94011d3 | 369 | */ |
sahilmgandhi | 18:6a4db94011d3 | 370 | #define USBD_IS_ATTACHED() ((uint32_t)(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk)) |
sahilmgandhi | 18:6a4db94011d3 | 371 | |
sahilmgandhi | 18:6a4db94011d3 | 372 | /** |
sahilmgandhi | 18:6a4db94011d3 | 373 | * @brief Stop USB transaction of the specified endpoint ID |
sahilmgandhi | 18:6a4db94011d3 | 374 | * |
sahilmgandhi | 18:6a4db94011d3 | 375 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 376 | * |
sahilmgandhi | 18:6a4db94011d3 | 377 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 378 | * |
sahilmgandhi | 18:6a4db94011d3 | 379 | * @details Write 1 to CLRRDY bit of USB_CFGPx register to stop USB transaction of the specified endpoint ID. |
sahilmgandhi | 18:6a4db94011d3 | 380 | * |
sahilmgandhi | 18:6a4db94011d3 | 381 | */ |
sahilmgandhi | 18:6a4db94011d3 | 382 | #define USBD_STOP_TRANSACTION(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_CLRRDY_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 383 | |
sahilmgandhi | 18:6a4db94011d3 | 384 | /** |
sahilmgandhi | 18:6a4db94011d3 | 385 | * @brief Set USB DATA1 PID for the specified endpoint ID |
sahilmgandhi | 18:6a4db94011d3 | 386 | * |
sahilmgandhi | 18:6a4db94011d3 | 387 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 388 | * |
sahilmgandhi | 18:6a4db94011d3 | 389 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 390 | * |
sahilmgandhi | 18:6a4db94011d3 | 391 | * @details Set DSQ_SYNC bit of USB_CFGx register to specify the DATA1 PID for the following IN token transaction. |
sahilmgandhi | 18:6a4db94011d3 | 392 | * Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions. |
sahilmgandhi | 18:6a4db94011d3 | 393 | * |
sahilmgandhi | 18:6a4db94011d3 | 394 | */ |
sahilmgandhi | 18:6a4db94011d3 | 395 | #define USBD_SET_DATA1(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQSYNC_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 396 | |
sahilmgandhi | 18:6a4db94011d3 | 397 | /** |
sahilmgandhi | 18:6a4db94011d3 | 398 | * @brief Set USB DATA0 PID for the specified endpoint ID |
sahilmgandhi | 18:6a4db94011d3 | 399 | * |
sahilmgandhi | 18:6a4db94011d3 | 400 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 401 | * |
sahilmgandhi | 18:6a4db94011d3 | 402 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 403 | * |
sahilmgandhi | 18:6a4db94011d3 | 404 | * @details Clear DSQ_SYNC bit of USB_CFGx register to specify the DATA0 PID for the following IN token transaction. |
sahilmgandhi | 18:6a4db94011d3 | 405 | * Base on this setting, hardware will toggle PID between DATA0 and DATA1 automatically for IN token transactions. |
sahilmgandhi | 18:6a4db94011d3 | 406 | * |
sahilmgandhi | 18:6a4db94011d3 | 407 | */ |
sahilmgandhi | 18:6a4db94011d3 | 408 | #define USBD_SET_DATA0(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQSYNC_Msk)) |
sahilmgandhi | 18:6a4db94011d3 | 409 | |
sahilmgandhi | 18:6a4db94011d3 | 410 | /** |
sahilmgandhi | 18:6a4db94011d3 | 411 | * @brief Set USB payload size (IN data) |
sahilmgandhi | 18:6a4db94011d3 | 412 | * |
sahilmgandhi | 18:6a4db94011d3 | 413 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 414 | * |
sahilmgandhi | 18:6a4db94011d3 | 415 | * @param[in] size The transfer length. |
sahilmgandhi | 18:6a4db94011d3 | 416 | * |
sahilmgandhi | 18:6a4db94011d3 | 417 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 418 | * |
sahilmgandhi | 18:6a4db94011d3 | 419 | * @details This macro will write the transfer length to USB_MXPLDx register for IN data transaction. |
sahilmgandhi | 18:6a4db94011d3 | 420 | * |
sahilmgandhi | 18:6a4db94011d3 | 421 | */ |
sahilmgandhi | 18:6a4db94011d3 | 422 | #define USBD_SET_PAYLOAD_LEN(ep, size) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size)) |
sahilmgandhi | 18:6a4db94011d3 | 423 | |
sahilmgandhi | 18:6a4db94011d3 | 424 | /** |
sahilmgandhi | 18:6a4db94011d3 | 425 | * @brief Get USB payload size (OUT data) |
sahilmgandhi | 18:6a4db94011d3 | 426 | * |
sahilmgandhi | 18:6a4db94011d3 | 427 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 428 | * |
sahilmgandhi | 18:6a4db94011d3 | 429 | * @return The value of USB_MXPLDx register. |
sahilmgandhi | 18:6a4db94011d3 | 430 | * |
sahilmgandhi | 18:6a4db94011d3 | 431 | * @details Get the data length of OUT data transaction by reading USB_MXPLDx register. |
sahilmgandhi | 18:6a4db94011d3 | 432 | * |
sahilmgandhi | 18:6a4db94011d3 | 433 | */ |
sahilmgandhi | 18:6a4db94011d3 | 434 | #define USBD_GET_PAYLOAD_LEN(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4)))) |
sahilmgandhi | 18:6a4db94011d3 | 435 | |
sahilmgandhi | 18:6a4db94011d3 | 436 | /** |
sahilmgandhi | 18:6a4db94011d3 | 437 | * @brief Configure endpoint |
sahilmgandhi | 18:6a4db94011d3 | 438 | * |
sahilmgandhi | 18:6a4db94011d3 | 439 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 440 | * |
sahilmgandhi | 18:6a4db94011d3 | 441 | * @param[in] config The USB configuration. |
sahilmgandhi | 18:6a4db94011d3 | 442 | * |
sahilmgandhi | 18:6a4db94011d3 | 443 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 444 | * |
sahilmgandhi | 18:6a4db94011d3 | 445 | * @details This macro will write config parameter to USB_CFGx register of specified endpoint ID. |
sahilmgandhi | 18:6a4db94011d3 | 446 | * |
sahilmgandhi | 18:6a4db94011d3 | 447 | */ |
sahilmgandhi | 18:6a4db94011d3 | 448 | #define USBD_CONFIG_EP(ep, config) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config)) |
sahilmgandhi | 18:6a4db94011d3 | 449 | |
sahilmgandhi | 18:6a4db94011d3 | 450 | /** |
sahilmgandhi | 18:6a4db94011d3 | 451 | * @brief Set USB endpoint buffer |
sahilmgandhi | 18:6a4db94011d3 | 452 | * |
sahilmgandhi | 18:6a4db94011d3 | 453 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 454 | * |
sahilmgandhi | 18:6a4db94011d3 | 455 | * @param[in] offset The SRAM offset. |
sahilmgandhi | 18:6a4db94011d3 | 456 | * |
sahilmgandhi | 18:6a4db94011d3 | 457 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 458 | * |
sahilmgandhi | 18:6a4db94011d3 | 459 | * @details This macro will set the SRAM offset for the specified endpoint ID. |
sahilmgandhi | 18:6a4db94011d3 | 460 | * |
sahilmgandhi | 18:6a4db94011d3 | 461 | */ |
sahilmgandhi | 18:6a4db94011d3 | 462 | #define USBD_SET_EP_BUF_ADDR(ep, offset) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset)) |
sahilmgandhi | 18:6a4db94011d3 | 463 | |
sahilmgandhi | 18:6a4db94011d3 | 464 | /** |
sahilmgandhi | 18:6a4db94011d3 | 465 | * @brief Get the offset of the specified USB endpoint buffer |
sahilmgandhi | 18:6a4db94011d3 | 466 | * |
sahilmgandhi | 18:6a4db94011d3 | 467 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 468 | * |
sahilmgandhi | 18:6a4db94011d3 | 469 | * @return The offset of the specified endpoint buffer. |
sahilmgandhi | 18:6a4db94011d3 | 470 | * |
sahilmgandhi | 18:6a4db94011d3 | 471 | * @details This macro will return the SRAM offset of the specified endpoint ID. |
sahilmgandhi | 18:6a4db94011d3 | 472 | * |
sahilmgandhi | 18:6a4db94011d3 | 473 | */ |
sahilmgandhi | 18:6a4db94011d3 | 474 | #define USBD_GET_EP_BUF_ADDR(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4)))) |
sahilmgandhi | 18:6a4db94011d3 | 475 | |
sahilmgandhi | 18:6a4db94011d3 | 476 | /** |
sahilmgandhi | 18:6a4db94011d3 | 477 | * @brief Set USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 478 | * |
sahilmgandhi | 18:6a4db94011d3 | 479 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 480 | * |
sahilmgandhi | 18:6a4db94011d3 | 481 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 482 | * |
sahilmgandhi | 18:6a4db94011d3 | 483 | * @details Set USB endpoint stall state for the specified endpoint ID. Endpoint will respond STALL token automatically. |
sahilmgandhi | 18:6a4db94011d3 | 484 | * |
sahilmgandhi | 18:6a4db94011d3 | 485 | */ |
sahilmgandhi | 18:6a4db94011d3 | 486 | #define USBD_SET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_SSTALL_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 487 | |
sahilmgandhi | 18:6a4db94011d3 | 488 | /** |
sahilmgandhi | 18:6a4db94011d3 | 489 | * @brief Clear USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 490 | * |
sahilmgandhi | 18:6a4db94011d3 | 491 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 492 | * |
sahilmgandhi | 18:6a4db94011d3 | 493 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 494 | * |
sahilmgandhi | 18:6a4db94011d3 | 495 | * @details Clear USB endpoint stall state for the specified endpoint ID. Endpoint will respond ACK/NAK token. |
sahilmgandhi | 18:6a4db94011d3 | 496 | */ |
sahilmgandhi | 18:6a4db94011d3 | 497 | #define USBD_CLR_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) &= ~USBD_CFGP_SSTALL_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 498 | |
sahilmgandhi | 18:6a4db94011d3 | 499 | /** |
sahilmgandhi | 18:6a4db94011d3 | 500 | * @brief Get USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 501 | * |
sahilmgandhi | 18:6a4db94011d3 | 502 | * @param[in] ep The USB endpoint ID. M451 Series supports 8 hardware endpoint ID. This parameter could be 0 ~ 7. |
sahilmgandhi | 18:6a4db94011d3 | 503 | * |
sahilmgandhi | 18:6a4db94011d3 | 504 | * @retval 0 USB endpoint is not stalled. |
sahilmgandhi | 18:6a4db94011d3 | 505 | * @retval Others USB endpoint is stalled. |
sahilmgandhi | 18:6a4db94011d3 | 506 | * |
sahilmgandhi | 18:6a4db94011d3 | 507 | * @details Get USB endpoint stall state of the specified endpoint ID. |
sahilmgandhi | 18:6a4db94011d3 | 508 | * |
sahilmgandhi | 18:6a4db94011d3 | 509 | */ |
sahilmgandhi | 18:6a4db94011d3 | 510 | #define USBD_GET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) & USBD_CFGP_SSTALL_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 511 | |
sahilmgandhi | 18:6a4db94011d3 | 512 | /** |
sahilmgandhi | 18:6a4db94011d3 | 513 | * @brief To support byte access between USB SRAM and system SRAM |
sahilmgandhi | 18:6a4db94011d3 | 514 | * |
sahilmgandhi | 18:6a4db94011d3 | 515 | * @param[in] dest Destination pointer. |
sahilmgandhi | 18:6a4db94011d3 | 516 | * |
sahilmgandhi | 18:6a4db94011d3 | 517 | * @param[in] src Source pointer. |
sahilmgandhi | 18:6a4db94011d3 | 518 | * |
sahilmgandhi | 18:6a4db94011d3 | 519 | * @param[in] size Byte count. |
sahilmgandhi | 18:6a4db94011d3 | 520 | * |
sahilmgandhi | 18:6a4db94011d3 | 521 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 522 | * |
sahilmgandhi | 18:6a4db94011d3 | 523 | * @details This function will copy the number of data specified by size and src parameters to the address specified by dest parameter. |
sahilmgandhi | 18:6a4db94011d3 | 524 | * |
sahilmgandhi | 18:6a4db94011d3 | 525 | */ |
sahilmgandhi | 18:6a4db94011d3 | 526 | static __INLINE void USBD_MemCopy(uint8_t *dest, uint8_t *src, int32_t size) |
sahilmgandhi | 18:6a4db94011d3 | 527 | { |
sahilmgandhi | 18:6a4db94011d3 | 528 | while(size--) *dest++ = *src++; |
sahilmgandhi | 18:6a4db94011d3 | 529 | } |
sahilmgandhi | 18:6a4db94011d3 | 530 | |
sahilmgandhi | 18:6a4db94011d3 | 531 | |
sahilmgandhi | 18:6a4db94011d3 | 532 | /** |
sahilmgandhi | 18:6a4db94011d3 | 533 | * @brief Set USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 534 | * |
sahilmgandhi | 18:6a4db94011d3 | 535 | * @param[in] epnum USB endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 536 | * |
sahilmgandhi | 18:6a4db94011d3 | 537 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 538 | * |
sahilmgandhi | 18:6a4db94011d3 | 539 | * @details Set USB endpoint stall state. Endpoint will respond STALL token automatically. |
sahilmgandhi | 18:6a4db94011d3 | 540 | * |
sahilmgandhi | 18:6a4db94011d3 | 541 | */ |
sahilmgandhi | 18:6a4db94011d3 | 542 | static __INLINE void USBD_SetStall(uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 543 | { |
sahilmgandhi | 18:6a4db94011d3 | 544 | uint32_t u32CfgAddr; |
sahilmgandhi | 18:6a4db94011d3 | 545 | uint32_t u32Cfg; |
sahilmgandhi | 18:6a4db94011d3 | 546 | int i; |
sahilmgandhi | 18:6a4db94011d3 | 547 | |
sahilmgandhi | 18:6a4db94011d3 | 548 | for(i = 0; i < USBD_MAX_EP; i++) |
sahilmgandhi | 18:6a4db94011d3 | 549 | { |
sahilmgandhi | 18:6a4db94011d3 | 550 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */ |
sahilmgandhi | 18:6a4db94011d3 | 551 | u32Cfg = *((__IO uint32_t *)(u32CfgAddr)); |
sahilmgandhi | 18:6a4db94011d3 | 552 | |
sahilmgandhi | 18:6a4db94011d3 | 553 | if((u32Cfg & 0xf) == epnum) |
sahilmgandhi | 18:6a4db94011d3 | 554 | { |
sahilmgandhi | 18:6a4db94011d3 | 555 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */ |
sahilmgandhi | 18:6a4db94011d3 | 556 | u32Cfg = *((__IO uint32_t *)(u32CfgAddr)); |
sahilmgandhi | 18:6a4db94011d3 | 557 | |
sahilmgandhi | 18:6a4db94011d3 | 558 | *((__IO uint32_t *)(u32CfgAddr)) = (u32Cfg | USBD_CFGP_SSTALL); |
sahilmgandhi | 18:6a4db94011d3 | 559 | break; |
sahilmgandhi | 18:6a4db94011d3 | 560 | } |
sahilmgandhi | 18:6a4db94011d3 | 561 | } |
sahilmgandhi | 18:6a4db94011d3 | 562 | } |
sahilmgandhi | 18:6a4db94011d3 | 563 | |
sahilmgandhi | 18:6a4db94011d3 | 564 | /** |
sahilmgandhi | 18:6a4db94011d3 | 565 | * @brief Clear USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 566 | * |
sahilmgandhi | 18:6a4db94011d3 | 567 | * @param[in] epnum USB endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 568 | * |
sahilmgandhi | 18:6a4db94011d3 | 569 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 570 | * |
sahilmgandhi | 18:6a4db94011d3 | 571 | * @details Clear USB endpoint stall state. Endpoint will respond ACK/NAK token. |
sahilmgandhi | 18:6a4db94011d3 | 572 | */ |
sahilmgandhi | 18:6a4db94011d3 | 573 | static __INLINE void USBD_ClearStall(uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 574 | { |
sahilmgandhi | 18:6a4db94011d3 | 575 | uint32_t u32CfgAddr; |
sahilmgandhi | 18:6a4db94011d3 | 576 | uint32_t u32Cfg; |
sahilmgandhi | 18:6a4db94011d3 | 577 | int i; |
sahilmgandhi | 18:6a4db94011d3 | 578 | |
sahilmgandhi | 18:6a4db94011d3 | 579 | for(i = 0; i < USBD_MAX_EP; i++) |
sahilmgandhi | 18:6a4db94011d3 | 580 | { |
sahilmgandhi | 18:6a4db94011d3 | 581 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */ |
sahilmgandhi | 18:6a4db94011d3 | 582 | u32Cfg = *((__IO uint32_t *)(u32CfgAddr)); |
sahilmgandhi | 18:6a4db94011d3 | 583 | |
sahilmgandhi | 18:6a4db94011d3 | 584 | if((u32Cfg & 0xf) == epnum) |
sahilmgandhi | 18:6a4db94011d3 | 585 | { |
sahilmgandhi | 18:6a4db94011d3 | 586 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */ |
sahilmgandhi | 18:6a4db94011d3 | 587 | u32Cfg = *((__IO uint32_t *)(u32CfgAddr)); |
sahilmgandhi | 18:6a4db94011d3 | 588 | |
sahilmgandhi | 18:6a4db94011d3 | 589 | *((__IO uint32_t *)(u32CfgAddr)) = (u32Cfg & ~USBD_CFGP_SSTALL); |
sahilmgandhi | 18:6a4db94011d3 | 590 | break; |
sahilmgandhi | 18:6a4db94011d3 | 591 | } |
sahilmgandhi | 18:6a4db94011d3 | 592 | } |
sahilmgandhi | 18:6a4db94011d3 | 593 | } |
sahilmgandhi | 18:6a4db94011d3 | 594 | |
sahilmgandhi | 18:6a4db94011d3 | 595 | /** |
sahilmgandhi | 18:6a4db94011d3 | 596 | * @brief Get USB endpoint stall state |
sahilmgandhi | 18:6a4db94011d3 | 597 | * |
sahilmgandhi | 18:6a4db94011d3 | 598 | * @param[in] epnum USB endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 599 | * |
sahilmgandhi | 18:6a4db94011d3 | 600 | * @retval 0 USB endpoint is not stalled. |
sahilmgandhi | 18:6a4db94011d3 | 601 | * @retval Others USB endpoint is stalled. |
sahilmgandhi | 18:6a4db94011d3 | 602 | * |
sahilmgandhi | 18:6a4db94011d3 | 603 | * @details Get USB endpoint stall state. |
sahilmgandhi | 18:6a4db94011d3 | 604 | * |
sahilmgandhi | 18:6a4db94011d3 | 605 | */ |
sahilmgandhi | 18:6a4db94011d3 | 606 | static __INLINE uint32_t USBD_GetStall(uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 607 | { |
sahilmgandhi | 18:6a4db94011d3 | 608 | uint32_t u32CfgAddr; |
sahilmgandhi | 18:6a4db94011d3 | 609 | uint32_t u32Cfg; |
sahilmgandhi | 18:6a4db94011d3 | 610 | int i; |
sahilmgandhi | 18:6a4db94011d3 | 611 | |
sahilmgandhi | 18:6a4db94011d3 | 612 | for(i = 0; i < USBD_MAX_EP; i++) |
sahilmgandhi | 18:6a4db94011d3 | 613 | { |
sahilmgandhi | 18:6a4db94011d3 | 614 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFG; /* USBD_CFG0 */ |
sahilmgandhi | 18:6a4db94011d3 | 615 | u32Cfg = *((__IO uint32_t *)(u32CfgAddr)); |
sahilmgandhi | 18:6a4db94011d3 | 616 | |
sahilmgandhi | 18:6a4db94011d3 | 617 | if((u32Cfg & 0xf) == epnum) |
sahilmgandhi | 18:6a4db94011d3 | 618 | { |
sahilmgandhi | 18:6a4db94011d3 | 619 | u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&USBD->EP[0].CFGP; /* USBD_CFGP0 */ |
sahilmgandhi | 18:6a4db94011d3 | 620 | break; |
sahilmgandhi | 18:6a4db94011d3 | 621 | } |
sahilmgandhi | 18:6a4db94011d3 | 622 | } |
sahilmgandhi | 18:6a4db94011d3 | 623 | |
sahilmgandhi | 18:6a4db94011d3 | 624 | return ((*((__IO uint32_t *)(u32CfgAddr))) & USBD_CFGP_SSTALL); |
sahilmgandhi | 18:6a4db94011d3 | 625 | } |
sahilmgandhi | 18:6a4db94011d3 | 626 | |
sahilmgandhi | 18:6a4db94011d3 | 627 | |
sahilmgandhi | 18:6a4db94011d3 | 628 | extern volatile uint8_t g_usbd_RemoteWakeupEn; |
sahilmgandhi | 18:6a4db94011d3 | 629 | |
sahilmgandhi | 18:6a4db94011d3 | 630 | |
sahilmgandhi | 18:6a4db94011d3 | 631 | typedef void (*VENDOR_REQ)(void); /*!< Functional pointer type definition for Vendor class */ |
sahilmgandhi | 18:6a4db94011d3 | 632 | typedef void (*CLASS_REQ)(void); /*!< Functional pointer type declaration for USB class request callback handler */ |
sahilmgandhi | 18:6a4db94011d3 | 633 | typedef void (*SET_INTERFACE_REQ)(void); /*!< Functional pointer type declaration for USB set interface request callback handler */ |
sahilmgandhi | 18:6a4db94011d3 | 634 | typedef void (*SET_CONFIG_CB)(void); /*!< Functional pointer type declaration for USB set configuration request callback handler */ |
sahilmgandhi | 18:6a4db94011d3 | 635 | |
sahilmgandhi | 18:6a4db94011d3 | 636 | |
sahilmgandhi | 18:6a4db94011d3 | 637 | /*--------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 638 | void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface); |
sahilmgandhi | 18:6a4db94011d3 | 639 | void USBD_Start(void); |
sahilmgandhi | 18:6a4db94011d3 | 640 | void USBD_GetSetupPacket(uint8_t *buf); |
sahilmgandhi | 18:6a4db94011d3 | 641 | void USBD_ProcessSetupPacket(void); |
sahilmgandhi | 18:6a4db94011d3 | 642 | void USBD_StandardRequest(void); |
sahilmgandhi | 18:6a4db94011d3 | 643 | void USBD_PrepareCtrlIn(uint8_t *pu8Buf, uint32_t u32Size); |
sahilmgandhi | 18:6a4db94011d3 | 644 | void USBD_CtrlIn(void); |
sahilmgandhi | 18:6a4db94011d3 | 645 | void USBD_PrepareCtrlOut(uint8_t *pu8Buf, uint32_t u32Size); |
sahilmgandhi | 18:6a4db94011d3 | 646 | void USBD_CtrlOut(void); |
sahilmgandhi | 18:6a4db94011d3 | 647 | void USBD_SwReset(void); |
sahilmgandhi | 18:6a4db94011d3 | 648 | void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq); |
sahilmgandhi | 18:6a4db94011d3 | 649 | void USBD_SetConfigCallback(SET_CONFIG_CB pfnSetConfigCallback); |
sahilmgandhi | 18:6a4db94011d3 | 650 | void USBD_LockEpStall(uint32_t u32EpBitmap); |
sahilmgandhi | 18:6a4db94011d3 | 651 | |
sahilmgandhi | 18:6a4db94011d3 | 652 | /*@}*/ /* end of group USBD_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 653 | |
sahilmgandhi | 18:6a4db94011d3 | 654 | /*@}*/ /* end of group USBD_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 655 | |
sahilmgandhi | 18:6a4db94011d3 | 656 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 657 | |
sahilmgandhi | 18:6a4db94011d3 | 658 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 659 | } |
sahilmgandhi | 18:6a4db94011d3 | 660 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 661 | |
sahilmgandhi | 18:6a4db94011d3 | 662 | #endif //__USBD_H__ |
sahilmgandhi | 18:6a4db94011d3 | 663 | |
sahilmgandhi | 18:6a4db94011d3 | 664 | /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/ |