xref: /btstack/port/esp32/template/main/main.c (revision 8c35a1166e5eb1e0fd77609842b374fcadb15a2c)
1bd8e4ef6SMatthias Ringwald /*
2bd8e4ef6SMatthias Ringwald  * Copyright (C) 2020 BlueKitchen GmbH
3bd8e4ef6SMatthias Ringwald  *
4bd8e4ef6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5bd8e4ef6SMatthias Ringwald  * modification, are permitted provided that the following conditions
6bd8e4ef6SMatthias Ringwald  * are met:
7bd8e4ef6SMatthias Ringwald  *
8bd8e4ef6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9bd8e4ef6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10bd8e4ef6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11bd8e4ef6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12bd8e4ef6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13bd8e4ef6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14bd8e4ef6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15bd8e4ef6SMatthias Ringwald  *    from this software without specific prior written permission.
16bd8e4ef6SMatthias Ringwald  *
172fca4dadSMilanka Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
18bd8e4ef6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19bd8e4ef6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
202fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
212fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22bd8e4ef6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23bd8e4ef6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24bd8e4ef6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25bd8e4ef6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26bd8e4ef6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27bd8e4ef6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28bd8e4ef6SMatthias Ringwald  * SUCH DAMAGE.
29bd8e4ef6SMatthias Ringwald  *
30bd8e4ef6SMatthias Ringwald  */
31bd8e4ef6SMatthias Ringwald 
32bd8e4ef6SMatthias Ringwald /*
33bd8e4ef6SMatthias Ringwald  *  main.c
34bd8e4ef6SMatthias Ringwald  *
35bd8e4ef6SMatthias Ringwald  *  Minimal main application that initializes BTstack, prepares the example and enters BTstack's Run Loop.
36bd8e4ef6SMatthias Ringwald  *
37bd8e4ef6SMatthias Ringwald  *  If needed, you can create other threads. Please note that BTstack's API is not thread-safe and can only be
38bd8e4ef6SMatthias Ringwald  *  called from BTstack timers or in response to its callbacks, e.g. packet handlers.
39bd8e4ef6SMatthias Ringwald  */
40bd8e4ef6SMatthias Ringwald 
41bd8e4ef6SMatthias Ringwald #include "btstack_port_esp32.h"
42bd8e4ef6SMatthias Ringwald #include "btstack_run_loop.h"
437f664105SMatthias Ringwald #include "btstack_stdio_esp32.h"
44bd8e4ef6SMatthias Ringwald #include "hci_dump.h"
45be2a7549SMatthias Ringwald #include "hci_dump_embedded_stdout.h"
46bd8e4ef6SMatthias Ringwald 
47bd8e4ef6SMatthias Ringwald #include <stddef.h>
48bd8e4ef6SMatthias Ringwald 
49e9a15bc5SMatthias Ringwald // warn about unsuitable sdkconfig
50e9a15bc5SMatthias Ringwald #include "sdkconfig.h"
51e9a15bc5SMatthias Ringwald #if !CONFIG_BT_ENABLED
52e9a15bc5SMatthias Ringwald #error "Bluetooth disabled - please set CONFIG_BT_ENABLED via menuconfig -> Component Config -> Bluetooth -> [x] Bluetooth"
53e9a15bc5SMatthias Ringwald #endif
54e9a15bc5SMatthias Ringwald #if !CONFIG_BT_CONTROLLER_ONLY
55e9a15bc5SMatthias Ringwald #error "Different Bluetooth Host stack selected - please set CONFIG_BT_CONTROLLER_ONLY via menuconfig -> Component Config -> Bluetooth -> Host -> Disabled"
56e9a15bc5SMatthias Ringwald #endif
57862392e5SMatthias Ringwald #if ESP_IDF_VERSION_MAJOR >= 5
58e9a15bc5SMatthias Ringwald #if !CONFIG_BT_CONTROLLER_ENABLED
59e9a15bc5SMatthias Ringwald #error "Different Bluetooth Host stack selected - please set CONFIG_BT_CONTROLLER_ENABLED via menuconfig -> Component Config -> Bluetooth -> Controller -> Enabled"
60e9a15bc5SMatthias Ringwald #endif
615e40310dSMatthias Ringwald #endif
62e9a15bc5SMatthias Ringwald 
63bd8e4ef6SMatthias Ringwald extern int btstack_main(int argc, const char * argv[]);
64bd8e4ef6SMatthias Ringwald 
app_main(void)65bd8e4ef6SMatthias Ringwald int app_main(void){
66bd8e4ef6SMatthias Ringwald 
67bd8e4ef6SMatthias Ringwald     // optional: enable packet logger
68be2a7549SMatthias Ringwald     // hci_dump_init(hci_dump_embedded_stdout_get_instance());
69bd8e4ef6SMatthias Ringwald 
70*8c35a116SMatthias Ringwald #ifdef CONFIG_ESP_CONSOLE_UART
717f664105SMatthias Ringwald     // Enable buffered stdout
727f664105SMatthias Ringwald     btstack_stdio_init();
73*8c35a116SMatthias Ringwald #endif
747f664105SMatthias Ringwald 
75bd8e4ef6SMatthias Ringwald     // Configure BTstack for ESP32 VHCI Controller
76bd8e4ef6SMatthias Ringwald     btstack_init();
77bd8e4ef6SMatthias Ringwald 
78bd8e4ef6SMatthias Ringwald     // Setup example
79bd8e4ef6SMatthias Ringwald     btstack_main(0, NULL);
80bd8e4ef6SMatthias Ringwald 
81bd8e4ef6SMatthias Ringwald     // Enter run loop (forever)
82bd8e4ef6SMatthias Ringwald     btstack_run_loop_execute();
83bd8e4ef6SMatthias Ringwald 
84bd8e4ef6SMatthias Ringwald     return 0;
85bd8e4ef6SMatthias Ringwald }
86