/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    adc.h
  * @brief   This file contains all the function prototypes for
  *          the adc.c file
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ADC_H__
#define __ADC_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

extern ADC_HandleTypeDef hadc1;

extern ADC_HandleTypeDef hadc2;

extern ADC_HandleTypeDef hadc3;

/* USER CODE BEGIN Private defines */
extern uint16_t ADC_Buffer[8];
extern uint16_t ADC_Inject[3][4];

/* USER CODE END Private defines */

void MX_ADC1_Init(void);
void MX_ADC2_Init(void);
void MX_ADC3_Init(void);

/* USER CODE BEGIN Prototypes */

// Regular ADC (ADC3)
#define ADC_Start_DMA()               HAL_ADC_Start_DMA(&hadc3, (uint32_t*)ADC_Buffer, 8)
#define ADC_Stop_DMA()                HAL_ADC_Stop_DMA(&hadc3)
#define ADC_SWStart()                 LL_ADC_REG_StartConversionSWStart(ADC3)     //This function must be called after ADC_Start_DMA().
#define Get_ADC_Buffer(index)         ADC_Buffer[index]             //index:0~7
                                                                    //[0]ADC3_IN4(Pin 18) [1]ADC3_IN5(Pin 19) [2]ADC3_IN6 (Pin 20) [3]ADC3_IN7 (Pin 21)
                                                                    //[4]ADC3_IN8(Pin 22) [5]ADC3_IN9(Pin 13) [6]ADC3_IN14(Pin 14) [7]ADC3_IN15(Pin 15)
// Injected ADC (ADC1,ADC2,ADC3)
#define ADC1_InjectedStart_IT()       HAL_ADCEx_InjectedStart_IT(&hadc1)
#define ADC2_InjectedStart_IT()       HAL_ADCEx_InjectedStart_IT(&hadc2)
#define ADC3_InjectedStart_IT()       HAL_ADCEx_InjectedStart_IT(&hadc3)
#define Get_ADC_Inject(ch,index)      ADC_Inject[(ch)-1][index]     //ch:1~3, index:0~3
#define Get_ADC1_Inject(index)        Get_ADC_Inject(1,index)       //[0]ADC1_IN0(Pin 34) [1]ADC1_IN8 (Pin 46) [2]ADC1_IN3 (Pin 37) [3]ADC1_IN11(Pin 27)
#define Get_ADC2_Inject(index)        Get_ADC_Inject(2,index)       //[0]ADC2_IN1(Pin 35) [1]ADC2_IN9 (Pin 47) [2]ADC2_IN15(Pin 45) [3]ADC2_IN14(Pin 44)
#define Get_ADC3_Inject(index)        Get_ADC_Inject(3,index)       //[0]ADC3_IN2(Pin 36) [1]ADC3_IN10(Pin 26) [2]ADC3_IN12(Pin 28) [3]ADC3_IN13(Pin 29)

float   Get_Temperature(int ch);      //0 or 1 from NTC

float   Get_IDC();                    //-40~40A             ///somebp 2024.02.02
void Init_ADC_IDC();

float   Get_I_CHG();          // HSW 2025.04.14
void Init_ADC_I_CHG();
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __ADC_H__ */

