diff --git a/CHANGELOG.md b/CHANGELOG.md index af43de7b8..0e5d705f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Broadcom/Cypress: wait 300 ms after PatchRAM update in hci.c to assert Controller is ready +- esp32: provide esp-idf/component/btstack/btstack_port_esp32.c and only minimal app_main in template/main/main.c ## Changes March 2020 diff --git a/port/esp32/components/btstack/main.c b/port/esp32/components/btstack/btstack_port_esp32.c similarity index 97% rename from port/esp32/components/btstack/main.c rename to port/esp32/components/btstack/btstack_port_esp32.c index d6ef9dddf..2a931b8f8 100644 --- a/port/esp32/components/btstack/main.c +++ b/port/esp32/components/btstack/btstack_port_esp32.c @@ -58,6 +58,7 @@ #include "esp_bt.h" #include "btstack_debug.h" #include "btstack_audio.h" +#include "btstack_port_esp32.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -359,17 +360,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } } -extern int btstack_main(int argc, const char * argv[]); - -// main -int app_main(void){ - - printf("BTstack: setup\n"); - - // enable packet logger - // hci_dump_open(NULL, HCI_DUMP_STDOUT); - - /// GET STARTED with BTstack /// +uint8_t btstack_init(void){ + // Setup memory pools and run loop btstack_memory_init(); btstack_run_loop_init(btstack_run_loop_freertos_get_instance()); @@ -394,10 +386,6 @@ int app_main(void){ // setup i2s audio sink btstack_audio_sink_set_instance(btstack_audio_esp32_sink_get_instance()); - btstack_main(0, NULL); - - printf("BTstack: execute run loop\n"); - btstack_run_loop_execute(); - return 0; + return ERROR_CODE_SUCCESS; } diff --git a/port/esp32/components/btstack/include/btstack_port_esp32.h b/port/esp32/components/btstack/include/btstack_port_esp32.h new file mode 100644 index 000000000..25dadb859 --- /dev/null +++ b/port/esp32/components/btstack/include/btstack_port_esp32.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * btstack_port_esp32.h + * + * Integration of ESP32 Bluetooth Controller into BTstack + */ + +#ifndef __BTSTACK_PORT_ESP32_H +#define __BTSTACK_PORT_ESP32_H + +#include + +/** + * Configure BTstack for use with ESP32 VHCI Bluetooth Controller + * + * + * @returns status ERROR_CODE_SUCCESS if ok + */ + +uint8_t btstack_init(void); + +#endif //__BTSTACK_PORT_ESP32_H diff --git a/port/esp32/create_examples.py b/port/esp32/create_examples.py index c3c6d660e..94dbc51c2 100755 --- a/port/esp32/create_examples.py +++ b/port/esp32/create_examples.py @@ -117,6 +117,9 @@ def create_examples(script_path, suffix): if not os.path.exists(main_folder): os.makedirs(main_folder) + # copy main file + shutil.copyfile(script_path + '/template/main/main.c', apps_folder + "/main/main.c") + # copy example file shutil.copyfile(examples_embedded + file, apps_folder + "/main/" + example + ".c") diff --git a/port/esp32/template/main/main.c b/port/esp32/template/main/main.c new file mode 100644 index 000000000..66a6fab35 --- /dev/null +++ b/port/esp32/template/main/main.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * main.c + * + * Minimal main application that initializes BTstack, prepares the example and enters BTstack's Run Loop. + * + * If needed, you can create other threads. Please note that BTstack's API is not thread-safe and can only be + * called from BTstack timers or in response to its callbacks, e.g. packet handlers. + */ + +#include "btstack_port_esp32.h" +#include "btstack_run_loop.h" +#include "hci_dump.h" + +#include + +extern int btstack_main(int argc, const char * argv[]); + +int app_main(void){ + + // optional: enable packet logger + // hci_dump_open(NULL, HCI_DUMP_STDOUT); + + // Configure BTstack for ESP32 VHCI Controller + btstack_init(); + + // Setup example + btstack_main(0, NULL); + + // Enter run loop (forever) + btstack_run_loop_execute(); + + return 0; +}