Author Topic: Control Panel and HID  (Read 25365 times)

tallman

  • Member
  • ***
  • Posts: 25
Control Panel and HID
« on: October 16, 2013, 06:35:45 pm »
I am a beginner but have USB Complete book and of course google.

I have a embedded ARM device as a composite USB device with a standard USB HID Mouse, and HID Keyboard.

I want to have a control panel in windows to allow the user to set some parameters.  And I want to pass those parameters back to my device when it's connected, and when they change and save.  Is there a standard place to save this data and/or a way via HID to allow me to put information from application on PC, and my device can issue a command for the HID to send this information as report?  I suspect I'm using all the wrong terms, but I don't know how this is officially described. 

I don't want to create a custom Driver if I can avoid.  I see terms like HID API functions, but don't know, if thats how it's done.

Right now I use winusb to transfer the information, but would prefer it be a standard way of doing it without needing winusb since my application wont be running on computer all the time, only when user wants to change parameters, and when I install device.

Thank you for any help.
Brent

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #1 on: October 16, 2013, 10:18:16 pm »
You can make the device a "generic" HID with a vendor-defined function. The host system can run an application and use the HID API and ReadFile/WriteFile or Filestreams to access the device. You can define the content of the HID reports any way you want.

I have example generic HID applications here:

http://www.lvr.com/hidpage.htm#MyExampleCode

tallman

  • Member
  • ***
  • Posts: 25
Re: Control Panel and HID
« Reply #2 on: October 17, 2013, 01:25:58 pm »
Jan,
Thank you so much for your response.  I've read through the product and use of generic HID, and what I don't understand is how to get that program running when I connect my device.  So the first time I connect it, or anytime after, I want information to immediatly be sent to the device for the user parameters.  If I understand using the Generic HID, I need to read my information via my application program and pass it to the device, but what if my application isn't running when the consumer connects the device?  How do I get it running automatically (or a smaller version to pass just the stored information settings)?  I haven't found anything in INF.  I assume a device driver does this as part of it's operation, but I'm of course trying to avoid that route.

Thank you so much.  Your book has been very helpful to me and I see a section covering this info.
Brent

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #3 on: October 17, 2013, 04:57:07 pm »
Here is one article I found with a search on

windows run application startup

http://grok.lsu.edu/article.aspx?articleId=13076

I'm glad to hear you've found USB Complete useful.

tallman

  • Member
  • ***
  • Posts: 25
Re: Control Panel and HID
« Reply #4 on: October 17, 2013, 06:43:12 pm »
Jan,
Thanks for the response.  I was hoping there was a standard way this is done specifically for USB devices.  So based on your reply, I'm assuming my only way to deal with this would be to have a program or service out running all the time, looking to see when the device is connected, then send the information at that time to the device throught he generic HID api.  Let me know if that sounds right.

I was hoping there was a generic HID device that automatically read registry or something and passed it immediately based on connection.  Seems like that would be a great way for more host independance.

Appreciate the feedback.
Brent

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #5 on: October 17, 2013, 08:42:55 pm »
You could make the device a composite device that contains both a HID interface and a mass-storage interface that holds an autorun.inf file that runs an application on attachment.

tallman

  • Member
  • ***
  • Posts: 25
Re: Control Panel and HID
« Reply #6 on: October 17, 2013, 09:23:21 pm »
Well thats a creative and cool solution!  I'll give that a try.
Thanks a bunch.
Brent

sdecorme

  • Member
  • ***
  • Posts: 7
Re: Control Panel and HID
« Reply #7 on: November 27, 2013, 03:25:39 am »
Hi
I've found this topic really instructive because I would like to do the same with the joystick sample.
I would like to add the way to send custom data throught a MFC to change some parameters.
My descriptor works perfectly it is based on the microchip library.
But I don't really understand how to add the specific vendor frame
I would like to add a simple example in feature mode.
Code: [Select]
0x09, 0x01, // Usage ID (vendor defined)
  0xA1, 0x01, // Collection (application)
    0x09, 0x05,      // Usage ID - vendor defined
    0x15, 0x00,      // Logical Minimum (0)
    0x26, 0xFF, 0x00,           // Logical Maximum (255)
    0x75, 0x08, // Report Size (8 bits)
    0x95, 0x02, // Report Count (2 fields)
    0xB1, 0x02,      // Feature (Data, Variable, Absolute)
0xC0
I don't really understand where to add it in my descriptor
I've done this but the joystick doesn't work
Code: [Select]
ROM struct{BYTE report[HID_RPT01_SIZE];}hid_rpt01={

  0x05,0x01,        //USAGE_PAGE (Generic Desktop)
  0x09,0x05,        //USAGE (Game Pad)
  0xA1,0x01,        //COLLECTION (Application)
    0x15,0x00,        //  LOGICAL_MINIMUM(0)
    0x25,0x01,        //  LOGICAL_MAXIMUM(1)
    0x35,0x00,        //  PHYSICAL_MINIMUM(0)
    0x45,0x01,        //  PHYSICAL_MAXIMUM(1)
    0x75,0x01,        //  REPORT_SIZE(1)
    0x95,0x08,        //  REPORT_COUNT(5)
    0x05,0x09,        //  USAGE_PAGE(Button)
    0x19,0x01,        //  USAGE_MINIMUM(Button 1)
    0x29,0x08,        //  USAGE_MAXIMUM(Button 5)
    0x81,0x02,        //  INPUT(Data,Var,Abs)

    0x05,0x01,        //USAGE_PAGE (Generic Desktop)
    0x26,0xFF,0x00,   //  LOGICAL_MAXIMUM(255)
    0x46,0xFF,0x00,   //  PHYSICAL_MAXIMUM(255)
    0x09,0x30,        //  USAGE(X)
    0x09,0x31,        //  USAGE(Y)
    0x09,0x32,        //  USAGE(Z)
    0x09,0x35,        //  USAGE(Rz)
    0x75,0x08,        //  REPORT_SIZE(8)
    0x95,0x04,        //  REPORT_COUNT(4)
    0x81,0x02,        //  INPUT(Data,Var,Abs)
  0xC0,              //END_COLLECTION

//  0x06, 0xA0, 0xFF, // Usage page (vendor defined)
  0x09, 0x01, // Usage ID (vendor defined)
  0xA1, 0x01, // Collection (application)
    0x09, 0x05,      // Usage ID - vendor defined
    0x15, 0x00,      // Logical Minimum (0)
    0x26, 0xFF, 0x00,    // Logical Maximum (255)
    0x75, 0x08, // Report Size (8 bits)
    0x95, 0x02, // Report Count (2 fields)
    0xB1, 0x02,      // Feature (Data, Variable, Absolute)
 0xC0

};

Thanks you

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #8 on: November 27, 2013, 10:17:35 am »
My HID page has host application and PIC firmware examples for feature reports using control transfers:

http://www.lvr.com/hidpage.htm#MyExampleCode

sdecorme

  • Member
  • ***
  • Posts: 7
Re: Control Panel and HID
« Reply #9 on: November 27, 2013, 10:51:16 am »
Hi jan,
I've look at your code : Device - HID - Generic (LVR)
But it is only vendor specidic protocol , what I would like to do is to add at the joystick sample some parameters capabilities.
I've found a code of a composite system , but I'm not really sure to make everything right because mys joystick doesn't work anymore.
I've modified the descriptor like this
Code: [Select]
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
    MY_VID,                 // Vendor ID, see usb_config.h
    MY_PID,                 // Product ID, see usb_config.h
    0x0001,                 // 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
    DESC_CONFIG_WORD(0x0049),       // Total length of data for this cfg
    2,                              // 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 Descriptor1  Joystick */
    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
    BOOT_INTF_SUBCLASS,             // Subclass code
    HID_PROTOCOL_JOYSTICK,          // Protocol code
    0,                              // Interface string index

    /* HID Class-Specific Descriptor */
    0x09,//sizeof(USB_HID_DSC)+3,   // Size of this descriptor in bytes RRoj hack
    DSC_HID,                        // HID descriptor type
    DESC_CONFIG_WORD(0x0111),       // 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
    DESC_CONFIG_WORD(HID_RPT01_SIZE),// sizeof(hid_rpt01),      // Size of the report descriptor
   
    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
    HID_EP1 | _EP_IN,               // EndpointAddress
    _INTERRUPT,                     // Attributes
    DESC_CONFIG_WORD(64),           // size
    0x01,                           // Interval

    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
    HID_EP1 | _EP_OUT,              // EndpointAddress
    _INTERRUPT,                     // Attributes
    DESC_CONFIG_WORD(64),           // size
    0x01,                           // Interval

/* Interface Descriptor2  Control panel */
    0x09,//sizeof(USB_INTF_DSC),    // Size of this descriptor in bytes
    USB_DESCRIPTOR_INTERFACE,       // INTERFACE descriptor type
    1,                              // Interface Number
    0,                              // Alternate Setting Number
    2,                              // Number of endpoints in this intf
    HID_INTF,                       // Class code
    BOOT_INTF_SUBCLASS,             // Subclass code
    HID_PROTOCOL_CONFIG,            // Protocol code
    0,                              // Interface string index

/* HID Class-Specific Descriptor */
    0x09,//sizeof(USB_HID_DSC)+3,   // Size of this descriptor in bytes RRoj hack
    DSC_HID,                        // HID descriptor type
    DESC_CONFIG_WORD(0x0111),       // 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
    DESC_CONFIG_WORD(HID_RPT02_SIZE),//sizeof(hid_rpt02),      // Size of the report descriptor

    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
    HID_EP2 | _EP_IN,               // EndpointAddress
    _INTERRUPT,                     // Attributes
    DESC_CONFIG_WORD(64),           // size
    0x01,                           // Interval

    /* Endpoint Descriptor */
    0x07,/*sizeof(USB_EP_DSC)*/
    USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
    HID_EP2 | _EP_OUT,              // EndpointAddress
    _INTERRUPT,                     // Attributes
    DESC_CONFIG_WORD(64),           // size
    0x01                            // Interval

};


and I add a second report

Code: [Select]
ROM struct{BYTE report[HID_RPT02_SIZE];}hid_rpt02=
{
    0x06,0x00, 0xFF,        // USAGE_PAGE (Vendor Defined Page 1)
    0x09,0x01,              // USAGE (Vendor Usage 1)
    0xa1,0x01,              // COLLECTION (Application)
        0x85,0x01,          // Report Id  1
        0x16,0x30,0xF8,     // LOGICAL_MINIMUM(-2000)
        0x26,0xD0,0x07,     // LOGICAL_MAXIMUM(+2000)
        0x75,0x10,          // REPORT_SIZE(16)
        0x95,0x04,          // REPORT_COUNT(1)
        0xB1,0x02,          // FEATURE (Data,Var,Abs)
        0x85,0x02,          // Report Id  2
        0x15,0x00,          // LOGICAL_MINIMUM(0)
        0x25,0x64,          // LOGICAL_MAXIMUM(1)
        0x75,0x08,          // REPORT_SIZE(8)
        0x95,0x0D,          // REPORT_COUNT(1)
        0xB1,0x02,          // FEATURE (Data,Var,Abs)
  0xC0,                  //END_COLLECTION

};


And of course I've modified the USBCheckHIDRequest function to accept the request to send the report 1 and report 2

Code: [Select]
case DSC_HID: //HID Descriptor         
                if(USBActiveConfiguration == 1)
                {
                    if (SetupPkt.bIntfID == HID_INTF_ID1)
                    {
                        USBEP0SendROMPtr(
                        (ROM BYTE*)&configDescriptor1 + 18,        //18 is a magic number.  It is the offset from start of the configuration descriptor to the start of the HID descriptor.
                        sizeof(USB_HID_DSC)+3,
                        USB_EP0_INCLUDE_ZERO);
                    }
                    if (SetupPkt.bIntfID == HID_INTF_ID2)
                    {
                        USBEP0SendROMPtr(
                        (ROM BYTE*)&configDescriptor1 + 43,        //43 is a magic number.  It is the offset from start of the configuration descriptor to the start of the HID descriptor.
                        sizeof(USB_HID_DSC)+3,
                        USB_EP0_INCLUDE_ZERO);
                    }
                }
                break;
            case DSC_RPT:  //Report Descriptor           
                if(USBActiveConfiguration == 1)
                {
                    if (SetupPkt.bIntfID == HID_INTF_ID1)
                    {
                        USBEP0SendROMPtr(
                        (ROM BYTE*)&hid_rpt01,
                        HID_RPT01_SIZE,     //See usbcfg.h
                        USB_EP0_INCLUDE_ZERO);
                    }
                    if (SetupPkt.bIntfID == HID_INTF_ID2)
                    {
                        USBEP0SendROMPtr(
                        (ROM BYTE*)&hid_rpt02,
                        HID_RPT02_SIZE,     //See usbcfg.h
                        USB_EP0_INCLUDE_ZERO);
                    }
                }
                break;
 



maybe I've forgot something because my pic is not connected the initialisation failed is here my http://pro.ellip6.com/SebastienForum/Log.html

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #10 on: November 27, 2013, 11:38:05 am »
If you haven't changed the Product ID, Windows might be remembering the previous descriptors.

With the functioning device attached, open Windows Device Manager and uninstall the device (under Driver). Then reattach with the new firmware.

sdecorme

  • Member
  • ***
  • Posts: 7
Re: Control Panel and HID
« Reply #11 on: November 28, 2013, 01:03:44 am »
Hi,
Good idea now it works , The composite is detected as 2 HID compoment and the joystick works.
I use your sample to make my second descriptor and I've a question .
Why the usage ID doesn't start at 0x01 ? : 0x09,0x03,              // Usage ID - vendor defined
If I put 0x01 instead 0x03 it doesn't work.
Another question how can I speak to my component. I've downloaded your sample "Generic_Hid_cs_v62"
but how I address either Endpoint 1 or 2 ?
Thanks you

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #12 on: November 30, 2013, 01:26:02 pm »
I don't know why a vendor-defined usage of 01 doesn't work unless it's the Windows remembering issue again.

The application software doesn't know or care what endpoints it's accessing. It just opens a handle to the HID and uses the HID's endpoints. To access both of your HIDs, you will need to open two handles. Both will have the same Vendor ID and Product ID, but you can use other values in the Capabilities structure to tell them apart.

sdecorme

  • Member
  • ***
  • Posts: 7
Re: Control Panel and HID
« Reply #13 on: December 02, 2013, 11:00:30 am »
Is there radical way to remove all of the key in the windows registers ? , some keys can't be remove with suppr?
I try to use USBView but some keys are not remove too , even in administator mode .

I try another way, I add directly new report in the initial descriptor like this I've only 2 Endpoints.

Code: [Select]

  0x06,0x00,0xFF,   //  Usage page Vendor defined
  0x09,0x01,        //  Usage Vendor defined
  0x95,0x01,        //  REPORT_COUNT(1)
  0x91,0x02,        //  OUTPUT(Data,Var,Abs)

  0x09,0x02,        //  Usage Vendor defined
  0x95,0x02,        //  REPORT_COUNT(1)
  0x91,0x02,        //  OUTPUT(Data,Var,Abs)


It seem to work and the joystick works fine.
Now I can simply use your code to "send Output report".
In you code I've to change the "outputReportBuffer[0] =  ???;"
with the ID I would like to modify Isn't it ?

Thanks you


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Control Panel and HID
« Reply #14 on: December 02, 2013, 02:40:28 pm »
I don't know what you mean by "way to remove all of the key in the windows registers".

Yes, you can try defining multiple Output reports with different report IDs and placing the ID for the desired report in the buffer. Both Output reports should have a report ID > 0.