WangXuan95 / FPGA-USB-Device

An FPGA-based USB full-speed device core to implement USB-serial, USB-camera, USB-audio, USB-hid, etc. It requires only 3 FPGA common IOs rather than additional chips. 基于FPGA的USB full-speed device端控制器,可实现USB串口、USB摄像头、USB音频、U盘、USB键盘等设备,只需要3个FPGA普通IO,而不需要额外的接口芯片。
https://gitee.com/wangxuan95/FPGA-USB-Device
GNU General Public License v3.0
512 stars 83 forks source link

USB differential benefits #24

Open TheAnimatrix opened 3 months ago

TheAnimatrix commented 3 months ago

After reading the source of usb_fs_bitlevel

It is unclear to me why you don't try to merge the P & N lines together for data identification. Instead you only seem to use dpv and last_dp.

sig = p-n, would actually take advantage of differential characteristics whereas you completely ignore the negative part of the differential for data packets.

Also the naming scheme is really unclear. What is dpv ? dpl ? what is L and V ?

TheAnimatrix commented 3 months ago

// high when dpl has atleast one pair of 1's - 110,011,111 (101-X) - low when 000,001,100 //but why is it high for 110 and low for 001, we are transitioning to the opposite state wire dpv = &dpl[3:2] | &dpl[2:1] | dpl[3] & dpl[1];

it's really unclear to me how exactly this works,

TheAnimatrix commented 3 months ago

After having a better look of the code, dpv looks like an "average" over the shifted in values. however, this only really makes sense when you look at in tandem with the condition its used in. Separating the signal from the condition is needless to say bad code, atleast if not indicated through comments or some other means.

churchmice commented 1 month ago

// high when dpl has atleast one pair of 1's - 110,011,111 (101-X) - low when 000,001,100 //but why is it high for 110 and low for 001, we are transitioning to the opposite state wire dpv = &dpl[3:2] | &dpl[2:1] | dpl[3] & dpl[1];

it's really unclear to me how exactly this works,

This is actually a simple voting algorithm. If out of 2 votes for 1, the result is 1. 5 samples are taken for a single usb bit time, and the code uses the middle 3 bits to deduce the value. As for the diffrential issue, this is a simple digital implementation, there is no point to do dp - dn here.