/*
 * exo_io_al_temperature.c
 *
 *  Created on: Jan 16, 2024
 *      Author: Invcuser_102
 */

#include <stdio.h>
#include <stdint.h>
#include "exo_io_al_temperature.h"
#include "exo_io_al_adc_common.h"

#define V25 0.76                      ///< Voltage at 25 °C
#define VSENSE 3.3 / 4095             ///< 3.3 Voltage / VDDA = 4095
#define AVG_SLOPE 0.0025              ///< Average slope 2.5/1000 = 0.0025
#define IC_TEMP_TIME_OUT 500

extern ioal_adc_hdle ioal_hadc1;


float get_mcu_ic_temperature()
{
	float temperature = 0;
	uint32_t adc_val = 0;
	if (io_hal_adc_start(&ioal_hadc1)== HAL_SCS)
	{
		if (io_hal_adc_pollforconversion(&ioal_hadc1, IC_TEMP_TIME_OUT) == HAL_SCS)
		{
			adc_val = io_hal_adc_getvalue(&ioal_hadc1);
		}
	}
	temperature = ((((adc_val*3.3)/4095) - V25)/AVG_SLOPE) + 25;
	io_hal_adc_stop(&ioal_hadc1);
	return temperature;
}



