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

📄 sl811.lst

📁 51单片机读写U盘
💻 LST
📖 第 1 页 / 共 5 页
字号:
 441                  
 442                  if(usbXfer())
 443                          return TRUE;
 444          
 445                  return FALSE;
 446          }
 447          */
 448          
 449          //*****************************************************************************************
 450          // USB Device Enumeration Process
 451          // Support 1 confguration and interface #0 and alternate setting #0 only
 452          // Support up to 1 control endpoint + 4 data endpoint only
 453          //*****************************************************************************************
 454          unsigned char EnumUsbDev(BYTE usbaddr)
 455          {  
 456   1              unsigned char i;                                                                                        // always reset USB transfer address 
 457   1              unsigned char uAddr = 0;                                                        // for enumeration to Address #0
 458   1              unsigned char epLen;
 459   1              //unsigned short strLang;
 460   1              
 461   1              pDevDesc  pDev; 
 462   1              pCfgDesc pCfg;
 463   1              pIntfDesc pIfc;
 464   1              pEPDesc pEnp;
 465   1              //------------------------------------------------
 466   1              // Reset only Slave device attached directly
 467   1              //------------------------------------------------
 468   1              uDev.wPayLoad[0] = 64;  // default 64-byte payload of Endpoint 0, address #0
 469   1              if(usbaddr == 1)                // bus reset for the device attached to SL811HS only
 470   1                      USBReset();             // that will always have the USB address = 0x01 (for a hub)
 471   1              
 472   1              DelayMs(25);
 473   1              
 474   1              //i = SL811Read(EP0Status);     
 475   1              //i=SL811Read(IntStatus);
 476   1              //------------------------------------------------
 477   1              // Get USB Device Descriptors on EP0 & Addr 0
 478   1              // with default 64-byte payload
 479   1              //------------------------------------------------
 480   1              pDev =(pDevDesc)DBUF;                                   // ask for 64 bytes on Addr #0
 481   1              
 482   1              usbstack.usbaddr=uAddr;
 483   1              usbstack.setup.wValue=DEVICE;
 484   1              usbstack.setup.wIndex=0;
 485   1              usbstack.setup.wLength=18;
 486   1              //usbstack.setup.wLength=sbstack.setup.wLength);
 487   1              usbstack.buffer=DBUF;
 488   1              
 489   1              if (!GetDesc())                 // and determine the wPayload size
 490   1                      return FALSE;                                                           // get correct wPayload of Endpoint 0
 491   1              uDev.wPayLoad[0]=pDev->bMaxPacketSize0;// on current non-zero USB address
 492   1      
 493   1              //------------------------------------------------
 494   1              // Set Slave USB Device Address
 495   1              //------------------------------------------------
 496   1              if (!SetAddress(usbaddr))                                               // set to specific USB address
 497   1                      return FALSE;                                                           //
 498   1              uAddr = usbaddr;                                                                // transfer using this new address
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 11  

 499   1      
 500   1              //------------------------------------------------
 501   1              // Get USB Device Descriptors on EP0 & Addr X
 502   1              //------------------------------------------------
 503   1              pDev =(pDevDesc)DBUF;
 504   1              usbstack.usbaddr=uAddr;
 505   1              
 506   1              usbstack.setup.wLength=pDev->bLength;
 507   1              usbstack.setup.wValue=DEVICE;
 508   1              usbstack.setup.wIndex=0;
 509   1              
 510   1              //usbstack.setup.wLength=0x12;//(unsigned short)DBUF[0];//pDev->bLength;
 511   1              usbstack.buffer=DBUF;
 512   1              
 513   1              if (!GetDesc())         
 514   1                      return FALSE;                                                           // For this current device:
 515   1              uDev.wVID  = pDev->idVendor;                    // save VID
 516   1              uDev.wPID  = pDev->idProduct;                   // save PID
 517   1              uDev.iMfg  = pDev->iManufacturer;               // save Mfg Index
 518   1              uDev.iPdt  = pDev->iProduct;                    // save Product Index
 519   1      
 520   1              //------------------------------------------------
 521   1              // Get String Descriptors
 522   1              //------------------------------------------------
 523   1              /*
 524   1              pStr = (pStrDesc)DBUF;  
 525   1              
 526   1              usbstack.usbaddr=uAddr;
 527   1              usbstack.setup.wValue=STRING;
 528   1              usbstack.setup.wIndex=0;
 529   1              usbstack.setup.wLength=4;
 530   1              usbstack.buffer=DBUF;
 531   1              
 532   1              if (!GetDesc())                         // Get string language
 533   1                      return FALSE;                                                           
 534   1      
 535   1              strLang = pStr->wLang;  
 536   1              
 537   1              usbstack.usbaddr=uAddr;
 538   1              usbstack.setup.wValue=(unsigned short)(uDev.iMfg<<8)|STRING;
 539   1              usbstack.setup.wIndex=strLang;
 540   1              usbstack.setup.wLength=4;
 541   1              usbstack.buffer=DBUF;   
 542   1                                                      // get iManufacturer String length
 543   1              if (!GetDesc())                 
 544   1                      return FALSE;   
 545   1              
 546   1              usbstack.usbaddr=uAddr;
 547   1              usbstack.setup.wValue=(unsigned short)(uDev.iMfg<<8)|STRING;
 548   1              usbstack.setup.wIndex=strLang;
 549   1              usbstack.setup.wLength=pStr->bLength;
 550   1              //usbstack.buffer=DBUF; 
 551   1                                                              // get iManufacturer String descriptors
 552   1              if (!GetDesc())                 
 553   1                      return FALSE;                   
 554   1              */
 555   1              //------------------------------------------------
 556   1              // Get Slave USB Configuration Descriptors
 557   1              //------------------------------------------------
 558   1              
 559   1              pCfg = (pCfgDesc)DBUF;  
 560   1              
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 12  

 561   1              usbstack.usbaddr=uAddr;
 562   1              usbstack.setup.wValue=CONFIGURATION;
 563   1              usbstack.setup.wIndex=0;
 564   1              usbstack.setup.wLength=64;
 565   1              usbstack.buffer=DBUF;   
 566   1              if (!GetDesc())                 
 567   1                      return FALSE;   
 568   1              /*      
 569   1              usbstack.usbaddr=uAddr;
 570   1              usbstack.setup.wValue=CONFIGURATION;
 571   1              usbstack.setup.wIndex=0;
 572   1              usbstack.setup.wLength=WordSwap(pCfg->wLength);
 573   1              
 574   1              usbstack.buffer=DBUF;   
 575   1              if (!GetDesc())         
 576   1                      return FALSE;           
 577   1              */
 578   1              
 579   1              pIfc = (pIntfDesc)(DBUF + 9);                                   // point to Interface Descp
 580   1              uDev.bClass     = pIfc->iClass;                 // update to class type
 581   1              uDev.bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
 582   1              
 583   1              if(uDev.bClass==8) //mass storage device
 584   1                      bXXGFlags.bits.bMassDevice=TRUE;
 585   1              //------------------------------------------------
 586   1              // Set configuration (except for HUB device)
 587   1              //------------------------------------------------
 588   1              usbstack.usbaddr=uAddr;
 589   1              usbstack.setup.wValue=DEVICE;
 590   1              //if (uDev[usbaddr].bClass!=HUBCLASS)                           // enumerating a FS/LS non-hub device
 591   1                      if (!Set_Configuration())               // connected directly to SL811HS
 592   1                                      return FALSE;
 593   1      
 594   1              //------------------------------------------------
 595   1              // For each slave endpoints, get its attributes
 596   1              // Excluding endpoint0, only data endpoints
 597   1              //------------------------------------------------
 598   1              
 599   1              epLen = 0;
 600   1              for (i=1; i<=uDev.bNumOfEPs; i++)                               // For each data endpoint
 601   1              {
 602   2                      pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen);                         // point to Endpoint Descp(non-HID)
 603   2                      //if(pIfc->iClass == HIDCLASS)  
 604   2                      //      pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen);             // update pointer to Endpoint(HID)
 605   2                      uDev.bEPAddr[i]         = pEnp->bEPAdd;                 // Ep address and direction
 606   2                      uDev.bAttr[i]           = pEnp->bAttr;                  // Attribute of Endpoint
 607   2                      uDev.wPayLoad[i]        = WordSwap(pEnp->wPayLoad);             // Payload of Endpoint
 608   2                      uDev.bInterval[i]       = pEnp->bInterval;              // Polling interval
 609   2                      uDev.bData1[i] = 0;                                 // init data toggle
 610   2                      epLen += 7;
 611   2                      //////////////////////////////
 612   2                      if(uDev.bAttr[i]==0x2)
 613   2                      {
 614   3                          if(uDev.bEPAddr[i]&0x80)
 615   3                              usbstack.epbulkin=uDev.bEPAddr[i];
 616   3                          else
 617   3                              usbstack.epbulkout=uDev.bEPAddr[i];
 618   3                      }
 619   2                      //////////////////////////////
 620   2              }
 621   1              
 622   1              return TRUE;
C51 COMPILER V7.20   SL811                                                                 12/13/2005 15:28:02 PAGE 13  

 623   1      }
 624          
 625          //*****************************************************************************************
 626          // Full-speed and low-speed detect - Device atttached directly to SL811HS
 627          //*****************************************************************************************
 628          /*

⌨️ 快捷键说明

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