fl \ 2012/11/11 12:36:29 hex : Print_data last_transfer_size W@ 0 do XfrData i + C@ . loop ; : print_char last_transfer_size W@ 2 do XfrData i + C@ emit 2 +loop ; : tab 9 emit ; : 2tab tab tab ; : 3tab tab tab tab ; : desc hex init_host detect_device d200 waitframe \ ." Issuing USB bus reset" cr \ Reset usb-bus(Send reset-signal[50msec] to peripheral device) BUSRST HCTL Hwreg \ Wait until BUSRST is cleared begin HCTL Hrreg BUSRST and if 0 else 1 then until \ Wait some frames before programming any transfers d200 waitframe \ ." enu1 " st? \ Get the device descriptor 8 maxPacketSize W! \ First request goes to address 0 0 PERADDR Hwreg \ ." enu1 " st? 8 Get_Descriptor_Device 6 + C! \ Get_Descriptor_Device[6]=8 low wLength 0 Get_Descriptor_Device 7 + C! \ Get_Descriptor_Device[7]=0 high wLength \ ." First 8 bytes of Device Descriptor" cr \ Get device-descriptor into XfrFata array \ Get_Descriptor_Device 8 0 do C@++ . loop drop cr Get_Descriptor_Device CTL_Read dup \ ." enu2 " st? if print_error else drop \ Show NAK count for data stage/status stage \ ." NAK count:" IN_nak_count W@ . cr XfrData 7 + C@ maxPacketSize W! \ Print_data cr \ ." EP0 maxPacketsize is " maxPacketSize W@ . ." bytes." cr cr \ Issue another USB bus reset" \ ." Issuing USB bus reset" cr \ Reset usb-bus(Send reset-signal[50msec] to peripheral device) BUSRST HCTL Hwreg \ Wait until BUSRST is cleared begin HCTL Hrreg BUSRST and if 0 else 1 then until \ Wait some frames before programming any transfers d200 waitframe \ Set_Address_to_7 ( note:this request goes to address 0,already in PERADDR register) \ ." Setting address to 0x07" cr \ Set_Address_to_7 8 0 do C@++ . loop drop cr Set_Address_to_7 CTL_Write_ND dup if print_error else drop \ Device gets 2msec recovery time d30 waitframe \ now all transfers go to address 7 7 PERADDR Hwreg \ Get device-descriptor at the assigned address XfrData C@ Get_Descriptor_Device 6 + C! \ Get_Descriptor_Device[6] low wLength ." Device Descriptor ( " Get_Descriptor_Device CTL_Read dup if print_error else \ -----------------Device Descriptor ------------------------------------------ drop IN_nak_count W@ . ." NAKS )" cr \ Print_data cr ." Descriptor Size:" 2tab XfrData C@ . cr ." Descriptor Type:" 2tab XfrData 1+ C@ . cr ." USB version:" 3tab XfrData 3 + C@ h30 + emit 2E emit XfrData 2 + C@ . cr ." Device class:" 3tab XfrData 4+ C@ . cr ." Device subclass:" 2tab XfrData 5 + C@ . cr ." Device Protocol:" 2tab XfrData 6 + C@ . cr ." EP0 MaxPacketsize:" 2tab XfrData 7 + C@ . cr ." Vendor ID:" 3tab XfrData 8 + C@ XfrData 9 + C@ h100 u* + . cr ." Product ID:" 3tab XfrData d10 + C@ XfrData d11 + C@ h100 u* + . cr ." Device release:" 3tab XfrData d12 + C@ XfrData d13 + C@ h100 u* + . cr XfrData d14 + C@ iMFG W! XfrData d15 + C@ iPROD W! XfrData d16 + C@ iSERIAL W! XfrData d17 + C@ numConf W! \ Get String Descriptor 0 str 2+ C! \ index 0 is language ID string 0 str 4 + C! \ lang ID is 0 0 str 5 + C! 4 str 6 + C! \ wLengthL 0 str 7 + C! \ wLengthH \ str 8 0 do C@++ . loop drop cr str CTL_Read 0= \ Get lang ID string if \ Check for ACK (could be a STALL if the device has no strings) ." (Language ID String Descriptor is " Print_data ." )" XfrData 2+ C@ str 4 + C! \ LangID-L XfrData 3 + C@ str 5 + C! \ LangID-H hFF str 6 + C! \ now request a really big string else ." (There is no Lang string)" then cr ." Manufacture str index:" 2tab iMFG W@ dup . if iMFG W@ str 2+ C! str CTL_Read drop \ Get Manufacturer ID string print_char then cr ." Product str index:" 2tab iPROD W@ dup . if iPROD W@ str 2+ C! str CTL_Read drop \ Get Product ID string print_char then cr ." Serial number str index:" tab iSERIAL W@ dup . if iSERIAL W@ str 2+ C! str CTL_Read drop \ Get Serial Number ID string print_char then cr ." Number of Configuration:" tab numConf W@ . cr cr cr then \ -----------------Configuration Descriptor ------------------------------------------ ." Configuration Descriptor (" \ Get the 9-byte configuration descriptor \ ." 9Byte Configuration Descriptor ( " 9 Get_Descriptor_Config 6 + C! 0 Get_Descriptor_Config 7 + C! Get_Descriptor_Config CTL_Read dup 0= \ Get config descriptor into XfrData[] if drop IN_nak_count W@ . ." NAKS )" cr \ Print_data \ Get Full length of all descriptor(Config,Interfase,Endpoint,Class) XfrData 2+ C@ Get_Descriptor_Config 6 + C! \ LengthL XfrData 3 + C@ Get_Descriptor_Config 7 + C! \ LengthH Get_Descriptor_Config CTL_Read drop \ Get config descriptor into XfrData[] \ Print_data cr \ optional configuration string XfrData 6 + C@ iCONFIG W! XfrData 7 + C@ Attr W! XfrData 8 + C@ Power W! XfrData h11 + C@ iINTERFACE W! XfrData h19 + C@ XfrData h1A + C@ hFF u* + wDESCLENGTH W! ." Descriptor Size:" 2tab XfrData C@ . cr ." Descriptor Type:" 2tab XfrData 1+ C@ . cr ." TotalLength:" 3tab XfrData 2+ C@ XfrData 3 + C@ d256 u* + . cr ." Number of Interface:" 2tab XfrData 4 + C@ . cr ." Configuration Value:" 2tab XfrData 5 + C@ . cr ." Configuration str index:" tab XfrData 6 + C@ dup . dup 0 <> if str 2+ C! str CTL_Read drop print_char else drop then cr ." Attribute:" 3tab Attr W@ dup . h40 and 0> if ." self-powered " else ." bus powered " then cr ." MaxPower:" 3tab Power W@ dup . 2 u* decimal . hex ." mA" cr cr \ ----------------- Interface Descriptor ------------------------------------------ Get_Descriptor_Config CTL_Read drop \ Print_data cr ." Interface Descriptor " cr ." Descriptor Size:" 2tab XfrData d9 + C@ . cr ." Descriptor Type:" 2tab XfrData d10 + C@ . cr ." Interafce Number:" 2tab XfrData d11 + C@ . cr ." Alternate Setting:" 2tab XfrData d12 + C@ . cr ." Number of EndPoint:" 2tab XfrData d13 + C@ . cr ." Interface Class:" 2tab XfrData d14 + C@ . cr ." Interface SubClass" 2tab XfrData d15 + C@ . cr ." Interface Protpcol:" 2tab XfrData d16 + C@ dup . dup 1 = if drop ." Kwyboard" else 2 = if ." Mouse" then then cr ." Interface str index:" 2tab iINTERFACE W@ dup . dup 0<> if str 2+ C! \ str 8 0 do C@++ . loop drop cr str CTL_Read drop print_char else drop then cr cr \ ----------------- HID Class Descriptor ------------------------------------------ Get_Descriptor_Config CTL_Read drop \ Print_data cr ." HID Class Descriptor " cr ." Descriptors Size:" 2tab XfrData d18 + C@ . cr ." Descriptor Type:" 2tab XfrData d19 + C@ . cr ." HID version:" 3tab XfrData d21 + C@ h30 + emit 2E emit XfrData d20 + C@ . cr ." Cuntry code:" 3tab XfrData d22 + C@ . cr ." Number of Descriptor:" 2tab XfrData d23 + C@ . cr ." Descriptor Type:" 2tab XfrData d24 + C@ . cr ." Descriptor Length" 2tab XfrData d26 + C@ d256 u* XfrData d25 + C@ + dup . decimal . ." bytes" cr hex cr cr \ ----------------- EndPoint Descriptor ------------------------------------------ ." EndPoint Descriptor " cr ." Descriptors Size:" 2tab XfrData d27 + C@ . cr ." Descriptor Type:" 2tab XfrData d28 + C@ . cr ." EndPoint No/dir:" 2tab XfrData d29 + C@ dup . dup 80 and 0<> if ." OUT " else ." IN " then hF and ." EP" . cr ." Attribute:" 3tab XfrData d30 + C@ dup . 0 over = if ." CONTROL" else 1 over = if ." ISOCHRONOUS" else 2 over = if ." BULK" else ." INTERRUPT" then then then drop cr ." MaxPacketSize:" 3tab XfrData d32 + C@ d256 u* XfrData d31 + C@ + dup . dup Size W! decimal . ." bytes" cr hex ." Interval Time:" 3tab XfrData d33 + C@ dup . decimal . ." msec" cr cr then then then ." start" Set_Config CTL_Write_ND dup 0= st? if drop ." Issue SET_CONFIGURATION (" IN_nak_count W@ . ." NAKS )" cr wDESCLENGTH W@ Get_Descriptor 6 + W! \ Get_Descriptor 8 0 do C@++ . loop drop cr Get_Descriptor CTL_Read drop \ dup 0= ." Issue GET_REPORT_DESCRIPTOR (" IN_nak_count W@ . ." NAKS )" cr ." Report Descriptor" cr hex last_transfer_size W@ 0 do XfrData i + C@ dup . 3 and 1 over = if XfrData i + 1+ C@ . i 1+ seti else 2 over = if XfrData i + 1+ C@ . XfrData i + 2 + C@ . i 2 + seti else 3 over = if XfrData i + 1+ C@ . XfrData i + 2 + C@ . XfrData i + 3 + C@ . XfrData i + 4 + C@ . i 4 + seti thens drop cr loop cr decimal begin d10 delms \ ." 1" 1 Size W@ IN_Transfer drop \ st? Size W@ 0 do XfrData i + C@ \ i 0 > \ if \ d128 swap - . \ else . \ then loop cr \ st? fkey? swap drop until else drop then wait_disconnect ; decimal