usb: hid: Add status_cb to hid ops
Adding status callback allows to control report sending only when i.e. device is connected or configured. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
7ff64bfead
commit
3288da9c0b
2 changed files with 32 additions and 27 deletions
|
@ -54,6 +54,7 @@ struct usb_hid_descriptor {
|
|||
typedef int (*hid_cb_t)(struct usb_setup_packet *setup, s32_t *len,
|
||||
u8_t **data);
|
||||
typedef void (*hid_int_ready_callback)(void);
|
||||
typedef void (*status_cb_t)(enum usb_dc_status_code status, u8_t *param);
|
||||
|
||||
struct hid_ops {
|
||||
hid_cb_t get_report;
|
||||
|
@ -72,6 +73,7 @@ struct hid_ops {
|
|||
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
|
||||
hid_int_ready_callback int_out_ready;
|
||||
#endif
|
||||
status_cb_t status_cb;
|
||||
};
|
||||
|
||||
/* HID Report Definitions */
|
||||
|
|
|
@ -98,33 +98,36 @@ static struct hid_device_info {
|
|||
|
||||
static void hid_status_cb(enum usb_dc_status_code status, u8_t *param)
|
||||
{
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
case USB_DC_ERROR:
|
||||
USB_DBG("USB device error");
|
||||
break;
|
||||
case USB_DC_RESET:
|
||||
USB_DBG("USB device reset detected");
|
||||
break;
|
||||
case USB_DC_CONNECTED:
|
||||
USB_DBG("USB device connected");
|
||||
break;
|
||||
case USB_DC_CONFIGURED:
|
||||
USB_DBG("USB device configured");
|
||||
break;
|
||||
case USB_DC_DISCONNECTED:
|
||||
USB_DBG("USB device disconnected");
|
||||
break;
|
||||
case USB_DC_SUSPEND:
|
||||
USB_DBG("USB device suspended");
|
||||
break;
|
||||
case USB_DC_RESUME:
|
||||
USB_DBG("USB device resumed");
|
||||
break;
|
||||
case USB_DC_UNKNOWN:
|
||||
default:
|
||||
USB_DBG("USB unknown state");
|
||||
break;
|
||||
if (hid_device.ops->status_cb) {
|
||||
hid_device.ops->status_cb(status, param);
|
||||
} else {
|
||||
switch (status) {
|
||||
case USB_DC_ERROR:
|
||||
USB_DBG("USB device error");
|
||||
break;
|
||||
case USB_DC_RESET:
|
||||
USB_DBG("USB device reset detected");
|
||||
break;
|
||||
case USB_DC_CONNECTED:
|
||||
USB_DBG("USB device connected");
|
||||
break;
|
||||
case USB_DC_CONFIGURED:
|
||||
USB_DBG("USB device configured");
|
||||
break;
|
||||
case USB_DC_DISCONNECTED:
|
||||
USB_DBG("USB device disconnected");
|
||||
break;
|
||||
case USB_DC_SUSPEND:
|
||||
USB_DBG("USB device suspended");
|
||||
break;
|
||||
case USB_DC_RESUME:
|
||||
USB_DBG("USB device resumed");
|
||||
break;
|
||||
case USB_DC_UNKNOWN:
|
||||
default:
|
||||
USB_DBG("USB unknown state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue