Commit 2ab59968 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

copying usb stuff from thedi's branch

parent e152aa5b
================ Revision history ============================================
3.20.6:
- No changes.
3.20.5:
- Fixed bug which could cause malfunctioning when prescaling core clock.
- Updated license terms.
- Fixed potential EP sram partitioning problems.
- Allow 64 and 32 byte EP0 max packetsize.
- Fixed bug in USBTIMER_Start(), added check on timeout value of 0.
- Fixed setting USB device state on USB reset from suspend.
- Added support for composite devices in the device stack.
- Made special provisions for passing USB-IF "Powered Suspend" test.
3.20.2:
- Increased robustness when plug/unplug-ing the USB cable rapidly.
- Changed implementation of usb string macro, wchar_t is no longer used.
GCC commandline options -fwide-exec-charset=UTF-16LE, -fshort-wchar and
-Wl,--no-wchar-size-warning are no longer needed.
Old version was used like this:
STATIC_CONST_STRING_DESC( iManufacturer, L"Energy Micro AS" );
New version is used like this:
STATIC_CONST_STRING_DESC( iManufacturer, 'E','n','e','r','g','y',' ', \
'M','i','c','r','o',' ','A','S' );
3.20.0:
- Documentation changes only.
3.0.3:
- Fixed compile time error when using USB stack energy saving on devices with
no endpoints in addition to EP0.
- Fixed bug when repeatedly unplugging/replugging a device USB cable and using
energy saving modes.
3.0.2:
- Bugfix: USBD_Init() may now be called when USB peripheral is in partial
powerdown mode.
- New function USBD_EpIsBusy( int epAddr ) added to API.
- Changed USBD_AbortTransfer() from USBD_AbortTransfer( uint8_t ) to
USBD_AbortTransfer( int ).
- Added configuration of which hw TIMER the stack will use.
3.0.1:
- USBD_Stop() now disables all USB related interrupts correctly.
- Minor documentation changes.
- Added more flexibility for taking advantage of energymodes in USB applications.
- Fixed bug in device stack partial powerdown procedure.
3.0.0:
- Updated to CMSIS_V3, "efm32lib" is now called "emlib"
- This library has been renamed from "efm32usb" to "usb"
- Prefixes changed from efm32_ to em_, to reflect changes in emlib
- Updated software license, see top of every file for details
2.4.1:
- Corrected USBC clock enable for header file updates
2.4.0:
- Added raw transfer API in the host USB stack for internal testing purposes.
- Added USB energy-saving modes in device protocol stack.
2.3.2:
- 19/12-2011: MSD updates
2.3.0:
- 29/11-2011: Initial version of host stack.
- 11/11-2011: Added Doxygen doc for host stack.
2.2.2:
- 18/10-2011: Fixed bug in USBDHAL_AbortEpOut() which in some scenarios would hang.
- 18/10-2011: Added function USBD_Stop(), which disables device stack operation.
2.2.1:
- 23/03-2011: Initial version.
- 15/04-2011: Added host device stack.
- 24/05-2011: First release candidate.
- 06/06-2011: Host driver port plug/unplug code improvements.
- 18/08-2011: Redesign of device abort transfer function.
================ Silicon Labs USB STACK =====================================
This directory, "usb", contains the Silicon Labs USB stack for the EFM32
series of microcontrollers.
Some design guidelines for this library is:
* Follow the guidelines established by ARM's and Silicon Labs's adaptation
of the CMSIS (see below) standard
* Be usable as a starting point for developing richer, more target specific
functionality (i.e. copy and modify further)
* Ability to be used as a standalone software component, used by other drivers
that should cover "the most common cases"
* Readability of the code and usability preferred before optimization for speed
and size or covering a particular "narrow" purpose
* As little "cross-dependency" between modules as possible, to enable users to
pick and choose what they want
================ About CMSIS ================================================
The USB APIs are built on top of EFM32 CMSIS headers and em_lib API'S, which
again are based on the Cortex Microcontroller Software Interface Standard.
These files are supplied together with this archive in separate folders.
The library requires basic C99-support. You might have to enable C99 support
in your compiler. Comments are in doxygen compatible format, and can be viewed
online from Silicon Labs's web site.
To download updates of this EFM32 CMSIS release, go to
http://www.silabs.com/
For more information about CMSIS see
http://www.onarm.com
================ File structure ==============================================
inc/ - header files
src/ - source files
================ License =====================================================
See the top of each file for SW license. Basically you are free to use the
Silicon Labs code for any project using Silicon Labs devices. Parts of the
CMSIS library is copyrighted by ARM Inc. See "License.doc" for ARM's CMSIS
license.
================ Software updates ============================================
Silicon Labs continually works to provide updated and improved example code,
header files and other software of use for our customers. Please check
http://www.silabs.com/support/pages/document-library.aspx?p=MCUs--32-bit&f=Low-Power%20MCUs--32-bit
for the latest releases. If you download and install the
Simplicity Studio application, you will be notified about updates when
available.
(C) Copyright Silicon Labs, 2014
END-USER LICENSE AGREEMENT
IMPORTANT: READ CAREFULLY
BEFORE AGREEING TO TERMS
THIS PRODUCT CONTAINS CERTAIN COMPUTER PROGRAMS AND OTHER THIRD PARTY
PROPRIETARY MATERIAL ("LICENSED PRODUCT"), THE USE OF WHICH IS SUBJECT TO THIS
END-USER LICENSE AGREEMENT. INDICATING YOUR AGREEMENT CONSTITUTES YOUR AND
(IF APPLICABLE) YOUR COMPANY'S ASSENT TO AND ACCEPTANCE OF THIS END-USER LICENSE
AGREEMENT (THE "LICENSE" OR "AGREEMENT"). IF YOU DO NOT AGREE WITH ALL OF THE
TERMS, YOU MUST NOT USE THIS PRODUCT. WRITTEN APPROVAL IS NOT A PREREQUISITE TO
THE VALIDITY OR ENFORCEABILITY OF THIS AGREEMENT, AND NO SOLICITATION OF SUCH
WRITTEN APPROVAL BY OR ON BEHALF OF SILICON LABORATORIES, INC. ("SILICON LABS")
SHALL BE CONSTRUED AS AN INFERENCE TO THE CONTRARY. IF THESE TERMS ARE
CONSIDERED AN OFFER BY SILICON LABS, ACCEPTANCE IS EXPRESSLY LIMITED TO THESE
TERMS.
LICENSE AND WARRANTY: The Licensed Product and the embedded Software which is
made the subject of this License is either the property of SILICON LABS or a
third party from whom SILICON LABS has the authorization to distribute to you
subject to the terms of this Agreement. This Licensed Product is protected by
state, federal, and international copyright law. Although SILICON LABS continues
to own the Licensed Product and the right to distribute the embedded third party
Software, you will have certain rights to use the Licensed Product and the
embedded Software after your acceptance of this License. Except as may be
modified by a license addendum which accompanies this License, your rights and
obligations with respect to the use of this Product and the embedded software
are as follows:
1. AS APPROPRIATE WITH RESPECT TO THE LICENSED PRODUCT, YOU MAY: Use, copy,
distribute and make derivative works of the Software for any purpose,
including commercial applications, subject to the following restrictions:
(i) The origin of this software must not be misrepresented; (ii) you must
not claim that you wrote the original software; (iii) altered source
versions must be plainly marked as such, and must not be misrepresented as
being the original software; and (iv) any notices contained in the Software
may not be removed or altered, including notices in source code versions.
2. YOU MAY NOT: (A) Sublicense, assign, rent or lease any portion of the
Licensed Product or the embedded Software; or (B) Remove any product
identification, copyright or other notices that appear on the Licensed
Product or embedded Software.
3. Limited Use: Use of any of the Software is strictly limited to use in
systems containing one or more SILICON LABS products when the Software is
enabled to be functional. Any unauthorized use is expressly prohibited and
will constitute a breach of this Agreement.
4. Warranty: SILICON LABS does not warrant that the Licensed Product or
embedded Software will meet your requirements or that operation of the
Licensed Product will be uninterrupted or that the embedded Software will be
error-free. You agree that the Licensed Product is provided "AS IS" and
that SILICON LABS makes no warranty as to the Licensed Product or embedded
Software. SILICON LABS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT, RELATED TO THE
SOFTWARE, ITS USE OR ANY INABILITY TO USE IT, THE RESULTS OF ITS USE AND
THIS AGREEMENT.
YOU MAY HAVE OTHER RIGHTS, WHICH VARY FROM STATE TO STATE.
5. Disclaimer of Damages: IN NO EVENT WILL SILICON LABS BE LIABLE TO YOU FOR
ANY SPECIAL, CONSEQUENTIAL, INDIRECT, OR SIMILAR DAMAGES, INCLUDING ANY LOST
PROFITS OR LOST DATA ARISING OUT OF THE USE OR INABILITY TO USE THE LICENSED
PRODUCT EVEN IF SILICON LABS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
SOME STATES DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY FOR
INCIDENTAL OR CONSEQUENTIAL DAMAGES. SO THE ABOVE LIMITATION OR EXCLUSION
MAY NOT APPLY TO YOU.
IN NO CASE SHALL SILICON LABS' LIABILITY EXCEED THE PURCHASE PRICE FOR THE
LICENSED PRODUCT. The disclaimers and limitations set forth above will
apply regardless of whether you accept the Licensed Software.
6. Term and Termination: The term of this Agreement and the License granted
herein shall begin upon use of the Licensed Product and continue in
perpetuity unless you breach any of the obligations set out under this
Agreement. Upon your breach of this Agreement by you, the license granted
hereunder shall terminate immediately and you shall cease all use of the
Licensed Products and return same as well as any copies of the Licensed
Product and/or embedded Software to SILICON LABS immediately. Termination
of this License upon your breach is only one remedy available to SILICON
LABS. In addition to termination of this Agreement upon your breach,
SILICON LABS shall be entitled to seek any and all other available remedies,
at law or at equity, arising from your breach.
7. Export: You shall comply with all applicable federal, provincial, state and
local laws, regulations and ordinances including but not limited to
applicable U.S. Export Administration Laws and Regulations. You shall not
export or re-export, or allow the export or re-export of the Licensed
Product, any component of the Licensed Product, or any copy of the embedded
Software in violation of any such restrictions, laws or regulations, or to
Cuba, Libya, North Korea, Iran, Iraq, or Rwanda or to any Group D:1 or E:2
country (or any national of such country) specified in the then current
Supplement No. 1 to Part 740, or, in violation of the embargo provisions in
Part 746, of the U.S. Export Administration Regulations (or any successor
regulations or supplement), except in compliance with and with all licenses
and approvals required under applicable export laws and regulations,
including without limitation, those of the U.S. Department of Commerce.
8. General: This Agreement will be governed by the laws of the State of Texas
and any applicable federal laws or regulations. The waiver by either Party
of any default or breach of this Agreement shall not constitute a waiver of
any other or subsequent default or breach. This Agreement constitutes the
complete and exclusive statement of the mutual understanding between you and
SILICON LABS with respect to this subject matter herein. This Agreement may
only be modified by a written addendum, which has been signed by both you
and SILICON LABS. Should you have any questions concerning this Agreement,
or if you desire to contact SILICON LABS for any reason, please write:
Silicon Laboratories, Inc.
400 West Cesar Chavez
Austin, Texas 78701, U.S.A.
This diff is collapsed.
/***************************************************************************//**
* @file em_usbd.h
* @brief USB protocol stack library API for EFM32.
* @version 3.20.6
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __EM_USBD_H
#define __EM_USBD_H
#include "em_device.h"
#if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
#include "em_usb.h"
#if defined( USB_DEVICE )
#ifdef __cplusplus
extern "C" {
#endif
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
#if defined( DEBUG_USB_API )
#define DEBUG_TRACE_ABORT( x ) \
{ \
if ( x == USB_STATUS_EP_STALLED ) \
{ DEBUG_USB_API_PUTS( "\nEP cb(), EP stalled" ); } \
else if ( x == USB_STATUS_EP_ABORTED ) \
{ DEBUG_USB_API_PUTS( "\nEP cb(), EP aborted" ); } \
else if ( x == USB_STATUS_DEVICE_UNCONFIGURED ) \
{ DEBUG_USB_API_PUTS( "\nEP cb(), device unconfigured" ); } \
else if ( x == USB_STATUS_DEVICE_SUSPENDED ) \
{ DEBUG_USB_API_PUTS( "\nEP cb(), device suspended" ); } \
else /* ( x == USB_STATUS_DEVICE_RESET ) */ \
{ DEBUG_USB_API_PUTS( "\nEP cb(), device reset" ); } \
}
#else
#define DEBUG_TRACE_ABORT( x )
#endif
extern USBD_Device_TypeDef *dev;
extern volatile bool USBD_poweredDown;
__STATIC_INLINE void USBD_ArmEp0( USBD_Ep_TypeDef *ep );
__STATIC_INLINE void USBD_ArmEpN( USBD_Ep_TypeDef *ep );
__STATIC_INLINE void USBD_AbortEp( USBD_Ep_TypeDef *ep );
void USBD_SetUsbState( USBD_State_TypeDef newState );
int USBDCH9_SetupCmd( USBD_Device_TypeDef *device );
void USBDEP_Ep0Handler( USBD_Device_TypeDef *device );
void USBDEP_EpHandler( uint8_t epAddr );
__STATIC_INLINE void USBD_ActivateAllEps( bool forceIdle )
{
int i;
for ( i = 1; i <= NUM_EP_USED; i++ )
{
USBDHAL_ActivateEp( &dev->ep[ i ], forceIdle );
}
}
__STATIC_INLINE void USBD_ArmEp( USBD_Ep_TypeDef *ep )
{
if ( ep->num == 0 )
{
USBD_ArmEp0( ep );
}
else
{
USBD_ArmEpN( ep );
}
}
__STATIC_INLINE void USBD_ArmEp0( USBD_Ep_TypeDef *ep )
{
if ( ep->in )
{
if ( ep->remaining == 0 ) /* Zero Length Packet? */
{
ep->zlp = 1;
}
USBDHAL_SetEp0InDmaPtr( ep->buf );
USBDHAL_StartEp0In( EFM32_MIN( ep->remaining, ep->packetSize ),
dev->ep0MpsCode );
}
else
{
USBDHAL_SetEp0OutDmaPtr( ep->buf );
USBDHAL_StartEp0Out( ep->packetSize, dev->ep0MpsCode );
}
}
__STATIC_INLINE void USBD_ArmEpN( USBD_Ep_TypeDef *ep )
{
if ( ep->in )
{
USBDHAL_StartEpIn( ep );
}
else
{
USBDHAL_StartEpOut( ep );
}
}
__STATIC_INLINE void USBD_DeactivateAllEps( USB_Status_TypeDef reason )
{
int i;
USBD_Ep_TypeDef *ep;
for ( i = 1; i <= NUM_EP_USED; i++ )
{
ep = &dev->ep[ i ];
if ( ep->state == D_EP_IDLE )
{
USBDHAL_DeactivateEp( ep );
}
}
USBDHAL_AbortAllTransfers( reason );
}
__STATIC_INLINE USBD_Ep_TypeDef *USBD_GetEpFromAddr( uint8_t epAddr )
{
int epIndex;
USBD_Ep_TypeDef *ep = NULL;
if ( epAddr & USB_SETUP_DIR_MASK )
{
epIndex = dev->inEpAddr2EpIndex[ epAddr & USB_EPNUM_MASK ];
}
else
{
epIndex = dev->outEpAddr2EpIndex[ epAddr & USB_EPNUM_MASK ];
}
if ( epIndex )
{
ep = &dev->ep[ epIndex ];
}
else if ( ( epAddr & USB_EPNUM_MASK ) == 0 )
{
ep = &dev->ep[ 0 ];
}
return ep;
}
__STATIC_INLINE void USBD_ReArmEp0( USBD_Ep_TypeDef *ep )
{
if ( ep->in )
{
USBDHAL_StartEp0In( EFM32_MIN( ep->remaining, ep->packetSize ),
dev->ep0MpsCode );
}
else
{
USBDHAL_StartEp0Out( ep->packetSize, dev->ep0MpsCode );
}
}
__STATIC_INLINE void USBD_AbortEp( USBD_Ep_TypeDef *ep )
{
if ( ep->state == D_EP_IDLE )
{
return;
}
if ( ep->in )
{
USBDHAL_AbortEpIn( ep );
}
else
{
USBDHAL_AbortEpOut( ep );
}
}
/** @endcond */
#ifdef __cplusplus
}
#endif
#endif /* defined( USB_DEVICE ) */
#endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
#endif /* __EM_USBD_H */
/***************************************************************************//**
* @file em_usbh.h
* @brief USB protocol stack library API for EFM32.
* @version 3.20.6
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __EM_USBH_H
#define __EM_USBH_H
#include "em_device.h"
#if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
#include "em_usb.h"
#if defined( USB_HOST )
#ifdef __cplusplus
extern "C" {
#endif
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
extern USBH_Hc_TypeDef hcs[];
extern int USBH_attachRetryCount;
extern const USBH_AttachTiming_TypeDef USBH_attachTiming[];
extern USBH_Init_TypeDef USBH_initData;
extern volatile USBH_PortState_TypeDef USBH_portStatus;
USB_Status_TypeDef USBH_CtlSendSetup( USBH_Ep_TypeDef *ep );
USB_Status_TypeDef USBH_CtlSendData( USBH_Ep_TypeDef *ep, uint16_t length );
USB_Status_TypeDef USBH_CtlReceiveData( USBH_Ep_TypeDef *ep, uint16_t length );
#if defined( USB_RAW_API )
int USBH_CtlRxRaw( uint8_t pid, USBH_Ep_TypeDef *ep, void *data, int byteCount );
int USBH_CtlTxRaw( uint8_t pid, USBH_Ep_TypeDef *ep, void *data, int byteCount );
#endif
void USBHEP_EpHandler( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result );
void USBHEP_CtrlEpHandler( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result );
void USBHEP_TransferDone( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result );
__STATIC_INLINE uint16_t USBH_GetFrameNum( void )
{
return USBHHAL_GetFrameNum();
}
__STATIC_INLINE bool USBH_FrameNumIsEven( void )
{
return ( USBHHAL_GetFrameNum() & 1 ) == 0;
}
/** @endcond */
#ifdef __cplusplus
}
#endif
#endif /* defined( USB_HOST ) */
#endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
#endif /* __EM_USBH_H */
This diff is collapsed.
/***************************************************************************//**
* @file em_usbtypes.h
* @brief USB protocol stack library, internal type definitions.
* @version 3.20.6
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __EM_USBTYPES_H
#define __EM_USBTYPES_H
#include "em_device.h"
#if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
#include "em_usb.h"
#if defined( USB_DEVICE ) || defined( USB_HOST )
#ifdef __cplusplus
extern "C" {
#endif
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/* Limits imposed by the USB peripheral */
#define NP_RX_QUE_DEPTH 8
#define HP_RX_QUE_DEPTH 8
#define MAX_XFER_LEN 524287L /* 2^19 - 1 bytes */
#define MAX_PACKETS_PR_XFER 1023 /* 2^10 - 1 packets */
#define MAX_NUM_TX_FIFOS 6 /* In addition to EP0 Tx FIFO */
#define MAX_NUM_IN_EPS 6 /* In addition to EP0 */
#define MAX_NUM_OUT_EPS 6 /* In addition to EP0 */
#define MIN_EP_FIFO_SIZE_INWORDS 16U /* Unit is words (32bit) */
#define MIN_EP_FIFO_SIZE_INBYTES 64U /* Unit is bytes (8bit) */
/* Limit imposed by the USB standard */
#define MAX_USB_EP_NUM 15
#if defined( USB_DEVICE )
/* Check power saving modes. */
#ifndef USB_PWRSAVE_MODE
/* Default powersave-mode is OFF. */
#define USB_PWRSAVE_MODE USB_PWRSAVE_MODE_OFF
#else
#if ( USB_PWRSAVE_MODE & \
~( USB_PWRSAVE_MODE_ONSUSPEND | USB_PWRSAVE_MODE_ONVBUSOFF | \
USB_PWRSAVE_MODE_ENTEREM2 ) )
#error "Illegal USB powersave mode."
#endif
#endif /* ifndef USB_PWRSAVE_MODE */
/* Check power saving low frequency clock selection. */
#ifndef USB_USBC_32kHz_CLK
/* Default clock source is LFXO. */
#define USB_USBC_32kHz_CLK USB_USBC_32kHz_CLK_LFXO
#else
#if ( ( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFXO ) && \
( USB_USBC_32kHz_CLK != USB_USBC_32kHz_CLK_LFRCO ) )
#error "Illegal USB 32kHz powersave clock selection."
#endif
#endif /* ifndef USB_USBC_32kHz_CLK */
#endif /* defined( USB_DEVICE ) */
#if defined( USB_HOST )
/* Check VBUS overcurrent definitions. */
#ifndef USB_VBUSOVRCUR_PORT
#define USB_VBUSOVRCUR_PORT gpioPortE
#define USB_VBUSOVRCUR_PIN 2
#define USB_VBUSOVRCUR_POLARITY USB_VBUSOVRCUR_POLARITY_LOW
#endif
#endif
/* Developer mode debugging macro's */
#if defined( DEBUG_USB_INT_LO )
#define DEBUG_USB_INT_LO_PUTS( s ) USB_PUTS( s )
#define DEBUG_USB_INT_LO_PUTCHAR( c ) USB_PUTCHAR( c )
#else
#define DEBUG_USB_INT_LO_PUTS( s )
#define DEBUG_USB_INT_LO_PUTCHAR( c )
#endif /* defined( DEBUG_USB_INT_LO ) */
#if defined( DEBUG_USB_INT_HI )
#define DEBUG_USB_INT_HI_PUTS( s ) USB_PUTS( s )
#define DEBUG_USB_INT_HI_PUTCHAR( c ) USB_PUTCHAR( c )
#else
#define DEBUG_USB_INT_HI_PUTS( s )
#define DEBUG_USB_INT_HI_PUTCHAR( c )
#endif /* defined( DEBUG_USB_INT_HI ) */
#if defined( USB_HOST )
#if defined( NUM_APP_TIMERS )
#define HOSTPORT_TIMER_INDEX (NUM_APP_TIMERS)
#else
#define HOSTPORT_TIMER_INDEX (0)
#endif
#define HOSTCH_TIMER_INDEX (HOSTPORT_TIMER_INDEX + 1 )
#endif
/* Macros for selecting a hardware timer. */
#define USB_TIMER0 0
#define USB_TIMER1 1
#define USB_TIMER2 2
#define USB_TIMER3 3
#if defined( USB_HOST )
#define HCS_NAK 0x01
#define HCS_STALL 0x02
#define HCS_XACT 0x04
#define HCS_TGLERR 0x08
#define HCS_BABBLE 0x10
#define HCS_TIMEOUT 0x20
#define HCS_COMPLETED 0x40
#define HCS_RETRY 0x80
#endif
#if defined( USB_DEVICE )
typedef enum
{
D_EP_IDLE = 0,
D_EP_TRANSMITTING = 1,
D_EP_RECEIVING = 2,
D_EP_STATUS = 3
} USBD_EpState_TypeDef;
typedef struct
{
bool in;
uint8_t zlp;
uint8_t num;
uint8_t addr;
uint8_t type;
uint8_t txFifoNum;
uint8_t *buf;
uint16_t packetSize;
uint16_t mask;
uint32_t remaining;
uint32_t xferred;
uint32_t hwXferSize;
uint32_t fifoSize;
USBD_EpState_TypeDef state;
USB_XferCompleteCb_TypeDef xferCompleteCb;
} USBD_Ep_TypeDef;
typedef struct
{
USB_Setup_TypeDef *setup;
USB_Setup_TypeDef setupPkt[3];
uint8_t configurationValue; /* Must be DWORD aligned */
bool remoteWakeupEnabled;
uint8_t numberOfStrings;
uint8_t numberOfInterfaces;
USBD_State_TypeDef state;
USBD_State_TypeDef savedState;
USBD_State_TypeDef lastState;
const USB_DeviceDescriptor_TypeDef *deviceDescriptor;
const USB_ConfigurationDescriptor_TypeDef *configDescriptor;
const void * const *stringDescriptors;
const USBD_Callbacks_TypeDef *callbacks;
USBD_Ep_TypeDef ep[ NUM_EP_USED + 1 ];
uint8_t inEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ];
uint8_t outEpAddr2EpIndex[ MAX_USB_EP_NUM + 1 ];
uint32_t ep0MpsCode;
} USBD_Device_TypeDef;
#endif /* defined( USB_DEVICE ) */
#if defined( USB_HOST )
typedef enum
{
H_PORT_DISCONNECTED = 0,
H_PORT_CONNECTED_DEBOUNCING = 1,
H_PORT_CONNECTED_RESETTING = 2,
H_PORT_CONNECTED = 3,
H_PORT_OVERCURRENT = 4
} USBH_PortState_TypeDef;
typedef struct
{
int debounceTime;
int resetTime;
} USBH_AttachTiming_TypeDef;
typedef struct
{
uint8_t *buf;
int errorCnt;
uint32_t remaining;
uint32_t xferred;
uint32_t hwXferSize;
uint8_t status;
bool idle;
USBH_Ep_TypeDef *ep;
} USBH_Hc_TypeDef;
#endif /* defined( USB_HOST ) */
/** @endcond */
#ifdef __cplusplus
}
#endif
#endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */
#endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
#endif /* __EM_USBTYPES_H */
This diff is collapsed.
This diff is collapsed.
/**************************************************************************//**
* @file em_usbdep.c
* @brief USB protocol stack library, USB device endpoint handlers.
* @version 3.20.6
******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include "em_device.h"
#if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
#include "em_usb.h"
#if defined( USB_DEVICE )
#include "em_usbtypes.h"
#include "em_usbhal.h"
#include "em_usbd.h"
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/*
* USBDEP_Ep0Handler() is called each time a packet has been transmitted
* or recieved on the default endpoint.
* A state machine navigate us through the phases of a control transfer
* according to "chapter 9" in the USB spec.
*/
void USBDEP_Ep0Handler( USBD_Device_TypeDef *device )
{
int status;
USBD_Ep_TypeDef *ep;
static bool statusIn;
static uint32_t xferred;
static USB_XferCompleteCb_TypeDef callback;
ep = &device->ep[ 0 ];
switch ( ep->state )
{
case D_EP_IDLE:
ep->remaining = 0;
ep->zlp = 0;
callback = NULL;
statusIn = false;
status = USBDCH9_SetupCmd( device );
if ( status == USB_STATUS_REQ_ERR )
{
ep->in = true;
USBDHAL_StallEp( ep ); /* Stall Ep0 IN */
ep->in = false; /* OUT for next SETUP */
USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */
USBDHAL_ReenableEp0Setup( device ); /* Prepare for next SETUP packet*/
}
else /* ( Status == USB_STATUS_OK ) */
{
if ( (ep->state == D_EP_RECEIVING) || (ep->state == D_EP_TRANSMITTING) )
{
callback = ep->xferCompleteCb;
}
if ( ep->state != D_EP_RECEIVING )
{
if ( ep->remaining )
{
/* Data will be sent to host, check if a ZLP must be appended */
if ( ( ep->remaining < device->setup->wLength ) &&
( ep->remaining % ep->packetSize == 0 ) )
{
ep->zlp = 1;
}
}
else
{
/* Prepare for next SETUP packet*/
USBDHAL_ReenableEp0Setup( device );
/* No data stage, a ZLP may have been sent. If not, send one */
xferred = 0;
if ( ep->zlp == 0 )
{
USBD_Write( 0, NULL, 0, NULL ); /* ACK to host */
ep->state = D_EP_STATUS;
}
else
{
ep->state = D_EP_IDLE;
ep->in = false; /* OUT for next SETUP */
}
}
}
}
break;
case D_EP_RECEIVING:
if ( ep->remaining )
{
/* There is more data to receive */
USBD_ReArmEp0( ep );
}
else
{
status = USB_STATUS_OK;
if ( callback != NULL )
{
status = callback( USB_STATUS_OK, ep->xferred, 0 );
callback = NULL;
}
if ( status != USB_STATUS_OK )
{
ep->in = true;
USBDHAL_StallEp( ep ); /* Stall Ep0 IN */
ep->in = false; /* OUT for next SETUP */
USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */
USBDHAL_ReenableEp0Setup( device ); /* Prepare for next SETUP pkt. */
ep->state = D_EP_IDLE;
}
else /* Everything OK, send a ZLP (ACK) to host */
{
USBDHAL_ReenableEp0Setup( device );/* Prepare for next SETUP packet*/
ep->state = D_EP_IDLE; /* USBD_Write() sets state back*/
/* to EP_TRANSMITTING */
USBD_Write( 0, NULL, 0, NULL );
ep->state = D_EP_STATUS;
}
}
break;
case D_EP_TRANSMITTING:
if ( ep->remaining )
{
/* There is more data to transmit */
USBD_ReArmEp0( ep );
}
else
{
/* All data transferred, is a ZLP packet needed ? */
if ( ep->zlp == 1 )
{
xferred = ep->xferred;
ep->state = D_EP_IDLE; /* USBD_Write() sets state back */
/* to EP_TRANSMITTING */
USBD_Write( 0, NULL, 0, NULL ); /* Send ZLP */
ep->zlp = 2;
}
else
{
if ( ep->zlp == 0 )
{
xferred = ep->xferred;
}
ep->state = D_EP_IDLE;
USBD_Read( 0, NULL, 0, NULL ); /* Get ZLP packet (ACK) from host */
statusIn = true;
ep->state = D_EP_STATUS;
}
}
break;
case D_EP_STATUS:
if ( statusIn )
{
USBDHAL_ReenableEp0Setup( device );
}
if ( callback != NULL )
{
callback( USB_STATUS_OK, xferred, 0 );
}
ep->state = D_EP_IDLE;
ep->in = false; /* OUT for next SETUP */
break;
default:
EFM_ASSERT( false );
break;
}
}
/*
* USBDEP_EpHandler() is called each time a packet has been transmitted
* or recieved on an endpoint other than the default endpoint.
*/
void USBDEP_EpHandler( uint8_t epAddr )
{
USB_XferCompleteCb_TypeDef callback;
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
if ( ( ep->state == D_EP_TRANSMITTING ) || ( ep->state == D_EP_RECEIVING ) )
{
ep->state = D_EP_IDLE;
if ( ep->xferCompleteCb )
{
callback = ep->xferCompleteCb;
ep->xferCompleteCb = NULL;
callback( USB_STATUS_OK, ep->xferred, ep->remaining );
}
}
else
{
EFM_ASSERT( false );
}
}
/** @endcond */
#endif /* defined( USB_DEVICE ) */
#endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/***************************************************************************//**
* @file em_usbhep.c
* @brief USB protocol stack library, USB host endpoint handlers.
* @version 3.20.6
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#include "em_device.h"
#if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
#include "em_usb.h"
#if defined( USB_HOST )
#include "em_usbtypes.h"
#include "em_usbhal.h"
#include "em_usbh.h"
/** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
/*
* USBHEP_CtrlEpHandler() is called each time a packet has been transmitted
* or recieved on host channels serving a device default endpoint (EP0).
* A state machine navigate us through the phases of a control transfer
* according to "chapter 9" in the USB spec.
*/
void USBHEP_CtrlEpHandler( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result )
{
uint8_t direction;
switch ( ep->state )
{
/* ------- Setup stage ------------------------------------------------ */
case H_EP_SETUP: /* SETUP packet sent successfully */
if ( result == USB_STATUS_OK )
{
direction = ep->setup.bmRequestType & USB_SETUP_DIR_MASK;
/* Check if there is a data stage */
if ( ep->setup.wLength != 0 )
{
if ( direction == USB_SETUP_DIR_D2H ) /* Data direction is IN */
{
USBH_CtlReceiveData( ep, ep->setup.wLength );
ep->state = H_EP_DATA_IN;
break;
}
else /* Data direction is OUT */
{
USBH_CtlSendData( ep, ep->setup.wLength );
ep->state = H_EP_DATA_OUT;
break;
}
}
USBH_CtlReceiveData( ep, 0 ); /* No data stage */
ep->state = H_EP_STATUS_IN; /* Get zero length in status packet */
break;
}
ep->setupErrCnt++;
/*
* After a halt condition is encountered or an error is detected by the
* host, a control endpoint is allowed to recover by accepting the next
* SETUP package. If the next Setup package is not accepted, a device
* reset will ultimately be needed.
*/
if ( ( ep->setupErrCnt == 1 ) && ( ep->timeout != 0 ) )
{
USBH_CtlSendSetup( ep ); /* Retry */
break;
}
USBHEP_TransferDone( ep, result );
break;
/* ------- Data IN stage ---------------------------------------------- */
case H_EP_DATA_IN: /* Data received */
if ( result == USB_STATUS_OK )
{
USBH_CtlSendData( ep, 0 ); /* Send zero length out status packet */
ep->state = H_EP_STATUS_OUT;
break;
}
USBHEP_TransferDone( ep, result );
break;
/* ------- Data OUT stage --------------------------------------------- */
case H_EP_DATA_OUT: /* Data sent */
if ( result == USB_STATUS_OK )
{
USBH_CtlReceiveData( ep, 0 ); /* Get zero length in status packet */
ep->state = H_EP_STATUS_IN;
break;
}
USBHEP_TransferDone( ep, result );
break;
/* ------- Status IN/OUT stage ---------------------------------------- */
case H_EP_STATUS_IN: /* Status packet received */
case H_EP_STATUS_OUT : /* Status packet sent */
USBHEP_TransferDone( ep, result );
break;
case H_EP_IDLE:
break;
}
}
/*
* USBHEP_EpHandler() is called each time a packet has been transmitted
* or recieved on a host channel serving a non-control device endpoint.
*/
void USBHEP_EpHandler( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result )
{
switch ( ep->state )
{
case H_EP_DATA_IN:
case H_EP_DATA_OUT:
USBHEP_TransferDone( ep, result );
break;
default:
case H_EP_IDLE:
break;
}
}
/*
* USBHEP_TransferDone() is called on transfer completion on all types of
* device endpoints.
*/
void USBHEP_TransferDone( USBH_Ep_TypeDef *ep, USB_Status_TypeDef result )
{
int hcnum;
USB_XferCompleteCb_TypeDef callback;
ep->xferCompleted = true;
ep->xferStatus = result;
ep->state = H_EP_IDLE;
if ( ep->type == USB_EPTYPE_CTRL )
{
hcnum = ep->setup.Direction == USB_SETUP_DIR_IN ? ep->hcIn : ep->hcOut;
if ( ep->timeout )
USBTIMER_Stop( ep->hcOut + HOSTCH_TIMER_INDEX );
ep->xferred = hcs[ hcnum ].xferred;
ep->remaining = hcs[ hcnum ].remaining;
hcs[ ep->hcIn ].idle = true;
hcs[ ep->hcOut ].idle = true;
if ( ep->setup.wLength == 0 )
{
ep->xferred = 0;
}
}
else
{
hcnum = ep->in ? ep->hcIn : ep->hcOut;
if ( ep->timeout || ep->type == USB_EPTYPE_INTR )
USBTIMER_Stop( hcnum + HOSTCH_TIMER_INDEX );
hcs[ hcnum ].idle = true;
ep->xferred = hcs[ hcnum ].xferred;
ep->remaining = hcs[ hcnum ].remaining;
}
if ( ep->xferCompleteCb )
{
callback = ep->xferCompleteCb;
ep->xferCompleteCb = NULL;
(callback)( result, ep->xferred, ep->remaining );
}
}
/** @endcond */
#endif /* defined( USB_HOST ) */
#endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
This diff is collapsed.
This diff is collapsed.
/***************************************************************************//**
* @file usbconfig.h
* @brief USB protocol stack library, application supplied configuration options.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifndef __USBCONFIG_H
#define __USBCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#define USB_DEVICE /* Compile stack for device mode. */
/****************************************************************************
** **
** Specify number of endpoints used (in addition to EP0). **
** **
*****************************************************************************/
#define NUM_EP_USED 3
/****************************************************************************
** **
** Specify number of application timers you need. **
** **
*****************************************************************************/
#define NUM_APP_TIMERS 1
#ifdef __cplusplus
}
#endif
#endif /* __USBCONFIG_H */
#include "usbdesc.h"
/* The serial port LINE CODING data structure, used to carry information */
/* about serial port baudrate, parity etc. between host and device. */
EFM32_PACK_START(1)
struct __attribute__ ((packed)) cdc_line_coding {
uint32_t dwDTERate; /** Baudrate */
uint8_t bCharFormat; /** Stop bits, 0=1 1=1.5 2=2 */
uint8_t bParityType; /** 0=None 1=Odd 2=Even 3=Mark 4=Space */
uint8_t bDataBits; /** 5, 6, 7, 8 or 16 */
uint8_t dummy; /** To ensure size is a multiple of 4 bytes.*/
};
EFM32_PACK_END()
/*** Variables ***/
/*
* The LineCoding variable must be 4-byte aligned as it is used as USB
* transmit and receive buffer
*/
EFM32_ALIGN(4)
EFM32_PACK_START(1)
static struct cdc_line_coding __attribute__ ((aligned(4))) line_coding =
{
4800, 2, 0, 8, 0
};
EFM32_PACK_END()
/**************************************************************************//**
* @brief
* Handle USB setup commands. Implements CDC class specific commands.
*
* @param[in] setup Pointer to the setup packet received.
*
* @return USB_STATUS_OK if command accepted.
* USB_STATUS_REQ_UNHANDLED when command is unknown, the USB device
* stack will handle the request.
*****************************************************************************/
int usbdesc_cb_setup(const USB_Setup_TypeDef *setup)
{
int r = USB_STATUS_REQ_UNHANDLED;
if ((setup->Type == USB_SETUP_TYPE_CLASS) &&
(setup->Recipient == USB_SETUP_RECIPIENT_INTERFACE)) {
switch (setup->bRequest)
{
case USB_CDC_GETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) &&
(setup->wLength == 7) &&
(setup->Direction == USB_SETUP_DIR_IN)) {
/* Send current settings to USB host. */
USBD_Write(0, (void*) &line_coding, 7, NULL);
r = USB_STATUS_OK;
}
break;
case USB_CDC_SETLINECODING:
/********************/
if ((setup->wValue == 0) &&
(setup->wIndex == 0) &&
(setup->wLength == 7) &&
(setup->Direction != USB_SETUP_DIR_IN)) {
/* Get new settings from USB host. */
USBD_Read(0, (void*) &line_coding, 7, NULL);
r = USB_STATUS_OK;
}
break;
case USB_CDC_SETCTRLLINESTATE:
/********************/
if ((setup->wIndex == 0) &&
(setup->wLength == 0)) {
/* Do nothing ( Non compliant behaviour !! ) */
r = USB_STATUS_OK;
}
break;
}
}
return r;
}
/***************************************************************************//**
* @file descriptors.h
* @brief USB descriptors for CDC Serial Port adapter example project.
* @version 3.20.5
*******************************************************************************
* @section License
* <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
*******************************************************************************
*
* This file is licensensed under the Silabs License Agreement. See the file
* "Silabs_License_Agreement.txt" for details. Before using this software for
* any purpose, you must agree to the terms of that agreement.
*
******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#include "em_usb.h"
/*=====================*/
/* Function prototypes */
/*=====================*/
int usbdesc_cb_setup(const USB_Setup_TypeDef *setup);
/*===============================*/
/* Define USB endpoint addresses */
/*===============================*/
#define USBDESC_EP_DATA_IN 0x01 /* Endpoint for USB data reception. */
#define USBDESC_EP_DATA_OUT 0x81 /* Endpoint for USB data transmission. */
#define USBDESC_EP_NOTIFY 0x82 /* The notification endpoint (not used). */
#define USBDESC_BULK_EP_SIZE USB_MAX_EP_SIZE /* This is the max. ep size. */
EFM32_ALIGN(4)
static const USB_DeviceDescriptor_TypeDef deviceDesc __attribute__ ((aligned(4)))=
{
.bLength = USB_DEVICE_DESCSIZE,
.bDescriptorType = USB_DEVICE_DESCRIPTOR,
.bcdUSB = 0x0200,
.bDeviceClass = USB_CLASS_CDC,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = USB_EP0_SIZE,
.idVendor = 0x10c4,
.idProduct = 0x00ff,
.bcdDevice = 0x0000,
.iManufacturer = 1,
.iProduct = 2,
.iSerialNumber = 0,
.bNumConfigurations = 1
};
#define CONFIG_DESCSIZE ( USB_CONFIG_DESCSIZE + \
(USB_INTERFACE_DESCSIZE * 2) + \
(USB_ENDPOINT_DESCSIZE * NUM_EP_USED) + \
USB_CDC_HEADER_FND_DESCSIZE + \
USB_CDC_CALLMNG_FND_DESCSIZE + \
USB_CDC_ACM_FND_DESCSIZE + \
5 )
EFM32_ALIGN(4)
static const uint8_t configDesc[] __attribute__ ((aligned(4)))=
{
/*** Configuration descriptor ***/
USB_CONFIG_DESCSIZE, /* bLength */
USB_CONFIG_DESCRIPTOR, /* bDescriptorType */
CONFIG_DESCSIZE, /* wTotalLength (LSB) */
USB_CONFIG_DESCSIZE>>8, /* wTotalLength (MSB) */
2, /* bNumInterfaces */
1, /* bConfigurationValue */
0, /* iConfiguration */
CONFIG_DESC_BM_RESERVED_D7 | /* bmAttrib: Self powered */
CONFIG_DESC_BM_SELFPOWERED,
CONFIG_DESC_MAXPOWER_mA( 100 ),/* bMaxPower: 100 mA */
/*** Communication Class Interface descriptor (interface no. 0) ***/
USB_INTERFACE_DESCSIZE, /* bLength */
USB_INTERFACE_DESCRIPTOR,/* bDescriptorType */
0, /* bInterfaceNumber */
0, /* bAlternateSetting */
1, /* bNumEndpoints */
USB_CLASS_CDC, /* bInterfaceClass */
USB_CLASS_CDC_ACM, /* bInterfaceSubClass */
0, /* bInterfaceProtocol */
0, /* iInterface */
/*** CDC Header Functional descriptor ***/
USB_CDC_HEADER_FND_DESCSIZE, /* bFunctionLength */
USB_CS_INTERFACE_DESCRIPTOR, /* bDescriptorType */
USB_CLASS_CDC_HFN, /* bDescriptorSubtype */
0x20, /* bcdCDC spec.no LSB */
0x01, /* bcdCDC spec.no MSB */
/*** CDC Call Management Functional descriptor ***/
USB_CDC_CALLMNG_FND_DESCSIZE, /* bFunctionLength */
USB_CS_INTERFACE_DESCRIPTOR, /* bDescriptorType */
USB_CLASS_CDC_CMNGFN, /* bDescriptorSubtype */
0, /* bmCapabilities */
1, /* bDataInterface */
/*** CDC Abstract Control Management Functional descriptor ***/
USB_CDC_ACM_FND_DESCSIZE, /* bFunctionLength */
USB_CS_INTERFACE_DESCRIPTOR, /* bDescriptorType */
USB_CLASS_CDC_ACMFN, /* bDescriptorSubtype */
0x02, /* bmCapabilities */
/* The capabilities that this configuration supports: */
/* D7..D4: RESERVED (Reset to zero) */
/* D3: 1 - Device supports the notification Network_Connection. */
/* D2: 1 - Device supports the request Send_Break */
/* D1: 1 - Device supports the request combination of Set_Line_Coding, */
/* Set_Control_Line_State, Get_Line_Coding, and the */
/* notification Serial_State. */
/* D0: 1 - Device supports the request combination of Set_Comm_Feature, */
/* Clear_Comm_Feature, and Get_Comm_Feature. */
/*** CDC Union Functional descriptor ***/
5, /* bFunctionLength */
USB_CS_INTERFACE_DESCRIPTOR, /* bDescriptorType */
USB_CLASS_CDC_UNIONFN, /* bDescriptorSubtype */
0, /* bControlInterface, itf. no. 0 */
1, /* bSubordinateInterface0, itf. no. 1 */
/*** CDC Notification endpoint descriptor ***/
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_NOTIFY, /* bEndpointAddress (IN) */
USB_EPTYPE_INTR, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0xFF, /* bInterval */
/*** Data Class Interface descriptor (interface no. 1) ***/
USB_INTERFACE_DESCSIZE, /* bLength */
USB_INTERFACE_DESCRIPTOR,/* bDescriptorType */
1, /* bInterfaceNumber */
0, /* bAlternateSetting */
2, /* bNumEndpoints */
USB_CLASS_CDC_DATA, /* bInterfaceClass */
0, /* bInterfaceSubClass */
0, /* bInterfaceProtocol */
0, /* iInterface */
/*** CDC Data interface endpoint descriptors ***/
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_IN, /* bEndpointAddress (IN) */
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0, /* bInterval */
USB_ENDPOINT_DESCSIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR,/* bDescriptorType */
USBDESC_EP_DATA_OUT, /* bEndpointAddress (OUT)*/
USB_EPTYPE_BULK, /* bmAttributes */
USBDESC_BULK_EP_SIZE, /* wMaxPacketSize (LSB) */
0, /* wMaxPacketSize (MSB) */
0 /* bInterval */
};
STATIC_CONST_STRING_DESC_LANGID( langID, 0x04, 0x09 );
STATIC_CONST_STRING_DESC( iManufacturer, 'S','i','l','i','c','o','n',' ','L', \
'a','b','o','r','a','t','o','r','i', \
'e','s',' ','I','n','c','.' );
STATIC_CONST_STRING_DESC( iProduct , 'E','F','M','3','2',' ','U','S','B', \
' ','C','D','C',' ','s','e','r','i', \
'a','l',' ','p','o','r','t',' ','d', \
'e','v','i','c','e' );
static const void * const strings[] =
{
&langID,
&iManufacturer,
&iProduct,
};
/* Endpoint buffer sizes */
/* 1 = single buffer, 2 = double buffering, 3 = triple buffering ... */
/* Use double buffering on the BULK endpoints. */
static const uint8_t bufferingMultiplier[ NUM_EP_USED + 1 ] = { 1, 1, 2, 2 };
static const USBD_Callbacks_TypeDef callbacks =
{
.usbReset = NULL,
.usbStateChange = NULL,
.setupCmd = usbdesc_cb_setup,
.isSelfPowered = NULL,
.sofInt = NULL
};
static const USBD_Init_TypeDef initstruct =
{
.deviceDescriptor = &deviceDesc,
.configDescriptor = configDesc,
.stringDescriptors = strings,
.numberOfStrings = sizeof(strings)/sizeof(void*),
.callbacks = &callbacks,
.bufferingMultiplier = bufferingMultiplier,
.reserved = 0
};
#ifdef __cplusplus
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment