├── README.md └── docs ├── 0001_USB_Specification.md ├── 0002_EZ-USB_Integrated_Microprocessor.md ├── 0003_Quick_Start.md ├── 0004_Capturing_USB_Traffic.md ├── 0005_Wireshark_GET_DESCRIPTOR_Analyzer.md ├── 0006_CY3684_EZ-USB_FX2LP_DVK.md ├── 0007_Bulkloop_Example.md ├── 0008_HID_Keyboard.md ├── 0009_Wireshare_Filter.md ├── 0010_HID_Keyboard_Modify.md ├── 0011_HID_Compliant_Device.md ├── 0012_CYStream_Compile.md ├── 0013_USB_Descriptors_AlternateSetting.md ├── 0014_Why_StreamExample_Always_Select_Alt6.md ├── 0015_Send_Setup_Packet.md ├── 0016_Isochronous_Transfers.md ├── 0017_Type-C.md ├── 0018_CY7C68013A_FPGA.md ├── 0019_Linux_Compile.md ├── 0020_Keil.md ├── 0021_GPIF.md ├── 0022_Vendor_Command.md ├── 0023_USB_Camera_UVC.md ├── 0024_USB_Keyboard.md ├── images ├── AlternateStting_Interface_Request.png ├── AlternateStting_Interface_Request_With_USB_Control_Center.png ├── Autopointers.png ├── CPU_Control_and_Status_Register.png ├── CY7C68013A_Combinor.jpg ├── CY7C68013A_Register_Debug.png ├── CY7C68013A_Schematic.png ├── CYStream_Code_Arch.png ├── CYStream_Compile.png ├── CySuiteUSB_Download_And_Install.png ├── Download_Program_To_RAM.png ├── Driver_Download_Alone.png ├── EZ-USB_FX2LP_Default_VID_PID.png ├── GPIF_Back2Back_FIFO_Connect.png ├── GPIF_Back2Back_System_ARCH.png ├── Get_AlternateSetting.png ├── HID_Keyboard_Enumerate.png ├── HID_Keyboard_IN_Wireshark.png ├── HID_Keyboard_Interrupt_IN_Data.png ├── HID_Keyboard_Out_Wireshark.png ├── HID_Keyboard_To_HID_Compliant_Device.png ├── HID_Keyboard_To_HID_Compliant_Device_2_Byte.png ├── HID_Keyboard_To_HID_Compliant_Device_Read_Write.png ├── HID_Keyboard_To_HID_Compliant_Device_With_Report_ID.png ├── HID_Keyboard_Wireshark_Filter.png ├── Isochronous_Data_IN.png ├── Isochronous_Data_OUT.png ├── Keil_Bulk_Example_Sample_Device.png ├── Keil_Bulk_Example_Sample_Device_In_Control_Center.png ├── Keil_Bulk_Example_Sample_Device_In_Control_Center_In.png ├── Keil_Bulk_Example_Sample_Device_In_Control_Center_Out.png ├── Keil_Components.png ├── Keil_Environment.png ├── PB02_As_INPUT_Background.jpg ├── PB02_As_OUTPUT_Background.jpg ├── Set_AlternateSetting.png ├── Set_Keil_Project_Environment_Item.png ├── Set_Keil_Project_Environment_With_Build_Info.png ├── StreamExample_Always_Select_Alt6.png ├── USB_Analyzer.png ├── USB_Control_Center.png ├── UVC_USB_Get_Buffer.svg ├── UnknowDevice_Detect.png ├── UnknowDevice_To_Cypress_FX2LP_No_EEPROM_Device.png ├── Vendor_Commands.png └── WireShark_USB_Capture.png └── refers ├── 001-13670_EZ-USB_Technical_Reference_Manual.pdf ├── 001-88669_AN65209_Getting_Started_with_FX2LP_Chinese.pdf ├── SimpleHIDWrite3.zip ├── USB_HID_Keyboard_Firmware.pdf ├── USB_Video_Class_1.1.pdf └── UVC 1.5 Class specification.pdf /README.md: -------------------------------------------------------------------------------- 1 | # USB 2 | 3 | 之前有看过几次USB方面的书,也移植过USB驱动,不过一直也没什么时间投入来研究USB底层通信里面的东西,这次打算花点时间系统性刨根究底的分析一次。 4 | 5 | ## 参考文档 6 | 7 | * [EZ-USB FX2LP CY7C68013A USB 开发板 逻辑分析仪YourCee](https://item.taobao.com/item.htm?spm=a230r.1.14.34.36aa2429c1z3Fr&id=522553287560&ns=1&abbucket=6#detail) 8 | * [CY7C68013A-56PVXC](http://www.cypress.com/part/cy7c68013a-56pvxc) 9 | * [AN65209 - Getting Started with FX2LP™](http://www.cypress.com/documentation/application-notes/an65209-getting-started-fx2lp) 10 | * [AN65209 Getting Started with FX2LP(Chinese).pdf](http://www.cypress.com/file/44946/download) 11 | * [CY3684 EZ-USB FX2LP Development Kit](http://www.cypress.com/documentation/development-kitsboards/cy3684-ez-usb-fx2lp-development-kit) 12 | * [EZ-USB® Technical Reference Manual](http://www.cypress.com/documentation/technical-reference-manuals/ez-usb-technical-reference-manual) 13 | * [SuiteUSB 3.4 - USB Development tools for Visual Studio](http://www.cypress.com/documentation/software-and-drivers/suiteusb-34-usb-development-tools-visual-studio) 14 | * [Drivers for EZ-USB® FX1™, FX2LP™ , and FX3 - KBA94413](https://community.cypress.com/docs/DOC-12366) 15 | * [USB Hi-Speed Code Examples](http://www.cypress.com/documentation/code-examples/usb-hi-speed-code-examples) 16 | * [USB Type-C™ and Power Delivery Minidock With Video and Charging Support Reference Design](http://www.ti.com/tool/TIDA-01243?tdsourcetag=s_pcqq_aiomsg) 17 | 18 | ## 开发工具、示例 19 | 20 | [CY3684 EZ-USB FX2LP DVK Setup (Kit Design Files, Kiel IDE,GPIF Designer, Host applications, Documentation, Examples)](http://www.cypress.com/file/135301) 21 | 22 | ## Schematic 23 | 24 | ![docs/images/CY7C68013A_Schematic.png](docs/images/CY7C68013A_Schematic.png) 25 | 26 | ## 笔记文档 27 | 28 | * [0024_USB_Keyboard.md](docs/0024_USB_Keyboard.md) 29 | * [0023_USB_Camera_UVC.md](docs/0023_USB_Camera_UVC.md) 30 | * [0022_Vendor_Command.md](docs/0022_Vendor_Command.md) 31 | * [0021_GPIF.md](docs/0021_GPIF.md) 32 | * [0020_Keil.md](docs/0020_Keil.md) 33 | * [0019_Linux_Compile.md](docs/0019_Linux_Compile.md) 34 | * [0018_CY7C68013A_FPGA.md](docs/0018_CY7C68013A_FPGA.md) 35 | * [0017_Type-C.md](docs/0017_Type-C.md) 36 | * [0016_Isochronous_Transfers.md](docs/0016_Isochronous_Transfers.md) 37 | * [0015_Send_Setup_Packet.md](docs/0015_Send_Setup_Packet.md) 38 | * [0014_Why_StreamExample_Always_Select_Alt6.md](docs/0014_Why_StreamExample_Always_Select_Alt6.md) 39 | * [0013_USB_Descriptors_AlternateSetting.md](docs/0013_USB_Descriptors_AlternateSetting.md) 40 | * [0012_CYStream_Compile.md](docs/0012_CYStream_Compile.md) 41 | * [0011_HID_Compliant_Device.md](docs/0011_HID_Compliant_Device.md) 42 | * [0010_HID_Keyboard_Modify.md](docs/0010_HID_Keyboard_Modify.md) 43 | * [0009_Wireshare_Filter.md](docs/0009_Wireshare_Filter.md) 44 | * [0008_HID_Keyboard.md](docs/0008_HID_Keyboard.md) 45 | * [0007_Bulkloop_Example.md](docs/0007_Bulkloop_Example.md) 46 | * [0006_CY3684_EZ-USB_FX2LP_DVK.md](docs/0006_CY3684_EZ-USB_FX2LP_DVK.md) 47 | * [0005_Wireshark_GET_DESCRIPTOR_Analyzer.md](docs/0005_Wireshark_GET_DESCRIPTOR_Analyzer.md) 48 | * [0004_Capturing_USB_Traffic.md](docs/0004_Capturing_USB_Traffic.md) 49 | * [0003_Quick_Start.md](docs/0003_Quick_Start.md) 50 | * [0002_EZ-USB_Integrated_Microprocessor.md](docs/0002_EZ-USB_Integrated_Microprocessor.md) 51 | * [0001_USB_Specification.md](docs/0001_USB_Specification.md) 52 | -------------------------------------------------------------------------------- /docs/0001_USB_Specification.md: -------------------------------------------------------------------------------- 1 | # USB Specification 2 | 3 | ## 参考文档 4 | 5 | * [EZ-USB® Technical Reference Manual](http://www.cypress.com/documentation/technical-reference-manuals/ez-usb-technical-reference-manual)——1.2 The USB Specification 6 | 7 | ## 简要 8 | 9 | * USB分master(Host)、slave,输入(IN)输出(OUT)端点是站在Master的角度来定义的; 10 | * 除了USB远程唤醒以外,所有的操作均是由USB Master发起; 11 | * USB通信的时候和I2C通信的时候数据方式类似: 12 | * 站在地址、数据、响应三个阶段进行分析; 13 | * USB Token相当于I2C发送地址阶段,当然功能不止于I2C地址那么简单; 14 | * USB Data相当于I2C发送数据阶段,当然功能不止于I2C数据那么简单; 15 | * USB Handshake相当于I2C发送响应阶段,当然功能不止于I2C响应那么简单; 16 | * 由于USB比I2C功能更完善,不过思维模型可以从I2C上借鉴; 17 | * DATA0/DATA1出现原因是为了防止握手数据包出错; 18 | * SETUP tokens是控制命令,8 Bytes; 19 | * SOF在全速模式和高速模式下不一样; 20 | * Host发送数据: 21 | * OUT token packet; 22 | * Data packet 23 | * handshake packet; 24 | * ACK; 25 | * NAK; (host re-sends the data at a later time) 26 | * Back nothing; (host re-sends the data at a later time) 27 | * Host接收数据: 28 | * Salve从来不会主动发送数据给主设备,除了远程唤醒功能; 29 | * 和HOST发送数据类似 30 | * USB Frames(SOF),不管是全速、高速,都是1ms计数一次,高速1ms中的8次计数不会增加,可以用于数据同步; 31 | * 传输方式: 32 | * Bulk传输:8/16/32/64 Bytes全速,512 Bytes高速,Host在适当的时候进行数据发送; 33 | * Interrupt传输:64 Bytes全速,1024Byte高速,实时性相对高的场合; 34 | * Isochronous传输:实时性要求比较高的场合,音视频流,1023 Bytes全速,1024 Bytes高速,没有handshake,不使用数据切换机制; 35 | * Control传输: 36 | * SETUP阶段; 37 | * 数据阶段(可选); 38 | * 状态阶段; 39 | * 除了Control传输,前面都是针对应用场合,控制传输是在设备配置阶段进行处理的; 40 | * USB枚举: 41 | * 首先硬件、固件正常情况下; 42 | * USB设备插入Host,使用USB Host的默认地址0; 43 | * USB Host通过默认地址发送获取设备描述符请求,控制指令; 44 | * USB设备反馈ID数据给USB Host; 45 | * USB Host分配一个唯一的地址并发送给USB设备,控制指令; 46 | * USB Host获取全部的描述符,从而知道设备端点数、供电、带宽以及需要什么驱动; 47 | * Serial Interface Engine(SIE) 48 | * 每个USB设备都有SIE; 49 | * SIE主要进行数据编解码USB总线上的数据包; 50 | * 自动获取PID,数据校验,提取数据; 51 | * 会自动处理handshake; 52 | * Endpoint 53 | * Since USB is a serial bus, a device endpoint is actually a FIFO which sequentially empties or fills with USB data bytes. 54 | * 最大4 bit地址 + 1 bit方向位,最多32个Endpoint IN和OUT; 55 | * From the EZ-USB’s point of view, an endpoint is a buffer full of bytes received or held for transmission over the bus. The EZ-USB reads host data from an OUT endpoint buffer, and writes data for transmission to the host to an IN endpoint buffer. 56 | * EZ-USB contains three 64-byte endpoint buffers, plus 4 KB of buffer space that can be configured 12 ways. The three 64-byte buffers are common to all configurations. 57 | * The three 64-byte buffers are designated EP0, EP1IN and EP1OUT. EP0 is the default CONTROL endpoint, a bidirectional endpoint that uses a single 64-byte buffer for both IN and OUT data. EZ-USB firmware reads or fills the EP0 buffer when the (optional) data stage of a CONTROL transfer is required. 58 | * **Note** The eight SETUP bytes in a CONTROL transfer do not appear in the 64-byte EP0 endpoint buffer. Instead, to simplify programming, the EZ-USB automatically stores the eight SETUP bytes in a separate buffer (SETUPDAT, at 0xE6B8-0xE6BF). 59 | * EP1IN and EP1OUT use separate 64 byte buffers. EZ-USB firmware can configure these endpoints as BULK or INTERRUPT. These endpoints, as well as EP0, are accessible only by EZ-USB firmware. This is in contrast to the large endpoint buffers EP2, EP4, EP6 and EP8, which are designed to move high bandwidth data directly on and off chip without firmware intervention. 60 | 61 | -------------------------------------------------------------------------------- /docs/0002_EZ-USB_Integrated_Microprocessor.md: -------------------------------------------------------------------------------- 1 | # EZ-USB Integrated Microprocessor 2 | 3 | ## 参考文档 4 | 5 | * [EZ-USB® Technical Reference Manual](http://www.cypress.com/documentation/technical-reference-manuals/ez-usb-technical-reference-manual) 6 | 7 | ## EZ-USB Integrated Microprocessor 8 | 9 | * 16KB Pgm/Data RAM就认为是ROM比较合适(程序从EEPROM来),然后只有0.5K RAM和4KB的Endpoint RAM; 10 | * The CPU communicates with the SIE using a set of registers occupying on-chip RAM addresses 0xE500-0xE6FF. These registers are grouped and described by function in individual chapters of this reference manual and summarized in register order. 11 | * The EZ-USB chips add eight interrupt sources to the standard 8051 interrupt system: 12 | * INT2: USB Interrupt 13 | * INT3: I2C Bus Interrupt 14 | * INT4: FIFO/GPIF Interrupt 15 | * INT4: External Interrupt 4 16 | * INT5: External Interrupt 5 17 | * INT6: External Interrupt 6 18 | * USART1: USART1 Interrupt 19 | * WAKEUP: USB Resume Interrupt 20 | * The EZ-USB chips provide 27 individual USB-interrupt sources which share the INT2 interrupt, and 14 individual FIFO/GPIF-interrupt sources which share the INT4 interrupt. 21 | -------------------------------------------------------------------------------- /docs/0003_Quick_Start.md: -------------------------------------------------------------------------------- 1 | # Quick Start 2 | 3 | ## 参考文档 4 | 5 | * [AN65209 Getting Started with FX2LP(Chinese).pdf](http://www.cypress.com/file/44946/download) 6 | * [CY3684 DVK Quick Start Guide (Chinese).pdf](http://www.cypress.com/file/393081/download) 7 | * [Drivers for EZ-USB® FX1™, FX2LP™ , and FX3 - KBA94413](https://community.cypress.com/docs/DOC-12366) 8 | 9 | ## Plugin Device 10 | 11 | ![./images/UnknowDevice_Detect.png](./images/UnknowDevice_Detect.png) 12 | 13 | `USB\VID_04B4&PID_8613\6&3799B1B1&0&4` 14 | ![images/EZ-USB_FX2LP_Default_VID_PID.png](images/EZ-USB_FX2LP_Default_VID_PID.png) 15 | 16 | ## Download SuiteUSB And Install Driver 17 | 18 | * [SuiteUSB 3.4 - USB Development tools for Visual Studio](http://www.cypress.com/documentation/software-and-drivers/suiteusb-34-usb-development-tools-visual-studio) 19 | ![./images/CySuiteUSB_Download_And_Install.png](./images/CySuiteUSB_Download_And_Install.png) 20 | * [Drivers for EZ-USB® FX1™, FX2LP™ , and FX3 - KBA94413](https://community.cypress.com/docs/DOC-12366) 21 | ![./images/Driver_Download_Alone.png](./images/Driver_Download_Alone.png) 22 | 23 | ![./images/UnknowDevice_To_Cypress_FX2LP_No_EEPROM_Device.png](./images/UnknowDevice_To_Cypress_FX2LP_No_EEPROM_Device.png) 24 | 25 | ## USB Control Center 26 | 27 | * `/CyUSB.NET/bin/CyControl.exe`; 28 | ![./images/USB_Control_Center.png](./images/USB_Control_Center.png) 29 | 30 | ``` 31 | 32 | FriendlyName="Cypress FX2LP No EEPROM Device" 33 | Manufacturer="" 34 | Product="" 35 | SerialNumber="" 36 | Configurations="1" 37 | MaxPacketSize="64" 38 | VendorID="04 B4" 39 | ProductID="86 13" 40 | Class="FFh" 41 | SubClass="FFh" 42 | Protocol="FFh" 43 | BcdDevice="A0 01" 44 | BcdUSB="02 00" 45 | 46 | Configuration="0" 47 | ConfigurationValue="1" 48 | Attributes="80h" 49 | Interfaces="1" 50 | DescriptorType="2" 51 | DescriptorLength="9" 52 | TotalLength="171" 53 | MaxPower="50" 54 | 55 | Interface="0" 56 | InterfaceNumber="0" 57 | AltSetting="0" 58 | Class="FFh" 59 | Subclass="FFh" 60 | Protocol="255" 61 | Endpoints="0" 62 | DescriptorType="4" 63 | DescriptorLength="9" 64 | 65 | 66 | Interface="0" 67 | InterfaceNumber="0" 68 | AltSetting="1" 69 | Class="FFh" 70 | Subclass="FFh" 71 | Protocol="255" 72 | Endpoints="6" 73 | DescriptorType="4" 74 | DescriptorLength="9" 75 | 76 | Type="BULK" 77 | Direction="OUT" 78 | Address="01h" 79 | Attributes="02h" 80 | MaxPktSize="512" 81 | DescriptorType="5" 82 | DescriptorLength="7" 83 | Interval="0" 84 | 85 | 86 | Type="BULK" 87 | Direction="IN" 88 | Address="81h" 89 | Attributes="02h" 90 | MaxPktSize="512" 91 | DescriptorType="5" 92 | DescriptorLength="7" 93 | Interval="0" 94 | 95 | 96 | Type="BULK" 97 | Direction="OUT" 98 | Address="02h" 99 | Attributes="02h" 100 | MaxPktSize="512" 101 | DescriptorType="5" 102 | DescriptorLength="7" 103 | Interval="0" 104 | 105 | 106 | Type="BULK" 107 | Direction="OUT" 108 | Address="04h" 109 | Attributes="02h" 110 | MaxPktSize="512" 111 | DescriptorType="5" 112 | DescriptorLength="7" 113 | Interval="0" 114 | 115 | 116 | Type="BULK" 117 | Direction="IN" 118 | Address="86h" 119 | Attributes="02h" 120 | MaxPktSize="512" 121 | DescriptorType="5" 122 | DescriptorLength="7" 123 | Interval="0" 124 | 125 | 126 | Type="BULK" 127 | Direction="IN" 128 | Address="88h" 129 | Attributes="02h" 130 | MaxPktSize="512" 131 | DescriptorType="5" 132 | DescriptorLength="7" 133 | Interval="0" 134 | 135 | 136 | 137 | Interface="0" 138 | InterfaceNumber="0" 139 | AltSetting="2" 140 | Class="FFh" 141 | Subclass="FFh" 142 | Protocol="255" 143 | Endpoints="6" 144 | DescriptorType="4" 145 | DescriptorLength="9" 146 | 147 | Type="INTERRUPT" 148 | Direction="OUT" 149 | Address="01h" 150 | Attributes="03h" 151 | MaxPktSize="64" 152 | DescriptorType="5" 153 | DescriptorLength="7" 154 | Interval="1" 155 | 156 | 157 | Type="INTERRUPT" 158 | Direction="IN" 159 | Address="81h" 160 | Attributes="03h" 161 | MaxPktSize="64" 162 | DescriptorType="5" 163 | DescriptorLength="7" 164 | Interval="1" 165 | 166 | 167 | Type="INTERRUPT" 168 | Direction="OUT" 169 | Address="02h" 170 | Attributes="03h" 171 | MaxPktSize="512" 172 | DescriptorType="5" 173 | DescriptorLength="7" 174 | Interval="1" 175 | 176 | 177 | Type="BULK" 178 | Direction="OUT" 179 | Address="04h" 180 | Attributes="02h" 181 | MaxPktSize="512" 182 | DescriptorType="5" 183 | DescriptorLength="7" 184 | Interval="0" 185 | 186 | 187 | Type="INTERRUPT" 188 | Direction="IN" 189 | Address="86h" 190 | Attributes="03h" 191 | MaxPktSize="512" 192 | DescriptorType="5" 193 | DescriptorLength="7" 194 | Interval="1" 195 | 196 | 197 | Type="BULK" 198 | Direction="IN" 199 | Address="88h" 200 | Attributes="02h" 201 | MaxPktSize="512" 202 | DescriptorType="5" 203 | DescriptorLength="7" 204 | Interval="0" 205 | 206 | 207 | 208 | Interface="0" 209 | InterfaceNumber="0" 210 | AltSetting="3" 211 | Class="FFh" 212 | Subclass="FFh" 213 | Protocol="255" 214 | Endpoints="6" 215 | DescriptorType="4" 216 | DescriptorLength="9" 217 | 218 | Type="INTERRUPT" 219 | Direction="OUT" 220 | Address="01h" 221 | Attributes="03h" 222 | MaxPktSize="64" 223 | DescriptorType="5" 224 | DescriptorLength="7" 225 | Interval="1" 226 | 227 | 228 | Type="INTERRUPT" 229 | Direction="IN" 230 | Address="81h" 231 | Attributes="03h" 232 | MaxPktSize="64" 233 | DescriptorType="5" 234 | DescriptorLength="7" 235 | Interval="1" 236 | 237 | 238 | Type="ISOC" 239 | Direction="OUT" 240 | Address="02h" 241 | Attributes="01h" 242 | MaxPktSize="512" 243 | DescriptorType="5" 244 | DescriptorLength="7" 245 | Interval="1" 246 | 247 | 248 | Type="BULK" 249 | Direction="OUT" 250 | Address="04h" 251 | Attributes="02h" 252 | MaxPktSize="512" 253 | DescriptorType="5" 254 | DescriptorLength="7" 255 | Interval="0" 256 | 257 | 258 | Type="ISOC" 259 | Direction="IN" 260 | Address="86h" 261 | Attributes="01h" 262 | MaxPktSize="512" 263 | DescriptorType="5" 264 | DescriptorLength="7" 265 | Interval="1" 266 | 267 | 268 | Type="BULK" 269 | Direction="IN" 270 | Address="88h" 271 | Attributes="02h" 272 | MaxPktSize="512" 273 | DescriptorType="5" 274 | DescriptorLength="7" 275 | Interval="0" 276 | 277 | 278 | 279 | 280 | ``` 281 | 282 | ## Download To RAM 283 | 284 | * Select Download to RAM: 285 | ![./images/Download_Program_To_RAM.png](./images/Download_Program_To_RAM.png) 286 | * Select hex file will be auto programed to RAM; 287 | -------------------------------------------------------------------------------- /docs/0004_Capturing_USB_Traffic.md: -------------------------------------------------------------------------------- 1 | # Capturing USB Traffic 2 | 3 | ## 参考文档 4 | 5 | * [USB枚举过程详细分析](https://wenku.baidu.com/view/ffa4f33a227916888486d7a4.html) 6 | * [wireshark usb traces explanations](https://superuser.com/questions/873896/wireshark-usb-traces-explanations) 7 | * [USB Request Blocks (URBs)](https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/communicating-with-a-usb-device) 8 | 9 | ## Free USB Analyzer 10 | 11 | * Download:https://freeusbanalyzer.com/ 12 | 13 | ![./images/USB_Analyzer.png](./images/USB_Analyzer.png) 14 | 15 | ## Wireshark 16 | 17 | Download:https://www.wireshark.org/download.html 18 | 19 | **Note**:安装的时候要选择安装USB支持包,默认不安装USB支持包 20 | 21 | ![./images/WireShark_USB_Capture.png](./images/WireShark_USB_Capture.png) 22 | 23 | ## 枚举流程分析 24 | 25 | * USB枚举阶段分三个过程: 26 | * 获取设备描述符; 27 | * 设置地址; 28 | * 获取所有描述符; 29 | * 从目前的抓包工具获取的数据来看,能抓到的都是第三个阶段的数据,前面两个阶段的数据目前貌似无法通过工具获取到; 30 | 31 | ## URB(USB Request Block) 32 | 33 | * A USB URB is like an IP packet and a USB endpoint is like an IP port. USB endpoints 0x00-0x7F are on the host, and the endpoints 0x80-0xFF are on the device. Therefore, the endpoint encodes the direction of the transfer; 34 | * 一个urb包含了执行usb传输所需要的所有信息。当要进行数据传输时,需要分配一个urb结构体,对其进行初始化,然后将其提交给usb核心。USB核心对urb进行解析,将控制信息提交给主机控制器,由主机控制器负责数据到设备的传输。这时,驱动程序只需等待,当数据回传到主机控制器后,会转发给USB核心,唤醒等待的驱动程序,由驱动程序完成剩下的工作; 35 | * 一个URB相当于一次USB总线实际数据传输,不过在设备总,能看到的不过是中断/IN/OUT端点数据; 36 | -------------------------------------------------------------------------------- /docs/0005_Wireshark_GET_DESCRIPTOR_Analyzer.md: -------------------------------------------------------------------------------- 1 | # Wireshark GET DESCRIPTOR Analyzer 2 | 3 | **纯个人想法**: 4 | * URB可以认为是保证数据传送到对应的设备的数据格式,相当于总线仲裁数据; 5 | * 我们一般说的数据分析USB协议分析,分析的是实际到设备以后的数据包,这里就是SETUP包、DATA0、DATA1、响应包等; 6 | 7 | ## GET DESCRIPTOR Request DEVICE 8 | * raw data: 9 | ``` 10 | 0000 1c 00 f0 7a 0f a1 05 ac ff ff 00 00 00 00 0b 00 ..ðz.¡.¬ÿÿ...... 11 | 0010 00 01 00 28 00 00 02 08 00 00 00 00 80 06 00 01 ...(............ 12 | 0020 00 00 12 00 .... 13 | ``` 14 | * data analyzer: 15 | ``` 16 | Frame 2903: 36 bytes on wire (288 bits), 36 bytes captured (288 bits) on interface 0 17 | USB URB 18 | [Source: host] 19 | [Destination: 1.40.0] 20 | USBPcap pseudoheader length: 28 21 | IRP ID: 0xffffac05a10f7af0 22 | IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000) 23 | URB Function: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE (0x000b) 24 | IRP information: 0x00, Direction: FDO -> PDO 25 | 0000 000. = Reserved: 0x00 26 | .... ...0 = Direction: FDO -> PDO (0x0) 27 | URB bus id: 1 28 | Device address: 40 29 | Endpoint: 0x00, Direction: OUT 30 | 0... .... = Direction: OUT (0) 31 | .... 0000 = Endpoint number: 0 32 | URB transfer type: URB_CONTROL (0x02) 33 | Packet Data Length: 8 34 | [Response in: 2904] 35 | Control transfer stage: Setup (0) 36 | URB setup 37 | bmRequestType: 0x80 38 | 1... .... = Direction: Device-to-host 39 | .00. .... = Type: Standard (0x0) 40 | ...0 0000 = Recipient: Device (0x00) 41 | bRequest: GET DESCRIPTOR (6) 42 | Descriptor Index: 0x00 43 | bDescriptorType: 0x01 44 | Language Id: no language specified (0x0000) 45 | wLength: 18 46 | ``` 47 | 48 | ## GET DESCRIPTOR Response DEVICE 49 | * raw data: 50 | ``` 51 | 0000 1c 00 f0 7a 0f a1 05 ac ff ff 00 00 00 00 08 00 ..ðz.¡.¬ÿÿ...... 52 | 0010 01 01 00 28 00 80 02 12 00 00 00 01 12 01 00 02 ...(............ 53 | 0020 ff ff ff 40 b4 04 13 86 01 a0 00 00 00 01 ÿÿÿ@´.... .... 54 | ``` 55 | * data analyzer: 56 | ``` 57 | Frame 2904: 46 bytes on wire (368 bits), 46 bytes captured (368 bits) on interface 0 58 | USB URB 59 | [Source: 1.40.0] 60 | [Destination: host] 61 | USBPcap pseudoheader length: 28 62 | IRP ID: 0xffffac05a10f7af0 63 | IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000) 64 | URB Function: URB_FUNCTION_CONTROL_TRANSFER (0x0008) 65 | IRP information: 0x01, Direction: PDO -> FDO 66 | 0000 000. = Reserved: 0x00 67 | .... ...1 = Direction: PDO -> FDO (0x1) 68 | URB bus id: 1 69 | Device address: 40 70 | Endpoint: 0x80, Direction: IN 71 | 1... .... = Direction: IN (1) 72 | .... 0000 = Endpoint number: 0 73 | URB transfer type: URB_CONTROL (0x02) 74 | Packet Data Length: 18 75 | [Request in: 2903] 76 | [Time from request: 0.000115000 seconds] 77 | Control transfer stage: Data (1) 78 | DEVICE DESCRIPTOR 79 | bLength: 18 80 | bDescriptorType: 0x01 (DEVICE) 81 | bcdUSB: 0x0200 82 | bDeviceClass: Vendor Specific (0xff) 83 | bDeviceSubClass: 255 84 | bDeviceProtocol: 255 85 | bMaxPacketSize0: 64 86 | idVendor: Cypress Semiconductor Corp. (0x04b4) 87 | idProduct: CY7C68013 EZ-USB FX2 USB 2.0 Development Kit (0x8613) 88 | bcdDevice: 0xa001 89 | iManufacturer: 0 90 | iProduct: 0 91 | iSerialNumber: 0 92 | bNumConfigurations: 1 93 | ``` 94 | 95 | ## GET DESCRIPTOR Status 96 | 97 | * raw data: 98 | ``` 99 | 0000 1c 00 f0 7a 0f a1 05 ac ff ff 00 00 00 00 08 00 ..ðz.¡.¬ÿÿ...... 100 | 0010 01 01 00 28 00 80 02 00 00 00 00 02 ...(........ 101 | ``` 102 | * data analyzer: 103 | ``` 104 | Frame 2905: 28 bytes on wire (224 bits), 28 bytes captured (224 bits) on interface 0 105 | USB URB 106 | [Source: 1.40.0] 107 | [Destination: host] 108 | USBPcap pseudoheader length: 28 109 | IRP ID: 0xffffac05a10f7af0 110 | IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000) 111 | URB Function: URB_FUNCTION_CONTROL_TRANSFER (0x0008) 112 | IRP information: 0x01, Direction: PDO -> FDO 113 | 0000 000. = Reserved: 0x00 114 | .... ...1 = Direction: PDO -> FDO (0x1) 115 | URB bus id: 1 116 | Device address: 40 117 | Endpoint: 0x80, Direction: IN 118 | 1... .... = Direction: IN (1) 119 | .... 0000 = Endpoint number: 0 120 | URB transfer type: URB_CONTROL (0x02) 121 | Packet Data Length: 0 122 | [Request in: 2903] 123 | [Time from request: 0.000116000 seconds] 124 | Control transfer stage: Status (2) 125 | ``` 126 | -------------------------------------------------------------------------------- /docs/0006_CY3684_EZ-USB_FX2LP_DVK.md: -------------------------------------------------------------------------------- 1 | # CY3684 EZ-USB FX2LP DVK 2 | 3 | 配置Firmware开发环境,使用Keil UV2进行开发,不过需要配置环境才能使用,而不是安装完成了直接能够使用,目前是在Windows 10上进行配置环境是OK,说明在Windows 10上可以正常工作。 4 | 5 | ## Download 6 | 7 | [CY3684 EZ-USB FX2LP DVK Setup (Kit Design Files, Kiel IDE,GPIF Designer, Host applications, Documentation, Examples)](http://www.cypress.com/file/135301) 8 | 9 | 安装的时候貌似如果选了C盘的话,Keil会需要指定路径,如果不是C盘,不需要指定的样子; 10 | 11 | ## 参考文档 12 | 13 | * Firmware Readme(根据自己的安装目录查看):`C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Firmware\Readme.txt` 14 | 15 | ## 配置Keil Firmware开发环境 16 | 17 | * 选择配置项目环境: 18 | ![./images/Set_Keil_Project_Environment_Item.png](./images/Set_Keil_Project_Environment_Item.png) 19 | * 配置项目环境及编译输出: 20 | ![./images/Set_Keil_Project_Environment_With_Build_Info.png](./images/Set_Keil_Project_Environment_With_Build_Info.png) 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/0007_Bulkloop_Example.md: -------------------------------------------------------------------------------- 1 | # Bulkloop Example 2 | 3 | ## Code Position 4 | 5 | 代码位置(根据自己的安装目录查看):`C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Firmware\Bulkloop` 6 | 7 | ## 参考文档 8 | 9 | * 文档位置(根据自己的安装目录查看):`C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Documentation\EZ-USB(R) Development Kit User Guide.pdf` 10 | * [Getting Start with example Bulkloop fail](https://community.cypress.com/thread/13140): To avoid this problem, the following two lines implemented in the firmware must be commented out. 11 | ```C 12 | EZUSB_WriteI2C(LED_ADDR, 0x01, &(Digit[AlternateSetting])); 13 | EZUSB_WaitForEEPROMWrite(LED_ADDR); 14 | ``` 15 | * [Absolute Variable Location](http://www.keil.com/support/man/docs/c51/c51_le_absvarloc.htm) 16 | * [EZ-USB® FX2LP™中的中断处理](https://www.cypress.com/file/202956/download) 17 | 18 | ## 修改源代码 19 | 20 | * `C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Firmware\Bulkloop\Fx2.h`:不知道为什么Keil编辑器里打不开,要另外用文本编辑器打开 21 | ```C 22 | [...省略] 23 | // #define ENABLE_7_SEG_DISPLAY 24 | extern int start_7_seg_display; 25 | [...省略] 26 | ``` 27 | 28 | ## Device Bulkloop Test 29 | 30 | * 设备管理器查看设备 31 | ![./images/Keil_Bulk_Example_Sample_Device.png](./images/Keil_Bulk_Example_Sample_Device.png) 32 | * 查看设备枚举信息 33 | ![./images/Keil_Bulk_Example_Sample_Device_In_Control_Center.png](./images/Keil_Bulk_Example_Sample_Device_In_Control_Center.png) 34 | * Bulk Out 35 | ![./images/Keil_Bulk_Example_Sample_Device_In_Control_Center_Out.png](./images/Keil_Bulk_Example_Sample_Device_In_Control_Center_Out.png) 36 | * Bulk In 37 | ![./images/Keil_Bulk_Example_Sample_Device_In_Control_Center_In.png](./images/Keil_Bulk_Example_Sample_Device_In_Control_Center_In.png) 38 | 39 | ## 设备描述符dscr.a51 40 | 41 | * Descriptor Info 42 | ```XML 43 | 44 | FriendlyName="Cypress FX2LP Sample Device" 45 | Manufacturer="Cypress" 46 | Product="EZ-USB" 47 | SerialNumber="" 48 | Configurations="1" 49 | MaxPacketSize="64" 50 | VendorID="04 B4" 51 | ProductID="10 04" 52 | Class="00h" 53 | SubClass="00h" 54 | Protocol="00h" 55 | BcdDevice="00 00" 56 | BcdUSB="02 00" 57 | 58 | Configuration="0" 59 | ConfigurationValue="1" 60 | Attributes="80h" 61 | Interfaces="1" 62 | DescriptorType="2" 63 | DescriptorLength="9" 64 | TotalLength="32" 65 | MaxPower="50" 66 | 67 | Interface="0" 68 | InterfaceNumber="0" 69 | AltSetting="0" 70 | Class="FFh" 71 | Subclass="00h" 72 | Protocol="0" 73 | Endpoints="2" 74 | DescriptorType="4" 75 | DescriptorLength="9" 76 | 77 | Type="BULK" 78 | Direction="OUT" 79 | Address="02h" 80 | Attributes="02h" 81 | MaxPktSize="512" 82 | DescriptorType="5" 83 | DescriptorLength="7" 84 | Interval="0" 85 | 86 | 87 | Type="BULK" 88 | Direction="IN" 89 | Address="86h" 90 | Attributes="02h" 91 | MaxPktSize="512" 92 | DescriptorType="5" 93 | DescriptorLength="7" 94 | Interval="0" 95 | 96 | 97 | 98 | 99 | ``` 100 | * Source Code 101 | ```ASM 102 | ;;----------------------------------------------------------------------------- 103 | ;; File: dscr.a51 104 | ;; Contents: This file contains descriptor data tables. 105 | ;; 106 | ;; $Archive: /USB/Examples/Fx2lp/bulkloop/dscr.a51 $ 107 | ;; $Date: 9/01/03 8:51p $ 108 | ;; $Revision: 3 $ 109 | ;; 110 | ;; 111 | ;;----------------------------------------------------------------------------- 112 | ;; Copyright 2003, Cypress Semiconductor Corporation 113 | ;;-----------------------------------------------------------------------------;;----------------------------------------------------------------------------- 114 | 115 | ;; 相当于是宏定义 116 | DSCR_DEVICE equ 1 ;; Descriptor type: Device 117 | DSCR_CONFIG equ 2 ;; Descriptor type: Configuration 118 | DSCR_STRING equ 3 ;; Descriptor type: String 119 | DSCR_INTRFC equ 4 ;; Descriptor type: Interface 120 | DSCR_ENDPNT equ 5 ;; Descriptor type: Endpoint 121 | DSCR_DEVQUAL equ 6 ;; Descriptor type: Device Qualifier 122 | 123 | DSCR_DEVICE_LEN equ 18 124 | DSCR_CONFIG_LEN equ 9 125 | DSCR_INTRFC_LEN equ 9 126 | DSCR_ENDPNT_LEN equ 7 127 | DSCR_DEVQUAL_LEN equ 10 128 | 129 | ET_CONTROL equ 0 ;; Endpoint type: Control 130 | ET_ISO equ 1 ;; Endpoint type: Isochronous 131 | ET_BULK equ 2 ;; Endpoint type: Bulk 132 | ET_INT equ 3 ;; Endpoint type: Interrupt 133 | 134 | public DeviceDscr, DeviceQualDscr, HighSpeedConfigDscr, FullSpeedConfigDscr, StringDscr, UserDscr 135 | 136 | DSCR SEGMENT CODE PAGE 137 | 138 | ;;----------------------------------------------------------------------------- 139 | ;; Global Variables 140 | ;;----------------------------------------------------------------------------- 141 | rseg DSCR ;; locate the descriptor table in on-part memory. 142 | 143 | ;; db/dw解释 144 | ;; http://www.keil.com/support/man/docs/a51/a51_st_db.htm 145 | DeviceDscr: 146 | db DSCR_DEVICE_LEN ;; Descriptor length 147 | db DSCR_DEVICE ;; Decriptor type 148 | dw 0002H ;; Specification Version (BCD) 149 | db 00H ;; Device class 150 | db 00H ;; Device sub-class 151 | db 00H ;; Device sub-sub-class 152 | db 64 ;; Maximum packet size 153 | dw 0B404H ;; Vendor ID 154 | dw 0410H ;; Product ID (Sample Device) 155 | dw 0000H ;; Product version ID 156 | db 1 ;; Manufacturer string index 157 | db 2 ;; Product string index 158 | db 0 ;; Serial number string index 159 | db 1 ;; Number of configurations 160 | 161 | DeviceQualDscr: 162 | db DSCR_DEVQUAL_LEN ;; Descriptor length 163 | db DSCR_DEVQUAL ;; Decriptor type 164 | dw 0002H ;; Specification Version (BCD) 165 | db 00H ;; Device class 166 | db 00H ;; Device sub-class 167 | db 00H ;; Device sub-sub-class 168 | db 64 ;; Maximum packet size 169 | db 1 ;; Number of configurations 170 | db 0 ;; Reserved 171 | 172 | HighSpeedConfigDscr: 173 | db DSCR_CONFIG_LEN ;; Descriptor length 174 | db DSCR_CONFIG ;; Descriptor type 175 | db (HighSpeedConfigDscrEnd-HighSpeedConfigDscr) mod 256 ;; Total Length (LSB) 176 | db (HighSpeedConfigDscrEnd-HighSpeedConfigDscr) / 256 ;; Total Length (MSB) 177 | db 1 ;; Number of interfaces 178 | db 1 ;; Configuration number 179 | db 0 ;; Configuration string 180 | db 10000000b ;; Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu) 181 | db 50 ;; Power requirement (div 2 ma) 182 | 183 | ;; Interface Descriptor 184 | db DSCR_INTRFC_LEN ;; Descriptor length 185 | db DSCR_INTRFC ;; Descriptor type 186 | db 0 ;; Zero-based index of this interface 187 | db 0 ;; Alternate setting 188 | db 2 ;; Number of end points 189 | db 0ffH ;; Interface class 190 | db 00H ;; Interface sub class 191 | db 00H ;; Interface sub sub class 192 | db 0 ;; Interface descriptor string index 193 | 194 | ;; Endpoint Descriptor 195 | db DSCR_ENDPNT_LEN ;; Descriptor length 196 | db DSCR_ENDPNT ;; Descriptor type 197 | db 02H ;; Endpoint number, and direction 198 | db ET_BULK ;; Endpoint type 199 | db 00H ;; Maximun packet size (LSB) 200 | db 02H ;; Max packect size (MSB) 201 | db 00H ;; Polling interval 202 | 203 | ;; Endpoint Descriptor 204 | db DSCR_ENDPNT_LEN ;; Descriptor length 205 | db DSCR_ENDPNT ;; Descriptor type 206 | db 86H ;; Endpoint number, and direction 207 | db ET_BULK ;; Endpoint type 208 | db 00H ;; Maximun packet size (LSB) 209 | db 02H ;; Max packect size (MSB) 210 | db 00H ;; Polling interval 211 | 212 | HighSpeedConfigDscrEnd: 213 | 214 | FullSpeedConfigDscr: 215 | db DSCR_CONFIG_LEN ;; Descriptor length 216 | db DSCR_CONFIG ;; Descriptor type 217 | db (FullSpeedConfigDscrEnd-FullSpeedConfigDscr) mod 256 ;; Total Length (LSB) 218 | db (FullSpeedConfigDscrEnd-FullSpeedConfigDscr) / 256 ;; Total Length (MSB) 219 | db 1 ;; Number of interfaces 220 | db 1 ;; Configuration number 221 | db 0 ;; Configuration string 222 | db 10000000b ;; Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu) 223 | db 50 ;; Power requirement (div 2 ma) 224 | 225 | ;; Interface Descriptor 226 | db DSCR_INTRFC_LEN ;; Descriptor length 227 | db DSCR_INTRFC ;; Descriptor type 228 | db 0 ;; Zero-based index of this interface 229 | db 0 ;; Alternate setting 230 | db 2 ;; Number of end points 231 | db 0ffH ;; Interface class 232 | db 00H ;; Interface sub class 233 | db 00H ;; Interface sub sub class 234 | db 0 ;; Interface descriptor string index 235 | 236 | ;; Endpoint Descriptor 237 | db DSCR_ENDPNT_LEN ;; Descriptor length 238 | db DSCR_ENDPNT ;; Descriptor type 239 | db 02H ;; Endpoint number, and direction 240 | db ET_BULK ;; Endpoint type 241 | db 40H ;; Maximun packet size (LSB) 242 | db 00H ;; Max packect size (MSB) 243 | db 00H ;; Polling interval 244 | 245 | ;; Endpoint Descriptor 246 | db DSCR_ENDPNT_LEN ;; Descriptor length 247 | db DSCR_ENDPNT ;; Descriptor type 248 | db 86H ;; Endpoint number, and direction 249 | db ET_BULK ;; Endpoint type 250 | db 40H ;; Maximun packet size (LSB) 251 | db 00H ;; Max packect size (MSB) 252 | db 00H ;; Polling interval 253 | 254 | FullSpeedConfigDscrEnd: 255 | 256 | StringDscr: 257 | 258 | StringDscr0: 259 | db StringDscr0End-StringDscr0 ;; String descriptor length 260 | db DSCR_STRING 261 | db 09H,04H 262 | StringDscr0End: 263 | 264 | StringDscr1: 265 | db StringDscr1End-StringDscr1 ;; String descriptor length 266 | db DSCR_STRING 267 | db 'C',00 268 | db 'y',00 269 | db 'p',00 270 | db 'r',00 271 | db 'e',00 272 | db 's',00 273 | db 's',00 274 | StringDscr1End: 275 | 276 | StringDscr2: 277 | db StringDscr2End-StringDscr2 ;; Descriptor length 278 | db DSCR_STRING 279 | db 'E',00 280 | db 'Z',00 281 | db '-',00 282 | db 'U',00 283 | db 'S',00 284 | db 'B',00 285 | StringDscr2End: 286 | 287 | UserDscr: 288 | dw 0000H 289 | end 290 | 291 | ``` 292 | 293 | ## 寄存器定义头文件 294 | 295 | * 代码位置(根据自己的安装目录查看):`C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Target\Inc\fx2regs.h` 296 | * 寄存器定义说明:[Absolute Variable Location](http://www.keil.com/support/man/docs/c51/c51_le_absvarloc.htm) 297 | * `volatile`用于防止相关变量被优化,防止编译器对寄存器读写操作优化导致数据写入过程被忽略。 298 | * 示例 CPUCS寄存器: 299 | ![./images/CPU_Control_and_Status_Register.png](./images/CPU_Control_and_Status_Register.png) 300 | ```C 301 | [...省略] 302 | EXTERN xdata volatile BYTE CPUCS _AT_ 0xE600; // Control & Status 303 | [...省略] 304 | /* CPU Control & Status Register (CPUCS) */ 305 | #define bmPRTCSTB bmBIT5 306 | #define bmCLKSPD (bmBIT4 | bmBIT3) 307 | #define bmCLKSPD1 bmBIT4 308 | #define bmCLKSPD0 bmBIT3 309 | #define bmCLKINV bmBIT2 310 | #define bmCLKOE bmBIT1 311 | #define bm8051RES bmBIT0 312 | [...省略] 313 | ``` 314 | 315 | ## Autopointers 316 | 317 | * 《EZ-USB(R) Technical Reference Manual.pdf》 —— 8.8 Autopointers(Page 96) 318 | 319 | ![./images/Autopointers.png](./images/Autopointers.png) 320 | 321 | ## Bulkloop 322 | 323 | ```C 324 | [...省略] 325 | //----------------------------------------------------------------------------- 326 | // Task Dispatcher hooks 327 | // The following hooks are called by the task dispatcher. 328 | //----------------------------------------------------------------------------- 329 | 330 | void TD_Init(void) // Called once at startup 331 | { 332 | BYTE dum; // For the LEDS 333 | CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ; // 48 MHz CPU clock 334 | 335 | 336 | // Turn off all 4 LEDS 337 | dum = D2OFF; 338 | dum = D3OFF; 339 | dum = D4OFF; 340 | dum = D5OFF; 341 | 342 | // EP2CFG & EP6CFG configure our two endpoints, EP2-OUT and EP6-IN 343 | // b7: Valid 344 | // b6: DIR (0=OUT, 1=IN) 345 | // b[5:4] Type (01=ISO, 10=BULK, 11=INT) 346 | // b3: Size (0=512, 1=1024 bytes) 347 | // b2: 0 348 | // b[1:0] Buffering (00=quad, 10=double, 11=triple) 349 | // 350 | 351 | EP2CFG = 0xA2; // Valid, BULK-OUT, 512 byte buffer, double-buffered 352 | SYNCDELAY; // Some regs take longer to update, see TRM Section 15.14. 353 | EP6CFG = 0xE2; // Valid, BULK-IN, 512 byte buffer, double-buffered 354 | SYNCDELAY; 355 | 356 | // OUT endpoints do not come up armed 357 | // Since the endpoint is double buffered we must write dummy byte counts twice 358 | EP2BCL = 0x80; // arm EP2OUT by writing byte count w/skip. 359 | SYNCDELAY; 360 | EP2BCL = 0x80; // again 361 | SYNCDELAY; 362 | // enable dual autopointer feature 363 | AUTOPTRSETUP |= 0x01; 364 | 365 | USBIE |= bmSOF; // Enable the SOF IRQ to serve as LED timers 366 | EPIE = bmEP6IRQ | bmEP2IRQ; // Enable EP6 and EP2 Interrupts to turn on transfer LEDS 367 | } 368 | 369 | void TD_Poll(void) // Called repeatedly while the device is idle 370 | { 371 | WORD i; 372 | WORD count; 373 | // BYTE dummy_LED2; // ***For the LED 374 | BYTE waiting_inpkts; 375 | 376 | #ifdef ENABLE_7_SEG_DISPLAY 377 | if(start_7_seg_display) 378 | { 379 | // update 7-seg readout with number of IN packets waiting for transfer to the host 380 | waiting_inpkts = (EP6CS & 0xF0)>>4; 381 | EZUSB_WriteI2C(LED_ADDR, 0x01, &(Digit[waiting_inpkts])); 382 | EZUSB_WaitForEEPROMWrite(LED_ADDR); 383 | } 384 | #endif 385 | 386 | // Transfer EP6-OUT buffer to EP2-IN buffer when there is a packet in one of the EP6-OUT buffers, AND 387 | // there is an available EP2-IN buffer. The FIFO status flags update after full packets are transferred. 388 | // Therefore EP2-OUT "Not Empty" means a packet is available, and "EP6-IN "Not Full" means there is an 389 | // available buffer. Using the flags this way handles any packet size and takes multiple buffering 390 | // into account. 391 | 392 | if(!(EP2468STAT & bmEP2EMPTY)) // Is EP2-OUT buffer not empty (has at least one packet)? 393 | { 394 | if(!(EP2468STAT & bmEP6FULL)) // YES: Is EP6-IN buffer not full (room for at least 1 pkt)? 395 | { 396 | /* 397 | #define AUTOPTR1H AUTOPTRH1 // for backwards compatibility with examples 398 | #define AUTOPTR1L AUTOPTRL1 // for backwards compatibility with examples 399 | #define APTR1H AUTOPTRH1 // for backwards compatibility with examples 400 | #define APTR1L AUTOPTRL1 // for backwards compatibility with examples 401 | 402 | // this is how they are defined in the TRM 403 | sfr AUTOPTRH1 = 0x9A; 404 | sfr AUTOPTRL1 = 0x9B; 405 | sfr AUTOPTRH2 = 0x9D; 406 | sfr AUTOPTRL2 = 0x9E; 407 | */ 408 | APTR1H = MSB( &EP2FIFOBUF ); 409 | APTR1L = LSB( &EP2FIFOBUF ); 410 | AUTOPTRH2 = MSB( &EP6FIFOBUF ); 411 | AUTOPTRL2 = LSB( &EP6FIFOBUF ); 412 | 413 | count = (EP2BCH << 8) + EP2BCL; 414 | 415 | // loop EP2OUT buffer data to EP6IN 416 | for( i = 0; i < count; i++ ) 417 | { 418 | /* 419 | EXTERN xdata volatile BYTE XAUTODAT1 _AT_ 0xE67B; // Autoptr1 MOVX access 420 | EXTERN xdata volatile BYTE XAUTODAT2 _AT_ 0xE67C; // Autoptr2 MOVX access 421 | 422 | #define EXTAUTODAT1 XAUTODAT1 423 | #define EXTAUTODAT2 XAUTODAT2 424 | */ 425 | EXTAUTODAT2 = EXTAUTODAT1; // Autopointers make block transfers easy... 426 | } 427 | EP6BCH = EP2BCH; // Send the same number of bytes as received 428 | SYNCDELAY; 429 | EP6BCL = EP2BCL; // arm EP6IN 430 | SYNCDELAY; 431 | EP2BCL = 0x80; // arm EP2OUT 432 | } 433 | } 434 | } 435 | ``` 436 | 437 | -------------------------------------------------------------------------------- /docs/0008_HID_Keyboard.md: -------------------------------------------------------------------------------- 1 | # HID Keyboard 2 | 3 | 键盘的描述符共有8字节的输入报告和1字节的输出报告: 4 | * 8字节输入报告:第1字节特殊按键,第2字节保留常量,第3-8字节普通按键。键值可以参考USB HID to PS/2 Scan Code Translation Table. 5 | * 1字节输出报告:这1个字节总共用了5bits使用3bits常量来补足成1个字节。5bits用来点亮特殊键盘上的Led灯,比如键盘的大小写,数字键,小键盘的LED灯。 6 | * 如果不给键盘配置OUT端点,那么键盘的1字节输出报告将由控制端点的SetReport进行传输。 7 | 8 | ## 参考文档 9 | 10 | * [./refers/USB_HID_Keyboard_Firmware.pdf](./refers/USB_HID_Keyboard_Firmware.pdf) 11 | * [Tutorial about USB HID Report Descriptors](https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/) 12 | * [关于USBHID协议以及鼠标键盘描述符的解释](https://blog.csdn.net/jiujiujiuqiuqiuqiu/article/details/47277685) 13 | * [USB HID Keyboard Firmware Using EZ-USB® FX2LPTM](https://www.cypress.com/file/103181/download) 14 | 15 | ## 报告描述符生成器 16 | 17 | [HID Descriptor Tool](https://www.usb.org/document-library/hid-descriptor-tool) 18 | 19 | ## Code Positon 20 | 21 | `C:\Cypress\USB\CY3684_EZ-USB_FX2LP_DVK\1.1\Firmware\hid_kb` 22 | 23 | ## HID 报告描述符 24 | 25 | ```ASM 26 | HIDReportDscr: 27 | ; 通用桌面键盘 28 | db 05h, 01h ; Usage Page (Generic Desktop) 29 | db 09h, 06h ; Usage (Keyboard) 30 | db 0A1h, 01h ; Collection (Application) 31 | 32 | ; 按键值类型,输入,占用8bit * 1 33 | db 05h, 07h ; Usage Page (Key codes) 34 | db 19h, 0E0h ; Usage minimum (224) 35 | db 29h, 0E7h ; Usage maximum (231) 36 | db 15h, 00h ; Logical minimum (0) 37 | db 25h, 01h ; Logical maximum (1) 38 | db 75h, 01h ; Report size (1) 39 | db 95h, 08h ; Report count (8) 40 | db 81h, 02h ; Input (data, variable, absolute) 41 | 42 | ; 常量,也就是保留,占用8bit * 1 43 | db 95h, 01h ; Report count (1) 44 | db 75h, 08h ; Report size (8) 45 | db 81h, 01h ; Input (constant) 46 | 47 | ; 灯类型,输出,占用1bit * 5 48 | db 95h, 05h ; Report count (5) 49 | db 75h, 01h ; Report size (1) 50 | db 05h, 08h ; Usage Page (LED) 51 | db 19h, 01h ; Usage minimum (1) 52 | db 29h, 05h ; Usage maximum (5) 53 | db 91h, 02h ; Output (data, variable, absolute) 54 | 55 | ; 常量,也就是保留,占用3bit * 1,填充前面的5bit,达到8bit 56 | db 95h, 01h ; Report count (1) 57 | db 75h, 03h ; Report size (3) 58 | db 91h, 01h ; Output (constant) 59 | 60 | ; 按键值类型,输入,占用8bit * 3 61 | db 95h, 03h ; Report count (3) 62 | db 75h, 08h ; Report size (8) 63 | db 15h, 00h ; Logical minimum (0) 每个字节的取值范围是 0~101 64 | db 25h, 65h ; Logical maximum (101) 65 | db 05h, 07h ; Usage page (key codes) 66 | db 19h, 00h ; Usage minimum (0) 分别是键盘码 0~键盘码 101 67 | db 29h, 65h ; Usage maximum (101) 68 | db 81h, 00h ; Input (data, array) 69 | db 0C0h ; End Collection 70 | HIDReportDscrEnd: 71 | ``` 72 | 73 | ## HID Keyboard 74 | 75 | ```C 76 | [...省略] 77 | void TD_Init(void) // Called once at startup 78 | { 79 | leds = 0xFF; 80 | oldbuttons = 0xFF; 81 | 82 | EP1OUTCFG = 0xB0; // valid, interrupt 83 | EP1INCFG = 0XB0; // valid, interrupt 84 | 85 | EP2CFG = EP4CFG = EP6CFG = EP8CFG = 0; // disable unused endpoints 86 | 87 | // EZUSB_InitI2C(); // Initialize EZ-USB I2C controller 88 | 89 | 90 | } 91 | 92 | void TD_Poll(void) // Called repeatedly while the device is idle 93 | { 94 | if( !(EP1INCS & bmEPBUSY) ) // Is the IN1BUF available; 八字节的输入报文 95 | { 96 | // EZUSB_ReadI2C(BTN_ADDR,0x01,&buttons); // Read button states 97 | buttons = 0x01; 98 | // buttons &= 0x0F; 99 | // if ((oldbuttons - buttons) != 0) //Change in button state 100 | if ((buttons) != 0) //Change in button state 101 | { 102 | if (buttons & 1) //Shift 103 | EP1INBUF[0] = 0; 104 | else 105 | EP1INBUF[0] = 2; 106 | 107 | if (buttons & 2) //a 108 | EP1INBUF[2] = 0; 109 | else 110 | EP1INBUF[2] = 4; 111 | 112 | if (buttons & 4) //b 113 | EP1INBUF[3] = 0; 114 | else 115 | EP1INBUF[3] = 5; 116 | 117 | if (buttons & 8) //c 118 | EP1INBUF[4] = 0; 119 | else 120 | EP1INBUF[4] = 6; 121 | 122 | EP1INBUF[1] = 0; 123 | EP1INBC = 5; 124 | } 125 | // oldbuttons = buttons; 126 | } 127 | 128 | if( !(EP1OUTCS & bmEPBUSY) ) // Is there something available; 1字节的输出报文 129 | { 130 | leds = 0xFF; //Turn all off 131 | 132 | if (EP1OUTBUF[0] & 0x02) //Caps 133 | leds &= 0xBF; 134 | if (EP1OUTBUF[0] & 0x01) //Scroll 135 | leds &= 0xF7; 136 | if (EP1OUTBUF[0] & 0x04) //Num 137 | leds &= 0xFE; 138 | 139 | // EZUSB_WriteI2C(LED_ADDR, 0x01, &leds); 140 | // EZUSB_WaitForEEPROMWrite(LED_ADDR); 141 | 142 | EP1OUTBC = 0; //Rearm endpoint buffer 143 | } 144 | } 145 | 146 | [...省略] 147 | //----------------------------------------------------------------------------- 148 | // Device Request hooks 149 | // The following hooks are called by the end point 0 device request parser. 150 | //----------------------------------------------------------------------------- 151 | 152 | BOOL DR_GetDescriptor(void) 153 | { 154 | BYTE length,i; 155 | 156 | pHIDDscr = (WORD)&HIDDscr; 157 | pReportDscr = (WORD)&HIDReportDscr; 158 | pReportDscrEnd = (WORD)&HIDReportDscrEnd; 159 | 160 | switch (SETUPDAT[3]) 161 | { 162 | case GD_HID: //HID Descriptor 163 | SUDPTRH = MSB(pHIDDscr); 164 | SUDPTRL = LSB(pHIDDscr); 165 | return (FALSE); 166 | case GD_REPORT: //Report Descriptor 167 | length = pReportDscrEnd - pReportDscr; 168 | 169 | AUTOPTR1H = MSB(pReportDscr); 170 | AUTOPTR1L = LSB(pReportDscr); 171 | 172 | for(i=0;i 0) 17 | GetEndpointsOfNode(node); // 递归 18 | else 19 | { 20 | CyUSBEndPoint ept = node.Tag as CyUSBEndPoint; 21 | if (ept == null) 22 | { 23 | //return; 24 | } 25 | else if (!node.Text.Contains("Control")) 26 | { 27 | CyUSBInterface ifc = node.Parent.Tag as CyUSBInterface; 28 | string s = string.Format("ALT-{0}, {1} Byte {2}", ifc.bAlternateSetting, ept.MaxPktSize, node.Text); 29 | EndPointsComboBox.Items.Add(s); 30 | } 31 | 32 | } 33 | } 34 | 35 | } 36 | [...省略] 37 | ``` 38 | 39 | ## 自动选择接口描述符流程 40 | 41 | ```C# 42 | [...省略] 43 | /*Summary 44 | Search the device with VID-PID 04b4-00F1 and if found, select the end point 45 | */ 46 | private void SetDevice(bool bPreserveSelectedDevice) 47 | { 48 | [...省略] 49 | PpxBox.Text = "16"; //Set default value to 8 Packets 50 | QueueBox.Text = "8"; 51 | if (EndPointsComboBox.Items.Count > 0) 52 | { 53 | /** 54 | * ALT-6, 1024 Byte Isoc in endpoint (0x82) 55 | * ALT-6, 1024 Byte Isoc out endpoint (0x06) 56 | */ 57 | EndPointsComboBox.SelectedIndex = 0; // 设置索引,会自动触发对应的事件 58 | StartBtn.Enabled = true; 59 | } 60 | else StartBtn.Enabled = false; 61 | 62 | [...省略] 63 | } 64 | [...省略] 65 | /*Summary 66 | This is a system event handler, when the selected index changes(end point selection). 67 | */ 68 | private void EndPointsComboBox_SelectedIndexChanged(object sender, EventArgs e) 69 | { 70 | // Get the Alt setting 71 | // EndPointsComboBox.Text = "ALT-6, 1024 Byte Isoc in endpoint (0x82)" 72 | string sAlt = EndPointsComboBox.Text.Substring(4, 1); 73 | byte a = Convert.ToByte(sAlt); 74 | MyDevice.AltIntfc = a; // a = 6 75 | 76 | // Get the endpoint 77 | int aX = EndPointsComboBox.Text.LastIndexOf("0x"); 78 | string sAddr = EndPointsComboBox.Text.Substring(aX, 4); 79 | byte addr = (byte)Util.HexToInt(sAddr); 80 | 81 | EndPoint = MyDevice.EndPointOf(addr); 82 | 83 | // Ensure valid PPX for this endpoint 84 | PpxBox_SelectedIndexChanged(sender, null); 85 | } 86 | [...省略] 87 | ``` 88 | 89 | ![./images/StreamExample_Always_Select_Alt6.png](./images/StreamExample_Always_Select_Alt6.png) 90 | -------------------------------------------------------------------------------- /docs/0015_Send_Setup_Packet.md: -------------------------------------------------------------------------------- 1 | # Send Setup Packet 2 | 3 | ## 参考文档 4 | 5 | * [The Setup Packet](https://www.beyondlogic.org/usbnutshell/usb6.shtml) 6 | 7 | ## 测似方法 8 | 9 | * 使用`USB Control Center`直接发送`Setup Packet`; 10 | * 获取`AlternateSetting`的值; 11 | * `bRequest`: 12 | * `GET_INTERFACE (0x0A)`; 13 | * `SET_INTERFACE (0x0B)`; 14 | * 单片机实现方法: 15 | ```C 16 | BOOL DR_GetInterface(void) // Called when a Set Interface command is received 17 | { 18 | EP0BUF[0] = AlternateSetting; 19 | EP0BCH = 0; 20 | EP0BCL = 1; 21 | return(TRUE); // Handled by user code 22 | } 23 | ``` 24 | * 测试验证: 25 | ![./images/Get_AlternateSetting.png](./images/Get_AlternateSetting.png) 26 | ![images/Set_AlternateSetting.png](images/Set_AlternateSetting.png) -------------------------------------------------------------------------------- /docs/0016_Isochronous_Transfers.md: -------------------------------------------------------------------------------- 1 | # Isochronous Transfers 2 | 3 | ## 参考文档 4 | 5 | * [Isochronous Transfers](https://www.keil.com/pack/doc/mw/USB/html/_u_s_b__isochronous__transfers.html): 6 | An Isochronous pipe sends a new data packet in **every frame**, regardless of the success or failure of the last packet. 7 | * [USB Protocol](https://www.keil.com/pack/doc/mw/USB/html/_u_s_b__protocol.html) 8 | 9 | A special packet is the Start-of-Frame packet (SOF) that splits the USB bus into time segments. Each pipe is allocated a slot in each frame. The Start-of-Frame packet is sent every 1ms on full speed links. At high speed, the 1ms frame is divided into 8 microframes of 125μs each. A Start-of-Frame packet is sent at the beginning of each microframe using the same frame number. The frame number increments every 1ms. 10 | 11 | ## Isochronous IN 12 | 13 | * 处理同步数据方法 14 | ```C 15 | [...省略] 16 | case Alt6_IsocINOUT: 17 | { 18 | // Send data on EP2 19 | while(!(EP2468STAT & bmEP2FULL)) 20 | { 21 | EP2FIFOBUF[0] = LSB(mycount); 22 | EP2FIFOBUF[1] = MSB(mycount); 23 | EP2FIFOBUF[2] = USBFRAMEL; 24 | EP2FIFOBUF[3] = USBFRAMEH; 25 | EP2FIFOBUF[4] = MICROFRAME; 26 | 27 | EP2BCH = 0x04; 28 | EP2BCL = 0x00; 29 | 30 | mycount++; 31 | } 32 | 33 | // check EP6 EMPTY(busy) bit in EP2468STAT (SFR), core set's this bit when FIFO is empty 34 | if(!(EP2468STAT & bmEP6EMPTY)) 35 | { 36 | EP6BCL = 0x80; // re(arm) EP6OUT 37 | } 38 | } 39 | break; 40 | [...省略] 41 | ``` 42 | * 运行效果 43 | ![./images/Isochronous_Data_IN.png](./images/Isochronous_Data_IN.png) 44 | * 目前不知道为什么端点缓冲区是1k Byte,但是发送的数据却至少要8k Byte的倍数,难道是因为至少用1ms来算?暂不追查原理。 45 | * StreamExample采用的是16k Byte的参数; 46 | 47 | ## Isochronous OUT 48 | 49 | ![./images/Isochronous_Data_OUT.png](./images/Isochronous_Data_OUT.png) 50 | 51 | 52 | ## Buffer Data 53 | 54 | 初始化端点2的4个buffer中的数据 55 | 56 | ``` 57 | void TD_Init(void) // Called once at startup 58 | { 59 | [...省略] 60 | 61 | // Prepare data 62 | for (i=1;i<5;i++) 63 | { 64 | EP2FIFOBUF[0] = LSB(mycount); 65 | EP2FIFOBUF[1] = MSB(mycount); 66 | EP2FIFOBUF[2] = USBFRAMEL; 67 | EP2FIFOBUF[3] = USBFRAMEH; 68 | EP2FIFOBUF[4] = MICROFRAME; 69 | for (j=5;j<1024;j++) 70 | { 71 | EP2FIFOBUF[j] = i; 72 | } 73 | EP2BCH = 0x02; 74 | EP2BCL = 0x00; 75 | } 76 | 77 | [...省略] 78 | } 79 | ``` -------------------------------------------------------------------------------- /docs/0017_Type-C.md: -------------------------------------------------------------------------------- 1 | # Type-C 2 | 3 | ## 参考文档 4 | 5 | * [USB Type-C™ and Power Delivery Minidock With Video and Charging Support Reference Design](http://www.ti.com/tool/TIDA-01243?tdsourcetag=s_pcqq_aiomsg) -------------------------------------------------------------------------------- /docs/0018_CY7C68013A_FPGA.md: -------------------------------------------------------------------------------- 1 | # CY7C68013A FPGA 2 | 3 | ## 参考文档 4 | 5 | * [AN61345 - Designing with EZ-USB® FX2LP™ Slave FIFO Interface](https://www.cypress.com/documentation/application-notes/an61345-designing-ez-usb-fx2lp-slave-fifo-interface) 6 | * [Designing with EZ-USB® FX2LP™ Slave FIFO Interface](https://www.cypress.com/file/44551/download) 7 | * [USB-FPGA Module 1.11](https://www.ztex.de/usb-fpga-1/usb-fpga-1.11.e.html) 8 | * [Experimental Board 1.3 for Series 1 FPGA Boards](https://www.ztex.de/usb-fpga-1/exp-1.3.e.html) 9 | * [DreamSourceLab DSLogic Plus](https://sigrok.org/wiki/DreamSourceLab_DSLogic_Plus) 10 | * [DreamSourceLab DSLogic Pro](https://sigrok.org/wiki/DreamSourceLab_DSLogic_Pro) -------------------------------------------------------------------------------- /docs/0019_Linux_Compile.md: -------------------------------------------------------------------------------- 1 | # Linux Compile 2 | 3 | ## Source Code 4 | 5 | * git clone https://github.com/DreamSourceLab/DSLogic-fw 6 | 7 | ## Steps 8 | 9 | * apt-cache search sdcc 10 | * sudo apt-get install sdcc 11 | * ./autogen.sh 12 | * ./configure 13 | * make 14 | 15 | ## Dir info 16 | 17 | ```Console 18 | pi@raspberrypi:~/zengjf/DSLogic-fw $ ls 19 | aclocal.m4 autom4te.cache config.h.in configure DSLogic.asm DSLogic.re 20 | AUTHORS autostuff config.log configure.ac DSLogic.c DSLogic.rs 21 | autogen.sh config.h config.status COPYING DSLogic.lst DSLogic.sy 22 | pi@raspberrypi:~/zengjf/DSLogic-fw $ ls 23 | aclocal.m4 config.log DSLogic.lst INSTALL Makefile usb.c 24 | AUTHORS config.status DSLogic.rel interface.asm Makefile.am usb.lst 25 | autogen.sh configure DSLogic.rst interface.c Makefile.in usb.rel 26 | autom4te.cache configure.ac DSLogic.sym interface.lst NEWS usb.rst 27 | autostuff COPYING fx2lib interface.rel README usb.sym 28 | config.h DSLogic.asm hw interface.rst stamp-h1 29 | config.h.in DSLogic.c include interface.sym usb.asm 30 | pi@raspberrypi:~/zengjf/DSLogic-fw $ ls hw/ 31 | dscr.a51 dscr.rst DSLogic.ihx DSLogic.mem Makefile.in 32 | dscr.lst dscr.sym DSLogic.lk Makefile 33 | dscr.rel DSLogic.fw DSLogic.map Makefile.am 34 | pi@raspberrypi:~/zengjf/DSLogic-fw $ ls -alh hw/DSLogic.fw 35 | -rw-r--r-- 1 pi pi 8.0K Nov 30 08:42 hw/DSLogic.fw 36 | ``` 37 | 38 | ## 反汇编 39 | 40 | * 安装dis51 41 | * http://plit.de/asem-51/dis51.html 42 | * http://plit.de/asem-51/dis51-0.5.tar.gz 43 | * wget http://plit.de/asem-51/dis51-0.5.tar.gz 44 | * tar xvf dis51-0.5.tar.gz 45 | * make 46 | * sudo apt-get install dis51 47 | * packihx DSLogic.ihx > DSLogic.hex 48 | * 反汇编: 49 | * cat DSLogic.hex | dis51 > DSLogic.a51 50 | * cat DSLogic.hex | dis51 0x80 0x00 > DSLogic.a51 51 | * CSEG:code segment 52 | * LJMP:The LJMP instruction transfers program execution to the specified 16-bit address. 53 | * DB:The DB statement initializes memory with one or more byte values. label is a symbol that is assigned the current memory address. expression is a byte value that is stored in memory. Each expression may be a symbol, a string, or an expression. -------------------------------------------------------------------------------- /docs/0020_Keil.md: -------------------------------------------------------------------------------- 1 | # Keil 2 | 3 | ## Shortcut 4 | 5 | * `F12` 6 | * `CTRL` + `-`:这个要注意主键盘的减号不一定有效,可以试试数字键盘上的减号; 7 | 8 | ## 编译环境配置 9 | 10 | * 源代码配置 11 | ![images/Keil_Components.png](images/Keil_Components.png) 12 | * 库、头文件配置 13 | ![images/Keil_Environment.png](images/Keil_Environment.png) -------------------------------------------------------------------------------- /docs/0021_GPIF.md: -------------------------------------------------------------------------------- 1 | # GPIF 2 | 3 | 4 | ## 参考文档 5 | 6 | * [通过 GPIF 使 SRAM 与 FX2LP 相互连接](https://www.cypress.com/file/134606/download) 7 | * [AN63787 - EZ-USB® FX2LP™ GPIF and Slave FIFO Configuration Examples Using an 8-Bit Asynchronous Interface](https://www.cypress.com/documentation/application-notes/an63787-ez-usb-fx2lp-gpif-and-slave-fifo-configuration-examples) 8 | * [EZ-USB FX2LP GPIF And Slave FIFO Configuration Examples Using An 8-Bit Asynchronous Interface](https://www.cypress.com/file/202291/download) 9 | * [AN66806 - Getting Started with EZ-USB® FX2LP™ GPIF](https://www.cypress.com/documentation/application-notes/an66806-getting-started-ez-usb-fx2lp-gpif) 10 | * [EZ-USB® FX2LP™ GPIF 入门](https://www.cypress.com/file/135391/download) 11 | * [USB Vendor Command](docs/0022_Vendor_Command.md) 12 | 13 | 14 | ## 硬件连接器 15 | 16 | https://github.com/ZengjfOS/DebugHAT/tree/CY7C68013ACombinor 17 | 18 | ![images/CY7C68013A_Combinor.jpg](images/CY7C68013A_Combinor.jpg) 19 | 20 | 21 | ## 源代码 22 | 23 | * 参考源代码: [AN63787 EZ-USB FX2LP GPIF and Slave FIFO Configuration Examples Using an 8-Bit Asynchronous Interface.zip](https://www.cypress.com/file/44776/download) 24 | * https://github.com/ZengjfOS/USB/blob/GPIF_FIFO 25 | 26 | 27 | ## 调试方法 28 | 29 | 由于以前的个人经验都是使用UART口进行调试,在调试USB的通信方面经验不多,所以一直在思考怎么调试才能方便,在无意中注意到,可以用发送setup包,例如Vendor Command来获取51单片机内部寄存器的值,从而解决调试难的问题; 30 | 31 | ![images/CY7C68013A_Register_Debug.png](images/CY7C68013A_Register_Debug.png) 32 | 33 | 34 | ## 系统框图 35 | 36 | ![images/GPIF_Back2Back_System_ARCH.png](images/GPIF_Back2Back_System_ARCH.png) 37 | 38 | * 两个 FX2LP 芯片相连:一个工作于 GPIF 模式,另一个工作于 Slave FIFO 模式。 39 | * EP2 — BULK OUT、512 个字节、四缓冲 40 | * EP6 — BULK IN、512 个字节,四缓冲 41 | 42 | 43 | ## FIFO Connect 44 | 45 | ![images/GPIF_Back2Back_FIFO_Connect.png](images/GPIF_Back2Back_FIFO_Connect.png) 46 | 47 | * 主设备引脚: 48 | * CTL[5:0]是可编程的控制输出,可将它们作为选通,读/写线或其他输出使用。该应用程序使用的控制信号(CTL0、CTL1 和 CTL2)连接到从设备的 SLRD、SLWR 和 SLOE。 49 | * RDY[5:0]为“就绪”输入,可对它们进行采样,并允许数据传输等待(插入等待状态)、继续或重复,直到该信号处于合适的电平为止。该过程使用了 RDY0 和 RDY1 来控制数据流。RDY0 连接着从设备的 FLAGC(EP2 空标志),而 RDY1 连接着从设备的 FLAGB(EP6 满标志)。 50 | * 主设备 FX2LP 使用端口 A 引脚[6, 7]来驱动由主设 51 | 备访问的 Slave FIFO 地址。 52 | * PC2(SLAVEREADY)是从设备到主设备的输入,表示目前从设备已经复位,其固件准备就绪。这是为了防止主设备在从设备复位前或在复位过程中读取其 EP6 FIFO 中任何无效值。 53 | * 对于手动操作模式,从设备和主设备间进行的交换需要其他两条线来实现主出从入的传输。PC0(Txn_Over)和 PC1(Pkt_Committed)用于实现此目的。后面各章节说明了更多有关这些引脚使用情况的信息。 54 | * 从设备引脚: 55 | * FLAGB 和 FLAGC 用于报告 Slave FIFO 的状态。 56 | * FLAGB — EP6FF(端点 6 满标志)表示 EP6 FIFO 的“满”状态。 57 | * FLAGC — EP6FF(端点 2 空标志)表示 EP2 FIFO 的“空”状态。 58 | * 所使用的 Slave FIFO 控制引脚分别是 SLOE(从设备输出使能)、SLRD(从设备读取)、SLWR(从设备写入)和 FIFOADR[1:0](FIFO 选择)。 59 | * FIFOADR[1:0]引脚用于选择与数据总线相连接的四个 FIFO(由外部主设备控制)。 60 | * PC2 是从设备的输出,在从设备复位后它被设置为高电平,因此准备好了它的固件。 61 | * FD[0:7] 这是被配置为 8 位数据总线的端口 B。如果设置任意 EPxFIFOCG 寄存器的 WORDWIDE(EPxFIFOCG.0)位 , 那么端口 D 将被配置为 FD[8:15] 。 所有四个 WORLDWIDE 位的或操作,会导致 PORTD 成为 PORTD 或者 FD[15:8]。每一个单独的 WORLDWIDE 位指示每个单独的端点数据如何传递。这种传递使用 8-bit 接口如何该过程使用了一个 8 位的接口。 62 | 63 | 64 | ## 操作方法 65 | 66 | * 由Slave往Master发数据,没什么问题; 67 | * 由Master往Slave发数据,需要Master先上电,Slave后上电,可以按Slave的reset按键,主要原因是Master发数据的时候,需要Slave的一个引脚的信号翻转; -------------------------------------------------------------------------------- /docs/0022_Vendor_Command.md: -------------------------------------------------------------------------------- 1 | # Vendor Command 2 | 3 | ## 参考文档 4 | 5 | * [Create Your Own USB Vendor Commands Using FX2LP™](https://www.cypress.com/file/202971/download) 6 | * [Interfacing FX2LP™ with Image Sensor – KBA95736](https://community.cypress.com/docs/DOC-9329) 7 | 8 | ## Source 9 | 10 | https://github.com/ZengjfOS/USB/tree/VendorCMD 11 | 12 | ## Vendor Commands Steps 13 | 14 | ![images/Vendor_Commands.png](images/Vendor_Commands.png) -------------------------------------------------------------------------------- /docs/0023_USB_Camera_UVC.md: -------------------------------------------------------------------------------- 1 | # USB Camera UVC 2 | 3 | 貌似这份代码没有完整实现UVC,所以没啥用 4 | 5 | ## 参考文档 6 | 7 | * [Interfacing FX2LP™ with Image Sensor – KBA95736](https://community.cypress.com/docs/DOC-9329) 8 | * [USB2.0 Camera Interface Using FX2LP™ and Lattice CrossLink FPGA - KBA222479](https://community.cypress.com/docs/DOC-14406) 9 | * [Create Your Own USB Vendor Commands Using FX2LP™](https://www.cypress.com/file/202971/download) 10 | * [USB68013种的arm endpoint是什么意思](http://bbs.21ic.com/icview-828608-1-1.html) 11 | * arm相当于使Endpoint处于待命的状态,随时准备数据传输! 12 | * re-arm就是再次待命。 13 | * [UVC v4l2](https://github.com/ZengjfOS/V4L2/blob/master/docs/0001_uvc/README.md) 14 | * [camera驱动部分视频数据流分析(uvc)](https://blog.csdn.net/qq160816/article/details/62419489) 15 | * [USB Video Class 1_5 Specification](https://www.usb.org/document-library/video-class-v15-document-set) 16 | 17 | 18 | ## Source 19 | 20 | https://github.com/ZengjfOS/USB/tree/UVCCamera 21 | 22 | ## USB描述符 23 | 24 | * lsusb 25 | ``` 26 | Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 27 | Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 28 | Bus 001 Device 003: ID 04b4:0036 Cypress Semiconductor Corp. 29 | Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub 30 | Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 31 | ``` 32 | * lsusb -vd 04b4:0036 33 | ``` 34 | Bus 001 Device 005: ID 04b4:0036 Cypress Semiconductor Corp. 35 | Couldn't open device, some information will be missing 36 | Device Descriptor: 37 | bLength 18 38 | bDescriptorType 1 39 | bcdUSB 2.00 40 | bDeviceClass 239 Miscellaneous Device 41 | bDeviceSubClass 2 42 | bDeviceProtocol 1 Interface Association 43 | bMaxPacketSize0 64 44 | idVendor 0x04b4 Cypress Semiconductor Corp. 45 | idProduct 0x0036 46 | bcdDevice 0.00 47 | iManufacturer 1 48 | iProduct 2 49 | iSerial 0 50 | bNumConfigurations 1 51 | Configuration Descriptor: 52 | bLength 9 53 | bDescriptorType 2 54 | wTotalLength 0x00ce 55 | bNumInterfaces 2 56 | bConfigurationValue 1 57 | iConfiguration 0 58 | bmAttributes 0x80 59 | (Bus Powered) 60 | MaxPower 500mA 61 | Interface Association: 62 | bLength 8 63 | bDescriptorType 11 64 | bFirstInterface 0 65 | bInterfaceCount 2 66 | bFunctionClass 14 Video 67 | bFunctionSubClass 3 Video Interface Collection 68 | bFunctionProtocol 0 69 | iFunction 2 70 | Interface Descriptor: 71 | bLength 9 72 | bDescriptorType 4 73 | bInterfaceNumber 0 74 | bAlternateSetting 0 75 | bNumEndpoints 1 76 | bInterfaceClass 14 Video 77 | bInterfaceSubClass 1 Video Control 78 | bInterfaceProtocol 0 79 | iInterface 2 80 | VideoControl Interface Descriptor: 81 | bLength 13 82 | bDescriptorType 36 83 | bDescriptorSubtype 1 (HEADER) 84 | bcdUVC 1.10 85 | wTotalLength 0x0051 86 | dwClockFrequency 48.000000MHz 87 | bInCollection 1 88 | baInterfaceNr( 0) 1 89 | VideoControl Interface Descriptor: 90 | bLength 18 91 | bDescriptorType 36 92 | bDescriptorSubtype 2 (INPUT_TERMINAL) 93 | bTerminalID 1 94 | wTerminalType 0x0201 Camera Sensor 95 | bAssocTerminal 0 96 | iTerminal 0 97 | wObjectiveFocalLengthMin 0 98 | wObjectiveFocalLengthMax 0 99 | wOcularFocalLength 0 100 | bControlSize 3 101 | bmControls 0x00000000 102 | VideoControl Interface Descriptor: 103 | bLength 13 104 | bDescriptorType 36 105 | bDescriptorSubtype 5 (PROCESSING_UNIT) 106 | bUnitID 2 107 | bSourceID 1 108 | wMaxMultiplier 16384 109 | bControlSize 3 110 | bmControls 0x00000000 111 | iProcessing 0 112 | bmVideoStandards 0x00 113 | VideoControl Interface Descriptor: 114 | bLength 28 115 | bDescriptorType 36 116 | bDescriptorSubtype 6 (EXTENSION_UNIT) 117 | bUnitID 3 118 | guidExtensionCode {ffffffff-ffff-ffff-ffff-ffffffffffff} 119 | bNumControl 0 120 | bNrPins 1 121 | baSourceID( 0) 2 122 | bControlSize 3 123 | bmControls( 0) 0x00 124 | bmControls( 1) 0x00 125 | bmControls( 2) 0x00 126 | iExtension 0 127 | VideoControl Interface Descriptor: 128 | bLength 9 129 | bDescriptorType 36 130 | bDescriptorSubtype 3 (OUTPUT_TERMINAL) 131 | bTerminalID 4 132 | wTerminalType 0x0101 USB Streaming 133 | bAssocTerminal 0 134 | bSourceID 3 135 | iTerminal 0 136 | Endpoint Descriptor: 137 | bLength 7 138 | bDescriptorType 5 139 | bEndpointAddress 0x88 EP 8 IN 140 | bmAttributes 3 141 | Transfer Type Interrupt 142 | Synch Type None 143 | Usage Type Data 144 | wMaxPacketSize 0x0040 1x 64 bytes 145 | bInterval 8 146 | Interface Descriptor: 147 | bLength 9 148 | bDescriptorType 4 149 | bInterfaceNumber 1 150 | bAlternateSetting 0 151 | bNumEndpoints 1 152 | bInterfaceClass 14 Video 153 | bInterfaceSubClass 2 Video Streaming 154 | bInterfaceProtocol 0 155 | iInterface 0 156 | VideoStreaming Interface Descriptor: 157 | bLength 14 158 | bDescriptorType 36 159 | bDescriptorSubtype 1 (INPUT_HEADER) 160 | bNumFormats 1 161 | wTotalLength 0x0047 162 | bEndPointAddress 130 163 | bmInfo 0 164 | bTerminalLink 4 165 | bStillCaptureMethod 1 166 | bTriggerSupport 0 167 | bTriggerUsage 0 168 | bControlSize 1 169 | bmaControls( 0) 0 170 | VideoStreaming Interface Descriptor: 171 | bLength 27 172 | bDescriptorType 36 173 | bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED) 174 | bFormatIndex 1 175 | bNumFrameDescriptors 1 176 | guidFormat {32595559-0000-0010-8000-00aa00389b71} 177 | bBitsPerPixel 16 178 | bDefaultFrameIndex 1 179 | bAspectRatioX 8 180 | bAspectRatioY 6 181 | bmInterlaceFlags 0x00 182 | Interlaced stream or variable: No 183 | Fields per frame: 2 fields 184 | Field 1 first: No 185 | Field pattern: Field 1 only 186 | bCopyProtect 0 187 | VideoStreaming Interface Descriptor: 188 | bLength 30 189 | bDescriptorType 36 190 | bDescriptorSubtype 5 (FRAME_UNCOMPRESSED) 191 | bFrameIndex 1 192 | bmCapabilities 0x01 193 | Still image supported 194 | wWidth 640 195 | wHeight 480 196 | dwMinBitRate 147456000 197 | dwMaxBitRate 147456000 198 | dwMaxVideoFrameBufferSize 614400 199 | dwDefaultFrameInterval 333333 200 | bFrameIntervalType 1 201 | dwFrameInterval( 0) 333333 202 | Endpoint Descriptor: 203 | bLength 7 204 | bDescriptorType 5 205 | bEndpointAddress 0x82 EP 2 IN 206 | bmAttributes 2 207 | Transfer Type Bulk 208 | Synch Type None 209 | Usage Type Data 210 | wMaxPacketSize 0x0200 1x 512 bytes 211 | bInterval 0 212 | ``` 213 | 214 | ## UVC 215 | 216 | * https://github.com/ZengjfOS/V4L2/blob/master/docs/0002_v4l2_capture/README.md 217 | * Kernel 218 | * drivers/media/usb/uvc/uvc_video.c 219 | * `static void uvc_video_complete(struct urb *urb)`这个函数相当于MIPI CSI的帧中断函数; 220 | * urb->complete = uvc_video_complete; (收到数据后此函数被调用,它又调用video->decode(urb, video, buf); ==> uvc_video_decode_isoc/uvc_video_encode_bulk => uvc_queue_next_buffer => wake_up(&buf->wait);) 221 | * 一帧图片的获取流程 222 | ``` 223 | * drivers/media/usb/uvc/uvc_v4l2.c 224 | * const struct v4l2_ioctl_ops uvc_ioctl_ops 225 | * .vidioc_streamon = uvc_ioctl_streamon 226 | * ret = uvc_queue_streamon(&stream->queue, type); 227 | * ret = vb2_streamon(&queue->queue, type); 228 | * drivers/media/common/videobuf2/videobuf2-v4l2.c 229 | * vb2_core_streamon(q, type); 230 | * ret = vb2_start_streaming(q); 231 | * ret = call_qop(q, start_streaming, q, atomic_read(&q->owned_by_drv_count)); 232 | * drivers/media/usb/uvc/uvc_queue.c 233 | * static const struct vb2_ops uvc_queue_qops 234 | * .start_streaming = uvc_start_streaming 235 | * ret = uvc_video_enable(stream, 1); 236 | * ret = uvc_commit_video(stream, &stream->ctrl); 237 | * ret = uvc_init_video(stream, GFP_KERNEL); 238 | * ret = uvc_init_video_isoc(stream, best_ep, gfp_flags); 239 | * urb->complete = uvc_video_complete; 240 | * stream->decode(urb, stream, buf, buf_meta); 241 | * drivers/media/usb/uvc/uvc_video.c 242 | * int uvc_video_init(struct uvc_streaming *stream) 243 | * stream->decode = uvc_video_decode_isoc; 244 | * stream->decode = uvc_video_decode_bulk; 245 | * ret = uvc_init_video_bulk(stream, ep, gfp_flags); 246 | * usb_fill_bulk_urb(urb, stream->dev->udev, pipe, stream->urb_buffer[i], size, uvc_video_complete, stream); 247 | ``` 248 | ![images/UVC_USB_Get_Buffer.svg](images/UVC_USB_Get_Buffer.svg) 249 | * uvc_video_decode_isoc,参考《USB_Video_Class_1.x.pdf》中"2.4.3.3 Video and Still Image Payload Headers"小节: 250 | Every Payload Transfer containing video or still-image sample data must start with a Payload Header. 251 | ```C 252 | static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream, 253 | struct uvc_buffer *buf, struct uvc_buffer *meta_buf) 254 | { 255 | u8 *mem; 256 | int ret, i; 257 | 258 | for (i = 0; i < urb->number_of_packets; ++i) { 259 | if (urb->iso_frame_desc[i].status < 0) { 260 | uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame " 261 | "lost (%d).\n", urb->iso_frame_desc[i].status); 262 | /* Mark the buffer as faulty. */ 263 | if (buf != NULL) 264 | buf->error = 1; 265 | continue; 266 | } 267 | 268 | /* Decode the payload header. */ 269 | mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 270 | do { 271 | ret = uvc_video_decode_start(stream, buf, mem, 272 | urb->iso_frame_desc[i].actual_length); 273 | if (ret == -EAGAIN) 274 | uvc_video_next_buffers(stream, &buf, &meta_buf); 275 | } while (ret == -EAGAIN); 276 | 277 | if (ret < 0) 278 | continue; 279 | 280 | uvc_video_decode_meta(stream, meta_buf, mem, ret); 281 | 282 | /* Decode the payload data. */ 283 | uvc_video_decode_data(stream, buf, mem + ret, 284 | urb->iso_frame_desc[i].actual_length - ret); 285 | 286 | /* Process the header again. */ 287 | uvc_video_decode_end(stream, buf, mem, 288 | urb->iso_frame_desc[i].actual_length); 289 | 290 | if (buf->state == UVC_BUF_STATE_READY) 291 | uvc_video_next_buffers(stream, &buf, &meta_buf); 292 | } 293 | } 294 | ``` 295 | * 这个时候我们就会疑问,一帧结束了我们才调用complete,这是为什么呢?一张图片那么大,不可能一次传完,肯定分很多小帧,这个我们可能就要去找出`urb->number_of_packets`是谁决定的; 296 | * static int uvc_init_video_isoc(struct uvc_streaming *stream, struct usb_host_endpoint *ep, gfp_t gfp_flags) 297 | * urb->number_of_packets = npackets; 298 | * npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); 299 | * npackets = DIV_ROUND_UP(size, psize); 300 | * 以上size是图片数据大小,psize是单次USB端点数据传输大小; 301 | * uvc_alloc_urb_buffers 302 | ```C 303 | static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, 304 | unsigned int size, unsigned int psize, gfp_t gfp_flags) 305 | { 306 | unsigned int npackets; 307 | unsigned int i; 308 | 309 | /* Buffers are already allocated, bail out. */ 310 | if (stream->urb_size) 311 | return stream->urb_size / psize; 312 | 313 | /* Compute the number of packets. Bulk endpoints might transfer UVC 314 | * payloads across multiple URBs. 315 | */ 316 | npackets = DIV_ROUND_UP(size, psize); 317 | if (npackets > UVC_MAX_PACKETS) 318 | npackets = UVC_MAX_PACKETS; 319 | 320 | /* Retry allocations until one succeed. */ 321 | for (; npackets > 1; npackets /= 2) { 322 | for (i = 0; i < UVC_URBS; ++i) { 323 | stream->urb_size = psize * npackets; 324 | #ifndef CONFIG_DMA_NONCOHERENT 325 | stream->urb_buffer[i] = usb_alloc_coherent( 326 | stream->dev->udev, stream->urb_size, 327 | gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]); 328 | #else 329 | stream->urb_buffer[i] = 330 | kmalloc(stream->urb_size, gfp_flags | __GFP_NOWARN); 331 | #endif 332 | if (!stream->urb_buffer[i]) { 333 | uvc_free_urb_buffers(stream); 334 | break; 335 | } 336 | } 337 | 338 | if (i == UVC_URBS) { 339 | uvc_trace(UVC_TRACE_VIDEO, "Allocated %u URB buffers " 340 | "of %ux%u bytes each.\n", UVC_URBS, npackets, 341 | psize); 342 | return npackets; 343 | } 344 | } 345 | 346 | uvc_trace(UVC_TRACE_VIDEO, "Failed to allocate URB buffers (%u bytes " 347 | "per packet).\n", psize); 348 | return 0; 349 | } 350 | ``` 351 | * 如上可知,获取一张UVC图片,本身是一个URB请求完成一帧图片的获取,在初始化URB的时候,会算好要请求多少次,完成一次请求; -------------------------------------------------------------------------------- /docs/0024_USB_Keyboard.md: -------------------------------------------------------------------------------- 1 | # USB Keyboard 2 | 3 | ## 参考文档 4 | 5 | * [USB键盘驱动分析](https://www.cnblogs.com/likaiming/p/10841385.html) 6 | 7 | 8 | ## 源代码 9 | 10 | * drivers/hid/usbhid/usbkbd.c -------------------------------------------------------------------------------- /docs/images/AlternateStting_Interface_Request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/AlternateStting_Interface_Request.png -------------------------------------------------------------------------------- /docs/images/AlternateStting_Interface_Request_With_USB_Control_Center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/AlternateStting_Interface_Request_With_USB_Control_Center.png -------------------------------------------------------------------------------- /docs/images/Autopointers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Autopointers.png -------------------------------------------------------------------------------- /docs/images/CPU_Control_and_Status_Register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CPU_Control_and_Status_Register.png -------------------------------------------------------------------------------- /docs/images/CY7C68013A_Combinor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CY7C68013A_Combinor.jpg -------------------------------------------------------------------------------- /docs/images/CY7C68013A_Register_Debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CY7C68013A_Register_Debug.png -------------------------------------------------------------------------------- /docs/images/CY7C68013A_Schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CY7C68013A_Schematic.png -------------------------------------------------------------------------------- /docs/images/CYStream_Code_Arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CYStream_Code_Arch.png -------------------------------------------------------------------------------- /docs/images/CYStream_Compile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CYStream_Compile.png -------------------------------------------------------------------------------- /docs/images/CySuiteUSB_Download_And_Install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/CySuiteUSB_Download_And_Install.png -------------------------------------------------------------------------------- /docs/images/Download_Program_To_RAM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Download_Program_To_RAM.png -------------------------------------------------------------------------------- /docs/images/Driver_Download_Alone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Driver_Download_Alone.png -------------------------------------------------------------------------------- /docs/images/EZ-USB_FX2LP_Default_VID_PID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/EZ-USB_FX2LP_Default_VID_PID.png -------------------------------------------------------------------------------- /docs/images/GPIF_Back2Back_FIFO_Connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/GPIF_Back2Back_FIFO_Connect.png -------------------------------------------------------------------------------- /docs/images/GPIF_Back2Back_System_ARCH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/GPIF_Back2Back_System_ARCH.png -------------------------------------------------------------------------------- /docs/images/Get_AlternateSetting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Get_AlternateSetting.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_Enumerate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_Enumerate.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_IN_Wireshark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_IN_Wireshark.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_Interrupt_IN_Data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_Interrupt_IN_Data.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_Out_Wireshark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_Out_Wireshark.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_To_HID_Compliant_Device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_To_HID_Compliant_Device.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_To_HID_Compliant_Device_2_Byte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_To_HID_Compliant_Device_2_Byte.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_To_HID_Compliant_Device_Read_Write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_To_HID_Compliant_Device_Read_Write.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_To_HID_Compliant_Device_With_Report_ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_To_HID_Compliant_Device_With_Report_ID.png -------------------------------------------------------------------------------- /docs/images/HID_Keyboard_Wireshark_Filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/HID_Keyboard_Wireshark_Filter.png -------------------------------------------------------------------------------- /docs/images/Isochronous_Data_IN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Isochronous_Data_IN.png -------------------------------------------------------------------------------- /docs/images/Isochronous_Data_OUT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Isochronous_Data_OUT.png -------------------------------------------------------------------------------- /docs/images/Keil_Bulk_Example_Sample_Device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Bulk_Example_Sample_Device.png -------------------------------------------------------------------------------- /docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center.png -------------------------------------------------------------------------------- /docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center_In.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center_In.png -------------------------------------------------------------------------------- /docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center_Out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Bulk_Example_Sample_Device_In_Control_Center_Out.png -------------------------------------------------------------------------------- /docs/images/Keil_Components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Components.png -------------------------------------------------------------------------------- /docs/images/Keil_Environment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Keil_Environment.png -------------------------------------------------------------------------------- /docs/images/PB02_As_INPUT_Background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/PB02_As_INPUT_Background.jpg -------------------------------------------------------------------------------- /docs/images/PB02_As_OUTPUT_Background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/PB02_As_OUTPUT_Background.jpg -------------------------------------------------------------------------------- /docs/images/Set_AlternateSetting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Set_AlternateSetting.png -------------------------------------------------------------------------------- /docs/images/Set_Keil_Project_Environment_Item.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Set_Keil_Project_Environment_Item.png -------------------------------------------------------------------------------- /docs/images/Set_Keil_Project_Environment_With_Build_Info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Set_Keil_Project_Environment_With_Build_Info.png -------------------------------------------------------------------------------- /docs/images/StreamExample_Always_Select_Alt6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/StreamExample_Always_Select_Alt6.png -------------------------------------------------------------------------------- /docs/images/USB_Analyzer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/USB_Analyzer.png -------------------------------------------------------------------------------- /docs/images/USB_Control_Center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/USB_Control_Center.png -------------------------------------------------------------------------------- /docs/images/UVC_USB_Get_Buffer.svg: -------------------------------------------------------------------------------- 1 | drivers/media/usb/uvc/uvc_v4l2.cconst struct v4l2_ioctl_ops uvc_ioctl_ops.vidioc_streamon = uvc_ioctl_streamonret = uvc_queue_streamon(&stream->queue, type);ret = vb2_streamon(&queue->queue, type);drivers/media/common/videobuf2/videobuf2-v4l2.cvb2_core_streamon(q, type);ret = vb2_start_streaming(q);ret = call_qop(q, start_streaming, q, atomic_read(&q->owned_by_drv_count));drivers/media/usb/uvc/uvc_queue.cstatic const struct vb2_ops uvc_queue_qops.start_streaming = uvc_start_streamingret = uvc_video_enable(stream, 1);ret = uvc_commit_video(stream, &stream->ctrl);ret = uvc_init_video(stream, GFP_KERNEL);ret = uvc_init_video_isoc(stream, best_ep, gfp_flags);urb->complete = uvc_video_complete;stream->decode(urb, stream, buf, buf_meta);drivers/media/usb/uvc/uvc_video.cint uvc_video_init(struct uvc_streaming *stream)stream->decode = uvc_video_decode_isoc;stream->decode = uvc_video_decode_bulk;ret = uvc_init_video_bulk(stream, ep, gfp_flags);usb_fill_bulk_urb(urb, stream->dev->udev, pipe, stream->urb_buffer[i], size, uvc_video_complete, stream); -------------------------------------------------------------------------------- /docs/images/UnknowDevice_Detect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/UnknowDevice_Detect.png -------------------------------------------------------------------------------- /docs/images/UnknowDevice_To_Cypress_FX2LP_No_EEPROM_Device.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/UnknowDevice_To_Cypress_FX2LP_No_EEPROM_Device.png -------------------------------------------------------------------------------- /docs/images/Vendor_Commands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/Vendor_Commands.png -------------------------------------------------------------------------------- /docs/images/WireShark_USB_Capture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/images/WireShark_USB_Capture.png -------------------------------------------------------------------------------- /docs/refers/001-13670_EZ-USB_Technical_Reference_Manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/001-13670_EZ-USB_Technical_Reference_Manual.pdf -------------------------------------------------------------------------------- /docs/refers/001-88669_AN65209_Getting_Started_with_FX2LP_Chinese.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/001-88669_AN65209_Getting_Started_with_FX2LP_Chinese.pdf -------------------------------------------------------------------------------- /docs/refers/SimpleHIDWrite3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/SimpleHIDWrite3.zip -------------------------------------------------------------------------------- /docs/refers/USB_HID_Keyboard_Firmware.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/USB_HID_Keyboard_Firmware.pdf -------------------------------------------------------------------------------- /docs/refers/USB_Video_Class_1.1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/USB_Video_Class_1.1.pdf -------------------------------------------------------------------------------- /docs/refers/UVC 1.5 Class specification.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FolderLevel/USB/2c853153bc8e2eefb785c8a0a819e02136cc7da0/docs/refers/UVC 1.5 Class specification.pdf --------------------------------------------------------------------------------