| Description | The Init function is used for initialization of the device. It will be called automatically by the USB Host Core when new device is attached and configured. The argument ctrl specifies the controller index. The argument dev_idx specifies the device instance index. Initialization function has to do device specific initialization (for example for Mass Storage Device it has to check if device is ready or put the device into ready state), it also has to set Init bit in Device Class Instance (USBH_DCI) structure to 1 after initialization is successful. You can modify this function to suit different class driver. This function will need to be changed for class that does not have driver provided. |
| Example |
/* MSC Class Driver Control Block */
USBH_DCD usbh_dcd_cls = {
USB_DEVICE_CLASS_STORAGE,
Config,
UnConfig,
Init,
UnInit,
GetLastError
};
static BOOL Init (U8 ctrl, U8 dev_idx) {
U32 stat;
ptrHCD = usbh_hcd_ptr[ctrl];
ptrDCI = &usbh_dci_msc[ctrl*usbh_msc_num+dev_idx];
for (retry = 100000; retry > 0; retry--) {
ok = USBH_MSC_TestUnitReady (ctrl, dev_idx, &stat);
if (ok && !stat)
break;
}
ptrDCI->Init = 1;
return (__TRUE);
}
|