USB de HID fakat hangi sinif?

Başlatan bunalmis, 24 Ocak 2011, 19:15:18

z

Windows API leri kullanarak HID yapisinda USB bir cihaz tasarlamaya calisiyorum.
Amacim olabildigince hizli bir sekilde her iki yonde de veri aktarimi.

Bu amacla USB kartin kendi yazilimini komplikelestirden yapabilecegim en yalin cihaz sinifi ne olabilir?

Secenekler cok. Ornegin Keyboard, mouse, trackball, joystick, font-panel controls, telephones, VCR remote controls,
games or simulation devices vs vs

Fakat sectigim cihaz tipinin isletim sistemine olumsuz etkisi de olmamali.  Atiyorum, mouse gibi tasarlanmis bir cihaz PC ile veri aktarimi yaparken kursorun ordan oraya ziplamasi hos olmaz.

Bana e^st de diyebilirsiniz.   www.cncdesigner.com

t2

En yalın sınıf budur bunu kullanmalısın. Ben çok kullandım. hala da kullanıyorum


;Configuration Descriptor
___Config1
   retlw   (__Interface1-___Config1) / 2   ; bLength Length of this descriptor
   retlw   __DSC_CFG                  ; bDescType 2 = CONFIGURATION
__Config1Len
   retlw   low ((__EndConfig1 - ___Config1) / 2)   ; Length of this configuration
   retlw   high ((__EndConfig1 - ___Config1) / 2)
   retlw   0x01                     ; bNumInterfaces Number of interfaces
   retlw   0x01                     ; bConfigValue Configuration Value
   retlw   0x04                     ; iConfig String Index for this config = #01
   retlw   0xA0                     ; bmAttributes attributes - bus powered

        ; Max power consumption (2X mA)
   retlw   0x32
__Interface1
   retlw   (__HIDDescriptor1 - __Interface1) / 2   ; length of descriptor
   retlw   __DSC_INTF
   retlw   0x00                     ; number of interface, 0 based array
   retlw   0x00                     ; alternate setting
   retlw   0x02                     ; number of endpoints used in this interface
   retlw   0x03                     ; interface CLASS - assigned by the USB
   retlw   0x00                     ; boot device
   retlw   0x00                     ; interface protocol - mouse
   retlw    0x00                     ; index to string descriptor that describes this interface
__HIDDescriptor1
   retlw   (__Endpoint1In - __HIDDescriptor1) / 2   ; descriptor size (9 bytes)
     retlw   0x21                     ; descriptor type (HID)
   dt      0x00, 0x00                  ; HID CLASS release number (1.00) low byte, high byte
      retlw   0x00                     ; Localised country code (none)
   retlw   0x01                     ; Number of HID CLASS descriptor to follow (1)
   retlw   0x22                     ; Report descriptor type (HID)
__ReportDescriptor1Len
   retlw   low ((__EndReportDescriptor1 - __ReportDescriptor1) / 2)
   retlw   high ((__EndReportDescriptor1 - __ReportDescriptor1) / 2)
__Endpoint1In
   retlw   (__EndPoint1Out - __Endpoint1In) / 2   ; length of descriptor
   retlw   __DSC_EP
   retlw   0x81                     ; EP1, IN
   retlw   0x03                     ; Interrupt
   dt   0x40, 0x00                  ; This should be the size of the endpoint buffer low byte, high byte
   retlw   0x01                     ; Polling interval
__EndPoint1Out
   retlw   (__EndConfig1 - __EndPoint1Out) / 2   ; Length of this Endpoint Descriptor
   retlw   __DSC_EP                  ; bDescriptorType = 5 for Endpoint Descriptor
   retlw   0x01                     ; Endpoint number & direction
   retlw   0x03                     ; Transfer type supported by this Endpoint
   dt   0x40, 0x00                  ; This should be the size of the endpoint buffer low byte, high byte
   retlw   0x01                     ; Polling interval
__EndConfig1

__ReportDescriptor1
    ; vendor defined usage page
    retlw   0x06      
   retlw   0x00       
    retlw   0xFF

    ; vendor defined usage
    retlw   0x09      
    retlw   0x00

    ; collection(application)
    retlw   0xA1      
    retlw   0x01

    ; *** INPUT REPORT ***
               
    ; vendor defined usage
    retlw   0x09      
    retlw   0x01

    retlw   0x15      ; logical minimum (-128)
    retlw   0x80        ;
    retlw   0x25      ; logical maximum (127)
    retlw   0x7F        ;
    retlw   0x35      ; Physical Minimum (0)
    retlw   0x00        ;
    retlw   0x45      ; Physical Maximum (255)
    retlw   0xFF        ;
       
    ; report size in bits
    retlw   0x75   
   retlw   0x08
       
    ; report count (number of fields)
    retlw   0x95      
   retlw   0x40
       
    ; Input (Data, Variable, Absolute)
    retlw   0x81      
   retlw   0x02

    ; *** OUTPUT REPORT ***
   
    ; vendor defined usage
    retlw   0x09      ; usage (Vendor Defined)
   retlw   0x02        ;

   retlw   0x15      ; logical minimum (-128)
   retlw   0x80        ;
    retlw   0x25      ; logical maximum (127)
   retlw   0x7F        ;
    retlw   0x35      ; Physical Minimum (0)
   retlw   0x00        ;
    retlw   0x45      ; Physical Maximum (255)
   retlw   0xFF        ;
       
    ; report size in bits
    retlw   0x75      
   retlw   0x08
       
    ; report count (number of fields)
    retlw   0x95   
   retlw   0x40
       
    ; Output (Data, Variable, Absolute)
    retlw   0x91      
   retlw   0x02

   retlw   0xC0      ; end collection
__EndReportDescriptor1

t2

#2
Bu da olur. Genel amaçlı insan arabirim aygıtı olarak görünür. fare gibi bilindik bir aygıt sınıfı olması gerekmez.

/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
    0x12,    // Size of this descriptor in bytes
    USB_DESCRIPTOR_DEVICE,                // DEVICE descriptor type
    0x0200,                 // USB Spec Release Number in BCD format
    0x00,                   // Class Code
    0x00,                   // Subclass code
    0x00,                   // Protocol code
    USB_EP0_BUFF_SIZE,          // Max packet size for EP0, see usb_config.h
    0x04D8,                 // Vendor ID
    0x003F,                 // Product ID: Custom HID demo
    0x0002,                 // Device release number in BCD format
    0x01,                   // Manufacturer string index
    0x02,                   // Product string index
    0x00,                   // Device serial number string index
    0x01                    // Number of possible configurations
};

/* Configuration 1 Descriptor */
ROM BYTE configDescriptor1[]={
    /* Configuration Descriptor */
    0x09,//sizeof(USB_CFG_DSC),    // Size of this descriptor in bytes
    USB_DESCRIPTOR_CONFIGURATION,                // CONFIGURATION descriptor type
    0x29,0x00,            // Total length of data for this cfg
    1,                      // Number of interfaces in this cfg
    1,                      // Index value of this configuration
    0,                      // Configuration string index
    _DEFAULT | _SELF,               // Attributes, see usb_device.h
    50,                     // Max power consumption (2X mA)
                     
    /* Interface Descriptor */
    0x09,//sizeof(USB_INTF_DSC),   // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,               // INTERFACE descriptor type
    0,                      // Interface Number
    0,                      // Alternate Setting Number
    2,                      // Number of endpoints in this intf
    HID_INTF,               // Class code
    0,     // Subclass code
    0,     // Protocol code
    0,                      // Interface string index

    /* HID Class-Specific Descriptor */
    0x09,//sizeof(USB_HID_DSC)+3,    // Size of this descriptor in bytes
    DSC_HID,                // HID descriptor type
    0x11,0x01,                 // HID Spec Release Number in BCD format (1.11)
    0x00,                   // Country Code (0x00 for Not supported)
    HID_NUM_OF_DSC,         // Number of class descriptors, see usbcfg.h
    DSC_RPT,                // Report descriptor type
    HID_RPT01_SIZE,0x00,//sizeof(hid_rpt01),      // Size of the report descriptor
   
    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    HID_EP | _EP_IN,                   //EndpointAddress
    _INTERRUPT,                       //Attributes
    0x40,0x00,                  //size
    0x01,                        //Interval

    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
    HID_EP | _EP_OUT,                   //EndpointAddress
    _INTERRUPT,                       //Attributes
    0x40,0x00,                  //size
    0x01                        //Interval
};

//Language code string descriptor
ROM struct{BYTE bLength;BYTE bDscType;WORD string[1];}sd000={
sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409
}};





//Class specific descriptor - HID
ROM struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={
{
    0x06, 0x00, 0xFF,       // Usage Page = 0xFF00 (Vendor Defined Page 1)
    0x09, 0x01,             // Usage (Vendor Usage 1)
    0xA1, 0x01,             // Collection (Application)
    0x19, 0x01,             //      Usage Minimum
    0x29, 0x40,             //      Usage Maximum    //64 input usages total (0x01 to 0x40)
    0x15, 0x01,             //      Logical Minimum (data bytes in the report may have minimum value = 0x00)
    0x25, 0x40,              //      Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
    0x75, 0x08,             //      Report Size: 8-bit field size
    0x95, 0x40,             //      Report Count: Make sixty-four 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item)
    0x81, 0x00,             //      Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage.
    0x19, 0x01,             //      Usage Minimum
    0x29, 0x40,             //      Usage Maximum    //64 output usages total (0x01 to 0x40)
    0x91, 0x00,             //      Output (Data, Array, Abs): Instantiates output packet fields.  Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item.
    0xC0}                   // End Collection
};                 



z

Inceledigim kadariyla verdigin bu tablolarda bazi degerler header dosyadan geliyor ve adi sanirim usbcfg.h.

Bu dosyayi da ekleyebilirmisin?

Bana e^st de diyebilirsiniz.   www.cncdesigner.com