diff --git a/device_hal/device/esp32h2_devkit_c/device.c b/device_hal/device/esp32h2_devkit_c/device.c new file mode 100644 index 000000000..5fa9e7cb8 --- /dev/null +++ b/device_hal/device/esp32h2_devkit_c/device.c @@ -0,0 +1,45 @@ +// Copyright 2021 Espressif Systems (Shanghai) CO LTD +// +// 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 + +#include +#include + +#define LED_GPIO_PIN 8 /* GPIO_NUM_8 */ +#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ + + +static const char *TAG = "device"; + +static esp_err_t device_light_init() +{ + light_driver_config_t config = { + .gpio = LED_GPIO_PIN, + .channel = LED_CHANNEL, + }; + return light_driver_init(&config); +} + +static esp_err_t device_button_init() +{ + return button_driver_init(NULL); +} + +esp_err_t device_init() +{ + ESP_LOGI(TAG, "Initializing device"); + device_light_init(); + device_button_init(); + return ESP_OK; +} diff --git a/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake b/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake new file mode 100644 index 000000000..8238dd37a --- /dev/null +++ b/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.5) +if (NOT ("${IDF_TARGET}" STREQUAL "esp32h2")) + message(FATAL_ERROR "please set esp32h2 as the IDF_TARGET using 'idf.py -- preview set-target esp32h2'") +endif() + +SET(device_hal_path $ENV{ESP_MATTER_DEVICE_PATH}/../../) +SET(device_name esp32h2_devkit_c) +SET(light_type ws2812) +SET(button_type hollow) +SET(used_driver light_driver button_driver) +SET(extra_components_dirs_append "${device_hal_path}/light_driver" + "${device_hal_path}/button_driver" + "$ENV{IDF_PATH}/examples/common_components/led_strip") diff --git a/examples/light/CMakeLists.txt b/examples/light/CMakeLists.txt index a457e2ff8..57a7e8366 100644 --- a/examples/light/CMakeLists.txt +++ b/examples/light/CMakeLists.txt @@ -10,6 +10,8 @@ if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH}) set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32_devkit_c) elseif("${IDF_TARGET}" STREQUAL "esp32c3") set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c3_devkit_m) + elseif("${IDF_TARGET}" STREQUAL "esp32h2") + set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32h2_devkit_c) else() message(FATAL_ERROR "Unsupported IDF_TARGT") endif() diff --git a/examples/light/main/CMakeLists.txt b/examples/light/main/CMakeLists.txt index 3b74c11a8..3ace58d5f 100644 --- a/examples/light/main/CMakeLists.txt +++ b/examples/light/main/CMakeLists.txt @@ -19,6 +19,10 @@ set(PRIV_INCLUDE_DIRS_LIST "${CMAKE_CURRENT_LIST_DIR}" set(PRIV_REQUIRES_LIST chip bt esp32_mbedtls app_driver) +if ("${IDF_TARGET}" STREQUAL "esp32h2") + list(APPEND PRIV_REQUIRES_LIST openthread mynewt_nimble) +endif() + idf_component_register(SRC_DIRS ${SRC_DIRS_LIST} PRIV_INCLUDE_DIRS ${PRIV_INCLUDE_DIRS_LIST} PRIV_REQUIRES ${PRIV_REQUIRES_LIST}) diff --git a/examples/light/main/app_matter.cpp b/examples/light/main/app_matter.cpp index c975aec85..596ae9a57 100644 --- a/examples/light/main/app_matter.cpp +++ b/examples/light/main/app_matter.cpp @@ -34,6 +34,9 @@ using chip::DeviceLayer::ChipDeviceEvent; using chip::DeviceLayer::ConnectivityMgr; using chip::DeviceLayer::DeviceEventType::PublicEventTypes; using chip::DeviceLayer::PlatformMgr; +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +using chip::DeviceLayer::ThreadStackMgr; +#endif static void on_on_off_attribute_changed(chip::EndpointId endpoint, chip::AttributeId attribute, uint8_t *value, size_t size) { @@ -82,6 +85,11 @@ static void on_device_event(const ChipDeviceEvent *event, intptr_t arg) if (event->Type == PublicEventTypes::kInterfaceIpAddressChanged) { chip::app::Mdns::StartServer(); } +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (event->Type == PublicEventTypes::kThreadStateChange) { + chip::app::Mdns::StartServer(); + } +#endif ESP_LOGI(APP_LOG_TAG, "Current free heap: %zu", heap_caps_get_free_size(MALLOC_CAP_8BIT)); } @@ -173,7 +181,17 @@ esp_err_t app_matter_init() return ESP_FAIL; } PlatformMgr().AddEventHandler(on_device_event, static_cast(NULL)); +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR) { + ESP_LOGE(APP_LOG_TAG, "Failed to initialize Thread stack"); + return ESP_FAIL; + } + if (ThreadStackMgr().StartThreadTask() != CHIP_NO_ERROR) { + ESP_LOGE(APP_LOG_TAG, "Failed to launch Thread task"); + return ESP_FAIL; + } +#endif InitServer(); app_driver_register_src(APP_DRIVER_SRC_MATTER, &callbacks); diff --git a/examples/light/partitions_h2.csv b/examples/light/partitions_h2.csv new file mode 100644 index 000000000..5fc6c06a9 --- /dev/null +++ b/examples/light/partitions_h2.csv @@ -0,0 +1,10 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table +sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition +nvs, data, nvs, 0x10000, 0x6000, +otadata, data, ota, , 0x2000 +phy_init, data, phy, , 0x1000, +ota_0, app, ota_0, 0x20000, 0x1E0000, +ota_1, app, ota_1, 0x200000, 0x1E0000, +fctry, data, nvs, 0x3E0000, 0x6000, +ot_storage,data, fat, , 0x6000, diff --git a/examples/light/sdkconfig.defaults.esp32h2 b/examples/light/sdkconfig.defaults.esp32h2 new file mode 100644 index 000000000..c763fa7a7 --- /dev/null +++ b/examples/light/sdkconfig.defaults.esp32h2 @@ -0,0 +1,62 @@ +CONFIG_IDF_TARGET="esp32h2" + +# Default to 921600 baud when flashing and monitoring device +CONFIG_ESPTOOLPY_BAUD_921600B=y +CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_COMPRESSED=y +CONFIG_ESPTOOLPY_FLASHFREQ_40M=y +CONFIG_ESPTOOLPY_FLASHFREQ="40m" +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + + +# Enable NIMBLE which is mynewt_nimble component out of bt component +# It will be merge to bt component soon +CONFIG_BT_ENABLED=n +CONFIG_NIMBLE_ENABLED=y +CONFIG_NEWTOS_ENABLE=n +CONFIG_BLE_50_FEATURE_SUPPORT=y +CONFIG_BLE_HCI_UART_BAUD=921600 +CONFIG_BLE_EXT_ADV=n + +# Enable OpenThread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_SRP_CLIENT=y + +# Disable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=n + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_h2.csv" + +# LwIP config for OpenThread +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_MULTICAST_PING=y + +# mbedTLS +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_HARDWARE_MPI=n +CONFIG_MBEDTLS_HARDWARE_SHA=n +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 + +# MDNS platform +CONFIG_USE_MINIMAL_MDNS=n + +# Disable Matter Shell +CONFIG_ENABLE_CHIP_SHELL=n + +# Increase stacks size +CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096 +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