/*
 * FBKW.h
 *
 *  Created on: Nov 20, 2024
 *      Author: herli
 */

#ifndef INC_FBKW_H_
#define INC_FBKW_H_
#include "main.h"
#include "pwm.h"
#include "ckp_acquisition.h"

extern TIM_HandleTypeDef htim4;

extern uint8_t CKP_PULSE_AVAILABLE;
extern uint8_t FBKW_PID_OPEN;
extern volatile uint32_t IC_SYNCOUT;
extern volatile uint32_t IC_CKP2;
extern volatile float RPM;
extern float refClock;
extern uint8_t safetySHUTOFF;

extern float FBKW_DEMAND;
extern float FBKW_DC;
extern float FBKW_FEEDBACK;

extern float B_FB_KW;
extern int16_t B_FB_NW;
extern uint8_t forceDC;



/*extern void FBKW_RESET_CKP_COUNT();
extern void FBKW_PIDInterrupt();
extern void FBKW_PROCESS_CKP_PULSE();
extern void updatePIDfreq(struct PID *pid, uint8_t millis);*/
extern void FBKW_CKP_ISR();

/* ---- VP44 reverse-engineered pipeline bridge ---------------------------
 * FBKW_init    : call once at startup (after RPM/Temp/etc globals exist).
 * FBKW_service : call once per control tick; pulls getters, runs pipeline,
 *                writes FBKW_DC and drives htim4/CH2 via UpdateFBKW_MODULATION.
 * FBKW_pipeline_runtime : accessor to inspect pipeline state for diagnostics.
 */
void FBKW_init(void);
void FBKW_service(void);
const pwm_runtime_t *FBKW_pipeline_runtime(void);
float FBKW_GET_CKP_OFFSET(void);
#endif /* INC_FBKW_H_ */
