Skip to content
Permalink
Browse files

subsys: usb: class: hid: Add OUT interrupt endpoint

patch add a OUT interrupt endpoint descriptor and registers a
corresponding notification callback with usb driver, which is invoked
when data is sent to device from host.

Implement the read ready notification as suggesteed by
Aurelien Jarno <aurelien@aurel32.net>

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
Signed-off-by: Johann Fischer <j.fischer@phytec.de>
  • Loading branch information...
SavinayDharmappa authored and nashif committed May 3, 2018
1 parent d2b4d8f commit 6b44a00336df36893597247c0702397ece4ede94
Showing with 63 additions and 7 deletions.
  1. +6 −0 include/usb/class/usb_hid.h
  2. +6 −0 subsys/usb/class/hid/Kconfig
  3. +51 −7 subsys/usb/class/hid/core.c
@@ -69,6 +69,9 @@ struct hid_ops {
* the next transfer.
*/
hid_int_ready_callback int_in_ready;
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
hid_int_ready_callback int_out_ready;
#endif
};

/* HID Report Definitions */
@@ -157,6 +160,9 @@ void usb_hid_register_device(const u8_t *desc, size_t size,
/* Write to hid interrupt endpoint */
int hid_int_ep_write(const u8_t *data, u32_t data_len, u32_t *bytes_ret);

/* Read from hid interrupt endpoint */
int hid_int_ep_read(u8_t *data, u32_t max_data_len, u32_t *ret_bytes);

/* Initialize USB HID */
int usb_hid_init(void);

@@ -13,6 +13,12 @@ config USB_DEVICE_HID

if USB_DEVICE_HID

config ENABLE_HID_INT_OUT_EP
bool
prompt "Enable USB HID Device Interrupt OUT Endpoint"
help
Enable USB HID Device Interrupt OUT Endpoint.

config HID_INTERRUPT_EP_MPS
int "USB HID Device Interrupt Endpoint size"
default 16
@@ -17,15 +17,19 @@
#include <usb_descriptor.h>
#include <class/usb_hid.h>

#define HID_INT_EP_ADDR 0x81
#define HID_INT_IN_EP_ADDR 0x81
#define HID_INT_OUT_EP_ADDR 0x01

#define HID_INT_IN_EP_IDX 0
#define HID_INT_OUT_EP_IDX 1

struct usb_hid_config {
struct usb_if_descriptor if0;
struct usb_hid_descriptor if0_hid;
struct usb_ep_descriptor if0_int_ep;
struct usb_ep_descriptor if0_int_in_ep;
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
struct usb_ep_descriptor if0_int_out_ep;
#endif
} __packed;

USBD_CLASS_DESCR_DEFINE(primary) struct usb_hid_config hid_cfg = {
@@ -56,16 +60,27 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_hid_config hid_cfg = {
.wDescriptorLength = 0,
},
},
.if0_int_ep = {
.if0_int_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC,
.bEndpointAddress = HID_INT_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_INTERRUPT,
.wMaxPacketSize =
sys_cpu_to_le16(CONFIG_HID_INTERRUPT_EP_MPS),
.bInterval = 0x09,
},
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
.if0_int_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC,
.bEndpointAddress = HID_INT_EP_ADDR,
.bEndpointAddress = HID_INT_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_INTERRUPT,
.wMaxPacketSize =
sys_cpu_to_le16(
CONFIG_HID_INTERRUPT_EP_MPS),
sys_cpu_to_le16(CONFIG_HID_INTERRUPT_EP_MPS),
.bInterval = 0x09,
},
#endif

};

static void usb_set_hid_report_size(u16_t report_desc_size)
@@ -203,17 +218,36 @@ static void hid_int_in(u8_t ep, enum usb_dc_ep_cb_status_code ep_status)
hid_device.ops->int_in_ready();
}

#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
static void hid_int_out(u8_t ep, enum usb_dc_ep_cb_status_code ep_status)
{
if (ep_status != USB_DC_EP_DATA_OUT ||
hid_device.ops->int_out_ready == NULL) {
return;
}
hid_device.ops->int_out_ready();
}
#endif

/* Describe Endpoints configuration */
static struct usb_ep_cfg_data hid_ep_data[] = {
{
.ep_cb = hid_int_in,
.ep_addr = HID_INT_EP_ADDR
.ep_addr = HID_INT_IN_EP_ADDR
},
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
{
.ep_cb = hid_int_out,
.ep_addr = HID_INT_OUT_EP_ADDR,

}
#endif
};

static void hid_interface_config(u8_t bInterfaceNumber)
{
hid_cfg.if0.bInterfaceNumber = bInterfaceNumber;
hid_cfg.if0.bNumEndpoints = ARRAY_SIZE(hid_ep_data);
}

USBD_CFG_DATA_DEFINE(hid) struct usb_cfg_data hid_config = {
@@ -281,3 +315,13 @@ int hid_int_ep_write(const u8_t *data, u32_t data_len, u32_t *bytes_ret)
return usb_write(hid_ep_data[HID_INT_IN_EP_IDX].ep_addr, data,
data_len, bytes_ret);
}

int hid_int_ep_read(u8_t *data, u32_t max_data_len, u32_t *ret_bytes)
{
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
return usb_read(hid_ep_data[HID_INT_OUT_EP_IDX].ep_addr,
data, max_data_len, ret_bytes);
#else
return -ENOTSUP;
#endif
}

0 comments on commit 6b44a00

Please sign in to comment.
You can’t perform that action at this time.