/*
**********************************************************************
*name: IE_stm32_usbdev.h
*author: Samuel Igwe
*date: 08/27/2013
*description: IE_stm32_usbdev usb device header
**********************************************************************
*/
#ifndef IE_STM32_USB_DEV
#define IE_STM32_USB_DEV
/*
**********************************************************************
*usb control and user endpoint (interrupt)
**********************************************************************
*/
#define STMUSB_ENDP_CTRL_NUM 0
#define STMUSB_ENDP_CTRL_SIZE 8
#define STMUSB_ENDP_CTRL_MAX_SIZE 64
#define STMUSB_ENDP_USER_NUM 1
#define STMUSB_ENDP_USER_SIZE 8
#define STMUSB_ENDP_INT_INTERVAL 2
/*
**********************************************************************
*descriptor type
**********************************************************************
*/
#define USBDEV_DESCR_TYPE_DEVICE 1
#define USBDEV_DESCR_TYPE_CONFIGURATION 2
#define USBDEV_DESCR_TYPE_STRING 3
#define USBDEV_DESCR_TYPE_INTERFACE 4
#define USBDEV_DESCR_TYPE_ENDPOINT 5
#define USBDEV_DESCR_TYPE_DEV_QUALIFIER 6
#define USBDEV_DESCR_TYPE_OTHER_SPEED_CONFIG 7
#define USBDEV_DESCR_TYPE_INTERFACE_POWER 8
#define USBDEV_DESCR_TYPE_OTG 9
#define USBDEV_DESCR_TYPE_DEBUG 10
#define USBDEV_DESCR_TYPE_INTERFACE_ASSOC 11
/*
**********************************************************************
*usb class code
**********************************************************************
*/
#define USBDEV_CLASS_CODE_AUDIO 0x01
#define USBDEV_CLASS_CODE_COMM 0x02
#define USBDEV_CLASS_CODE_HID 0x03
#define USBDEV_CLASS_CODE_PHYSICAL 0x05
#define USBDEV_CLASS_CODE_IMAGE 0x06
#define USBDEV_CLASS_CODE_PRINTER 0x07
#define USBDEV_CLASS_CODE_STORAGE 0x08
#define USBDEV_CLASS_CODE_HUB 0x09
#define USBDEV_CLASS_CODE_DATA 0x0a
#define USBDEV_CLASS_CODE_CARD 0x0b
#define USBDEV_CLASS_CODE_SECURITY 0x0d
#define USBDEV_CLASS_CODE_VIDEO 0x0e
#define USBDEV_CLASS_CODE_PERSONAL 0x0f
#define USBDEV_CLASS_CODE_AUDIO_VIDEO 0x10
#define USBDEV_CLASS_CODE_DIAGNOSTIC 0xdc
#define USBDEV_CLASS_CODE_WIRELESS 0xe0
#define USBDEV_CLASS_CODE_APPLICATION 0xfe
#define USBDEV_CLASS_CODE_VENDOR_SPECIFIC 0xff
/*
**********************************************************************
*usb requests
**********************************************************************
*/
#define USBDEV_REQ_GET_STATUS 0
#define USBDEV_REQ_CLEAR_FEATURE 1
#define USBDEV_REQ_SET_FEATURE 3
#define USBDEV_REQ_SET_ADDRESS 5
#define USBDEV_REQ_GET_DESCRIPTOR 6
#define USBDEV_REQ_SET_DESCRIPTOR 7
#define USBDEV_REQ_GET_CONFIGURATION 8
#define USBDEV_REQ_SET_CONFIGURATION 9
#define USBDEV_REQ_GET_INTERFACE 10
#define USBDEV_REQ_SET_INTERFACE 11
#define USBDEV_REQ_SYNTH_FRAME 12
/*
**********************************************************************
*transfer type request related #defines
**********************************************************************
*/
#define USBDEV_CONFIG_DESC_ATTR_BUS (1 << 7)
#define USBDEV_CONFIG_DESC_ATTR_SELF (1 << 6)
#define USBDEV_CONFIG_DESC_ATTR_REMOTE_WAKE (1 << 5)
#define USBDEV_ENDP_DESC_ADDR_DIR_IN (1 << 7)
#define USBDEV_ENDP_DESC_ADDR_DIR_OUT (0 << 7)
#define USBDEV_ENDP_DESC_ATTR_CTRL 0
#define USBDEV_ENDP_DESC_ATTR_ISOCHRONOUS 1
#define USBDEV_ENDP_DESC_ATTR_BULK 2
#define USBDEV_ENDP_DESC_ATTR_INTERRRUPT 3
/*
**********************************************************************
*8 byte setup packet offsets
**********************************************************************
*/
#define USBDEV_SETUP_REQTYPE_OFFSET 0
#define USBDEV_SETUP_REQTYPE_DIR_H_TO_D (0 << 7)
#define USBDEV_SETUP_REQTYPE_DIR_D_TO_H (1 << 7)
#define USBDEV_SETUP_REQTYPE_DIR_MASK (1 << 7)
#define USBDEV_SETUP_REQTYPE_TYPE_STANDARD (0 << 5)
#define USBDEV_SETUP_REQTYPE_TYPE_CLASS (1 << 5)
#define USBDEV_SETUP_REQTYPE_TYPE_VENDOR (2 << 5)
#define USBDEV_SETUP_REQTYPE_TYPE_RESERVED (3 << 5)
#define USBDEV_SETUP_REQTYPE_TYPE_MASK (3 << 5)
#define USBDEV_SETUP_REQTYPE_DEST_DEVICE 0
#define USBDEV_SETUP_REQTYPE_DEST_INTERFACE 1
#define USBDEV_SETUP_REQTYPE_DEST_ENDPOINT 2
#define USBDEV_SETUP_REQTYPE_DEST_OTHER 3
#define USBDEV_SETUP_REQTYPE_DEST_MASK 0x1f
#define USBDEV_SETUP_REQUEST_OFFSET 1
#define USBDEV_SETUP_VALUE_OFFSET 2
#define USBDEV_SETUP_INDEX_OFFSET 4
#define USBDEV_SETUP_LENGTH_OFFSET 6
/*
**********************************************************************
*string descriptors
*offset 1 = manufacturers string
*offset 2 = product string
*offset 3 = serial number
*
*swStrDescr below is an array of 4 of: pointer
**********************************************************************
**********************************************************************
*string descriptor is unicode (16 bits)
*string descriptor is 2*strlen(ptrDescStr)+2 bytes
**********************************************************************
*/
static unsigned char ptrStr0[]={
(4), /*byte length of descriptor*/
USBDEV_DESCR_TYPE_STRING, /*string descriptor type*/
0x9, /*english code*/
0x4}; /*english subcode*/
static unsigned char ptrStr1[]={
((13 << 1)+2), /*byte length of descriptor*/
USBDEV_DESCR_TYPE_STRING, /*string descriptor type*/
'I',0,'g',0,'b',0,'o',0,' ',0,\
'E',0,'m',0,'b',0,'e',0,'d',0,'d',0,'e',0,'d',0};
static unsigned char ptrStr2[]={
((9 << 1)+2), /*byte length of descriptor*/
USBDEV_DESCR_TYPE_STRING, /*string descriptor type*/
'M',0,'y',0,' ',0,\
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0};
static unsigned char ptrStr3[]={
((4 << 1)+2), /*byte length of descriptor*/
USBDEV_DESCR_TYPE_STRING, /*string descriptor type*/
'1',0,'2',0,'3',0,'4',0};
static unsigned int swUsbDevDescr[]={(unsigned int)ptrStr0,\
(unsigned int)ptrStr1,\
(unsigned int)ptrStr2,\
(unsigned int)ptrStr3};
/*
**********************************************************************
*device descriptor
**********************************************************************
*/
static const char sbDevDescr[]={
18, /*byte length of descriptor*/
USBDEV_DESCR_TYPE_DEVICE, /*device descriptor type*/
0x10, /*bcd usb version 1.1 = word*/
0x01,
0, /*device class*/
0, /*device subclass*/
0, /*device protocol*/
STMUSB_ENDP_CTRL_SIZE,
/*max packet size*/
0xde, /*vendor id = word*/
0xc0,
0xed, /*device id = word*/
0xfe,
0x0, /*bcd device = word*/
0x1,
1, /*manufacturer descriptor string*/
2, /*product descriptor string*/
3, /*serial descriptor string*/
1}; /*number of configurations*/
/*
**********************************************************************
*configuration descriptor
**********************************************************************
*/
static const char sbConfDescr[]={
9, /*byte length of descriptor*/
USBDEV_DESCR_TYPE_CONFIGURATION, /*configuration descriptor type*/
(9+9+7+7), /*total lenght = word*/
0,
1, /*number of interfaces*/
1, /*configuration value id*/
0, /*configuration descriptor string*/
(USBDEV_CONFIG_DESC_ATTR_SELF | \
USBDEV_CONFIG_DESC_ATTR_BUS), /*bus attributes*/
250,
/*
**************************************************************
*interface descriptor
**************************************************************
*/
9, /*byte length of descriptor*/
USBDEV_DESCR_TYPE_INTERFACE, /*interface descriptor type*/
0, /*interface number - zero based*/
0, /*alternate setting*/
2, /*number of endpoints*/
USBDEV_CLASS_CODE_HID, /*human interface device*/
0, /*interface subclass*/
0, /*interface protocol*/
0, /*interface descriptor string*/
/*
**************************************************************
*endpoint descriptor - input
**************************************************************
*/
7, /*byte lenght of descriptor*/
USBDEV_DESCR_TYPE_ENDPOINT, /*endpoint descriptor type*/
(USBDEV_ENDP_DESC_ADDR_DIR_IN |\
STMUSB_ENDP_USER_NUM), /*endpoint in*/
USBDEV_ENDP_DESC_ATTR_INTERRRUPT, /*attributes*/
STMUSB_ENDP_USER_SIZE, /*packet length = word*/
0,
STMUSB_ENDP_INT_INTERVAL, /*interrupt interval*/
/*
**************************************************************
*endpoint descriptor - output
**************************************************************
*/
7, /*byte lenght of descriptor*/
USBDEV_DESCR_TYPE_ENDPOINT, /*endpoint descriptor type*/
(USBDEV_ENDP_DESC_ADDR_DIR_OUT |\
STMUSB_ENDP_USER_NUM), /*endpoint in*/
USBDEV_ENDP_DESC_ATTR_INTERRRUPT, /*attributes*/
STMUSB_ENDP_USER_SIZE, /*packet length = word*/
0,
STMUSB_ENDP_INT_INTERVAL}; /*interrupt interval*/
#endif