Home |
Attachment/Detachment Callbacks Structure of a Passive USB Client |
Attachment/Detachment CallbacksThe device attachment and detachment callback is the primary interface of a USB client. For some clients such as the USB keyboard class driver, it is the only API function available. Example:void USBEvent(RTUDeviceHandle Device, RTUSBEvent Event) { switch (Event) { case RTUConnect: printf("New device, "); DisplayDevice(Device); RTUCallOnDisconnect(Device, USBEvent); break; case RTUDisconnect: printf("Device detached\n"); break; } } int main(void) { RTURegisterCallback(USBKeyboard); // install keyboard driver's callback RTURegisterCallback(USBEvent); // install our own callback FindUSBControllers(); ... Function USBEvent() is a device attachment and detachment callback. RTUSB-32 calls it on every attachment event. Parameter Device is a handle to the device being attached or removed. For attach events, parameter Event is set to RTUConnect; for removal events, is has value RTUDisconnect. RTUDisconnect events are only called for clients which have called RTUCallOnDisconnect or have claimed one or more interfaces of the device using RTUClaimInterface. For attach events, USB clients should retrieve information about the device using RTUSB-32 device query functions. If the client wishes to handle one or more interfaces, it should then call device configuration functions and open all required pipes. For RTUDisconnect events, the client should close all of its pipes to the device using RTUClosePipe, or it should signal a separate thread to close all pipes. The attachment and detachment callbacks are called by RTUSB-32's internal USB hub class driver. The hub driver uses a single thread for this purpose, so all attachment and detachment callbacks are sequentialized. Note that attachment and detachment callbacks are not called at program termination or for devices attached before the callback was registered.
|