This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Attach to a USB device
#include <sys/usbdi.h> int usbd_attach( struct usbd_connection *connection, usbd_device_instance_t *instance, size_t extra, struct usbd_device **device );
You use the usbd_attach() function to attach to a USB device. Typically, you do this out of the insertion callback (made when the device matched your filter), which will give you the connection and instance parameters involved. The insertion callback is prototyped as follows:
void (*insertion)(struct usbd_connection *, usbd_device_instance_t *instance)
Here are the parameters:
The usbd_device_instance_t structure looks like this:
typedef struct usbd_device_instance { _uint8 path; _uint8 devno; _uint16 generation; usbd_device_ident_t ident; _uint32 config; _uint32 iface; _uint32 alternate; } usbd_device_instance_t;
Another way to attach is to loop and attach to all devices (in which case you build the instance yourself). For example:
for (devno = 0; devno < 64; ++devno) { memset(&instance, USBD_CONNECT_WILDCARD, sizeof(usbd_device_instance_t)); instance.path = 0, instance.devno = devno; if (usbd_attach(connection, &instance, 0, &device) == EOK) { ...... } }
The degree of "attachedness" depends on how you connected. If you specified insertion/removal callback functions, then you'll get exclusive access to the device and can make I/O to it.
If you didn't use callbacks and you attached as in the loop above, you get shared access, so you can only read device configuration.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
usbd_connect(), usbd_detach(), usbd_device_extra(), usbd_disconnect()