From 2ee9140e941fb102830bb023a939a8b4c9b5eace Mon Sep 17 00:00:00 2001 From: zwj Date: Thu, 6 May 2021 15:47:26 +0800 Subject: [PATCH] hid examples support esp32c3/s3 --- .../esp_hid_device/main/esp_hid_device_main.c | 5 +++++ .../esp_hid_device/main/esp_hid_gap.c | 18 +++++++++++++++--- .../esp_hid_device/sdkconfig.defaults.esp32c3 | 14 ++++++++++++++ .../esp_hid_device/sdkconfig.defaults.esp32s3 | 14 ++++++++++++++ .../bluetooth/esp_hid_host/main/esp_hid_gap.c | 18 ++++++++++++++---- .../esp_hid_host/main/esp_hid_host_main.c | 4 ++++ .../esp_hid_host/sdkconfig.defaults.esp32c3 | 14 ++++++++++++++ .../esp_hid_host/sdkconfig.defaults.esp32s3 | 14 ++++++++++++++ 8 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32c3 create mode 100644 examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32s3 create mode 100644 examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32c3 create mode 100644 examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32s3 diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c index 014849a216..d9a84119a6 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c @@ -368,7 +368,12 @@ void app_main(void) } ESP_ERROR_CHECK( ret ); +#if CONFIG_BT_CLASSIC_ENABLED ret = esp_hid_gap_init(ESP_BT_MODE_BTDM); +#else + ret = esp_hid_gap_init(ESP_BT_MODE_BLE); +#endif + ESP_ERROR_CHECK( ret ); ret = esp_hid_ble_gap_adv_init(ESP_HID_APPEARANCE_GENERIC, hid_config.device_name); diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c index 2c3ff904d5..a75f6a1fea 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c @@ -135,6 +135,7 @@ static esp_hid_scan_result_t *find_scan_result(esp_bd_addr_t bda, esp_hid_scan_r return NULL; } +#if CONFIG_BT_CLASSIC_ENABLED static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid_t *uuid, uint8_t *name, uint8_t name_len, int rssi) { esp_hid_scan_result_t *r = find_scan_result(bda, bt_scan_results); @@ -186,6 +187,7 @@ static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid bt_scan_results = r; num_bt_scan_results++; } +#endif static void add_ble_scan_result(esp_bd_addr_t bda, esp_ble_addr_type_t addr_type, uint16_t appearance, uint8_t *name, uint8_t name_len, int rssi) { @@ -237,6 +239,7 @@ void print_uuid(esp_bt_uuid_t *uuid) } } +#if CONFIG_BT_CLASSIC_ENABLED static void handle_bt_device_result(struct disc_res_param *disc_res) { GAP_DBG_PRINTF("BT : " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(disc_res->bda)); @@ -325,6 +328,7 @@ static void handle_bt_device_result(struct disc_res_param *disc_res) add_bt_scan_result(disc_res->bda, cod, &uuid, name, name_len, rssi); } } +#endif static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst) { @@ -372,7 +376,7 @@ static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst) } } - +#if CONFIG_BT_CLASSIC_ENABLED /* * BT GAP * */ @@ -440,6 +444,7 @@ static esp_err_t start_bt_scan(uint32_t seconds) } return ret; } +#endif /* * BLE GAP @@ -671,11 +676,15 @@ static esp_err_t init_low_level(uint8_t mode) { esp_err_t ret; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); +#if CONFIG_BT_CLASSIC_ENABLED if (mode & ESP_BT_MODE_CLASSIC_BT) { bt_cfg.mode = mode; bt_cfg.bt_max_acl_conn = 3; bt_cfg.bt_max_sync_conn = 3; - } else { + } else +#endif + { + ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); if (ret) { ESP_LOGE(TAG, "esp_bt_controller_mem_release failed: %d", ret); @@ -705,13 +714,14 @@ static esp_err_t init_low_level(uint8_t mode) ESP_LOGE(TAG, "esp_bluedroid_enable failed: %d", ret); return ret; } - +#if CONFIG_BT_CLASSIC_ENABLED if (mode & ESP_BT_MODE_CLASSIC_BT) { ret = init_bt_gap(); if (ret) { return ret; } } +#endif if (mode & ESP_BT_MODE_BLE) { ret = init_ble_gap(); @@ -772,9 +782,11 @@ esp_err_t esp_hid_scan(uint32_t seconds, size_t *num_results, esp_hid_scan_resul } if (start_ble_scan(seconds) == ESP_OK) { +#if CONFIG_BT_CLASSIC_ENABLED if (start_bt_scan(seconds) == ESP_OK) { WAIT_BT_CB(); } +#endif WAIT_BLE_CB(); } else { return ESP_FAIL; diff --git a/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32c3 b/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32c3 new file mode 100644 index 0000000000..7a475bc657 --- /dev/null +++ b/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32c3 @@ -0,0 +1,14 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET_ARCH_RISCV=y +CONFIG_IDF_TARGET="esp32c3" +CONFIG_IDF_TARGET_ESP32C3=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0005 + +# +# Bluetooth +# +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y diff --git a/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32s3 b/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000000..7a475bc657 --- /dev/null +++ b/examples/bluetooth/esp_hid_device/sdkconfig.defaults.esp32s3 @@ -0,0 +1,14 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET_ARCH_RISCV=y +CONFIG_IDF_TARGET="esp32c3" +CONFIG_IDF_TARGET_ESP32C3=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0005 + +# +# Bluetooth +# +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c index 2c3ff904d5..2d61e75a3e 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c @@ -135,6 +135,7 @@ static esp_hid_scan_result_t *find_scan_result(esp_bd_addr_t bda, esp_hid_scan_r return NULL; } +#if CONFIG_BT_CLASSIC_ENABLED static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid_t *uuid, uint8_t *name, uint8_t name_len, int rssi) { esp_hid_scan_result_t *r = find_scan_result(bda, bt_scan_results); @@ -186,6 +187,7 @@ static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid bt_scan_results = r; num_bt_scan_results++; } +#endif static void add_ble_scan_result(esp_bd_addr_t bda, esp_ble_addr_type_t addr_type, uint16_t appearance, uint8_t *name, uint8_t name_len, int rssi) { @@ -237,6 +239,7 @@ void print_uuid(esp_bt_uuid_t *uuid) } } +#if CONFIG_BT_CLASSIC_ENABLED static void handle_bt_device_result(struct disc_res_param *disc_res) { GAP_DBG_PRINTF("BT : " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(disc_res->bda)); @@ -325,6 +328,7 @@ static void handle_bt_device_result(struct disc_res_param *disc_res) add_bt_scan_result(disc_res->bda, cod, &uuid, name, name_len, rssi); } } +#endif static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst) { @@ -372,7 +376,7 @@ static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst) } } - +#if CONFIG_BT_CLASSIC_ENABLED /* * BT GAP * */ @@ -440,6 +444,7 @@ static esp_err_t start_bt_scan(uint32_t seconds) } return ret; } +#endif /* * BLE GAP @@ -671,11 +676,14 @@ static esp_err_t init_low_level(uint8_t mode) { esp_err_t ret; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); +#if CONFIG_BT_CLASSIC_ENABLED if (mode & ESP_BT_MODE_CLASSIC_BT) { bt_cfg.mode = mode; bt_cfg.bt_max_acl_conn = 3; bt_cfg.bt_max_sync_conn = 3; - } else { + } else +#endif + { ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); if (ret) { ESP_LOGE(TAG, "esp_bt_controller_mem_release failed: %d", ret); @@ -705,14 +713,14 @@ static esp_err_t init_low_level(uint8_t mode) ESP_LOGE(TAG, "esp_bluedroid_enable failed: %d", ret); return ret; } - +#if CONFIG_BT_CLASSIC_ENABLED if (mode & ESP_BT_MODE_CLASSIC_BT) { ret = init_bt_gap(); if (ret) { return ret; } } - +#endif if (mode & ESP_BT_MODE_BLE) { ret = init_ble_gap(); if (ret) { @@ -772,9 +780,11 @@ esp_err_t esp_hid_scan(uint32_t seconds, size_t *num_results, esp_hid_scan_resul } if (start_ble_scan(seconds) == ESP_OK) { +#if CONFIG_BT_CLASSIC_ENABLED if (start_bt_scan(seconds) == ESP_OK) { WAIT_BT_CB(); } +#endif WAIT_BLE_CB(); } else { return ESP_FAIL; diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c index 49f93f2e44..a6a3663d2a 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c @@ -123,7 +123,11 @@ void app_main(void) ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret ); +#if CONFIG_BT_CLASSIC_ENABLED ESP_ERROR_CHECK( esp_hid_gap_init(ESP_BT_MODE_BTDM) ); +#else + ESP_ERROR_CHECK( esp_hid_gap_init(ESP_BT_MODE_BLE) ); +#endif ESP_ERROR_CHECK( esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler) ); esp_hidh_config_t config = { .callback = hidh_callback, diff --git a/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32c3 b/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32c3 new file mode 100644 index 0000000000..7a475bc657 --- /dev/null +++ b/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32c3 @@ -0,0 +1,14 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET_ARCH_RISCV=y +CONFIG_IDF_TARGET="esp32c3" +CONFIG_IDF_TARGET_ESP32C3=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0005 + +# +# Bluetooth +# +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y diff --git a/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32s3 b/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32s3 new file mode 100644 index 0000000000..7a475bc657 --- /dev/null +++ b/examples/bluetooth/esp_hid_host/sdkconfig.defaults.esp32s3 @@ -0,0 +1,14 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET_ARCH_RISCV=y +CONFIG_IDF_TARGET="esp32c3" +CONFIG_IDF_TARGET_ESP32C3=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0005 + +# +# Bluetooth +# +CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y