mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 10:40:47 +03:00
feat(zigbee): upgrade zigbee example to v2.0
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRC_DIRS "src"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES esp_timer
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
menu "Zigbee Example Configuration"
|
||||
|
||||
config ZB_EXAMPLE_PRIMARY_CHANNEL
|
||||
int "Zigbee primary channel"
|
||||
range 11 26
|
||||
default 13
|
||||
|
||||
config ZB_EXAMPLE_SECONDARY_CHANNEL_MASK
|
||||
hex "Zigbee secondary channel mask"
|
||||
default 0x07FFF800
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Alarm driver
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, this
|
||||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The argument type for the alarm callback.
|
||||
*
|
||||
*/
|
||||
typedef uintptr_t alarm_timer_arg_t;
|
||||
|
||||
/**
|
||||
* @brief The callback for the timer.
|
||||
*
|
||||
*/
|
||||
typedef void (*alarm_timer_callback_t)(alarm_timer_arg_t arg);
|
||||
|
||||
/**
|
||||
* @brief Schedule an alarm to fire at a given time.
|
||||
*
|
||||
* @param cb The callback to execute when the alarm fires.
|
||||
* @param arg The argument to pass to the callback.
|
||||
* @param time_ms The time to fire the timer in milliseconds.
|
||||
*
|
||||
* @return ESP_OK on success, error code otherwise.
|
||||
*/
|
||||
esp_err_t alarm_timer_schedule(alarm_timer_callback_t cb, alarm_timer_arg_t arg, uint32_t time_ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
# This config file optimizes the mbedTLS code size by disabling
|
||||
# unused features by ESP-Zigbee-SDK.
|
||||
|
||||
#
|
||||
# mbedTLS
|
||||
#
|
||||
|
||||
# Enable required
|
||||
CONFIG_MBEDTLS_AES_C=y
|
||||
CONFIG_MBEDTLS_CCM_C=y
|
||||
|
||||
# Disable unused
|
||||
CONFIG_MBEDTLS_GCM_C=n
|
||||
CONFIG_MBEDTLS_CMAC_C=n
|
||||
CONFIG_MBEDTLS_SHA1_C=n
|
||||
CONFIG_MBEDTLS_SHA3_C=n
|
||||
CONFIG_MBEDTLS_SHA512_C=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=n
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK=n
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=n
|
||||
|
||||
## v5.0
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=n
|
||||
CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=n
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=n
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=n
|
||||
|
||||
## v6.0
|
||||
CONFIG_MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH=y
|
||||
CONFIG_MBEDTLS_CTR_DRBG_C=y
|
||||
CONFIG_MBEDTLS_HMAC_DRBG_C=n
|
||||
CONFIG_MBEDTLS_X509_RSASSA_PSS_SUPPORT=n
|
||||
CONFIG_MBEDTLS_CIPHER_MODE_CBC=n
|
||||
CONFIG_MBEDTLS_CIPHER_MODE_CFB=n
|
||||
CONFIG_MBEDTLS_CIPHER_MODE_CTR=n
|
||||
CONFIG_MBEDTLS_CIPHER_MODE_OFB=n
|
||||
CONFIG_MBEDTLS_CIPHER_MODE_XTS=n
|
||||
# PSA_WANT_ALG_RSA_PSS needs CONFIG_MBEDTLS_RSA_C=y on ESP-IDF master
|
||||
CONFIG_MBEDTLS_RSA_C=y
|
||||
CONFIG_MBEDTLS_MD5_C=n
|
||||
CONFIG_MBEDTLS_SHA384_C=n
|
||||
|
||||
# end of mbedTLS
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: LicenseRef-Included
|
||||
*
|
||||
* Alarm Timer
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, this
|
||||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
#include "alarm_timer.h"
|
||||
|
||||
typedef struct alarm_timer_s {
|
||||
esp_timer_handle_t timer;
|
||||
alarm_timer_callback_t cb;
|
||||
alarm_timer_arg_t arg;
|
||||
} alarm_timer_t;
|
||||
|
||||
static void alarm_timer_cb(void *arg)
|
||||
{
|
||||
alarm_timer_t *alarm = (alarm_timer_t *)arg;
|
||||
|
||||
esp_timer_delete(alarm->timer);
|
||||
alarm->cb(alarm->arg);
|
||||
free(alarm);
|
||||
}
|
||||
|
||||
esp_err_t alarm_timer_schedule(alarm_timer_callback_t cb, alarm_timer_arg_t arg, uint32_t time_ms)
|
||||
{
|
||||
if (cb == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
alarm_timer_t *alarm = malloc(sizeof(alarm_timer_t));
|
||||
if (alarm == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
alarm->cb = cb;
|
||||
alarm->arg = arg;
|
||||
alarm->timer = NULL;
|
||||
|
||||
esp_timer_create_args_t timer_args = {
|
||||
.callback = alarm_timer_cb,
|
||||
.arg = alarm,
|
||||
};
|
||||
|
||||
esp_err_t err = esp_timer_create(&timer_args, &alarm->timer);
|
||||
if (err != ESP_OK) {
|
||||
free(alarm);
|
||||
return err;
|
||||
}
|
||||
|
||||
uint64_t time_us = (uint64_t)time_ms * 1000;
|
||||
err = esp_timer_start_once(alarm->timer, time_us);
|
||||
if (err != ESP_OK) {
|
||||
esp_timer_delete(alarm->timer);
|
||||
free(alarm);
|
||||
return err;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user