Commit e8ccb169 authored by Andrei Emeltchenko's avatar Andrei Emeltchenko Committed by Anas Nashif
Browse files

usb: hid: Add Human Interface Device (HID) class



Add support for Human Interface Device USB class.

Signed-off-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
parent 8f21a378
Loading
Loading
Loading
Loading
+71 −0
Original line number Diff line number Diff line
/*
 * Human Interface Device (HID) USB class core header
 *
 * Copyright (c) 2018 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file
 * @brief USB Human Interface Device (HID) Class public header
 *
 * Header follows Device Class Definition for Human Interface Devices (HID)
 * Version 1.11 document (HID1_11-1.pdf).
 */

#ifndef __USB_HID_H__
#define __USB_HID_H__

struct usb_hid_class_subdescriptor {
	u8_t bDescriptorType;
	u16_t wDescriptorLength;
} __packed;

struct usb_hid_descriptor {
	u8_t bLength;
	u8_t bDescriptorType;
	u16_t bcdHID;
	u8_t bCountryCode;
	u8_t bNumDescriptors;

	/*
	 * Specification says at least one Class Descriptor needs to
	 * be present (Report Descriptor).
	 */
	struct usb_hid_class_subdescriptor subdesc[1];
} __packed;

/* HID Class Specific Requests */

#define HID_GET_REPORT		0x01
#define HID_GET_IDLE		0x02
#define HID_GET_PROTOCOL	0x03
#define HID_SET_REPORT		0x09
#define HID_SET_IDLE		0x0A
#define HID_SET_PROTOCOL	0x0B

/* Public headers */

struct hid_ops {
	int (*get_report)(struct usb_setup_packet *setup, s32_t *len,
			  u8_t **data);
	int (*get_idle)(struct usb_setup_packet *setup, s32_t *len,
			u8_t **data);
	int (*get_protocol)(struct usb_setup_packet *setup, s32_t *len,
			    u8_t **data);
	int (*set_report)(struct usb_setup_packet *setup, s32_t *len,
			  u8_t **data);
	int (*set_idle)(struct usb_setup_packet *setup, s32_t *len,
			u8_t **data);
	int (*set_protocol)(struct usb_setup_packet *setup, s32_t *len,
			    u8_t **data);
};

/* Register HID device */
void usb_hid_register_device(const u8_t *desc, size_t size, struct hid_ops *op);

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

#endif /* __USB_HID_H__ */
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ zephyr_sources_ifdef(CONFIG_USB_CDC_ACM cdc_acm.c)
zephyr_sources_ifdef(CONFIG_USB_MASS_STORAGE mass_storage.c)

add_subdirectory_ifdef(CONFIG_USB_DEVICE_NETWORK netusb)
add_subdirectory_ifdef(CONFIG_USB_DEVICE_HID hid)
+2 −0
Original line number Diff line number Diff line
@@ -134,4 +134,6 @@ config SYS_LOG_USB_MASS_STORAGE_LEVEL

source "subsys/usb/class/netusb/Kconfig"

source "subsys/usb/class/hid/Kconfig"

endif # CONFIG_USB_DEVICE_STACK
+12 −0
Original line number Diff line number Diff line
zephyr_library()

zephyr_library_include_directories(
  # USB headers
  #${ZEPHYR_BASE}/include/drivers/usb
  ${ZEPHYR_BASE}/include/usb
  ${ZEPHYR_BASE}/subsys/usb
  )

zephyr_library_sources(
  core.c
  )
+32 −0
Original line number Diff line number Diff line
# Kconfig - USB HID configuration options

#
# Copyright (c) 2018 Intel Corp.
#
# SPDX-License-Identifier: Apache-2.0
#

config USB_DEVICE_HID
	bool
	prompt "USB Human Interface Device support"
	default n
	help
	  Enables USB Human Interface Device support.

if USB_DEVICE_HID

config HID_INT_EP_ADDR
	hex
	prompt "USB HID Device Interrupt Endpoint address"
	default 0x81
	range 0x81 0x8F
	help
	  USB HID Device interrupt endpoint address

config HID_INTERRUPT_EP_MPS
	int
	default 16
	help
	  USB HID Device interrupt endpoint size

endif # USB_DEVICE_HID
Loading