#include "internal_temp_sensor.h"

/**
 * @brief Calculate temperature (tested on STM32F401, other MCU may have different constants!)
 * @note If IntRef not use, set it [ex.: #define TMPSENSOR_USE_INTREF 0]
 * @param Temperature sensor's ADC 16-bit value, Internal Reference ADC 16-bit value (if use)
 * @retval Internal sensor temperature
 */
int32_t TMPSENSOR_getTemperature(uint16_t adc_sensor, uint16_t adc_intref)
{

#if(TMPSENSOR_USE_INTREF)

	int32_t v_ref_int = __HAL_ADC_CALC_VREFANALOG_VOLTAGE(adc_intref,
			TMPSENSOR_ADC_RESOLUTION);

#else
	int32_t v_ref_int = TMPSENSOR_ADCREFVOL;
#endif

	int32_t internal_temperature = __HAL_ADC_CALC_TEMPERATURE(v_ref_int,
			adc_sensor, TMPSENSOR_ADC_RESOLUTION);

	//return sensor_tmp;
	return internal_temperature;
}

