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:
Andrei Emeltchenko 2018-09-19 14:46:54 +03:00 committed by Anas Nashif
commit 3288da9c0b
2 changed files with 32 additions and 27 deletions

View file

@ -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 */

View file

@ -98,7 +98,9 @@ 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 */
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");
@ -126,6 +128,7 @@ static void hid_status_cb(enum usb_dc_status_code status, u8_t *param)
USB_DBG("USB unknown state");
break;
}
}
}
static int hid_class_handle_req(struct usb_setup_packet *setup,