소스 검색

[esp-hosted][bt] add numble of the bluetooth supports

Evlers 11 달 전
부모
커밋
fc41019375
4개의 변경된 파일64개의 추가작업 그리고 7개의 파일을 삭제
  1. 19 3
      Kconfig
  2. 3 0
      esp-hosted/host/drivers/bt/hci_stub_drv.c
  3. 35 4
      esp-hosted/host/drivers/bt/vhci_drv.c
  4. 7 0
      porting/port/include/config_convert.h

+ 19 - 3
Kconfig

@@ -15,9 +15,9 @@ menuconfig RT_USING_ESP_HOSTED
 
                     config ESP_HOSTED_SPI_HOST_INTERFACE
                         bool "SPI"
-                    
-                    config ESP_HOSTED_SDIO_HOST_INTERFACE
-                        bool "SDIO"
+
+                    # config ESP_HOSTED_SDIO_HOST_INTERFACE
+                    #     bool "SDIO"
             endchoice
 
             choice
@@ -156,10 +156,12 @@ menuconfig RT_USING_ESP_HOSTED
                 config ESP_HOSTED_DATA_READY_PIN_NAME
                     string "Set the data ready pin name"
                     default "PA.0"
+                    depends on ESP_HOSTED_SPI_HOST_INTERFACE
 
                 config ESP_HOSTED_HANDSHAKE_PIN_NAME
                     string "Set the handshake pin name"
                     default "PA.0"
+                    depends on ESP_HOSTED_SPI_HOST_INTERFACE
 
                 config ESP_HOSTED_RESET_PIN_NAME
                     string "Set the reset pin name"
@@ -202,6 +204,20 @@ menuconfig RT_USING_ESP_HOSTED
             endif
         endmenu # ESP-Hosted Configure
 
+        menuconfig ESP_HOSTED_BT_ENABLED
+            bool "Enable Bluetooth"
+            default n
+
+            if ESP_HOSTED_BT_ENABLED
+                choice
+                    prompt "Select the stack type"
+                    default ESP_HOSTED_BT_NIMBLE_STACK
+
+                    config ESP_HOSTED_BT_NIMBLE_STACK
+                        bool "NimBLE"
+                endchoice
+            endif
+
         menu "Wi-Fi Configure"
 
             config SOC_WIFI_HE_SUPPORT

+ 3 - 0
esp-hosted/host/drivers/bt/hci_stub_drv.c

@@ -7,6 +7,9 @@
 static const char TAG[] = "hci_stub_drv";
 
 #if H_BT_HOST_ESP_NIMBLE
+#include <sysinit/sysinit.h>
+#include <syscfg/syscfg.h>
+#include "os/os_mbuf.h"
 #include "host/ble_hs_mbuf.h"
 #include "nimble/transport.h"
 #endif

+ 35 - 4
esp-hosted/host/drivers/bt/vhci_drv.c

@@ -10,33 +10,60 @@
 #include "hci_drv.h"
 
 #if H_BT_HOST_ESP_NIMBLE
+#include <sysinit/sysinit.h>
+#include <syscfg/syscfg.h>
 #include "host/ble_hs_mbuf.h"
 #include "os/os_mbuf.h"
 #include "nimble/transport.h"
 #include "nimble/transport/hci_h4.h"
-#include "nimble/hci_common.h"
 #endif
 
 #include "esp_hosted_log.h"
 static const char TAG[] = "vhci_drv";
 
+#if H_BT_HOST_ESP_NIMBLE
+struct hci_h4_sm hci_h4sm;
+
+static int hci_uart_frame_cb(uint8_t pkt_type, void *data)
+{
+    switch (pkt_type) {
+    case HCI_H4_EVT:
+        return ble_transport_to_hs_evt(data);
+    case HCI_H4_ACL:
+        return ble_transport_to_hs_acl(data);
+    default:
+        assert(0);
+        break;
+    }
+    return -1;
+}
+#endif /* H_BT_HOST_ESP_NIMBLE */
+
 /**
  * HCI_H4_xxx is the first byte of the received data
  */
 int hci_rx_handler(interface_buffer_handle_t *buf_handle)
 {
+#if H_BT_HOST_ESP_NIMBLE
+	hci_h4_sm_rx(&hci_h4sm, buf_handle->payload, buf_handle->payload_len);
+#endif /* H_BT_HOST_ESP_NIMBLE */
 	return ESP_OK;
 }
 
 void hci_drv_init(void)
 {
-	// do nothing for VHCI: underlying transport should be ready
+#if H_BT_HOST_ESP_NIMBLE
+	hci_h4_sm_init(&hci_h4sm, &hci_h4_allocs_from_ll, hci_uart_frame_cb);
+#endif /* H_BT_HOST_ESP_NIMBLE */
 }
 
 void hci_drv_show_configuration(void)
 {
+#if H_BT_HOST_ESP_NIMBLE
 	ESP_LOGI(TAG, "Host BT Support: Enabled");
 	ESP_LOGI(TAG, "\tBT Transport Type: VHCI");
+	ESP_LOGI(TAG, "\tBT Stack Type: NimBLE");
+#endif /* H_BT_HOST_ESP_NIMBLE */
 }
 
 #if H_BT_HOST_ESP_NIMBLE
@@ -69,7 +96,7 @@ int ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 	uint8_t * data = NULL;
 	int res;
 
-	data = MEM_ALLOC(data_len);
+	data = g_h.funcs->_h_malloc(data_len);
 	if (!data) {
 		ESP_LOGE(TAG, "Tx %s: malloc failed", __func__);
 		res = ESP_FAIL;
@@ -84,6 +111,8 @@ int ble_transport_to_ll_acl_impl(struct os_mbuf *om)
 		goto exit;
 	}
 
+	ESP_LOG_BUFFER_HEXDUMP(TAG, data, data_len, ESP_LOG_DEBUG);
+
 	res = esp_hosted_tx(ESP_HCI_IF, 0, data, data_len, H_BUFF_NO_ZEROCOPY, H_DEFLT_FREE_FUNC);
 
  exit:
@@ -102,7 +131,7 @@ int ble_transport_to_ll_cmd_impl(void *buf)
 	uint8_t * data = NULL;
 	int res;
 
-	data = MEM_ALLOC(buf_len);
+	data = g_h.funcs->_h_malloc(buf_len);
 	if (!data) {
 		ESP_LOGE(TAG, "Tx %s: malloc failed", __func__);
 		res =  ESP_FAIL;
@@ -112,6 +141,8 @@ int ble_transport_to_ll_cmd_impl(void *buf)
 	data[0] = HCI_H4_CMD;
 	memcpy(&data[1], buf, buf_len - 1);
 
+	ESP_LOG_BUFFER_HEXDUMP(TAG, data, buf_len, ESP_LOG_DEBUG);
+
 	res = esp_hosted_tx(ESP_HCI_IF, 0, data, buf_len, H_BUFF_NO_ZEROCOPY, H_DEFLT_FREE_FUNC);
 
  exit:

+ 7 - 0
porting/port/include/config_convert.h

@@ -75,4 +75,11 @@
 
 #define CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM      ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM
 
+/* BT Configuration */
+#ifdef ESP_HOSTED_BT_ENABLED
+#ifdef ESP_HOSTED_BT_NIMBLE_STACK
+#define CONFIG_BT_NIMBLE_ENABLED 1
+#endif
+#endif
+
 #endif /* __CONFIG_CONVERT_H__ */