Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
usb_hid.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 * Copyright (c) 2018,2021 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13#ifndef ZEPHYR_INCLUDE_USB_HID_CLASS_DEVICE_H_
14#define ZEPHYR_INCLUDE_USB_HID_CLASS_DEVICE_H_
15
16#include <usb/class/hid.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
35typedef int (*hid_cb_t)(const struct device *dev,
36 struct usb_setup_packet *setup, int32_t *len,
37 uint8_t **data);
38typedef void (*hid_int_ready_callback)(const struct device *dev);
39typedef void (*hid_protocol_cb_t)(const struct device *dev, uint8_t protocol);
40typedef void (*hid_idle_cb_t)(const struct device *dev, uint16_t report_id);
41
45struct hid_ops {
50 /*
51 * int_in_ready is an optional callback that is called when
52 * the current interrupt IN transfer has completed. This can
53 * be used to wait for the endpoint to go idle or to trigger
54 * the next transfer.
55 */
57#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
58 hid_int_ready_callback int_out_ready;
59#endif
60};
61
70void usb_hid_register_device(const struct device *dev,
71 const uint8_t *desc,
72 size_t size,
73 const struct hid_ops *op);
74
85int hid_int_ep_write(const struct device *dev,
86 const uint8_t *data,
87 uint32_t data_len,
88 uint32_t *bytes_ret);
89
102int hid_int_ep_read(const struct device *dev,
103 uint8_t *data,
104 uint32_t max_data_len,
105 uint32_t *ret_bytes);
106
117int usb_hid_set_proto_code(const struct device *dev, uint8_t proto_code);
118
126int usb_hid_init(const struct device *dev);
127
132/*
133 * Macros below are deprecated in 2.6 release.
134 * Please replace with macros from common HID header, include/usb/class/hid.h
135 */
136
137#define HID_CLASS_DESCRIPTOR_HID __DEPRECATED_MACRO USB_DESC_HID
138#define HID_CLASS_DESCRIPTOR_REPORT __DEPRECATED_MACRO USB_DESC_HID_REPORT
139
140#define HID_GET_REPORT __DEPRECATED_MACRO USB_HID_GET_REPORT
141#define HID_GET_IDLE __DEPRECATED_MACRO USB_HID_GET_IDLE
142#define HID_GET_PROTOCOL __DEPRECATED_MACRO USB_HID_GET_PROTOCOL
143#define HID_SET_REPORT __DEPRECATED_MACRO USB_HID_SET_REPORT
144#define HID_SET_IDLE __DEPRECATED_MACRO USB_HID_SET_IDLE
145#define HID_SET_PROTOCOL __DEPRECATED_MACRO USB_HID_SET_PROTOCOL
146
147#define ITEM_MAIN __DEPRECATED_MACRO 0x0
148#define ITEM_GLOBAL __DEPRECATED_MACRO 0x1
149#define ITEM_LOCAL __DEPRECATED_MACRO 0x2
150
151#define ITEM_TAG_INPUT __DEPRECATED_MACRO 0x8
152#define ITEM_TAG_OUTPUT __DEPRECATED_MACRO 0x9
153#define ITEM_TAG_COLLECTION __DEPRECATED_MACRO 0xA
154#define ITEM_TAG_COLLECTION_END __DEPRECATED_MACRO 0xC
155
156#define ITEM_TAG_USAGE_PAGE __DEPRECATED_MACRO 0x0
157#define ITEM_TAG_LOGICAL_MIN __DEPRECATED_MACRO 0x1
158#define ITEM_TAG_LOGICAL_MAX __DEPRECATED_MACRO 0x2
159#define ITEM_TAG_REPORT_SIZE __DEPRECATED_MACRO 0x7
160#define ITEM_TAG_REPORT_ID __DEPRECATED_MACRO 0x8
161#define ITEM_TAG_REPORT_COUNT __DEPRECATED_MACRO 0x9
162
163#define ITEM_TAG_USAGE __DEPRECATED_MACRO 0x0
164#define ITEM_TAG_USAGE_MIN __DEPRECATED_MACRO 0x1
165#define ITEM_TAG_USAGE_MAX __DEPRECATED_MACRO 0x2
166
167#define HID_MAIN_ITEM(bTag, bSize) \
168 __DEPRECATED_MACRO HID_ITEM(bTag, ITEM_MAIN, bSize)
169#define HID_GLOBAL_ITEM(bTag, bSize) \
170 __DEPRECATED_MACRO HID_ITEM(bTag, ITEM_GLOBAL, bSize)
171#define HID_LOCAL_ITEM(bTag, bSize) \
172 __DEPRECATED_MACRO HID_ITEM(bTag, ITEM_LOCAL, bSize)
173
174#define HID_MI_COLLECTION \
175 __DEPRECATED_MACRO HID_MAIN_ITEM(ITEM_TAG_COLLECTION, 1)
176#define HID_MI_COLLECTION_END \
177 __DEPRECATED_MACRO HID_MAIN_ITEM(ITEM_TAG_COLLECTION_END, 0)
178#define HID_MI_INPUT \
179 __DEPRECATED_MACRO HID_MAIN_ITEM(ITEM_TAG_INPUT, 1)
180#define HID_MI_OUTPUT \
181 __DEPRECATED_MACRO HID_MAIN_ITEM(ITEM_TAG_OUTPUT, 1)
182#define HID_GI_USAGE_PAGE \
183 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_USAGE_PAGE, 1)
184#define HID_GI_LOGICAL_MIN(size) \
185 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_LOGICAL_MIN, size)
186#define HID_GI_LOGICAL_MAX(size) \
187 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_LOGICAL_MAX, size)
188#define HID_GI_REPORT_SIZE \
189 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_REPORT_SIZE, 1)
190#define HID_GI_REPORT_ID \
191 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_REPORT_ID, 1)
192#define HID_GI_REPORT_COUNT \
193 __DEPRECATED_MACRO HID_GLOBAL_ITEM(ITEM_TAG_REPORT_COUNT, 1)
194
195#define HID_LI_USAGE \
196 __DEPRECATED_MACRO HID_LOCAL_ITEM(ITEM_TAG_USAGE, 1)
197#define HID_LI_USAGE_MIN(size) \
198 __DEPRECATED_MACRO HID_LOCAL_ITEM(ITEM_TAG_USAGE_MIN, size)
199#define HID_LI_USAGE_MAX(size) \
200 __DEPRECATED_MACRO HID_LOCAL_ITEM(ITEM_TAG_USAGE_MAX, size)
201
202#define USAGE_GEN_DESKTOP __DEPRECATED_MACRO 0x01
203#define USAGE_GEN_KEYBOARD __DEPRECATED_MACRO 0x07
204#define USAGE_GEN_LEDS __DEPRECATED_MACRO 0x08
205#define USAGE_GEN_BUTTON __DEPRECATED_MACRO 0x09
206
207#define USAGE_GEN_DESKTOP_UNDEFINED __DEPRECATED_MACRO 0x00
208#define USAGE_GEN_DESKTOP_POINTER __DEPRECATED_MACRO 0x01
209#define USAGE_GEN_DESKTOP_MOUSE __DEPRECATED_MACRO 0x02
210#define USAGE_GEN_DESKTOP_JOYSTICK __DEPRECATED_MACRO 0x04
211#define USAGE_GEN_DESKTOP_GAMEPAD __DEPRECATED_MACRO 0x05
212#define USAGE_GEN_DESKTOP_KEYBOARD __DEPRECATED_MACRO 0x06
213#define USAGE_GEN_DESKTOP_KEYPAD __DEPRECATED_MACRO 0x07
214#define USAGE_GEN_DESKTOP_X __DEPRECATED_MACRO 0x30
215#define USAGE_GEN_DESKTOP_Y __DEPRECATED_MACRO 0x31
216#define USAGE_GEN_DESKTOP_WHEEL __DEPRECATED_MACRO 0x38
217
218#define COLLECTION_PHYSICAL __DEPRECATED_MACRO 0x00
219#define COLLECTION_APPLICATION __DEPRECATED_MACRO 0x01
220
221#ifdef __cplusplus
222}
223#endif
224
225#endif /* ZEPHYR_INCLUDE_USB_HID_CLASS_DEVICE_H_ */
void
Definition: eswifi_shell.c:15
int(* hid_cb_t)(const struct device *dev, struct usb_setup_packet *setup, int32_t *len, uint8_t **data)
Definition: usb_hid.h:35
void(* hid_idle_cb_t)(const struct device *dev, uint16_t report_id)
Definition: usb_hid.h:40
int hid_int_ep_read(const struct device *dev, uint8_t *data, uint32_t max_data_len, uint32_t *ret_bytes)
Read from USB HID interrupt endpoint buffer.
int usb_hid_init(const struct device *dev)
Initialize USB HID class support.
void usb_hid_register_device(const struct device *dev, const uint8_t *desc, size_t size, const struct hid_ops *op)
Register HID device.
int hid_int_ep_write(const struct device *dev, const uint8_t *data, uint32_t data_len, uint32_t *bytes_ret)
Write to USB HID interrupt endpoint buffer.
void(* hid_protocol_cb_t)(const struct device *dev, uint8_t protocol)
Definition: usb_hid.h:39
void(* hid_int_ready_callback)(const struct device *dev)
Definition: usb_hid.h:38
int usb_hid_set_proto_code(const struct device *dev, uint8_t proto_code)
Set USB HID class Protocol Code.
USB Human Interface Device (HID) common definitions header.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INT32_TYPE__ int32_t
Definition: stdint.h:44
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
USB HID device interface.
Definition: usb_hid.h:45
hid_idle_cb_t on_idle
Definition: usb_hid.h:49
hid_cb_t get_report
Definition: usb_hid.h:46
hid_cb_t set_report
Definition: usb_hid.h:47
hid_protocol_cb_t protocol_change
Definition: usb_hid.h:48
hid_int_ready_callback int_in_ready
Definition: usb_hid.h:56
Definition: usb_ch9.h:38
static fdata_t data[2]
Definition: test_fifo_contexts.c:15