This post was last edited by ljj3166 on 2018-4-16 16:31 Now I'm starting to get into the USB part, which is also a major selling point of this film. I played with the HID and KM demo in the example program. It's very simple to implement. You can get a general idea of the USB protocol by just understanding it a little bit. I won't go into the underlying USB protocol stuff in depth, as it makes me dizzy. The key point is to sort out a lot of descriptors and basically be able to run it. Think about it, the CH554 with integrated USB protocol is really convenient for full hardware implementation. Check the registers, play with the data, and click on anything you don't understand. It's great. The author uses the extremely hard OS usb driver. Although Qinheng also provides it, it is encapsulated and can't be played happily. So I thought of the invincible libusb-win32. The author uses CompatibilityHID. The VID used in the source code is 5131, and the PID is 2007. Take a look at the device descriptor:
Note the order of high and low bytes. There is another very important place to configure the descriptor:
The endpoint of the pipe describes the subsequent communication. This must match. First, change the windows driver and use the invincible libusb.
Find the USB device corresponding to the VID and PID. If the device is broken, blame the OP.
It is necessary to install 13. Then there are some basic installation operations.
It is very sexy.
The OP has 6 more videos like this one.
- while(1) { if(Ready&& (Ep2InKey==0)) { Enp2BlukIn() ; mDelaymS( 100 ); } // mDelaymS( 100 ); //Simulate the microcontroller to do other thingsif(send_flag == 0x01) { printf(Ep2Buffer); send_flag = 0x00; memset(Ep2Buffer, '\0', THIS_ENDP0_SIZE); } else {} }
复制代码Slightly modify the single-chip chicken code. The general meaning is to print out the received data after receiving the data
- case UIS_TOKEN_OUT | 2: //endpoint 2# Endpoint batch downloadif ( U_TOG_OK ) // Unsynchronized data packets will be discarded{ len = USB_RX_LEN; // Receive data length, data is stored from the first address of Ep2Buffer// for ( i = 0; i < len; i ++ ) // { // Ep2Buffer[MAX_PACKET_SIZE+i] = Ep2Buffer[i];// ^ 0xFF; // OUT data is inverted to IN and verified by the computer// } // UEP2_T_LEN = len; UEP2_T_LEN = 8; Ep2Buffer[MAX_PACKET_SIZE+0] = 'g'; Ep2Buffer[MAX_PACKET_SIZE+1] = 'o'; Ep2Buffer[MAX_PACKET_SIZE+2] = 't'; Ep2Buffer[MAX_PACKET_SIZE+3] = ' '; Ep2Buffer[MAX_PACKET_SIZE+4] = 'd'; Ep2Buffer[MAX_PACKET_SIZE+5] = 'a'; Ep2Buffer[MAX_PACKET_SIZE+6] = 't'; Ep2Buffer[MAX_PACKET_SIZE+7] = 'a'; UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK; // Allow upload send_flag = 0x01; }
复制代码After receiving data in the USB interrupt, it returns "got data" and sets send_flag. I am afraid that the editor will crash. To be continued, please watch the next episode......
This content is originally created by EEWORLD forum user ljj3166. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source