mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
driver: a better way to avoid new/old driver coexistence
This commit is contained in:
parent
5732e2a4be
commit
a7d380c80a
@ -5,7 +5,6 @@ set(srcs
|
||||
"gptimer.c"
|
||||
"i2c.c"
|
||||
"ledc.c"
|
||||
"legacy_new_driver_coexist.c"
|
||||
"rtc_io.c"
|
||||
"rtc_module.c"
|
||||
"sdspi_crc.c"
|
||||
|
@ -31,7 +31,7 @@
|
||||
#define PCNT_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
|
||||
#define PCNT_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
|
||||
|
||||
static const char *TAG = "pcnt";
|
||||
static const char *TAG = "pcnt(legacy)";
|
||||
|
||||
#define PCNT_CHECK(a, str, ret_val) ESP_RETURN_ON_FALSE(a, ret_val, TAG, "%s", str)
|
||||
|
||||
@ -552,11 +552,12 @@ void pcnt_isr_service_uninstall(void)
|
||||
__attribute__((constructor))
|
||||
static void check_pcnt_driver_conflict(void)
|
||||
{
|
||||
extern int pcnt_driver_init_count;
|
||||
pcnt_driver_init_count++;
|
||||
if (pcnt_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The pulse_cnt driver can't work along with the legacy pcnt driver");
|
||||
// This function was declared as weak here. pulse_cnt driver has one implementation.
|
||||
// So if pulse_cnt driver is not linked in, then `pcnt_new_unit` should be NULL at runtime.
|
||||
extern __attribute__((weak)) esp_err_t pcnt_new_unit(const void *config, void **ret_unit);
|
||||
if (pcnt_new_unit != NULL) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! driver_ng is not allowed to be used with the legacy driver");
|
||||
abort();
|
||||
}
|
||||
ESP_EARLY_LOGW(TAG, "legacy pcnt driver is deprecated, please migrate to use driver/pulse_cnt.h");
|
||||
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/pulse_cnt.h`");
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_types.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
@ -18,7 +19,6 @@
|
||||
#include "hal/temperature_sensor_ll.h"
|
||||
#include "driver/temp_sensor_types_legacy.h"
|
||||
#include "esp_private/periph_ctrl.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char *TAG = "tsens";
|
||||
|
||||
@ -158,11 +158,12 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
|
||||
__attribute__((constructor))
|
||||
static void check_legacy_temp_sensor_driver_conflict(void)
|
||||
{
|
||||
extern int temp_sensor_driver_init_count;
|
||||
temp_sensor_driver_init_count++;
|
||||
if (temp_sensor_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The legacy temp sensor driver can't work along with the new temperature driver");
|
||||
// This function was declared as weak here. temperature_sensor driver has one implementation.
|
||||
// So if temperature_sensor driver is not linked in, then `temperature_sensor_install()` should be NULL at runtime.
|
||||
extern __attribute__((weak)) esp_err_t temperature_sensor_install(const void *tsens_config, void **ret_tsens);
|
||||
if (temperature_sensor_install != NULL) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! driver_ng is not allowed to be used with the legacy driver");
|
||||
abort();
|
||||
}
|
||||
ESP_EARLY_LOGW(TAG, "legacy temp sensor driver is deprecated, please migrate to use driver/temperature_sensor.h");
|
||||
ESP_EARLY_LOGW(TAG, "legacy driver is deprecated, please migrate to `driver/temperature_sensor.h`");
|
||||
}
|
||||
|
@ -480,11 +480,12 @@ esp_err_t IRAM_ATTR timer_spinlock_give(timer_group_t group_num)
|
||||
__attribute__((constructor))
|
||||
static void check_legacy_timer_driver_conflict(void)
|
||||
{
|
||||
extern int timer_group_driver_init_count;
|
||||
timer_group_driver_init_count++;
|
||||
if (timer_group_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TIMER_TAG, "CONFLICT! The legacy timer group driver can't work along with the gptimer driver");
|
||||
// This function was declared as weak here. gptimer driver has one implementation.
|
||||
// So if gptimer driver is not linked in, then `gptimer_new_timer()` should be NULL at runtime.
|
||||
extern __attribute__((weak)) esp_err_t gptimer_new_timer(const void *config, void **ret_timer);
|
||||
if (gptimer_new_timer != NULL) {
|
||||
ESP_EARLY_LOGE(TIMER_TAG, "CONFLICT! driver_ng is not allowed to be used with the legacy driver");
|
||||
abort();
|
||||
}
|
||||
ESP_EARLY_LOGW(TIMER_TAG, "legacy timer group driver is deprecated, please migrate to use driver/gptimer.h");
|
||||
ESP_EARLY_LOGW(TIMER_TAG, "legacy driver is deprecated, please migrate to `driver/gptimer.h`");
|
||||
}
|
||||
|
@ -504,20 +504,3 @@ esp_err_t gptimer_get_pm_lock(gptimer_handle_t timer, esp_pm_lock_handle_t *ret_
|
||||
*ret_pm_lock = timer->pm_lock;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will be called during start up, to check that gptimer driver is not running along with the legacy timer group driver
|
||||
*/
|
||||
__attribute__((constructor))
|
||||
static void check_gptimer_driver_conflict(void)
|
||||
{
|
||||
#if CONFIG_GPTIMER_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
extern int timer_group_driver_init_count;
|
||||
timer_group_driver_init_count++;
|
||||
if (timer_group_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The gptimer driver can't work along with the legacy timer group driver");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This count is used to prevent the coexistence of
|
||||
* the legacy timer group driver (deprecated/driver/timer.h) and the new gptimer driver (driver/gptimer.h).
|
||||
*/
|
||||
int timer_group_driver_init_count = 0;
|
||||
|
||||
/**
|
||||
* @brief This count is used to prevent the coexistence of
|
||||
* the legacy pcnt driver (deprecated/driver/pcnt.h) and the new pulse_cnt driver (driver/pulse_cnt.h).
|
||||
*/
|
||||
int pcnt_driver_init_count = 0;
|
||||
|
||||
/**
|
||||
* @brief This count is used to prevent the coexistence of
|
||||
* the legacy temperature sensor driver (deprecated/driver/temp_sensor.h) and the new temperature sensor driver (driver/temperature_sensor.h).
|
||||
*/
|
||||
int temp_sensor_driver_init_count = 0;
|
@ -724,20 +724,3 @@ IRAM_ATTR static void pcnt_default_isr(void *args)
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will be called during start up, to check that pulse_cnt driver is not running along with the legacy pcnt driver
|
||||
*/
|
||||
__attribute__((constructor))
|
||||
static void check_pulse_cnt_driver_conflict(void)
|
||||
{
|
||||
#if CONFIG_PCNT_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
extern int pcnt_driver_init_count;
|
||||
pcnt_driver_init_count++;
|
||||
if (pcnt_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The pulse_cnt driver can't work along with the legacy pcnt driver");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -83,10 +83,10 @@ static esp_err_t temperature_sensor_choose_best_range(temperature_sensor_handle_
|
||||
|
||||
esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_config, temperature_sensor_handle_t *ret_tsens)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
#if CONFIG_TEMP_SENSOR_ENABLE_DEBUG_LOG
|
||||
esp_log_level_set(TAG, ESP_LOG_DEBUG);
|
||||
#endif
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_RETURN_ON_FALSE((tsens_config && ret_tsens), ESP_ERR_INVALID_ARG, TAG, "Invalid argument");
|
||||
ESP_RETURN_ON_FALSE((s_tsens_attribute_copy == NULL), ESP_ERR_INVALID_STATE, TAG, "Already installed");
|
||||
temperature_sensor_handle_t tsens;
|
||||
@ -198,17 +198,3 @@ esp_err_t temperature_sensor_get_celsius(temperature_sensor_handle_t tsens, floa
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function will be called during start up, to check the new temperature driver is not running along with the legacy temp sensor driver
|
||||
*/
|
||||
__attribute__((constructor))
|
||||
static void check_temperature_driver_conflict(void)
|
||||
{
|
||||
extern int temp_sensor_driver_init_count;
|
||||
temp_sensor_driver_init_count++;
|
||||
if (temp_sensor_driver_init_count > 1) {
|
||||
ESP_EARLY_LOGE(TAG, "CONFLICT! The temperature driver can't work along with the legacy temp sensor driver");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user