2018-01-15 11:47:23 +00:00
|
|
|
/*
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
2017-03-16 09:14:20 +00:00
|
|
|
|
2018-01-15 11:47:23 +00:00
|
|
|
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.
|
|
|
|
*/
|
2017-03-16 09:14:20 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2017-07-20 08:40:03 +00:00
|
|
|
#include "nvs_flash.h"
|
2017-12-07 13:48:27 +00:00
|
|
|
#include "esp_bt.h"
|
2017-03-16 09:14:20 +00:00
|
|
|
#include "driver/uart.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
|
|
|
|
static const char *tag = "CONTROLLER_UART_HCI";
|
|
|
|
|
|
|
|
static void uart_gpio_reset(void)
|
|
|
|
{
|
2017-09-20 10:13:51 +00:00
|
|
|
#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
|
2017-04-05 13:19:15 +00:00
|
|
|
ESP_LOGI(tag, "HCI UART%d Pin select: TX 5, RX, 18, CTS 23, RTS 19", CONFIG_BT_HCI_UART_NO);
|
2017-03-16 09:14:20 +00:00
|
|
|
|
2017-04-05 13:19:15 +00:00
|
|
|
uart_set_pin(CONFIG_BT_HCI_UART_NO, 5, 18, 19, 23);
|
2017-03-16 09:14:20 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-16 09:33:30 +00:00
|
|
|
void app_main(void)
|
2017-03-16 09:14:20 +00:00
|
|
|
{
|
2017-04-05 13:19:15 +00:00
|
|
|
esp_err_t ret;
|
|
|
|
|
2017-07-13 15:46:19 +00:00
|
|
|
/* Initialize NVS — it is used to store PHY calibration data */
|
|
|
|
ret = nvs_flash_init();
|
2018-07-25 15:11:09 +00:00
|
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
2017-07-13 15:46:19 +00:00
|
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
|
|
ret = nvs_flash_init();
|
|
|
|
}
|
|
|
|
ESP_ERROR_CHECK( ret );
|
|
|
|
|
|
|
|
|
2017-03-16 09:14:20 +00:00
|
|
|
/* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */
|
|
|
|
uart_gpio_reset();
|
|
|
|
|
2017-04-05 13:19:15 +00:00
|
|
|
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
|
|
|
ret = esp_bt_controller_init(&bt_cfg);
|
|
|
|
if (ret != ESP_OK) {
|
2018-02-22 13:48:53 +00:00
|
|
|
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
|
2017-04-05 13:19:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
|
|
|
|
if (ret != ESP_OK) {
|
2018-02-22 13:48:53 +00:00
|
|
|
ESP_LOGE(tag, "Bluetooth Controller initialize failed: %s", esp_err_to_name(ret));
|
2017-03-16 09:14:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|