xref: /btstack/example/hid_mouse_demo.c (revision 1ad99f3bd30dfda1f1d3c25ba34069bcf3cdff8c)
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
23aa29f587SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24aa29f587SMatthias Ringwald  * RINGWALD 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
4615de8206SMilanka Ringwald  *
4715de8206SMilanka Ringwald  * @text Status: Basic implementation. HID Request from Host are not answered yet. Works with iOS.
48aa29f587SMatthias Ringwald  */
49aa29f587SMatthias Ringwald // *****************************************************************************
50aa29f587SMatthias Ringwald 
51aa29f587SMatthias Ringwald 
52aa29f587SMatthias Ringwald #include <stdint.h>
53aa29f587SMatthias Ringwald #include <stdio.h>
54aa29f587SMatthias Ringwald #include <stdlib.h>
55aa29f587SMatthias Ringwald #include <string.h>
56aa29f587SMatthias Ringwald #include <inttypes.h>
57aa29f587SMatthias Ringwald 
58aa29f587SMatthias Ringwald #include "btstack.h"
59aa29f587SMatthias Ringwald 
60aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
61aa29f587SMatthias Ringwald #include "btstack_stdin.h"
62aa29f587SMatthias Ringwald #endif
63aa29f587SMatthias Ringwald 
64aa29f587SMatthias Ringwald // to enable demo text on POSIX systems
65aa29f587SMatthias Ringwald // #undef HAVE_BTSTACK_STDIN
66aa29f587SMatthias Ringwald 
67aa29f587SMatthias Ringwald static uint8_t hid_service_buffer[250];
68aa29f587SMatthias Ringwald static const char hid_device_name[] = "BTstack HID Mouse";
69aa29f587SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration;
70aa29f587SMatthias Ringwald static uint16_t hid_cid;
71aa29f587SMatthias Ringwald 
72aa29f587SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.2
73aa29f587SMatthias Ringwald const uint8_t hid_descriptor_mouse_boot_mode[] = {
74aa29f587SMatthias Ringwald     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
75aa29f587SMatthias Ringwald     0x09, 0x02,                    // USAGE (Mouse)
76aa29f587SMatthias Ringwald     0xa1, 0x01,                    // COLLECTION (Application)
77aa29f587SMatthias Ringwald 
78aa29f587SMatthias Ringwald     0x09, 0x01,                    //   USAGE (Pointer)
79aa29f587SMatthias Ringwald     0xa1, 0x00,                    //   COLLECTION (Physical)
80aa29f587SMatthias Ringwald 
81aa29f587SMatthias Ringwald     0x05, 0x09,                    //     USAGE_PAGE (Button)
82aa29f587SMatthias Ringwald     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
83aa29f587SMatthias Ringwald     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
84aa29f587SMatthias Ringwald     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
85aa29f587SMatthias Ringwald     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
86aa29f587SMatthias Ringwald     0x95, 0x03,                    //     REPORT_COUNT (3)
87aa29f587SMatthias Ringwald     0x75, 0x01,                    //     REPORT_SIZE (1)
88aa29f587SMatthias Ringwald     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
89aa29f587SMatthias Ringwald     0x95, 0x01,                    //     REPORT_COUNT (1)
90aa29f587SMatthias Ringwald     0x75, 0x05,                    //     REPORT_SIZE (5)
91aa29f587SMatthias Ringwald     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
92aa29f587SMatthias Ringwald 
93aa29f587SMatthias Ringwald     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
94aa29f587SMatthias Ringwald     0x09, 0x30,                    //     USAGE (X)
95aa29f587SMatthias Ringwald     0x09, 0x31,                    //     USAGE (Y)
96aa29f587SMatthias Ringwald     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
97aa29f587SMatthias Ringwald     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
98aa29f587SMatthias Ringwald     0x75, 0x08,                    //     REPORT_SIZE (8)
99aa29f587SMatthias Ringwald     0x95, 0x02,                    //     REPORT_COUNT (2)
100aa29f587SMatthias Ringwald     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
101aa29f587SMatthias Ringwald 
102aa29f587SMatthias Ringwald     0xc0,                          //   END_COLLECTION
103aa29f587SMatthias Ringwald     0xc0                           // END_COLLECTION
104aa29f587SMatthias Ringwald };
105aa29f587SMatthias Ringwald 
106aa29f587SMatthias Ringwald // HID Report sending
107aa29f587SMatthias Ringwald static void send_report(uint8_t buttons, int8_t dx, int8_t dy){
108aa29f587SMatthias Ringwald     uint8_t report[] = { 0xa1, buttons, (uint8_t) dx, (uint8_t) dy};
109aa29f587SMatthias Ringwald     hid_device_send_interrupt_message(hid_cid, &report[0], sizeof(report));
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 
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 
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 
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 
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 
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:
235aa29f587SMatthias Ringwald             switch (packet[0]){
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:
245aa29f587SMatthias Ringwald                             if (hid_subevent_connection_opened_get_status(packet)) 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[]);
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 
302aa29f587SMatthias Ringwald     // SDP Server
303aa29f587SMatthias Ringwald     sdp_init();
304aa29f587SMatthias Ringwald     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
305*1ad99f3bSMilanka Ringwald 
306*1ad99f3bSMilanka Ringwald     uint8_t hid_virtual_cable = 0;
307*1ad99f3bSMilanka Ringwald     uint8_t hid_remote_wake = 1;
308*1ad99f3bSMilanka Ringwald     uint8_t hid_reconnect_initiate = 1;
309*1ad99f3bSMilanka Ringwald 
310aa29f587SMatthias Ringwald     // hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable off, hid reconnect initiate off, hid boot device off
311*1ad99f3bSMilanka Ringwald     hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33,
312*1ad99f3bSMilanka Ringwald         hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate,
313*1ad99f3bSMilanka Ringwald         hid_boot_device, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode), hid_device_name);
314aa29f587SMatthias Ringwald     printf("SDP service record size: %u\n", de_get_len( hid_service_buffer));
315aa29f587SMatthias Ringwald     sdp_register_service(hid_service_buffer);
316aa29f587SMatthias Ringwald 
317aa29f587SMatthias Ringwald     // HID Device
318a796c06fSMilanka Ringwald     hid_device_init(hid_boot_device, sizeof(hid_descriptor_mouse_boot_mode), hid_descriptor_mouse_boot_mode);
319a4fe6467SMatthias Ringwald     // register for HCI events
320a4fe6467SMatthias Ringwald     hci_event_callback_registration.callback = &packet_handler;
321a4fe6467SMatthias Ringwald     hci_add_event_handler(&hci_event_callback_registration);
322a4fe6467SMatthias Ringwald 
323a4fe6467SMatthias Ringwald     // register for HID
324aa29f587SMatthias Ringwald     hid_device_register_packet_handler(&packet_handler);
325aa29f587SMatthias Ringwald 
326aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN
327aa29f587SMatthias Ringwald     btstack_stdin_setup(stdin_process);
328aa29f587SMatthias Ringwald #endif
329aa29f587SMatthias Ringwald     // turn on!
330aa29f587SMatthias Ringwald     hci_power_control(HCI_POWER_ON);
331aa29f587SMatthias Ringwald     return 0;
332aa29f587SMatthias Ringwald }
333aa29f587SMatthias Ringwald /* LISTING_END */
334aa29f587SMatthias Ringwald /* EXAMPLE_END */
335