controller_hci_uart_demo.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "bt.h"
  16. #include "driver/uart.h"
  17. #include "esp_log.h"
  18. static const char *tag = "CONTROLLER_UART_HCI";
  19. static void uart_gpio_reset(void)
  20. {
  21. #if CONFIG_BT_HCI_UART_NO
  22. ESP_LOGI(tag, "HCI UART%d Pin select: TX 5, RX, 18, CTS 23, RTS 19", CONFIG_BT_HCI_UART_NO);
  23. uart_set_pin(CONFIG_BT_HCI_UART_NO, 5, 18, 19, 23);
  24. #endif
  25. }
  26. void app_main()
  27. {
  28. esp_err_t ret;
  29. /* As the UART1/2 pin conflict with flash pin, so do matrix of the signal and pin */
  30. uart_gpio_reset();
  31. esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
  32. ret = esp_bt_controller_init(&bt_cfg);
  33. if (ret != ESP_OK) {
  34. ESP_LOGE(tag, "Bluetooth Controller initialize failed, ret %d", ret);
  35. return;
  36. }
  37. ret = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
  38. if (ret != ESP_OK) {
  39. ESP_LOGE(tag, "Bluetooth Controller initialize failed, ret %d", ret);
  40. return;
  41. }
  42. }