From dc01ccc6b23fb84d78b2e6c1f4a02f3559d9bd6a Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sat, 14 Oct 2017 21:10:45 +0200 Subject: [PATCH] esp32: support power down and power up. updated sdkconfig --- port/esp32/components/btstack/main.c | 27 ++++++++++++++++++++------- port/esp32/template/sdkconfig | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/port/esp32/components/btstack/main.c b/port/esp32/components/btstack/main.c index 8bf7bf1bb..8f7b278c4 100644 --- a/port/esp32/components/btstack/main.c +++ b/port/esp32/components/btstack/main.c @@ -210,7 +210,7 @@ static void transport_init(const void *transport_config){ /** * open transport connection */ - +static int bt_controller_initialized; static int transport_open(void){ esp_err_t ret; @@ -218,21 +218,31 @@ static int transport_open(void){ btstack_ring_buffer_init(&hci_ringbuffer, hci_ringbuffer_storage, sizeof(hci_ringbuffer_storage)); + // http://esp-idf.readthedocs.io/en/latest/api-reference/bluetooth/controller_vhci.html (2017104) + // - "esp_bt_controller_init: ... This function should be called only once, before any other BT functions are called." + // - "esp_bt_controller_deinit" .. This function should be called only once, after any other BT functions are called. + // This function is not whole completed, esp_bt_controller_init cannot called after this function." + // -> esp_bt_controller_init can only be called once after boot + if (!bt_controller_initialized){ + bt_controller_initialized = 1; - esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - ret = esp_bt_controller_init(&bt_cfg); - if (ret) { - log_error("transport: esp_bt_controller_init failed"); - return -1; + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + ret = esp_bt_controller_init(&bt_cfg); + if (ret) { + log_error("transport: esp_bt_controller_init failed"); + return -1; + } + + esp_vhci_host_register_callback(&vhci_host_cb); } + // enable dual mode ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM); if (ret) { log_error("transport: esp_bt_controller_enable failed"); return -1; } - esp_vhci_host_register_callback(&vhci_host_cb); return 0; } @@ -241,6 +251,9 @@ static int transport_open(void){ */ static int transport_close(void){ log_info("transport_close"); + + // disable controller + esp_bt_controller_disable(); return 0; } diff --git a/port/esp32/template/sdkconfig b/port/esp32/template/sdkconfig index 549b329ae..8a87df25c 100644 --- a/port/esp32/template/sdkconfig +++ b/port/esp32/template/sdkconfig @@ -310,6 +310,9 @@ CONFIG_LWIP_SO_RCVBUF= CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 CONFIG_LWIP_IP_FRAG= CONFIG_LWIP_IP_REASSEMBLY= +CONFIG_LWIP_STATS= +CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y +CONFIG_TCPIP_RECVMBOX_SIZE=32 # # TCP