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,
|
typedef int (*hid_cb_t)(struct usb_setup_packet *setup, s32_t *len,
|
||||||
u8_t **data);
|
u8_t **data);
|
||||||
typedef void (*hid_int_ready_callback)(void);
|
typedef void (*hid_int_ready_callback)(void);
|
||||||
|
typedef void (*status_cb_t)(enum usb_dc_status_code status, u8_t *param);
|
||||||
|
|
||||||
struct hid_ops {
|
struct hid_ops {
|
||||||
hid_cb_t get_report;
|
hid_cb_t get_report;
|
||||||
|
@ -72,6 +73,7 @@ struct hid_ops {
|
||||||
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
|
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
|
||||||
hid_int_ready_callback int_out_ready;
|
hid_int_ready_callback int_out_ready;
|
||||||
#endif
|
#endif
|
||||||
|
status_cb_t status_cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* HID Report Definitions */
|
/* 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)
|
static void hid_status_cb(enum usb_dc_status_code status, u8_t *param)
|
||||||
{
|
{
|
||||||
/* Check the USB status and do needed action if required */
|
if (hid_device.ops->status_cb) {
|
||||||
switch (status) {
|
hid_device.ops->status_cb(status, param);
|
||||||
case USB_DC_ERROR:
|
} else {
|
||||||
USB_DBG("USB device error");
|
switch (status) {
|
||||||
break;
|
case USB_DC_ERROR:
|
||||||
case USB_DC_RESET:
|
USB_DBG("USB device error");
|
||||||
USB_DBG("USB device reset detected");
|
break;
|
||||||
break;
|
case USB_DC_RESET:
|
||||||
case USB_DC_CONNECTED:
|
USB_DBG("USB device reset detected");
|
||||||
USB_DBG("USB device connected");
|
break;
|
||||||
break;
|
case USB_DC_CONNECTED:
|
||||||
case USB_DC_CONFIGURED:
|
USB_DBG("USB device connected");
|
||||||
USB_DBG("USB device configured");
|
break;
|
||||||
break;
|
case USB_DC_CONFIGURED:
|
||||||
case USB_DC_DISCONNECTED:
|
USB_DBG("USB device configured");
|
||||||
USB_DBG("USB device disconnected");
|
break;
|
||||||
break;
|
case USB_DC_DISCONNECTED:
|
||||||
case USB_DC_SUSPEND:
|
USB_DBG("USB device disconnected");
|
||||||
USB_DBG("USB device suspended");
|
break;
|
||||||
break;
|
case USB_DC_SUSPEND:
|
||||||
case USB_DC_RESUME:
|
USB_DBG("USB device suspended");
|
||||||
USB_DBG("USB device resumed");
|
break;
|
||||||
break;
|
case USB_DC_RESUME:
|
||||||
case USB_DC_UNKNOWN:
|
USB_DBG("USB device resumed");
|
||||||
default:
|
break;
|
||||||
USB_DBG("USB unknown state");
|
case USB_DC_UNKNOWN:
|
||||||
break;
|
default:
|
||||||
|
USB_DBG("USB unknown state");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue