OVMS3-idf/examples/bluetooth/bluedroid/hci/controller_hci_uart/main/controller_hci_uart_demo.c
Hrishikesh Dhayagude cba69dd088 Bluetooth examples restructuring
The existing Bluetooth examples are split as:

1. examples/bluetooth/bluedroid - Bluedroid Host (BT + BLE) examples
   a. examples/bluetooth/bluedroid/classic_bt - Classic BT examples
   b. examples/bluetooth/bluedroid/ble - BLE examples
   c. examples/bluetooth/bluedroid/coex - Classic BT and BLE coex examples
   d. examples/bluetooth/bluedroid/hci - VHCI and HCI UART examples
      i. Rename ble_adv to controller_vhci_ble_adv and move it in hci folder
2. examples/bluetooth/nimble - NimBLE BLE Host + NimBLE Mesh examples
3. examples/bluetooth/esp_ble_mesh - ESP BLE Mesh examples
4. Update documentation references
2019-07-01 19:21:57 +08:00

63 lines
1.8 KiB
C

/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "nvs_flash.h"
#include "esp_bt.h"
#include "driver/uart.h"
#include "esp_log.h"
static const char *tag = "CONTROLLER_UART_HCI";
static void uart_gpio_reset(void)
{
#if CONFIG_BT_HCI_UART_NO == 1
periph_module_enable(PERIPH_UART1_MODULE);
#elif CONFIG_BT_HCI_UART_NO == 2
periph_module_enable(PERIPH_UART2_MODULE);
#endif
periph_module_enable(PERIPH_UHCI0_MODULE);
#ifdef CONFIG_BT_HCI_UART_NO
ESP_LOGI(tag, "HCI UART%d Pin select: TX 5, RX, 18, CTS 23, RTS 19", CONFIG_BT_HCI_UART_NO);
uart_set_pin(CONFIG_BT_HCI_UART_NO, 5, 18, 19, 23);
#endif
}
void app_main()
{
esp_err_t ret;
/* Initialize NVS — it is used to store PHY calibration data */
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
/* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */
uart_gpio_reset();
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
return;
}
}