xref: /btstack/src/btstack_hid.h (revision e9933dfec49bb9cf50c4e12aac9165ec1b9890aa)
13cbedd43SMatthias Ringwald /*
23cbedd43SMatthias Ringwald  * Copyright (C) 2021 BlueKitchen GmbH
33cbedd43SMatthias Ringwald  *
43cbedd43SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53cbedd43SMatthias Ringwald  * modification, are permitted provided that the following conditions
63cbedd43SMatthias Ringwald  * are met:
73cbedd43SMatthias Ringwald  *
83cbedd43SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103cbedd43SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123cbedd43SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133cbedd43SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143cbedd43SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153cbedd43SMatthias Ringwald  *    from this software without specific prior written permission.
163cbedd43SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173cbedd43SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183cbedd43SMatthias Ringwald  *    monetary gain.
193cbedd43SMatthias Ringwald  *
203cbedd43SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213cbedd43SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223cbedd43SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
233cbedd43SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
243cbedd43SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253cbedd43SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263cbedd43SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273cbedd43SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283cbedd43SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293cbedd43SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303cbedd43SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313cbedd43SMatthias Ringwald  * SUCH DAMAGE.
323cbedd43SMatthias Ringwald  *
333cbedd43SMatthias Ringwald  * Please inquire about commercial licensing options at
343cbedd43SMatthias Ringwald  * [email protected]
353cbedd43SMatthias Ringwald  *
363cbedd43SMatthias Ringwald  */
373cbedd43SMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title Human Interface Device (HID)
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
42fe5a6c4eSMilanka Ringwald 
433cbedd43SMatthias Ringwald #ifndef HID_H
443cbedd43SMatthias Ringwald #define HID_H
453cbedd43SMatthias Ringwald 
463cbedd43SMatthias Ringwald #if defined __cplusplus
473cbedd43SMatthias Ringwald extern "C" {
483cbedd43SMatthias Ringwald #endif
493cbedd43SMatthias Ringwald 
503cbedd43SMatthias Ringwald 
513cbedd43SMatthias Ringwald #include <stdint.h>
523cbedd43SMatthias Ringwald 
533cbedd43SMatthias Ringwald #define HID_BOOT_MODE_KEYBOARD_ID 1
543cbedd43SMatthias Ringwald #define HID_BOOT_MODE_MOUSE_ID    2
553cbedd43SMatthias Ringwald 
563cbedd43SMatthias Ringwald typedef enum {
573cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HANDSHAKE = 0,
583cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HID_CONTROL,
593cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_2,
603cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_3,
613cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_REPORT,
623cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_REPORT,
633cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_PROTOCOL,
643cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_PROTOCOL,
653cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED,
663cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED,
673cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATA,
683cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATC_DEPRECATED
693cbedd43SMatthias Ringwald } hid_message_type_t;
703cbedd43SMatthias Ringwald 
713cbedd43SMatthias Ringwald typedef enum {
723cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_SUCCESSFUL = 0x00,        // This code is used to acknowledge requests. A device that has correctly received SET_REPORT, SET_IDLE or SET_PROTOCOL payload transmits an acknowledgment to the host.
733cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_NOT_READY,                // This code indicates that a device is too busy to accept data. The Bluetooth HID Host should retransmit the data the next time it communicates with the device.
743cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID,    // Invalid report ID transmitted.
753cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_UNSUPPORTED_REQUEST,  // The device does not support the request. This result code shall be used if the HIDP message type is unsupported.
763cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER,    // A parameter value is out of range or inappropriate for the request.
773cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E,       // Device could not identify the error condition.
783cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_FATAL = 0x0F,         // Restart is essential to resume functionality
793cbedd43SMatthias Ringwald     // BTstack custom error codes
803cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_DISCONNECT
813cbedd43SMatthias Ringwald } hid_handshake_param_type_t;
823cbedd43SMatthias Ringwald 
833cbedd43SMatthias Ringwald typedef enum {
843cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_NOP_DEPRECATED = 0,              // Deprecated: No Operation.
853cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_HARD_RESET_DEPRECATED,           // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations.
863cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED,           // Deprecated: Device initializes all internal variables and initiates normal operations.
873cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SUSPEND = 0x03,                  // Go to reduced power mode.
883cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_EXIT_SUSPEND,                    // Exit reduced power mode.
893cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG
903cbedd43SMatthias Ringwald } hid_control_param_t;
913cbedd43SMatthias Ringwald 
923cbedd43SMatthias Ringwald typedef enum {
933cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_BOOT = 0,
943cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT,
953cbedd43SMatthias Ringwald 
963cbedd43SMatthias Ringwald     // the following item is only used for API calls in hid_host.h: hid_host_connect, hid_host_accept_connection
973cbedd43SMatthias Ringwald     // in contrast to previous two enum items that will enforce given mode, this one enables fallback from report to boot mode
983cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT
993cbedd43SMatthias Ringwald } hid_protocol_mode_t;
1003cbedd43SMatthias Ringwald 
1013cbedd43SMatthias Ringwald typedef enum {
1023cbedd43SMatthias Ringwald     HID_REPORT_TYPE_RESERVED = 0,
1033cbedd43SMatthias Ringwald     HID_REPORT_TYPE_INPUT,
1043cbedd43SMatthias Ringwald     HID_REPORT_TYPE_OUTPUT,
1053cbedd43SMatthias Ringwald     HID_REPORT_TYPE_FEATURE
1063cbedd43SMatthias Ringwald } hid_report_type_t;
1073cbedd43SMatthias Ringwald 
1083cbedd43SMatthias Ringwald typedef enum {
1093cbedd43SMatthias Ringwald     HID_REPORT_ID_UNDECLARED,
1103cbedd43SMatthias Ringwald     HID_REPORT_ID_VALID,
1113cbedd43SMatthias Ringwald     HID_REPORT_ID_INVALID
1123cbedd43SMatthias Ringwald } hid_report_id_status_t;
1133cbedd43SMatthias Ringwald 
1143cbedd43SMatthias Ringwald /* API_START */
1153cbedd43SMatthias Ringwald 
1163cbedd43SMatthias Ringwald /*
1173cbedd43SMatthias Ringwald  * @brief Get boot descriptor data
1183cbedd43SMatthias Ringwald  * @result data
1193cbedd43SMatthias Ringwald  */
120*e9933dfeSMatthias Ringwald const uint8_t * btstack_hid_get_boot_descriptor_data(void);
1213cbedd43SMatthias Ringwald 
1223cbedd43SMatthias Ringwald /*
1233cbedd43SMatthias Ringwald  * @brief Get boot descriptor length
1243cbedd43SMatthias Ringwald  * @result length
1253cbedd43SMatthias Ringwald  */
126*e9933dfeSMatthias Ringwald uint16_t btstack_hid_get_boot_descriptor_len(void);
1273cbedd43SMatthias Ringwald 
1283cbedd43SMatthias Ringwald /* API_END */
1293cbedd43SMatthias Ringwald 
1303cbedd43SMatthias Ringwald #if defined __cplusplus
1313cbedd43SMatthias Ringwald }
1323cbedd43SMatthias Ringwald #endif
1333cbedd43SMatthias Ringwald 
1343cbedd43SMatthias Ringwald #endif
135