mikroSDK Reference Manual
hid_host.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_HID_HOST_H_
28#define _TUSB_HID_HOST_H_
29
30#include "hid.h"
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36//--------------------------------------------------------------------+
37// Class Driver Configuration
38//--------------------------------------------------------------------+
39
40// TODO Highspeed interrupt can be up to 512 bytes
41#ifndef CFG_TUH_HID_EPIN_BUFSIZE
42#define CFG_TUH_HID_EPIN_BUFSIZE 64
43#endif
44
45#ifndef CFG_TUH_HID_EPOUT_BUFSIZE
46#define CFG_TUH_HID_EPOUT_BUFSIZE 64
47#endif
48
49
50typedef struct
51{
52 uint8_t report_id;
53 uint8_t usage;
54 uint16_t usage_page;
55
56 // TODO still use the endpoint size for now
57// uint8_t in_len; // length of IN report
58// uint8_t out_len; // length of OUT report
60
61//--------------------------------------------------------------------+
62// Interface API
63//--------------------------------------------------------------------+
64
65// Get the total number of mounted HID interfaces of a device
66uint8_t tuh_hid_itf_get_count(uint8_t dev_addr);
67
68// Get all mounted interfaces across devices
69uint8_t tuh_hid_itf_get_total_count(void);
70
71// backward compatible rename
72#define tuh_hid_instance_count tuh_hid_itf_get_count
73
74// Get Interface information
75bool tuh_hid_itf_get_info(uint8_t daddr, uint8_t idx, tuh_itf_info_t* itf_info);
76
77// Get Interface index from device address + interface number
78// return TUSB_INDEX_INVALID_8 (0xFF) if not found
79uint8_t tuh_hid_itf_get_index(uint8_t daddr, uint8_t itf_num);
80
81// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
82uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t idx);
83
84// Check if HID interface is mounted
85bool tuh_hid_mounted(uint8_t dev_addr, uint8_t idx);
86
87// Parse report descriptor into array of report_info struct and return number of reports.
88// For complicated report, application should write its own parser.
89uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr, uint8_t arr_count, uint8_t const* desc_report, uint16_t desc_len) TU_ATTR_UNUSED;
90
91//--------------------------------------------------------------------+
92// Control Endpoint API
93//--------------------------------------------------------------------+
94
95// Get current protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
96// Note: Device will be initialized in Boot protocol for simplicity.
97// Application can use set_protocol() to switch back to Report protocol.
98uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t idx);
99
100// Set protocol to HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
101// This function is only supported by Boot interface (tuh_n_hid_interface_protocol() != NONE)
102bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t idx, uint8_t protocol);
103
104// Set Report using control endpoint
105// report_type is either Input, Output or Feature, (value from hid_report_type_t)
106bool tuh_hid_set_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, void* report, uint16_t len);
107
108//--------------------------------------------------------------------+
109// Interrupt Endpoint API
110//--------------------------------------------------------------------+
111
112// Check if HID interface is ready to receive report
113bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx);
114
115// Try to receive next report on Interrupt Endpoint. Immediately return
116// - true If succeeded, tuh_hid_report_received_cb() callback will be invoked when report is available
117// - false if failed to queue the transfer e.g endpoint is busy
118bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t idx);
119
120// Check if HID interface is ready to send report
121bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
122
123// Send report using interrupt endpoint
124// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
125bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len);
126
127//--------------------------------------------------------------------+
128// Callbacks (Weak is optional)
129//--------------------------------------------------------------------+
130
131// Invoked when device with hid interface is mounted
132// Report descriptor is also available for use. tuh_hid_parse_report_descriptor()
133// can be used to parse common/simple enough descriptor.
134// Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped
135// therefore report_desc = NULL, desc_len = 0
136TU_ATTR_WEAK void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report_desc, uint16_t desc_len);
137
138// Invoked when device with hid interface is un-mounted
139TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t idx);
140
141// Invoked when received report from device via interrupt endpoint
142// Note: if there is report ID (composite), it is 1st byte of report
143void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report, uint16_t len);
144
145// Invoked when sent report to device successfully via interrupt endpoint
146TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report, uint16_t len);
147
148// Invoked when Sent Report to device via either control endpoint
149// len = 0 indicate there is error in the transfer e.g stalled response
150TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, uint16_t len);
151
152// Invoked when Set Protocol request is complete
153TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t protocol);
154
155//--------------------------------------------------------------------+
156// Internal Class Driver API
157//--------------------------------------------------------------------+
158void hidh_init (void);
159bool hidh_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
160bool hidh_set_config (uint8_t dev_addr, uint8_t itf_num);
161bool hidh_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
162void hidh_close (uint8_t dev_addr);
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif /* _TUSB_HID_HOST_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
Definition hid_host.h:51
Definition usbh.h:74