![]() |
|
Tài trợ cho PIC Vietnam |
||||||||
| Giao tiếp USB, CAN, I2C, SPI, USART... Những giao tiếp được tích hợp trên PIC |
|
|
Ðiều Chỉnh | Xếp Bài |
|
|
#6 |
|
Đệ tử 2 túi
Tham gia ngày: Feb 2006
Bài gửi: 44
: |
File tiếp theo để định dạng cấu hình:
---------------------ten Bulk.c------------------- #IFNDEF __USB_DESCRIPTORS__ #DEFINE __USB_DESCRIPTORS__ #include <D:\Pic_USB\usb.h> #DEFINE USB_TOTAL_CONFIG_LEN 46 //46 config+interface+class+endpoint //Thong tin ve cau truc cua thiet bi char const USB_CONFIG_DESC[] = { //config_descriptor for config index 1 USB_DESC_CONFIG_LEN, //length of descriptor size USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (0x02) USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config 1, //number of interfaces this device supports 0x01, //identifier for this configuration. (IF we had more than one configurations) 0x00, //index of string descriptor for this configuration 0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1 0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) //interface descriptor 0 alt 0 USB_DESC_INTERFACE_LEN, //length of descriptor USB_DESC_INTERFACE_TYPE, //constant INTERFACE (0x04) 0x00, //number defining this interface (IF we had more than one interface) 0x00, //alternate setting 4, //So Endpoint su dung trong chuong trinh(khong tinh Endpint 0 la Endpoint Control) 0xFF, //class code, FF = vendor defined 0xFF, //subclass code, FF = vendor 0xFF, //protocol code, FF = vendor 0x00, //index of string descriptor for interface //endpoint 81 USB_DESC_ENDPOINT_LEN, //length of descriptor USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05) 0x81, //endpoint number and direction (0x81 = EP1 IN) 0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt) USB_EP1_TX_SIZE,0x00, //maximum packet size supported Max=64 0x01, //thoi gan hoi vong (polling) chi dung trong Ngat //Endpoin 82 USB_DESC_ENDPOINT_LEN, //length of descriptor USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05) 0x82, //endpoint number and direction (0x82 = EP1 IN) 0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt) USB_EP2_TX_SIZE,0x00, //maximum packet size supported Max=64 0x01, //Endpoin 83 USB_DESC_ENDPOINT_LEN, //length of descriptor USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05) 0x83, //endpoint number and direction (0x83 = EP1 IN) 0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt) USB_EP3_TX_SIZE,0x00, //maximum packet size supported Max=64 0x01, //endpoint descriptor USB_DESC_ENDPOINT_LEN, //length of descriptor USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05) 0x01, //endpoint number and direction (0x01 = EP1 OUT) 0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt) USB_EP1_RX_SIZE,0x00, //maximum packet size supported 0x01, //polling interval in ms. (for interrupt transfers ONLY) }; #define USB_NUM_HID_INTERFACES 0 //the maximum number of interfaces seen on any config //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2 #define USB_MAX_NUM_INTERFACES 1 //define how many interfaces there are per config. [0] is the first config, etc. const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1}; #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN) #error USB_TOTAL_CONFIG_LEN not defined correctly #endif ////////////////////////////////////////////////////////////////// /// // /// Dinh dang thiet bi USB // /// De hieu ro hon phan nay xin doc USBcomplete.Pdf kem theo // ////////////////////////////////////////////////////////////////// char const USB_DEVICE_DESC[] ={ USB_DESC_DEVICE_LEN, //the length of this report=18.Chuan cua USB 0x01, //constant DEVICE (0x01) 0x10,0x01, //usb version in bcd 0x00, //class code (if 0, interface defines class. FF is vendor defined) 0x00, //subclass code 0x00, //protocol code USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8).La endpoint Control //------------------------------------------------------------- //__vendor id va product id la ma san pham duoc host nhan ra:kich thuoc la 2 bytes 0x07,0x20, //vendor id la ma cong ty duoc dang ki tren: http:// usb.org__VD:0x07,0x20,=2007 0x04,0x01, //product id la ma san pham ___VD:0x04,0x01,=0104 //------------------------------------------------------------- 0x00,0x01, //device release number 0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) 0x02, //index of string descriptor of the product 0x00, //index of string descriptor of serial number USB_NUM_CONFIGURATIONS //number of possible configurations }; /////////////////////////////////////////////////////////////////////////////////////////// /// Day la dong thong bao cho Host biet hiet bi ma no tim thay.Ding dang thiet bi // /// String 0 :Ngon ngu the dien,va chung ta phai ding nghia // /////////////////////////////////////////////////////////////////////////////////////////// const char USB_STRING_DESC_OFFSET[]={0,4,12}; #define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET) char const USB_STRING_DESC[]={ //string 0____________Ngon ngu hien thi 4, //length of string index USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) 0x09,0x04, //Microsoft Defined for US-English //string 1____________Ten thiet bi se duoc hien thi tren Host 8, //length of string index USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING) 'D',0, 'L',0, '1',0, //string 2____________noi dung thong bao tren tastbar khi cam thiet bi vao PC 42, //_____Do dai cua chuoi thong bao thiet bi.Tinh ca so 0=So_ki_tu*2+2.neu thua se co loi ki tu USB_DESC_STRING_TYPE, //________Dung de truyen hay thong bao cho CCS biet do la String 'D',0, 'o',0, ' ',0, 'A',0, 'n',0, ' ',0, 'T',0, 'o',0, 't',0, ' ',0, 'N',0, 'g',0, 'h',0, 'i',0, 'e',0, 'p',0, ' ',0, 'K',0, '4',0, '7',0, }; #ENDIF |
|
|
|
| Ðiều Chỉnh | |
| Xếp Bài | |
|
|