Connect to the HID server

All USB devices are assigned a unique vendor ID. Clients may use the information provided in these fields to receive notification of device insertion only for devices they’re interested in. If there’s a specific vendor or device your driver wants to support, then you'd fill in the appropriate fields of the hidd_device_ident_t structure with the values the device would report, or use HIDD_CONNECT_WILDCARD if no device is of particular interest. If this identifier is set to NULL, then it’s assumed that all fields are HIDD_CONNECT_WILDCARD.

Refer to the main() function in joystick_demo.c of the demo driver for an example usage.

typedef struct hidd_device_ident {
        _Uint32t    vendor_id;
        _Uint32t    product_id;
        _Uint32t    version;
} hidd_device_ident_t;

Set up the callback functions to be used for device events by filling in the hidd_funcs_t structure:

typedef struct hidd_funcs {
        _Uint32t    nentries;
        void        (*insertion)(struct hidd_connection *, hidd_device_instance_t *instance);
        void        (*removal)(struct hidd_connection *, hidd_device_instance_t *instance);
        void        (*report)(struct hidd_connection *, struct hidd_report *handle, void *report_data, _Uint32t report_len, _Uint32t flags, void *user);
        void        (*event)(struct hidd_connection *, hidd_device_instance_t *instance, _Uint16t type);
} hidd_funcs_t;

Now, fill in the hidd_connect_parm_t structure with device identifiers, callback functions and other parameters of your interest to set up a connection:

typedef struct hidd_connect_parm {
        const char              *path;          // Name of the server (NULL defaults to the HID server i.e /dev/io-hid/io-hid
        _Uint16t                vhid;           // Version of the HID server (HID VERSION)
        _Uint16t                vhidd;          // Versions of the HID DDK (HIDD VERSION)
        _Uint32t                flags;          // HIDD_CONNECT_FLAGS_PNP_MONITOR or HIDD_CONNECT_FLAGS_SET_STACK_SIZE (in usual cases, you won't need either)
        _Uint32t                evtbufsz;       // Size of the event buffer used to buffer events from the HID server (Use 0 for default size)
        hidd_device_ident_t     *device_ident;  // The device identifier we previously defined
        hidd_funcs_t            *funcs;         // The callbacks we previously set up
        _Uint16t                connect_wait;   // A waittime in seconds (Use HIDD_CONNECT_WAIT)
        _Uint16t                stack_size;
        _Uint16t                _reserved[4];
} hidd_connect_parm_t;

Finally, connect to the HID server using hidd_connect(). This API takes connection parameters and connection handle and establishes a connection with the HID server:

...
if((status = hidd_connect (&parm, &ClientCtrl.connection)) != EOK) {
    fprintf (stderr, "%s: Can't connect to HID Server: %s\n", __FUNCTION__, strerror(status));
    return (1);
}
Page updated: