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
pull/8607/head
morris 2022-03-15 21:43:05 +08:00
commit cd10ac50cb
6 zmienionych plików z 49 dodań i 7 usunięć

Wyświetl plik

@ -146,7 +146,7 @@ menu "Driver configurations"
endmenu # TWAI Configuration
menu "Temperature sensor Configuration"
visible if SOC_TEMP_SENSOR_SUPPORTED
depends on SOC_TEMP_SENSOR_SUPPORTED
config TEMP_SENSOR_SUPPRESS_DEPRECATE_WARN
bool "Suppress legacy driver deprecated warning"

Wyświetl plik

@ -7,6 +7,7 @@
#pragma once
#include <stdint.h>
#include "sdkconfig.h"
#include "esp_err.h"
#include "driver/temp_sensor_types_legacy.h"

Wyświetl plik

@ -31,9 +31,15 @@ typedef struct {
temperature_sensor_clk_src_t clk_src; // the clock source of the temperature sensor.
} temperature_sensor_config_t;
#define TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(min, max) {.range_min = min, \
.range_max = max, \
}
/**
* @brief temperature_sensor_config_t default constructure
*/
#define TEMPERAUTRE_SENSOR_CONFIG_DEFAULT(min, max) \
{ \
.range_min = min, \
.range_max = max, \
.clk_src = TEMPERATURE_SENSOR_CLK_SRC_DEFAULT, \
}
/**
* @brief Install temperature sensor driver

Wyświetl plik

@ -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).
*/
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;

Wyświetl plik

@ -151,3 +151,18 @@ esp_err_t temp_sensor_read_celsius(float *celsius)
}
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");
}

Wyświetl plik

@ -54,12 +54,12 @@ static temp_sensor_ll_attribute_t *s_tsens_attribute_copy;
static int inline accuracy_compare(const void *p1, const void *p2)
{
return ((*(temp_sensor_ll_attribute_t*)p1).error_max < (*(temp_sensor_ll_attribute_t*)p2).error_max) ? -1 : 1;
return ((*(temp_sensor_ll_attribute_t *)p1).error_max < (*(temp_sensor_ll_attribute_t *)p2).error_max) ? -1 : 1;
}
static esp_err_t temperature_sensor_attribute_table_sort(void)
{
s_tsens_attribute_copy = (temp_sensor_ll_attribute_t*)heap_caps_malloc(sizeof(temp_sensor_ll_attributes), MALLOC_CAP_DEFAULT);
s_tsens_attribute_copy = (temp_sensor_ll_attribute_t *)heap_caps_malloc(sizeof(temp_sensor_ll_attributes), MALLOC_CAP_DEFAULT);
ESP_RETURN_ON_FALSE(s_tsens_attribute_copy != NULL, ESP_ERR_NO_MEM, TAG, "No space for s_tsens_attribute_copy");
for (int i = 0 ; i < TEMPERATURE_SENSOR_LL_RANGE_NUM; i++) {
s_tsens_attribute_copy[i] = temp_sensor_ll_attributes[i];
@ -90,7 +90,7 @@ esp_err_t temperature_sensor_install(const temperature_sensor_config_t *tsens_co
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;
tsens = (temperature_sensor_obj_t*) heap_caps_calloc(1, sizeof(temperature_sensor_obj_t), MALLOC_CAP_DEFAULT);
tsens = (temperature_sensor_obj_t *) heap_caps_calloc(1, sizeof(temperature_sensor_obj_t), MALLOC_CAP_DEFAULT);
ESP_GOTO_ON_FALSE(tsens != NULL, ESP_ERR_NO_MEM, err, TAG, "install fail...");
tsens->clk_src = tsens_config->clk_src;
@ -198,3 +198,17 @@ 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();
}
}