Cypress-USB教程第6講課件_第1頁(yè)
Cypress-USB教程第6講課件_第2頁(yè)
Cypress-USB教程第6講課件_第3頁(yè)
Cypress-USB教程第6講課件_第4頁(yè)
Cypress-USB教程第6講課件_第5頁(yè)
已閱讀5頁(yè),還剩33頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

Lecture6AgendaUsingtheEZ-USBFrameworksfw.c,periph.cFW2HIDMymodifiedframeworksSupportsHIDdescriptorsandreportsEmulates3KeyboardkeysandlightCapsLockNumLockScrollLockHowtomakea“B2”(codeboot)EEPROMUsingtheEZ-USBFrameworksEZ-USBFrameworksDividedintotwofilesfw.c&periph.cfw.ccontainsenumerationcodeandthreetypesof‘hooks’tocodeyouprovideinperiph.cTD_prefixmeans“TaskDispatcher”DR_prefixmans“DeviceRequest”ISR_prefix(inperiph.c)means“InterruptServiceRoutine”fw.c

callsTD_Init()once,atstartupfw.c

callsTD_Poll()repeatedlyfromaneventloop,whenevernoCONTROLtransfersarebeingservicedfw.c

callsTD_Suspend()justbeforeenteringpower-downmodefw.candperiph.cfw.c

hashooksinsidetheenumerationcodetoallowcodeinperiph.ctoaugmentorreplacefw.ccode(nextfoilshowsformat)periph.cisintendedforyourcustomdevicecodeHookswhereneededtofw.c

AllUSBISRSYoushouldneverneedtomodifyfw.c

MostofyourcodewillbeinTD_Poll()PlusalittleinTD_Init()TheframeworkscodeRe-NumeratesUsesadescriptoryoucaneditin‘DSCR.A51’Frameworks-EnumerationHooks(infw.c)caseSC_GET_DESCRIPTOR: if(DR_GetDescriptor()) switch(SETUPDAT[3]) (manycasestatements)TheHook(inperiph.c)BOOLDR_GetDescriptor(void) …h(huán)andletherequest return(FALSE); …don’thandletherequest return(TRUE)FALSEmeans“Ihandledit,youcanstopchecking”TRUEmeans“keepgoing”periph.cusesadifferentUSB(INT2)interruptmethodthanourclassprojectsDefinestheINT2jumptableinan.A51file,providesthelinkerobjectas‘USBJmpTb.OBJ’periph.cuses‘#pragmaNOIV’(NoInterruptVectors)toinhibitthecompiler/linkerfrombuildingthejumptablewhenitseesinterruptfunctionsTheperiph.cISRfunctionsuseinterruptnumber0(onlyasaplaceholder—thenumberismeaninglessdueto“NOIV”)Example:voidISR_EP2in(void)interrupt0FrameworksMynewHIDframeworks(nextsection)addsHIDenumerationcodetofw.cAlsotakesoutsome‘legacy’stufflikemovingcodefromexternalRAMintothepartUsestheAutopointertomoveReportDescriptordataintoEP0-INbufferFrameworks+HIDAWorkingHIDExampleHIDDesignGoal--FW2HIDDesignastandardWindowskeyboard,withthreekeysandthreelightsKeysCapsLockNumLockScrollLockLightsCapsLockNumLockScrollLockUsetheHID-frameworksasacodebaseTodoHID,weneedtoReNumerateWhenweplugintheDevBoard,theVID/PIDcomesfromanon-boardEEPROMthatsupplies:VID=0547(AnchorChips)PID=0080(ourtagforloadingthecontrolpanel)HIDrequiresanewsetofdescriptorstotellthehosttoloadtheHIDdriver,todefinetheHIDdataformats,tosetupHIDcompliantendpoints,etc.ThingsToDoDesigntheReportDescriptorTellstheHIDdriverwhattheformatandusageofourdatawillbeBuildthedescriptors(HID_descriptors.a51)DeviceConfiguration(includingHID)ReportString(Whyinassemblylanguageinsteadofin-lineCcode?)Modifyfw.c(nameitfw2HID.c)AddHID&ReportDescriptorservice“Un-nest”afewswitch-caselevelsUsetheAutopointertoserviceGet_Descriptor:ReportModifyperiph.c(nameitHIDapp.c)Re-doUSBinterruptslikepreviousclassexamplesWriteTD_Init()andTD_Poll()routinesWritesupportingfunctions(readbuttons,display)DesigntheReportDescriptorHIDReportDescriptorReportDescr: db 05h,01h ;Usagepage(genericdesktop) db 09h,06h ;Usage(keyboard) db 0A1h,01h ;Collection(application) db 05h,07h ;UsagePage(HIDPage7forkeycodes) db 95h,01h ;Reportcount(1) db 75h,08h ;Reportsize(8) db 15h,00h ;Logicalminimum(0) db 25h,65h ;Logicalmaximum(101d) db 19h,00h ;Usageminimum(0) db 29h,65h ;Usagemaximum(101d) db 81h,00h ;Input(Data,Array)--keycode db 05h,08h ;UsagePage(Page8forLEDS) db 95h,03h ;Reportcount(3) db 75h,01h ;Reportsize(1) db 19h,01h ;Usageminimum(1) db 29h,03h ;Usagemaximum(3) db 91h,02h ;Output(Data,Variable,Absolute)-LEDreport db 95h,01h ;Reportcount(1) db 75h,05h ;Reportsize(5) db 91h,01h ;Output(constant)-padLEDreportto8bits db 0C0h ;EndCollectionReportDescr_end:HID_Descriptors.a51DeviceDescriptorDeviceDescr: db 18d ;Descriptorlength db 01h ;Descriptortype=DEVICE db 10h,01h ;specversion(BCD)is1.10 db 0,0,0 ;HIDclassisdefinedintheinterface ;descriptor db 64 ;maxPacketSize db LOW(VID),HIGH(VID) db LOW(PID),HIGH(PID) db LOW(DID),HIGH(DID) db 01h,02h,0 ;manuf,product,s/nstringindex db 01h ;numberofconfigurationsConfigurationDescriptor(1of2)ConfigDescr: db 09h ;descriptorlength db 02h ;Descriptortype=CONFIG db LOW(EPend-ConfigDescr) ;totallength(conf+interface+HID+EP's) db HIGH(EPend-ConfigDescr) db 01h ;numberofinterfaces db 01h ;valuetoselectthisinterface db 00h ;stringindextodescribethisconfig db 10100000b ;b7=1;b6=self-powered;b5=RemoteWU db 40d ;buspower=80ma;InterfaceDescriptor db 09h ;Descriptorlength db 04h ;Descriptortype=INTERFACE db 0,0 ;Interface0,Alternatesetting0 db 02h ;numberofendpoints db 03h,0,0 ;class(03)=HID,nosubclassorprotocol db 0 ;stringindexforthisinterfaceHIDDescr: db 09h ;Descriptorlength db 21h ;Descriptortype-HID db 10h,01h ;HIDSpecversion1.10 db 0 ;countrycode(none) db 01h ;numberofHIDclassdescriptors db 22h ;classdescriptortype:REPORT db LOW(ReportDescr_end-ReportDescr);Reportdescriptorlength db HIGH(ReportDescr_end-ReportDescr);I-0,AS-0firstendpointdescriptor(EP1IN)NoticethatHIDdescriptorisbetweenInterfaceandEndpointDescriptors(HID1.10)(AboutHIDendpoints)HID1.0(Win98andlater)OnlyoneINTINendpointdefinedEP0fornormaldevicecontrolGet_Report:InputusestheINTERRUPTINendpointSet_Report:OutputusesEP0-OUTCONTROLtransferHID1.1(Win98SEandlater)AddsanINTERRUPT-OUTendpoint‘Set_Report:Output’usestheINTOUTendpointIfthedevicedoesnotdeclareanInterruptOUTendpoint,thehostdoesall“Set_Report”transfersoverEP0(likeHIDv1.0)IfthedevicedeclaresanInterruptOUTep,thehostsendsoutputreportdataovertheInterruptOUTendpointSet_Report:FeaturestillusesEP0-OUTConfigurationDescriptor(2of2);I-0,AS-0firstendpointdescriptor(EP1IN) db 07h ;Descriptorlength db 05h ;Descriptortype=ENDPOINT db 81h ;IN-1 db 03h ;type-INTERRUPT db 64d,0 ;maxPacketSize=64 db 50d ;pollingintervalis50msec;I-0,AS-0secondendpointdescriptor(EP1OUT) db 07h ;Descriptorlength db 05h ;Descriptortype=ENDPOINT db 01h ;OUT-1 db 03h ;type-INTERRUPT db 64d,0 ;maxPacketSize=64 db 50d ;pollingintervalis50msecEPend:StringDescriptorString0: db 4,3,9,4 ;string0islanguageID:len,type,lang, ;sub-langString1: db endStr1-String1 ;lengthisonebyteforstrings db 3 ;Descriptortype=STRING db 'C',0,'y',0,'p',0,'r',0,'e',0,'s',0,'s',0endStr1:String2: db endStr2-String2 ;lengthisonebyteforstrings db 3 ;Descriptortype=STRING db 'F',0,'W',0,'2',0,'H',0,'I',0,'D',0,'.',0,'C',0endStr2:AddHIDdescriptor/Reportparsingtofw.cbmRequestTypeStandardClassVendorbRequestCustomProgrammingSTALLd01XXXXXd00XXXXXd11XXXXXd10XXXXX000C010305060708090A0BotherGet_StatusClr_FeatureSet_FeatureSet_AddressGet_DescriptorSet_DescriptorGet_ConfigSet_ConfigGet_InterfaceSet_InterfaceSync_FrameStallbRequest010203090A0BotherGet_ReportGet_IdleGet_ProtocolSet_ReportSet_IdleSet_ProtocolStall010203DEVICECONFIGSTRING212223otherHIDREPORTPHYSICALStallwValueHbmRequestTypeStandardClassVendorbRequestCustomProgrammingSTALLd01XXXXXd00XXXXXd11XXXXXd10XXXXX000C010305060708090A0BotherGet_StatusClr_FeatureSet_FeatureSet_AddressGet_DescriptorSet_DescriptorGet_ConfigSet_ConfigGet_InterfaceSet_InterfaceSync_FrameStallbRequest010203090A0BotherGet_ReportGet_IdleGet_ProtocolSet_ReportSet_IdleSet_ProtocolStall010203DEVICECONFIGSTRING212223otherHIDREPORTPHYSICALStallwValueHfw2HID.c

un-nestafewswitch-caselevels(a)voidSetupCommand(void){ switch(SETUPDAT[0]&0x60) //bmRequestType&01100000:00-std,20- //class,40-vendor,60-reserved. { caseSETUP_STANDARD_REQUEST:

process_standard_request(); break; caseSETUP_CLASS_REQUEST:

process_class_request(); break; default: EZUSB_STALL_EP0(); //wedon'thandle //SETUP_VENDOR_REQUESTor"Reserved". }EP0CS=bmHS; //CleartheHS-NAKbitbywriting'1'toit}fw2HID.c

un-nestafewswitch-caselevels(b)voidprocess_standard_request(void){ switch(SETUPDAT[1]) //bRequest { caseSC_GET_DESCRIPTOR: //***GetDescriptor

process_descriptor(); break; caseSC_GET_INTERFACE: //***GetInterface DR_GetInterface(); …etc.fw2HID.c

HandletheHIDdescriptorrequest

caseGD_HID: //Get-Descriptor:HID SUDPTRH=MSB(&HIDDescr); SUDPTRL=LSB(&HIDDescr); break;fw2HID.c

HandletheREPORTdescriptorrequestcaseGD_REPORT: //Get-Descriptor:Report/*Note:AHIDreportdoesnothavealengthfieldwhichtheSIEcanreadtodeterminehowmanybytestosendusingtheSetupDataPointer.Thereforeweneedto'manually'sendthedata.*/ ReportSize=(WORD)&ReportDescr_end-(WORD)&ReportDescr;

AUTOPTRH=MSB(&ReportDescr);

AUTOPTRL=LSB(&ReportDescr); while(ReportSize) { k=min(ReportSize,64); //smallerofReportSizeorIN0BUF(64bytes) for(j=0;j<k;j++) IN0BUF[j]=AUTODATA; IN0BC=j; //armtheINtransfer ReportSize=ReportSize-j; while(EP0CS&bmIN); //waitforittogooutandgetACK'd } break;A16-bitloadableup-counterLoadaddressintoAUTOPTRHAUTOPTRLReadorwriteAUTODATAregistertoAccessthedatapointedtobytheaddressIncrementtheadddressaftertheread/writeMyautopointercodereplacesthisline:*(IN0BUF+i)=*((BYTExdata*)pHID1ReportDscr+i);TheAutopointerDemonstration:fw2HIDMakingcodebootable

(codemustbeinternaltoAN2131)Convertyourhex‘iic’formatusingthe‘hex2bix’utilityprogram.Removethe24LC00EEPROM(16bytes)fromsocket(U9)Replaceitwitha24LC64(8Kilobytes)FlipRockerSwitch8totheup(on)position.RockerSwitch7isalwaysdown(off).Thisidentifiesitasa“big”(16-bitaddress)EEPROM.StarttheControlPanelPressthe‘EEPROM’buttonandselectyour‘iic’programthepart.PresstheResetbutton;AN2131shouldbootcodefromtheEEPROMintointernalRAMandstartexecution.BasicSteps‘hex2bix’converts‘’to‘’,

the‘B2’EEPROMimage

hex2bix-i–oHID3KB.iic

fw2hid.hexIntelHexEZ-USBBinaryutilityCopyright(c)1997-1999,CypressSemiconductorInc.HEX2BIX[-AIBRH?][-Ssymbol][-Mmemsize][-CConfig0Byte][-FfirstByte][-O]SourceSource-InputA-OutputtheA51B-OutputtheBIX(Default)BI-InputtheBIX(hexisdefault)C-Config0BYTEforAN2200andFX2(Default=0x04)F-Firstbyte(0xB0,0xB2,0xB6,0xC0,0xC2)(Default=0xB2)H|?-Displaythishelpscreen

I-OutputtheIICM-Maximummemorysize,alsousedasBIXout.(Default=8k)

O-OutputP-ProductID(Default=2131)R-AppendbootloadblocktoreleaseresetS-PublicsymbolnameforlinkingV-VendorID(Default=0x0547)Movehex2bix.exetoyourprojectfolderFromtheDOSprompt,type:Hex2bix–i–oHID3KB.iic

fw2hid.hexIfyou’recurious,useDOS‘DEBUG’commandtoinspectthebinaryfileQuitbytyping‘Q’BeforeapplyingpowertotheDevBoard:Removethe24LC00EEPROMUseabladescrewdriverSwitchDIP-switch#8tothe‘on’(up)positionItshouldbetheonlyoneinthispositionMakingourcodebootable(1of4)PluginaMicrochip24LC64(8KByte)EEPROMMakesurethelittlenotchpointstowardthemiddleoftheboardPlugintheUSBcable‘Monitor’lightshouldnotcomeonTheEEPROMisblank,with0xFFatthefirstlocation;thisisdetectedas‘missing’TRMSection4.10Enumeratesas‘AnchorGeneric’;doesnotloadKeilmonitorMakingourcodebootable(2of4)StartupthecontrolpanelClickthe‘EEPROM’buttonThisdownloadsthe‘.iic’selectWaitforthecursortore-appearintheControlPaneloutputwindowScreenwillfreeze—don’tpanicEEPROMprogrammingtakesabout10secondsPresstheboardRESETbuttonYou’reinbusinesswithaself-containedthree-buttonHIDkeyboardSideEffects(nextfoil)Makingourcodebootable(3of4)SideEffectsLinkisbrokentoControlPanelFirmwareisnowattachedtotheWindows‘HID’driver,nottothedevtoolsdriverCan’treprogramtheEEPROMuntilwerestorethedevelopmentenvironmentA‘gotcha’:EEPROMhas‘0xB2’asf

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論