⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbproto.lst

📁 Comlete files for fullfile the slave USB function!
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE USBPROTO
OBJECT MODULE PLACED IN USBProto.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE USBProto.c DEBUG OBJECTEXTEND SRC(.\USBProto.SRC)

line level    source

   1          /*
   2          //*************************************************************************
   3          //
   4          //                  BASBA   P R O P R I E T A R Y
   5          //                     --  ALL RIGHTS RESERVED  --
   6          //
   7          // File Name:   USBProto.c
   8          // Purpose:             Handles the standard USB device requests
   9          // Author:              Shuming Yu
  10          // Created:             10 May 2003
  11          // Modified:
  12          // Revision:    1.0
  13          //
  14          //*************************************************************************
  15          */
  16          
  17          #include <stdio.h>
  18          #include <string.h>
  19          
  20          #include <reg51.h>                /* special function register declarations   */
  21          
  22          #include "d12hal.h"
  23          #include "cmds.h"
  24          #include "mainloop.h"
  25          #include "usbStruc.h"
  26          #include "USBProto.h"
  27          
  28          //#define NUM_ENDPOINTS 4
  29          #define NUM_ENDPOINTS   1
  30          
  31          unsigned char IDLE_TIME;
  32          /*
  33          //#define CONFIG_DESCRIPTOR_LENGTH    sizeof(USB_CONFIGURATION_DESCRIPTOR) \
  34          //                                                                      + sizeof(USB_INTERFACE_DESCRIPTOR) \
  35          //                                                                      + (NUM_ENDPOINTS * sizeof(USB_ENDPOINT_DESCRIPTOR))
  36          */
  37          extern CONTROL_XFER ControlData;
  38          //extern IO_REQUEST idata ioRequest;
  39          extern EPPFLAGS bEPPflags;
  40          //
  41          //           COPYRIGHT (c)   2003 BY BASBA USA.PPflags;
  42          extern unsigned char idata GenEpBuf[];  //Buffer which store data got from host
  43          
  44          UCHAR code REPORT_DESCRIPTOR[] = {
  45              0x06,0x00,0xFF, //Usage Page(vendor defined)
  46                  0x09,0x01, //Usage (I/O Device)
  47                  0xA1,0x01, //Collection (Application)
  48                  0x19,0x01, //Usage minimum (button1)
  49                  0x29,0x08, //Usage maximun (button8)
  50                  0x15,0x00, //Logic mininum (0)
  51                  0x25,0x01, //logic maximum (1)
  52                  0x75,0x01, //Report size (1)
  53                  0x95,0x08, //Report count (8)
  54                  0x81,0x02, //Input(Data,Var,Abs)
  55                  0x19,0x01, //Usage Minimum (LED1)
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 2   

  56                  0x29,0x08, //Usage Maximum (LED8)
  57                  0x91,0x02, //Output(Data,Var,Abs)
  58                  0xC0       //End of collection
  59          };
  60          
  61          struct CONFIG { USB_CONFIGURATION_DESCRIPTOR sConfig;
  62                          USB_INTERFACE_DESCRIPTOR sInterface;
  63                          USB_HID_DESCRIPTOR sHID;
  64                          USB_ENDPOINT_DESCRIPTOR sEndpoint;
  65          };
  66          
  67          #define CONFIG_DESCRIPTOR_LENGTH    sizeof(struct CONFIG)
  68          #define REPORT_DESC_LENGTH sizeof(REPORT_DESCRIPTOR)
  69          
  70          
  71          code USB_DEVICE_DESCRIPTOR DeviceDescr =
  72          {
  73                  sizeof(USB_DEVICE_DESCRIPTOR), //BYTE bLength,
  74              USB_DEVICE_DESCRIPTOR_TYPE, //BYTE bDescriptorType
  75              SWAP(0x0100), //WORD bcdUSB, USB Rev1.0
  76                  0x00, //Byte bDeviceClass
  77              0x00, //BYTE bDeviceSubClass
  78              0x00, //BYTE bDeviceProtocol
  79                  EP0_PACKET_SIZE,//BYTE bMaxPacketSize of 16
  80                  SWAP(0x4242), //WORD idVendor
  81                  SWAP(0x0100), //WORD idProduct
  82              SWAP(0x0100), //WORD bcdDevice
  83              0x01,  //BYTE iManufacturer name
  84              0x02,  //BYTE iProduct name
  85              0x00,  //BYTE iSerialNumber name
  86              0x01  //BYTE bNumConfigurations, number of configurations
  87          };
  88          
  89          /*
  90          code USB_CONFIGURATION_DESCRIPTOR  ConfigDescr =
  91          {
  92              sizeof(USB_CONFIGURATION_DESCRIPTOR), //BYTE bLength
  93              USB_CONFIGURATION_DESCRIPTOR_TYPE, //BYTE bDescriptorType //Assigned by USB
  94              SWAP(CONFIG_DESCRIPTOR_LENGTH), //WORD wTotalLength
  95              0x01, //BYTE bNumInterfaces
  96              0x01, //BYTE bConfigurationValue
  97              0x03, //BYTE iConfiguration
  98              0x80, //BYTE bmAttributes, Bus powered
  99              50, //BYTE MaxPower, 50x2=100mA
 100          };
 101          
 102          code USB_INTERFACE_DESCRIPTOR InterfaceDescr =
 103          {
 104              sizeof(USB_INTERFACE_DESCRIPTOR),//BYTE bLength
 105              USB_INTERFACE_DESCRIPTOR_TYPE,//BYTE bDescriptionType, assigned by USB
 106              0x00, //BYTE bInterfaceNumber
 107              0x00, //BYTE bAlternateSetting, no alternate setting
 108              0x01, //BYTE bNumEndpoints, HID uses endpoint 1
 109              0x03, //BYTE bInterfaceClass, HID Class - 0x03
 110              0x00, //BYTE bInterfaceSubClass
 111              0x00, //BYTE bInterfaceProtocol
 112              0x04  //BYTE iInterface, interface name
 113          };
 114          
 115          code USB_HID_DESCRIPTOR HIDDescr = 
 116          {
 117              sizeof(USB_HID_DESCRIPTOR), //BYTE bLength;
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 3   

 118              0x21, //BYTE bDescriptorType;
 119              0x0001, //WORD bcdHID;
 120              0x00, //BYTE bCountryCode, country localization = None;
 121              0x01, //BYTE bNumDescriptors, number of descriptor follow
 122              0x22, //BYTE bReportDescriptorType And it's a Report descriptor
 123              SWAP(REPORT_DESC_LENGTH) //WORD wItemLength, total length of report descriptor
 124          };
 125          
 126          code USB_ENDPOINT_DESCRIPTOR EP1_TXDescr =
 127          {
 128              sizeof(USB_ENDPOINT_DESCRIPTOR), //BYTE bLength
 129              0x05, //BYTE bDescriptorType, assigned by USB
 130              0x81, //BYTE bEndpointAddress, IN endpoint, endpoint 1
 131              USB_ENDPOINT_TYPE_INTERRUPT, //BYTE bmAttributes, Interrupt endpoint
 132              SWAP(EP1_PACKET_SIZE), //WORD wMaxPacketSize
 133              100 //Polling Time, poll over 100 ms
 134          };
 135          */
 136          
 137          struct CONFIG code sConfiguration= {
 138                  sizeof(USB_CONFIGURATION_DESCRIPTOR), //BYTE bLength
 139                  USB_CONFIGURATION_DESCRIPTOR_TYPE, //BYTE bDescriptorType //Assigned by USB
 140                  SWAP(CONFIG_DESCRIPTOR_LENGTH), //WORD wTotalLength
 141                  0x01, //BYTE bNumInterfaces
 142                  0x01, //BYTE bConfigurationValue
 143                  0x03, //BYTE iConfiguration
 144                  0x80, //BYTE bmAttributes, Bus powered
 145                  50, //BYTE MaxPower, 50x2=100mA
 146          
 147                  sizeof(USB_INTERFACE_DESCRIPTOR),//BYTE bLength
 148                          USB_INTERFACE_DESCRIPTOR_TYPE,//BYTE bDescriptionType, assigned by USB
 149                          0x00, //BYTE bInterfaceNumber
 150                          0x00, //BYTE bAlternateSetting, no alternate setting
 151                          0x01, //BYTE bNumEndpoints, HID uses endpoint 1
 152                      0x03, //BYTE bInterfaceClass, HID Class - 0x03
 153                      0x00, //BYTE bInterfaceSubClass
 154                      0x00, //BYTE bInterfaceProtocol
 155                      0x04,  //BYTE iInterface, interface name
 156          
 157                  sizeof(USB_HID_DESCRIPTOR), //BYTE bLength;
 158                          0x21, //BYTE bDescriptorType;
 159                          0x0001, //WORD bcdHID;
 160                          0x00, //BYTE bCountryCode, country localization = None;
 161                          0x01, //BYTE bNumDescriptors, number of descriptor follow
 162                          0x22, //BYTE bReportDescriptorType And it's a Report descriptor
 163                          SWAP(REPORT_DESC_LENGTH), //WORD wItemLength, total length of report descriptor
 164          
 165                  sizeof(USB_ENDPOINT_DESCRIPTOR), //BYTE bLength
 166                          0x05, //BYTE bDescriptorType, assigned by USB
 167                          0x81, //BYTE bEndpointAddress, 0x80=IN endpoint, endpoint 1
 168                          USB_ENDPOINT_TYPE_INTERRUPT, //BYTE bmAttributes, Interrupt
 169                          SWAP(EP1_PACKET_SIZE), //WORD wMaxPacketSize
 170                      100 //Polling Time unit ms, poll over 100 ms
 171           };
 172          
 173          
 174          code USB_ENDPOINT_DESCRIPTOR EP1_RXDescr =
 175          {
 176                  sizeof(USB_ENDPOINT_DESCRIPTOR),
 177                  USB_ENDPOINT_DESCRIPTOR_TYPE,
 178                  0x1,
 179                  USB_ENDPOINT_TYPE_INTERRUPT,
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 4   

 180                  SWAP(EP1_PACKET_SIZE),
 181                  10
 182          };
 183          
 184          code USB_ENDPOINT_DESCRIPTOR EP2_TXDescr =
 185          {
 186                  sizeof(USB_ENDPOINT_DESCRIPTOR),
 187                  USB_ENDPOINT_DESCRIPTOR_TYPE,
 188                  0x82,
 189                  USB_ENDPOINT_TYPE_BULK,
 190                  SWAP(EP2_PACKET_SIZE),
 191                  10
 192          };
 193          
 194          code USB_ENDPOINT_DESCRIPTOR EP2_RXDescr =
 195          {
 196                  sizeof(USB_ENDPOINT_DESCRIPTOR),
 197                  USB_ENDPOINT_DESCRIPTOR_TYPE,
 198                  0x2,
 199                  USB_ENDPOINT_TYPE_BULK,
 200                  SWAP(EP2_PACKET_SIZE),
 201                  10
 202          };
 203          
 204          
 205          unsigned char code LANG_ID[4] = {
 206                  0x04,  //4 bytes
 207                  0x03,  //bDescriptorType = String Desc
 208                  0x09,  //Lang ID for English = 0x0409
 209                  0x04
 210          };
 211          
 212          code csSTRING1[] = { //STRING1 Manumfacturer
 213          'M',0,'y',0,'U',0,'S',0,'B',0};
 214          code csSTRING2[] = { //STRING2 Product Name
 215          'D',0,'e',0,'c',0,'o',0,'d',0,'e',0,'r',0};
 216          code csSTRING3[] = { //STRING3 Configuration Name
 217          'S',0,'i',0,'m',0,'p',0,'l',0,'e',0,'D',0,'e',0,'v',0,'c',0,'e',0};
 218          code csSTRING4[] = { //STRING4 Interface Name
 219          'H',0,'I',0,'D',0,'e',0,'x',0,'a',0,'m',0,'p',0,'l',0,'e',0};
 220          
 221          
 222          struct STRING1 { 
 223              UCHAR bLength;
 224                  UCHAR bDescriptorType;
 225                  char string1[sizeof(csSTRING1)];
 226          };
 227          struct STRING1 code sSTRING1 = {
 228                  sizeof(csSTRING1)+2, //Size of String
 229                  0x03, //STRING Descriptor Type
 230                  csSTRING1};
 231          struct STRING2 { 
 232              UCHAR bLength;
 233                  UCHAR bDescriptorType;
 234                  char string1[sizeof(csSTRING2)];
 235          };
 236          struct STRING2 code sSTRING2 = {
 237                  sizeof(csSTRING2)+2, //Size of String
 238                  0x03, //STRING Descriptor Type
 239                  csSTRING2};
 240          struct STRING3 { 
 241              UCHAR bLength;
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 5   

 242                  UCHAR bDescriptorType;
 243                  char string1[sizeof(csSTRING3)];
 244          };
 245          struct STRING3 code sSTRING3 = {
 246                  sizeof(csSTRING3)+2, //Size of String
 247                  0x03, //STRING Descriptor Type
 248                  csSTRING3};
 249          struct STRING4 { 
 250              UCHAR bLength;
 251                  UCHAR bDescriptorType;
 252                  char string1[sizeof(csSTRING4)];
 253          };
 254          struct STRING4 code sSTRING4 = {
 255                  sizeof(csSTRING4)+2, //Size of String
 256                  0x03, //STRING Descriptor Type
 257                  csSTRING4};
 258          
 259          
 260          //*************************************************************************
 261          // USB Protocol Layer
 262          //*************************************************************************
 263          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -