USB device stack
Dependents: USBMSD_step1 USBMSD_step1_5 picossd_step1_2cs
targets/TARGET_Silicon_Labs/inc/em_usbd.h@73:72808bd55ce2, 2021-09-15 (annotated)
- Committer:
- muraguchi
- Date:
- Wed Sep 15 16:31:51 2021 +0000
- Revision:
- 73:72808bd55ce2
- Parent:
- 71:53949e6131f6
AirioBase + 2 chip PicoSSD board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 71:53949e6131f6 | 1 | /***************************************************************************//** |
Kojto | 71:53949e6131f6 | 2 | * @file em_usbd.h |
Kojto | 71:53949e6131f6 | 3 | * @brief USB protocol stack library API for EFM32. |
Kojto | 71:53949e6131f6 | 4 | * @version 3.20.14 |
Kojto | 71:53949e6131f6 | 5 | ******************************************************************************* |
Kojto | 71:53949e6131f6 | 6 | * @section License |
Kojto | 71:53949e6131f6 | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
Kojto | 71:53949e6131f6 | 8 | ******************************************************************************* |
Kojto | 71:53949e6131f6 | 9 | * |
Kojto | 71:53949e6131f6 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Kojto | 71:53949e6131f6 | 11 | * you may not use this file except in compliance with the License. |
Kojto | 71:53949e6131f6 | 12 | * You may obtain a copy of the License at |
Kojto | 71:53949e6131f6 | 13 | * |
Kojto | 71:53949e6131f6 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
Kojto | 71:53949e6131f6 | 15 | * |
Kojto | 71:53949e6131f6 | 16 | * Unless required by applicable law or agreed to in writing, software |
Kojto | 71:53949e6131f6 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
Kojto | 71:53949e6131f6 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Kojto | 71:53949e6131f6 | 19 | * See the License for the specific language governing permissions and |
Kojto | 71:53949e6131f6 | 20 | * limitations under the License. |
Kojto | 71:53949e6131f6 | 21 | * |
Kojto | 71:53949e6131f6 | 22 | ******************************************************************************/ |
Kojto | 71:53949e6131f6 | 23 | |
Kojto | 71:53949e6131f6 | 24 | #ifndef __EM_USBD_H |
Kojto | 71:53949e6131f6 | 25 | #define __EM_USBD_H |
Kojto | 71:53949e6131f6 | 26 | |
Kojto | 71:53949e6131f6 | 27 | #include "em_device.h" |
Kojto | 71:53949e6131f6 | 28 | #if defined( USB_PRESENT ) && ( USB_COUNT == 1 ) |
Kojto | 71:53949e6131f6 | 29 | #include "em_usb.h" |
Kojto | 71:53949e6131f6 | 30 | #if defined( USB_DEVICE ) |
Kojto | 71:53949e6131f6 | 31 | |
Kojto | 71:53949e6131f6 | 32 | #ifdef __cplusplus |
Kojto | 71:53949e6131f6 | 33 | extern "C" { |
Kojto | 71:53949e6131f6 | 34 | #endif |
Kojto | 71:53949e6131f6 | 35 | |
Kojto | 71:53949e6131f6 | 36 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
Kojto | 71:53949e6131f6 | 37 | |
Kojto | 71:53949e6131f6 | 38 | #if defined( DEBUG_USB_API ) |
Kojto | 71:53949e6131f6 | 39 | #define DEBUG_TRACE_ABORT( x ) \ |
Kojto | 71:53949e6131f6 | 40 | { \ |
Kojto | 71:53949e6131f6 | 41 | if ( x == USB_STATUS_EP_STALLED ) \ |
Kojto | 71:53949e6131f6 | 42 | { DEBUG_USB_API_PUTS( "\nEP cb(), EP stalled" ); } \ |
Kojto | 71:53949e6131f6 | 43 | else if ( x == USB_STATUS_EP_ABORTED ) \ |
Kojto | 71:53949e6131f6 | 44 | { DEBUG_USB_API_PUTS( "\nEP cb(), EP aborted" ); } \ |
Kojto | 71:53949e6131f6 | 45 | else if ( x == USB_STATUS_DEVICE_UNCONFIGURED ) \ |
Kojto | 71:53949e6131f6 | 46 | { DEBUG_USB_API_PUTS( "\nEP cb(), device unconfigured" ); } \ |
Kojto | 71:53949e6131f6 | 47 | else if ( x == USB_STATUS_DEVICE_SUSPENDED ) \ |
Kojto | 71:53949e6131f6 | 48 | { DEBUG_USB_API_PUTS( "\nEP cb(), device suspended" ); } \ |
Kojto | 71:53949e6131f6 | 49 | else /* ( x == USB_STATUS_DEVICE_RESET ) */ \ |
Kojto | 71:53949e6131f6 | 50 | { DEBUG_USB_API_PUTS( "\nEP cb(), device reset" ); } \ |
Kojto | 71:53949e6131f6 | 51 | } |
Kojto | 71:53949e6131f6 | 52 | #else |
Kojto | 71:53949e6131f6 | 53 | #define DEBUG_TRACE_ABORT( x ) |
Kojto | 71:53949e6131f6 | 54 | #endif |
Kojto | 71:53949e6131f6 | 55 | |
Kojto | 71:53949e6131f6 | 56 | extern USBD_Device_TypeDef *dev; |
Kojto | 71:53949e6131f6 | 57 | extern volatile bool USBD_poweredDown; |
Kojto | 71:53949e6131f6 | 58 | |
Kojto | 71:53949e6131f6 | 59 | __STATIC_INLINE void USBD_ArmEp0( USBD_Ep_TypeDef *ep ); |
Kojto | 71:53949e6131f6 | 60 | __STATIC_INLINE void USBD_ArmEpN( USBD_Ep_TypeDef *ep ); |
Kojto | 71:53949e6131f6 | 61 | __STATIC_INLINE void USBD_AbortEp( USBD_Ep_TypeDef *ep ); |
Kojto | 71:53949e6131f6 | 62 | |
Kojto | 71:53949e6131f6 | 63 | void USBD_SetUsbState( USBD_State_TypeDef newState ); |
Kojto | 71:53949e6131f6 | 64 | |
Kojto | 71:53949e6131f6 | 65 | int USBDCH9_SetupCmd( USBD_Device_TypeDef *device ); |
Kojto | 71:53949e6131f6 | 66 | |
Kojto | 71:53949e6131f6 | 67 | void USBDEP_Ep0Handler( USBD_Device_TypeDef *device ); |
Kojto | 71:53949e6131f6 | 68 | void USBDEP_EpHandler( uint8_t epAddr ); |
Kojto | 71:53949e6131f6 | 69 | |
Kojto | 71:53949e6131f6 | 70 | __STATIC_INLINE void USBD_ActivateAllEps( bool forceIdle ) |
Kojto | 71:53949e6131f6 | 71 | { |
Kojto | 71:53949e6131f6 | 72 | int i; |
Kojto | 71:53949e6131f6 | 73 | |
Kojto | 71:53949e6131f6 | 74 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Kojto | 71:53949e6131f6 | 75 | { |
Kojto | 71:53949e6131f6 | 76 | USBDHAL_ActivateEp( &dev->ep[ i ], forceIdle ); |
Kojto | 71:53949e6131f6 | 77 | } |
Kojto | 71:53949e6131f6 | 78 | } |
Kojto | 71:53949e6131f6 | 79 | |
Kojto | 71:53949e6131f6 | 80 | __STATIC_INLINE void USBD_ArmEp( USBD_Ep_TypeDef *ep ) |
Kojto | 71:53949e6131f6 | 81 | { |
Kojto | 71:53949e6131f6 | 82 | if ( ep->num == 0 ) |
Kojto | 71:53949e6131f6 | 83 | { |
Kojto | 71:53949e6131f6 | 84 | USBD_ArmEp0( ep ); |
Kojto | 71:53949e6131f6 | 85 | } |
Kojto | 71:53949e6131f6 | 86 | else |
Kojto | 71:53949e6131f6 | 87 | { |
Kojto | 71:53949e6131f6 | 88 | USBD_ArmEpN( ep ); |
Kojto | 71:53949e6131f6 | 89 | } |
Kojto | 71:53949e6131f6 | 90 | } |
Kojto | 71:53949e6131f6 | 91 | |
Kojto | 71:53949e6131f6 | 92 | __STATIC_INLINE void USBD_ArmEp0( USBD_Ep_TypeDef *ep ) |
Kojto | 71:53949e6131f6 | 93 | { |
Kojto | 71:53949e6131f6 | 94 | if ( ep->in ) |
Kojto | 71:53949e6131f6 | 95 | { |
Kojto | 71:53949e6131f6 | 96 | if ( ep->remaining == 0 ) /* Zero Length Packet? */ |
Kojto | 71:53949e6131f6 | 97 | { |
Kojto | 71:53949e6131f6 | 98 | ep->zlp = 1; |
Kojto | 71:53949e6131f6 | 99 | } |
Kojto | 71:53949e6131f6 | 100 | |
Kojto | 71:53949e6131f6 | 101 | USBDHAL_SetEp0InDmaPtr( ep->buf ); |
Kojto | 71:53949e6131f6 | 102 | USBDHAL_StartEp0In( EFM32_MIN( ep->remaining, ep->packetSize ), |
Kojto | 71:53949e6131f6 | 103 | dev->ep0MpsCode ); |
Kojto | 71:53949e6131f6 | 104 | } |
Kojto | 71:53949e6131f6 | 105 | else |
Kojto | 71:53949e6131f6 | 106 | { |
Kojto | 71:53949e6131f6 | 107 | USBDHAL_SetEp0OutDmaPtr( ep->buf ); |
Kojto | 71:53949e6131f6 | 108 | USBDHAL_StartEp0Out( ep->packetSize, dev->ep0MpsCode ); |
Kojto | 71:53949e6131f6 | 109 | } |
Kojto | 71:53949e6131f6 | 110 | } |
Kojto | 71:53949e6131f6 | 111 | |
Kojto | 71:53949e6131f6 | 112 | __STATIC_INLINE void USBD_ArmEpN( USBD_Ep_TypeDef *ep ) |
Kojto | 71:53949e6131f6 | 113 | { |
Kojto | 71:53949e6131f6 | 114 | if ( ep->in ) |
Kojto | 71:53949e6131f6 | 115 | { |
Kojto | 71:53949e6131f6 | 116 | USBDHAL_StartEpIn( ep ); |
Kojto | 71:53949e6131f6 | 117 | } |
Kojto | 71:53949e6131f6 | 118 | else |
Kojto | 71:53949e6131f6 | 119 | { |
Kojto | 71:53949e6131f6 | 120 | USBDHAL_StartEpOut( ep ); |
Kojto | 71:53949e6131f6 | 121 | } |
Kojto | 71:53949e6131f6 | 122 | } |
Kojto | 71:53949e6131f6 | 123 | |
Kojto | 71:53949e6131f6 | 124 | __STATIC_INLINE void USBD_DeactivateAllEps( USB_Status_TypeDef reason ) |
Kojto | 71:53949e6131f6 | 125 | { |
Kojto | 71:53949e6131f6 | 126 | int i; |
Kojto | 71:53949e6131f6 | 127 | USBD_Ep_TypeDef *ep; |
Kojto | 71:53949e6131f6 | 128 | |
Kojto | 71:53949e6131f6 | 129 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Kojto | 71:53949e6131f6 | 130 | { |
Kojto | 71:53949e6131f6 | 131 | ep = &dev->ep[ i ]; |
Kojto | 71:53949e6131f6 | 132 | |
Kojto | 71:53949e6131f6 | 133 | if ( ep->state == D_EP_IDLE ) |
Kojto | 71:53949e6131f6 | 134 | { |
Kojto | 71:53949e6131f6 | 135 | USBDHAL_DeactivateEp( ep ); |
Kojto | 71:53949e6131f6 | 136 | } |
Kojto | 71:53949e6131f6 | 137 | } |
Kojto | 71:53949e6131f6 | 138 | |
Kojto | 71:53949e6131f6 | 139 | USBDHAL_AbortAllTransfers( reason ); |
Kojto | 71:53949e6131f6 | 140 | } |
Kojto | 71:53949e6131f6 | 141 | |
Kojto | 71:53949e6131f6 | 142 | __STATIC_INLINE USBD_Ep_TypeDef *USBD_GetEpFromAddr( uint8_t epAddr ) |
Kojto | 71:53949e6131f6 | 143 | { |
Kojto | 71:53949e6131f6 | 144 | int epIndex; |
Kojto | 71:53949e6131f6 | 145 | USBD_Ep_TypeDef *ep = NULL; |
Kojto | 71:53949e6131f6 | 146 | |
Kojto | 71:53949e6131f6 | 147 | if ( epAddr & USB_SETUP_DIR_MASK ) |
Kojto | 71:53949e6131f6 | 148 | { |
Kojto | 71:53949e6131f6 | 149 | epIndex = dev->inEpAddr2EpIndex[ epAddr & USB_EPNUM_MASK ]; |
Kojto | 71:53949e6131f6 | 150 | } |
Kojto | 71:53949e6131f6 | 151 | else |
Kojto | 71:53949e6131f6 | 152 | { |
Kojto | 71:53949e6131f6 | 153 | epIndex = dev->outEpAddr2EpIndex[ epAddr & USB_EPNUM_MASK ]; |
Kojto | 71:53949e6131f6 | 154 | } |
Kojto | 71:53949e6131f6 | 155 | |
Kojto | 71:53949e6131f6 | 156 | if ( epIndex ) |
Kojto | 71:53949e6131f6 | 157 | { |
Kojto | 71:53949e6131f6 | 158 | ep = &dev->ep[ epIndex ]; |
Kojto | 71:53949e6131f6 | 159 | } |
Kojto | 71:53949e6131f6 | 160 | else if ( ( epAddr & USB_EPNUM_MASK ) == 0 ) |
Kojto | 71:53949e6131f6 | 161 | { |
Kojto | 71:53949e6131f6 | 162 | ep = &dev->ep[ 0 ]; |
Kojto | 71:53949e6131f6 | 163 | } |
Kojto | 71:53949e6131f6 | 164 | |
Kojto | 71:53949e6131f6 | 165 | return ep; |
Kojto | 71:53949e6131f6 | 166 | } |
Kojto | 71:53949e6131f6 | 167 | |
Kojto | 71:53949e6131f6 | 168 | __STATIC_INLINE void USBD_ReArmEp0( USBD_Ep_TypeDef *ep ) |
Kojto | 71:53949e6131f6 | 169 | { |
Kojto | 71:53949e6131f6 | 170 | if ( ep->in ) |
Kojto | 71:53949e6131f6 | 171 | { |
Kojto | 71:53949e6131f6 | 172 | USBDHAL_StartEp0In( EFM32_MIN( ep->remaining, ep->packetSize ), |
Kojto | 71:53949e6131f6 | 173 | dev->ep0MpsCode ); |
Kojto | 71:53949e6131f6 | 174 | } |
Kojto | 71:53949e6131f6 | 175 | else |
Kojto | 71:53949e6131f6 | 176 | { |
Kojto | 71:53949e6131f6 | 177 | USBDHAL_StartEp0Out( ep->packetSize, dev->ep0MpsCode ); |
Kojto | 71:53949e6131f6 | 178 | } |
Kojto | 71:53949e6131f6 | 179 | } |
Kojto | 71:53949e6131f6 | 180 | |
Kojto | 71:53949e6131f6 | 181 | __STATIC_INLINE void USBD_AbortEp( USBD_Ep_TypeDef *ep ) |
Kojto | 71:53949e6131f6 | 182 | { |
Kojto | 71:53949e6131f6 | 183 | if ( ep->state == D_EP_IDLE ) |
Kojto | 71:53949e6131f6 | 184 | { |
Kojto | 71:53949e6131f6 | 185 | return; |
Kojto | 71:53949e6131f6 | 186 | } |
Kojto | 71:53949e6131f6 | 187 | |
Kojto | 71:53949e6131f6 | 188 | if ( ep->in ) |
Kojto | 71:53949e6131f6 | 189 | { |
Kojto | 71:53949e6131f6 | 190 | USBDHAL_AbortEpIn( ep ); |
Kojto | 71:53949e6131f6 | 191 | } |
Kojto | 71:53949e6131f6 | 192 | else |
Kojto | 71:53949e6131f6 | 193 | { |
Kojto | 71:53949e6131f6 | 194 | USBDHAL_AbortEpOut( ep ); |
Kojto | 71:53949e6131f6 | 195 | } |
Kojto | 71:53949e6131f6 | 196 | } |
Kojto | 71:53949e6131f6 | 197 | |
Kojto | 71:53949e6131f6 | 198 | /** @endcond */ |
Kojto | 71:53949e6131f6 | 199 | |
Kojto | 71:53949e6131f6 | 200 | #ifdef __cplusplus |
Kojto | 71:53949e6131f6 | 201 | } |
Kojto | 71:53949e6131f6 | 202 | #endif |
Kojto | 71:53949e6131f6 | 203 | |
Kojto | 71:53949e6131f6 | 204 | #endif /* defined( USB_DEVICE ) */ |
Kojto | 71:53949e6131f6 | 205 | #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */ |
Kojto | 71:53949e6131f6 | 206 | #endif /* __EM_USBD_H */ |