sdm: deprecate legacy driver

pull/9446/head
morris 2022-06-22 16:36:35 +08:00
rodzic 4154eaec93
commit e080248141
7 zmienionych plików z 77 dodań i 24 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -9,22 +9,16 @@
#include <stdint.h>
#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
*

Wyświetl plik

@ -0,0 +1,54 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#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

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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,

Wyświetl plik

@ -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");
}

Wyświetl plik

@ -1,2 +1,3 @@
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT=n
CONFIG_SDM_SUPPRESS_DEPRECATE_WARN=y