xref: /btstack/example/hid_mouse_demo.c (revision 8c9bb29ec24759ba592d72f79417df812fd8a97f)
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 
65aa29f587SMatthias Ringwald static uint8_t hid_service_buffer[250];
66aa29f587SMatthias Ringwald static const char hid_device_name[] = "BTstack HID Mouse";
67aa29f587SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
68aa29f587SMatthias Ringwald static uint16_t hid_cid;
69aa29f587SMatthias Ringwald 
70aa29f587SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.2
71aa29f587SMatthias Ringwald const uint8_t hid_descriptor_mouse_boot_mode[] = {
72aa29f587SMatthias Ringwald     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
73aa29f587SMatthias Ringwald     0x09, 0x02,                    // USAGE (Mouse)
74aa29f587SMatthias Ringwald     0xa1, 0x01,                    // COLLECTION (Application)
75aa29f587SMatthias Ringwald 
76aa29f587SMatthias Ringwald     0x09, 0x01,                    //   USAGE (Pointer)
77aa29f587SMatthias Ringwald     0xa1, 0x00,                    //   COLLECTION (Physical)
78aa29f587SMatthias Ringwald 
79aa29f587SMatthias Ringwald     0x05, 0x09,                    //     USAGE_PAGE (Button)
80aa29f587SMatthias Ringwald     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
81aa29f587SMatthias Ringwald     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
82aa29f587SMatthias Ringwald     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
83aa29f587SMatthias Ringwald     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
84aa29f587SMatthias Ringwald     0x95, 0x03,                    //     REPORT_COUNT (3)
85aa29f587SMatthias Ringwald     0x75, 0x01,                    //     REPORT_SIZE (1)
86aa29f587SMatthias Ringwald     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
87aa29f587SMatthias Ringwald     0x95, 0x01,                    //     REPORT_COUNT (1)
88aa29f587SMatthias Ringwald     0x75, 0x05,                    //     REPORT_SIZE (5)
89aa29f587SMatthias Ringwald     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
90aa29f587SMatthias Ringwald 
91aa29f587SMatthias Ringwald     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
92aa29f587SMatthias Ringwald     0x09, 0x30,                    //     USAGE (X)
93aa29f587SMatthias Ringwald     0x09, 0x31,                    //     USAGE (Y)
94aa29f587SMatthias Ringwald     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
95aa29f587SMatthias Ringwald     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
96aa29f587SMatthias Ringwald     0x75, 0x08,                    //     REPORT_SIZE (8)
97aa29f587SMatthias Ringwald     0x95, 0x02,                    //     REPORT_COUNT (2)
98aa29f587SMatthias Ringwald     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
99aa29f587SMatthias Ringwald 
100aa29f587SMatthias Ringwald     0xc0,                          //   END_COLLECTION
101aa29f587SMatthias Ringwald     0xc0                           // END_COLLECTION
102aa29f587SMatthias Ringwald };
103aa29f587SMatthias Ringwald 
104aa29f587SMatthias Ringwald // HID Report sending
105aa29f587SMatthias Ringwald static void send_report(uint8_t buttons, int8_t dx, int8_t dy){
106aa29f587SMatthias Ringwald     uint8_t report[] = { 0xa1, buttons, (uint8_t) dx, (uint8_t) dy};
107aa29f587SMatthias Ringwald     hid_device_send_interrupt_message(hid_cid, &report[0], sizeof(report));
108aa29f587SMatthias Ringwald     printf("Mouse: %d/%d - buttons: %02x\n", dx, dy, buttons);
109aa29f587SMatthias Ringwald }
110aa29f587SMatthias Ringwald 
111aa29f587SMatthias Ringwald static int dx;
112aa29f587SMatthias Ringwald static int dy;
113aa29f587SMatthias Ringwald static uint8_t buttons;
114b274c7b3SMilanka Ringwald static int hid_boot_device = 0;
115aa29f587SMatthias Ringwald 
116aa29f587SMatthias Ringwald static void mousing_can_send_now(void){
117aa29f587SMatthias Ringwald     send_report(buttons, dx, dy);
118aa29f587SMatthias Ringwald     // reset
119aa29f587SMatthias Ringwald     dx = 0;
120aa29f587SMatthias Ringwald     dy = 0;
121aa29f587SMatthias Ringwald     if (buttons){
122aa29f587SMatthias Ringwald         buttons = 0;
123aa29f587SMatthias Ringwald         hid_device_request_can_send_now_event(hid_cid);
124aa29f587SMatthias Ringwald     }
125aa29f587SMatthias Ringwald }
126aa29f587SMatthias Ringwald 
127aa29f587SMatthias Ringwald // Demo Application
128aa29f587SMatthias Ringwald 
129aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
130aa29f587SMatthias Ringwald 
131aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 30;
132aa29f587SMatthias Ringwald 
133aa29f587SMatthias Ringwald // On systems with STDIN, we can directly type on the console
134aa29f587SMatthias Ringwald 
135aa29f587SMatthias Ringwald static void stdin_process(char character){
136aa29f587SMatthias Ringwald 
137aa29f587SMatthias Ringwald     if (!hid_cid) {
138aa29f587SMatthias Ringwald         printf("Mouse not connected, ignoring '%c'\n", character);
139aa29f587SMatthias Ringwald         return;
140aa29f587SMatthias Ringwald     }
141aa29f587SMatthias Ringwald 
142aa29f587SMatthias Ringwald     switch (character){
143aa29f587SMatthias Ringwald         case 'a':
144aa29f587SMatthias Ringwald             dx -= MOUSE_SPEED;
145aa29f587SMatthias Ringwald             break;
146aa29f587SMatthias Ringwald         case 's':
147aa29f587SMatthias Ringwald             dy += MOUSE_SPEED;
148aa29f587SMatthias Ringwald             break;
149aa29f587SMatthias Ringwald         case 'd':
150aa29f587SMatthias Ringwald             dx += MOUSE_SPEED;
151aa29f587SMatthias Ringwald             break;
152aa29f587SMatthias Ringwald         case 'w':
153aa29f587SMatthias Ringwald             dy -= MOUSE_SPEED;
154aa29f587SMatthias Ringwald             break;
155aa29f587SMatthias Ringwald         case 'l':
156aa29f587SMatthias Ringwald             buttons |= 1;
157aa29f587SMatthias Ringwald             break;
158aa29f587SMatthias Ringwald         case 'r':
159aa29f587SMatthias Ringwald             buttons |= 2;
160aa29f587SMatthias Ringwald             break;
161aa29f587SMatthias Ringwald         default:
162aa29f587SMatthias Ringwald             return;
163aa29f587SMatthias Ringwald     }
164aa29f587SMatthias Ringwald     hid_device_request_can_send_now_event(hid_cid);
165aa29f587SMatthias Ringwald }
166aa29f587SMatthias Ringwald 
167aa29f587SMatthias Ringwald #else
168aa29f587SMatthias Ringwald 
169aa29f587SMatthias Ringwald // On embedded systems, simulate clicking on 4 corners of a square
170aa29f587SMatthias Ringwald 
171aa29f587SMatthias Ringwald #define MOUSE_PERIOD_MS 15
172aa29f587SMatthias Ringwald 
173aa29f587SMatthias Ringwald static int step;
174aa29f587SMatthias Ringwald static const int STEPS_PER_DIRECTION = 50;
175aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 10;
176aa29f587SMatthias Ringwald 
177aa29f587SMatthias Ringwald static struct {
178aa29f587SMatthias Ringwald     int dx;
179aa29f587SMatthias Ringwald     int dy;
180aa29f587SMatthias Ringwald } directions[] = {
181aa29f587SMatthias Ringwald     {  1,  0 },
182aa29f587SMatthias Ringwald     {  0,  1 },
183aa29f587SMatthias Ringwald     { -1,  0 },
184aa29f587SMatthias Ringwald     {  0, -1 },
185aa29f587SMatthias Ringwald };
186aa29f587SMatthias Ringwald 
187aa29f587SMatthias Ringwald static btstack_timer_source_t mousing_timer;
188aa29f587SMatthias Ringwald 
189aa29f587SMatthias Ringwald static void mousing_timer_handler(btstack_timer_source_t * ts){
190aa29f587SMatthias Ringwald 
191173fff9bSMatthias Ringwald     if (!hid_cid) return;
192aa29f587SMatthias Ringwald 
193aa29f587SMatthias Ringwald     // simulate left click when corner reached
194aa29f587SMatthias Ringwald     if (step % STEPS_PER_DIRECTION == 0){
195aa29f587SMatthias Ringwald         buttons |= 1;
196aa29f587SMatthias Ringwald     }
197aa29f587SMatthias Ringwald     // simulate move
198aa29f587SMatthias Ringwald     int direction_index = step / STEPS_PER_DIRECTION;
199aa29f587SMatthias Ringwald     dx += directions[direction_index].dx * MOUSE_SPEED;
200aa29f587SMatthias Ringwald     dy += directions[direction_index].dy * MOUSE_SPEED;
201aa29f587SMatthias Ringwald 
202aa29f587SMatthias Ringwald     // next
203aa29f587SMatthias Ringwald     step++;
204aa29f587SMatthias Ringwald     if (step >= STEPS_PER_DIRECTION * 4) {
205aa29f587SMatthias Ringwald         step = 0;
206aa29f587SMatthias Ringwald     }
207aa29f587SMatthias Ringwald 
208aa29f587SMatthias Ringwald     // trigger send
209173fff9bSMatthias Ringwald     hid_device_request_can_send_now_event(hid_cid);
210aa29f587SMatthias Ringwald 
211aa29f587SMatthias Ringwald     // set next timer
212aa29f587SMatthias Ringwald     btstack_run_loop_set_timer(ts, MOUSE_PERIOD_MS);
213aa29f587SMatthias Ringwald     btstack_run_loop_add_timer(ts);
214aa29f587SMatthias Ringwald }
215aa29f587SMatthias Ringwald 
216aa29f587SMatthias Ringwald static void hid_embedded_start_mousing(void){
217aa29f587SMatthias Ringwald     printf("Start mousing..\n");
218aa29f587SMatthias Ringwald 
219aa29f587SMatthias Ringwald     step = 0;
220aa29f587SMatthias Ringwald 
221aa29f587SMatthias Ringwald     // set one-shot timer
222aa29f587SMatthias Ringwald     mousing_timer.process = &mousing_timer_handler;
223aa29f587SMatthias Ringwald     btstack_run_loop_set_timer(&mousing_timer, MOUSE_PERIOD_MS);
224aa29f587SMatthias Ringwald     btstack_run_loop_add_timer(&mousing_timer);
225aa29f587SMatthias Ringwald }
226aa29f587SMatthias Ringwald #endif
227aa29f587SMatthias Ringwald 
228aa29f587SMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t packet_size){
229aa29f587SMatthias Ringwald     UNUSED(channel);
230aa29f587SMatthias Ringwald     UNUSED(packet_size);
231aa29f587SMatthias Ringwald     switch (packet_type){
232aa29f587SMatthias Ringwald         case HCI_EVENT_PACKET:
2336058cb0dSMatthias Ringwald             switch (hci_event_packet_get_type(packet)){
234aa29f587SMatthias Ringwald                 case HCI_EVENT_USER_CONFIRMATION_REQUEST:
235aa29f587SMatthias Ringwald                     // ssp: inform about user confirmation request
236aa29f587SMatthias Ringwald                     log_info("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", hci_event_user_confirmation_request_get_numeric_value(packet));
237aa29f587SMatthias Ringwald                     log_info("SSP User Confirmation Auto accept\n");
238aa29f587SMatthias Ringwald                     break;
239aa29f587SMatthias Ringwald 
240aa29f587SMatthias Ringwald                 case HCI_EVENT_HID_META:
241aa29f587SMatthias Ringwald                     switch (hci_event_hid_meta_get_subevent_code(packet)){
242aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CONNECTION_OPENED:
2436058cb0dSMatthias Ringwald                             if (hid_subevent_connection_opened_get_status(packet) != ERROR_CODE_SUCCESS) return;
244aa29f587SMatthias Ringwald                             hid_cid = hid_subevent_connection_opened_get_hid_cid(packet);
245aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
246aa29f587SMatthias Ringwald                             printf("HID Connected, control mouse using 'a','s',''d', 'w' keys for movement and 'l' and 'r' for buttons...\n");
247aa29f587SMatthias Ringwald #else
248aa29f587SMatthias Ringwald                             printf("HID Connected, simulating mouse movements...\n");
249173fff9bSMatthias Ringwald                             hid_embedded_start_mousing();
250aa29f587SMatthias Ringwald #endif
251aa29f587SMatthias Ringwald                             break;
252aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CONNECTION_CLOSED:
253aa29f587SMatthias Ringwald                             printf("HID Disconnected\n");
254aa29f587SMatthias Ringwald                             hid_cid = 0;
255aa29f587SMatthias Ringwald                             break;
256aa29f587SMatthias Ringwald                         case HID_SUBEVENT_CAN_SEND_NOW:
257aa29f587SMatthias Ringwald                             mousing_can_send_now();
258aa29f587SMatthias Ringwald                             break;
259aa29f587SMatthias Ringwald                         default:
260aa29f587SMatthias Ringwald                             break;
261aa29f587SMatthias Ringwald                     }
262aa29f587SMatthias Ringwald                     break;
263aa29f587SMatthias Ringwald                 default:
264aa29f587SMatthias Ringwald                     break;
265aa29f587SMatthias Ringwald             }
266aa29f587SMatthias Ringwald             break;
267aa29f587SMatthias Ringwald         default:
268aa29f587SMatthias Ringwald             break;
269aa29f587SMatthias Ringwald     }
270aa29f587SMatthias Ringwald }
271aa29f587SMatthias Ringwald 
272aa29f587SMatthias Ringwald /* @section Main Application Setup
273aa29f587SMatthias Ringwald  *
274aa29f587SMatthias Ringwald  * @text Listing MainConfiguration shows main application code.
275aa29f587SMatthias Ringwald  * To run a HID Device service you need to initialize the SDP, and to create and register HID Device record with it.
276aa29f587SMatthias Ringwald  * At the end the Bluetooth stack is started.
277aa29f587SMatthias Ringwald  */
278aa29f587SMatthias Ringwald 
279aa29f587SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HID Device */
280aa29f587SMatthias Ringwald 
281aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]);
282aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]){
283aa29f587SMatthias Ringwald     (void)argc;
284aa29f587SMatthias Ringwald     (void)argv;
285aa29f587SMatthias Ringwald 
28645a92abaSMatthias Ringwald     // allow to get found by inquiry
287aa29f587SMatthias Ringwald     gap_discoverable_control(1);
28845a92abaSMatthias Ringwald     // use Limited Discoverable Mode; Peripheral; Pointing Device as CoD
28945a92abaSMatthias Ringwald     gap_set_class_of_device(0x2580);
29045a92abaSMatthias Ringwald     // set local name to be identified - zeroes will be replaced by actual BD ADDR
291aa29f587SMatthias Ringwald     gap_set_local_name("HID Mouse Demo 00:00:00:00:00:00");
29245a92abaSMatthias Ringwald     // allow for role switch in general and sniff mode
29345a92abaSMatthias Ringwald     gap_set_default_link_policy_settings( LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE );
29445a92abaSMatthias Ringwald     // allow for role switch on outgoing connections - this allow HID Host to become master when we re-connect to it
29545a92abaSMatthias Ringwald     gap_set_allow_role_switch(true);
296aa29f587SMatthias Ringwald 
297aa29f587SMatthias Ringwald     // L2CAP
298aa29f587SMatthias Ringwald     l2cap_init();
299aa29f587SMatthias Ringwald 
300*8c9bb29eSMatthias Ringwald #ifdef ENABLE_BLE
301*8c9bb29eSMatthias Ringwald     // Initialize LE Security Manager. Needed for cross-transport key derivation
302*8c9bb29eSMatthias Ringwald     sm_init();
303*8c9bb29eSMatthias Ringwald #endif
304*8c9bb29eSMatthias Ringwald 
305aa29f587SMatthias Ringwald     // SDP Server
306aa29f587SMatthias Ringwald     sdp_init();
307aa29f587SMatthias Ringwald     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
3081ad99f3bSMilanka Ringwald 
3091ad99f3bSMilanka Ringwald     uint8_t hid_virtual_cable = 0;
3101ad99f3bSMilanka Ringwald     uint8_t hid_remote_wake = 1;
3111ad99f3bSMilanka Ringwald     uint8_t hid_reconnect_initiate = 1;
312ffe3f1a1SMilanka Ringwald     uint8_t hid_normally_connectable = 1;
3131ad99f3bSMilanka Ringwald 
31480d9d5d4SMilanka Ringwald     hid_sdp_record_t hid_params = {
31580d9d5d4SMilanka Ringwald         // hid sevice subclass 2580 Mouse, hid counntry code 33 US
31680d9d5d4SMilanka Ringwald         0x2580, 33,
31780d9d5d4SMilanka Ringwald         hid_virtual_cable, hid_remote_wake,
31880d9d5d4SMilanka Ringwald         hid_reconnect_initiate, hid_normally_connectable,
31980d9d5d4SMilanka Ringwald         hid_boot_device,
32080d9d5d4SMilanka Ringwald         0xFFFF, 0xFFFF, 3200,
32180d9d5d4SMilanka Ringwald         hid_descriptor_mouse_boot_mode,
32280d9d5d4SMilanka Ringwald         sizeof(hid_descriptor_mouse_boot_mode),
32380d9d5d4SMilanka Ringwald         hid_device_name
32480d9d5d4SMilanka Ringwald     };
32580d9d5d4SMilanka Ringwald 
32680d9d5d4SMilanka Ringwald     hid_create_sdp_record(hid_service_buffer, 0x10001, &hid_params);
32780d9d5d4SMilanka Ringwald 
328aa29f587SMatthias Ringwald     printf("SDP service record size: %u\n", de_get_len( hid_service_buffer));
329aa29f587SMatthias Ringwald     sdp_register_service(hid_service_buffer);
330aa29f587SMatthias Ringwald 
331aa29f587SMatthias Ringwald     // HID Device
332a796c06fSMilanka Ringwald     hid_device_init(hid_boot_device, sizeof(hid_descriptor_mouse_boot_mode), hid_descriptor_mouse_boot_mode);
333a4fe6467SMatthias Ringwald     // register for HCI events
334a4fe6467SMatthias Ringwald     hci_event_callback_registration.callback = &packet_handler;
335a4fe6467SMatthias Ringwald     hci_add_event_handler(&hci_event_callback_registration);
336a4fe6467SMatthias Ringwald 
337a4fe6467SMatthias Ringwald     // register for HID
338aa29f587SMatthias Ringwald     hid_device_register_packet_handler(&packet_handler);
339aa29f587SMatthias Ringwald 
340aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
341aa29f587SMatthias Ringwald     btstack_stdin_setup(stdin_process);
342aa29f587SMatthias Ringwald #endif
343aa29f587SMatthias Ringwald     // turn on!
344aa29f587SMatthias Ringwald     hci_power_control(HCI_POWER_ON);
345aa29f587SMatthias Ringwald     return 0;
346aa29f587SMatthias Ringwald }
347aa29f587SMatthias Ringwald /* LISTING_END */
348aa29f587SMatthias Ringwald /* EXAMPLE_END */
349