/*
 * id.h
 *
 *  Created on: Jul 28, 2025
 *      Author: herli
 */

#ifndef INC_ID_H_
#define INC_ID_H_

/* DEBUG PARAMETERS*/
//#define T06301				//ford 			004 -> 002 004 006	||	504 -> 010 018
//#define T06215   			//bmw rover  	004 -> 005 014 015 016 017	||	504 -> 005 007 017	||	006 -> 001 002 003 004 007 008
//#define T15021   			//audi 			506 -> 030 033
//#define T31804   			//audi 			506 -> 037 038
#define T06209	//eq: T06216

/* FORD  */
#define FORD_SYNC_PULSE_OUT 0

#define ENABLE_AUDI_IMMO 0
#define HAS_PREINJECTION 0

#define CYLINDERS 4

/* TIMING COMPENSATIONS */
#define PHI1 41.016

#define TEIN_NOMINAL 1550
#define TEIN_FAULT 1092.5

/* ALL FBKW */
#define FBKW_DEM_M 0.5
#define FBKW_DEM_TEMP_M 0
#define FBKW_DEM_TEMP_N -6.05

//rpm comp
#define FBKW_DEM_A1 0
#define FBKW_DEM_A2 0
#define FBKW_DEM_A3 0

#define FBKW_DEM_MIN -6

#define FBKW_FEEDBACK_ZERO 55.12//6.04?
#define FBKW_FEEDBACK_MIN -4.24
#define FBKW_FEEDBACK_MAX 19.75
#define FBKW_FEEDBACK_IC_DT 27

#define FBKW_PID_KP 90	//16
#define FBKW_PID_KI 0	//18
#define FBKW_PID_KD 0
#define FBKW_PID_KAW 0	//16
#define FBKW_PID_BIAS 60
#define FBKW_PID_INTEGRAL 0
#define FBKW_PID_MAXRATE 10000

#define FBKW_PWM_MAX 95
#define FBKW_PWM_MIN 5

#define FBKW_MAX 90 //en 504 parece que era 506
#define FBKW_MAX_REAL_DEM 165 //wtf is this

/* CAN DEFINITIONS */
#define CAN_BAUDRATE 500
#define CAN_RPM_SEND_ASYNC 250
#define CAN_EMPF2_INSTANT 0

/* ALL FUELMAP */
#define FM_N_RPM 6
#define FM_N_ME 10
#define FM_N_T 5


/* PEAK AND HOLD */
#define PH_PEAK_DEF 600

/* ANALOG CALIBRATION PARAMETERS */
// MOSFET
#define V_PEAK 2.94
#define V_HOLD 1.94

#define INJ_CLOSING_MARGIN 0 //o cero, o 20

// TOOTHED WHEEL
#define TW_MT_THRESHOLD 2.4
#define TW_THEETHS 120
#define TW_TOOTH_ALPHA 3
#define TW_STARTED_RPM 400

#define MIN_RPM 20

#define USTODEG 0.000006
// TIMINGS
#define TEIN_READING_OFFSET 8

/* ifdef things */

#if CYLINDERS == 4
    #define TW_PERCYL_TEETH 26
#elif CYLINDERS == 6
    #define TW_PERCYL_TEETH 16
#else
	#define TW_PERCYL_TEETH 26
    #error "Unsupported number of cylinders"
#endif


#endif /* INC_ID_H_ */
