mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
remove(legacy_sdm): remove legacy sdm driver in IDF v6.0
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "driver/gpio.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 Configure Sigma-delta channel
|
||||
*
|
||||
* @param config Pointer of Sigma-delta channel configuration struct
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_STATE sigmadelta driver already initialized
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t sigmadelta_config(const sigmadelta_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Set Sigma-delta channel duty.
|
||||
*
|
||||
* This function is used to set Sigma-delta channel duty,
|
||||
* If you add a capacitor between the output pin and ground,
|
||||
* the average output voltage will be Vdc = VDDIO / 256 * duty + VDDIO/2,
|
||||
* where VDDIO is the power supply voltage.
|
||||
*
|
||||
* @param channel Sigma-delta channel number
|
||||
* @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90.
|
||||
* The waveform is more like a random one in this range.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t sigmadelta_set_duty(sigmadelta_channel_t channel, int8_t duty);
|
||||
|
||||
/**
|
||||
* @brief Set Sigma-delta channel's clock pre-scale value.
|
||||
* The source clock is APP_CLK, 80MHz. The clock frequency of the sigma-delta channel is APP_CLK / pre_scale
|
||||
*
|
||||
* @param channel Sigma-delta channel number
|
||||
* @param prescale The divider of source clock, ranges from 0 to 255
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t sigmadelta_set_prescale(sigmadelta_channel_t channel, uint8_t prescale);
|
||||
|
||||
/**
|
||||
* @brief Set Sigma-delta signal output pin
|
||||
*
|
||||
* @param channel Sigma-delta channel number
|
||||
* @param gpio_num GPIO number of output pin.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_STATE sigmadelta driver has not been initialized
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t sigmadelta_set_pin(sigmadelta_channel_t channel, gpio_num_t gpio_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_heap_caps.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"
|
||||
#include "esp_private/gpio.h"
|
||||
|
||||
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 {
|
||||
sdm_hal_context_t hal; /*!< SIGMADELTA hal context*/
|
||||
} sigmadelta_obj_t;
|
||||
|
||||
static sigmadelta_obj_t *p_sigmadelta_obj[SIGMADELTA_PORT_MAX] = {0};
|
||||
|
||||
#define SIGMADELTA_OBJ_CHECK(sigmadelta_port) { \
|
||||
SIGMADELTA_CHECK((sigmadelta_port < SIGMADELTA_PORT_MAX), "sigmadelta port error", ESP_ERR_INVALID_ARG); \
|
||||
SIGMADELTA_CHECK((p_sigmadelta_obj[sigmadelta_port]), "sigmadelta driver has not been initialized", ESP_ERR_INVALID_STATE); \
|
||||
}
|
||||
|
||||
static inline esp_err_t _sigmadelta_set_duty(sigmadelta_port_t sigmadelta_port, sigmadelta_channel_t channel, int8_t duty)
|
||||
{
|
||||
SIGMADELTA_OBJ_CHECK(sigmadelta_port);
|
||||
|
||||
sdm_ll_set_pulse_density(p_sigmadelta_obj[sigmadelta_port]->hal.dev, channel, duty);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static inline esp_err_t _sigmadelta_set_prescale(sigmadelta_port_t sigmadelta_port, sigmadelta_channel_t channel, uint8_t prescale)
|
||||
{
|
||||
SIGMADELTA_OBJ_CHECK(sigmadelta_port);
|
||||
|
||||
sdm_ll_set_prescale(p_sigmadelta_obj[sigmadelta_port]->hal.dev, channel, prescale + 1);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static inline esp_err_t _sigmadelta_set_pin(sigmadelta_port_t sigmadelta_port, sigmadelta_channel_t channel, gpio_num_t gpio_num)
|
||||
{
|
||||
SIGMADELTA_OBJ_CHECK(sigmadelta_port);
|
||||
|
||||
gpio_func_sel(gpio_num, PIN_FUNC_GPIO);
|
||||
gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT);
|
||||
esp_rom_gpio_connect_out_signal(gpio_num, sigma_delta_periph_signals.channels[channel].sd_sig, 0, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static inline esp_err_t _sigmadelta_config(sigmadelta_port_t sigmadelta_port, const sigmadelta_config_t *config)
|
||||
{
|
||||
SIGMADELTA_OBJ_CHECK(sigmadelta_port);
|
||||
|
||||
_sigmadelta_set_duty(sigmadelta_port, config->channel, config->sigmadelta_duty);
|
||||
_sigmadelta_set_prescale(sigmadelta_port, config->channel, config->sigmadelta_prescale);
|
||||
_sigmadelta_set_pin(sigmadelta_port, config->channel, config->sigmadelta_gpio);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t sigmadelta_deinit(sigmadelta_port_t sigmadelta_port)
|
||||
{
|
||||
SIGMADELTA_OBJ_CHECK(sigmadelta_port);
|
||||
|
||||
heap_caps_free(p_sigmadelta_obj[sigmadelta_port]);
|
||||
p_sigmadelta_obj[sigmadelta_port] = NULL;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t sigmadelta_init(sigmadelta_port_t sigmadelta_port)
|
||||
{
|
||||
SIGMADELTA_CHECK((sigmadelta_port < SIGMADELTA_PORT_MAX), "sigmadelta_port error", ESP_ERR_INVALID_ARG);
|
||||
SIGMADELTA_CHECK((p_sigmadelta_obj[sigmadelta_port]) == NULL, "sigmadelta driver already initialized", ESP_ERR_INVALID_STATE);
|
||||
|
||||
p_sigmadelta_obj[sigmadelta_port] = (sigmadelta_obj_t *) heap_caps_calloc(1, sizeof(sigmadelta_obj_t), MALLOC_CAP_DEFAULT);
|
||||
|
||||
if (p_sigmadelta_obj[sigmadelta_port] == NULL) {
|
||||
ESP_LOGE(TAG, "TAG driver malloc error");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// TODO: The following functions are wrappers, for compatibility with current API.
|
||||
|
||||
esp_err_t sigmadelta_set_duty(sigmadelta_channel_t channel, int8_t duty)
|
||||
{
|
||||
SIGMADELTA_CHECK(channel < SIGMADELTA_CHANNEL_MAX, "sigmadelta channel error", ESP_ERR_INVALID_ARG);
|
||||
return _sigmadelta_set_duty(SIGMADELTA_PORT_0, channel, duty);
|
||||
}
|
||||
|
||||
esp_err_t sigmadelta_set_prescale(sigmadelta_channel_t channel, uint8_t prescale)
|
||||
{
|
||||
SIGMADELTA_CHECK(channel < SIGMADELTA_CHANNEL_MAX, "sigmadelta channel error", ESP_ERR_INVALID_ARG);
|
||||
return _sigmadelta_set_prescale(SIGMADELTA_PORT_0, channel, prescale);
|
||||
}
|
||||
|
||||
esp_err_t sigmadelta_set_pin(sigmadelta_channel_t channel, gpio_num_t gpio_num)
|
||||
{
|
||||
SIGMADELTA_CHECK(channel < SIGMADELTA_CHANNEL_MAX, "sigmadelta channel error", ESP_ERR_INVALID_ARG);
|
||||
SIGMADELTA_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "sigmadelta gpio num error", ESP_ERR_INVALID_ARG);
|
||||
return _sigmadelta_set_pin(SIGMADELTA_PORT_0, channel, gpio_num);
|
||||
}
|
||||
|
||||
esp_err_t sigmadelta_config(const sigmadelta_config_t *config)
|
||||
{
|
||||
SIGMADELTA_CHECK(config->channel < SIGMADELTA_CHANNEL_MAX, "sigmadelta channel error", ESP_ERR_INVALID_ARG);
|
||||
SIGMADELTA_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(config->sigmadelta_gpio), "sigmadelta gpio num error", ESP_ERR_INVALID_ARG);
|
||||
esp_err_t ret;
|
||||
|
||||
if ((p_sigmadelta_obj[SIGMADELTA_PORT_0]) == NULL) {
|
||||
ret = sigmadelta_init(SIGMADELTA_PORT_0);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return _sigmadelta_config(SIGMADELTA_PORT_0, config);
|
||||
}
|
||||
|
||||
#if !CONFIG_SDM_SKIP_LEGACY_CONFLICT_CHECK
|
||||
/**
|
||||
* @brief This function will be called during start up, to check that sdm driver is not running along with the legacy sdm driver
|
||||
*/
|
||||
__attribute__((constructor))
|
||||
static void check_sdm_driver_conflict(void)
|
||||
{
|
||||
// This function was declared as weak here. sdm driver has one implementation.
|
||||
// So if sdm driver is not linked in, then `sdm_new_channel` should be NULL at runtime.
|
||||
extern __attribute__((weak)) esp_err_t sdm_new_channel(const void *config, void **ret_unit);
|
||||
if ((void *)sdm_new_channel != NULL) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! driver_ng is not allowed to be used with the legacy driver");
|
||||
abort();
|
||||
}
|
||||
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/sdm.h`");
|
||||
}
|
||||
#endif //CONFIG_PCNT_SKIP_LEGACY_CONFLICT_CHECK
|
||||
Reference in New Issue
Block a user