xref: /btstack/src/ble/gatt-service/hids_device.h (revision 8e7b5449bd1487734ee8171db779983e2b273d02)
1a4bfc4feSMatthias Ringwald /*
2a4bfc4feSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3a4bfc4feSMatthias Ringwald  *
4a4bfc4feSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5a4bfc4feSMatthias Ringwald  * modification, are permitted provided that the following conditions
6a4bfc4feSMatthias Ringwald  * are met:
7a4bfc4feSMatthias Ringwald  *
8a4bfc4feSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9a4bfc4feSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10a4bfc4feSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11a4bfc4feSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12a4bfc4feSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13a4bfc4feSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14a4bfc4feSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15a4bfc4feSMatthias Ringwald  *    from this software without specific prior written permission.
16a4bfc4feSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17a4bfc4feSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18a4bfc4feSMatthias Ringwald  *    monetary gain.
19a4bfc4feSMatthias Ringwald  *
20a4bfc4feSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21a4bfc4feSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22a4bfc4feSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25a4bfc4feSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26a4bfc4feSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27a4bfc4feSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28a4bfc4feSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29a4bfc4feSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30a4bfc4feSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a4bfc4feSMatthias Ringwald  * SUCH DAMAGE.
32a4bfc4feSMatthias Ringwald  *
33a4bfc4feSMatthias Ringwald  * Please inquire about commercial licensing options at
34a4bfc4feSMatthias Ringwald  * [email protected]
35a4bfc4feSMatthias Ringwald  *
36a4bfc4feSMatthias Ringwald  */
37fe5a6c4eSMilanka Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title HID Service Server
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
42fe5a6c4eSMilanka Ringwald 
4380e33422SMatthias Ringwald #ifndef HIDS_DEVICE_H
4480e33422SMatthias Ringwald #define HIDS_DEVICE_H
45bb880bddSMatthias Ringwald 
46bb880bddSMatthias Ringwald #include <stdint.h>
47bb880bddSMatthias Ringwald #include "btstack_defines.h"
48f4f6c196SMilanka Ringwald #include "btstack_hid.h"
49bb880bddSMatthias Ringwald #include "bluetooth.h"
50bb880bddSMatthias Ringwald 
51bb880bddSMatthias Ringwald #if defined __cplusplus
52bb880bddSMatthias Ringwald extern "C" {
53bb880bddSMatthias Ringwald #endif
54a4bfc4feSMatthias Ringwald 
5590f75057SMilanka Ringwald /* API_START */
5690f75057SMilanka Ringwald 
57f4f6c196SMilanka Ringwald typedef struct {
58f4f6c196SMilanka Ringwald     uint16_t value_handle;
59f4f6c196SMilanka Ringwald     uint16_t client_configuration_handle;
60f4f6c196SMilanka Ringwald     uint16_t client_configuration_value;
61f4f6c196SMilanka Ringwald 
62f4f6c196SMilanka Ringwald     hid_report_type_t type;
631b9864eaSMatthias Ringwald     uint8_t id;
641b9864eaSMatthias Ringwald     uint8_t size;
65f4f6c196SMilanka Ringwald } hids_device_report_t;
66f4f6c196SMilanka Ringwald 
67a4bfc4feSMatthias Ringwald /**
681ea30d1bSMilanka Ringwald  * @text Implementation of the GATT HIDS Device
69a4bfc4feSMatthias Ringwald  * To use with your application, add '#import <hids.gatt>' to your .gatt file
70a4bfc4feSMatthias Ringwald  */
71a4bfc4feSMatthias Ringwald 
72a4bfc4feSMatthias Ringwald /**
73f4f6c196SMilanka Ringwald  * @brief Set up HIDS Device with single INPUT, OUTPUT and FEATURE report
74a4bfc4feSMatthias Ringwald  */
75a4bfc4feSMatthias Ringwald void hids_device_init(uint8_t hid_country_code, const uint8_t * hid_descriptor, uint16_t hid_descriptor_size);
76a4bfc4feSMatthias Ringwald 
77a4bfc4feSMatthias Ringwald /**
78f823745aSMilanka Ringwald  * @brief Set up HIDS Device for multiple instances of INPUT, OUTPUT and FEATURE reports
79f823745aSMilanka Ringwald  */
80f823745aSMilanka Ringwald void hids_device_init_with_storage(uint8_t hid_country_code, const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
81f823745aSMilanka Ringwald     uint16_t num_reports, hids_device_report_t * report_storage);
82f823745aSMilanka Ringwald 
83f823745aSMilanka Ringwald /**
84a4bfc4feSMatthias Ringwald  * @brief Register callback for the HIDS Device client.
85a4bfc4feSMatthias Ringwald  * @param callback
86a4bfc4feSMatthias Ringwald  */
87a4bfc4feSMatthias Ringwald void hids_device_register_packet_handler(btstack_packet_handler_t callback);
88a4bfc4feSMatthias Ringwald 
89a4bfc4feSMatthias Ringwald /**
901b9864eaSMatthias Ringwald  * @brief Register report callback for Get Report operation
911b9864eaSMatthias Ringwald  * @param callback
921b9864eaSMatthias Ringwald  */
931b9864eaSMatthias Ringwald void hids_device_register_get_report_callback(void (*callback)(hci_con_handle_t con_handle, hid_report_type_t report_type, uint16_t report_id, uint16_t max_report_size, uint8_t * out_report));
941b9864eaSMatthias Ringwald 
951b9864eaSMatthias Ringwald /**
96a4bfc4feSMatthias Ringwald  * @brief Request can send now event to send HID Report
97a4bfc4feSMatthias Ringwald  * Generates an HIDS_SUBEVENT_CAN_SEND_NOW subevent
98a4bfc4feSMatthias Ringwald  * @param hid_cid
99*8e7b5449SMarkus Zehnder  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
100a4bfc4feSMatthias Ringwald  */
101*8e7b5449SMarkus Zehnder uint8_t hids_device_request_can_send_now_event(hci_con_handle_t con_handle);
102a4bfc4feSMatthias Ringwald 
103a4bfc4feSMatthias Ringwald /**
10445569c34SMatthias Ringwald  * @brief Send HID Input Report for Report ID
10545569c34SMatthias Ringwald  * @param con_handle
10645569c34SMatthias Ringwald  * @param report_id
10745569c34SMatthias Ringwald  * @param report
10845569c34SMatthias Ringwald  * @param report_len
109d38dfb7fSMatthias Ringwald  * @returns status
110f4f6c196SMilanka Ringwald  */
11145569c34SMatthias Ringwald uint8_t hids_device_send_input_report_for_id(hci_con_handle_t con_handle, uint16_t report_id, const uint8_t * report, uint16_t report_len);
112f4f6c196SMilanka Ringwald 
113f4f6c196SMilanka Ringwald /**
11445569c34SMatthias Ringwald  * @brief Send HID Input Report for first Input Report
11545569c34SMatthias Ringwald  * @param con_handle
11645569c34SMatthias Ringwald  * @param report
11745569c34SMatthias Ringwald  * @param report_len
118d38dfb7fSMatthias Ringwald  * @returns status
119a4bfc4feSMatthias Ringwald  */
120d38dfb7fSMatthias Ringwald uint8_t hids_device_send_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len);
121a4bfc4feSMatthias Ringwald 
122a4bfc4feSMatthias Ringwald /**
123a4bfc4feSMatthias Ringwald  * @brief Send HID Boot Mouse Input Report
124d38dfb7fSMatthias Ringwald  * @param con_handle
125d38dfb7fSMatthias Ringwald  * @param report
126d38dfb7fSMatthias Ringwald  * @param report_len
127d38dfb7fSMatthias Ringwald  * @returns status
128a4bfc4feSMatthias Ringwald  */
129d38dfb7fSMatthias Ringwald uint8_t hids_device_send_boot_mouse_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len);
130a4bfc4feSMatthias Ringwald 
131a4bfc4feSMatthias Ringwald /**
132a4bfc4feSMatthias Ringwald  * @brief Send HID Boot Mouse Input Report
133d38dfb7fSMatthias Ringwald  * @param con_handle
134d38dfb7fSMatthias Ringwald  * @param report
135d38dfb7fSMatthias Ringwald  * @param report_len
136d38dfb7fSMatthias Ringwald  * @returns status
137a4bfc4feSMatthias Ringwald  */
138d38dfb7fSMatthias Ringwald uint8_t hids_device_send_boot_keyboard_input_report(hci_con_handle_t con_handle, const uint8_t * report, uint16_t report_len);
139bb880bddSMatthias Ringwald 
14090f75057SMilanka Ringwald /* API_END */
14190f75057SMilanka Ringwald 
142bb880bddSMatthias Ringwald #if defined __cplusplus
143bb880bddSMatthias Ringwald }
144bb880bddSMatthias Ringwald #endif
145bb880bddSMatthias Ringwald 
146bb880bddSMatthias Ringwald #endif
147