mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-07 14:44:32 +02:00
Merge branch 'bugfix/temp_sensor_coexist_issue' into 'master'
temp_sensor: avoid coexistence of new and legacy driver See merge request espressif/esp-idf!17395
This commit is contained in:
@@ -146,7 +146,7 @@ menu "Driver configurations"
|
|||||||
endmenu # TWAI Configuration
|
endmenu # TWAI Configuration
|
||||||
|
|
||||||
menu "Temperature sensor Configuration"
|
menu "Temperature sensor Configuration"
|
||||||
visible if SOC_TEMP_SENSOR_SUPPORTED
|
depends on SOC_TEMP_SENSOR_SUPPORTED
|
||||||
|
|
||||||
config TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN
|
config TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN
|
||||||
bool "Suppress legacy driver deprecated warning"
|
bool "Suppress legacy driver deprecated warning"
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "sdkconfig.h"
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "driver/temp_sensor_types_legacy.h"
|
#include "driver/temp_sensor_types_legacy.h"
|
||||||
|
|
||||||
|
@@ -31,8 +31,14 @@ typedef struct {
|
|||||||
temperature_sensor_clk_src_t clk_src; // the clock source of the temperature sensor.
|
temperature_sensor_clk_src_t clk_src; // the clock source of the temperature sensor.
|
||||||
} temperature_sensor_config_t;
|
} temperature_sensor_config_t;
|
||||||
|
|
||||||
#define TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(min, max) {.range_min = min, \
|
/**
|
||||||
|
* @brief temperature_sensor_config_t default constructure
|
||||||
|
*/
|
||||||
|
#define TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(min, max) \
|
||||||
|
{ \
|
||||||
|
.range_min = min, \
|
||||||
.range_max = max, \
|
.range_max = max, \
|
||||||
|
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT, \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,3 +15,9 @@ int timer_group_driver_init_count = 0;
|
|||||||
* the legacy pcnt driver (deprecated/driver/pcnt.h) and the new pulse_cnt driver (driver/pulse_cnt.h).
|
* the legacy pcnt driver (deprecated/driver/pcnt.h) and the new pulse_cnt driver (driver/pulse_cnt.h).
|
||||||
*/
|
*/
|
||||||
int pcnt_driver_init_count = 0;
|
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;
|
||||||
|
@@ -151,3 +151,18 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
|
|||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function will be called during start up, to check that this legacy temp sensor driver is not running along with the new driver
|
||||||
|
*/
|
||||||
|
__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");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
ESP_EARLY_LOGW(TAG, "legacy temp sensor driver is deprecated, please migrate to use driver/temperature_sensor.h");
|
||||||
|
}
|
||||||
|
@@ -198,3 +198,17 @@ esp_err_t temperature_sensor_get_celsius(temperature_sensor_handle_t tsens, floa
|
|||||||
}
|
}
|
||||||
return ESP_OK;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user