diff --git a/porting/nimble/src/hal_uart.c b/porting/nimble/src/hal_uart.c index 7d8c80a6b..cbfe7225c 100644 --- a/porting/nimble/src/hal_uart.c +++ b/porting/nimble/src/hal_uart.c @@ -14,6 +14,10 @@ #include "riscv/interrupt.h" #include "hal/uart_ll.h" #include "freertos/semphr.h" +#include "rom/ets_sys.h" + +#include "driver/uart.h" +#include "driver/periph_ctrl.h" struct hal_uart { uint8_t u_open:1; @@ -296,23 +300,11 @@ void uart0_init(uint32_t baud) esp_intr_reserve(ISR_ID, xPortGetCoreID()); - gpio_set_level(tx_pin, 1); - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[tx_pin], FUNC_U0RXD_U0RXD); - gpio_set_pull_mode(tx_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(tx_pin, GPIO_MODE_OUTPUT); - gpio_matrix_out(tx_pin, U0TXD_OUT_IDX, 0, 0); - - PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[rx_pin], FUNC_U0TXD_U0TXD); - gpio_set_pull_mode(rx_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(rx_pin, GPIO_MODE_INPUT); - gpio_pad_input_enable(rx_pin); - gpio_matrix_in(rx_pin, U0RXD_IN_IDX, 0); + ESP_ERROR_CHECK(uart_set_pin(0, tx_pin, rx_pin, -1, -1)); } -#include "driver/uart.h" -#include "driver/periph_ctrl.h" void uart_init(uint32_t baud) { @@ -369,7 +361,7 @@ void uart_init(uint32_t baud) u->u_rx_sem = xSemaphoreCreateBinary(); - uint8_t TX_IO = CONFIG_HCI_UART_TX_PIN, RX_IO = CONFIG_HCI_UART_RX_PIN, ISR_ID = ETS_UART1_INUM; + uint8_t TX_IO = CONFIG_BT_NIMBLE_HCI_UART_TX_PIN, RX_IO = CONFIG_BT_NIMBLE_HCI_UART_RX_PIN, ISR_ID = ETS_UART1_INUM; ets_printf("set nimble port tx:%d, rx:%d.\n", TX_IO, RX_IO); ets_printf("set baud:%d.\n", baud); intr_handler_set(ISR_ID, (intr_handler_t)&uart_tout_isr, NULL); diff --git a/porting/nimble/src/nimble_port.c b/porting/nimble/src/nimble_port.c index f09bf5926..964b4cb3b 100644 --- a/porting/nimble/src/nimble_port.c +++ b/porting/nimble/src/nimble_port.c @@ -20,7 +20,11 @@ #include #include "os/os.h" #include "sysinit/sysinit.h" + +#if CONFIG_BT_NIMBLE_ENABLED #include "host/ble_hs.h" +#endif //CONFIG_BT_NIMBLE_ENABLED + #include "nimble/nimble_port.h" #include "nimble/nimble_port_freertos.h" #ifdef ESP_PLATFORM @@ -46,13 +50,16 @@ #include "freertos/task.h" #include "esp_bt.h" -extern void ble_hs_deinit(void); #define NIMBLE_PORT_LOG_TAG "BLE_INIT" extern void os_msys_init(void); - -static struct ble_npl_eventq g_eventq_dflt; + +#if CONFIG_BT_NIMBLE_ENABLED +extern void ble_hs_deinit(void); static struct ble_hs_stop_listener stop_listener; +#endif //CONFIG_BT_NIMBLE_ENABLED + +static struct ble_npl_eventq g_eventq_dflt; static struct ble_npl_sem ble_hs_stop_sem; static struct ble_npl_event ble_hs_ev_stop; @@ -68,8 +75,10 @@ nimble_port_init(void) ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n"); return; } +#if CONFIG_BT_NIMBLE_ENABLED /* Initialize the host */ ble_hs_init(); +#endif #else //SOC_ESP_NIMBLE_CONTROLLER @@ -102,7 +111,10 @@ void nimble_port_deinit(void) { #if SOC_ESP_NIMBLE_CONTROLLER + +#if CONFIG_BT_NIMBLE_ENABLED ble_hs_deinit(); +#endif //CONFIG_BT_NIMBLE_ENABLED esp_bt_controller_deinit(); @@ -134,9 +146,10 @@ nimble_port_stop_cb(struct ble_npl_event *ev) int nimble_port_stop(void) { - int rc; + int rc = 0; ble_npl_sem_init(&ble_hs_stop_sem, 0); +#if CONFIG_BT_NIMBLE_ENABLED /* Initiate a host stop procedure. */ rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb, NULL); @@ -144,6 +157,7 @@ nimble_port_stop(void) ble_npl_sem_deinit(&ble_hs_stop_sem); return rc; } +#endif //CONFIG_BT_NIMBLE_ENABLED /* Wait till the host stop procedure is complete */ ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER); diff --git a/porting/npl/freertos/src/nimble_port_freertos.c b/porting/npl/freertos/src/nimble_port_freertos.c index aa33ed475..231d5de73 100644 --- a/porting/npl/freertos/src/nimble_port_freertos.c +++ b/porting/npl/freertos/src/nimble_port_freertos.c @@ -37,6 +37,7 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn) */ esp_bt_controller_enable(ESP_BT_MODE_BLE); #endif +#if CONFIG_BT_NIMBLE_ENABLED /* * Create task where NimBLE host will run. It is not strictly necessary to * have separate task for NimBLE host, but since something needs to handle @@ -44,6 +45,7 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn) */ xTaskCreatePinnedToCore(host_task_fn, "ble", NIMBLE_HS_STACK_SIZE, NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE); +#endif //CONFIG_BT_NIMBLE_ENABLED } void