USB HID Generic Disconnect callback

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB HID Generic Disconnect callback

Jump to solution
1,796 Views
mail6
Contributor II

I am using the NXP LPCXpresso54628. I have a USB HID device that is implemented in RTOS. I want to create a function that is executed when the usb is disconnected from a computer. 

I have looked in the hid_generic.c and placed breakpoints in the functions:

static usb_status_t USB_DeviceHidGenericCallback(class_handle_t handle, uint32_t event, void *param)

and

static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)

but no callback is generated when the device is disconnected.

How can I implement this callback ? What are your suggestions ? 

 

Thanks in advance,

Jim

0 Kudos
Reply
1 Solution
1,724 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Jim,

 

To do this you need to enable detach feature by setting the following define in usb_device_config.h file.

#define USB_DEVICE_CONFIG_DETACH_ENABLE (1U)

This will enable notification to the device callback through USB_DeviceAttachNotification and USB_DeviceDetachNotification functions.

#if USB_DEVICE_CONFIG_DETACH_ENABLE
        case kUSB_DeviceNotifyDetach:
            status = USB_DeviceDetachNotification(handle, message);
            break;
        case kUSB_DeviceNotifyAttach:
            status = USB_DeviceAttachNotification(handle, message);
            break;
#endif

Now you can implement what you like to do in USB_DeviceCallback when this events occurred. I just print message a in console.

usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
{
 usb_status_t error = kStatus_USB_Error;

 switch (event)
 {
 case kUSB_DeviceEventAttach:
  usb_echo("USB device attached\r\n");
  break;
 case kUSB_DeviceEventDetach:
  usb_echo("USB device detached\r\n");
  break;

Hope it helps!

 

Best regards,

Felipe

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored.

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

------------------------------------------------------------------------------ 

View solution in original post

3 Replies
491 Views
fractalgarden
Contributor III

I have a similar problem same problem on IMXRT1052;
I did #define USB_DEVICE_CONFIG_DETACH_ENABLE 1U
but no event is triggered in the low level isr in the first place when the cable is disconnected;

a breakpoint on USB_OTG1_IRQHandler and USB_OTG2_IRQHandler does nothing when the cable is disconnected,
but attach and other events work correctly

0 Kudos
Reply
1,725 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Jim,

 

To do this you need to enable detach feature by setting the following define in usb_device_config.h file.

#define USB_DEVICE_CONFIG_DETACH_ENABLE (1U)

This will enable notification to the device callback through USB_DeviceAttachNotification and USB_DeviceDetachNotification functions.

#if USB_DEVICE_CONFIG_DETACH_ENABLE
        case kUSB_DeviceNotifyDetach:
            status = USB_DeviceDetachNotification(handle, message);
            break;
        case kUSB_DeviceNotifyAttach:
            status = USB_DeviceAttachNotification(handle, message);
            break;
#endif

Now you can implement what you like to do in USB_DeviceCallback when this events occurred. I just print message a in console.

usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
{
 usb_status_t error = kStatus_USB_Error;

 switch (event)
 {
 case kUSB_DeviceEventAttach:
  usb_echo("USB device attached\r\n");
  break;
 case kUSB_DeviceEventDetach:
  usb_echo("USB device detached\r\n");
  break;

Hope it helps!

 

Best regards,

Felipe

-------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored.

Please open a new thread and refer to the closed one, if you have a related question at a later point in time.

------------------------------------------------------------------------------ 

1,724 Views
mail6
Contributor II

Dear Felipe,

This is perfect. Thank you for your help !

Best,

Jim

0 Kudos
Reply