/*
 * injection.h
 *
 *  Created on: Aug 4, 2025
 *      Author: herli
 */

#ifndef INC_INJECTION_H_
#define INC_INJECTION_H_

#include "stdint.h"
#include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_dac.h"
#include "can_schema.h"

extern DAC_HandleTypeDef hdac1;
extern TIM_HandleTypeDef htim1;

extern volatile uint8_t isInjecting;
extern volatile uint8_t hasInjected;
extern volatile uint8_t hasInjectionEnded;
extern volatile uint8_t hasInjectionEndedFlag;

extern float dFi;
extern uint8_t INJ_closingTeeth;
extern float ME;
extern float MEPI;

extern uint8_t safetySHUTOFF;
extern uint8_t timer1started;

extern uint32_t T_hold; 		//Time on in microseconds
extern uint16_t T_peak;
extern uint32_t T_integrated;


extern float current_Beta;
extern float current_Alpha;

extern void INJ_EVAL_EOI_COMPENSATION(void);
extern void INJ_UPDATE_ALPHA(void);
extern void INJ_UPDATE_CLOSING_TEETH(void);
extern void INJ_EVAL_END();
extern void INJ_END(void);
extern void INJ_SET_DAC(uint8_t isPeak);
extern void INJ_UPDATE_BOI_TRIGGER(void);
extern float INJ_GET_TARGET_BETA();
extern float INJ_GET_TARGET_EOI();
extern void INJ_UPDATE_BOI_MARGIN(float rpm);

float DEGTOTIME(float DEG, float revs);
float TIMETODEG(float TIME, float revs);

extern void SEND1_Handler();


#endif /* INC_INJECTION_H_ */
