Here is some code that only calls the callback on detach for some reason, and returns error 97, meaning TR failed. I still haven't been able to successfully create a control command or retrieve a string index from the device.
This is in the main device callback, under the attached event.
case USB_DEVICE_ATTACHED:
printf( "Device Attached\n" );
dev_ptr = (DEV_INSTANCE_PTR)usb_dev.dev_handle;
usb_dev.dev_state = USB_DEVICE_OTHER;
dev_ptr->state = DEVSTATE_ENUM_OK;
status = _usb_host_register_ch9_callback(
usb_dev.dev_handle,
usb_host_mass_device_cntrl,
usb_dev.intf_handle);
if(status != USB_OK) {
printf("Control callback registration ERROR: 0x%x\n", status);
}
/* Read device status to push it into DEVSTATE_ENUM_OK */
status = _usb_host_ch9_get_descriptor(usb_dev.dev_handle,
(REQ_GET_DESCRIPTOR << 8) | 3, 0x0409 , 0x40, buffer);
if(status != USB_STATUS_TRANSFER_QUEUED) {
printf("Get descriptor ERROR: 0x%x\n", status);
}
break;
This is the ch9 registered callback, that seems to only fire on detach (or on attach if I change the get_descriptor call to ..0, 0, 2, buffer, which is getstatus):
void usb_host_mass_device_cntrl
(
/* [IN] pointer to pipe */
_usb_pipe_handle pipe_handle,
/* [IN] user-defined parameter */
pointer user_parm,
/* [IN] buffer address */
uchar_ptr buffer,
/* [IN] length of data transferred */
uint_32 length_data_transfered,
/* [IN] status, hopefully USB_OK or USB_DONE */
uint_32 status
)
{
uint_8 count;
if(status == USB_OK) {
printf("Serial Number: ");
for(count = 0; count < length_data_transfered; count++) {
printf("%x-", buffer[count]);
}
printf("\n");
}
else {
printf("Callback Error: 0x%x\n", status);
}
}