Skip to content

Commit 57463ea

Browse files
committed
Merge pull request #5 from mbedmicro/master
Update my fork with original
2 parents 160d4bc + 376d6a7 commit 57463ea

File tree

119 files changed

+26570
-26823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+26570
-26823
lines changed

libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/inc/em_usb.h

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

0 commit comments

Comments
 (0)