From 878d3e6fb87e6a060253d9d287988b3165a88699 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 26 May 2022 23:07:03 +0800 Subject: [PATCH 1/2] ci: fix ci and add esp32h2 build --- .gitlab-ci.yml | 15 ++++++++++++--- .gitmodules | 2 +- examples/switch/sdkconfig.defaults.esp32h2 | 14 +++++++++----- examples/zap_light/sdkconfig.defaults.esp32h2 | 15 +++++++++------ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4448db806..1be7c32ac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,10 +78,19 @@ variables: - idf.py build - cp sdkconfig.defaults.backup sdkconfig.defaults -.build_bridge_zigbee_app: &build_bridge_zigbee_app - - cd $ESP_MATTER_PATH/examples/bridge_zigbee +.build_examples_idf_v5_0: &build_examples_idf_v5_0 # pyparsing in python_env created by matter is version 2.4.0 IDF v5.0 requires 3.0.8 - pip install pyparsing==3.0.8 + - cd $ESP_MATTER_PATH/examples/zap_light + - idf.py --preview set-target esp32h2 + - idf.py build + - cd $ESP_MATTER_PATH/examples/switch + - idf.py --preview set-target esp32h2 + - idf.py build + - cd $ESP_MATTER_PATH/examples/light + - idf.py --preview set-target esp32h2 + - idf.py build + - cd $ESP_MATTER_PATH/examples/bridge_zigbee - idf.py set-target esp32 - idf.py build @@ -114,7 +123,7 @@ build_esp_matter_examples_idf_v5_0: - *chip_submodule_update - *setup_idf_v5_0 - *setup_matter - - *build_bridge_zigbee_app + - *build_examples_idf_v5_0 build_upstream_examples: stage: build diff --git a/.gitmodules b/.gitmodules index 8ae0c1616..908740f27 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "connectedhomeip"] +[submodule "connectedhomeip/connectedhomeip"] path = connectedhomeip/connectedhomeip url = https://github.com/espressif/connectedhomeip.git diff --git a/examples/switch/sdkconfig.defaults.esp32h2 b/examples/switch/sdkconfig.defaults.esp32h2 index fb483329a..b94164d2f 100644 --- a/examples/switch/sdkconfig.defaults.esp32h2 +++ b/examples/switch/sdkconfig.defaults.esp32h2 @@ -17,11 +17,15 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # It will be merge to bt component soon CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_NEWTOS_ENABLE=n -CONFIG_BLE_50_FEATURE_SUPPORT=y -CONFIG_BLE_HCI_UART_BAUD=921600 -CONFIG_BLE_EXT_ADV=n -CONFIG_BLE_LOG_LEVEL=1 +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 + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y # Enable OpenThread CONFIG_OPENTHREAD_ENABLED=y diff --git a/examples/zap_light/sdkconfig.defaults.esp32h2 b/examples/zap_light/sdkconfig.defaults.esp32h2 index ccc23de7a..afc0fdcc8 100644 --- a/examples/zap_light/sdkconfig.defaults.esp32h2 +++ b/examples/zap_light/sdkconfig.defaults.esp32h2 @@ -17,11 +17,15 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # It will be merge to bt component soon CONFIG_BT_ENABLED=y CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_NEWTOS_ENABLE=n -CONFIG_BLE_50_FEATURE_SUPPORT=y -CONFIG_BLE_HCI_UART_BAUD=921600 -CONFIG_BLE_EXT_ADV=n -CONFIG_BLE_LOG_LEVEL=1 +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 + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y # Enable OpenThread CONFIG_OPENTHREAD_ENABLED=y @@ -52,7 +56,6 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y CONFIG_USE_MINIMAL_MDNS=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 From a0bc65f2797852ff0cb968a14bf2712eb2fef0c9 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Thu, 26 May 2022 23:02:21 +0800 Subject: [PATCH 2/2] hollow_button: use hollow_button for esp32h2 --- .../button_driver/{ => button}/CMakeLists.txt | 4 +- .../hollow_button/button_driver.c | 0 .../button_driver/button/include/button_adc.h | 79 +++++++++++ .../button/include/button_gpio.h | 65 +++++++++ .../button_driver/button/include/iot_button.h | 131 ++++++++++++++++++ .../button_driver/iot_button/CMakeLists.txt | 7 + .../button_driver/{ => iot_button}/README.md | 0 .../{ => iot_button}/idf_component.yml | 0 device_hal/device/CMakeLists.txt | 11 +- .../esp32_devkit_c/esp_matter_device.cmake | 4 +- .../esp32c3_devkit_m/esp_matter_device.cmake | 4 +- .../esp32h2_devkit_c/esp_matter_device.cmake | 4 +- .../esp32s2_devkit_c/esp_matter_device.cmake | 4 +- .../esp32s3_devkit_c/esp_matter_device.cmake | 4 +- .../device/m5stack/esp_matter_device.cmake | 4 +- 15 files changed, 306 insertions(+), 15 deletions(-) rename device_hal/button_driver/{ => button}/CMakeLists.txt (80%) rename device_hal/button_driver/{ => button}/hollow_button/button_driver.c (100%) create mode 100644 device_hal/button_driver/button/include/button_adc.h create mode 100644 device_hal/button_driver/button/include/button_gpio.h create mode 100644 device_hal/button_driver/button/include/iot_button.h create mode 100644 device_hal/button_driver/iot_button/CMakeLists.txt rename device_hal/button_driver/{ => iot_button}/README.md (100%) rename device_hal/button_driver/{ => iot_button}/idf_component.yml (100%) diff --git a/device_hal/button_driver/CMakeLists.txt b/device_hal/button_driver/button/CMakeLists.txt similarity index 80% rename from device_hal/button_driver/CMakeLists.txt rename to device_hal/button_driver/button/CMakeLists.txt index d12d588ea..a856f57ff 100644 --- a/device_hal/button_driver/CMakeLists.txt +++ b/device_hal/button_driver/button/CMakeLists.txt @@ -1,12 +1,12 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(src_dirs ) -set(requires driver button) +set(requires driver) if ("${button_type}" STREQUAL "hollow_button") list(APPEND src_dirs hollow_button) endif() idf_component_register(SRC_DIRS ${src_dirs} - INCLUDE_DIRS + INCLUDE_DIRS include REQUIRES ${requires}) diff --git a/device_hal/button_driver/hollow_button/button_driver.c b/device_hal/button_driver/button/hollow_button/button_driver.c similarity index 100% rename from device_hal/button_driver/hollow_button/button_driver.c rename to device_hal/button_driver/button/hollow_button/button_driver.c diff --git a/device_hal/button_driver/button/include/button_adc.h b/device_hal/button_driver/button/include/button_adc.h new file mode 100644 index 000000000..f1b004106 --- /dev/null +++ b/device_hal/button_driver/button/include/button_adc.h @@ -0,0 +1,79 @@ +// Copyright 2020 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. +#ifndef _IOT_BUTTON_ADC_H_ +#define _IOT_BUTTON_ADC_H_ + +#include "driver/gpio.h" +#include "driver/adc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ADC_BUTTON_COMBINE(channel, index) ((channel)<<8 | (index)) +#define ADC_BUTTON_SPLIT_INDEX(data) ((uint32_t)(data)&0xff) +#define ADC_BUTTON_SPLIT_CHANNEL(data) (((uint32_t)(data) >> 8) & 0xff) + +/** + * @brief adc button configuration + * + */ +typedef struct { + adc1_channel_t adc_channel; /**< Channel of ADC */ + uint8_t button_index; /**< button index on the channel */ + uint16_t min; /**< min voltage in mv corresponding to the button */ + uint16_t max; /**< max voltage in mv corresponding to the button */ +} button_adc_config_t; + +/** + * @brief Initialize gpio button + * + * @param config pointer of configuration struct + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG Arguments is NULL. + * - ESP_ERR_NOT_SUPPORTED Arguments out of range. + * - ESP_ERR_INVALID_STATE State is error. + */ +esp_err_t button_adc_init(const button_adc_config_t *config); + +/** + * @brief Deinitialize gpio button + * + * @param channel ADC channel + * @param button_index Button index on the channel + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG Arguments is invalid. + */ +esp_err_t button_adc_deinit(adc1_channel_t channel, int button_index); + +/** + * @brief Get the adc button level + * + * @param button_index It is compressed by ADC channel and button index, use the macro ADC_BUTTON_COMBINE to generate. It will be treated as a uint32_t variable. + * + * @return + * - 0 Not pressed + * - 1 Pressed + */ +uint8_t button_adc_get_key_level(void *button_index); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/device_hal/button_driver/button/include/button_gpio.h b/device_hal/button_driver/button/include/button_gpio.h new file mode 100644 index 000000000..78bb98564 --- /dev/null +++ b/device_hal/button_driver/button/include/button_gpio.h @@ -0,0 +1,65 @@ +// Copyright 2020 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. +#ifndef _IOT_BUTTON_GPIO_H_ +#define _IOT_BUTTON_GPIO_H_ + +#include "driver/gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief gpio button configuration + * + */ +typedef struct { + int32_t gpio_num; + uint8_t active_level; +} button_gpio_config_t; + +/** + * @brief Initialize gpio button + * + * @param config pointer of configuration struct + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG Arguments is NULL. + */ +esp_err_t button_gpio_init(const button_gpio_config_t *config); + +/** + * @brief Deinitialize gpio button + * + * @param gpio_num gpio number of button + * + * @return Always return ESP_OK + */ +esp_err_t button_gpio_deinit(int gpio_num); + +/** + * @brief Get current level on button gpio + * + * @param gpio_num gpio number of button, it will be treated as a uint32_t variable. + * + * @return Level on gpio + */ +uint8_t button_gpio_get_key_level(void *gpio_num); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/device_hal/button_driver/button/include/iot_button.h b/device_hal/button_driver/button/include/iot_button.h new file mode 100644 index 000000000..7c68e4a0f --- /dev/null +++ b/device_hal/button_driver/button/include/iot_button.h @@ -0,0 +1,131 @@ +// Copyright 2020 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. +#ifndef _IOT_BUTTON_H_ +#define _IOT_BUTTON_H_ + +#include "button_adc.h" +#include "button_gpio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (* button_cb_t)(void *); +typedef void *button_handle_t; + +/** + * @brief Button events + * + */ +typedef enum { + BUTTON_PRESS_DOWN = 0, + BUTTON_PRESS_UP, + BUTTON_PRESS_REPEAT, + BUTTON_SINGLE_CLICK, + BUTTON_DOUBLE_CLICK, + BUTTON_LONG_PRESS_START, + BUTTON_LONG_PRESS_HOLD, + BUTTON_EVENT_MAX, + BUTTON_NONE_PRESS, +} button_event_t; + +/** + * @brief Supported button type + * + */ +typedef enum { + BUTTON_TYPE_GPIO, + BUTTON_TYPE_ADC, +} button_type_t; + +/** + * @brief Button configuration + * + */ +typedef struct { + button_type_t type; /**< button type, The corresponding button configuration must be filled */ + union { + button_gpio_config_t gpio_button_config; /**< gpio button configuration */ + button_adc_config_t adc_button_config; /**< adc button configuration */ + }; /**< button configuration */ +} button_config_t; + +/** + * @brief Create a button + * + * @param config pointer of button configuration, must corresponding the button type + * + * @return A handle to the created button, or NULL in case of error. + */ +button_handle_t iot_button_create(const button_config_t *config); + +/** + * @brief Delete a button + * + * @param btn_handle A button handle to delete + * + * @return + * - ESP_OK Success + * - ESP_FAIL Failure + */ +esp_err_t iot_button_delete(button_handle_t btn_handle); + +/** + * @brief Register the button event callback function. + * + * @param btn_handle A button handle to register + * @param event Button event + * @param cb Callback function. + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG Arguments is invalid. + */ +esp_err_t iot_button_register_cb(button_handle_t btn_handle, button_event_t event, button_cb_t cb); + +/** + * @brief Unregister the button event callback function. + * + * @param btn_handle A button handle to unregister + * @param event Button event + * + * @return + * - ESP_OK on success + * - ESP_ERR_INVALID_ARG Arguments is invalid. + */ +esp_err_t iot_button_unregister_cb(button_handle_t btn_handle, button_event_t event); + +/** + * @brief Get button event + * + * @param btn_handle Button handle + * + * @return Current button event. See button_event_t + */ +button_event_t iot_button_get_event(button_handle_t btn_handle); + +/** + * @brief Get button repeat times + * + * @param btn_handle Button handle + * + * @return button pressed times. For example, double-click return 2, triple-click return 3, etc. + */ +uint8_t iot_button_get_repeat(button_handle_t btn_handle); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/device_hal/button_driver/iot_button/CMakeLists.txt b/device_hal/button_driver/iot_button/CMakeLists.txt new file mode 100644 index 000000000..1a5ad6f09 --- /dev/null +++ b/device_hal/button_driver/iot_button/CMakeLists.txt @@ -0,0 +1,7 @@ +include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) + +set(requires driver button) + +idf_component_register(SRC_DIRS + INCLUDE_DIRS + REQUIRES ${requires}) diff --git a/device_hal/button_driver/README.md b/device_hal/button_driver/iot_button/README.md similarity index 100% rename from device_hal/button_driver/README.md rename to device_hal/button_driver/iot_button/README.md diff --git a/device_hal/button_driver/idf_component.yml b/device_hal/button_driver/iot_button/idf_component.yml similarity index 100% rename from device_hal/button_driver/idf_component.yml rename to device_hal/button_driver/iot_button/idf_component.yml diff --git a/device_hal/device/CMakeLists.txt b/device_hal/device/CMakeLists.txt index 73fa61b90..0b92f9ae7 100644 --- a/device_hal/device/CMakeLists.txt +++ b/device_hal/device/CMakeLists.txt @@ -1,4 +1,13 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) + +set(requires led_driver) + +if ("${button_type}" STREQUAL "iot") + list(APPEND requires iot_button) +else() + list(APPEND requires button) +endif() + idf_component_register(SRC_DIRS "${device_type}" INCLUDE_DIRS include - REQUIRES button_driver led_driver) + REQUIRES "${requires}") diff --git a/device_hal/device/esp32_devkit_c/esp_matter_device.cmake b/device_hal/device/esp32_devkit_c/esp_matter_device.cmake index 965caec49..a8fb06702 100644 --- a/device_hal/device/esp32_devkit_c/esp_matter_device.cmake +++ b/device_hal/device/esp32_devkit_c/esp_matter_device.cmake @@ -5,7 +5,7 @@ endif() SET(device_type esp32_devkit_c) SET(led_type gpio) -SET(button_type gpio) +SET(button_type iot) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver") + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/iot_button") diff --git a/device_hal/device/esp32c3_devkit_m/esp_matter_device.cmake b/device_hal/device/esp32c3_devkit_m/esp_matter_device.cmake index 6daf4dc01..c18540baa 100644 --- a/device_hal/device/esp32c3_devkit_m/esp_matter_device.cmake +++ b/device_hal/device/esp32c3_devkit_m/esp_matter_device.cmake @@ -5,8 +5,8 @@ endif() SET(device_type esp32c3_devkit_m) SET(led_type ws2812) -SET(button_type gpio) +SET(button_type iot) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/iot_button" "$ENV{IDF_PATH}/examples/common_components/led_strip") diff --git a/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake b/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake index bad15f157..b7c753832 100644 --- a/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake +++ b/device_hal/device/esp32h2_devkit_c/esp_matter_device.cmake @@ -5,8 +5,8 @@ endif() SET(device_type esp32h2_devkit_c) SET(led_type ws2812) -SET(button_type gpio) +SET(button_type hollow_button) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/button" "$ENV{IDF_PATH}/examples/common_components/led_strip") diff --git a/device_hal/device/esp32s2_devkit_c/esp_matter_device.cmake b/device_hal/device/esp32s2_devkit_c/esp_matter_device.cmake index 3109d21af..b35c0a420 100644 --- a/device_hal/device/esp32s2_devkit_c/esp_matter_device.cmake +++ b/device_hal/device/esp32s2_devkit_c/esp_matter_device.cmake @@ -5,7 +5,7 @@ endif() SET(device_type esp32s2_devkit_c) SET(led_type hollow_led) -SET(button_type gpio) +SET(button_type iot) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver") + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/iot_button") diff --git a/device_hal/device/esp32s3_devkit_c/esp_matter_device.cmake b/device_hal/device/esp32s3_devkit_c/esp_matter_device.cmake index bc446e068..e6e2368d3 100644 --- a/device_hal/device/esp32s3_devkit_c/esp_matter_device.cmake +++ b/device_hal/device/esp32s3_devkit_c/esp_matter_device.cmake @@ -5,8 +5,8 @@ endif() SET(device_type esp32s3_devkit_c) SET(led_type ws2812) -SET(button_type gpio) +SET(button_type iot) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/iot_button" "$ENV{IDF_PATH}/examples/common_components/led_strip") diff --git a/device_hal/device/m5stack/esp_matter_device.cmake b/device_hal/device/m5stack/esp_matter_device.cmake index 1f9023b6c..c2b076daf 100644 --- a/device_hal/device/m5stack/esp_matter_device.cmake +++ b/device_hal/device/m5stack/esp_matter_device.cmake @@ -5,9 +5,9 @@ endif() SET(device_type m5stack) SET(led_type vled) -SET(button_type gpio) +SET(button_type iot) SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" - "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/iot_button" "$ENV{ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/examples/common/m5stack-tft/repo/components/tft/" "$ENV{ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/examples/common/m5stack-tft/repo/components/spidriver/")