From e08024814165a4ce2219b71206f21dadb63c876e Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 22 Jun 2022 16:36:35 +0800 Subject: [PATCH] sdm: deprecate legacy driver --- components/driver/CMakeLists.txt | 4 +- .../driver/sigmadelta.h | 16 ++---- .../driver/sigmadelta_types_legacy.h | 54 +++++++++++++++++++ .../sigma_delta_legacy.c} | 18 ++++--- .../driver/test_apps/gpio/main/CMakeLists.txt | 4 +- ...sigmadelta.c => test_sigma_delta_legacy.c} | 4 +- .../driver/test_apps/gpio/sdkconfig.defaults | 1 + 7 files changed, 77 insertions(+), 24 deletions(-) rename components/driver/{include => deprecated}/driver/sigmadelta.h (82%) create mode 100644 components/driver/deprecated/driver/sigmadelta_types_legacy.h rename components/driver/{gpio/sigmadelta_gpio.c => deprecated/sigma_delta_legacy.c} (88%) rename components/driver/test_apps/gpio/main/{test_sigmadelta.c => test_sigma_delta_legacy.c} (94%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 60e70f9cf9..5c1de62755 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -39,8 +39,8 @@ if(CONFIG_SOC_DEDICATED_GPIO_SUPPORTED) list(APPEND srcs "gpio/dedic_gpio.c") endif() -if(CONFIG_SOC_SIGMADELTA_SUPPORTED) - list(APPEND srcs "gpio/sigmadelta_gpio.c") +if(CONFIG_SOC_SDM_SUPPORTED) + list(APPEND srcs "sdm.c" "deprecated/sigma_delta_legacy.c") endif() if(CONFIG_SOC_RMT_SUPPORTED) diff --git a/components/driver/include/driver/sigmadelta.h b/components/driver/deprecated/driver/sigmadelta.h similarity index 82% rename from components/driver/include/driver/sigmadelta.h rename to components/driver/deprecated/driver/sigmadelta.h index eaecead4d9..9b956cb3e9 100644 --- a/components/driver/include/driver/sigmadelta.h +++ b/components/driver/deprecated/driver/sigmadelta.h @@ -9,22 +9,16 @@ #include #include "esp_err.h" #include "driver/gpio.h" -#include "hal/sigmadelta_types.h" +#include "driver/sigmadelta_types_legacy.h" + +#if !CONFIG_SDM_SUPPRESS_DEPRECATE_WARN +#warning "The legacy sigma-delta driver is deprecated, please use driver/sdm.h" +#endif #ifdef __cplusplus extern "C" { #endif -/** - * @brief Sigma-delta configure struct - */ -typedef struct { - sigmadelta_channel_t channel; /*!< Sigma-delta channel number */ - int8_t sigmadelta_duty; /*!< Sigma-delta duty, duty ranges from -128 to 127. */ - uint8_t sigmadelta_prescale; /*!< Sigma-delta prescale, prescale ranges from 0 to 255. */ - gpio_num_t sigmadelta_gpio; /*!< Sigma-delta output io number, refer to gpio.h for more details. */ -} sigmadelta_config_t; - /** * @brief Configure Sigma-delta channel * diff --git a/components/driver/deprecated/driver/sigmadelta_types_legacy.h b/components/driver/deprecated/driver/sigmadelta_types_legacy.h new file mode 100644 index 0000000000..dddb9cac50 --- /dev/null +++ b/components/driver/deprecated/driver/sigmadelta_types_legacy.h @@ -0,0 +1,54 @@ +/* + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include "soc/soc_caps.h" +#include "driver/gpio.h" // for gpio_num_t type define + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief SIGMADELTA port number, the max port number is (SIGMADELTA_NUM_MAX -1). + */ +typedef enum { + SIGMADELTA_PORT_0, /*!< SIGMADELTA port 0 */ + SIGMADELTA_PORT_MAX, /*!< SIGMADELTA port max */ +} sigmadelta_port_t; + +/** + * @brief Sigma-delta channel list + */ +typedef enum { + SIGMADELTA_CHANNEL_0, /*!< Sigma-delta channel 0 */ + SIGMADELTA_CHANNEL_1, /*!< Sigma-delta channel 1 */ + SIGMADELTA_CHANNEL_2, /*!< Sigma-delta channel 2 */ + SIGMADELTA_CHANNEL_3, /*!< Sigma-delta channel 3 */ +#if SOC_SDM_CHANNELS_PER_GROUP > 4 + SIGMADELTA_CHANNEL_4, /*!< Sigma-delta channel 4 */ + SIGMADELTA_CHANNEL_5, /*!< Sigma-delta channel 5 */ + SIGMADELTA_CHANNEL_6, /*!< Sigma-delta channel 6 */ + SIGMADELTA_CHANNEL_7, /*!< Sigma-delta channel 7 */ +#endif + SIGMADELTA_CHANNEL_MAX, /*!< Sigma-delta channel max */ +} sigmadelta_channel_t; + +/** + * @brief Sigma-delta configure struct + */ +typedef struct { + sigmadelta_channel_t channel; /*!< Sigma-delta channel number */ + int8_t sigmadelta_duty; /*!< Sigma-delta duty, duty ranges from -128 to 127. */ + uint8_t sigmadelta_prescale; /*!< Sigma-delta prescale, prescale ranges from 0 to 255. */ + gpio_num_t sigmadelta_gpio; /*!< Sigma-delta output io number, refer to gpio.h for more details. */ +} sigmadelta_config_t; + +#ifdef __cplusplus +} +#endif diff --git a/components/driver/gpio/sigmadelta_gpio.c b/components/driver/deprecated/sigma_delta_legacy.c similarity index 88% rename from components/driver/gpio/sigmadelta_gpio.c rename to components/driver/deprecated/sigma_delta_legacy.c index 4e909a043f..d490d6f186 100644 --- a/components/driver/gpio/sigmadelta_gpio.c +++ b/components/driver/deprecated/sigma_delta_legacy.c @@ -7,18 +7,21 @@ #include "esp_log.h" #include "esp_check.h" #include "esp_err.h" -#include "driver/sigmadelta.h" #include "esp_heap_caps.h" -#include "hal/sigmadelta_hal.h" +#include "driver/gpio.h" +#include "driver/sigmadelta_types_legacy.h" +#include "soc/sdm_periph.h" +#include "hal/sdm_hal.h" +#include "hal/sdm_ll.h" #include "hal/gpio_hal.h" #include "esp_rom_gpio.h" -static const char *TAG = "sigma-delta"; +static const char *TAG = "sdm(legacy)"; #define SIGMADELTA_CHECK(a,str,ret_val) ESP_RETURN_ON_FALSE(a, ret_val, TAG, "%s", str) typedef struct { - sigmadelta_hal_context_t hal; /*!< SIGMADELTA hal context*/ + sdm_hal_context_t hal; /*!< SIGMADELTA hal context*/ } sigmadelta_obj_t; static sigmadelta_obj_t *p_sigmadelta_obj[SIGMADELTA_PORT_MAX] = {0}; @@ -32,7 +35,7 @@ static inline esp_err_t _sigmadelta_set_duty(sigmadelta_port_t sigmadelta_port, { SIGMADELTA_OBJ_CHECK(sigmadelta_port); - sigmadelta_hal_set_duty(&(p_sigmadelta_obj[sigmadelta_port]->hal), channel, duty); + sdm_ll_set_duty(p_sigmadelta_obj[sigmadelta_port]->hal.dev, channel, duty); return ESP_OK; } @@ -40,7 +43,7 @@ static inline esp_err_t _sigmadelta_set_prescale(sigmadelta_port_t sigmadelta_po { SIGMADELTA_OBJ_CHECK(sigmadelta_port); - sigmadelta_hal_set_prescale(&(p_sigmadelta_obj[sigmadelta_port]->hal), channel, prescale); + sdm_ll_set_prescale(p_sigmadelta_obj[sigmadelta_port]->hal.dev, channel, prescale + 1); return ESP_OK; } @@ -85,7 +88,8 @@ esp_err_t sigmadelta_init(sigmadelta_port_t sigmadelta_port) return ESP_FAIL; } - sigmadelta_hal_init(&(p_sigmadelta_obj[sigmadelta_port]->hal), sigmadelta_port); + sdm_hal_init(&(p_sigmadelta_obj[sigmadelta_port]->hal), sigmadelta_port); + sdm_ll_enable_clock(p_sigmadelta_obj[sigmadelta_port]->hal.dev, true); return ESP_OK; } diff --git a/components/driver/test_apps/gpio/main/CMakeLists.txt b/components/driver/test_apps/gpio/main/CMakeLists.txt index d60fc4d15e..c010006435 100644 --- a/components/driver/test_apps/gpio/main/CMakeLists.txt +++ b/components/driver/test_apps/gpio/main/CMakeLists.txt @@ -5,8 +5,8 @@ if(CONFIG_SOC_DEDICATED_GPIO_SUPPORTED) list(APPEND srcs "test_dedicated_gpio.c") endif() -if(CONFIG_SOC_SIGMADELTA_SUPPORTED) - list(APPEND srcs "test_sigmadelta.c") +if(CONFIG_SOC_SDM_SUPPORTED) + list(APPEND srcs "test_sigma_delta_legacy.c") endif() # In order for the cases defined by `TEST_CASE` to be linked into the final elf, diff --git a/components/driver/test_apps/gpio/main/test_sigmadelta.c b/components/driver/test_apps/gpio/main/test_sigma_delta_legacy.c similarity index 94% rename from components/driver/test_apps/gpio/main/test_sigmadelta.c rename to components/driver/test_apps/gpio/main/test_sigma_delta_legacy.c index 2cf3f472e2..d470deffa5 100644 --- a/components/driver/test_apps/gpio/main/test_sigmadelta.c +++ b/components/driver/test_apps/gpio/main/test_sigma_delta_legacy.c @@ -17,12 +17,12 @@ TEST_CASE("SigmaDelta_config_test", "[sigma_delta]") .sigmadelta_duty = 45, .sigmadelta_gpio = 4, }; - for (int i = 0; i < SOC_SIGMADELTA_CHANNEL_NUM; i++) { + for (int i = 0; i < SIGMADELTA_CHANNEL_MAX; i++) { sigmadelta_cfg.channel = i; TEST_ESP_OK(sigmadelta_config(&sigmadelta_cfg)); } - sigmadelta_cfg.channel = SOC_SIGMADELTA_CHANNEL_NUM; + sigmadelta_cfg.channel = SIGMADELTA_CHANNEL_MAX; TEST_ASSERT_EQUAL_MESSAGE(ESP_ERR_INVALID_ARG, sigmadelta_config(&sigmadelta_cfg), "wrong channel number should be inspected"); } diff --git a/components/driver/test_apps/gpio/sdkconfig.defaults b/components/driver/test_apps/gpio/sdkconfig.defaults index b308cb2ddd..a0545fb89b 100644 --- a/components/driver/test_apps/gpio/sdkconfig.defaults +++ b/components/driver/test_apps/gpio/sdkconfig.defaults @@ -1,2 +1,3 @@ CONFIG_FREERTOS_HZ=1000 CONFIG_ESP_TASK_WDT=n +CONFIG_SDM_SUPPRESS_DEPRECATE_WARN=y