USB device stack - Added support for the logo/windows key to USB keyboard.

Dependents:   randomSearch

Fork of USBDevice by mbed official

Committer:
mbed_official
Date:
Thu Aug 13 15:46:06 2015 +0100
Revision:
59:2af474687369
Synchronized with git revision 376d6a73e345b728a788041adb166b08cd8d2b95

Full URL: https://github.com/mbedmicro/mbed/commit/376d6a73e345b728a788041adb166b08cd8d2b95/

Silicon Labs - Add support for USBDevice

Who changed what in which revision?

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