xref: /btstack/example/hid_mouse_demo.c (revision d7bfc7cd4013738a7f0e7693f3ebe2ef5d9977a3)
1aa29f587SMatthias Ringwald /*
2aa29f587SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3aa29f587SMatthias Ringwald  *
4aa29f587SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5aa29f587SMatthias Ringwald  * modification, are permitted provided that the following conditions
6aa29f587SMatthias Ringwald  * are met:
7aa29f587SMatthias Ringwald  *
8aa29f587SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9aa29f587SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10aa29f587SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11aa29f587SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12aa29f587SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13aa29f587SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14aa29f587SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15aa29f587SMatthias Ringwald  *    from this software without specific prior written permission.
16aa29f587SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17aa29f587SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18aa29f587SMatthias Ringwald  *    monetary gain.
19aa29f587SMatthias Ringwald  *
20aa29f587SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21aa29f587SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22aa29f587SMatthias 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,
25aa29f587SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26aa29f587SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27aa29f587SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28aa29f587SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29aa29f587SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30aa29f587SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31aa29f587SMatthias Ringwald  * SUCH DAMAGE.
32aa29f587SMatthias Ringwald  *
33aa29f587SMatthias Ringwald  * Please inquire about commercial licensing options at
34aa29f587SMatthias Ringwald  * [email protected]
35aa29f587SMatthias Ringwald  *
36aa29f587SMatthias Ringwald  */
37aa29f587SMatthias Ringwald 
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "hid_mouse_demo.c"
39aa29f587SMatthias Ringwald 
40aa29f587SMatthias Ringwald // *****************************************************************************
41ec8ae085SMilanka Ringwald /* EXAMPLE_START(hid_mouse_demo): HID Mouse Classic
42aa29f587SMatthias Ringwald  *
43aa29f587SMatthias Ringwald  * @text This HID Device example demonstrates how to implement
44aa29f587SMatthias Ringwald  * an HID keyboard. Without a HAVE_BTSTACK_STDIN, a fixed demo text is sent
45aa29f587SMatthias Ringwald  * If HAVE_BTSTACK_STDIN is defined, you can type from the terminal
46aa29f587SMatthias Ringwald  */
47aa29f587SMatthias Ringwald // *****************************************************************************
48aa29f587SMatthias Ringwald 
49aa29f587SMatthias Ringwald 
50aa29f587SMatthias Ringwald #include <stdint.h>
51aa29f587SMatthias Ringwald #include <stdio.h>
52aa29f587SMatthias Ringwald #include <stdlib.h>
53aa29f587SMatthias Ringwald #include <string.h>
54aa29f587SMatthias Ringwald #include <inttypes.h>
55aa29f587SMatthias Ringwald 
56aa29f587SMatthias Ringwald #include "btstack.h"
57aa29f587SMatthias Ringwald 
58aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
59aa29f587SMatthias Ringwald #include "btstack_stdin.h"
60aa29f587SMatthias Ringwald #endif
61aa29f587SMatthias Ringwald 
62aa29f587SMatthias Ringwald // to enable demo text on POSIX systems
63aa29f587SMatthias Ringwald // #undef HAVE_BTSTACK_STDIN
64aa29f587SMatthias Ringwald 
65762141afSMatthias Ringwald static uint8_t hid_service_buffer[270];
66762141afSMatthias Ringwald static uint8_t device_id_sdp_service_buffer[100];
67aa29f587SMatthias Ringwald static const char hid_device_name[] = "BTstack HID Mouse";
68aa29f587SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
69aa29f587SMatthias Ringwald static uint16_t hid_cid;
70aa29f587SMatthias Ringwald 
71aa29f587SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.2
72aa29f587SMatthias Ringwald const uint8_t hid_descriptor_mouse_boot_mode[] = {
73aa29f587SMatthias Ringwald     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
74aa29f587SMatthias Ringwald     0x09, 0x02,                    // USAGE (Mouse)
75aa29f587SMatthias Ringwald     0xa1, 0x01,                    // COLLECTION (Application)
76aa29f587SMatthias Ringwald 
77aa29f587SMatthias Ringwald     0x09, 0x01,                    //   USAGE (Pointer)
78aa29f587SMatthias Ringwald     0xa1, 0x00,                    //   COLLECTION (Physical)
79aa29f587SMatthias Ringwald 
80aa29f587SMatthias Ringwald     0x05, 0x09,                    //     USAGE_PAGE (Button)
81aa29f587SMatthias Ringwald     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
82aa29f587SMatthias Ringwald     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
83aa29f587SMatthias Ringwald     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
84aa29f587SMatthias Ringwald     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
85aa29f587SMatthias Ringwald     0x95, 0x03,                    //     REPORT_COUNT (3)
86aa29f587SMatthias Ringwald     0x75, 0x01,                    //     REPORT_SIZE (1)
87aa29f587SMatthias Ringwald     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
88aa29f587SMatthias Ringwald     0x95, 0x01,                    //     REPORT_COUNT (1)
89aa29f587SMatthias Ringwald     0x75, 0x05,                    //     REPORT_SIZE (5)
90aa29f587SMatthias Ringwald     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
91aa29f587SMatthias Ringwald 
92aa29f587SMatthias Ringwald     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
93aa29f587SMatthias Ringwald     0x09, 0x30,                    //     USAGE (X)
94aa29f587SMatthias Ringwald     0x09, 0x31,                    //     USAGE (Y)
95aa29f587SMatthias Ringwald     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
96aa29f587SMatthias Ringwald     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
97aa29f587SMatthias Ringwald     0x75, 0x08,                    //     REPORT_SIZE (8)
98aa29f587SMatthias Ringwald     0x95, 0x02,                    //     REPORT_COUNT (2)
99aa29f587SMatthias Ringwald     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
100aa29f587SMatthias Ringwald 
101aa29f587SMatthias Ringwald     0xc0,                          //   END_COLLECTION
102aa29f587SMatthias Ringwald     0xc0                           // END_COLLECTION
103aa29f587SMatthias Ringwald };
104aa29f587SMatthias Ringwald 
105aa29f587SMatthias Ringwald // HID Report sending
send_report(uint8_t buttons,int8_t dx,int8_t dy)106aa29f587SMatthias Ringwald static void send_report(uint8_t buttons, int8_t dx, int8_t dy){
107*d7bfc7cdSMatthias Ringwald     // setup HID message: A1 = Input Report, Report ID, Payload
108*d7bfc7cdSMatthias Ringwald     uint8_t message[] = {0xa1, buttons, (uint8_t) dx, (uint8_t) dy};
109*d7bfc7cdSMatthias Ringwald     hid_device_send_interrupt_message(hid_cid, &message[0], sizeof(message));
110aa29f587SMatthias Ringwald     printf("Mouse: %d/%d - buttons: %02x\n", dx, dy, buttons);
111aa29f587SMatthias Ringwald }
112aa29f587SMatthias Ringwald 
113aa29f587SMatthias Ringwald static int dx;
114aa29f587SMatthias Ringwald static int dy;
115aa29f587SMatthias Ringwald static uint8_t buttons;
116b274c7b3SMilanka Ringwald static int hid_boot_device = 0;
117aa29f587SMatthias Ringwald 
mousing_can_send_now(void)118aa29f587SMatthias Ringwald static void mousing_can_send_now(void){
119aa29f587SMatthias Ringwald     send_report(buttons, dx, dy);
120aa29f587SMatthias Ringwald     // reset
121aa29f587SMatthias Ringwald     dx = 0;
122aa29f587SMatthias Ringwald     dy = 0;
123aa29f587SMatthias Ringwald     if (buttons){
124aa29f587SMatthias Ringwald         buttons = 0;
125aa29f587SMatthias Ringwald         hid_device_request_can_send_now_event(hid_cid);
126aa29f587SMatthias Ringwald     }
127aa29f587SMatthias Ringwald }
128aa29f587SMatthias Ringwald 
129aa29f587SMatthias Ringwald // Demo Application
130aa29f587SMatthias Ringwald 
131aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
132aa29f587SMatthias Ringwald 
133aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 30;
134aa29f587SMatthias Ringwald 
135aa29f587SMatthias Ringwald // On systems with STDIN, we can directly type on the console
136aa29f587SMatthias Ringwald 
stdin_process(char character)137aa29f587SMatthias Ringwald static void stdin_process(char character){
138aa29f587SMatthias Ringwald 
139aa29f587SMatthias Ringwald     if (!hid_cid) {
140aa29f587SMatthias Ringwald         printf("Mouse not connected, ignoring '%c'\n", character);
141aa29f587SMatthias Ringwald         return;
142aa29f587SMatthias Ringwald     }
143aa29f587SMatthias Ringwald 
144aa29f587SMatthias Ringwald     switch (character){
145aa29f587SMatthias Ringwald         case 'a':
146aa29f587SMatthias Ringwald             dx -= MOUSE_SPEED;
147aa29f587SMatthias Ringwald             break;
148aa29f587SMatthias Ringwald         case 's':
149aa29f587SMatthias Ringwald             dy += MOUSE_SPEED;
150aa29f587SMatthias Ringwald             break;
151aa29f587SMatthias Ringwald         case 'd':
152aa29f587SMatthias Ringwald             dx += MOUSE_SPEED;
153aa29f587SMatthias Ringwald             break;
154aa29f587SMatthias Ringwald         case 'w':
155aa29f587SMatthias Ringwald             dy -= MOUSE_SPEED;
156aa29f587SMatthias Ringwald             break;
157aa29f587SMatthias Ringwald         case 'l':
158aa29f587SMatthias Ringwald             buttons |= 1;
159aa29f587SMatthias Ringwald             break;
160aa29f587SMatthias Ringwald         case 'r':
161aa29f587SMatthias Ringwald             buttons |= 2;
162aa29f587SMatthias Ringwald             break;
163aa29f587SMatthias Ringwald         default:
164aa29f587SMatthias Ringwald             return;
165aa29f587SMatthias Ringwald     }
166aa29f587SMatthias Ringwald     hid_device_request_can_send_now_event(hid_cid);
167aa29f587SMatthias Ringwald }
168aa29f587SMatthias Ringwald 
169aa29f587SMatthias Ringwald #else
170aa29f587SMatthias Ringwald 
171aa29f587SMatthias Ringwald // On embedded systems, simulate clicking on 4 corners of a square
172aa29f587SMatthias Ringwald 
173aa29f587SMatthias Ringwald #define MOUSE_PERIOD_MS 15
174aa29f587SMatthias Ringwald 
175aa29f587SMatthias Ringwald static int step;
176aa29f587SMatthias Ringwald static const int STEPS_PER_DIRECTION = 50;
177aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 10;
178aa29f587SMatthias Ringwald 
179aa29f587SMatthias Ringwald static struct {
180aa29f587SMatthias Ringwald     int dx;
181aa29f587SMatthias Ringwald     int dy;
182aa29f587SMatthias Ringwald } directions[] = {
183aa29f587SMatthias Ringwald     {  1,  0 },
184aa29f587SMatthias Ringwald     {  0,  1 },
185aa29f587SMatthias Ringwald     { -1,  0 },
186aa29f587SMatthias Ringwald     {  0, -1 },
187aa29f587SMatthias Ringwald };
188aa29f587SMatthias Ringwald 
189aa29f587SMatthias Ringwald static btstack_timer_source_t mousing_timer;
190aa29f587SMatthias Ringwald 
mousing_timer_handler(btstack_timer_source_t * ts)191aa29f587SMatthias Ringwald static void mousing_timer_handler(btstack_timer_source_t * ts){
192aa29f587SMatthias Ringwald 
193173fff9bSMatthias Ringwald     if (!hid_cid) return;
194aa29f587SMatthias Ringwald 
195aa29f587SMatthias Ringwald     // simulate left click when corner reached
196aa29f587SMatthias Ringwald     if (step % STEPS_PER_DIRECTION == 0){
197aa29f587SMatthias Ringwald         buttons |= 1;
198aa29f587SMatthias Ringwald     }
199aa29f587SMatthias Ringwald     // simulate move
200aa29f587SMatthias Ringwald     int direction_index = step / STEPS_PER_DIRECTION;
201aa29f587SMatthias Ringwald     dx += directions[direction_index].dx * MOUSE_SPEED;
202aa29f587SMatthias Ringwald     dy += directions[direction_index].dy * MOUSE_SPEED;
203aa29f587SMatthias Ringwald 
204aa29f587SMatthias Ringwald     // next
205aa29f587SMatthias Ringwald     step++;
206aa29f587SMatthias Ringwald     if (step >= STEPS_PER_DIRECTION * 4) {
207aa29f587SMatthias Ringwald         step = 0;
208aa29f587SMatthias Ringwald     }
209aa29f587SMatthias Ringwald 
210aa29f587SMatthias Ringwald     // trigger send
211173fff9bSMatthias Ringwald     hid_device_request_can_send_now_event(hid_cid);
212aa29f587SMatthias Ringwald 
213aa29f587SMatthias Ringwald     // set next timer
214aa29f587SMatthias Ringwald     btstack_run_loop_set_timer(ts, MOUSE_PERIOD_MS);
215aa29f587SMatthias Ringwald     btstack_run_loop_add_timer(ts);
216aa29f587SMatthias Ringwald }
217aa29f587SMatthias Ringwald 
hid_embedded_start_mousing(void)218aa29f587SMatthias Ringwald static void hid_embedded_start_mousing(void){
219aa29f587SMatthias Ringwald     printf("Start mousing..\n");
220aa29f587SMatthias Ringwald 
221aa29f587SMatthias Ringwald     step = 0;
222aa29f587SMatthias Ringwald 
223aa29f587SMatthias Ringwald     // set one-shot timer
224aa29f587SMatthias Ringwald     mousing_timer.process = &mousing_timer_handler;
225aa29f587SMatthias Ringwald     btstack_run_loop_set_timer(&mousing_timer, MOUSE_PERIOD_MS);
226aa29f587SMatthias Ringwald     btstack_run_loop_add_timer(&mousing_timer);
227aa29f587SMatthias Ringwald }
228aa29f587SMatthias Ringwald #endif
229aa29f587SMatthias Ringwald 
packet_handler(uint8_t packet_type,uint16_t channel,uint8_t * packet,uint16_t packet_size)230aa29f587SMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t packet_size){
231aa29f587SMatthias Ringwald     UNUSED(channel);
232aa29f587SMatthias Ringwald     UNUSED(packet_size);
233aa29f587SMatthias Ringwald     switch (packet_type){
234aa29f587SMatthias Ringwald         case HCI_EVENT_PACKET:
2356058cb0dSMatthias Ringwald             switch (hci_event_packet_get_type(packet)){
236aa29f587SMatthias Ringwald                 case HCI_EVENT_USER_CONFIRMATION_REQUEST:
237aa29f587SMatthias Ringwald                     // ssp: inform about user confirmation request
238aa29f587SMatthias Ringwald                     log_info("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", hci_event_user_confirmation_request_get_numeric_value(packet));
239aa29f587SMatthias Ringwald                     log_info("SSP User Confirmation Auto accept\n");
240aa29f587SMatthias Ringwald                     break;
241aa29f587SMatthias Ringwald 
242aa29f587SMatthias Ringwald                 case HCI_EVENT_HID_META:
243aa29f587SMatthias Ringwald                     switch (hci_event_hid_meta_get_subevent_code(packet)){
244aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CONNECTION_OPENED:
2456058cb0dSMatthias Ringwald                             if (hid_subevent_connection_opened_get_status(packet) != ERROR_CODE_SUCCESS) return;
246aa29f587SMatthias Ringwald                             hid_cid = hid_subevent_connection_opened_get_hid_cid(packet);
247aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
248aa29f587SMatthias Ringwald                             printf("HID Connected, control mouse using 'a','s',''d', 'w' keys for movement and 'l' and 'r' for buttons...\n");
249aa29f587SMatthias Ringwald #else
250aa29f587SMatthias Ringwald                             printf("HID Connected, simulating mouse movements...\n");
251173fff9bSMatthias Ringwald                             hid_embedded_start_mousing();
252aa29f587SMatthias Ringwald #endif
253aa29f587SMatthias Ringwald                             break;
254aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CONNECTION_CLOSED:
255aa29f587SMatthias Ringwald                             printf("HID Disconnected\n");
256aa29f587SMatthias Ringwald                             hid_cid = 0;
257aa29f587SMatthias Ringwald                             break;
258aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CAN_SEND_NOW:
259aa29f587SMatthias Ringwald                             mousing_can_send_now();
260aa29f587SMatthias Ringwald                             break;
261aa29f587SMatthias Ringwald                         default:
262aa29f587SMatthias Ringwald                             break;
263aa29f587SMatthias Ringwald                     }
264aa29f587SMatthias Ringwald                     break;
265aa29f587SMatthias Ringwald                 default:
266aa29f587SMatthias Ringwald                     break;
267aa29f587SMatthias Ringwald             }
268aa29f587SMatthias Ringwald             break;
269aa29f587SMatthias Ringwald         default:
270aa29f587SMatthias Ringwald             break;
271aa29f587SMatthias Ringwald     }
272aa29f587SMatthias Ringwald }
273aa29f587SMatthias Ringwald 
274aa29f587SMatthias Ringwald /* @section Main Application Setup
275aa29f587SMatthias Ringwald  *
276aa29f587SMatthias Ringwald  * @text Listing MainConfiguration shows main application code.
277aa29f587SMatthias Ringwald  * To run a HID Device service you need to initialize the SDP, and to create and register HID Device record with it.
278aa29f587SMatthias Ringwald  * At the end the Bluetooth stack is started.
279aa29f587SMatthias Ringwald  */
280aa29f587SMatthias Ringwald 
281aa29f587SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HID Device */
282aa29f587SMatthias Ringwald 
283aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]);
btstack_main(int argc,const char * argv[])284aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]){
285aa29f587SMatthias Ringwald     (void)argc;
286aa29f587SMatthias Ringwald     (void)argv;
287aa29f587SMatthias Ringwald 
28845a92abaSMatthias Ringwald     // allow to get found by inquiry
289aa29f587SMatthias Ringwald     gap_discoverable_control(1);
29045a92abaSMatthias Ringwald     // use Limited Discoverable Mode; Peripheral; Pointing Device as CoD
29145a92abaSMatthias Ringwald     gap_set_class_of_device(0x2580);
29245a92abaSMatthias Ringwald     // set local name to be identified - zeroes will be replaced by actual BD ADDR
293aa29f587SMatthias Ringwald     gap_set_local_name("HID Mouse Demo 00:00:00:00:00:00");
29445a92abaSMatthias Ringwald     // allow for role switch in general and sniff mode
29545a92abaSMatthias Ringwald     gap_set_default_link_policy_settings( LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE );
29645a92abaSMatthias Ringwald     // allow for role switch on outgoing connections - this allow HID Host to become master when we re-connect to it
29745a92abaSMatthias Ringwald     gap_set_allow_role_switch(true);
298aa29f587SMatthias Ringwald 
299aa29f587SMatthias Ringwald     // L2CAP
300aa29f587SMatthias Ringwald     l2cap_init();
301aa29f587SMatthias Ringwald 
3028c9bb29eSMatthias Ringwald #ifdef ENABLE_BLE
3038c9bb29eSMatthias Ringwald     // Initialize LE Security Manager. Needed for cross-transport key derivation
3048c9bb29eSMatthias Ringwald     sm_init();
3058c9bb29eSMatthias Ringwald #endif
3068c9bb29eSMatthias Ringwald 
307aa29f587SMatthias Ringwald     // SDP Server
308aa29f587SMatthias Ringwald     sdp_init();
3091ad99f3bSMilanka Ringwald 
3101ad99f3bSMilanka Ringwald     uint8_t hid_virtual_cable = 0;
3111ad99f3bSMilanka Ringwald     uint8_t hid_remote_wake = 1;
3121ad99f3bSMilanka Ringwald     uint8_t hid_reconnect_initiate = 1;
313ffe3f1a1SMilanka Ringwald     uint8_t hid_normally_connectable = 1;
3141ad99f3bSMilanka Ringwald 
31580d9d5d4SMilanka Ringwald     hid_sdp_record_t hid_params = {
31680d9d5d4SMilanka Ringwald         // hid sevice subclass 2580 Mouse, hid counntry code 33 US
31780d9d5d4SMilanka Ringwald         0x2580, 33,
31880d9d5d4SMilanka Ringwald         hid_virtual_cable, hid_remote_wake,
31980d9d5d4SMilanka Ringwald         hid_reconnect_initiate, hid_normally_connectable,
32080d9d5d4SMilanka Ringwald         hid_boot_device,
32180d9d5d4SMilanka Ringwald         0xFFFF, 0xFFFF, 3200,
32280d9d5d4SMilanka Ringwald         hid_descriptor_mouse_boot_mode,
32380d9d5d4SMilanka Ringwald         sizeof(hid_descriptor_mouse_boot_mode),
32480d9d5d4SMilanka Ringwald         hid_device_name
32580d9d5d4SMilanka Ringwald     };
32680d9d5d4SMilanka Ringwald 
327762141afSMatthias Ringwald     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
328762141afSMatthias Ringwald     hid_create_sdp_record(hid_service_buffer, sdp_create_service_record_handle(), &hid_params);
329762141afSMatthias Ringwald     btstack_assert(de_get_len( hid_service_buffer) <= sizeof(hid_service_buffer));
330aa29f587SMatthias Ringwald     sdp_register_service(hid_service_buffer);
331aa29f587SMatthias Ringwald 
332762141afSMatthias Ringwald     // See https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers if you don't have a USB Vendor ID and need a Bluetooth Vendor ID
333762141afSMatthias Ringwald     // device info: BlueKitchen GmbH, product 2, version 1
334762141afSMatthias Ringwald     device_id_create_sdp_record(device_id_sdp_service_buffer, sdp_create_service_record_handle(), DEVICE_ID_VENDOR_ID_SOURCE_BLUETOOTH, BLUETOOTH_COMPANY_ID_BLUEKITCHEN_GMBH, 2, 1);
335762141afSMatthias Ringwald     btstack_assert(de_get_len( device_id_sdp_service_buffer) <= sizeof(device_id_sdp_service_buffer));
336762141afSMatthias Ringwald     sdp_register_service(device_id_sdp_service_buffer);
337762141afSMatthias Ringwald 
338aa29f587SMatthias Ringwald     // HID Device
339a796c06fSMilanka Ringwald     hid_device_init(hid_boot_device, sizeof(hid_descriptor_mouse_boot_mode), hid_descriptor_mouse_boot_mode);
340a4fe6467SMatthias Ringwald     // register for HCI events
341a4fe6467SMatthias Ringwald     hci_event_callback_registration.callback = &packet_handler;
342a4fe6467SMatthias Ringwald     hci_add_event_handler(&hci_event_callback_registration);
343a4fe6467SMatthias Ringwald 
344a4fe6467SMatthias Ringwald     // register for HID
345aa29f587SMatthias Ringwald     hid_device_register_packet_handler(&packet_handler);
346aa29f587SMatthias Ringwald 
347aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
348aa29f587SMatthias Ringwald     btstack_stdin_setup(stdin_process);
349aa29f587SMatthias Ringwald #endif
350aa29f587SMatthias Ringwald     // turn on!
351aa29f587SMatthias Ringwald     hci_power_control(HCI_POWER_ON);
352aa29f587SMatthias Ringwald     return 0;
353aa29f587SMatthias Ringwald }
354aa29f587SMatthias Ringwald /* LISTING_END */
355aa29f587SMatthias Ringwald /* EXAMPLE_END */
356