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

📄 chap_9.lst

📁 USB_D12开发评估板实现USB键盘的全部源代码
💻 LST
字号:
C51 COMPILER V7.50   CHAP_9                                                                04/16/2007 15:22:54 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE CHAP_9
OBJECT MODULE PLACED IN .\Obj\Chap_9.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Chap_9.c LARGE OPTIMIZE(2,SPEED) BROWSE MODP2 PRINT(.\Obj\Chap_9.lst) OBJEC
                    -T(.\Obj\Chap_9.obj)

line level    source

   1          #include "..\..\Driver\inc\includes.h"
   2          
   3          
   4          #include "mainloop.h"
   5          #include "usb100.h"
   6          #include "chap_9.h"
   7          
   8          
   9          #define NUM_ENDPOINTS   4
  10          
  11          #define CONFIG_DESCRIPTOR_LENGTH    34
  12          
  13          extern CONTROL_XFER ControlData;
  14          extern IO_REQUEST idata ioRequest;
  15          extern EPPFLAGS bEPPflags;
  16          
  17          /*
  18          unsigned char code Keyboard_DeviceDescriptor[] = {
  19                  18, 1,                                  // Length, Type
  20                  0x10, 1,                                // USB Rev 1.1 (=0110H, low=10H, High=01H)
  21                  0, 0, 0,                                // Class, Subclass and Protocol
  22                  EP0Size,                                // EP0 size
  23                  0x42, 0x42, 0, 2, 0, 0, // Vendor ID, Product ID and Version
  24                  1, 0, 0,                                // Manufacturer, Product & Serial# Names
  25                  1                                       // #Configs
  26          };
  27          unsigned char code Keyboard_ConfigurationDescriptor[] = {
  28                  9, 2,                                   // Length, Type
  29                  34, 0,
  30                  1, 1, 0,                                // #Interfaces, Configuration#, Config. Name
  31                  0xa0,                                   // Attributes = Bus Powered & Remote Wakened
  32                  50                                      // Max. Power is 50x2 = 100mA
  33          };
  34          unsigned char code Keyboard_InterfaceDescriptor[] = {
  35                  9, 4,                                   // Length, Type
  36                  0, 0, 1,                                // No alternate setting, HID uses EP1
  37                  3,                                      // Class = Human Interface Device
  38                  1, 1,                                   // Subclass and Protocol
  39                  0                                       // Interface Name
  40          };
  41          unsigned char code Keyboard_HIDDescriptor[] = {
  42                  9, 0x21,                                // Length, Type
  43                  0, 1,                                   // HID Class Specification compliance
  44                  0,                                      // Country localization (=none)
  45                  1,                                      // Number of descriptors to follow
  46                  0x22,                                   // And it's a Report descriptor
  47                  63, 00
  48          };
  49          unsigned char code Keyboard_EndpointDescriptor[] = {
  50                  7, 5,                                   // Length, Type
  51                  0x81,                                   // Address = IN 1
  52                  0x03,                                   // Interrupt
  53                  EP0Size, 0,                             // Maximum packet size
  54                  10                                      // Poll every 10 msec (OS will round down to 8) 
C51 COMPILER V7.50   CHAP_9                                                                04/16/2007 15:22:54 PAGE 2   

  55          };
  56          
  57          unsigned char code Keyboard_ReportDescriptor[] = {      // Generated with HID Tool, copied to here
  58                  5, 1,                   // Usage_Page (Vendor Defined)
  59                  9, 6,                   // Usage (I/O Device)
  60                  0xa1, 1,                // Collection (Application)
  61                  0x05, 07,
  62                  0x19, 0xe0,             //   Usage_Minimum
  63                  0x29, 0xe7,             //   Usage_Maximum
  64                  0x15, 0,                //   Logical_Minimum (0)
  65                  0x25, 1,                //   Logical_Maximum (1)
  66                  0x75, 1,                //   Report_Size (1)
  67                  0x95, 8,                //   Report_Count (8)
  68                  0x81, 2,                //   Input (Data,Var,Abs)
  69          
  70                  0x95, 0x01,
  71                  0x75, 0x08,
  72                  0x81, 0x01,
  73                  0x95, 0x05,
  74                  0x75, 0x01,
  75                  0x05, 0x08,
  76                  0x19, 0x01,
  77                  0x29, 0x05,
  78                  0x91, 0x02,
  79          
  80                  0x95, 0x01,
  81                  0x75, 0x03,
  82                  0x91, 0x01,
  83                  
  84                  0x95, 0x06,
  85                  0x75, 0x08,
  86                  0x15, 0x00,
  87                  0x25, 0x65,
  88                  0x05, 0x07,
  89                  0x19, 0x00,             //   Usage_Minimum
  90                  0x29, 0x65,             //   Usage_Maximum
  91                  0x81, 0x00,             //   Output (Data,Var,Abs)
  92                  0xc0                    // End_Collection
  93          };
  94          
  95          */
  96          
  97          
  98          //设备描述符
  99          code USB_DEVICE_DESCRIPTOR DeviceDescr =
 100          {
 101                  18, 1,                                  // Length, Type
 102                  0x1001,                 // USB Rev 1.1 (=0110H, low=10H, High=01H)
 103                  0, 0, 0,                                // Class, Subclass and Protocol
 104                  16,                             // EP0 size
 105                  0x4242, 0x0002, 0x0000, // Vendor ID, Product ID and Version
 106                  0, 0, 0,                                // Manufacturer, Product & Serial# Names
 107                  1       
 108          };
 109          
 110          //配置描述符
 111          code USB_CONFIGURATION_DESCRIPTOR ConfigDescr =
 112          {
 113                  9, 2,                                   // Length, Type
 114                  0x2200,
 115                  1, 1, 0,                                // #Interfaces, Configuration#, Config. Name
 116                  0xa0,                                   // Attributes = Bus Powered & Remote Wakened
C51 COMPILER V7.50   CHAP_9                                                                04/16/2007 15:22:54 PAGE 3   

 117                  150                                             //Current = 150*2mA 
 118          };
 119          
 120          //接口描述符
 121          code USB_INTERFACE_DESCRIPTOR InterfaceDescr =
 122          {
 123                  9, 4,                                   // Length, Type
 124                  0, 0, 1,                                // No alternate setting, HID uses EP1
 125                  3,                                      // Class = Human Interface Device
 126                  0, 1,                                   // Subclass and Protocol
 127                  0                                       // Interface Name
 128          };
 129          
 130          unsigned char code Keyboard_HIDDescriptor[] = {
 131                  9, 0x21,                                // Length, Type
 132                  0, 1,                                   // HID Class Specification compliance
 133                  0,                                      // Country localization (=none)
 134                  1,                                      // Number of descriptors to follow
 135                  0x22,                                   // And it's a Report descriptor
 136                  63, 00
 137          };
 138          
 139          //端点描述符
 140          code USB_ENDPOINT_DESCRIPTOR EP1_TXDescr =
 141          {
 142                  sizeof(USB_ENDPOINT_DESCRIPTOR),                //7
 143                  USB_ENDPOINT_DESCRIPTOR_TYPE,
 144                  0x81,
 145                  USB_ENDPOINT_TYPE_INTERRUPT,
 146                  SWAP(EP1_PACKET_SIZE),
 147                  10
 148          };
 149          
 150          
 151          unsigned char code Keyboard_ReportDescriptor[] = {      // Generated with HID Tool, copied to here
 152                  5, 1,                   // Usage_Page (Vendor Defined)
 153                  9, 6,                   // Usage (I/O Device)
 154                  0xa1, 1,                // Collection (Application)
 155                  0x05, 07,
 156                  0x19, 0xe0,             //   Usage_Minimum
 157                  0x29, 0xe7,             //   Usage_Maximum
 158                  0x15, 0,                //   Logical_Minimum (0)
 159                  0x25, 1,                //   Logical_Maximum (1)
 160                  0x75, 1,                //   Report_Size (1)
 161                  0x95, 8,                //   Report_Count (8)
 162                  0x81, 2,                //   Input (Data,Var,Abs)
 163          
 164                  0x95, 0x01,
 165                  0x75, 0x08,
 166                  0x81, 0x01,
 167                  0x95, 0x05,
 168                  0x75, 0x01,
 169                  0x05, 0x08,
 170                  0x19, 0x01,
 171                  0x29, 0x05,
 172                  0x91, 0x02,
 173          
 174                  0x95, 0x01,
 175                  0x75, 0x03,
 176                  0x91, 0x01,
 177                  
 178                  0x95, 0x06,
C51 COMPILER V7.50   CHAP_9                                                                04/16/2007 15:22:54 PAGE 4   

 179                  0x75, 0x08,
 180                  0x15, 0x00,
 181                  0x25, 0x65,
 182                  0x05, 0x07,
 183                  0x19, 0x00,             //   Usage_Minimum
 184                  0x29, 0x65,             //   Usage_Maximum
 185                  0x81, 0x00,             //   Output (Data,Var,Abs)
 186                  0xc0                    // End_Collection
 187          };
 188          
 189          
 190          /*
 191             //*************************************************************************
 192             // USB Protocol Layer
 193             //*************************************************************************
 194          */
 195          //----------------------usb标准设备请求用到的了程序 ----------------/
 196          //返回stall应答
 197          void stall_ep0(void)
 198          {
 199   1              D12_SetEndpointStatus(0, 1);
 200   1              D12_SetEndpointStatus(1, 1);
 201   1      }
 202          
 203          //恢复到未配置状态
 204          //禁止0除外的所有端点
 205          void init_unconfig(void)
 206          {
 207   1      //      unsigned char i;
 208   1      
 209   1              D12_SetEndpointEnable(0);       /* Disable all endpoints but EPP0. */
 210   1      }
 211          
 212          //设置配置状态
 213          //允许端点收发。
 214          void init_config(void)
 215          {
 216   1              D12_SetEndpointEnable(1);       /* Enable  generic/iso endpoints. */
 217   1      }
 218          
 219          //从端点号1发送数据
 220          void single_transmit(unsigned char * buf, unsigned char len)
 221          {
 222   1              if( len <= EP0_PACKET_SIZE) 
 223   1              {
 224   2                      D12_WriteEndpoint(1, len, buf);
 225   2              }
 226   1      }
 227          
 228          //发送端点号1建立代码
 229          //将第1包数据发送到主机,后继发送与处理由中断程序来完成。
 230          void code_transmit(unsigned char code * pRomData, unsigned short len)
 231          {
 232   1              ControlData.wCount = 0;                 //发送字符计数器请零。
 233   1      
 234   1              if(ControlData.wLength > len)
 235   1                      ControlData.wLength = len;
 236   1      
 237   1              ControlData.pData = pRomData;
 238   1              if( ControlData.wLength >= EP0_PACKET_SIZE) 
 239   1              {
 240   2                      D12_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData);//发送16字节数据
C51 COMPILER V7.50   CHAP_9                                                                04/16/2007 15:22:54 PAGE 5   

 241   2                      ControlData.wCount += EP0_PACKET_SIZE;
 242   2                      DISABLE;
 243   2                      bEPPflags.bits.control_state = USB_TRANSMIT;
 244   2                      ENABLE;
 245   2              }
 246   1              else 
 247   1              {
 248   2                      D12_WriteEndpoint(1, ControlData.wLength, pRomData);//发送16字节内数据
 249   2                      ControlData.wCount += ControlData.wLength;
 250   2                      DISABLE;
 251   2                      bEPPflags.bits.control_state = USB_IDLE;
 252   2                      ENABLE;
 253   2              }
 254   1      }
 255          
 256          
 257          void reserved(void)
 258          {
 259   1              stall_ep0();
 260   1      }
 261          
 262          /*
 263             //*************************************************************************
 264             // USB standard device requests
 265          //----------

⌨️ 快捷键说明

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