fl \ 2015/01/10 23:20:04 \ Reset usb-bus(Send reset-signal[50msec] to peripheral device) \ ( -- ) : bus_reset ." Issuing USB bus reset" cr BUSRST HCTL MAXreg_wr \ Wait until BUSRST is cleared begin HCTL MAXreg_rd BUSRST and if 0 else 1 then until ." end" HIRQ MAXreg_rd . ; \ Search usb-descriptor \ ( -- ) : usb init_MAX3421E d10 waitframe bus_reset \ Wait some frames before programming any transfers d200 waitframe HIRQ MAXreg_rd . ." waitframe finished" cr \ Get the device descriptor 8 maxPacketSize W! \ First request goes to address 0 0 PERADDR MAXreg_wr 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 CTL_Read dup HIRQ MAXreg_rd . if print_error else drop bus_reset \ Wait some frames before programming any transfers d10 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 CTL_Write_ND dup HIRQ MAXreg_rd . if print_error else drop \ Device gets 2msec recovery time d30 waitframe \ now all transfers go to address 7 7 PERADDR MAXreg_wr \ 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 HIRQ MAXreg_rd . 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 h2E 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 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 then then ;