Переглянути джерело

feat(ble): Add duplicate refersh function support for esp32h2

Geng Yuchao 2 роки тому
батько
коміт
0b2fde8a17

+ 16 - 0
components/bt/controller/esp32h2/Kconfig.in

@@ -458,3 +458,19 @@ config BT_LE_SCAN_DUPL_CACHE_SIZE
     help
         Maximum number of devices which can be recorded in scan duplicate filter.
         When the maximum amount of device in the filter is reached, the cache will be refreshed.
+
+config BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD
+    int "Duplicate scan list refresh period (seconds)"
+    depends on BT_LE_SCAN_DUPL
+    range 0 1000
+    default 0
+    help
+        If the period value is non-zero, the controller will periodically clear the device information
+        stored in the scan duuplicate filter. If it is 0, the scan duuplicate filter will not be cleared
+        until the scanning is disabled. Duplicate advertisements for this period should not be sent to the
+        Host in advertising report events.
+        There are two scenarios where the ADV packet will be repeatedly reported:
+        1. The duplicate scan cache is full, the controller will delete the oldest device information and
+        add new device information.
+        2. When the refresh period is up, the controller will clear all device information and start filtering
+        again.

+ 8 - 1
components/bt/controller/esp32h2/bt.c

@@ -598,6 +598,7 @@ typedef enum {
 extern void filter_duplicate_mode_enable(disc_duplicate_mode_t mode);
 extern void filter_duplicate_mode_disable(disc_duplicate_mode_t mode);
 extern void filter_duplicate_set_ring_list_max_num(uint32_t max_num);
+extern void scan_duplicate_cache_refresh_set_time(uint32_t period_time);
 
 int
 ble_vhci_disc_duplicate_mode_enable(int mode)
@@ -621,6 +622,11 @@ int ble_vhci_disc_duplicate_set_max_cache_size(int max_cache_size){
     return true;
 }
 
+int ble_vhci_disc_duplicate_set_period_refresh_time(int refresh_period_time){
+    // TODO: use vendor hci to update
+    scan_duplicate_cache_refresh_set_time(refresh_period_time);
+    return true;
+}
 
 /**
  * @brief Config scan duplicate option mode from menuconfig (Adapt to the old configuration method.)
@@ -642,6 +648,7 @@ void ble_controller_scan_duplicate_config()
     ble_vhci_disc_duplicate_mode_disable(0xFF);
     ble_vhci_disc_duplicate_mode_enable(duplicate_mode);
     ble_vhci_disc_duplicate_set_max_cache_size(cache_size);
+    ble_vhci_disc_duplicate_set_period_refresh_time(CONFIG_BT_LE_SCAN_DUPL_CACHE_REFRESH_PERIOD);
 }
 
 esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
@@ -730,7 +737,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
     }
 
     ble_controller_scan_duplicate_config();
-    
+
     ret = controller_sleep_init();
     if (ret != ESP_OK) {
         ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret);