diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index 63dff3ee1f5589..74b79dffc93466 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -31,7 +31,11 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake) -set(CHIP_REQURIE_COMPONENTS freertos lwip bt mdns mbedtls fatfs app_update console openthread) +set(CHIP_REQURIE_COMPONENTS freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash) + +if(NOT "${IDF_TARGET}" STREQUAL "esp32h2") + list(APPEND CHIP_REQURIE_COMPONENTS mdns) +endif() if (NOT CMAKE_BUILD_EARLY_EXPANSION) if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE) @@ -270,7 +274,9 @@ if(CONFIG_BT_ENABLED) idf_component_get_property(bt_lib bt COMPONENT_LIB) idf_component_get_property(bt_dir bt COMPONENT_DIR) list(APPEND chip_libraries $) - list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a) + if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2) + list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/beta2/libble_app.a) + endif() else() idf_component_get_property(bt_lib bt COMPONENT_LIB) list(APPEND chip_libraries $ -lbtdm_app) @@ -287,7 +293,7 @@ if(CONFIG_OPENTHREAD_ENABLED) list(APPEND chip_libraries $) endif() -if(NOT CONFIG_USE_MINIMAL_MDNS) +if(NOT CONFIG_USE_MINIMAL_MDNS AND NOT CONFIG_IDF_TARGET_ESP32H2) idf_component_get_property(mdns_lib mdns COMPONENT_LIB) list(APPEND chip_libraries $) endif() diff --git a/docs/guides/esp32/setup_idf_chip.md b/docs/guides/esp32/setup_idf_chip.md index acc001e67a6874..f6c7f649834fd7 100644 --- a/docs/guides/esp32/setup_idf_chip.md +++ b/docs/guides/esp32/setup_idf_chip.md @@ -39,13 +39,13 @@ step. $ ./install.sh ``` -- For ESP32H2, please checkout commit id - [10f3aba770](https://github.com/espressif/esp-idf/tree/10f3aba770), +- For ESP32H2, please checkout tag + [v5.0-beta1](https://github.com/espressif/esp-idf/tree/v5.0-beta1), currently only lighting-app is supported on H2 ``` $ cd esp-idf - $ git checkout 10f3aba770 + $ git checkout v5.0-beta1 $ git submodule update --init $ ./install.sh ``` diff --git a/examples/lighting-app/esp32/main/Button.cpp b/examples/lighting-app/esp32/main/Button.cpp index 73a3758818070f..aadae002bc2d08 100644 --- a/examples/lighting-app/esp32/main/Button.cpp +++ b/examples/lighting-app/esp32/main/Button.cpp @@ -1,4 +1,22 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Button.h" +#include "esp_attr.h" #define GPIO_INPUT_IO_0 9 #define GPIO_INPUT_PIN_SEL (1ULL << GPIO_INPUT_IO_0) diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index 097f5ba8c41357..233b25d29ada1f 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -65,7 +65,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server" - PRIV_REQUIRES chip QRCode bt led_strip app_update openthread) + PRIV_REQUIRES chip QRCode bt led_strip app_update openthread driver nvs_flash) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/lighting-app/esp32/main/LEDWidget.cpp b/examples/lighting-app/esp32/main/LEDWidget.cpp index 12cbf0f6d3295a..bf2221b26446c9 100644 --- a/examples/lighting-app/esp32/main/LEDWidget.cpp +++ b/examples/lighting-app/esp32/main/LEDWidget.cpp @@ -17,6 +17,7 @@ #include "LEDWidget.h" #include "ColorFormat.h" +#include "led_strip.h" static const char * TAG = "LEDWidget"; @@ -26,6 +27,14 @@ void LEDWidget::Init(void) mBrightness = UINT8_MAX; #if CONFIG_LED_TYPE_RMT +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_config_t strip_config = { + .strip_gpio_num = CONFIG_LED_GPIO, + .max_leds = 1, + }; + + led_strip_new_rmt_device(&strip_config, &mStrip); +#else rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t) CONFIG_LED_GPIO, (rmt_channel_t) CONFIG_LED_RMT_CHANNEL); led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); @@ -33,7 +42,8 @@ void LEDWidget::Init(void) rmt_config(&config); rmt_driver_install(config.channel, 0, 0); - mStrip = led_strip_new_rmt_ws2812(&strip_config); + mStrip = led_strip_new_rmt_ws2812(&strip_config); +#endif mHue = 0; mSaturation = 0; #else @@ -121,9 +131,13 @@ void LEDWidget::DoSet(void) { HsvColor_t hsv = { mHue, mSaturation, brightness }; RgbColor_t rgb = HsvToRgb(hsv); - +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); + led_strip_refresh(mStrip); +#else mStrip->set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); mStrip->refresh(mStrip, 100); +#endif } #else ESP_LOGI(TAG, "DoSet to GPIO number %d", mGPIONum); diff --git a/examples/lighting-app/esp32/main/include/LEDWidget.h b/examples/lighting-app/esp32/main/include/LEDWidget.h index c390d63ac1024f..f9d00a2b6882a9 100644 --- a/examples/lighting-app/esp32/main/include/LEDWidget.h +++ b/examples/lighting-app/esp32/main/include/LEDWidget.h @@ -50,7 +50,11 @@ class LEDWidget #if CONFIG_LED_TYPE_RMT uint8_t mHue; uint8_t mSaturation; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_handle_t mStrip; +#else led_strip_t * mStrip; +#endif #else gpio_num_t mGPIONum; #endif diff --git a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 index 3a6d8da8ff4033..dc637d31dc7a2e 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 +++ b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -16,14 +17,9 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # NIMBLE CONFIG_BT_ENABLED=y -CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # Enable OpenThread @@ -45,22 +41,19 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y CONFIG_MBEDTLS_SSL_PROTO_DTLS=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# rtc clk for ble +# CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y + # MDNS platform CONFIG_USE_MINIMAL_MDNS=n - -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 - -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y -CONFIG_ESP32H2_RTC_CLK_CAL_CYCLES=576 +CONFIG_ENABLE_EXTENDED_DISCOVERY=y # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -71,3 +64,6 @@ CONFIG_ENABLE_WIFI_AP=n # Enable OTA Requestor CONFIG_ENABLE_OTA_REQUESTOR=y + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp index e975dce62914f2..ba9eafc19c1397 100644 --- a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp +++ b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp @@ -20,7 +20,9 @@ #if CONFIG_BT_ENABLED #include "esp_bt.h" #if CONFIG_BT_NIMBLE_ENABLED +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "nimble/nimble_port.h" #endif // CONFIG_BT_NIMBLE_ENABLED #endif // CONFIG_BT_ENABLED @@ -45,6 +47,9 @@ using namespace chip::DeviceLayer; using namespace chip::System; DeviceCallbacksDelegate * appDelegate = nullptr; +#if CONFIG_ENABLE_OTA_REQUESTOR +static bool isOTAInitialized = false; +#endif void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) { @@ -62,17 +67,30 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i ESP_LOGI(TAG, "CHIPoBLE disconnected"); break; + case DeviceEventType::kThreadConnectivityChange: +#if CONFIG_ENABLE_OTA_REQUESTOR + if (event->ThreadConnectivityChange.Result == kConnectivity_Established && !isOTAInitialized) + { + OTAHelpers::Instance().InitOTARequestor(); + isOTAInitialized = true; + } +#endif + break; + case DeviceEventType::kCommissioningComplete: { ESP_LOGI(TAG, "Commissioning complete"); #if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE if (ble_hs_is_enabled()) { - int ret = nimble_port_stop(); + int ret = nimble_port_stop(); + esp_err_t err = ESP_OK; if (ret == 0) { nimble_port_deinit(); - esp_err_t err = esp_nimble_hci_and_controller_deinit(); +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + err = esp_nimble_hci_and_controller_deinit(); +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err += esp_bt_mem_release(ESP_BT_MODE_BLE); if (err == ESP_OK) { @@ -114,9 +132,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i void CommonDeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif appDelegate = DeviceCallbacksDelegate::Instance().GetAppDelegate(); if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { diff --git a/src/lib/shell/streamer_esp32.cpp b/src/lib/shell/streamer_esp32.cpp index c35abed55c5eb0..7d51afd7399cbe 100644 --- a/src/lib/shell/streamer_esp32.cpp +++ b/src/lib/shell/streamer_esp32.cpp @@ -62,7 +62,11 @@ int streamer_esp32_init(streamer_t * streamer) .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_APB, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .source_clk = UART_SCLK_DEFAULT, +#else + .source_clk = UART_SCLK_APB, +#endif }; ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config)); esp_vfs_dev_uart_use_driver(0); diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 0feaa568886f29..dcd133da55dbd2 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -352,8 +352,14 @@ CHIP_ERROR ESP32Config::ClearConfigValue(Key key) bool ESP32Config::ConfigValueExists(Key key) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + nvs_iterator_t iterator = NULL; + esp_err_t err = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY, &iterator); + for (; iterator && err == ESP_OK; err = nvs_entry_next(&iterator)) +#else nvs_iterator_t iterator = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY); for (; iterator; iterator = nvs_entry_next(iterator)) +#endif { nvs_entry_info_t info; nvs_entry_info(iterator, &info); diff --git a/src/platform/ESP32/OpenthreadLauncher.c b/src/platform/ESP32/OpenthreadLauncher.c index c9ef95fb5cb4de..c1ad467e032174 100644 --- a/src/platform/ESP32/OpenthreadLauncher.c +++ b/src/platform/ESP32/OpenthreadLauncher.c @@ -53,7 +53,7 @@ static void ot_task_worker(void * context) // Initialize the OpenThread stack ESP_ERROR_CHECK(esp_openthread_init(&config)); // The OpenThread log level directly matches ESP log level - (void) otLoggingSetLevel(OT_LOG_LEVEL_INFO); + (void) otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL); // Initialize the esp_netif bindings openthread_netif = init_openthread_netif(&config); diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index 2cf626c1751c50..b4459196fd9baa 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -40,7 +40,9 @@ #include #include "esp_log.h" +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif #include "host/ble_hs.h" #include "host/ble_hs_pvcy.h" #include "host/ble_uuid.h" @@ -152,7 +154,7 @@ CHIP_ERROR BLEManagerImpl::_Init() mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); mFlags.Set(Flags::kFastAdvertisingEnabled, true); mNumGAPCons = 0; - memset(mCons, 0, sizeof(mCons)); + memset(reinterpret_cast(mCons), 0, sizeof(mCons)); mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; memset(mDeviceName, 0, sizeof(mDeviceName)); @@ -613,9 +615,10 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void) { mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED; } - +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err = MapBLEError(esp_nimble_hci_and_controller_init()); SuccessOrExit(err); +#endif nimble_port_init();